[slbackup-commit] CVS update: slbackup-php/src functions.php
index.php
finnarne-guest at alioth.debian.org
finnarne-guest at alioth.debian.org
Fri Apr 13 06:07:38 UTC 2007
User: finnarne-guest
Date: 07/04/13 06:07:38
Modified: src functions.php index.php
Log:
Rewritten to use smarty-templates
Revision Changes Path
1.2 +2 -1 slbackup-php/src/functions.php
Index: functions.php
===================================================================
RCS file: /cvsroot/slbackup/slbackup-php/src/functions.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- functions.php 12 Apr 2007 13:23:57 -0000 1.1
+++ functions.php 13 Apr 2007 06:07:38 -0000 1.2
@@ -19,7 +19,8 @@
*/
function loadConfig () {
- global $backuphost, $backupuser, $backupconf, $backupcron, $ssh_options ;
+ global $backuphost, $backupuser, $backupconf, $backupcron, $ssh_options,
+ $smarty_templ, $smarty_compile ;
@include_once ("/etc/slbackup/config.php") ;
1.6 +36 -160 slbackup-php/src/index.php
Index: index.php
===================================================================
RCS file: /cvsroot/slbackup/slbackup-php/src/index.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- index.php 12 Apr 2007 13:33:01 -0000 1.5
+++ index.php 13 Apr 2007 06:07:38 -0000 1.6
@@ -19,7 +19,6 @@
*/
-require_once ('functions.php') ;
function readcron ($passwd) {
global $backuphost, $backupuser, $backupcron, $ssh_options, $ssh_askpass ;
@@ -177,8 +176,17 @@
return $config ;
}
-# Define some variables to easier change configuration during development
+require_once ('functions.php') ;
loadConfig () ;
+require('/usr/share/php/smarty/libs/Smarty.class.php') ;
+session_start() ;
+$authenticated = ($_COOKIE['Authenticated'] == "True") ;
+loadLocale () ;
+ob_start ();
+
+$smarty = new Smarty();
+$smarty->template_dir = $smarty_templ ;
+$smarty->compile_dir = $smarty_compile ;
# fetch script to use whith passing the ssh-password
$ssh_askpass = sprintf ("%s/script/mypass.sh",
@@ -211,26 +219,13 @@
}
-printf ("<html>\n") ;
-printf ("<head>\n") ;
-printf ("<title>SLBackup Configuration</title>\n") ;
-printf ("</head>\n") ;
-printf ("<body>\n") ;
-
-
if (isset ($passwd))
$config = readconf ($passwd) ;
if (empty ($config)) {
- 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>",
- $backupuser, $backuphost) ;
- printf ("<INPUT type=password name=Passwd><BR>\n") ;
- printf ("<INPUT type=submit name=login value='Login'>\n") ;
- printf ("<INPUT type=reset name=Reset value='Reset'>\n") ;
- printf ("</FORM>") ;
+ $smarty->assign ('backupuser', $backupuser) ;
+ $smarty->assign ('backuphost', $backuphost) ;
+ $smarty->display ('login.tpl') ;
return ;
}
@@ -352,147 +347,28 @@
writeconf ($passwd, $config) ;
break ;
}
-
-?>
-<FORM method=post>
-<INPUT type=hidden name=Passwd value="<?php echo $passwd ?>">
-<H2>Server scheduler</H2>
-Backup enabled
-<INPUT type=checkbox name=active <?php if ($config["active"]) echo "checked" ?>>
-Run backup at
-<select name=minutes>
-<?php
+ $smarty->assign ('passwd', $passwd) ;
+ if ($config["active"])
+ $smarty->assign ('active', "checked") ;
for ($i = 0 ; $i < 60 ; $i += 5)
- printf ("<OPTION value=%02d %s>%02d</option>",
- $i, ($i == $config["minutes"] ? "selected" : ""), $i) ;
-?>
-</select>
-:
-<select name=hours>
-<?php
- for ($i = 0 ; $i < 24 ; $i++)
- printf ("<OPTION value=%02d %s>%02d</option>",
- $i, ($i == $config["hours"] ? "selected" : ""), $i) ;
-?>
-</select>
-<INPUT type=submit name=scheduler value="Update">
-<INPUT type=reset name=reset value="Reset">
-<H2>Server config</H2>
-<TABLE>
- <TR>
- <TD>Address</TD>
- <TD>
- <INPUT type=text name=server_address
- value="<?php echo $config[server_address] ?>">
- </TD>
- <TD>Destdir</TD>
- <TD>
- <INPUT type=text name=server_destdir
- value="<?php echo $config[server_destdir] ?>">
- </TD>
- </TR>
- <TR>
- <TD>Servertype</TD>
- <TD>
- <SELECT name=server_type>
-<?php
- foreach (array ('local', 'remote') as $value)
- printf ("<OPTION value=%s %s>%s</option>",
- $value,
- ($config[server_type] == $value ? "selected": ""),
- $value) ;
-?>
- </SELECT>
- </TD>
- <TD>User</TD>
- <TD>
- <INPUT type=text name=server_user
- value="<?php echo $config[server_user] ?>">
- </TD>
- </TR>
- <TR>
- <TD colspan=4 align=right>
- <INPUT type=submit name=server
- value="Update">
- <INPUT type=reset name=reset
- value="Reset">
- </TD>
- </TR>
-
-</TABLE>
-<H2>Client config</H2>
-Client:
-<select name=client>
-<?php
-foreach ($config["clients"] as $key => $value) {
- if (empty($client))
- $client=$key ;
- printf ("<option value='%s' %s>%s</option>\n",
- $key, ($key == $client) ? "selected" : "" , $key) ;
-}
-?>
-</select>
-<INPUT type=submit name=chooseclient value="Choose">
-<INPUT type=submit name=addclient value="New">
-<INPUT type=submit name=delclient value="Remove">
-<TABLE>
- <TR>
- <TD>Address</TD>
- <TD>
- <INPUT type=text name=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["clients"][$client]["keep"] ?>">
- </TD>
- </TR>
- <TR>
- <TD>Clienttype</TD>
- <TD>
- <SELECT name=client_type>
-<?php
- foreach (array ('local', 'remote') as $value)
- printf ("<OPTION value=%s %s>%s</option>",
- $value,
- ($config["clients"][$client]["type"] == $value ? "selected": ""),
- $value) ;
-?>
- </SELECT>
- </TD>
- <TD>User</TD>
- <TD>
- <INPUT type=text name=client_user
- value="<?php echo $config["clients"][$client]["user"] ?>">
- </TD>
- </TR>
- <TR>
- <TD colspan=4 align=right>
- <INPUT type=submit name=clientconfig
- value="<?php echo ($client == "<new>"? "Add": "Update") ?>">
- <INPUT type=reset name=reset
- value="reset">
- </TD>
- </TR>
- <TR>
- <TD>Locations:</TD>
- <TD><INPUT type=text name=newloc></TD>
- <TD><INPUT Type=submit name=addloc value="Add"></TD>
- </TR>
- <TR>
- <TD/>
- <TD>
-<select name=location size=5>
-<?php
-foreach ($config["clients"][$client][location] as $key => $value) {
- printf ("<option value=%s>%s</option>\n",
- $value, $value) ;
-}
+ $amin[] = sprintf ("%02d", $i) ;
+ $smarty->assign ('a_minutes', $amin);
+ $smarty->assign ('minutes', $config["minutes"]) ;
+ for ($i = 0 ; $i < 24 ; $i++)
+ $ahour[] = sprintf ("%02d", $i) ;
+ $smarty->assign ('a_hours', $ahour);
+ $smarty->assign ('hours', $config["hours"]) ;
+ $smarty->assign ('server_address', $config["server_address"]) ;
+ $smarty->assign ('server_destdir', $config["server_destdir"]) ;
+ $smarty->assign ('server_type', $config["server_type"]) ;
+ $smarty->assign ('server_user', $config["server_user"]) ;
+ $smarty->assign ('types', array ('local', 'remote')) ;
+ $smarty->assign ('clients', $config["clients"]) ;
+ $smarty->assign ('client', $client) ;
+ $smarty->assign ('clientaddress', $config["clients"][$client]["address"]) ;
+ $smarty->assign ('clientkeep', $config["clients"][$client]["keep"]) ;
+ $smarty->assign ('client_type', $config["clients"][$client]["type"]) ;
+ $smarty->assign ('clientuser', $config["clients"][$client]["user"]) ;
+ $smarty->assign ('locations', $config["clients"][$client]["location"]) ;
+ $smarty->display ('config.tpl') ;
?>
-</select>
- </TD>
- <TD valign=top><INPUT type=submit name=delloc value="Delete"></TD>
- </TR>
-</TABLE>
-</FORM>
More information about the slbackup-commit
mailing list