function updateApplicableToSlaveToo() { global $gbl, $sgbl, $login, $ghtml, $osversion; print "Download 3rdparty\n"; // Fixes #303 and #304 download_thirdparty(); print "Installing binaries\n"; lxfile_cp("__path_program_root/cexe/lxxen", "/usr/bin"); lxfile_cp("__path_program_root/cexe/lxopenvz", "/usr/bin"); print "Fixing binaries permissions\n"; lxfile_generic_chmod("/usr/bin/lxopenvz", "6755"); lxfile_generic_chmod("/usr/bin/lxxen", "6755"); print "Install missing rpm packages if any"; install_if_package_not_exist("rrdtool"); print "-rrdtool-"; install_if_package_not_exist("ntfsprogs"); print "-ntfsprogs-"; install_if_package_not_exist("parted"); print "-parted-"; install_if_package_not_exist("kpartx"); print "-kpartx-"; install_if_package_not_exist("dhcp"); print "-dhcp-"; install_if_package_not_exist("openssl"); print "-openssl-"; install_if_package_not_exist("openssl-devel"); print "-openssl-devel-\n"; system("chkconfig dhcpd on"); print "Enable dhcpd at system startup\n"; if (lxfile_exists("/etc/xen")) { lxfile_mkdir("/etc/xen/hypervm"); if (!lxfile_exists("/boot/hypervm-xen-vmlinuz")) { system("cd /boot ; ln -sf vmlinuz-2.6-xen hypervm-xen-vmlinuz; ln -sf initrd-2.6-xen.img hypervm-xen-initrd.img"); } $list = lscandir_without_dot("/etc/xen/auto"); foreach ($list as $l) { $dir = strtil($l, ".cfg"); lunlink("/etc/xen/auto/{$l}"); if (lxfile_exists("/home/xen/{$dir}/{$l}")) { lxfile_symlink("/home/xen/{$dir}/{$l}", "/etc/xen/auto/{$l}"); } } } if (lxfile_exists("/var/log/loadvg.log")) { lunlink("/var/log/loadvg.log"); } if (lxfile_exists("/etc/vz")) { lxfile_cp("__path_program_root/file/sysfile/openvz/ve-vps.basic.conf-sample", "/etc/vz/conf"); print "Set NEIGHBOUR_DEVS=all to vz.conf\n"; vps__openvz::staticChangeConf("/etc/vz/vz.conf", "NEIGHBOUR_DEVS", "all"); } print "Fixing openvz repo\n"; // add openvz.repo lxfile_cp("../file/openvz.repo", "/etc/yum.repos.d/openvz.repo"); print "Fixing lxcenter repo\n"; // add lxcenter.repo $osversion = find_os_version(); print "- Your OS {$osversion}\n"; $cont = our_file_get_contents("../file/lxcenter.repo"); $cont = str_replace("%distro%", $osversion, $cont); our_file_put_contents("/etc/yum.repos.d/lxcenter.repo", $cont); print "Fix RHN\n"; fix_rhn_sources_file(); print "Fix ipconntrack\n"; fix_ipconntrack(); if (lxfile_exists("/home/hypervm/xen/template")) { print "Check Xen windows-lxblank.img template\n"; system("echo hypervm-windows > /home/hypervm/xen/template/windows-lxblank.img"); } print "Fix memory graph\n"; memoryGraphFix(); print "Fix permission of closeallinput\n"; lxfile_unix_chmod("../cexe/closeallinput", "0755"); print "Fix LxEtc\n"; installLxetc(); print "Check binaries\n"; system("cp ../sbin/lxrestart /usr/sbin/"); system("chown root:root /usr/sbin/lxrestart"); system("chmod 755 /usr/sbin/lxrestart"); system("chmod ug+s /usr/sbin/lxrestart"); system("chmod 777 /tmp"); system("chmod o+t /tmp"); print "Create script dir\n"; copy_script(); if (!lxfile_exists("/usr/local/lxlabs/kloxo/")) { print "Remove /usr/local/lxlabs/kloxo/ as it should not be here!\n"; system("rmdir /usr/local/lxlabs/kloxo/httpdocs/ >/dev/null 2>&1"); system("rmdir /usr/local/lxlabs/kloxo/ >/dev/null 2>&1"); } if (!lxfile_exists("/var/named/chroot/etc/kloxo.named.conf")) { if (lxfile_exists("/var/named/chroot/etc/lxadmin.named.conf")) { remove_line("/var/named/chroot/etc/named.conf", "lxadmin.named.conf"); $pattern = 'include "/etc/kloxo.named.conf";'; $file = "/var/named/chroot/etc/named.conf"; $comment = "//Kloxo"; @addLineIfNotExistInside($file, $pattern, $comment); @lxfile_mv("/var/named/chroot/etc/lxadmin.named.conf", "/var/named/chroot/etc/kloxo.named.conf"); } } }
function fix_network_forwarding() { $list = file("/etc/sysctl.conf"); foreach ($list as $__l) { if (strstr($__l, "net.ipv4.ip_forward") !== false) { $newlist[] = "net.ipv4.ip_forward = 1\n"; } else { $newlist[] = $__l; } } our_file_put_contents("/etc/sysctl.conf", implode("", $newlist)); shell_exec("sysctl -p"); }
function install_yum_repo($osversion) { if (!file_exists("/etc/yum.repos.d")) { print "No yum.repos.d dir detected!\n"; return; } if (file_exists("/etc/yum.repos.d/lxcenter.repo")) { print "LxCenter yum repository file already present.\n"; return; } $cont = our_file_get_contents("../lxcenter.repo.template"); $cont = str_replace("%distro%", $osversion, $cont); our_file_put_contents("/etc/yum.repos.d/lxcenter.repo", $cont); }
function install_yum_repo($osversion) { if (!file_exists("/etc/yum.repos.d")) { return; } $cont = our_file_get_contents("../lxcenter.repo.template"); $cont = str_replace("%distro%", $osversion, $cont); our_file_put_contents("/etc/yum.repos.d/lxcenter.repo", $cont); if ($osversion === 'centos-4') { //system("cp ../CentOS-Base.repo /etc/yum.repos.d/"); } }
function lxins_main() { global $argv, $downloadserver; $opt = parse_opt($argv); $dir_name = dirname(__FILE__); $installtype = $opt['install-type']; $dbroot = isset($opt['db-rootuser']) ? $opt['db-rootuser'] : "******"; $dbpass = isset($opt['db-rootpassword']) ? $opt['db-rootpassword'] : ""; $osversion = find_os_version(); $arch = `arch`; $arch = trim($arch); if (!char_search_beg($osversion, "centos") && !char_search_beg($osversion, "rhel")) { print "Kloxo is only supported on CentOS 5 and RHEL 5\n"; exit; } if (file_exists("/usr/local/lxlabs/kloxo")) { // Ask Reinstall if (get_yes_no("Kloxo seems already installed do you wish to continue?") == 'n') { print "Installation Aborted.\n"; exit; } } else { // Ask License if (get_yes_no("Kloxo is using AGPL-V3.0 License, do you agree with the terms?") == 'n') { print "You did not agree to the AGPL-V3.0 license terms.\n"; print "Installation aborted.\n\n"; exit; } else { print "Installing Kloxo = YES\n\n"; } } // Ask for InstallApp print "InstallApp: PHP Applications like PHPBB, WordPress, Joomla etc\n"; print "When you choose Yes, be aware of downloading about 350Mb of data!\n"; if (get_yes_no("Do you want to install the InstallAPP sotfware?") == 'n') { print "Installing InstallApp = NO\n"; print "You can install it later with /script/installapp-update\n\n"; $installappinst = false; } else { print "Installing InstallApp = YES\n\n"; $installappinst = true; } print "Adding System users and groups (nouser, nogroup and lxlabs, lxlabs)\n"; system("groupadd nogroup"); system("useradd nouser -g nogroup -s '/sbin/nologin'"); system("groupadd lxlabs"); system("useradd lxlabs -g lxlabs -s '/sbin/nologin'"); print "Installing LxCenter yum repository for updates\n"; install_yum_repo($osversion); $packages = array("sendmail", "sendmail-cf", "sendmail-doc", "sendmail-devel", "exim", "vsftpd", "postfix", "vpopmail", "qmail", "lxphp", "lxzend", "pure-ftpd", "imap"); $list = implode(" ", $packages); print "Removing packages {$list}...\n"; foreach ($packages as $package) { exec("rpm -e --nodeps {$package} > /dev/null 2>&1"); } $packages = array("php-mbstring", "php-mysql", "which", "gcc-c++", "php-imap", "php-pear", "php-devel", "lxlighttpd", "httpd", "mod_ssl", "zip", "unzip", "lxphp", "lxzend", "mysql", "mysql-server", "curl", "autoconf", "automake", "libtool", "bogofilter", "gcc", "cpp", "openssl", "pure-ftpd", "yum-protectbase"); $list = implode(" ", $packages); while (true) { print "Installing packages {$list}...\n"; system("PATH=\$PATH:/usr/sbin yum -y install {$list}", $return_value); if (file_exists("/usr/local/lxlabs/ext/php/php")) { break; } else { print "Yum Gave Error... Trying Again...\n"; } } print "Prepare installation directory\n"; system("mkdir -p /usr/local/lxlabs/kloxo"); chdir("/usr/local/lxlabs/kloxo"); system("mkdir -p /usr/local/lxlabs/kloxo/log"); @unlink("kloxo-current.zip"); print "Downloading latest Kloxo release\n"; system("wget " . $downloadserver . "download/kloxo/production/kloxo/kloxo-current.zip"); print "\n\nInstalling Kloxo.....\n\n"; system("unzip -oq kloxo-current.zip", $return); if ($return) { print "Unzipping the core Failed.. Most likely it is corrupted. Report it at http://forum.lxcenter.org/\n"; exit; } unlink("kloxo-current.zip"); system("chown -R lxlabs:lxlabs /usr/local/lxlabs/"); chdir("/usr/local/lxlabs/kloxo/httpdocs/"); system("service mysqld start"); if ($installtype !== 'slave') { check_default_mysql($dbroot, $dbpass); } $mypass = password_gen(); print "Prepare defaults and configurations...\n"; system("/usr/local/lxlabs/ext/php/php {$dir_name}/installall.php"); our_file_put_contents("/etc/sysconfig/spamassassin", "SPAMDOPTIONS=\" -v -d -p 783 -u lxpopuser\""); print "Creating Vpopmail database...\n"; system("sh {$dir_name}/vpop.sh {$dbroot} \"{$dbpass}\" lxpopuser {$mypass}"); system("chmod -R 755 /var/log/httpd/"); system("chmod -R 755 /var/log/httpd/fpcgisock >/dev/null 2>&1"); system("mkdir -p /var/log/kloxo/"); system("mkdir -p /var/log/news"); system("ln -sf /var/qmail/bin/sendmail /usr/sbin/sendmail"); system("ln -sf /var/qmail/bin/sendmail /usr/lib/sendmail"); system("echo `hostname` > /var/qmail/control/me"); system("service qmail restart >/dev/null 2>&1 &"); system("service courier-imap restart >/dev/null 2>&1 &"); $dbfile = "/home/kloxo/httpd/webmail/horde/scripts/sql/create.mysql.sql"; if (file_exists($dbfile)) { if ($dbpass == "") { system("mysql -u {$dbroot} <{$dbfile}"); } else { system("mysql -u {$dbroot} -p{$dbpass} <{$dbfile}"); } } system("mkdir -p /home/kloxo/httpd"); chdir("/home/kloxo/httpd"); @unlink("skeleton-disable.zip"); system("chown -R lxlabs:lxlabs /home/kloxo/httpd"); system("/etc/init.d/kloxo restart >/dev/null 2>&1 &"); chdir("/usr/local/lxlabs/kloxo/httpdocs/"); system("/usr/local/lxlabs/ext/php/php /usr/local/lxlabs/kloxo/bin/install/create.php --install-type={$installtype} --db-rootuser={$dbroot} --db-rootpassword={$dbpass}"); system("/usr/local/lxlabs/ext/php/php /usr/local/lxlabs/kloxo/bin/misc/secure-webmail-mysql.phps"); system("/bin/rm /usr/local/lxlabs/kloxo/bin/misc/secure-webmail-mysql.phps"); system("/script/centos5-postpostupgrade"); if ($installappinst) { system("/script/installapp-update"); // First run (gets installappdata) system("/script/installapp-update"); // Second run (gets applications) } print "Congratulations. Kloxo has been installed succesfully on your server as {$installtype} \n"; if ($installtype === 'master') { print "You can connect to the server at https://<ip-address>:7777 or http://<ip-address>:7778\n"; print "Please note that first is secure ssl connection, while the second is normal one.\n"; print "The login and password are 'admin' 'admin'. After Logging in, you will have to change your password to something more secure\n"; print "We hope you will find managing your hosting with Kloxo refreshingly pleasurable, and also we wish you all the success on your hosting venture\n"; print "Thanks for choosing Kloxo to manage your hosting, and allowing us to be of service\n"; } else { print "You should open the port 7779 on this server, since this is used for the communication between master and slave\n"; print "To access this slave, to go admin->servers->add server, give the ip/machine name of this server. The password is 'admin'. The slave will appear in the list of slaves, and you can access it just like you access localhost\n\n"; } }
function install_yum_repo($osversion) { if (!file_exists("/etc/yum.repos.d")) { return; } if (!file_exists("../lxcenter.repo.template")) { $cont = our_file_get_contents("../hypervm-linux/lxcenter.repo.template"); } else { $cont = our_file_get_contents("../lxcenter.repo.template"); } $cont = str_replace("%distro%", $osversion, $cont); our_file_put_contents("/etc/yum.repos.d/lxcenter.repo", $cont); }