[slbackup-commit] CVS update: slbackup-php/src functions.php index.php

finnarne-guest at alioth.debian.org finnarne-guest at alioth.debian.org
Sat Apr 14 05:19:34 UTC 2007


  User: finnarne-guest
  Date: 07/04/14 05:19:34

  Modified:    src      functions.php index.php
  Log:
  Now we can kind of check the logfile...
  
  Revision  Changes    Path
  1.5       +3 -2      slbackup-php/src/functions.php
  
  Index: functions.php
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup-php/src/functions.php,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- functions.php	13 Apr 2007 22:16:30 -0000	1.4
  +++ functions.php	14 Apr 2007 05:19:34 -0000	1.5
  @@ -19,8 +19,8 @@
   */
   
   function loadConfig () {
  -    global $backuphost, $backupuser, $backupconf, $backupcron, $ssh_options,
  -           $smarty_templ, $smarty_compile ; 
  +    global $backuphost, $backupuser, $backupconf, $backupcron,
  +           $ssh_options, $logfile, $smarty_templ, $smarty_compile ; 
   
       @include_once ("/etc/slbackup/config.php") ; 
   
  @@ -32,6 +32,7 @@
       if (empty ($backupconf)) $backupconf="/etc/slbackup/slbackup.conf" ; 
       if (empty ($backupcron)) $backupcron="/etc/cron.d/slbackup" ; 
       if (empty ($ssh_options)) $ssh_options="-o StrictHostKeyChecking=no" ; 
  +    if (empty ($logfile)) $logfile="/var/log/slbackup/slbackup.log" ; 
   
   
       if (empty ($smarty_templ)) {
  
  
  
  1.13      +53 -1     slbackup-php/src/index.php
  
  Index: index.php
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup-php/src/index.php,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- index.php	13 Apr 2007 22:16:30 -0000	1.12
  +++ index.php	14 Apr 2007 05:19:34 -0000	1.13
  @@ -176,6 +176,49 @@
       return $config ; 
   }
   
  +function readlog ($passwd, $log) {
  +global $backuphost, $backupuser, $logfile, $ssh_options, $ssh_askpass ;
  +
  +    $cmd = sprintf ("ssh %s %s@%s cat %s", 
  +   		     $ssh_options, $backupuser, 
  +		     $backuphost, $logfile) ; 
  +
  +    $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) ; 
  +	fclose ($pipes[0]) ; 
  +	while ($line = fgets ($pipes[1], 1024)) {
  +	    list ($timestamp, $info) = explode (" - ", trim($line)) ; 
  +	    if ($info == "Starting slbackup:")
  +	        $log["start"] = $timestamp ; 
  +	    elseif ($info == "Finished slbackup.")
  +	        $log["end"] = $timestamp ; 
  +	    elseif (strpos ($line, "Starting backup of client") !== false) {
  +	        sscanf ($info, "Starting backup of client %s", $client) ; 
  +	        if (!empty ($client))
  +	            $log["clients"][$client]["start"] = $timestamp ; 
  +	    } elseif (strpos ($line, "Failed backing up client") !== false) {
  +	        sscanf ($info, "Failed backing up client %s", $client) ; 
  +	        if (!empty ($client))
  +	            $log["clients"][$client]["failed"] = $timestamp ; 
  +	    } elseif (strpos ($line, "Successfully finished backing up client") !== false) {
  +	        sscanf ($info, "Successfully finished backing up client %s", $client) ; 
  +	        if (!empty ($client))
  +	            $log["clients"][$client]["ok"] = $timestamp ; 
  +	    }
  +        }
  +	fclose ($pipes[1]) ; 
  +	proc_close ($proc) ; 
  +    }
  +    return $log ; 
  +}
  +
   require_once ('functions.php') ; 
   loadConfig () ;
   require('/usr/share/php/smarty/libs/Smarty.class.php') ; 
  @@ -247,6 +290,8 @@
       $xorstring = xorstring ($encrypt, $passwd) ; 
   }
   
  +$smarty->assign ('xorstring', $xorstring) ; 
  +
   $scheduler = readcron ($passwd) ; 
   
   foreach ($scheduler as $line) {
  @@ -259,7 +304,15 @@
       sscanf ($array[0], "%d", $config["minutes"]) ; 
       sscanf ($array[1], "%d", $config["hours"]) ; 
   }
  +
   switch ($submit) {
  +    case "status":
  +        $log = array ('start' => '', 'end' => '') ; 
  +        foreach ($config["clients"] as $key => $value) 
  +            $log["clients"][$key] = 
  +                array ('start' => '', 'failed' => '', 'ok' => '') ; 
  +        debug (readlog ($passwd, $log)) ; 
  +        break ; 
       case "scheduler": 
           $newsched = "" ; 
           foreach ($scheduler as $line) {
  @@ -365,7 +418,6 @@
   	writeconf ($passwd, $config) ; 
   	break ;
   }
  -    $smarty->assign ('xorstring', $xorstring) ; 
       if ($config["active"]) 
   	$smarty->assign ('active', "checked") ; 
       for ($i = 0 ; $i < 60 ; $i += 5)
  
  
  



More information about the slbackup-commit mailing list