[slbackup-commit] CVS update: slbackup-php index.php

finnarne-guest at alioth.debian.org finnarne-guest at alioth.debian.org
Thu Apr 12 11:58:26 UTC 2007


  User: finnarne-guest
  Date: 07/04/12 11:58:26

  Modified:    .        index.php
  Log:
  now it's able to save changes to the scheduler as well.
  
  Revision  Changes    Path
  1.12      +71 -18    slbackup-php/index.php
  
  Index: index.php
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup-php/index.php,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- index.php	12 Apr 2007 11:15:02 -0000	1.11
  +++ index.php	12 Apr 2007 11:58:26 -0000	1.12
  @@ -26,6 +26,30 @@
       return $cron ; 
   }
   
  +function writecron ($passwd, $cron) {
  +global $backuphost, $backupuser, $backupcron, $ssh_options, $ssh_askpass ;
  +
  +    $cmd = sprintf ("ssh %s %s@%s 'cat > %s'", 
  +   		     $ssh_options, $backupuser, 
  +		     $backuphost, $backupcron) ; 
  +
  +    $desc[0] = array ("pipe", "r") ; 
  +    $desc[1] = array ("pipe", "w") ; 
  +    $desc[2] = array ("file", "/tmp/error.log", "a") ; 
  +
  +    $env = array ('SSH_ASKPASS' => $ssh_askpass, 
  +		  'DISPLAY' => ':nowhere') ; 
  +    $proc = proc_open ($cmd, $desc, $pipes, '/tmp', $env) ; 
  +    if (is_resource ($proc)) {
  +	fprintf ($pipes[0], "%s\n", $passwd) ; 
  +	fprintf ($pipes[0], "%s", $cron) ; 
  +	fclose ($pipes[1]) ; 
  +	fclose ($pipes[0]) ; 
  +	proc_close ($proc) ; 
  +	}
  +}
  +
  +
   function writeconf ($passwd, $config) {
   global $backuphost, $backupuser, $backupconf, $ssh_options, $ssh_askpass ;
   
  @@ -193,7 +217,54 @@
   
   $scheduler = readcron ($passwd) ; 
   
  +foreach ($scheduler as $line) {
  +    if ($line[0] == "#") 
  +        continue ; 
  +    if (strpos ($line, "slbackup-cron") === false)
  +        continue ; 
  +    $config["active"] = true ; 
  +    $array = explode (" ", $line) ; 
  +    sscanf ($array[0], "%d", $config["minutes"]) ; 
  +    sscanf ($array[1], "%d", $config["hours"]) ; 
  +}
   switch ($submit) {
  +    case "scheduler": 
  +        $newsched = "" ; 
  +        foreach ($scheduler as $line) {
  +	    if ($line[0] == "#") 
  +		$newsched .= sprintf ("%s\n", $line) ; 
  +	    elseif (strpos ($line, "slbackup-cron") === false)
  +		$newsched .= sprintf ("%s\n", $line) ; 
  +	    elseif (empty ($newconf["active"])) {
  +		$newsched .= sprintf ("#%s\n", $line) ; 
  +                $changed = true ; 
  +                $config["active"] = false ; 
  +	    } else {
  +	        if ($config["minutes"] <> $newconf ["minutes"])
  +	            $changed = true ; 
  +	        if ($config["hours"] <> $newconf ["hours"])
  +	            $changed = true ; 
  +	        if ($changed) {
  +	            $config["active"] = true ; 
  +	            $config["minutes"] = $newconf ["minutes"] ; 
  +		    $config["hours"] = $newconf ["hours"] ; 
  +		    $newsched .= sprintf ("%02d %02d * * * root if [ -x /usr/share/slbackup/slbackup-cron -a -f /etc/slbackup/slbackup.conf ]; then /usr/share/slbackup/slbackup-cron ; fi\n", $newconf["minutes"], $newconf["hours"]) ; 
  +		} else 
  +		    $newsched .= sprintf ("%s\n", $line) ; 
  +            }
  +        }
  +        if (!$changed and empty($config["active"]) and 
  +             $newconf["active"] == "on") {
  +	    $config["active"] = true ; 
  +	    $config["minutes"] = $newconf ["minutes"] ; 
  +	    $config["hours"] = $newconf ["hours"] ; 
  +	    $newsched .= sprintf ("%02d %02d * * * root if [ -x /usr/share/slbackup/slbackup-cron -a -f /etc/slbackup/slbackup.conf ]; then /usr/share/slbackup/slbackup-cron ; fi\n", $newconf["minutes"], $newconf["hours"]) ; 
  +	    $changed = true ; 
  +	}
  +        if ($changed) {
  +	    writecron ($passwd, $newsched);
  +	}
  +        break ;
       case "server":
           foreach (array ("server_address", "server_destdir", "server_user", "server_type") as $key) {
               if ($newconf[$key] <> $config[$key]) {
  @@ -263,16 +334,6 @@
   	break ;
   }
   
  -foreach ($scheduler as $line) {
  -    if ($line[0] == "#") 
  -        continue ; 
  -    if (strpos ($line, "slbackup-cron") === false)
  -        continue ; 
  -    $config["active"] = true ; 
  -    $array = explode (" ", $line) ; 
  -    sscanf ($array[0], "%d", $config["minutes"]) ; 
  -    sscanf ($array[1], "%d", $config["hours"]) ; 
  -}
   ?>
   <FORM method=post>
   <INPUT type=hidden name=Passwd value="<?php echo $passwd ?>">
  @@ -415,11 +476,3 @@
       </TR>
   </TABLE>
   </FORM>
  -<?php
  -
  -if ($submit == "scheduler") {
  -    printf ("<pre>\n") ; 
  -    print_r ($newconf) ; 
  -    printf ("</pre>") ; 
  -} 
  -?>
  
  
  



More information about the slbackup-commit mailing list