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(); }
static function getweb_usage($name, $customer_name, $oldtime, $newtime, $d) { global $gbl, $sgbl, $login, $ghtml; $web_home = "{$sgbl->__path_httpd_root}"; $log_path = "{$web_home}/{$name}/stats"; $processeddir = "{$sgbl->__path_customer_root}/{$customer_name}/__processed_stats/"; lxfile_mkdir($processeddir); lxfile_generic_chown($processeddir, $customer_name); $dir1 = "{$log_path}/"; $files = lscandir_without_dot($dir1); $total = 0; foreach ($files as $file) { if (!strstr($file, "gz")) { $total += self::getEachwebfilequota("{$dir1}/{$file}", $oldtime, $newtime); $stat = stat("{$dir1}/{$file}"); if ($stat['size'] >= 50 * 1024 * 1024) { if (isOn($d->remove_processed_stats)) { lxfile_rm("{$dir1}/{$file}"); } else { $fname = getNotexistingFile($processeddir, $file); lxfile_mv("{$dir1}/{$file}", $fname); lxfile_generic_chown($fname, $customer_name); } } } } return $total; }
static function MakeSureDirectoryExists($name) { if (!lxfile_exists($name)) { lxfile_mkdir($name); lxfile_generic_chown($name, "lxlabs"); } }
static function moveToTrash($user, $root, $name) { $trashcont = "{$root}/.trash/.__trash_" . basename($name); $fullpath = "{$root}/{$name}"; lxfile_rm_rec("{$root}/.trash/" . basename($name)); lxfile_rm_rec($trashcont); $res = lxfile_mkdir("{$root}/.trash/"); lxfile_generic_chown("{$root}/.trash", $user); lfile_put_contents($trashcont, $name . "\n"); $res = new_process_mv_rec($user, $fullpath, "{$root}/.trash"); //unlink($f); }
function add_admin($pass) { global $gbl, $sgbl, $login, $ghtml; $client = new Client(null, null, 'admin'); $login = $client; $client->initThisDef(); $client->priv->pserver_num = 'Unlimited'; $client->priv->maindomain_num = 'Unlimited'; $client->priv->vps_num = 'Unlimited'; $client->priv->client_num = 'Unlimited'; $client->ddate = time(); $ddb = new Sqlite(null, "client"); if (!$ddb->existInTable("nname", 'admin')) { if ($sgbl->dbg > 0) { $pass = '******'; $res['contacemail'] = '*****@*****.**'; } $res['password'] = crypt($pass); $res['cttype'] = 'admin'; $res['cpstatus'] = 'on'; if (if_demo()) { $res['email'] = "*****@*****.**"; } $client->create($res); $client->driverApp = new client__sync(null, null, 'admin'); $client->was(); lxfile_mkdir("__path_client_root/{$client->nname}"); lxfile_generic_chown("__path_client_root/{$client->nname}", "lxlabs"); } $notif = new Notification(null, null, $client->getClName()); $notif->initThisDef(); $notif->dbaction = 'add'; $notif->text_newaccountmessage = lfile_get_contents("__path_program_root/file/welcome.txt"); $notif->parent_clname = $client->getClName(); $notif->write(); $display = new sp_SpecialPlay(null, null, $client->getClName()); $display->initThisDef(); $display->parent_clname = $client->getClName(); $display->dbaction = 'add'; $display->write(); }
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; } // --- 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}/user_prefs"; $prefpath = "{$mailpath}/{$user}/user_prefs"; } else { return; } if (!lxfile_exists(dirname($prefpath))) { lxfile_mkdir(dirname($prefpath)); lxfile_generic_chown(dirname($prefpath), "lxpopuser:lxpopgroup"); } $fdata = null; $fdata .= "required_score " . $this->main->spam_hit . "\n"; $fdata .= "ok_locales all\n"; $fdata .= "rewrite_header Subject {$this->main->subject_tag}\n"; foreach ((array) $this->main->wlist_a as $wlist) { $fdata .= "whitelist_from " . $wlist->nname . "\n"; } $fdata .= "#***********************************\n"; foreach ((array) $this->main->blist_a as $blist) { $fdata .= "blocklist_from " . $blist->nname . "\n"; } lxfile_rm($prefpath); lfile_write_content($prefpath, $fdata, "lxpopuser:lxpopgroup"); }
function checkRestart() { if (if_demo()) { return; } $res = lscandir_without_dot("__path_program_etc/.restart"); if ($res === false) { dprint(".restart does not exist... Creating\n"); lxfile_mkdir("__path_program_etc/.restart"); lxfile_generic_chown("__path_program_etc/.restart", "lxlabs"); } foreach ((array) $res as $r) { if (csb($r, "._restart_")) { $cmd = strfrom($r, "._restart_"); } lunlink("__path_program_etc/.restart/{$r}"); dprint("Restarting {$cmd}\n"); // THe 3,4 etc are the tcp ports of this program, and it should be closed, else some programs will grab it. //exec("/etc/init.d/$cmd restart </dev/null >/dev/null 2>&1 3</dev/null 4</dev/null 5</dev/null 6</dev/null &"); switch ($cmd) { case 'lxcollectquota': exec_justdb_collectquota(); break; case 'openvz_tc': exec_openvz_tc(); break; default: exec_with_all_closed("/etc/init.d/{$cmd} restart"); break; } } }
} } 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 getAndUnzipSkeleton($ip, $filepass, $dir) { $oldir = getcwd(); // File may be a variable path. dprintr($filepass); $file = $filepass['file']; // The thing is this needs to be executed even on secondary master and then the primary master would be down. // So if we cannot connect back, we just continue. Skeleton is not an important thing. try { getFromFileserv($ip, $filepass, "{$dir}/{$file}"); } catch (exception $e) { return; } lxfile_generic_chown("{$dir}/{$file}", $this->username); lxshell_unzip($this->username, $dir, "{$dir}/{$file}"); lunlink("{$dir}/{$file}"); $this->replaceVariables("{$dir}/index.html"); // --- also copy /home/kloxo/httpd/user-logo.png to each domain path if (lxfile_exists("../file/user-logo.png")) { lxfile_cp("../file/user-logo.png", "{$dir}/images/logo.png"); } }
/** * Writes a string to a file * * @param string $username file owner * @param string $file path to the file * @param mixed $data the data to write * @param int $flag */ function lxuser_put_contents($username, $file, $data, $flag = 0) { $file = expand_real_root($file); dprint("Debug: filename is: " . $file . "\n"); if (is_soft_or_hardlink($file)) { log_log("link_error", "{$file} is hard or symlink. Not writing\n"); return false; } if (!lxuser_mkdir($username, dirname($file))) { return false; } if ($flag == FILE_APPEND) { $mode = 'a'; } else { $mode = 'w'; } $f = fopen($file, $mode); if (!$f) { return false; } else { if (flock($f, LOCK_EX)) { $bytes = fwrite($f, $data); lxfile_generic_chown($file, $username); flock($f, LOCK_UN); fclose($f); return $bytes; } else { return false; } } }
function checkRestart() { if (if_demo()) { return; } log_log("cron_exec", "Check service restarts...\n"); $res = lscandir_without_dot("__path_program_etc/.restart"); if ($res === false) { dprint(".restart does not exist... Creating\n"); lxfile_mkdir("__path_program_etc/.restart"); lxfile_generic_chown("__path_program_etc/.restart", "lxlabs"); } foreach ((array) $res as $r) { if (csb($r, "._restart_")) { $cmd = strfrom($r, "._restart_"); } lunlink("__path_program_etc/.restart/{$r}"); dprint("Restarting {$cmd}\n"); switch ($cmd) { case 'lxcollectquota': log_log("cron_exec", "Start collecting Quota's\n"); exec_justdb_collectquota(); break; case 'openvz_tc': log_log("cron_exec", "Start openvz_tc script\n"); exec_openvz_tc(); break; default: log_log("cron_exec", "Restarting {$cmd}\n"); exec_with_all_closed("/etc/init.d/{$cmd} restart"); break; } } }
function checkClusterDiskQuota() { global $gbl, $sgbl, $login, $ghtml; $maclist = $login->getList('pserver'); $mess = null; foreach ($maclist as $mc) { try { rl_exec_get(null, $mc->nname, "remove_old_serve_file", null); } catch (exception $e) { } $driverapp = $gbl->getSyncClass(null, $mc->nname, 'diskusage'); try { $list = rl_exec_get(null, $mc->nname, array("diskusage__{$driverapp}", "getDiskUsage")); } catch (exception $e) { $mess .= "Failed to connect to Slave {$mc->nname}: {$e->getMessage()}\n"; continue; } foreach ($list as $l) { if (intval($l['pused']) >= 87) { $mess .= "Filesystem {$l['mountedon']} ({$l['nname']}) on {$mc->nname} is using {$l['pused']}%\n"; } } } dprint($mess); dprint("\n"); if ($mess) { lx_mail(null, $login->contactemail, "Filesystem Warning", $mess); } lxfile_generic_chown("..", "lxlabs"); }
function dbactionUpdate($subaction) { global $gbl, $sgbl, $login, $ghtml; if_demo_throw_exception('ffile'); $this->aux = new Ffile__common(null, null, $this->nname); $this->aux->main = $this->main; if ($this->main->isOn('readonly')) { throw new lxexception('file_manager_is_readonly', ''); } $chownug = "{$this->main->__username_o}:{$this->main->__username_o}"; switch ($subaction) { case "fancyedit": case "edit": lxuser_put_contents($chownug, $this->main->getFullPath(), $this->main->content); lxuser_return($chownug, "dos2unix", $this->main->getFullPath()); lxuser_chmod($chownug, $this->main->getFullPath(), "0644"); break; case "upload_s": $filename = $this->aux->uploadDirect(); lxuser_chmod($chownug, $filename, "0644"); lxfile_generic_chown($filename, $chownug); break; case "rename": $this->aux->reName(); break; case "paste": $this->aux->filePaste(); break; case "perm": $arg = null; $perm = $this->main->newperm; $perm = 0 . $perm; if ($this->main->isOn('recursive_f')) { new_process_chmod_rec($this->main->__username_o, $this->main->fullpath, $perm); } else { lxfile_unix_chmod($this->main->fullpath, "{$perm}"); } break; case "newdir": $path = $this->aux->newDir(); lxfile_unix_chown($path, $chownug); break; case "content": if ($this->main->is_image()) { $this->aux->resizeImage(); } else { throw new lxexception('cannot_save_content', ''); } break; case "thumbnail": $this->aux->createThumbnail(); break; case "convert_image": $this->aux->convertImage(); break; case "zip_file": $zipfile = $this->aux->zipFile(); break; case "filedelete": $this->aux->moveAllToTrash(); break; case "filerealdelete": $this->aux->fileRealDelete(); break; case "restore_trash": $this->aux->restoreTrash(); break; case "clear_trash": $this->aux->clearTrash(); break; case "download_from_http": $fullpath = $this->aux->downloadFromHttp(); lxfile_unix_chown($fullpath, $chownug); break; case "download_from_ftp": $fullpath = $this->aux->downloadFromFtp(); lxfile_unix_chown($fullpath, $chownug); break; case "zipextract": $dir = $this->aux->zipExtract(); break; } }
function add_domain_backup_dir() { log_cleanup("Create domain backup dirs"); log_cleanup("- Create process"); // must set this mkdir if want without php warning when cleanup lxfile_mkdir("__path_program_home/domain"); lxfile_generic_chown("__path_program_home/domain", "lxlabs"); if (lxfile_exists("__path_program_home/domain")) { dprint("Domain backupdir exists... returning\n"); return; } $sq = new Sqlite(null, 'domain'); $res = $sq->getTable(array('nname')); foreach ($res as $r) { lxfile_mkdir("__path_program_home/domain/{$r['nname']}/__backup"); lxfile_generic_chown("__path_program_home/domain/{$r['nname']}/", "lxlabs"); lxfile_generic_chown("__path_program_home/domain/{$r['nname']}/__backup", "lxlabs"); } }
function do_restore($docd) { global $gbl, $sgbl, $login, $ghtml; $name = $this->main->getPathFromName('nname'); $fullpath = "{$sgbl->__path_customer_root}/{$name}/"; lxfile_mkdir($fullpath); lxshell_unzip_with_throw($fullpath, $docd); lxfile_generic_chown_rec($fullpath, "{$this->main->username}:{$this->main->username}"); lxfile_generic_chown($fullpath, "{$this->main->username}:apache"); lxfile_generic_chmod($fullpath, "0750"); }