function ScanComputers_deploy()
{
    $cmp = new computers($GLOBALS[__FILE__]["uid"]);
    $sock = new sockets();
    $unix = new unix();
    setComputerProgress(10);
    $hash = unserialize(base64_decode($sock->GET_INFO("GlobalNetAdmin")));
    $global_user = $hash["GLOBAL"]["username"];
    $global_password = $hash["GLOBAL"]["password"];
    if ($MinutesToWait == 0) {
        $MinutesToWait = 5;
    }
    $sql = "SELECT * FROM computers_storage WHERE ID='{$GLOBALS[__FILE__]["PACKAGEID"]}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    task_computers_events("Deploy {$ligne["PUBLISHER"]} {$ligne["NAME"]} {$ligne["version"]}");
    $source_path = $ligne["local_path"];
    $commandline = $ligne["command_line"];
    if (!is_file($source_path)) {
        task_computers_events("Source {$source_path} no such file");
        task_events("{$ligne["uid"]} Failed");
        setComputerStatus(-1);
        setComputerProgress(100);
        return;
    }
    if ($global_user != null) {
        $users[] = array($global_user, $global_password);
    }
    $ini = new Bs_IniHandler();
    $ini->loadString($cmp->ComputerCryptedInfos);
    $global_user = $ini->_params["ACCOUNT"]["USERNAME"];
    $global_password = $ini->_params["ACCOUNT"]["PASSWORD"];
    if ($global_user != null) {
        $users[] = array($global_user, $global_password);
    }
    task_computers_events("using " . count($users) . " potentials users");
    if (count($users) == 0) {
        task_computers_events("no administrator account set for this computer.");
        task_events("{$ligne["uid"]} Failed");
        setComputerStatus(-1);
        setComputerProgress(100);
        return;
    }
    if (!preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+#", $cmp->ComputerIP)) {
        $cmp->ComputerIP = null;
    }
    $ip_src = $cmp->ComputerIP;
    $realname = $cmp->ComputerRealName;
    $cmp->ComputerIP = $unix->HostToIp($realname);
    if ($cmp->ComputerIP == null) {
        $cmp->ComputerIP = $ip_src;
    }
    task_computers_events("{$realname} resolved to {$cmp->ComputerIP}");
    setComputerProgress(30);
    $pp = new ping($cmp->ComputerIP);
    if (!$pp->Isping()) {
        task_computers_events("Failed to ping  {$realname} ({$cmp->ComputerIP}), aborting process.");
        return false;
    }
    setComputerProgress(40);
    task_computers_events("Mount the admin\$ to targeted {$realname} computer...");
    $mount = new mount();
    $mounted = false;
    while (list($index, $hash_credentials) = each($users)) {
        if ($mount->MountComputerRemote($realname, $cmp->ComputerIP, $hash_credentials[0], $hash_credentials[1])) {
            task_computers_events("Success connecting to the {$realname} computer");
            $mounted = true;
            $username = $hash_credentials[0];
            $password = $hash_credentials[1];
        } else {
            task_computers_events("Failed connecting to the {$realname} computer using {$hash_credentials[0]}");
        }
    }
    if (!$mounted) {
        task_events("{$ligne["uid"]} Failed");
        setComputerStatus(-1);
        setComputerProgress(100);
        return false;
    }
    $mounted_path = $mount->mount_point;
    @mkdir($mounted . "/artica_remote_install", null, true);
    if (!is_dir($mounted . "/artica_remote_install")) {
        task_computers_events("{$mounted}/artica_remote_install permission denied");
        shell_exec("umount -l {$mounted_path}");
        setComputerStatus(-1);
        setComputerProgress(100);
        return false;
    }
    if (!@copy($source_path, $mounted . "/artica_remote_install/" . basename($source_path))) {
        task_computers_events("{$mounted}/artica_remote_install permission denied will copy source file");
        shell_exec("umount -l {$mounted_path}");
        setComputerStatus(-1);
        setComputerProgress(100);
        return false;
    }
    $execute_path = "C:\\tmp\\artica_remote_install\\" . basename($source_path) . " {$commandline}";
    task_computers_events("runtask:: execute {$execute_path} on target computer");
    $logfile = "/tmp/" . md5($cmp->ComputerIP);
    $cmd = "/usr/bin/winexe -d 2 --user={$username} --password={$password} --interactive=1 --runas={$username}%{$password} --uninstall //{$cmp->ComputerIP} \"{$execute_path}\" >{$logfile} &";
    exec($cmd);
    if (!WaitWinexeForSecondes($MinutesToWait, $cmp->ComputerIP)) {
        events("runtask:: Time-out !!");
        winexe_umount($workingDirectory);
        return false;
    }
    if ($ExecuteAfter != null) {
        events("runtask:: execute {$ExecuteAfter} on target computer");
        $cmd = "/usr/bin/winexe -d 2 --user={$username} --password={$password} --interactive=1 --runas={$username}%{$password} --uninstall //{$cmp->ComputerIP} {$ExecuteAfter} >{$logfile} &";
        exec($cmd);
        if (!WaitWinexeForSecondes($MinutesToWait, $cmp->ComputerIP)) {
            events("runtask:: execute {$ExecuteAfter} time-out on target computer");
        }
    }
    winexe_umount($workingDirectory);
    events("runtask:: Done...");
    return true;
}
<?php

header('Content-type: application/json');
chdir("../..");
chdir("database");
require_once "computers.php";
require_once "users.php";
/**
 * DESCRIPTION: Notifies that the computer is starting the budibox application
 * PARAMETERS: api/computers/notifyStartup.php <apikey> <user> <computer>
 */
if (isset($_GET["apikey"]) and isset($_GET["user"]) and isset($_GET["computer"])) {
    $auth = (string) $_GET['apikey'];
    if ($auth != $apikey) {
        echo json_encode(array("result" => "permissionDenied"));
    } else {
        $user = (string) $_GET["user"];
        $computer = (string) $_GET["computer"];
        if (!userExists($user)) {
            echo json_encode(array("result" => "invalidUser"));
        } else {
            if (!computerExists($user, $computer)) {
                createComputer($user, $computer);
            }
            setComputerStatus($user, $computer, "on");
            echo json_encode(array("result" => "ok"));
        }
    }
} else {
    echo json_encode(array("result" => "misingParams"));
}