Skip to content

Instantly share code, notes, and snippets.

@johanneswuerbach
Created May 7, 2012 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanneswuerbach/2626652 to your computer and use it in GitHub Desktop.
Save johanneswuerbach/2626652 to your computer and use it in GitHub Desktop.
Start Confixx backups
<?php
// Start Confixx backups
// Created by Johannes Würbach
// http://nerd20.de
/* SETTINGS */
$confixx_user = "web123"; // Your username
$confixx_password = "your_password"; // Your password
$confixx_host = "your_host"; // Host of your confixx installation
// What should be backuped?
$backup_html = true;
$backup_files = true;
$backup_mail = true;
$backup_mysql = true;
// General
$print_responses = true;
$backup = array();
if ($backup_html) {
$backup[] = "html";
}
if ($backup_files) {
$backup[] = "files";
}
if ($backup_mail) {
$backup[] = "mail";
}
if ($backup_mysql) {
$backup[] = "mysql";
}
if (empty($backup)) {
echo "Nothing to backup.\n";
}
else {
$fp = fsockopen($confixx_host, 80, $errno, $errstr, 30);
if (!$fp) {
echo $errstr . " (" . $errno . ")\n";
}
else {
// Login
$login_params = array(
"username" => $confixx_user,
"password" => $confixx_password
);
$login_query = http_build_query($login_params, '', '&');
$out = "POST /login.php HTTP/1.0\r\n";
$out .= "Host: " . $confixx_host . "\r\n";
$out .= "Connection: close\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: " . strlen($login_query) . "\r\n";
$out .= "\r\n";
$out .= $login_query . "\r\n";
fwrite($fp, $out);
$response = '';
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
fclose($fp);
preg_match_all('#Set-Cookie: (.*);#', $response, $matches);
if ($print_responses) {
echo $response . "\n\r";
}
// Start backup
$backup_params = array(
"destination" => "upload",
"selectAll" => 1,
"action" => "backup",
"backup" => $backup
);
$out = "GET /user/" . $confixx_user . "/tools_backup2.php?".http_build_query($backup_params, '', '&')." HTTP/1.0\r\n";
$out .= "Host: " . $confixx_host . "\r\n";
$out .= "Connection: close\r\n";
$out .= "Cookie: " . implode("; ", $matches[1]) . "\r\n";
$out .= "\r\n";
$fp = fsockopen($confixx_host, 80, $errno, $errstr, 30);
fwrite($fp, $out);
$response = "";
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
fclose($fp);
if ($print_responses) {
echo $response . "\n\r";
}
// Logout
$out = "GET /logout.php?".http_build_query(array("user" => $confixx_user), '', '&')." HTTP/1.0\r\n";
$out .= "Host: " . $confixx_host . "\r\n";
$out .= "Connection: close\r\n";
$out .= "Cookie: " . implode("; ", $matches[1]) . "\r\n";
$out .= "\r\n";
$fp = fsockopen($confixx_host, 80, $errno, $errstr, 30);
fwrite($fp, $out);
$response = "";
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
fclose($fp);
if ($print_responses) {
echo $response . "\n\r";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment