function setupsecondary_main() { global $gbl, $sgbl, $login, $ghtml; global $argv; $dbf = $sgbl->__var_dbf; $prgm = $sgbl->__var_program_name; $list = parse_opt($argv); if (!isset($list['primary-master'])) { print "need --primary-master=\n"; exit; } if (!isset($list['sshport'])) { print "need --sshport=\n"; exit; } $master = $list['primary-master']; $sshport = $list['sshport']; print "Taking backup of the current database anyway...\n"; lxshell_php("../bin/common/mebackup.php"); $slavepass = randomString(7); print "Setting up mysql to receive data from master\n"; add_line_to_secondary_mycnf($master, $slavepass); $pass = slave_get_db_pass(); // TODO: REPLACE MYSQL_CONNECT $dblink = mysqli_connect("localhost", "root", $pass, $dbf); mysqli_query($dblink, "STOP SLAVE"); print "Getting initial data from the master\n"; system("ssh -p {$sshport} {$master} \"(cd /usr/local/lxlabs/{$prgm}/httpdocs ; lphp.exe ../bin/common/setupprimarymaster.php --slavepass={$slavepass})\" | mysql -u root -p{$pass} {$dbf}"); print "starting mysql data getting process\n"; mysqli_query($dblink, "CHANGE MASTER TO master_host='{$master}', master_password='******'"); mysqli_query($dblink, "START SLAVE"); lxfile_touch("../etc/secondary_master"); lxfile_touch("../etc/running_secondary"); }
function initString($ver) { $pclass = $this->main->getParentClass(); $this->main->fixphpIniFlag(); if ($this->main->phpini_flag_b->isON('enable_zend_flag')) { $this->main->phpini_flag_b->enable_zend_val = <<<XML [Zend] zend_extension_manager.optimizer=/usr/lib/kloxophp/zend/lib/Optimizer-3.2.8 zend_extension_manager.optimizer_ts=/usr/lib/kloxophp/zend/lib/Optimizer_TS-3.2.8 zend_optimizer.version=3.2.8 zend_extension=/usr/lib/kloxophp/zend/lib/ZendExtensionManager.so zend_extension_ts=/usr/lib/kloxophp/zend/lib/ZendExtensionManager_TS.so XML; } else { $this->main->phpini_flag_b->enable_zend_val = ""; } if ($this->main->phpini_flag_b->isON('enable_xcache_flag')) { lxfile_touch("../etc/flag/xcache_enabled.flg"); $this->main->phpini_flag_b->enable_xcache_val = <<<XML zend_extension = /usr/lib/php/modules/xcache.so XML; } else { lxfile_rm("../etc/flag/xcache_enabled.flg"); $this->main->phpini_flag_b->enable_xcache_val = ""; } if ($this->main->phpini_flag_b->isON('enable_ioncube_flag')) { $this->main->phpini_flag_b->enable_ioncube_val = <<<XML zend_extension=/usr/lib/kloxophp/ioncube/ioncube_loader_lin_{$ver}.so XML; } else { $this->main->phpini_flag_b->enable_ioncube_val = ""; } }
function os_update_server() { system("yum -y install --nosig webalizer lxjailshell autorespond unzip lxlighttpd lxphp >/dev/null 2>&1 &"); os_fix_some_permissions(); lxfile_touch("../etc/flag/lowmem.flag"); os_createLowMem(); }
function fixlogdir_main() { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; $logl = lscandir_without_dot("../log"); lxfile_mkdir("../processed_log"); @lunlink("../log/access_log"); @lunlink("/usr/local/lxlabs/ext/php/error.log"); $dir = getNotexistingFile("../processed_log", "proccessed"); system("mv ../log ../processed_log/{$dir}"); mkdir("../log"); $list = lscandir_without_dot("../processed_log"); foreach ($list as $l) { remove_directory_if_older_than_a_day("../processed_log/{$l}", 6); } foreach ($logl as $l) { lxfile_touch("../log/{$l}"); } lxfile_generic_chown_rec("../log", "lxlabs:lxlabs"); // // Related to Issue #15 // lxfile_generic_chmod_rec("../log", "0640"); lxfile_generic_chmod_rec("../processed_log", "0640"); lxfile_generic_chmod("../log", "0700"); lxfile_generic_chmod("../processed_log", "0700"); lxfile_generic_chmod("../log/lighttpd_error.log", "0644"); lxfile_generic_chmod("../log/access_log", "0644"); lxfile_generic_chown("../log/lighttpd_error.log", "lxlabs:root"); lxfile_generic_chown("../log/access_log", "lxlabs:root"); // os_restart_program(); }
function updatecleanup_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; $program = $sgbl->__var_program_name; $opt = parse_opt($argv); if ($opt['type'] === 'master') { initProgram('admin'); $flg = "__path_program_start_vps_flag"; if (!lxfile_exists($flg)) { set_login_skin_to_feather(); } } else { $login = new Client(null, null, 'update'); } print "Executing UpdateCleanup. This can take a long time. Please be patient\n"; log_log("update", "Executing Updatecleanup"); // // Cleanup old lxlabs.repo file // print "Fixing Repo's\n"; if (lxfile_exists("/etc/yum.repos.d/lxcenter.repo")) { if (lxfile_exists("/etc/yum.repos.d/lxlabs.repo")) { lxfile_mv("/etc/yum.repos.d/lxlabs.repo", "/etc/yum.repos.d/lxlabs.repo.lxsave"); system("rm -f /etc/yum.repos.d/lxlabs.repo"); } } if (lxfile_exists("CVS")) { print "Found Development version, we just go on.\n"; // exit; } if ($opt['type'] === 'master') { $sgbl->slave = false; if (!is_secondary_master()) { print "Update database\n"; updateDatabaseProperly(); print "Fix Extra database issues\n"; fixExtraDB(); print "Update extra issues\n"; doUpdateExtraStuff(); print "Get Driver info\n"; lxshell_return("__path_php_path", "../bin/common/driverload.php"); } print "Starting Update all slaves\n"; update_all_slave(); print "Fix main {$program} databasefile\n"; cp_dbfile(); } else { $sgbl->slave = true; } if (!is_secondary_master()) { print "Starting update cleanups\n"; updatecleanup(); } lxfile_touch("__path_program_start_vps_flag"); }
function createVirtualHost() { $string = null; foreach ($this->main->__var_domlist as $v) { $string .= "\$HTTP[\"host\"] =~ \"^{$v}\" {\n"; $string .= "server.document-root = \"/usr/local/lxlabs/kloxo/httpdocs/webdisk/\"\n"; $string .= "cgi.assign = ( \".php\" => \"/home/httpd/{$v}/davsuexec.sh\" )\n"; $string .= $this->getDirprotectCore($v); $string .= "}\n\n\n"; lxfile_mkdir("__path_httpd_root/{$v}/__davuser/"); lxfile_touch("__path_httpd_root/{$v}/__davuser/davuser"); } return $string; }
function syncSpamUserPref() { global $gbl, $sgbl, $ghtml; // The parent can be either a domain or a user. CHeck for the @ sign. if (csa($this->main->nname, "@")) { list($user, $domain) = explode("@", $this->main->nname); } else { $domain = $this->main->nname; $user = null; } $sysuser = mmail__qmail::getUserGroup($domain); // --- issue #578/#721 - missing in version 6.1.6 // $mailpath = "/home/lxadmin/mail"; $mailpath = mmail__qmail::getDir($domain); if ($user) { // $prefpath = "$mailpath/domains/{$domain}/{$user}/.bogopref.cf"; $prefpath = "{$mailpath}/{$user}/.bogopref.cf"; } else { return; } $prefdir = dirname($prefpath); if (!lxfile_exists(dirname($prefpath))) { lxuser_mkdir($sysuser, dirname($prefpath)); } $wname = fix_nname_to_be_variable($this->main->nname); $fdata = null; $cutoff = $this->main->spam_hit / 10 + 0.2; $fdata .= "spam_cutoff {$cutoff}\n"; $fdata .= "spam_subject_tag={$this->main->subject_tag}\n"; $fdata .= "wordlist R,user,{$wname}.wordlist.db,1\n"; $fdata .= "wordlist R,system,wordlist.db,2\n"; $fdata .= "wordlist R,system,kloxo.wordlist.db,3\n"; lxuser_put_contents($sysuser, $prefpath, $fdata); if (!lxfile_real("/var/bogofilter/{$wname}.wordlist.db")) { new_process_cmd($sysuser, null, "bogofilter -d /var/bogofilter/ --wordlist=R,user,{$wname}.wordlist.db,1 -n < /etc/my.cnf"); } lxfile_touch("/var/bogofilter/wordlist.db"); // Using generic because spamassasin is used on windows too. Or at least can be used. //lxfile_generic_chown("/var/bogofilter", mmail__qmail::getUserGroup($domain)); }
function initString($ver) { // DT16022014 // TODO: Refactor this function See #1075 #1076 // $pclass = $this->main->getParentClass(); $this->main->fixphpIniFlag(); if ($this->main->phpini_flag_b->isON('enable_zend_flag')) { $this->main->phpini_flag_b->enable_zend_val = <<<XML [Zend] zend_extension_manager.optimizer=/usr/lib/kloxophp/zend/lib/Optimizer-3.2.8 zend_extension_manager.optimizer_ts=/usr/lib/kloxophp/zend/lib/Optimizer_TS-3.2.8 zend_optimizer.version=3.2.8 zend_extension=/usr/lib/kloxophp/zend/lib/ZendExtensionManager.so zend_extension_ts=/usr/lib/kloxophp/zend/lib/ZendExtensionManager_TS.so XML; } else { $this->main->phpini_flag_b->enable_zend_val = ""; } // Project issue #1095 // DT16022014 Turn off xcache.so as zend_extension. // It does not work anymore as zend_extension. // It is enabled/disabled with function enableDisableModule() if ($this->main->phpini_flag_b->isON('enable_xcache_flag')) { lxfile_touch("../etc/flag/xcache_enabled.flg"); $this->main->phpini_flag_b->enable_xcache_val = <<<XML ;zend_extension = /usr/lib/php/modules/xcache.so XML; } else { lxfile_rm("../etc/flag/xcache_enabled.flg"); $this->main->phpini_flag_b->enable_xcache_val = ""; } if ($this->main->phpini_flag_b->isON('enable_ioncube_flag')) { $this->main->phpini_flag_b->enable_ioncube_val = <<<XML zend_extension=/usr/lib/kloxophp/ioncube/ioncube_loader_lin_{$ver}.so XML; } else { $this->main->phpini_flag_b->enable_ioncube_val = ""; } }
} } foreach ($list as &$l) { $l = preg_replace("/__cgi_or_fcgi__/", $php_st, $l); $l = preg_replace("/__program_name__/", $sgbl->__var_program_name, $l); $l = preg_replace("/__program_disable_nonssl__/", $nonsslhash, $l); $l = preg_replace("/__program_port__/", $nonsslport, $l); $l = preg_replace("/__program_sslport__/", $sslport, $l); $l = preg_replace("/__program_user__/", $user, $l); } lfile_put_contents("../file/lighttpd.conf", implode("", $list)); $pemfile = "__path_program_root/etc/program.pem"; $cafile = "__path_program_root/etc/program.ca"; if (!lxfile_exists($pemfile)) { lxfile_cp("__path_program_htmlbase/htmllib/filecore/program.pem", $pemfile); lxfile_generic_chown($pemfile, "lxlabs"); } // Merged from 6.1.x/kloxo/bin/common/misc/fixlighty.php (revision 472) lxfile_touch("__path_program_root/log/lighttpd_error.log"); lxfile_touch("__path_program_root/log/access_log"); lxfile_generic_chmod("__path_program_root/log", "0700"); lxfile_generic_chown("__path_program_root/log", "lxlabs:lxlabs"); lxfile_generic_chmod("__path_program_root/log/lighttpd_error.log", "0644"); lxfile_generic_chmod("__path_program_root/log/access_log", "0644"); lxfile_generic_chown("__path_program_root/log/lighttpd_error.log", "lxlabs:root"); lxfile_generic_chown("__path_program_root/log/access_log", "lxlabs:root"); // if (!lxfile_exists($cafile)) { lxfile_cp("__path_program_htmlbase/htmllib/filecore/program.ca", $cafile); lxfile_generic_chown($cafile, "lxlabs"); }
function memoryGraphFix() { global $gbl, $sgbl, $login, $ghtml; $file = "__path_program_root/etc/openvzmemorygraphfix"; if (lxfile_exists($file)) { print "Memory Graph fix not needed\n"; return; } lxfile_touch($file); system("rm {$sgbl->__path_program_root}/data/memory/*"); }
function updatecleanup_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; $program = $sgbl->__var_program_name; $opt = parse_opt($argv); if ($opt['type'] === 'master') { initProgram('admin'); $flg = "__path_program_start_vps_flag"; if (!lxfile_exists($flg)) { set_login_skin_to_feather(); } } else { $login = new Client(null, null, 'update'); } log_cleanup("*** Executing Update (cleanup) - BEGIN ***"); // // Check for lxlabs yum repo file and if exists // Change to lxcenter repo file // if (lxfile_exists("/etc/yum.repos.d/lxlabs.repo")) { log_cleanup("- Deleting old lxlabs yum repo"); lxfile_mv("/etc/yum.repos.d/lxlabs.repo", "/etc/yum.repos.d/lxlabs.repo.lxsave"); exec("rm -f /etc/yum.repos.d/lxlabs.repo"); log_cleanup("- Removed lxlabs.repo"); log_cleanup("- Installing lxcenter.repo"); exec("wget -O /etc/yum.repos.d/lxcenter.repo http://download.lxcenter.org/lxcenter.repo"); log_cleanup("- Installing yum-protectbase plugin"); exec("yum install -y -q yum-protectbase"); } // Fix #388 - phpMyAdmin config.inc.php permission $correct_perm = "0644"; $check_perm = substr(decoct(fileperms("/usr/local/lxlabs/{$program}/httpdocs/thirdparty/phpMyAdmin/config.inc.php")), 2); if ($check_perm != $correct_perm) { lxfile_unix_chmod("/usr/local/lxlabs/{$program}/httpdocs/thirdparty/phpMyAdmin/config.inc.php", "0644"); } // if (lxfile_exists(".svn")) { log_cleanup("- SVN Found... Exiting"); exit; } if ($opt['type'] === 'master') { $sgbl->slave = false; if (!is_secondary_master()) { updateDatabaseProperly(); fixDataBaseIssues(); doUpdates(); lxshell_return("__path_php_path", "../bin/common/driverload.php"); } update_all_slave(); cp_dbfile(); } else { $sgbl->slave = true; } if (!is_secondary_master()) { updatecleanup(); } if ($opt['type'] === 'master') { lxfile_touch("__path_program_start_vps_flag"); } // issue #716 -- [beta] Unresolved dependency on Apache version // --- remove httpd-itk rpm (from webtatic.repo or others) because may conflict with // httpd 2.2.21 that include mpm itk beside mpm worker and event exec("rpm -q httpd-itk | grep -i 'not installed'", $out, $ret); // --- not work with !$ret if ($ret !== 0) { log_cleanup("Remove httpd-itk rpm package"); log_cleanup("- Remove httpd-itk"); exec("rpm -e httpd-itk --nodeps"); exec("rpm -q httpd | grep -i 'not installed'", $out2, $ret2); if ($ret2 === 0) { log_cleanup("- Reinstall httpd"); exec("yum reinstall httpd -y"); } } // MR -- mysql not start after kloxo slave install log_cleanup("Preparing MySQL service"); log_cleanup("- MySQL activated"); exec("chkconfig mysqld on"); log_cleanup("- MySQL restarted"); exec("service mysqld restart"); // MR -- importance for update from 6.1.6 or previous where change apache/lighttpd structure // or others for next version $slist = array("httpd*", "lighttpd*", "bind*", "djbdns*", "pure-ftpd*", "php*", "vpopmail", "courier-imap-toaster", "courier-authlib-toaster", "qmail", "safecat", "spamassassin", "bogofilter", "ezmlm-toaster", "autorespond-toaster", "clamav-toaster"); setUpdateServices($slist); // MR -- use this trick for qmail non-daemontools based log_cleanup("Preparing some services again"); log_cleanup("- courier-imap enabled and restart queue"); exec("chkconfig courier-imap on"); createRestartFile("courier-imap"); log_cleanup("- qmail enabled and restart queue"); exec("chkconfig qmail on"); createRestartFile("qmail"); $fixapps = array("dns", "web", "php", "mail", "ftpuser", "vpop"); setUpdateConfigWithVersionCheck($fixapps, $opt['type']); // --- for anticipate change xinetd listing exec("service xinetd restart"); }
function call_with_flag($func) { $file = "__path_program_etc/flag/{$func}.flg"; if (lxfile_exists($file)) { return; } call_user_func($func); lxfile_touch($file); }
function lxshell_zip_core($updateflag, $dir, $zipname, $filelist) { $dir = expand_real_root($dir); foreach ($filelist as &$__f) { $__f = expand_real_root($__f); } $zipname = expand_real_root($zipname); $files = null; if ($filelist) { foreach ($filelist as &$__nf) { $__nf = "'{$__nf}'"; } $files = implode(" ", $filelist); } if ($updateflag === 'zipadd') { $command = "zip -y -rq -u"; } else { if ($updateflag === 'zip') { $command = "zip -y -rq"; } else { if ($updateflag === 'tar') { $command = "tar -cf"; } else { $command = "tar -czf"; } } } if ($zipname[0] !== '/') { $fullpath = getcwd() . "/{$zipname}"; } else { $fullpath = $zipname; } if (!$files) { lxfile_touch("{$dir}/lxblank_file"); $files = "'lxblank_file'"; } print_time("zipfile"); $fcmd = "{$command} {$fullpath} {$files}"; $fcmd = str_replace(";", "", $fcmd); do_exec_system("__system__", $dir, "nice -n 15 {$fcmd}", $out, $err, $ret, null); print_time("zipfile", "Ziptook"); return $ret; }
function top_level_network_backup() { $bc = $this->do_backup(); if (!count($bc[1])) { $bc[1][] = 'blank_file'; lxfile_touch("{$bc[0]}/blank_file"); } if ($this->main->getZiptype() === 'zip') { $res = zip_to_fileserv($bc[0], $bc[1]); } else { if ($this->main->getZiptype() === 'tar') { $res = tar_to_fileserv($bc[0], $bc[1]); } else { $res = tgz_to_fileserv($bc[0], $bc[1]); } } $this->do_backup_cleanup($bc); return $res; }
function updatecleanup_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; $program = $sgbl->__var_program_name; $opt = parse_opt($argv); if ($opt['type'] === 'master') { initProgram('admin'); $flg = "__path_program_start_vps_flag"; if (!lxfile_exists($flg)) { set_login_skin_to_feather(); } } else { $login = new Client(null, null, 'update'); } log_cleanup("*** Executing Update (cleanup) - BEGIN ***"); // Do things that is needed before the cleanup starts. print "########################################\n"; print "## Executing PreCleanup ##\n"; print "########################################\n"; doBeforeUpdate(); print "########################################\n"; print "## Finished PreCleanup ##\n"; print "########################################\n"; if (lxfile_exists('.git')) { log_cleanup('- Development found!'); } if ($opt['type'] === 'master') { $sgbl->slave = false; if (!is_secondary_master()) { updateDatabaseProperly(); fixDataBaseIssues(); doUpdates(); lxshell_return("__path_php_path", "../bin/common/driverload.php"); } update_all_slave(); cp_dbfile(); } else { $sgbl->slave = true; } if (!is_secondary_master()) { updatecleanup(); } if ($opt['type'] === 'master') { lxfile_touch("__path_program_start_vps_flag"); } // issue #716 -- [beta] Unresolved dependency on Apache version // --- remove httpd-itk rpm (from webtatic.repo or others) because may conflict with // httpd 2.2.21 that include mpm itk beside mpm worker and event exec("rpm -q httpd-itk | grep -i 'not installed'", $out, $ret); // --- not work with !$ret if ($ret !== 0) { log_cleanup("Remove httpd-itk rpm package"); log_cleanup("- Remove httpd-itk"); exec("rpm -e httpd-itk --nodeps"); exec("rpm -q httpd | grep -i 'not installed'", $out2, $ret2); if ($ret2 === 0) { log_cleanup("- Reinstall httpd"); exec("yum reinstall httpd -y"); } } // MR -- mysql not start after kloxo slave install log_cleanup("Preparing MySQL service"); log_cleanup("- MySQL activated"); exec("chkconfig mysqld on"); log_cleanup("- MySQL restarted"); exec("service mysqld restart"); // MR -- importance for update from 6.1.6 or previous where change apache/lighttpd structure // or others for next version $slist = array("httpd*", "lighttpd*", "bind*", "djbdns*", "pure-ftpd*", "php*", "vpopmail", "courier-imap-toaster", "courier-authlib-toaster", "qmail", "safecat", "spamassassin", "bogofilter", "ezmlm-toaster", "autorespond-toaster", "clamav-toaster"); setUpdateServices($slist); // MR -- use this trick for qmail non-daemontools based log_cleanup("Preparing some services again"); log_cleanup("- courier-imap enabled and restart queue"); exec("chkconfig courier-imap on"); createRestartFile("courier-imap"); log_cleanup("- qmail enabled and restart queue"); exec("chkconfig qmail on"); createRestartFile("qmail"); $fixapps = array("dns", "web", "php", "mail", "ftpuser", "vpop"); setUpdateConfigWithVersionCheck($fixapps, $opt['type']); // --- for anticipate change xinetd listing exec("service xinetd restart"); }
<?php include_once "htmllib/lib/include.php"; $flg = "__path_program_root/etc/flag/start_vps.flg"; lxfile_touch($flg);
function getDav() { global $gbl, $sgbl, $login, $ghtml; $string = null; $bdir = "/home/httpd/{$this->main->nname}/__webdav"; lxfile_mkdir($bdir); foreach ($this->main->__var_davuser as $k => $v) { $file = get_file_from_path($k); $dbf = "/tmp/{$file}.db"; $file = "{$bdir}/{$file}"; lxfile_touch($file); $string .= "\$HTTP[\"url\"] =~ \"^{$k}(\$|/)\" {\n"; $string .= "webdav.activate = \"enable\"\n"; $string .= "webdav.is-readonly = \"disable\"\n"; $string .= "auth.backend = \"htpasswd\"\n"; $string .= "auth.backend.htpasswd.userfile = \"{$file}\"\n"; $string .= "webdav.sqlite-db-name = \"{$dbf}\"\n"; $string .= "auth.require = ( \"\" => ( \"method\" => \"basic\",\n"; $string .= "\"realm\" => \"webdav\",\n"; $string .= "\"require\" => \"valid-user\" ) )\n"; $string .= "}\n"; } return $string; }
function setInitialBind() { log_cleanup("Initialize Kloxo bind config files"); if (!lxfile_exists("/var/named/chroot/etc/kloxo.named.conf")) { log_cleanup("- Initialize process"); lxfile_touch("/var/named/chroot/etc/kloxo.named.conf"); lxfile_touch("/var/named/chroot/etc/global.options.named.conf"); } else { log_cleanup("- No need to initialize"); } }
function setInitialBind() { log_cleanup("Initialize Kloxo bind config files"); $pattern = 'include "/etc/global.options.named.conf";'; $file = "/var/named/chroot/etc/named.conf"; $comment = "//Kloxo global config (stop being open recursors)"; addLineIfNotExist($file, $pattern, $comment); if (!lxfile_exists("/var/named/chroot/etc/kloxo.named.conf")) { log_cleanup("- Initialize process"); lxfile_touch("/var/named/chroot/etc/kloxo.named.conf"); lxfile_touch("/var/named/chroot/etc/global.options.named.conf"); } else { log_cleanup("- No need to initialize"); } }