function cyrus_paritition_default_path() { $unix = new unix(); echo "<articadatascgi>" . base64_encode($unix->IMAPD_GET("partition-default")) . "</articadatascgi>"; }
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $unix = new unix(); if ($unix->process_exists(@file_get_contents($pidfile))) { echo "Process already exists...\n"; die; } @file_put_contents($pidfile, getmypid()); $t1 = time(); $time = date('Y-m-d') . "_" . date('h:i'); $ini = new Bs_IniHandler(); $ini->loadFile("/etc/artica-postfix/settings/Daemons/CyrusAVConfig"); $nice = EXEC_NICE(); $clamscan = $unix->find_program("clamscan"); if (!is_file($clamscan)) { die; } $partition_default = $unix->IMAPD_GET("partition-default"); if (!is_dir($partition_default)) { send_email_events("Mailboxes antivirus scanning failed", "partition-default: \"{$partition_default}\"\nno such directory", "mailbox"); echo "partition-default: no such directory\n"; die; } @mkdir("/var/log/artica-postfix/antivirus/cyrus-imap", 0755, true); $time = date('Y-m-d') . "_" . date('h:I'); $cmd = "{$nice} /usr/bin/clamscan --recursive=yes --infected "; $cmd = $cmd . "--max-filesize=10M --max-scansize=10M --max-recursion=5 --max-dir-recursion=10 "; $cmd = $cmd . "--log=/log/artica-postfix/antivirus/cyrus-imap/{$time}.scan {$partition_default}"; shell_exec($cmd); $t2 = time(); $time_duration = distanceOfTimeInWords($t1, $t2); send_email_events("Mailboxes antivirus scan terminated: {$time_duration}", @file_get_contents("/log/artica-postfix/antivirus/cyrus-imap/{$time}.scan"), "mailbox");
function restorembx($basedContent) { $GLOBALS["ONNLY_MOUNT"] = true; $unix = new unix(); $rsync = $unix->find_program("rsync"); $chown = $unix->find_program("chown"); $sudo = $unix->find_program("sudo"); $reconstruct = $unix->LOCATE_CYRRECONSTRUCT(); if (!is_file($rsync)) { writelogs(date('m-d H:i:s') . " " . "Unable to stat rsync program", __FUNCTION__, __FILE__, __LINE__); return; } if (!is_file($reconstruct)) { writelogs(date('m-d H:i:s') . " " . "Unable to stat reconstruct program", __FUNCTION__, __FILE__, __LINE__); return; } $array = unserialize(base64_decode($basedContent)); $id = $array["taskid"]; writelogs(date('m-d H:i:s') . " " . "mounting {$id}", __FUNCTION__, __FILE__); $mounted_dir = backup($id); if ($mounted_dir == null) { writelogs(date('m-d H:i:s') . " " . "cannot mount task id {$id}", __FUNCTION__, __FILE__); return; } $path = $array["path"]; $uid = $array["uid"]; if (preg_match("#INBOX\\/(.+)#", $array["mailbox"], $re)) { $mailbox = $re[1]; $cyrus = new cyrus(); $cyrus->CreateSubDir($uid, $mailbox); } else { $mailbox = $array["mailbox"]; } $localimapdir = $unix->IMAPD_GET("partition-default"); if (!is_dir($localimapdir)) { writelogs(date('m-d H:i:s') . " " . "Unable to stat local partition-default", __FUNCTION__, __FILE__, __LINE__); return; } $userfs = str_replace(".", "^", $uid); $firstletter = substr($userfs, 0, 1); $localuserfs = "{$localimapdir}/{$firstletter}/user/{$userfs}"; $localimapdir = "{$localimapdir}/{$firstletter}/user/{$userfs}/"; if (!is_dir($localimapdir)) { writelogs(date('m-d H:i:s') . " " . "Unable to stat local \"{$localimapdir}\"", __FUNCTION__, __FILE__, __LINE__); return; } $remoteimapdir = "{$mounted_dir}/{$path}/{$mailbox}"; @mkdir($localimapdir, null, true); if (substr($remoteimapdir, strlen($remoteimapdir) - 1, 1) != "/") { $remoteimapdir = $remoteimapdir . "/"; } $cmd = "{$rsync} -z --stats {$remoteimapdir}* {$localimapdir} 2>&1"; if ($GLOBALS["USE_RSYNC"]) { $backup = new backup_protocols(); writelogs(date('m-d H:i:s') . " " . "Using rsync protocol", __FUNCTION__, __FILE__, __LINE__); $array_config = $backup->extract_rsync_protocol($remoteimapdir); if (!is_array($array)) { writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: rsync protocol error", __FUNCTION__, __FILE__, __LINE__); return false; } if ($array_config["PASSWORD"] != null) { $tmpstr = "/opt/artica/passwords/" . md5($array_config["PASSWORD"]); @mkdir("/opt/artica/passwords", null, true); @file_put_contents($tmpstr, $array_config["PASSWORD"]); $pwd = " --password-file={$tmpstr}"; } if ($array["USER"] != null) { $user = "******"USER"]}@"; } $cmd = "{$rsync}{$pwd} --stats rsync://{$user}{$array_config["SERVER"]}/{$array_config["FOLDER"]}* {$localimapdir} 2>&1"; } writelogs(date('m-d H:i:s') . " " . "Restore from {$remoteimapdir}", __FUNCTION__, __FILE__, __LINE__); writelogs(date('m-d H:i:s') . " " . "Restore to {$localimapdir}", __FUNCTION__, __FILE__, __LINE__); writelogs(date('m-d H:i:s') . " " . "reconstruct path {$reconstruct}", __FUNCTION__, __FILE__, __LINE__); writelogs(date('m-d H:i:s') . " " . "{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $rsynclogs); $i = 0; while (list($num, $line) = each($rsynclogs)) { if (preg_match("#Number of files transferred:\\s+([0-9]+)#", $line, $re)) { $GLOBALS["events"][] = "Files restored: {$re[1]}"; } if (preg_match("#Total transferred file size:\\s+([0-9]+)#", $line, $re)) { $bytes = $re[1]; $re[1] = round($re[1] / 1024 / 1000) . "M"; $GLOBALS["events"][] = "{$re[1]} size restored ({$bytes} bytes)"; } if (preg_match("#Permission denied#", $line)) { $i = $i + 1; } } $GLOBALS["events"][] = "{$i} file(s) on error"; shell_exec("{$chown} -R cyrus:mail {$localuserfs}"); shell_exec("/bin/chmod -R 755 {$localuserfs}"); $cmd = "{$sudo} -u cyrus {$reconstruct} -r -f user/{$uid} 2>&1"; writelogs(date('m-d H:i:s') . " " . "{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $rsynclogs); $GLOBALS["events"][] = "Reconstruct information: "; while (list($num, $line) = each($rsynclogs)) { $GLOBALS["events"][] = "reconstructed path: {$line}"; } writelogs(date('m-d H:i:s') . " " . "restarting imap service", __FUNCTION__, __FILE__, __LINE__); system("/etc/init.d/cyrus-imapd restart"); print_r($GLOBALS["events"]); }
function move_default_dir_to_newdir($path) { $path = base64_decode($path); if ($path == null) { return null; } if (!is_dir($path)) { return null; } $unix = new unix(); $logs = "/usr/share/artica-postfix/ressources/logs/cyrus_dir_logs"; $currentdir = $unix->IMAPD_GET("partition-default"); $sock = new sockets(); $sock->SET_INFO("CyrusPartitionDefault", $path); system($unix->find_program("mv") . " -fv {$currentdir}/* {$path}/ >{$logs} 2>&1"); system("/usr/share/artica-postfix/bin/artica-install --reconfigure-cyrus >>{$logs} 2>&1"); @chmod("/usr/share/artica-postfix/ressources/logs/cyrus_dir_logs", 0755); }
$su = $unix->find_program("su"); if (!is_file($su)) { events("unable to locate su tool !"); die; } $cyrreconstruct = $unix->LOCATE_CYRRECONSTRUCT(); if (!is_file($cyrreconstruct)) { events("unable to locate CYRRECONSTRUCT tool !"); die; } $cyrquota = $unix->LOCATE_CYRQUOTA(); if (!is_file($cyrquota)) { events("unable to locate cyrquota tool !"); die; } $unixhierarchysep = $unix->IMAPD_GET('unixhierarchysep'); $account = "user.{$GLOBALS["uid"]}"; if (strtolower($unixhierarchysep) == "yes") { $account = "user/{$GLOBALS["uid"]}"; } events("unixhierarchysep -> {$unixhierarchysep} ({$account})"); $queue_path = $unix->IMAPD_GET('partition-default'); events("unixhierarchysep -> {$unixhierarchysep} ({$account}) on {$queue_path}"); $first_letter = substr($GLOBALS["uid"], 0, 1); $user_path = str_replace('.', '^', $GLOBALS["uid"]); $fpath = "{$queue_path}/{$first_letter}/user/{$user_path}"; events("mailbox path -> {$fpath}"); if (is_file("{$fpath}/cyrus.seen")) { events("Delete file {$fpath}/cyrus.seen"); @unlink("{$fpath}/cyrus.seen"); }
function move_default_dir_to_newdir($path) { $path = base64_decode($path); movedir_events("Move to dir: {$path}"); if ($path == null) { movedir_events("Move to dir: path is null..aborting"); return null; } if (!is_dir($path)) { movedir_events("Move to dir: {$path} no such directory"); return null; } $unix = new unix(); $currentdir = $unix->IMAPD_GET("partition-default"); movedir_events("Current directory: {$currentdir}"); $sock = new sockets(); movedir_events("Save Current directory to : {$currentdir}"); $sock->SET_INFO("CyrusPartitionDefault", $path); movedir_events("Move to dir: Please wait... moving datas"); shell_exec($unix->find_program("mv") . " -fv {$currentdir}/* {$path}/ 2>&1"); movedir_events("Move to dir: moving datas done"); exec("/usr/share/artica-postfix/bin/artica-install --reconfigure-cyrus 2>&1", $results); while (list($index, $line) = each($results)) { movedir_events("{$line}"); } @chmod("/usr/share/artica-postfix/ressources/logs/cyrus_dir_logs", 0755); }
function DirectorySize() { $unix = new unix(); $pid_path = "/etc/artica-postfix/pids/" . __FILE__ . "." . __FUNCTION__; $oldpid = @file_get_contents($pid_path); if ($unix->process_exists($oldpid)) { die; } $childpid = posix_getpid(); @file_put_contents($pid_path, $childpid); $filetim = file_time_min("/etc/artica-postfix/croned.1/" . __FILE__ . "." . __FUNCTION__); if ($filetim < 240) { die; } $partition_default = $unix->IMAPD_GET("partition-default"); artica_mysql_events("Starting calculate - {$partition_default} - disk size", null, __FILE__, "mailbox"); if (strlen($partition_default) < 3) { return; } if (!is_dir($partition_default)) { return; } $GLOBALS["NICE"] = EXEC_NICE(); $du_bin = $unix->find_program("du"); exec("{$GLOBALS["NICE"]}{$du_bin} -h -s {$partition_default} 2>&1", $results); $r = implode("", $results); if (preg_match("#^(.+?)\\s+#", $r, $re)) { $sock = new sockets(); $sock->SET_INFO("CyrusImapPartitionDefaultSize", $re[1]); send_email_events("Mailboxes size on your server: {$re['1']}", "Mailboxes size on your server: {$re['1']}", "mailbox"); if ($partition_default == "/var/spool/cyrus/mail") { $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $re[1]); return; } unset($results); exec("{$GLOBALS["NICE"]}{$du_bin} -h -s /var/spool/cyrus/mail 2>&1", $results); $r = implode("", $results); if (preg_match("#^(.+?)\\s+#", $r, $re)) { $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $re[1]); } } }
function DirectorySize() { $unix = new unix(); $pid_path = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__; $timePath = "/etc/artica-postfix/croned.1/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = @file_get_contents($pid_path); if (!$GLOBALS["FORCE"]) { if ($unix->process_exists($pid)) { die; } $childpid = posix_getpid(); @file_put_contents($pid_path, $childpid); if (system_is_overloaded()) { if ($GLOBALS["VERBOSE"]) { echo "Overloaded system.\n"; } return; } } $filetim = $unix->file_time_min($timePath); if ($GLOBALS["VERBOSE"]) { echo "Time File: {$timePath} ({$filetim}Mn)\n"; } if (!$GLOBALS["FORCE"]) { if ($filetim < 240) { return; } } $partition_default = $unix->IMAPD_GET("partition-default"); if (is_link($partition_default)) { $partition_default = readlink($partition_default); } @file_put_contents($timePath, time()); if ($GLOBALS["VERBOSE"]) { echo "partition_default = {$partition_default}\n"; } artica_mysql_events("Starting calculate - {$partition_default} - disk size", null, __FILE__, "mailbox"); if (strlen($partition_default) < 3) { return; } if (!is_dir($partition_default)) { return; } $currentsize = $unix->DIRSIZE_BYTES($partition_default) / 1024 / 1024; $PartInfo = $unix->DIRPART_INFO($partition_default); $totalMB = $PartInfo["TOT"]; $totalMB = round($totalMB / 1048576); if ($GLOBALS["VERBOSE"]) { echo "partition_default = {$currentsize}MB/{$totalMB}MB\n"; } $sock = new sockets(); $currentsize = round($currentsize); $sock->SET_INFO("CyrusImapPartitionDefaultSize", $currentsize); $sock->SET_INFO("CyrusImapPartitionDefaultSizeTime", time()); $sock->SET_INFO("CyrusImapPartitionDiskSize", $totalMB); send_email_events("Mailboxes size on your server: {$currentsize} MB", "Mailboxes size on your server: {$currentsize} MB", "mailbox"); if ($partition_default == "/var/spool/cyrus/mail") { $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $currentsize); return; } $currentsize = $unix->DIRSIZE_BYTES("/var/spool/cyrus/mail") / 1024 / 1024; $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $currentsize); }