Skip to content

Instantly share code, notes, and snippets.

@Zalvie
Last active August 1, 2016 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Zalvie/5592be456141f76af1bf to your computer and use it in GitHub Desktop.
Save Zalvie/5592be456141f76af1bf to your computer and use it in GitHub Desktop.
<?php
# "server":{"host":"x","port":22,"username":"x","password":"x","path":"\\/root\\/back","type":"scp","email":"x@gmail.com"}
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