Exemplo n.º 1
0
function mount_ssh($pattern, $ID, $testwrite = true)
{
    $backup = new backup_protocols();
    $unix = new unix();
    $rsync = $unix->find_program("rsync");
    $umount = $unix->find_program("umount");
    $cp = $unix->find_program("cp");
    $touch = $unix->find_program("touch");
    $array = $backup->extract_ssh_protocol($pattern);
    if (!is_array($array)) {
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: ssh 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_ssh())", __LINE__);
    include_once dirname(__FILE__) . "/ressources/class.mount.inc";
    backup_events($ID, "initialization", "INFO, mount({$GLOBALS["ADDLOG"]})", __LINE__);
    $mount = new mount($GLOBALS["ADDLOG"]);
    $mount = new mount($GLOBALS["ADDLOG"]);
    if (!$mount->ismounted($mount_path)) {
        backup_events($ID, "initialization", "INFO, local mount point {$mount_path} not mounted (mount_ssh())", __LINE__);
        @mkdir($mount_path, null, true);
    }
    if (!$mount->ssh_mount($mount_path, $array["SERVER"], $array["USER"], $array["PASSWORD"], $array["FOLDER"])) {
        backup_events($ID, "initialization", "ERROR, unable to mount target server (ssh_mount({$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("{$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"] = "{$cp} -ru {SRC_PATH} {NEXT}";
        }
        $GLOBALS["COMMANDLINE_MOUNTED_PATH"] = $mount_path;
        return true;
    } else {
        $logs_touch = implode("<br>", $results_touch);
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: Permissions error ! FAILED", __FUNCTION__, __FILE__, __LINE__);
        backup_events($ID, "initialization", "ERROR, writing test failed", __LINE__);
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: {$logs_touch}", __FUNCTION__, __FILE__, __LINE__);
        writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: umount {$mount_path}", __FUNCTION__, __FILE__, __LINE__);
        exec("{$umount} -l {$mount_path}");
    }
}