pfsense/etc/phpshellsessions/cvssync
Matthew Grooms 659fa7f23b Cleanup authentication code. The basic auth method, the passwd, htpasswd
and pam backing functions have been removed. The basic auth method was
legacy code and the backing functions were redundant with no added value
that I could see. A simplified replacement backing function named
local_backed has been added that authenticates to the local configuration
info which should be identical to system pwdb credentials. Since the
htpassword file is no longer required, sync_webgui_passwords and its
wrapper function system_password_configure have been removed.

The local account management functions were renamed for consistency. A few
minor bugs related to setting local passwords have also been corrected.
2008-08-03 17:54:35 +00:00

174 lines
4.9 KiB
Plaintext

/* cvs_sync
* Written by Scott Ullrich
* (C)2005-2007 Scott Ullrich
* Part of the pfSense project pfSsh.php subsystem
*/
function create_supfile($branch) {
if($branch == "HEAD")
$BRANCHTAG = ".";
else
$BRANCHTAG = $branch;
$supfile = "
*default host=cvs.pfsense.com
*default base=/home/pfsense/$branch
*default release=cvs tag=$BRANCHTAG
*default delete use-rel-suffix
pfSense
*default compress
";
file_put_contents("/var/etc/pfSense-supfile", $supfile);
}
unlink_if_exists("/tmp/config.cache");
if(!file_exists("/usr/local/bin/cvsup")) {
echo "Cannot find cvsup, pkg_add in progress...";
system("/usr/sbin/pkg_add -r cvsup-without-gui");
}
if(!file_exists("/usr/bin/cvs")) {
echo "Cannot find cvs, fetching static cvs...";
system("fetch -o /usr/bin/cvs http://files.pfsense.org/extras/7/cvs");
system("chmod a+rx /usr/bin/cvs");
}
if(!file_exists("/usr/bin/cvs") or !file_exists("/usr/local/bin/cvsup")) {
echo "Could not fetch cvs or cvsup. exiting.";
exit;
}
global $argv;
global $command_split;
/* NOTE: Set branches here */
$branches = array(
"RELENG_1" => "1.3 development branch",
"RELENG_1_2" => "1.2 release branch",
);
if(file_exists("/root/cvssync_backup.tgz"))
$branches[] = array("RESTORE" => "Restores prior CVSSync backup data.");
if($command_split[2]) {
$branch = $command_split[2];
} else {
if(!$argv[3]) {
echo "\nPlease select which branch you would like:\n\n";
foreach($branches as $branchname => $branchdesc) {
echo "{$branchname} - {$branchdesc}\n";
}
$branch = readline("\n> ");
echo "\n";
} else {
$branch = $argv[3];
}
}
create_supfile($branch);
$CODIR = "/home/pfsense/$branch";
exec("mkdir -p /home/pfsense/$BRANCHTAG");
$found = false;
foreach($branches as $branchname => $branchdesc) {
if($branchname == $branch)
$found = true;
}
if(!$found) {
echo "\nInvalid branch.\n";
exit;
}
if($branch == "RESTORE") {
if(!file_exists("/root/cvssync_backup.tgz")) {
echo "Sorry, we could not find a previous CVSSync backup file.\n";
exit();
}
echo "===> Restoring previous CVSSync backup... Please wait...\n";
exec("tar Uxpf /root/cvssync_backup.tgz -C /");
post_cvssync_commands();
exit();
}
echo "===> Backing up current pfSense information...\n";
echo "===> Please wait... ";
exec("tar czPf /root/cvssync_backup.tgz --exclude /root --exclude /dev --exclude /tmp --exclude /var/run --exclude /var/empty /");
$size = filesize("/root/cvssync_backup.tgz");
echo "{$size} bytes.\n\n";
sleep(5);
echo "===> Checking out $branch\n";
exec("mkdir -p /home/pfsense/$branch");
system("cvsup /var/etc/pfSense-supfile");
exec("rm -rf /usr/local/www/includes/*");
exec("rm -rf /usr/local/www/javascript/*");
exec("find /usr/local/www -name \"*.js\" -exec rm {} \;");
exec("mkdir -p /tmp/lighttpd/cache/compress/");
exec("cd ${CODIR}/ && find . -name CVS -exec rm -rf {} \; 2>/dev/null");
exec("cd ${CODIR}/ && find . -name pfSense.tgz -exec rm {} \; 2>/dev/null");
exec("rm -rf ${CODIR}/conf*");
exec("rm ${CODIR}/pfSense/usr/local/www/trigger_initial_wizard 2>/dev/null");
exec("rm ${CODIR}/pfSense/etc/crontab 2>/dev/null");
exec("rm ${CODIR}/pfSense/etc/master.passwd 2>/dev/null");
exec("rm ${CODIR}/pfSense/etc/passwd 2>/dev/null");
exec("rm ${CODIR}/pfSense/etc/fstab 2>/dev/null");
exec("rm ${CODIR}/pfSense/etc/ttys 2>/dev/null");
exec("rm ${CODIR}/pfSense/etc/group 2>/dev/null");
exec("rm ${CODIR}/pfSense/etc/fstab 2>/dev/null");
exec("rm ${CODIR}/pfSense/boot/device.hints 2>/dev/null");
exec("rm ${CODIR}/pfSense/boot/loader.conf 2>/dev/null");
exec("rm ${CODIR}/pfSense/boot/loader.rc 2>/dev/null");
exec("rm -rf ${CODIR}/pfSense/conf/ 2>/dev/null");
exec("rm -rf ${CODIR}/pfSense/cf/ 2>/dev/null");
exec("rm -rf ${CODIR}/pfSense/root/.shrc");
exec("rm -rf ${CODIR}/pfSense/root/.tcshrc");
exec("rm -f ${CODIR}/pfSense/etc/syslog.conf 2>/dev/null");
echo "===> Installing new files...\n";
exec("cd $CODIR/pfSense ; tar -cpf - . | (cd / ; tar -Uxpf -)");
post_cvssync_commands();
echo "===> Checkout complete.\n";
echo "\n";
echo "Your system is now sync'd and PHP and Lighty will be restarted in 5 seconds.\n\n";
function post_cvssync_commands() {
echo "===> Removing FAST-CGI temporary files...\n";
exec("find /tmp -name \"*php*\" -exec rm -rf {} \;");
exec("rm -rf /tmp/xcache/* 2>/dev/null");
echo "===> Upgrading configuration (if needed)...\n";
convert_config();
echo "===> Syncing system passwords...\n";
local_sync_accounts();
echo "===> Restarting check_reload_status...\n";
exec("killall check_reload_status");
mwexec_bg("nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status");
echo "===> Configuring filter...";
exec("/etc/rc.filter_configure_sync");
exec("pfctl -f /tmp/rules.debug");
echo "\n";
echo "===> Signaling PHP and Lighty restart...";
$fd = fopen("/tmp/restart_lighty", "w");
fwrite($fd, "#!/bin/sh\n");
fwrite($fd, "sleep 5\n");
fwrite($fd, "killall php\n");
fwrite($fd, "touch /tmp/restart_webgui\n");
fclose($fd);
mwexec_bg("sh /tmp/restart_lighty");
echo "\n";
}