コード例 #1
0
ファイル: exec.backup.php プロジェクト: articatech/artica
function mount_smb($pattern, $ID, $testwrite = true)
{
    $backup = new backup_protocols();
    $unix = new unix();
    $rsync = $unix->find_program("rsync");
    if ($GLOBALS["VERBOSE"]) {
        backup_events($ID, "initialization", "INFO, Extract protocol: `{$pattern}`", __LINE__);
    }
    $array = $backup->extract_smb_protocol($pattern);
    if (!is_array($array)) {
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: smb protocol error", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    $mount_path = "/opt/artica/mounts/backup/{$ID}";
    backup_events($ID, "initialization", "INFO, local mount point {$mount_path} (mount_smb())", __LINE__);
    include_once dirname(__FILE__) . "/ressources/class.mount.inc";
    backup_events($ID, "initialization", "INFO, mount({$GLOBALS["ADDLOG"]})", __LINE__);
    $mount = new mount($GLOBALS["ADDLOG"]);
    if (!$mount->ismounted($mount_path)) {
        backup_events($ID, "initialization", "INFO, local mount point {$mount_path} not mounted creating mount point `{$mount_path}`", __LINE__);
        @mkdir($mount_path, null, true);
    }
    if (!$mount->smb_mount($mount_path, $array["SERVER"], $array["USER"], $array["PASSWORD"], $array["FOLDER"])) {
        backup_events($ID, "initialization", "ERROR, unable to mount target server (mount_smb({$mount_path},{$array["SERVER"]}))\n" . @implode("\n", $GLOBALS["MOUNT_EVENTS"]), __LINE__);
        return false;
    }
    if (!$testwrite) {
        return true;
    }
    $md5 = md5(date('Y-m-d H:i:s'));
    exec("/bin/touch {$mount_path}/{$md5} 2>&1", $results_touch);
    if (is_file("{$mount_path}/{$md5}")) {
        @unlink("{$mount_path}/{$md5}");
        backup_events($ID, "initialization", "INFO, writing test successfully passed OK !", __LINE__);
        if ($GLOBALS["ONLY_TESTS"]) {
            writelogs(date('m-d H:i:s') . " " . "<H2>{success}</H2>", __FUNCTION__, __FILE__, __LINE__);
        }
        if (is_file($rsync)) {
            $GLOBALS["COMMANDLINECOPY"] = "{$rsync} -ar --no-p --no-g --no-o --chmod=ug=rwX,o=rwX {SRC_PATH} {NEXT} --stats -v";
        } else {
            $GLOBALS["COMMANDLINECOPY"] = "/bin/cp -ru {SRC_PATH} {NEXT}";
        }
        $GLOBALS["COMMANDLINE_MOUNTED_PATH"] = $mount_path;
        return true;
    } else {
        $logs_touch = implode("<br>", $results_touch);
        backup_events($ID, "initialization", "ERROR, writing test failed");
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: {$logs_touch}", __FUNCTION__, __FILE__, __LINE__);
        exec("umount -l {$mount_path}");
    }
}
コード例 #2
0
ファイル: exec.sarg.php プロジェクト: brucewu16899/1.6.x
function backup()
{
    $sock = new sockets();
    $unix = new unix();
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " [INIT]: nginx Already Artica task running PID {$pid} since {$time}mn\n";
        return;
    }
    $time = $unix->file_time_min($pidTime);
    if ($time < 60) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($pidTime);
    @file_put_contents($pidTime, getmypid());
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    $BackupSargUseNas = $sock->GET_INFO("BackupSargUseNas");
    if (!is_numeric($BackupSargUseNas)) {
        $BackupSargUseNas = 0;
    }
    $nice = EXEC_NICE();
    $mount = new mount("/var/log/sarg-exec.log");
    if ($BackupSargUseNas == 0) {
        return;
    }
    $BackupSargNASIpaddr = $sock->GET_INFO("BackupSargNASIpaddr");
    $BackupSargNASFolder = $sock->GET_INFO("BackupSargNASFolder");
    $BackupSargNASUser = $sock->GET_INFO("BackupSargNASUser");
    $BackupSargNASPassword = $sock->GET_INFO("BackupSargNASPassword");
    $mountPoint = "/mnt/BackupSargUseNas";
    if (!$mount->smb_mount($mountPoint, $BackupSargNASIpaddr, $BackupSargNASUser, $BackupSargNASPassword, $BackupSargNASFolder)) {
        sarg_admin_events("SARG: Unable to connect to NAS storage system: {$BackupSargNASUser}@{$BackupSargNASIpaddr}", __FUNCTION__, __FILE__, __LINE__, "sarg");
        return;
    }
    $BackupDir = "{$mountPoint}/sarg";
    @mkdir("{$BackupDir}", 0755);
    if (!is_dir($BackupDir)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Fatal {$BackupDir} permission denied\n";
        }
        sarg_admin_events("Fatal {$BackupDir} permission denied", __FUNCTION__, __FILE__, __LINE__, "sarg");
        $mount->umount($mountPoint);
        return false;
    }
    $t = time();
    @file_put_contents("{$BackupDir}/{$t}", time());
    if (!is_file("{$BackupDir}/{$t}")) {
        sarg_admin_events("Fatal {$BackupDir} permission denied", __FUNCTION__, __FILE__, __LINE__, "sarg");
        $mount->umount($mountPoint);
        return false;
    }
    @unlink("{$BackupDir}/{$t}");
    $cp = $unix->find_program("cp");
    shell_exec(trim("{$nice} {$cp} -dpR {$SargOutputDir}/* {$BackupDir}/"));
    $mount->umount($mountPoint);
    sarg_admin_events("Copy to {$BackupSargNASIpaddr}/{$BackupSargNASFolder} done", __FUNCTION__, __FILE__, __LINE__, "sarg");
}
コード例 #3
0
function restore_TestNas()
{
    $sock = new sockets();
    $unix = new unix();
    $sock = new sockets();
    $BackupArticaRestoreNASIpaddr = $sock->GET_INFO("BackupArticaRestoreNASIpaddr");
    $BackupArticaRestoreNASFolder = $sock->GET_INFO("BackupArticaRestoreNASFolder");
    $BackupArticaRestoreNASUser = $sock->GET_INFO("BackupArticaRestoreNASUser");
    $BackupArticaRestoreNASPassword = $sock->GET_INFO("BackupArticaRestoreNASPassword");
    $BackupArticaRestoreNASFolderSource = $sock->GET_INFO("BackupArticaRestoreNASFolderSource");
    $BackupArticaRestoreNetwork = $sock->GET_INFO("BackupArticaRestoreNetwork");
    $mount = new mount("/var/log/artica-postfix/backup.debug");
    $mountPoint = "/mnt/BackupArticaRestoreNAS";
    if ($mount->ismounted($mountPoint)) {
        return true;
    }
    @mkdir($mountPoint, 0755, true);
    if (!$mount->smb_mount($mountPoint, $BackupArticaRestoreNASIpaddr, $BackupArticaRestoreNASUser, $BackupArticaRestoreNASPassword, $BackupArticaRestoreNASFolder)) {
        system_admin_events("Mounting //{$BackupArticaRestoreNASIpaddr}/{$BackupArticaRestoreNASFolder} failed", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    if (!$mount->ismounted($mountPoint)) {
        return false;
    }
    return true;
}
コード例 #4
0
function updatev2_NAS()
{
    $sock = new sockets();
    $unix = new unix();
    $t = time();
    $GLOBALS["TEMP_PATH"] = $unix->TEMP_DIR();
    $mount_point = "{$GLOBALS["TEMP_PATH"]}/{$t}";
    $ArticaDBPath = $sock->GET_INFO("ArticaDBPath");
    if ($ArticaDBPath == null) {
        $ArticaDBPath = "/opt/articatech";
    }
    $ArticaDBNasUpdt = unserialize(base64_decode($sock->GET_INFO("ArticaDBNasUpdt")));
    include_once dirname(__FILE__) . "/ressources/class.mount.inc";
    $mount = new mount();
    updatev2_progress(30, "{mouting} {$ArticaDBNasUpdt["hostname"]}...");
    $umount = $unix->find_program("umount");
    if (!$mount->smb_mount($mount_point, $ArticaDBNasUpdt["hostname"], $ArticaDBNasUpdt["username"], $ArticaDBNasUpdt["password"], $ArticaDBNasUpdt["folder"])) {
        updatev2_progress(100, "{failed} to update Artica categories database trough NAS");
        squid_admin_mysql(1, "Unable to mount on {$ArticaDBNasUpdt["hostname"]}", @implode("\n", $GLOBALS["MOUNT_EVENTS"]));
        return false;
    }
    $filename = $ArticaDBNasUpdt["filename"];
    if (!is_file("{$mount_point}/{$filename}")) {
        updatev2_progress(100, "{failed} {$ArticaDBNasUpdt["hostname"]}/{$ArticaDBNasUpdt["folder"]}/{$filename} no such file");
        squid_admin_mysql(1, "{failed} to update Artica categories database trough NAS", "{$ArticaDBNasUpdt["hostname"]}/{$ArticaDBNasUpdt["folder"]}/{$filename} no such file");
        shell_exec("{$umount} -l {$mount_point}");
        return false;
    }
    $tar = $unix->find_program("tar");
    updatev2_progress(40, "{installing}...");
    if ($GLOBALS["VERBOSE"]) {
        echo "uncompressing {$mount_point}/{$filename}\n";
    }
    @mkdir($ArticaDBPath, 0755, true);
    updatev2_progress(50, "{stopping_service}...");
    shell_exec("/etc/init.d/artica-postfix stop articadb");
    updatev2_progress(60, "{extracting_package}...");
    shell_exec("{$tar} -xf  {$mount_point}/{$filename} -C {$ArticaDBPath}/");
    updatev2_progress(70, "{cleaning}...");
    $sock->SET_INFO("ManualArticaDBPathNAS", "0");
    shell_exec("{$umount} -l {$mount_point}");
    updatev2_progress(75, "{starting_service}...");
    if ($GLOBALS["VERBOSE"]) {
        echo "starting Articadb\n";
    }
    shell_exec("/etc/init.d/artica-postfix start articadb");
    updatev2_progress(80, "{checking}");
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("catz")) {
        updatev2_progress(85, "Removing old database catz");
        $q->DELETE_DATABASE("catz");
    }
    updatev2_progress(90, "{finish}");
    $took = $unix->distanceOfTimeInWords($t, time());
    $LOCAL_VERSION = @file_get_contents("{$ArticaDBPath}/VERSION");
    squid_admin_mysql(2, "New Artica Database statistics {$LOCAL_VERSION} updated took:{$took}", "");
    artica_update_event(2, "New Artica Database statistics {$LOCAL_VERSION} updated took:{$took}", null, __FILE__, __LINE__, "ufbd-artica");
    updatev2_progress(100, "{done}");
    $q->QUERY_SQL("TRUNCATE TABLE `catztemp`");
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $cmd = trim("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.visited.sites.php --schedule-id={$GLOBALS["SCHEDULE_ID"]} >/dev/null 2>&1 &");
    shell_exec($cmd);
    return true;
}
コード例 #5
0
function shared()
{
    $FOLDERS = array();
    $unix = new unix();
    $sock = new sockets();
    $GLOBALS["omindex"] = $unix->find_program("omindex");
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        system_admin_events("Already instance executed pid:{$olpid}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $EnableSambaXapian = $sock->GET_INFO("EnableSambaXapian");
    if (!is_numeric($EnableSambaXapian)) {
        $EnableSambaXapian = 0;
    }
    if ($EnableSambaXapian == 0) {
        system_admin_events("Parsing shared folder is disabled in this configuration, aborting", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $SambaXapianAuth = unserialize(base64_decode($sock->GET_INFO("SambaXapianAuth")));
    if (!is_file($GLOBALS["omindex"])) {
        system_admin_events("omindex no such binary, aborting", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $smbclient = $unix->find_program("smbclient");
    $umount = $unix->find_program("umount");
    if (!is_file($smbclient)) {
        system_admin_events("smbclient, no such binary, aborting...", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $username = $SambaXapianAuth["username"];
    $password = $SambaXapianAuth["password"];
    $domain = $SambaXapianAuth["domain"];
    $comp = $SambaXapianAuth["ip"];
    if (!isset($SambaXapianAuth["lang"])) {
        $SambaXapianAuth["lang"] == "none";
    }
    $lang = $SambaXapianAuth["lang"];
    if ($lang == null) {
        $lang = "none";
    }
    $localdatabase = "/usr/share/artica-postfix/LocalDatabases";
    $database = "{$localdatabase}/samba.default.db";
    $nice = EXEC_NICE();
    if ($comp == null) {
        system_admin_events("smbclient, no computer set, aborting...", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    if ($username != null) {
        $creds = "-U {$username}";
        if ($password != null) {
            $creds = $creds . "%{$password}";
        }
    }
    $t1 = time();
    $cmd = "{$smbclient} -N {$creds} -L //{$comp} -g 2>&1";
    if ($GLOBALS["VERBOSE"]) {
        echo $cmd . "\n";
    }
    exec($cmd, $results);
    if (is_array($results)) {
        while (list($num, $ligne) = each($results)) {
            if (preg_match("#Disk\\|(.+?)\\|#", $ligne, $re)) {
                $folder = $re[1];
                if ($folder == "{$username}") {
                    continue;
                }
                $FOLDERS[$folder] = true;
            }
        }
    }
    if (count($FOLDERS) == 0) {
        system_admin_events("No shared folder can be browsed with {$username}@{$comp}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $tmpM = "/artica-mount-xapian";
    $count = 0;
    @mkdir($tmp, 0755, true);
    while (list($directory, $none) = each($FOLDERS)) {
        $mount = new mount();
        if (!$mount->smb_mount($tmpM, $comp, $username, $password, $directory)) {
            system_admin_events("Folder:{$directory}, permission denied\n" . @implode("\n", $GLOBALS["MOUNT_EVENTS"]), __FUNCTION__, __FILE__, __LINE__, "xapian");
            return;
        }
        $BaseUrl = "file://///{$comp}/{$directory}";
        $cmd = "{$nice}{$GLOBALS["omindex"]} -l 0 -s {$lang} -E 512 -m 60M --follow -D \"{$database}\" -U \"{$BaseUrl}\" \"{$tmpM}\" 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        $results_scan = array();
        exec($cmd, $results_scan);
        shell_exec("{$umount} -l {$tmpM}");
        $dirRes = ParseLogs($results_scan);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $count++;
        system_admin_events("scanned smb://{$comp}/{$directory} took {$took} indexed:{$dirRes[0]} skipped:{$dirRes[1]}", __FUNCTION__, __FILE__, __LINE__, "xapian");
    }
    @rmdir($tmpM);
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    system_admin_events("scanned {$count} directorie(s) took {$took}", __FUNCTION__, __FILE__, __LINE__, "xapian");
}
コード例 #6
0
function BackupToNas($directory)
{
    if (!is_dir($directory)) {
        return;
    }
    $syslog = new mysql_storelogs();
    $sock = new sockets();
    $users = new usersMenus();
    $unix = new unix();
    $myHostname = $unix->hostname_g();
    $DirSuffix = basename($directory);
    $mount = new mount("/var/log/artica-postfix/logrotate.debug");
    $BackupSquidLogsNASIpaddr = $sock->GET_INFO("BackupSquidLogsNASIpaddr");
    $BackupSquidLogsNASFolder = $sock->GET_INFO("BackupSquidLogsNASFolder");
    $BackupSquidLogsNASUser = $sock->GET_INFO("BackupSquidLogsNASUser");
    $BackupSquidLogsNASPassword = $sock->GET_INFO("BackupSquidLogsNASPassword");
    $BackupSquidLogsNASRetry = $sock->GET_INFO("BackupSquidLogsNASRetry");
    if (!is_numeric($BackupSquidLogsNASRetry)) {
        $BackupSquidLogsNASRetry = 0;
    }
    $mount = new mount("/var/log/artica-postfix/logrotate.debug");
    $BackupSquidLogsNASIpaddr = $sock->GET_INFO("BackupSquidLogsNASIpaddr");
    $BackupSquidLogsNASFolder = $sock->GET_INFO("BackupSquidLogsNASFolder");
    $BackupSquidLogsNASUser = $sock->GET_INFO("BackupSquidLogsNASUser");
    $BackupSquidLogsNASPassword = $sock->GET_INFO("BackupSquidLogsNASPassword");
    $BackupSquidLogsNASRetry = $sock->GET_INFO("BackupSquidLogsNASRetry");
    if (!is_numeric($BackupSquidLogsNASRetry)) {
        $BackupSquidLogsNASRetry = 0;
    }
    $mv = $unix->find_program("mv");
    if ($BackupSquidLogsNASIpaddr == null) {
        $this->events("Backup via NAS is disabled, skip", __FUNCTION__, __FILE__, __LINE__, "logrotate");
        return false;
    }
    $mountPoint = "/mnt/BackupSquidLogsUseNas";
    if (!$mount->smb_mount($mountPoint, $BackupSquidLogsNASIpaddr, $BackupSquidLogsNASUser, $BackupSquidLogsNASPassword, $BackupSquidLogsNASFolder)) {
        $syslog->events("Unable to connect to NAS storage system (1): {$BackupSquidLogsNASUser}@{$BackupSquidLogsNASIpaddr}", __FUNCTION__, __FILE__, __LINE__, "logrotate");
        if ($BackupSquidLogsNASRetry == 0) {
            return;
        }
        sleep(3);
        $mount = new mount("/var/log/artica-postfix/logrotate.debug");
        if (!$mount->smb_mount($mountPoint, $BackupSquidLogsNASIpaddr, $BackupSquidLogsNASUser, $BackupSquidLogsNASPassword, $BackupSquidLogsNASFolder)) {
            $syslog->events("Unable to connect to NAS storage system (1): {$BackupSquidLogsNASUser}@{$BackupSquidLogsNASIpaddr}", __FUNCTION__, __FILE__, __LINE__, "logrotate");
            return;
        }
    }
    $syslog->events("Hostname={$myHostname} Suffix = {$DirSuffix} {$BackupSquidLogsNASIpaddr}/{$BackupSquidLogsNASFolder}", __FUNCTION__, __LINE__);
    $BackupMaxDaysDir = "{$mountPoint}/artica-backup-syslog";
    @mkdir("{$BackupMaxDaysDir}", 0755, true);
    if (!is_dir($BackupMaxDaysDir)) {
        $syslog->events("Fatal {$BackupMaxDaysDir} permission denied", __FUNCTION__, __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "Fatal {$BackupMaxDaysDir} permission denied\n";
        }
        squid_admin_mysql(0, "SYSLOG: FATAL {$BackupMaxDaysDir} permission denied", null, __FILE__, __LINE__);
        $mount->umount($mountPoint);
        return false;
    }
    $t = time();
    @file_put_contents("{$BackupMaxDaysDir}/{$t}", time());
    if (!is_file("{$BackupMaxDaysDir}/{$t}")) {
        $syslog->events("Fatal {$BackupMaxDaysDir} permission denied ({$BackupMaxDaysDir}/{$t}) test failed", __FUNCTION__, __LINE__);
        squid_admin_mysql(0, "SYSLOG: FATAL {$BackupMaxDaysDir} permission denied", null, __FILE__, __LINE__);
        $mount->umount($mountPoint);
        return false;
    }
    @unlink("{$BackupMaxDaysDir}/{$t}");
    exec("{$mv} --force {$directory} --target-directory={$BackupMaxDaysDir}/ 2>&1", $results);
    while (list($index, $line) = each($results)) {
        $syslog->events("{$line}", __FUNCTION__, __LINE__);
    }
    analyze_destination_directory($BackupMaxDaysDir . "/proxy");
    $mount->umount($mountPoint);
    return true;
}
コード例 #7
0
function tests_nas()
{
    $sock = new sockets();
    $unix = new unix();
    $failed = "***********************\n** FAILED **\n***********************\n";
    $success = "***********************\n******* SUCCESS *******\n***********************\n";
    if (!isset($GLOBALS["CyrusBackupNas"])) {
        $GLOBALS["CyrusBackupNas"] = unserialize(base64_decode($sock->GET_INFO("CyrusBackupNas")));
    }
    $CyrusBackupNas = $GLOBALS["CyrusBackupNas"];
    if (!isset($CyrusBackupNas["hostname"])) {
        return;
    }
    if ($CyrusBackupNas["hostname"] == null) {
        return;
    }
    if (!is_numeric($CyrusBackupNas["notifs"])) {
        $CyrusBackupNas["notifs"] = 0;
    }
    if ($GLOBALS["VERBOSE"]) {
        if ($CyrusBackupNas["notifs"] == 1) {
            $unix->SendEmailConfigured($CyrusBackupNas, "Test-message", "This is a content");
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        while (list($index, $line) = each($CyrusBackupNas)) {
            echo "{$index}.........: {$line}\n";
        }
    }
    $mount = new mount($GLOBALS["LOGFILE"]);
    $NasFolder = $CyrusBackupNas["folder"];
    $NasFolder = str_replace('\\\\', '/', $NasFolder);
    if (strpos($NasFolder, "/") > 0) {
        $f = explode("/", $NasFolder);
        $NasFolder = $f[0];
    }
    if ($mount->ismounted($GLOBALS["MOUNT_POINT"])) {
        if ($GLOBALS["VERBOSE"]) {
            echo $success . @implode("\n", $GLOBALS["MOUNT_EVENTS"]);
        }
        return true;
    }
    if (!$mount->smb_mount($GLOBALS["MOUNT_POINT"], $CyrusBackupNas["hostname"], $CyrusBackupNas["username"], $CyrusBackupNas["password"], $NasFolder)) {
        if ($GLOBALS["VERBOSE"]) {
            echo $failed . @implode("\n", $GLOBALS["MOUNT_EVENTS"]);
            return;
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo $success . @implode("\n", $GLOBALS["MOUNT_EVENTS"]);
    }
    return true;
}
コード例 #8
0
function tests_nas()
{
    $sock = new sockets();
    $BackupSquidStatsUseNas = $sock->GET_INFO("BackupSquidStatsUseNas");
    $MySQLSyslogType = $sock->GET_INFO("MySQLSyslogType");
    $EnableSyslogDB = $sock->GET_INFO("EnableSyslogDB");
    if (!is_numeric($EnableSyslogDB)) {
        $EnableSyslogDB = 0;
    }
    if (!is_numeric($MySQLSyslogType)) {
        $MySQLSyslogType = 1;
    }
    if (!is_numeric($BackupSquidStatsUseNas)) {
        $BackupSquidStatsUseNas = 0;
    }
    $users = new usersMenus();
    $mount = new mount("/var/log/artica-postfix/logrotate.debug");
    if ($BackupSquidStatsUseNas == 0) {
        echo "Backup using NAS is not enabled\n";
        return;
    }
    $BackupSquidStatsNASIpaddr = $sock->GET_INFO("BackupSquidStatsNASIpaddr");
    $BackupSquidStatsNASFolder = $sock->GET_INFO("BackupSquidStatsNASFolder");
    $BackupSquidStatsNASUser = $sock->GET_INFO("BackupSquidStatsNASUser");
    $BackupSquidStatsNASPassword = $sock->GET_INFO("BackupSquidStatsNASPassword");
    $BackupSquidStatsNASRetry = $sock->GET_INFO("BackupSquidStatsNASRetry");
    if (!is_numeric($BackupSquidStatsNASRetry)) {
        $BackupSquidStatsNASRetry = 0;
    }
    $failed = "***********************\n** FAILED **\n***********************\n";
    $success = "***********************\n******* SUCCESS *******\n***********************\n";
    $mountPoint = "/mnt/BackupSquidStatsUseNas";
    if (!$mount->smb_mount($mountPoint, $BackupSquidStatsNASIpaddr, $BackupSquidStatsNASUser, $BackupSquidStatsNASPassword, $BackupSquidStatsNASFolder)) {
        if ($BackupSquidStatsNASRetry == 1) {
            sleep(3);
            $mount = new mount("/var/log/artica-postfix/logrotate.debug");
            if (!$mount->smb_mount($mountPoint, $BackupSquidStatsNASIpaddr, $BackupSquidStatsNASUser, $BackupSquidStatsNASPassword, $BackupSquidStatsNASFolder)) {
                echo "{$failed}\nUnable to connect to NAS storage system: {$BackupSquidStatsNASUser}@{$BackupSquidStatsNASIpaddr}\n";
                echo @implode("\n", $GLOBALS["MOUNT_EVENTS"]);
                return;
            }
        } else {
            echo "{$failed}\nUnable to connect to NAS storage system: {$BackupSquidStatsNASUser}@{$BackupSquidStatsNASIpaddr}\n";
            echo @implode("\n", $GLOBALS["MOUNT_EVENTS"]);
            return;
        }
    }
    $BackupMaxDaysDir = "{$mountPoint}/backup-statistics/{$users->hostname}";
    @mkdir($BackupMaxDaysDir, 0755, true);
    if (!is_dir($BackupMaxDaysDir)) {
        echo "{$failed}{$BackupSquidStatsNASUser}@{$BackupSquidStatsNASIpaddr}/{$BackupSquidStatsNASFolder}/backup-statistics/{$users->hostname} permission denied.\n";
        $mount->umount($mountPoint);
        return;
    }
    $t = time();
    @file_put_contents("{$BackupMaxDaysDir}/{$t}", "#");
    if (!is_file("{$BackupMaxDaysDir}/{$t}")) {
        echo "{$failed}{$BackupSquidStatsNASUser}@{$BackupSquidStatsNASIpaddr}/{$BackupSquidStatsNASFolder}/backup-statistics/{$users->hostname}/* permission denied.\n";
        $mount->umount($mountPoint);
        return;
    }
    @unlink("{$BackupMaxDaysDir}/{$t}");
    $mount->umount($mountPoint);
    echo "{$success}";
}
コード例 #9
0
ファイル: exec.logrotate.php プロジェクト: brucewu16899/1.6.x
function CleanMysqlDatabase($PURGE_ALL = false)
{
    $filter = null;
    $users = new usersMenus();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/logrotate." . __FUNCTION__ . ".time";
    $pid = @file_get_contents("{$pidfile}");
    if ($unix->process_exists($pid, basename(__FILE__))) {
        system_admin_events("Already executed PID {$pid}", __FUNCTION__, __FILE__, __LINE__, "logrotate");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $time = $unix->file_time_min($timefile);
    if (!$PURGE_ALL) {
        if (!$GLOBALS["FORCE"]) {
            if ($time < 15) {
                events("No less than 15mn or delete {$timefile} file to force...");
                system_admin_events("No less than 15mn or delete {$timefile} file", __FUNCTION__, __FILE__, __LINE__, "logrotate");
                return;
            }
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $sock = new sockets();
    $MySQLSyslogType = $sock->GET_INFO("MySQLSyslogType");
    $EnableSyslogDB = $sock->GET_INFO("EnableSyslogDB");
    if (!is_numeric($EnableSyslogDB)) {
        $EnableSyslogDB = 0;
    }
    if (!is_numeric($MySQLSyslogType)) {
        $MySQLSyslogType = 1;
    }
    if ($MySQLSyslogType == 0) {
        $MySQLSyslogType = 4;
    }
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    $TuningParameters = unserialize(base64_decode($sock->GET_INFO("MySQLSyslogParams")));
    if ($EnableSyslogDB == 1) {
        if ($MySQLSyslogType == 2) {
            events("Is a client of remote MySQL server , aborting");
            if ($GLOBALS["VERBOSE"]) {
                echo "Is a client of remote MySQL server , aborting\n";
            }
            return;
        }
    }
    $LogRotateCompress = 1;
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    $SystemLogsPath = $sock->GET_INFO("SystemLogsPath");
    $BackupMaxDays = $sock->GET_INFO("BackupMaxDays");
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    $BackupSquidLogsUseNas = $sock->GET_INFO("BackupSquidLogsUseNas");
    if ($SystemLogsPath == null) {
        $SystemLogsPath = "/var/log";
    }
    $MySQLSyslogType = $sock->GET_INFO("MySQLSyslogType");
    $EnableSyslogDB = $sock->GET_INFO("EnableSyslogDB");
    if (!is_numeric($EnableSyslogDB)) {
        $EnableSyslogDB = 0;
    }
    if (!is_numeric($MySQLSyslogType)) {
        $MySQLSyslogType = 1;
    }
    if (!is_numeric($BackupSquidLogsUseNas)) {
        $BackupSquidLogsUseNas = 0;
    }
    if ($EnableSyslogDB == 1) {
        if ($MySQLSyslogType != 1) {
            return;
        }
    }
    if (!is_numeric($BackupMaxDays)) {
        $BackupMaxDays = 30;
    }
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    $mount = new mount("/var/log/artica-postfix/logrotate.debug");
    if ($BackupSquidLogsUseNas == 1) {
        $BackupSquidLogsNASIpaddr = $sock->GET_INFO("BackupSquidLogsNASIpaddr");
        $BackupSquidLogsNASFolder = $sock->GET_INFO("BackupSquidLogsNASFolder");
        $BackupSquidLogsNASUser = $sock->GET_INFO("BackupSquidLogsNASUser");
        $BackupSquidLogsNASPassword = $sock->GET_INFO("BackupSquidLogsNASPassword");
        $BackupSquidLogsNASRetry = $sock->GET_INFO("BackupSquidLogsNASRetry");
        if (!is_numeric($BackupSquidLogsNASRetry)) {
            $BackupSquidLogsNASRetry = 0;
        }
        $mountPoint = "/mnt/BackupSquidLogsUseNas";
        if (!$mount->smb_mount($mountPoint, $BackupSquidLogsNASIpaddr, $BackupSquidLogsNASUser, $BackupSquidLogsNASPassword, $BackupSquidLogsNASFolder)) {
            events("Unable to connect to NAS storage system (1): {$BackupSquidLogsNASUser}@{$BackupSquidLogsNASIpaddr}");
            if ($BackupSquidLogsNASRetry == 0) {
                return;
            }
            sleep(3);
            $mount = new mount("/var/log/artica-postfix/logrotate.debug");
            if (!$mount->smb_mount($mountPoint, $BackupSquidLogsNASIpaddr, $BackupSquidLogsNASUser, $BackupSquidLogsNASPassword, $BackupSquidLogsNASFolder)) {
                events("Unable to connect to NAS storage system (2): {$BackupSquidLogsNASUser}@{$BackupSquidLogsNASIpaddr}");
                return;
            }
        }
        $BackupMaxDaysDir = "{$mountPoint}/artica-backup-syslog/{$users->hostname}";
    }
    @mkdir("{$BackupMaxDaysDir}", 0755, true);
    if (!is_dir($BackupMaxDaysDir)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Fatal {$BackupMaxDaysDir} permission denied\n";
        }
        events("Fatal {$BackupMaxDaysDir} permission denied");
        squid_admin_notifs("SYSLOG: FATAL {$BackupMaxDaysDir} permission denied", __FUNCTION__, __FILE__, __LINE__);
        system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__, "logrotate");
        if ($BackupSquidLogsUseNas == 1) {
            $mount->umount($mountPoint);
        }
        return false;
    }
    $t = time();
    @file_put_contents("{$BackupMaxDaysDir}/{$t}", time());
    if (!is_file("{$BackupMaxDaysDir}/{$t}")) {
        events("Fatal {$BackupMaxDaysDir} permission denied");
        if ($GLOBALS["VERBOSE"]) {
            echo "Fatal {$BackupMaxDaysDir} permission denied\n";
        }
        squid_admin_notifs("SYSLOG: FATAL {$BackupMaxDaysDir} permission denied", __FUNCTION__, __FILE__, __LINE__);
        system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__, "logrotate");
        if ($BackupSquidLogsUseNas == 1) {
            $mount->umount($mountPoint);
        }
        return false;
    }
    @unlink("{$BackupMaxDaysDir}/{$t}");
    if ($BackupSquidLogsUseNas == 1) {
        if (is_dir("/home/logrotate_backup")) {
            $files = $unix->DirFiles("/home/logrotate_backup");
            events("Scanning the old storage systems.. " . count($files) . " file(s)");
            while (list($basename, $none) = each($files)) {
                $filepath = "/home/logrotate_backup/{$basename}";
                if ($GLOBALS["VERBOSE"]) {
                    echo "Checking \"{$filepath}\"\n";
                }
                $size = @filesize($filepath);
                if ($size < 20) {
                    events("Removing {$filepath}");
                    @unlink($filepath);
                    continue;
                }
                if (!@copy($filepath, "{$BackupMaxDaysDir}/{$basename}")) {
                    events("copy Failed {$filepath} to \"{$BackupMaxDaysDir}/{$basename}\" permission denied...");
                    continue;
                }
                events("Move {$filepath} to {$BackupSquidLogsNASIpaddr} success...");
                @unlink($filepath);
            }
        }
    }
    if ($PURGE_ALL == false) {
        $filter = "WHERE filetime<DATE_SUB(NOW(),INTERVAL {$BackupMaxDays} DAY)";
    }
    if ($EnableSyslogDB == 1) {
        $q = new mysql_storelogs();
        $sql = "SELECT `filename`,`hostname`,`storeid` FROM `files_info` {$filter}";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$sql}\n";
        }
        $results = $q->QUERY_SQL($sql);
        if (!$q->ok) {
            system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        $Count = mysql_num_rows($results);
        $c = 0;
        while ($ligne = mysql_fetch_assoc($results)) {
            $c++;
            if ($GLOBALS["VERBOSE"]) {
                echo "{$c}/{$Count} ******** {$ligne["filename"]} {$ligne["storeid"]} *********\n";
            }
            if (!$q->ExtractFile("{$BackupMaxDaysDir}/{$ligne["hostname"]}.{$ligne["filename"]}", $ligne["storeid"])) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$c}/{$Count} ******** {$ligne["filename"]} ExtractFile() = FALSE !!! *********\n";
                }
                continue;
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "{$c}/{$Count} DelteItem({$ligne["storeid"]}) *********\n";
            }
            $q->DelteItem($ligne["storeid"]);
            if ($GLOBALS["VERBOSE"]) {
                echo "********* EVENTS NOW --->\n";
            }
            $q->events("{$ligne["filename"]} saved into {$BackupMaxDaysDir}");
            if ($GLOBALS["VERBOSE"]) {
                echo "\n\n###### {$c}/{$Count} Continue to Next ##########\n";
            }
        }
        $sql = "SELECT `filename`,`hostname`,`storeid` FROM `accesslogs` {$filter}";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$sql}\n";
        }
        $results = $q->QUERY_SQL($sql);
        if (!$q->ok) {
            system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        $Count = mysql_num_rows($results);
        $c = 0;
        while ($ligne = mysql_fetch_assoc($results)) {
            $c++;
            if (!$q->ExtractAccessFile("{$BackupMaxDaysDir}/{$ligne["hostname"]}.{$ligne["filename"]}", $ligne["storeid"])) {
                continue;
            }
            $q->DelteAccessItem($ligne["storeid"]);
            $q->events("{$ligne["filename"]} saved into {$BackupMaxDaysDir}");
        }
        if ($BackupSquidLogsUseNas == 1) {
            $mount->umount($mountPoint);
        }
        return;
    }
    $q = new mysql_syslog();
    $sql = "SELECT `filename`,`taskid`,`filesize`,`filetime` FROM `store` {$filter}";
    $results = $q->QUERY_SQL($sql);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$sql} ({$q->mysql_error}) " . mysql_num_rows($results) . " file(s)\n";
    }
    if (!$q->ok) {
        system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Processing {$ligne["filename"]}\n";
        }
        if (!ExtractFileFromDatabase($ligne["filename"], $BackupMaxDaysDir)) {
            events("Unable to extract {$ligne["filename"]} to {$BackupMaxDaysDir}");
            squid_admin_notifs("SYSLOG: Unable to extract {$ligne["filename"]} to {$BackupMaxDaysDir}", __FUNCTION__, __FILE__, __LINE__);
            if ($BackupSquidLogsUseNas == 1) {
                $mount->umount($mountPoint);
            }
            return false;
        } else {
            events("Success extracting {$ligne["filename"]} to {$BackupMaxDaysDir}");
        }
    }
    if ($BackupSquidLogsUseNas == 1) {
        $mount->umount($mountPoint);
    }
}
コード例 #10
0
function tests_nas()
{
    $sock = new sockets();
    $failed = "***********************\n** FAILED **\n***********************\n";
    $success = "***********************\n******* SUCCESS *******\n***********************\n";
    $SquidOldLogsNAS = unserialize(base64_decode($sock->GET_INFO("SquidOldLogsNAS")));
    if (!isset($SquidOldLogsNAS["hostname"])) {
        return;
    }
    if ($SquidOldLogsNAS["hostname"] == null) {
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        while (list($index, $line) = each($SquidOldLogsNAS)) {
            echo "{$index}.........: {$line}\n";
        }
    }
    $mount = new mount($GLOBALS["LOGFILE"]);
    $NasFolder = $SquidOldLogsNAS["folder"];
    $NasFolder = str_replace('\\\\', '/', $NasFolder);
    if (strpos($NasFolder, "/") > 0) {
        $f = explode("/", $NasFolder);
        $NasFolder = $f[0];
    }
    $mountPoint = "/mnt/SquidImportLogs";
    if ($mount->ismounted($mountPoint)) {
        return true;
    }
    if (!$mount->smb_mount($mountPoint, $SquidOldLogsNAS["hostname"], $SquidOldLogsNAS["username"], $SquidOldLogsNAS["password"], $NasFolder)) {
        if ($GLOBALS["VERBOSE"]) {
            echo $failed . @implode("\n", $GLOBALS["MOUNT_EVENTS"]);
            return;
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo $success . @implode("\n", $GLOBALS["MOUNT_EVENTS"]);
    }
    return true;
}
コード例 #11
0
ファイル: exec.TextToLdap.php プロジェクト: BillTheBest/1.6.x
function connect($ligne)
{
    $unix = new unix();
    $Tmpdir = $unix->TEMP_DIR();
    $connection = $ligne["connection"];
    $server = $ligne["hostname"];
    $username = $ligne["username"];
    $password = $ligne["password"];
    $folder = $ligne["folder"];
    $folder = str_replace("\\", "/", $folder);
    if (strpos($folder, "/") > 0) {
        $FF = explode("/", $folder);
        $SharedDir = $FF[0];
        unset($FF[0]);
        $folder = @implode("/", $FF);
    }
    $mountpoint = "{$Tmpdir}/{$ligne["ID"]}";
    $mount = new mount();
    @mkdir($mountpoint, 0755, true);
    if (!$mount->smb_mount($mountpoint, $server, $username, $password, $SharedDir)) {
        system_admin_events("{$connection}: Unable to connect to smb://{$server}/{$folder}", __FUNCTION__, __FILE__, __LINE__, "import", $GLOBALS["SCHEDULE_ID"]);
        return false;
    }
    return true;
}