-
-
Save yashodhank/d204b0b48de69c553d794fa679483aa0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# "server":{"host":"x","port":22,"username":"x","password":"x","path":"\\/root\\/back","type":"scp","email":"[email protected]"} | |
function backup($user) { | |
global $config; | |
$postdata = http_build_query(array('cpanel_jsonapi_user' => $user, | |
'cpanel_jsonapi_module' => 'Fileman', | |
'cpanel_jsonapi_func' => 'fullbackup', | |
'cpanel_jsonapi_apiversion' => '1', | |
'arg-0' => $config['server']['type'], | |
'arg-1' => $config['server']['host'], | |
'arg-2' => $config['server']['username'], | |
'arg-3' => $config['server']['password'], | |
'arg-4' => $config['server']['email'], | |
'arg-5' => $config['server']['port'], | |
'arg-6' => $config['server']['path']), '', '&'); | |
$header = array('Authorization: WHM ' . $config['info']['username'] . ':' . preg_replace("/(\n|\r|\\s)/", '', $config['info']['key']) . "\r\n" . | |
"Content-Type: application/x-www-form-urlencoded\r\n" . | |
"Content-Length: " . strlen($postdata) . "\r\n" . "\r\n" . $postdata); | |
$curl = curl_init(); | |
curl_setopt_array($curl, array(CURLOPT_SSL_VERIFYPEER => 0, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_SSL_VERIFYHOST => 0, | |
CURLOPT_URL => 'https://' . $config['info']['server'] . ':2087/json-api/cpanel', | |
CURLOPT_BUFFERSIZE => 131072, | |
CURLOPT_HTTPHEADER => $header, | |
CURLOPT_POST => 1)); | |
$info = (array)json_decode(curl_exec($curl), TRUE); | |
curl_close($curl); | |
if (!isset($info['event'])) | |
return error(sprintf('[%s] %s', $user, 'Did not get an valid callback')); | |
if (intval($info['event']) != 1) | |
return error(sprintf('[%s] %s', $user, 'Event apperently went wrong')); | |
if (!empty($info['error'])) | |
return error($info['error']); | |
else { | |
error('Backup process started.', 1, 'success'); | |
if (isset($config['backup'][$user])) { | |
$config['backup'][$user]['last'] = time(); | |
write_conf($config, FALSE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment