function MountComputerRemote($uid, $ip, $username, $password, $sourcefile)
{
    $uidPoint = str_replace("\$", "", $uid);
    $sourcefile_base = basename($sourcefile);
    $GLOBALS["MOUNT_POINT"] = "/opt/artica/mounts/remote-{$uidPoint}";
    @mkdir($GLOBALS["MOUNT_POINT"], null, true);
    $unix = new unix();
    $mount_bin = $unix->find_program("mount");
    if ($mount_bin == null) {
        $GLOBALS[$uid]["EVENTS"][] = "[{$username}/{$ip}]:: mount program, no such file";
        return false;
    }
    $mount = new mount("/var/log/artica-postfix/remote-install-{$uidPoint}.debug");
    if (!$mount->ismounted($GLOBALS["MOUNT_POINT"])) {
        $GLOBALS[$uid]["EVENTS"][] = "[{$username}/{$ip}]:: Mount point is not mounted, mount it";
        $GLOBALS[$uid]["EVENTS"][] = "[{$username}/{$ip}]:: Mount c\$ on {$uidPoint} [{$ip}]";
        $cmd = "{$mount_bin} -t smbfs -o username={$username},password={$password} //{$ip}/c\$ {$GLOBALS["MOUNT_POINT"]} 2>&1";
        exec($cmd, $results);
        while (list($index, $line) = each($results)) {
            if (trim($line) == null) {
                continue;
            }
            $GLOBALS[$uid]["EVENTS"][] = $line;
        }
    } else {
        $GLOBALS[$uid]["EVENTS"][] = "[{$username}/{$ip}]:: Mount point is mounted";
    }
    if (!$mount->ismounted($GLOBALS["MOUNT_POINT"])) {
        return false;
    }
    $GLOBALS["MOUNTED_PATH"] = "{$GLOBALS["MOUNT_POINT"]}/tmp/ocs-agent";
    if (!is_dir($GLOBALS["MOUNTED_PATH"])) {
        @mkdir($GLOBALS["MOUNTED_PATH"], null, true);
    }
    if (!is_dir($GLOBALS["MOUNTED_PATH"])) {
        $GLOBALS[$uid]["EVENTS"][] = "[{$username}/{$ip}]:: c:\tmp\\ocs-agent, permission denied";
        exec("umount -l {$mountpoint}");
        return false;
    }
    unset($results);
    $GLOBALS["WORKING_FILE_PATH"] = "{$GLOBALS["MOUNTED_PATH"]}/{$sourcefile_base}";
    writelogs("WORKING_FILE_PATH={$GLOBALS["WORKING_FILE_PATH"]}", __FUNCTION__, __FILE__, __LINE__);
    $cmd = "/bin/cp -f {$sourcefile} {$GLOBALS["WORKING_FILE_PATH"]} 2>&1";
    writelogs("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
    exec($cmd, $results);
    while (list($index, $line) = each($results)) {
        if (trim($line) == null) {
            continue;
        }
        $GLOBALS[$uid]["EVENTS"][] = $line;
    }
    if (!is_file("{$workingDirectory}/{$sourcefile_base}")) {
        $GLOBALS[$uid]["EVENTS"][] = "[{$username}/{$ip}]:: {$GLOBALS["MOUNTED_PATH"]}\".{$sourcefile_base}, permission denied";
        exec("umount -l {$GLOBALS["MOUNT_POINT"]}");
        return false;
    }
    $GLOBALS["LOCAL_FILE_PATH"] = "c:\\tmp\\ocs-agent\\{$sourcefile_base}";
    $GLOBALS[$uid]["EVENTS"][] = "[{$username}/{$ip}]:: {$GLOBALS["MOUNTED_PATH"]}\\{{$sourcefile_base}}, success";
    return true;
}
예제 #2
0
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}");
    }
}
예제 #3
0
function restore()
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($GLOBALS["VERBOSE"]) {
        echo "PID: {$pidfile}\n";
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        $TTL = $unix->PROCESS_TTL($pid);
        if ($TTL < 240) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    $hostname = $unix->hostname_g();
    progress(10, "{mounting}");
    if (!restore_TestNas()) {
        system_admin_events("Mounting NAS filesystem report false", __FUNCTION__, __FILE__, __LINE__);
        progress(100, "{failed}");
        return;
    }
    $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");
    $mountPoint = "/mnt/BackupArticaRestoreNAS";
    $BackupArticaRestoreNASFolderSource = str_replace("\\", "/", $BackupArticaRestoreNASFolderSource);
    $sourceDir = "{$mountPoint}/{$BackupArticaRestoreNASFolderSource}";
    $sourceDir = str_replace("//", "/", $sourceDir);
    if (!is_file("{$sourceDir}/BKVERSION.txt")) {
        progress(100, "{failed} BKVERSION.txt no such file");
        $mount = new mount("/var/log/artica-postfix/backup.debug");
        if ($mount->ismounted($mountPoint)) {
            $mount->umount($mountPoint);
        }
        return;
    }
    $time = trim(@file_get_contents("{$sourceDir}/BKVERSION.txt"));
    progress(15, "{backup} " . date("Y-m-d H:i:s"));
    progress(20, "{restoring_ldap_database}, {please_wait}...");
    Restore_ldap($sourceDir);
    progress(40, "{restoring_artica_settings}, {please_wait}...");
    restore_artica_settings($sourceDir);
    progress(50, "{restoring_artica_databases}, {please_wait}...");
    restore_artica_backup($sourceDir);
    progress(60, "{restoring_artica_databases}, {please_wait}...");
    restore_ocsweb($sourceDir);
    progress(80, "{restoring_artica_databases}, {please_wait}...");
    restore_squidlogs($sourceDir);
    progress(82, "{restoring} PowerDNS, {please_wait}...");
    restore_powerdns($sourceDir);
    progress(90, "{reconfigure_server}, {please_wait}...");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $php = $unix->LOCATE_PHP5_BIN();
    if (is_file($squidbin)) {
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    }
    progress(100, "{success}");
    $mount = new mount("/var/log/artica-postfix/backup.debug");
    if ($mount->ismounted($mountPoint)) {
        $mount->umount($mountPoint);
    }
    if ($BackupArticaRestoreNetwork == 1) {
        $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php --build");
    }
    return;
}
예제 #4
0
function is_media_mounted()
{
    $mount = new mount();
    return $mount->ismounted("/media/cdrom0");
}
예제 #5
0
function usb_umount($uuid,$user){
	$usb=new usb($uuid);
	$unix=new unix();
	writelogs("Umount $uuid ($usb->TYPE) from $user",__FUNCTION__,__FILE__,__LINE__);
	$path="/media/$uuid";
	$mount=new mount();
	if(!$mount->ismounted($path)){exit(0);}
	$umount_bin=$unix->find_program("umount");
	exec("$umount_bin -l $path 2>&1",$results);
	while (list ($key, $line) = each ($results)){writelogs("$line",__FUNCTION__,__FILE__,__LINE__);}
	if(!$mount->ismounted($path)){exit(0);}
	exit(1);
	
}
예제 #6
0
function smbmount($host,$username,$password,$cmdline){

	if($username==null){
		events("smbmount(): using no user and password for remote connection is not supported");
		return false;
	}
	@mkdir("/opt/artica/mount/$host");
	$mount_point="/opt/artica/mount/$host";
	$f=new mount("/var/log/artica-postfix/computer-scan.debug");
	
	if(!$f->ismounted($mount_point)){
		events("smbmount(): not mounted...");
		$password_hidden=preg_replace("#.*#","*",$password);
		events("smbmount(): using $username $password_hidden\n");
	
		if($username<>null){$options=" -o username=$username,password=$password";}
		$cmd="mount -t smbfs$options //$host/c$ /opt/artica/mount/$host";
		events("smbmount(): $cmd");
		exec($cmd);
		
	}
	if($f->ismounted($mount_point)){
			events("smbmount(): $cmdline $mount_point");
			system("$cmdline $mount_point &");
			return true;
		}	
	
}
예제 #7
0
function exec_webdav()
{
    $mount = new mount();
    $unix = new unix();
    $mount_point = $GLOBALS["MOUNT_POINT"];
    @mkdir($mount_point, 0755, true);
    $server = $GLOBALS["CyrusBackupNas"]["WEBDAV_SERVER"];
    $username = $GLOBALS["CyrusBackupNas"]["WEBDAV_USER"];
    $password = $GLOBALS["CyrusBackupNas"]["WEBDAV_PASSWORD"];
    $path = $GLOBALS["CyrusBackupNas"]["WEBDAV_DIR"];
    if ($mount->ismounted($mount_point)) {
        $mount->umount($mount_point);
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "davfs:WEBDAV_DIR...: {$path}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "davfs:WEBDAV_SERVER: {$server}\n";
    }
    if (!$mount->davfs_mount($mount_point, $server, $username, $password, $path)) {
        if ($GLOBALS["VERBOSE"]) {
            echo $mount->events_compile() . "\n";
        }
        cyrus_admin_mysql(0, "Unable to connect to {$server}", $mount->events_compile(), __FILE__, __LINE__);
        return;
    }
    $path = $mount->davfs_path($mount_point, $server, $username, $password, $path);
    if ($GLOBALS["VERBOSE"]) {
        echo "davfs_path: {$path}\n";
    }
    $hostname = $unix->hostname_g();
    $GLOBALS["DIRBYTES"] = date("YmdH");
    $GLOBALS["MOUNTED_PATH__BACKUPDIR"] = "{$GLOBALS["MOUNT_POINT"]}/{$path}/{$hostname}";
    $GLOBALS["MOUNTED_PATH_FINAL"] = "{$GLOBALS["MOUNT_POINT"]}/{$path}/{$hostname}/{$GLOBALS["DIRBYTES"]}";
    $GLOBALS["MOUNTED_PATH_FINAL"] = str_replace("//", "/", $GLOBALS["MOUNTED_PATH_FINAL"]);
    if ($GLOBALS["VERBOSE"]) {
        echo "MOUNTED_PATH_FINAL: {$GLOBALS["MOUNTED_PATH_FINAL"]}\n";
    }
    if (!is_dir($GLOBALS["MOUNTED_PATH_FINAL"])) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Create -> {$GLOBALS["MOUNTED_PATH_FINAL"]}\n";
        }
        @mkdir($GLOBALS["MOUNTED_PATH_FINAL"], 0755, true);
        if (!is_dir($GLOBALS["MOUNTED_PATH_FINAL"])) {
            cyrus_admin_mysql(0, "Unable to backup: Permission denied on WebDAV resource {$server}", "For creating directory {$GLOBALS["MOUNTED_PATH_FINAL"]}", __FILE__, __LINE__);
            killNas();
            return;
        }
    }
    $t = time();
    @touch("{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}");
    if (!is_file("{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}")) {
        cyrus_admin_mysql(0, "Unable to backup: Permission denied on WebDAV", "resource {{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}}", __FILE__, __LINE__);
        killNas();
        return;
    }
    @unlink("{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}");
    if ($GLOBALS["VERBOSE"]) {
        echo "backup_ldap():\n";
    }
    backup_ldap();
    if ($GLOBALS["VERBOSE"]) {
        echo "backup_cyrus():\n";
    }
    backup_cyrus();
    remove_containers();
    killNas();
}
예제 #8
0
function smbmount($host, $username, $password, $cmdline)
{
    if ($username == null) {
        events("smbmount(): using no user and password for remote connection is not supported");
        return false;
    }
    @mkdir("/opt/artica/mount/{$host}");
    $mount_point = "/opt/artica/mount/{$host}";
    $f = new mount("/var/log/artica-postfix/computer-scan.debug");
    if (!$f->ismounted($mount_point)) {
        events("smbmount(): not mounted...");
        $password_hidden = preg_replace("#.*#", "*", $password);
        events("smbmount(): using {$username} {$password_hidden}\n");
        if ($username != null) {
            $options = " -o username={$username},password={$password}";
        }
        $cmd = "mount -t smbfs{$options} //{$host}/c\$ /opt/artica/mount/{$host}";
        events("smbmount(): {$cmd}");
        exec($cmd);
    }
    if ($f->ismounted($mount_point)) {
        events("smbmount(): {$cmdline} {$mount_point}");
        system("{$cmdline} {$mount_point} &");
        return true;
    }
}
예제 #9
0
function winexe_umount($workingDirectory)
{
    events("unmounting and cleaning....");
    shell_exec("/bin/rm -rf {$workingDirectory}");
    events(@file_get_contents($logfile));
    @unlink($logfile);
    exec("umount -l /opt/artica/mounts/remote-install");
    $mount = new mount();
    if (!$mount->ismounted("/opt/artica/mounts/remote-install")) {
        events("unmounted ....");
    }
}
예제 #10
0
function killNas()
{
    $sock = new sockets();
    $mount = new mount($GLOBALS["LOGFILE"]);
    $mountPoint = "/mnt/SquidImportLogs";
    if ($mount->ismounted($mountPoint)) {
        $mount->umount($mountPoint);
    }
}
예제 #11
0
function CreateHD()
{
    $sock = new sockets();
    $unix = new unix();
    $Config = unserialize($sock->GET_INFO("NewCacheCenterWizard"));
    if (!is_array($Config)) {
        echo "Corrupted configuration...\n";
        build_progress("{failed}", 110);
        return;
    }
    if (!isset($Config["dev"])) {
        echo "Corrupted configuration...\n";
        build_progress("{failed}", 110);
        return;
    }
    $dev = $Config["dev"];
    if ($dev == null) {
        echo "Corrupted configuration...\n";
        build_progress("{failed}", 110);
        return;
    }
    $size = $Config["size"];
    $oct = intval($Config["oct"]);
    build_progress("{checking} {$dev} {$size}", 20);
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{building_partition} {$dev} {$size}", 20);
    $explodedDev = basename($dev);
    $Label = "Cache{$explodedDev}";
    $mount = $unix->find_program("mount");
    $cpu = $Config["CPU"];
    $mount = new mount();
    $targetMountPoint = $unix->isDirInFsTab("/media/{$Label}");
    echo "Target in fstab = {$targetMountPoint}\n";
    if ($targetMountPoint == null) {
        system("{$php} /usr/share/artica-postfix/exec.system.build-partition.php --full \"{$dev}\" \"{$Label}\" \"ext4\" --bywizard");
    } else {
        build_progress("{building_partition} {$targetMountPoint}", 20);
    }
    if (!$mount->ismounted("/media/{$Label}")) {
        echo "/media/{$Label} is not mounted !!! (1/2)...\n";
        shell_exec("{$mount} /media/{$Label}");
        if (!$mount->ismounted("/media/{$Label}")) {
            echo "/media/{$Label} is not mounted !!! (2/2)...\n";
            build_progress("{failed}", 110);
            return;
        }
    }
    echo "Testing /media/{$Label}/proxy-caches\n";
    if (!is_dir("/media/{$Label}/proxy-caches")) {
        @mkdir("/media/{$Label}/proxy-caches", 0755, true);
    }
    if (!is_dir("/media/{$Label}/proxy-caches")) {
        echo "/media/{$Label}/proxy-caches permissions denied\n";
        build_progress("{failed}", 110);
        return;
    }
    @chown("/media/{$Label}/proxy-caches", "squid");
    @chgrp("/media/{$Label}/proxy-caches", "squid");
    $q = new mysql();
    if (!$q->FIELD_EXISTS("squid_caches_center", "wizard", "artica_backup")) {
        $sql = "ALTER TABLE `squid_caches_center` ADD `wizard` smallint NOT NULL DEFAULT 0";
        $q->QUERY_SQL($sql, "artica_backup");
        if (!$q->ok) {
            echo "{$q->mysql_error}\n{$sql}\n";
            build_progress("{failed} MySQL error", 110);
            return;
        }
    }
    build_progress("{configuring_caches}", 90);
    echo "Configuring caches\n";
    $oct_free = $oct * 0.8;
    $oct_small = $oct_free * 0.3;
    $oct_big = $oct_free * 0.7;
    echo "BIG: {$oct_free}*0.7; = {$oct_big}\n";
    $oct_small = $oct_small / 1000;
    $oct_small = round($oct_small / 1000);
    $oct_big = $oct_big / 1000;
    $oct_big = round($oct_big / 1000);
    if ($oct_big == 0) {
        echo "{$q->mysql_error}\n{$sql}\n";
        build_progress("{failed} Erro => 0 for big cache", 110);
        return;
    }
    echo "Cache1 - Small {$oct_small}MB\n";
    echo "Cache2 - Big {$oct_big}MB\n";
    $Cache_small_name = "{$explodedDev} - small - CPU#{$cpu}";
    $Cache_small_path = "/media/{$Label}/proxy-caches/small-cpu{$cpu}";
    $Cache_big_name = "{$explodedDev} - big - CPU#{$cpu}";
    $Cache_big_path = "/media/{$Label}/proxy-caches/big-cpu{$cpu}";
    @chown($Cache_small_path, "squid");
    @chgrp($Cache_small_path, "squid");
    @chown($Cache_big_path, "squid");
    @chgrp($Cache_big_path, "squid");
    $q->QUERY_SQL("INSERT IGNORE INTO squid_caches_center\n\t(cachename,cpu,cache_dir,cache_type,cache_size,cache_dir_level1,cache_dir_level2,enabled,percentcache,usedcache,zOrder,min_size,max_size,wizard)\n\tVALUES('{$Cache_small_name}',{$cpu},'{$Cache_small_path}','aufs','{$oct_small}','16','256',1,0,0,1,0,512,1)", "artica_backup");
    if (!$q->ok) {
        echo "{$q->mysql_error}\n{$sql}\n";
        build_progress("{failed} MySQL error", 110);
        return;
    }
    $q->QUERY_SQL("INSERT IGNORE INTO squid_caches_center\n\t(cachename,cpu,cache_dir,cache_type,cache_size,cache_dir_level1,cache_dir_level2,enabled,percentcache,usedcache,zOrder,min_size,max_size,wizard)\n\tVALUES('{$Cache_big_name}',{$cpu},'{$Cache_big_path}','aufs','{$oct_big}','16','256',1,0,0,1,512,3072000,1)", "artica_backup");
    if (!$q->ok) {
        echo "{$q->mysql_error}\n{$sql}\n";
        build_progress("{failed} MySQL error", 110);
        return;
    }
    build_progress("{building_caches}", 90);
    system("{$php} /usr/share/artica-postfix/exec.squid.verify.caches.php --bywizard");
    build_progress("{building_caches} {success}", 100);
    sleep(3);
    build_progress("{building_caches} {success}", 100);
}