function webChangeOwner() { if (!lxfile_exists("{$this->getFullDocRoot()}")) { lxfile_cp_rec("__path_customer_root/{$this->__var_oldcustomer_name}/{$this->docroot}", "{$this->getFullDocRoot()}"); } lxfile_unix_chown_rec("{$this->getFullDocRoot()}", "{$this->username}:{$this->username}"); lunlink("__path_httpd_root/{$this->nname}/httpdocs"); }
public function setInternalParam($mountpoint) { $name = $this->main->ostemplate; if ($this->main->isWindows()) { return; } if (!$mountpoint) { return; } if ($name === 'unknown') { return; } $name = strtolower($name); $mountpoint = expand_real_root($mountpoint); $result = $this->getScriptS($name); dprint("Distro Name {$name}, Scripts: \n"); dprintr($result); $init = strtilfirst($name, "-"); dprint("File is {$init}.inittab\n"); if (lxfile_exists("../file/sysfile/inittab/{$init}.inittab")) { dprint("Copying {$init}.inittab\n"); $content = lfile_get_contents("../file/sysfile/inittab/{$init}.inittab"); if ($this->main->text_inittab) { $content .= "\n{$this->main->text_inittab}"; } lfile_put_contents("{$mountpoint}/etc/inittab", $content); } $iplist = get_namelist_from_objectlist($this->main->vmipaddress_a); if ($this->main->mainipaddress) { $main_ip = $this->main->mainipaddress; $iplist = array_remove($iplist, $main_ip); } else { $main_ip = array_shift($iplist); } if ($this->main->networknetmask) { $main_netmask = $this->main->networknetmask; } else { $main_netmask = "255.255.255.0"; } $iplist = implode(" ", $iplist); $ipadd = $result['ADD_IP']; $sethostname = $result['SET_HOSTNAME']; $setuserpass = $result['SET_USERPASS']; $ipdel = $result['DEL_IP']; if ($this->main->networkgateway) { $gw = $this->main->networkgateway; } else { $gw = os_get_network_gateway(); } $gwn = strtil($gw, '.') . '.0'; $hostname = $this->main->hostname; if (!$hostname) { $hostname = os_get_hostname(); } if ($result['STARTUP_SCRIPT'] != 'systemd') { $name = createTempDir("{$mountpoint}/tmp", 'xen-scripts'); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $name); $basepath = strfrom($name, $mountpoint); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\nsource /{$basepath}/{$ipdel}\n"); $delipstring = "IPDELALL=yes chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($delipstring); log_shell(system($delipstring, $ret1) . ":return {$ret1}"); putenv("VE_STATE=stopped"); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$ipadd}\n"); $string = "IPDELALL=yes MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string, $ret1) . ":return {$ret1}"); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$sethostname}\n"); $string = "HOSTNM={$hostname} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string, $ret1) . ":return {$ret1}"); if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) { $rootpass = "******"; lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$setuserpass}\n"); $string = "USERPW={$rootpass} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string)); } lxfile_rm_rec($name); } else { if ($result['STARTUP_SCRIPT'] == 'systemd') { $script_dir = createTempDir("{$mountpoint}", "hypervm-runonce"); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $script_dir); $basepath = strfrom($script_dir, $mountpoint); $startupdir = 'lib/systemd/system'; $startupscript = 'fedora-startup.service'; $setrootpass = ''; if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) { $rootpass = "******"; $setrootpass = "******"; } $run_once_script = "#!/bin/bash\n" . "source {$basepath}/functions\n" . '(' . "IPDELALL=yes source {$basepath}/{$ipdel}" . " & IPDELALL=yes VE_STATE=stopped MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} source {$basepath}/{$ipadd}" . " & HOSTNM={$hostname} source {$basepath}/{$sethostname}" . "{$setrootpass})\n" . "service fedora-startup disable\nrm -f /{$startupdir}/{$startupscript}\nrm -rf {$basepath}"; lfile_put_contents("{$script_dir}/hypervm-runonce.sh", $run_once_script); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$startupscript}", "{$mountpoint}/{$startupdir}"); lfile_put_contents("{$mountpoint}/{$startupdir}/{$startupscript}", lfile_get_contents("{$mountpoint}/{$startupdir}/{$startupscript}") . "ExecStart={$basepath}/hypervm-runonce.sh\n"); system("ln -s /lib/systemd/system/fedora-startup.service {$mountpoint}/etc/systemd/system/multi-user.target.wants/fedora-startup.service"); system("chmod 755 {$script_dir}/hypervm-runonce.sh"); } } if ($this->main->nameserver) { $nlist = explode(" ", $this->main->nameserver); $nstring = null; foreach ($nlist as $l) { $nstring .= "nameserver {$l}\n"; } lfile_put_contents("{$mountpoint}/etc/resolv.conf", $nstring); } if ($this->main->timezone) { lxfile_rm("{$mountpoint}/etc/localtime"); $cmdstring = "ln -sf ../usr/share/zoneinfo/{$this->main->timezone} {$mountpoint}/etc/localtime"; log_log("localtime", $cmdstring); do_exec_system('__system__', "/", $cmdstring, $out, $err, $ret, null); //lxfile_cp("/usr/share/zoneinfo/{$this->main->timezone}", "$mountpoint/etc/localtime"); } lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0"); lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0:0"); $this->main->doKloxoInit($mountpoint); }
function fixZshEtc() { return; // TODO: Remove /root/.etc/ global $global_dontlogshell; $global_dontlogshell = true; $dir = os_get_home_dir("root"); if (lxfile_exists("{$dir}/.etc")) { lxfile_cp("htmllib/filecore/lxetc/commands.shell", "{$dir}/.etc/"); return; } $ret = lxshell_return("rpm", "-q", "zsh", "vim-ehhanced"); if ($ret) { system("yum -y install zsh vim-enhanced"); } print "Copy LxEtc\n"; lxfile_cp_rec("htmllib/filecore/lxetc/", "{$dir}/.etc"); }
function lxfile_cp_content($dirsource, $dirdest) { $username = "******"; $dirdest = expand_real_root($dirdest); $dirsource = expand_real_root($dirsource); if (!lxfile_exists($dirdest)) { lxfile_mkdir($dirdest); } $list = lscandir_without_dot($dirsource); foreach ($list as $l) { lxfile_cp_rec("{$dirsource}/{$l}", "{$dirdest}/{$l}"); } }
function cp_rec_if_not_exists($src, $dst) { if (lxfile_exists($dst)) { return; } if (!lxfile_exists($src)) { return; } lxfile_cp_rec($src, $dst); }
function dbactionUpdate($subaction) { if_demo_throw_exception('ffile'); if ($this->main->isOn('readonly')) { throw new lxexception('file_manager_is_readonly', ''); } switch ($subaction) { case "edit": lfile_put_contents($this->main->getFullPath(), $this->main->content); break; case "upload": $filename = $this->main->getFullPath() . "/{$this->main->upload_file_name}"; dprintr($this->main->upload_overwrite_f); if (!$this->main->isOn('upload_overwrite_f')) { if (lfile_exists($filename)) { throw new lxexception('file_exists_upload', 'upload_name_f'); } } getFromFileserv($this->main->__var_upload_tmp_server, $this->main->__var_upload_filepass, $filename); break; case "rename": $directory = dirname($this->main->fullpath); $new = $directory . "/" . $this->main->newname; if (lfile_exists($new)) { throw new lxexception('file_exists_rename', ''); } lxfile_mv_rec($this->main->fullpath, $new); //lxfile_unix_chown($new, $this->main->__username_o); break; case "paste": if ($this->main->paste_list) { // Hack... SPecifically checking for pasteaction. Should just use it directly in the command. $arglist[] = $this->main->__username_o; foreach ($this->main->paste_list as &$_tl) { $_tl = $this->main->root . $_tl; } //$arglist = array_merge($arglist, $this->main->paste_list); $arglist[] = $this->main->paste_list; $arglist[] = $this->main->fullpath; if ($this->main->pasteaction === 'copy') { foreach ($this->main->paste_list as $p) { lxfile_cp_rec($p, $this->main->fullpath); } } else { foreach ($this->main->paste_list as $p) { lxfile_mv_rec($p, $this->main->fullpath); } } //lxfile_unix_chown_rec($this->main->fullpath, $this->main->__username_o); } break; case "perm": throw new lxexception('no_perm_setting', ''); break; case "newdir": $i = 1; $rpath = $this->main->fullpath; $name = "/" . $this->main->newfolder_f; $path = $rpath . $name; if (lxfile_exists($path)) { throw new lxexception('file_exists', ''); } lxfile_mkdir($path); break; case "zip_file": foreach ($this->main->zip_file_list as &$_t_f) { $_t_f = coreFfile::removeLeadingSlash($_t_f); $_t_f = basename($_t_f); $_t_f = "\"{$_t_f}\""; } $list = implode(" ", $this->main->zip_file_list); $oldir = getcwd(); $fullpath = expand_real_root($this->main->fullpath); do_exec_system($this->main->__username_o, $fullpath, "c:/Progra~1/7-Zip/7z a NewArchive.zip {$list}", $out, $err, $ret, null); break; case "filedelete": foreach ($this->main->filedelete_list as $f) { ffile__common::moveToTrash($this->main->root, $f); } break; case "restore_trash": foreach ($this->main->restore_trash_list as $f) { ffile__common::restoreFromTrash($this->main->root, $f); } break; case "clear_trash": foreach ($this->main->clear_trash_list as $f) { ffile__common::clearFromTrash($this->main->root, $f); } break; case "zipextract": $fulzippath = $this->main->root . $this->main->zip_extract_dir_f; if (!lxfile_exists(null, $fulzippath)) { lxfile_mkdir($fulzippath); } else { $zipdir = new Ffile("localhost", "localhost", $this->main->root, $this->main->zip_extract_dir_f, $this->main->__username_o); $zipdir->get(); if (!$zipdir->is_dir()) { throw new lxexception("file_exists_but_not_dir", 'unzippath', $this->main->zip_extract_dir_f); } } $command = "c:/Progra~1/7-zip/7z x -y"; $dir = expand_real_root($fulzippath); $file = expand_real_root($this->main->getFullPath()); if (!csa($file, ":")) { $fullpath = getcwd() . "/{$file}"; } else { $fullpath = $file; } $oldir = getcwd(); $fullpath = expand_real_root($fullpath); do_exec_system($this->main->__username_o, $dir, "{$command} {$fullpath}", $out, $err, $ret, null); break; } }
function installChooser() { log_cleanup("Install Webmail chooser"); log_cleanup("- Install process"); $path = "/home/kloxo/httpd/webmail/"; lxfile_mkdir("/home/kloxo/httpd/webmail/img"); lxfile_cp_rec("../file/webmail-chooser/header/", "/home/kloxo/httpd/webmail/img"); lxfile_cp("../file/webmail-chooser/roundcube-config.phps", "/home/kloxo/httpd/webmail/roundcube/config/main.inc.php"); $list = array("horde", "roundcube"); foreach ($list as $l) { lfile_put_contents("{$path}/redirect-to-{$l}.php", "<?php\nheader(\"Location: /{$l}\");\n"); } lfile_put_contents("{$path}/disabled/index.html", "Disabled\n"); }
exit; } } lxshell_return("service", "lxadmin", "stop"); lxshell_return("chkconfig", "lxadmin", "off"); lxfile_rm("/etc/init.d/lxadmin"); lxfile_mkdir("/usr/local/lxlabs/kloxo"); chdir("/usr/local/lxlabs/kloxo/"); lxfile_rm("kloxo-current.zip"); system("wget http://download.lxcenter.org/download/kloxo/production/kloxo/kloxo-current.zip"); system("unzip -oq kloxo-current.zip"); lxfile_rm_rec("/usr/local/lxlabs/kloxo/etc/"); lxfile_cp_rec("/usr/local/lxlabs/lxadmin/etc/", "/usr/local/lxlabs/kloxo/etc/"); if (!$sgbl->is_this_slave()) { system("service mysqld stop"); if (!lxfile_exists("/var/lib/mysql/kloxo/")) { lxfile_cp_rec("/var/lib/mysql/lxadmin4_2", "/var/lib/mysql/kloxo"); } lxfile_unix_chown_rec("/var/lib/mysql/kloxo", "mysql:mysql"); system("service mysqld start"); sleep(10); chdir("/usr/local/lxlabs/lxadmin/httpdocs/"); passthru("lphp.exe ../bin/kloxo-db.php"); } lxfile_cp("/usr/local/lxlabs/kloxo/httpdocs/htmllib/filecore/init.program", "/etc/init.d/kloxo"); lxfile_cp("/usr/local/lxlabs/lxadmin/etc/conf/lxadmin.pass", "/usr/local/lxlabs/kloxo/etc/conf/kloxo.pass"); lxfile_unix_chmod("/etc/init.d/kloxo", "0755"); lxshell_return("chkconfig", "kloxo", "on"); chdir("/usr/local/lxlabs/kloxo/httpdocs/"); passthru("lphp.exe ../bin/kloxo-migrate.php"); print "\n\n\nMigration to Kloxo Succesful. Please reboot the server for everything to take effect.\n\n";