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

finnarne-guest at alioth.debian.org finnarne-guest at alioth.debian.org
Wed Apr 11 22:01:16 UTC 2007


  User: finnarne-guest
  Date: 07/04/11 22:01:16

  Modified:    .        index.php
  Log:
  Now writing of config also works, and the display is kind of nice
  
  Revision  Changes    Path
  1.8       +113 -21   slbackup-php/index.php
  
  Index: index.php
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup-php/index.php,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- index.php	11 Apr 2007 16:44:17 -0000	1.7
  +++ index.php	11 Apr 2007 22:01:16 -0000	1.8
  @@ -1,5 +1,45 @@
   <?php
   
  +function writeconf ($passwd, $config) {
  +global $backuphost, $backupuser, $backupconf, $ssh_options, $ssh_askpass ;
  +
  +    $out = sprintf ("<client>\n") ;
  +    foreach ($config["clients"] as $key => $value) {
  +	$out .= sprintf ("    <%s>\n", $key) ; 
  +	$out .= sprintf ("        address %s\n", $value["address"]) ; 
  +	$out .= sprintf ("        keep    %s\n", $value["keep"]) ; 
  +	foreach ($value["location"] as $loc)
  +	    $out .= sprintf ("        location %s\n", $loc) ; 
  +	$out .= sprintf ("        type    %s\n", $value["type"]) ; 
  +	$out .= sprintf ("        user    %s\n", $value["user"]) ; 
  +	$out .= sprintf ("    </%s>\n", $key) ; 
  +    }
  +    $out .= sprintf ("<client>\n") ;
  +    $out .= sprintf ("server_address %s\n", $config["server_address"]) ; 
  +    $out .= sprintf ("server_destdir %s\n", $config["server_destdir"]) ; 
  +    $out .= sprintf ("server_type    %s\n", $config["server_type"]) ; 
  +    $out .= sprintf ("server_user    %s\n", $config["server_user"]) ; 
  +
  +    $cmd = sprintf ("ssh %s %s@%s 'cat > %s'", 
  +   		     $ssh_options, $backupuser, 
  +		     $backuphost, $backupconf) ; 
  +
  +    $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\n", $out) ; 
  +	fclose ($pipes[1]) ; 
  +	fclose ($pipes[0]) ; 
  +	proc_close ($proc) ; 
  +	}
  +}
  +
   function readconf ($passwd) {
   global $backuphost, $backupuser, $backupconf, $ssh_options, $ssh_askpass ;
   
  @@ -48,8 +88,9 @@
   			if ($readclient && empty ($newclient)) {
   			    $newclient = trim ($key, "<>") ; 
   			    $clientconf = array () ; 
  +			    $clientconf["location"] = array () ; 
   			} elseif ($readclient && $key == "</" . $newclient . ">") {
  -			    $config["client"][$newclient] = $clientconf ; 
  +			    $config["clients"][$newclient] = $clientconf ; 
   			    unset ($newclient) ; 
   			    unset ($clientconf) ; 
   			}
  @@ -66,7 +107,7 @@
   }
   
   # Define some variables to easier change configuration during development
  -$backuphost="localhost" ; 
  +$backuphost="backup" ; 
   $backupuser="root" ; 
   $backupconf="/etc/slbackup/slbackup.conf" ; 
   $ssh_options="-o StrictHostKeyChecking=no" ; 
  @@ -123,15 +164,72 @@
   }
   
   switch ($submit) {
  +    case "server":
  +        foreach (array ("server_address", "server_destdir", "server_user", "server_type") as $key) {
  +            if ($newconf[$key] <> $config[$key]) {
  +                $changed = true ; 
  +                $config[$key] = $newconf[$key] ;
  +            }
  +        }
  +	if ($changed)
  +	    writeconf ($passwd, $config) ; 
  +	break ; 
  +    case "delclient": 
  +	if (empty ($client)) {
  +	    printf ("No client specified :(<BR>\n") ; 
  +	    break ; 
  +	}
  +	$pos = array_search($client, array_keys ($config["clients"])) ;
  +        if ($pos === false)
  +	    printf ("Unable to find %s in the list of clients<BR>\n", 
  +	 	    $client) ; 
  +	else {
  +	    array_splice ($config["clients"],
  +	                  $pos,1) ; 
  +	    writeconf ($passwd, $config) ; 
  +	}
  +	unset ($client) ; 
  +	break ;
  +    case "addclient":
  +        $client="<new>" ; 
  +        $config["clients"][$client]["keep"]="185" ; 
  +        $config["clients"][$client]["user"]="root" ; 
  +        break ;
  +    case "clientconfig":
  +        if ($client == "&lt;new&gt;") {
  +	    $client = $newconf["client_address"] ; 
  +	    $config["clients"][$client]["location"] = array () ;
  +        }
  +        foreach (array ("address", "keep", "user", "type") as $key) {
  +            if ($newconf["client_".$key] <> $config["clients"][$client][$key]) {
  +                $changed = true ; 
  +                $config["clients"][$client][$key] = $newconf["client_" . $key] ;
  +            }
  +        }
  +	if ($changed)
  +	    writeconf ($passwd, $config) ; 
  +	break ; 
  +    case "delloc": 
  +	if (empty ($newconf["location"]))
  +	    break ; 
  +	$pos = array_search ($newconf["location"], 
  +		         $config["clients"][$client]["location"]) ;
  +        if ($pos === false)
  +	    printf ("Unable to find %s in the locations of %s<BR>\n", 
  +	 	    $newconf["location"], $client) ; 
  +	else
  +	    array_splice ($config["clients"][$client]["location"],
  +	                  $pos,1) ; 
  +	writeconf ($passwd, $config) ; 
  +	break ;
       case "addloc": 
   	if (empty ($newconf["newloc"]))
   	    break ; 
   	if (in_array ($newconf["newloc"], 
  -		      $config["client"][$client]["location"]))
  +		      $config["clients"][$client]["location"]))
   	    break ;
  -	printf ("Trying to add %s to the locations of %s<BR>\n", 
  -		$newconf["newloc"], $client) ; 
  -	$config["client"][$client]["location"][] = $newconf["newloc"] ; 
  +	$config["clients"][$client]["location"][] = $newconf["newloc"] ; 
  +	writeconf ($passwd, $config) ; 
   	break ;
   }
   ?>
  @@ -184,7 +282,9 @@
   Client: 
   <select name=client>
   <?php
  -foreach ($config["client"] as $key => $value) {
  +if ($submit == "addclient")
  +    printf ("<option value='<new>' selected>&lt;new&gt;</option>\n") ;
  +foreach ($config["clients"] as $key => $value) {
       if (empty($client))
           $client=$key ; 
       printf ("<option value=%s %s>%s</option>\n", 
  @@ -200,12 +300,12 @@
           <TD>Address</TD>
           <TD>
               <INPUT type=text name=client_address 
  -                   value="<?php echo $config["client"][$client]["address"] ?>">
  +                   value="<?php echo $config["clients"][$client]["address"] ?>">
           </TD>
           <TD>Backup Age</TD>
           <TD>
               <INPUT type=text name=client_keep
  -                   value="<?php echo $config["client"][$client]["keep"] ?>">
  +                   value="<?php echo $config["clients"][$client]["keep"] ?>">
           </TD>
       </TR>
       <TR>
  @@ -216,7 +316,7 @@
       foreach (array ('local', 'remote') as $value) 
           printf ("<OPTION value=%s %s>%s</option>", 
                   $value, 
  -                ($config["client"][$client]["type"] == $value ? "selected": ""),
  +                ($config["clients"][$client]["type"] == $value ? "selected": ""),
                   $value) ; 
   ?>
               </SELECT>
  @@ -224,7 +324,7 @@
           <TD>User</TD>
           <TD>
               <INPUT type=text name=client_user 
  -                   value="<?php echo $config["client"][$client]["user"] ?>">
  +                   value="<?php echo $config["clients"][$client]["user"] ?>">
           </TD>
       </TR>
       <TR>
  @@ -243,9 +343,9 @@
       <TR>
           <TD/>
           <TD rowspan=5>
  -<select name=client size=7>
  +<select name=location size=7>
   <?php
  -foreach ($config["client"][$client][location] as $key => $value) {
  +foreach ($config["clients"][$client][location] as $key => $value) {
       printf ("<option value=%s>%s</option>\n", 
               $value, $value) ; 
   }
  @@ -258,12 +358,4 @@
   </FORM>
   <?php
   
  -# Show posted values at the bottom (except the password)
  -printf ("<pre>") ; 
  -print_r (array ('submit' => $submit, 
  -                'client' => $client,
  -                'newconf' => $newconf,
  -                'config' => $config)) ; 
  -printf ("</pre>") ; 
  -
   ?>
  
  
  



More information about the slbackup-commit mailing list