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

finnarne-guest at alioth.debian.org finnarne-guest at alioth.debian.org
Thu Apr 12 06:43:13 UTC 2007


  User: finnarne-guest
  Date: 07/04/12 06:43:13

  Modified:    .        index.php
  Log:
  Added functionality to read cron config
  
  Revision  Changes    Path
  1.9       +63 -5     slbackup-php/index.php
  
  Index: index.php
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup-php/index.php,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- index.php	11 Apr 2007 22:01:16 -0000	1.8
  +++ index.php	12 Apr 2007 06:43:13 -0000	1.9
  @@ -1,5 +1,31 @@
   <?php
   
  +function readcron ($passwd) {
  +global $backuphost, $backupuser, $backupcron, $ssh_options, $ssh_askpass ;
  +
  +    $cron = array() ; 
  +    $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) ; 
  +	fclose ($pipes[0]) ; 
  +	while ($line = fgets ($pipes[1], 1024))
  +	    $cron[] = trim ($line) ; 
  +	fclose ($pipes[1]) ; 
  +	proc_close ($proc) ; 
  +    }
  +    return $cron ; 
  +}
  +
   function writeconf ($passwd, $config) {
   global $backuphost, $backupuser, $backupconf, $ssh_options, $ssh_askpass ;
   
  @@ -107,9 +133,10 @@
   }
   
   # Define some variables to easier change configuration during development
  -$backuphost="backup" ; 
  +$backuphost="localhost" ; 
   $backupuser="root" ; 
   $backupconf="/etc/slbackup/slbackup.conf" ; 
  +$backupcron="/etc/cron.d/slbackup" ; 
   $ssh_options="-o StrictHostKeyChecking=no" ; 
   # fetch script to use whith passing the ssh-password
   $ssh_askpass = sprintf ("%s/mypass.sh", dirname ($_SERVER["SCRIPT_FILENAME"]));
  @@ -163,6 +190,8 @@
       return ; 
   }
   
  +$scheduler = readcron ($passwd) ; 
  +
   switch ($submit) {
       case "server":
           foreach (array ("server_address", "server_destdir", "server_user", "server_type") as $key) {
  @@ -232,10 +261,39 @@
   	writeconf ($passwd, $config) ; 
   	break ;
   }
  +foreach ($scheduler as $line) {
  +    if ($line[0] == "#") 
  +        continue ; 
  +    if (strpos ($line, "slbackup-cron") === false)
  +        continue ; 
  +    $isscheduled = true ; 
  +    $array = explode (" ", $line) ; 
  +    sscanf ($array[0], "%d", $minutes) ; 
  +    sscanf ($array[1], "%d", $hours) ; 
  +}
   ?>
   <FORM method=post>
   <INPUT type=hidden name=Passwd value="<?php echo $passwd ?>">
  -<H2>Server info</H2>
  +<H2>Server scheduler</H2>
  +Backup enabled 
  +<INPUT type=checkbox name=isscheduled <?php if ($isscheduled) echo "checked" ?>>
  +Run backup at
  +<select name=minutes>
  +<?php
  +    for ($i = 0 ; $i < 60 ; $i += 5)
  +        printf ("<OPTION value=%02d %s>%02d</option>", 
  +                $i, ($i == $minutes ? "selected" : ""), $i) ; 
  +?>
  +</select>
  +<select name=hours>
  +<?php
  +    for ($i = 0 ; $i < 24 ; $i++)
  +        printf ("<OPTION value=%02d %s>%02d</option>", 
  +                $i, ($i == $hours ? "selected" : ""), $i) ; 
  +?>
  +</select>
  +
  +<H2>Server config</H2>
   <TABLE>
       <TR>
           <TD>Address</TD>
  @@ -278,7 +336,7 @@
       </TR>
   
   </TABLE>
  -<H2>Client info</H2>
  +<H2>Client config</H2>
   Client: 
   <select name=client>
   <?php
  @@ -342,8 +400,8 @@
       </TR>
       <TR>
           <TD/>
  -        <TD rowspan=5>
  -<select name=location size=7>
  +        <TD>
  +<select name=location size=5>
   <?php
   foreach ($config["clients"][$client][location] as $key => $value) {
       printf ("<option value=%s>%s</option>\n", 
  
  
  



More information about the slbackup-commit mailing list