From fd4983badc222deb31e3707e20fc92d206790982 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Apr 2012 17:13:50 +0200 Subject: [PATCH] backup via /backup --- htdocs/application/config/stikked.php | 9 +++++ htdocs/application/controllers/backup.php | 43 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 htdocs/application/controllers/backup.php diff --git a/htdocs/application/config/stikked.php b/htdocs/application/config/stikked.php index 6f82e77..9aa9555 100755 --- a/htdocs/application/config/stikked.php +++ b/htdocs/application/config/stikked.php @@ -46,6 +46,15 @@ $config['bitly_apikey'] = ''; **/ $config['cron_key'] = ''; +/** + * Credentials for the backup URL + * + * Basic auth user & pass for the backup URL, accessible via http://yoursite.com/backup + * +**/ +$config['backup_user'] = ''; +$config['backup_pass'] = ''; + /** * Pastes Per Page * diff --git a/htdocs/application/controllers/backup.php b/htdocs/application/controllers/backup.php new file mode 100755 index 0000000..0f42026 --- /dev/null +++ b/htdocs/application/controllers/backup.php @@ -0,0 +1,43 @@ +config->item('backup_user'); + $pass = $this->config->item('backup_pass'); + + if ($user == '' || $pass == '' || !isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pass) + { + header('WWW-Authenticate: Basic realm="Backup"'); + header('HTTP/1.0 401 Unauthorized'); + exit; + } + } + + function index() + { + + // Load the DB utility class + $this->load->dbutil(); + + // Backup your entire database and assign it to a variable + $backup = & $this->dbutil->backup(); + + // Load the download helper and send the file to your desktop + $this->load->helper('download'); + force_download('stikked.gz', $backup); + } +}