return; } echo "{ \"done\" : 0, \"count\":0}"; break; case "files": header('Content-Type: application/json'); echo json_encode($cam->getFilesInFolder($_GET['folder'])); break; case "thumbnail": echo "{ \"thumbnailfile\" : \"" . $cam->getFileThumbnail($_GET['idx']) . "\" }"; break; case "grab": echo "{ \"file\" : \"" . $cam->getFile($_GET['idx']) . "\" }"; break; case "addCronJob": addCronJob(); break; } return; } function addCronJob() { $output = shell_exec('crontab -l'); file_put_contents('/tmp/crontab.txt', $output . '* * * * * NEW_CRON' . PHP_EOL); echo exec('crontab /tmp/crontab.txt'); } function GetLog() { $cam = Cameras::SelectedCamera(); $Log = array_reverse($cam->LogEntries); return $Log;
$os = $_REQUEST['os']; //lets test SSH prior. $connection = ssh2_connect($srvip, $sshport); ssh2_auth_password($connection, $user, $pass); $output = ssh2_exec($connection, "whoami"); stream_set_blocking($output, true); $stream_out = ssh2_fetch_stream($output, SSH2_STREAM_STDIO); $whoami = stream_get_contents($output); if (!strcmp(trim($whoami), $user)) { $query = "INSERT INTO swift_hosts(ip, user, pass, islinux, sshport, name) VALUES('{$srvip}', '{$user}', '{$pass}', '{$os}', '{$sshport}', '{$name}')"; $result = mysqli_query($mysql, $query); if (!$result) { die(mysqli_error($mysql)); } mysqli_query($mysql, "INSERT INTO swift_logs(username, ip, action, time) VALUES ('{$username}', '{$ip}', 'Added new server with IP {$srvip}', '" . time() . ")')"); addCronJob($srvip, $sshport, $user, $pass); echo "<h2>Server with the IP {$srvip} has been added to the system!</h2>"; } else { echo "<h2>Couldn't SSH to server with the IP {$srvip} with account {$user}.</h2>"; } } else { echo "<h2>Enter the server information below</h2>"; } ?> <form method="get" id="srv"> <div class="field"> <label for="name">Name</label> <input id="name" placeholder="Type in a friendly name for the server" type="text" name="name" required /> </div> <div class="field">
*/ // INSTRUCTIONS: To create a background task plugin do the following // - Copy this example file and save it as a new filename // - Update the plugin header with a new name and description to reflect what your plugin does // - Update addCronJob() with a short description of the cron activity, and set the cron expression to run as frequently as you want // - Rename all instances of 'cron_example' to a new function name // - Add any code as needed to your function and then test by clicking "Run Manually" from the plugins menu. // - Check the Background Tasks menu and make sure your plugin is running on schedule: admin.php?menu=admin&action=general#background-tasks // Setup scheduled background tasks // Cron Expression: minute(0-59), hour(0-23), dayOfMonth(1-31), month(1-12), dayOfWeek(0-7, 0=Sunday) Supports: *(any/all), 6(numbers), 1-3(ranges), 15,30,45(number lists) // Note: Called functions should return any content they want added to the log as the "Summary" and print/echo any content they wanted displayed as "output" textbox //addCronJob('yourFunctionName', "Activity Name to Log", '* * * * *'); // Run every minute //addCronJob('yourFunctionName', "Activity Name to Log", '0 * * * *'); // Run every hour //addCronJob('yourFunctionName', "Activity Name to Log", '0 3 * * *'); // Run at 3am every day //addCronJob('yourFunctionName', "Activity Name to Log", '0 10,13 * * *'); // Run at 10am, 1pm addCronJob('cron_example', "Cron Example Script", '0 * * * *'); // Run every hour // Plugin Menu - Add link to allow users to "Run Manually", this can be useful for testing pluginAction_addHandlerAndLink(t('Run Manually'), 'cron_example', 'admins'); // this function is called by cron, and logged under: Admin > General > Background Tasks // return()'d content is logged as "Summary" and and print/echo content is logged as "output" function cron_example() { if (!inCLI()) { // send headers (for running through web with "Run Manually" link above) if (!headers_sent()) { header("Content-type: text/plain"); header("Content-Disposition: inline; filename='output.txt'"); // Force IE to display as text and not download file ob_disable(); // Turn off browser buffering