-
Notifications
You must be signed in to change notification settings - Fork 49
Implement backup management #26
Comments
Backup management is not implemented. PRs welcome. |
I also need this feature. I'm trying to fully automate website creation. I have a default backup that I modify its content (with a C# app I've written) so that it works with the new user. I've been using it for a while but there are still time consuming steps I need to take. For example, user creation, deleting default files in public_html, transfering the modified backup to the server and restoring it. I've figured out how to create/delete user and delete default files in public_html. Now I'm working on transferring the backup to the server. It would be nice to also do the restoring with the API. |
We're currently not actively extending this library as we're not actually using it ourselves anymore. I still do active maintenance and perform updates though, and will review/merge PRs as offered. |
I've recently had time to experiment with I've just wrapped my head around authorization and running the API commands. So I can't provide a PR for this project, yet. /* ==================== HELPER FUNCTIONS ==================== */
function param_serialize($array) {
$pairs = [];
foreach ($array as $key => $value) {
$pairs[] = "$key=" . urlencode($value);
}
return join("&", $pairs);
}
function request_str($method = "GET", $path, $parameters, $headers) {
$path .= "?" . param_serialize($parameters);
$request = $method . " ". $path . " HTTP/1.1\r\n";
foreach ($headers as $key => $value) {
$request .= $key . ": " . $value . "\r\n";
}
return $request . "\r\n";
}
function parse_response($str) {
$response = [
"raw" => $str,
"protocol" => null,
"status" => null,
"headers" => [],
"content" => null,
];
preg_match("/(HTTP\/.*?)\s/", $str, $protocol_match);
$response["protocol"] = $protocol_match[1];
preg_match("/HTTP\/.*?\s(.*?)$/m", $str, $status_match);
$response["status"] = $status_match[1];
$parts = preg_split("/\r?\n\r?\n/", $str);
$headers = preg_split("/\r?\n/", $parts[0]);
array_shift($headers);
$headers_temp = [];
foreach ($headers as $value) {
$pair = explode(": ", $value);
$headers_temp[$pair[0]] = $pair[1];
}
foreach ($headers_temp as $key => $value) {
$response["headers"][$key] = $value;
}
$response["content"] = $parts[1];
return $response;
}
function parse_da_content($str) {
$content = [
"error" => null,
"text" => null,
"details" => null,
];
preg_match("/error=(\d+)/", $str, $error_matches);
$content["error"] = $error_matches[1];
preg_match("/text=(.*?)&/", $str, $text_matches);
$content["text"] = $text_matches[1];
preg_match("/details=(.*)/s", $str, $details_matches);
$content["details"] = $details_matches[1];
$content["details"] = str_replace("<br>", "", $content["details"]);
$content["details"] = str_replace("'", "'", $content["details"]);
$content["details"] = preg_split("/\r?\n/", $content["details"]);
$content["details"] = array_values(array_filter($content["details"], function ($line) { return $line != ""; }));
return $content;
}
/* ==================== SETUP ==================== */
$server = [
"ip" => "_SERVER_IP_",
"port" => 2222,
];
$direct_admin = [
"username" => "_DA_USERNAME_",
"password" => "_DA_PASSWORD_",
];
$headers = [
"Host" => "{$server["ip"]}:{$server["port"]}",
"User-Agent" => "Socket",
"Accept" => "*/*",
"Connection" => "Close",
"Authorization" => "Basic " . base64_encode("{$direct_admin["username"]}:{$direct_admin["password"]}"),
];
$parameters = [
"action" => "restore",
"restore_submit" => "Submit",
// these values are entered by default
// so they should be passed too?
"where" => "local",
"local_path" => "/home/admin/user_backups",
"ip_choice" => "file",
// this requires further examination
// probably, selectX and archive order should match
"select3" => "_ARCHIVE_NAME_",
];
$response = null;
$request = request_str("GET", "/CMD_API_ADMIN_BACKUP", $parameters, $headers);
/* ==================== SOCKET ==================== */
$socket = @fsockopen($server["ip"], $server["port"], $socket_errno, $socket_errstr, 10);
fwrite($socket, $request);
$status = socket_get_status($socket);
while (!feof($socket) && !$status['timed_out']) {
$response .= fgets($socket, 1024);
}
fclose($socket);
$response = parse_response($response);
$response["content"] = parse_da_content($response["content"]);
print_r($response); |
Hi,
Omines really help me a lot, Please help me backup website with code omines DA?
Thanks
The text was updated successfully, but these errors were encountered: