Guest User

Untitled

a guest
May 15th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. //Open a new connection to the MySQL server
  3. $mysqli = new mysqli('localhost','---','---','---');
  4.  
  5. //Output any connection error
  6. if ($mysqli->connect_error) {
  7.     die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
  8. }
  9. $output = shell_exec('crontab -r');
  10.  
  11.  
  12.  
  13. while ( list ($key, $value) = each($_POST)){
  14.  
  15.     $timer = explode(";", $value);
  16.     $on = $timer[0];
  17.     $off = $timer[1];
  18.    
  19.     $decOn = $on;
  20.     $hourOn = floor($decOn);
  21.     $minOn = round(60 * ($decOn - $hourOn));
  22.     If ($hourOn >= 24) {
  23.         $hourOn = $hourOn - 24;
  24.     }
  25.     $decOff = $off;
  26.     $hourOff = floor($decOff);
  27.     $minOff = round(60 * ($decOff - $hourOff));
  28.     If ($hourOff >= 24) {
  29.         $hourOff = $hourOff - 24;
  30.     }
  31.     $message = array($minOn,' ', $hourOn, ' * * * sudo python /var/www/timeron.py 33'.PHP_EOL,$minOff,' ', $hourOff, ' * * * sudo python /var/www/timeroff.py 33'.PHP_EOL );
  32.  
  33.     file_put_contents('/tmp/crontab.txt', $message);
  34.  
  35.     $statement = $mysqli->prepare("UPDATE pi_devices SET timerson=?, timersoff=?  WHERE device=?");
  36.     $statement->bind_param('sss', $on, $off, $key);
  37.     $statement->execute();
  38.    
  39. }
  40.  
  41. echo exec('crontab /tmp/crontab.txt');
  42.  
  43. $results->free();
  44. $mysqli->close();
  45. ?>
Add Comment
Please, Sign In to add comment