From: Joe Z. <jz...@us...> - 2003-04-26 22:39:46
|
Update of /cvsroot/bobs/bobs In directory sc8-pr-cvs1:/tmp/cvs-serv7450/bobs Modified Files: Makefile.am Makefile.in TODO admin.php systemcheck.php Added Files: lookadmin.css Log Message: Add server specific configuration checks to systemcheck.php. --- NEW FILE: lookadmin.css --- body { color: black; font-style: normal; font-size: 14px; font-family: Verdana, Helvetica, Arial } td { color: #000000; font-size: 14px; font-family: Verdana, Helvetica, Arial } tr { color: #000000; font-size: 14px; font-family: Verdana, Helvetica, Arial } a:link { color: #000000; text-decoration: none; font-size: 14px; font-family: Verdana, Helvetica, Arial } } a:visited { color: #000000; text-decoration: none; font-size: 14px; font-family: Verdana, Helvetica, Arial } } a:hover { color: #000000; text-decoration: underline; font-size: 14px; font-family: Verdana, Helvetica, Arial } } a:active { color: #000000; text-decoration: none; font-size: 14px; font-family: Verdana, Helvetica, Arial } } img { border-width: 0px } img { border: 0px } div.instruction {text-align: left; font-size: 14px;} div.serverhead {text-align: center; font-size: 14px;} div.servermode {text-align: right; font-size: 14px;} Index: Makefile.am =================================================================== RCS file: /cvsroot/bobs/bobs/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Makefile.am 20 Apr 2003 08:02:51 -0000 1.12 +++ Makefile.am 26 Apr 2003 22:39:43 -0000 1.13 @@ -36,6 +36,12 @@ FILES LICENSE VERSION # +# Other files to be removed before distribution +# + +DISTCLEANFILES = *.patch + +# # Other files to be removed for maintainer (me) # Index: Makefile.in =================================================================== RCS file: /cvsroot/bobs/bobs/Makefile.in,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.in 24 Apr 2003 06:15:56 -0000 1.10 +++ Makefile.in 26 Apr 2003 22:39:43 -0000 1.11 @@ -110,6 +110,12 @@ # +# Other files to be removed before distribution +# +DISTCLEANFILES = *.patch + + +# # Other files to be removed for maintainer (me) # MAINTAINERCLEANFILES = \ @@ -406,6 +412,7 @@ distclean-generic: -rm -f Makefile $(CONFIG_CLEAN_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" Index: TODO =================================================================== RCS file: /cvsroot/bobs/bobs/TODO,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- TODO 20 Apr 2003 08:02:51 -0000 1.14 +++ TODO 26 Apr 2003 22:39:43 -0000 1.15 @@ -34,6 +34,12 @@ Priority: Medium Backup directories (/var/bobsdata/) should not be world readable. Encrypt passwords. + Allow changing admin password in browser interface. + +User and group administration + Priority: Medium + Browser interface to allow maintaining authorized users + and groups. Make 'cmdloop' script a service. Priority: Medium Index: admin.php =================================================================== RCS file: /cvsroot/bobs/bobs/admin.php,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- admin.php 24 Apr 2003 06:15:56 -0000 1.18 +++ admin.php 26 Apr 2003 22:39:43 -0000 1.19 @@ -52,7 +52,12 @@ $tableborder = "0"; } -include("inc/header.pinc"); +// Don't output http header if going to redirect web page +// Yes, this is sloppy. + +if (! ($_POST['selectlist']['action'] == "Check Configuration") ){ + include_once("inc/header.pinc"); +} // ---------------------- // Display error message @@ -92,6 +97,12 @@ edit_server("delete", $server_name, $share_name, $_POST['settings']); // Server detail: delete mode break; + case ("Check Configuration"): // Test server config + $bobsdir = dirname($_SERVER['PHP_SELF']); + header("Location: $bobsdir/systemcheck.php?server=$server_name&share=$share_name"); + // Redirect browser + exit; + break; } break; case (isset($_POST['edit_server_OK'])): // On edit server detail already @@ -197,6 +208,7 @@ $serverlist->setadd(); // Show the "Add" button $serverlist->setchange(); // Show the "Change" button $serverlist->setdelete(); // Show the "Delete" button + $serverlist->addbutton("Check Configuration");// Test the system and server configuration $serverlist->addinput("Server name : ", 20); // Input fields for "Add" button $serverlist->addinput("Share description : ", 20); Index: systemcheck.php =================================================================== RCS file: /cvsroot/bobs/bobs/systemcheck.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- systemcheck.php 24 Apr 2003 06:15:56 -0000 1.1 +++ systemcheck.php 26 Apr 2003 22:39:43 -0000 1.2 @@ -10,10 +10,14 @@ require_once ('inc/class_rfasttemplate.php'); // Template class require_once("inc/class_config.php"); // configuration class -include("inc/header.pinc"); // Main menu +include_once("inc/header.pinc"); // Main menu $config = new config(); // Create instance of configuration class +// some global variables +$backup=''; +$srvtmpl=''; + $t = new rFastTemplate ('inc/templates'); $t->define (array('content' => 'systemcheck.thtml')); $t->define_dynamic (array ('item' => 'content', 'help' => 'content')); @@ -330,10 +334,262 @@ putfail(); } +// ---------------------------- +// Server specific checks +// ---------------------------- + +if (isset($_GET['server']) && $_GET['server'] != "" ) { + $server = $_GET['server']; + $share = $_GET['share']; + $t->assign ('ITEM', "<b>Performing tests on $server / $share<b>"); + $t->assign ('STATUS', 'INFO'); + putpass(); + server_tests($server, $share); +} + + + +// ---------------------------- +// End the table and html page +// ---------------------------- $t->parse ('ROW', 'endtable'); // end the table echo ($t->fetch()); -echo "</body></html>\n"; // End the html page +echo "</body></html>\n"; + +// ---------------------------- +// End of program +// ---------------------------- +return; + +// ======================================================== +// Functions start here +// ======================================================== + +// ---------------------------- +// Server specific tests +// ---------------------------- +function server_tests($server, $share){ + global $t, $backup, $srvtmpl; + + // Need 'add_queue_command' function from class_backup.php + + $t->assign ('ITEM', "Including file class_backup.php"); + $return = include_once('inc/class_backup.php'); + if ($return){ + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Unable to include file class_backup.php<br> + Cannot perform server tests. Reinstall bobs."); + putfail(); + } + + $t->assign ('ITEM', "Including file class_server.php"); + $return = include_once('inc/class_server.php'); + if ($return){ + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Unable to include file class_server.php<br> + Cannot perform server tests. Reinstall bobs."); + putfail(); + } + + // Instantiate the backup class so I can use add_queue_command() + + $srvcfg = new server(); + $srvcfg->set_config($server . '.' . $share); + $backup = new backup($srvcfg->sys_conf, $srvcfg->config); + + // Test communication with cmdloop process + + $srvtmpl = new rFastTemplate ('inc/templates'); + $srvtmpl->define (array('srvchk' => 'servercheck2.sh')); + + $srvtmpl->parse ('ROW', 'basictest'); + $rtnval = submit(); + if ($rtnval[0] != -1){ + $t->assign ('ITEM', "Testing communication with cmdloop process.<br> + Process said: \"$rtnval[0]\""); + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('ITEM', "Testing communication with cmdloop process"); + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Didn't get a valid response from cmdloop."); + putfail(); + } + $srvtmpl->clear_dynamic ('basictest'); + + // Try to mount the selected share. + + $config = $srvcfg->get_config(); + + $method = $config['backup_method']; + if ($method != "rsync"){ + $mntcmd = $srvcfg->get_mount_cmd('backup'); + $t->assign ('ITEM', "Attempting to mount for backup method type \"$method\" using this command:<br> + $mntcmd"); + $srvtmpl->assign ('COMMAND', "$mntcmd"); // the mount command + $srvtmpl->parse ('ROW', 'cmdwoutput'); + $rtnval = submit(); // submit the mount cmd + $srvtmpl->clear_dynamic ('cmdwoutput'); + $cmdoutput = getcmdout($rtnval); // Get the command's output + if ($rtnval[0] == 0) { + $t->assign ('STATUS', 'PASS'); + putpass(); + $mounted=TRUE; + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Mount failed with this message:<br><pre> $cmdoutput </pre>"); + putfail(); + $mounted=FALSE; + } + + // Test writing a file to the mounted directory + + if ($mounted == TRUE){ + $mountdir=$srvcfg->get_mount_dir(); + $t->assign ('ITEM', "Attempting to write, read and delete a file on<br> + $mountdir"); + $srvtmpl->assign ('MOUNTDIR', "$mountdir"); // the mount command + $srvtmpl->parse ('ROW', 'writetest'); + $rtnval = submit(); // submit the mount cmd + $srvtmpl->clear_dynamic ('writetest'); + $cmdoutput = getcmdout($rtnval); // Get the command's output + if ($rtnval[0] == 0) { + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Write file test failed with these messages:<br> + <pre> $cmdoutput </pre>"); + putfail(); + } + } + + + // Now unmount the share + + sleep(5); // Allow time for last operation to finish + $umntcmd = $srvcfg->get_umount_cmd('backup'); + $t->assign ('ITEM', "Attempting to unmount for backup method type \"$method\" using this command:<br> + $umntcmd"); + $srvtmpl->assign ('COMMAND', "$umntcmd"); // the mount command + $srvtmpl->parse ('ROW', 'cmdwoutput'); + $rtnval = submit(); // submit the mount cmd + $srvtmpl->clear_dynamic ('cmdwoutput'); + $cmdoutput = getcmdout($rtnval); // Get the command's output + if ($rtnval[0] == 0) { + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Unmount failed with this message:<br><pre> $cmdoutput </pre>"); + putfail(); + } + + } + + // Test mounting and unmounting the 'restore' method + // and reading and writing a file. + + sleep(5); // Allow time for last operation to finish + $method = $config['restore_method']; + if ($method != "rsync"){ + $mntcmd = $srvcfg->get_mount_cmd('restore'); + $t->assign ('ITEM', "Attempting to mount for restore method type \"$method\" using this command:<br> + $mntcmd"); + $srvtmpl->assign ('COMMAND', "$mntcmd"); // the mount command + $srvtmpl->parse ('ROW', 'cmdwoutput'); + $rtnval = submit(); // submit the mount cmd + $srvtmpl->clear_dynamic ('cmdwoutput'); + $cmdoutput = getcmdout($rtnval); // Get the command's output + if ($rtnval[0] == 0) { + $t->assign ('STATUS', 'PASS'); + putpass(); + $mounted=TRUE; + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Mount failed with this message:<br><pre> $cmdoutput </pre>"); + putfail(); + $mounted=FALSE; + } + + // Test writing a file to the mounted directory + + if ($mounted == TRUE){ + $mountdir=$srvcfg->get_mount_dir(); + $t->assign ('ITEM', "Attempting to write, read and delete a file on<br> + $mountdir"); + $srvtmpl->assign ('MOUNTDIR', "$mountdir"); // the mount command + $srvtmpl->parse ('ROW', 'writetest'); + $rtnval = submit(); // submit the mount cmd + $srvtmpl->clear_dynamic ('writetest'); + $cmdoutput = getcmdout($rtnval); // Get the command's output + if ($rtnval[0] == 0) { + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Write file test failed with these messages:<br> + <pre> $cmdoutput </pre>"); + putfail(); + } + } + + // Now unmount the share + + sleep(5); // Allow time for last operation to finish + $umntcmd = $srvcfg->get_umount_cmd('restore'); + $t->assign ('ITEM', "Attempting to unmount for restore method type \"$method\" using this command:<br> + $umntcmd."); + $srvtmpl->assign ('COMMAND', "$umntcmd"); // the mount command + $srvtmpl->parse ('ROW', 'cmdwoutput'); + $rtnval = submit(); // submit the mount cmd + $srvtmpl->clear_dynamic ('cmdwoutput'); + $cmdoutput = getcmdout($rtnval); // Get the command's output + if ($rtnval[0] == 0) { + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('STATUS', 'FAIL'); + $t->assign ('HELP', "Unmount failed with this message:<br><pre> $cmdoutput </pre>"); + putfail(); + } + + } + + // See if any backups have completed + + $backups_exist = FALSE; + $backupdir = $srvcfg->get_backupdir(); + $srvbakdir = $backupdir . '/' . $server . '/' . $share; + $t->assign ('ITEM', "Checking for completed backups in $srvbakdir."); + if ($dir = opendir("$srvbakdir")) { + while (($file = readdir($dir)) && ($backups_exist == FALSE)) { + if (($file != ".") & ($file != "..")){ + $backups_exist = TRUE; + } + } + } + closedir($dir); + + if ($backups_exist == TRUE) { + $t->assign ('STATUS', 'PASS'); + putpass(); + } else { + $t->assign ('STATUS', 'WARN'); + $t->assign ('HELP', "I didn't find any backup files.<br> + This is normal for a new installation.<br> + You won't be able to use the bobs 'restore' menu + until a backup has successfully completed."); + putfail(); + } +} // ---------------------------- // Output a passed template row @@ -360,4 +616,56 @@ $t->clear_dynamic ('help'); } -return; +// ---------------------------- +// Submit a script to be processed by cmdloop +// ---------------------------- +function submit(){ + global $backup, $srvtmpl; + + // Generate a temporary file name for return status + //$pid = posix_getpid(); // Current process id + $id = uniqid(bobssrvchk); + $tempfile = "/tmp/" . "$id"; + `umask 077; touch $tempfile`; // I need to create it so I can delete it + + $srvtmpl->assign ('TEMPFILE', $tempfile); + $srvtmpl->parse ('SRVCHK', 'srvchk'); + $script = $srvtmpl->fetch(); + $backup->add_queue_command($script, 'bash'); // submit the script to run under cmdloop + + // Read the response from the fifo + $maxsec = 20; // max seconds to wait for script + $count = 0; + $filesize = 0; + while ($filesize == 0 && $count < $maxsec) { + $count += 1; + sleep(1); + clearstatcache(); + $stats = stat("$tempfile"); + $filesize = $stats[7]; // element 8 is file size + } + + // Read the script output + if ($filesize > 0) { + $fout = file($tempfile); + unlink($tempfile); // cleanup: delete the temp file + return($fout); // return the script output + } + unlink($tempfile); // cleanup: delete the temp file + return(array(-1, 'Operation timed out.')); +} + +// ---------------------------- +// Get just the output portion of the submit() return value +// ---------------------------- +function getcmdout($rtnval){ + $cmdoutput = ""; + + foreach (array_slice($rtnval, 1) as $key => $value){ + $cmdoutput .= "$value"; + } + return $cmdoutput; +} + +// THE END +?> |