Example #1
0
function bar_process($vars)
{
    global $barNlc, $barEcho;
    $barNlc = md5(__DIR__ . date('Ymd'));
    $barEcho = false;
    if (!function_exists('bar_vars')) {
        require dirname(__FILE__) . '/bar.php';
    }
    $query = mysql_query("SELECT * FROM `mod_bar` where `status` = 'backingup'");
    if (mysql_num_rows($query)) {
        while ($m = mysql_fetch_assoc($query)) {
            bar_message('check message');
            if (strstr($vars['message'], '_' . $m['username'] . '.tar.gz') && strstr($vars['message'], 'backup-') && strstr($vars['message'], 'pkgacct')) {
                bar_message("Backup confirmation for " . $m['username'] . ': ' . $vars['message'], 'report');
                if ($m['to'] > 0) {
                    $result = bar_restore($m['id'], $m['from'], $m['to'], bar_vars());
                    if ($result['result'] == 1) {
                        bar_message('Restore successful for ' . $m['username'] . ': ' . $result['output'], 'report');
                    } else {
                        bar_message('Restore failed for ' . $m['username'] . ': ' . $result['output'], 'report');
                    }
                } else {
                    bar_message('Backup completed for ' . $m['username'] . ': ' . $vars['message'], 'report');
                    bar_updatestatus($m['username'], 'completed');
                }
            }
        }
    }
    return true;
}
Example #2
0
function bar_apicall2($s, $u, $call, $async = false)
{
    global $cc_encryption_hash;
    if ($s['secure']) {
        $apicall = "https://";
    } else {
        $apicall = "http://";
    }
    $apicall .= $s['ipaddress'] . ":";
    if ($s['secure']) {
        $apicall .= "2087";
    } else {
        $apicall .= "2086";
    }
    $apicall .= "/xml-api/";
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    if ($async) {
        curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
        curl_setopt($curl, CURLOPT_TIMEOUT_MS, 1);
    }
    if ($s['accesshash']) {
        $header[0] = "Authorization: WHM " . $s['username'] . ":" . preg_replace("'(\r|\n)'", "", $s['accesshash']);
    } elseif ($s['password']) {
        $header[0] = "Authorization: Basic " . base64_encode($s['username'] . ":" . decrypt($s['password'], $cc_encryption_hash)) . "\n\r";
    } else {
        bar_message("Fill in accesshash or password for your server " . $s['name']);
        return false;
    }
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    $apicall .= $call;
    $apicall .= '&api.version=1';
    curl_setopt($curl, CURLOPT_URL, $apicall);
    $result = curl_exec($curl);
    curl_close($curl);
    if ($result) {
        $xml = new SimpleXMLElement($result);
        $ret['reason'] = (string) $xml->metadata->reason;
        $ret['result'] = (string) $xml->metadata->result;
        $ret['output'] = $xml->metadata->output->raw;
        $ret['data'] = $xml->data;
        if (!$ret['result']) {
            bar_message($ret['reason']);
        }
        return $ret;
    } else {
        bar_message($ret['reason']);
        return array('result' => 0, 'reason' => 'API call failed');
    }
}