Skip to content

Instantly share code, notes, and snippets.

@hatzopoulos
Created January 21, 2015 02:54
Show Gist options
  • Save hatzopoulos/739fad080d455a5e757a to your computer and use it in GitHub Desktop.
Save hatzopoulos/739fad080d455a5e757a to your computer and use it in GitHub Desktop.
IP White List Update Cron
<?php
## ./ip-white-list-cron.php
$whitelist_json = __DIR__.'/whitelist.json';
$cache_mtime = filemtime($whitelist_json);
$write_error = 'Write Error. This needs to be properly setup to be able to write to '.$whitelist_json.PHP_EOL;
if ( $cache_mtime === false ) {
if ( touch($whitelist_json) === false) {
trigger_error($write_error, E_USER_ERROR);
}
}
elseif (!is_writeable($whitelist_json)) {
trigger_error($write_error, E_USER_ERROR);
}
if (filemtime(__FILE__) >= $cache_mtime) {
$json = json_encode( array(
'111.222.333.444', ## Office One
'111.222.333.444', ## Office Two
'111.222.333.444', ## Office Three
'111.222.333.444', ## Remote User One
'111.222.333.444', ## Remote User Two
'111.222.333.444', ## Remote User Three
) );
$bytes_written = file_put_contents( $whitelist_json, $json );
if ($bytes_written === false) {
trigger_error($write_error, E_USER_ERROR);
}
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment