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

finnarne-guest at alioth.debian.org finnarne-guest at alioth.debian.org
Wed Apr 11 13:52:10 UTC 2007


  User: finnarne-guest
  Date: 07/04/11 13:52:10

  Modified:    .        index.php
  Log:
  Better handling of passed values
  Use only one form
  
  Revision  Changes    Path
  1.5       +53 -50    slbackup-php/index.php
  
  Index: index.php
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup-php/index.php,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- index.php	11 Apr 2007 12:59:22 -0000	1.4
  +++ index.php	11 Apr 2007 13:52:10 -0000	1.5
  @@ -7,47 +7,53 @@
   $ssh_options="-o StrictHostKeyChecking=no" ; 
   
   # Fetch arguments passed as the script is executed
  -$action = $_POST["Action"] ; 
  -$passwd = $_POST["Passwd"] ; 
  -$client = $_POST["client"] ; 
  +foreach ($_POST as $key => $value) {
  +    switch ($key) {
  +        case "Passwd": 
  +            $passwd = $value ; 
  +            break ; 
  +        case "server":
  +        case "chooseclient":
  +        case "clientconfig":
  +        case "addclient":
  +            $submit=$key ; 
  +            break ;
  +        case "client":
  +            $client=htmlspecialchars(trim($value)) ; 
  +            break ;
  +        default:
  +            $newconf[$key] = htmlspecialchars(trim($value)) ; 
  +            break ;
  +    }
  +}
   
   # fetch script to use whith passing the ssh-password
   $ssh_askpass = sprintf ("%s/mypass.sh", dirname ($_SERVER["SCRIPT_FILENAME"])); 
   
   printf ("<html>\n") ; 
   printf ("<head>\n") ; 
  -printf ("<title>%s</title>\n", _("SLBackup Configuration")) ; 
  +printf ("<title>SLBackup Configuration</title>\n") ; 
   printf ("</head>\n") ; 
   printf ("<body>\n") ; 
   
  -printf ("<pre>") ; 
  -printf ("</pre>") ; 
   
  -switch ($action) {
  -    case "read": 
  -        if (! empty ($passwd)) {
  -	    $cmd = sprintf ("ssh %s %s@%s cat %s", 
  -	                     $ssh_options, $backupuser, 
  -	                     $backuphost, $backupconf) ; 
  -	    break ; 
  -        }
  -}
  -
  -# if no cmd is provided, show loginform
  -if (empty ($cmd)) {
  -    printf ("<form name=login method=POST>\n") ; 
  -    printf ("<input type=hidden name=Action value=read>\n") ; 
  -    printf (_("To read the configuration, you must log in as %s on %s.<BR>"),
  +if (empty ($passwd)) {
  +    printf ("<FORM name=login method=POST>\n") ; 
  +    printf ("To read the configuration, you must log in as %s on %s.<BR>",
   	    $backupuser, $backuphost) ; 
  -    printf (_("Please enter the password for the %s account on %s:<BR>"),
  +    printf ("Please enter the password for the %s account on %s:<BR>",
   	    $backupuser, $backuphost) ; 
       printf ("<INPUT type=password name=Passwd><BR>\n") ; 
  -    printf ("<INPUT type=submit name=Submit value='%s'>\n", _("Login")) ; 
  -    printf ("<INPUT type=reset name=Reset value='%s'>\n", _("Reset")) ; 
  -    printf ("</form>") ; 
  +    printf ("<INPUT type=submit name=login value='Login'>\n") ; 
  +    printf ("<INPUT type=reset name=Reset value='Reset'>\n") ; 
  +    printf ("</FORM>") ; 
       return ; 
   }
   
  +$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") ; 
  @@ -103,8 +109,9 @@
       fclose ($pipes[1]) ; 
       proc_close ($proc) ; 
   ?>
  -<form name=server method=post>
  -<H2><?php echo _("Server info") ?></H2>
  +<FORM method=post>
  +<INPUT type=hidden name=Passwd value="<?php echo $passwd ?>">
  +<H2>Server info</H2>
   <TABLE>
       <TR>
           <TD>Address</TD>
  @@ -132,20 +139,15 @@
       </TR>
       <TR>
           <TD colspan=4 align=right>
  -            <INPUT type=hidden name=Action value=write>
  -            <INPUT type=submit name=submit 
  -                   value="<?php echo _("Submit") ?>">
  +            <INPUT type=submit name=server 
  +                   value="Submit">
               <INPUT type=reset name=reset 
  -                   value="<?php echo _("reset") ?>">
  +                   value="Reset">
           </TD>
       </TR>
   
   </TABLE>
  -<input type=hidden name=Action value="<?php echo $action ?>">
  -<input type=hidden name=Passwd value="<?php echo $passwd ?>">
  -</form>
  -<H2><?php echo _("Client info") ?></H2>
  -<form name=client method=post>
  +<H2>Client info</H2>
   Client: 
   <select name=client>
   <?php
  @@ -157,11 +159,7 @@
   }
   ?>
   </select>
  -<input type=hidden name=Action value="<?php echo $action ?>">
  -<input type=hidden name=Passwd value="<?php echo $passwd ?>">
  -<input type=submit name=submit value="<?php echo _("Choose") ?>">
  -</form>
  -<form name=clientconfig method=post>
  +<INPUT type=submit name=chooseclient value="Choose">
   <TABLE>
       <TR>
           <TD>Address</TD>
  @@ -189,16 +187,16 @@
       </TR>
       <TR>
           <TD colspan=4 align=right>
  -            <INPUT type=submit name=submit 
  -                   value="<?php echo _("Submit") ?>">
  +            <INPUT type=submit name=clientconfig 
  +                   value="Submit">
               <INPUT type=reset name=reset 
  -                   value="<?php echo _("reset") ?>">
  +                   value="reset">
           </TD>
       </TR>
       <TR>
           <TD>Locations:</TD>
  -        <TD><input type=text name=newloc></TD>
  -        <TD><input Type=submit name=add value="Add"></TD>
  +        <TD><INPUT type=text name=newloc></TD>
  +        <TD><INPUT Type=submit name=addclient value="Add"></TD>
       </TR>
       <TR>
           <TD/>
  @@ -212,13 +210,18 @@
   ?>
   </select>
           </TD>
  -        <TD valign=top><input type=submit name=del value="Delete"></TD>
  +        <TD valign=top><INPUT type=delete name=del value="Delete"></TD>
       </TR>
   </TABLE>
  -<input type=hidden name=Action value="<?php echo $action ?>">
  -<input type=hidden name=Passwd value="<?php echo $passwd ?>">
  -</form>
  +</FORM>
   <?php
   }
   
  +# Show posted values at the bottom (except the password)
  +printf ("<pre>") ; 
  +print_r (array ('submit' => $submit, 
  +                'client' => $client,
  +                'newconf' => $newconf)) ; 
  +printf ("</pre>") ; 
  +
   ?>
  
  
  



More information about the slbackup-commit mailing list