Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Open a new connection to the MySQL server
- $mysqli = new mysqli('localhost','---','---','---');
- //Output any connection error
- if ($mysqli->connect_error) {
- die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
- }
- $output = shell_exec('crontab -r');
- while ( list ($key, $value) = each($_POST)){
- $timer = explode(";", $value);
- $on = $timer[0];
- $off = $timer[1];
- $decOn = $on;
- $hourOn = floor($decOn);
- $minOn = round(60 * ($decOn - $hourOn));
- If ($hourOn >= 24) {
- $hourOn = $hourOn - 24;
- }
- $decOff = $off;
- $hourOff = floor($decOff);
- $minOff = round(60 * ($decOff - $hourOff));
- If ($hourOff >= 24) {
- $hourOff = $hourOff - 24;
- }
- $message = array($minOn,' ', $hourOn, ' * * * sudo python /var/www/timeron.py 33'.PHP_EOL,$minOff,' ', $hourOff, ' * * * sudo python /var/www/timeroff.py 33'.PHP_EOL );
- file_put_contents('/tmp/crontab.txt', $message);
- $statement = $mysqli->prepare("UPDATE pi_devices SET timerson=?, timersoff=? WHERE device=?");
- $statement->bind_param('sss', $on, $off, $key);
- $statement->execute();
- }
- echo exec('crontab /tmp/crontab.txt');
- $results->free();
- $mysqli->close();
- ?>
Add Comment
Please, Sign In to add comment