| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @name: DBExport <http://jeenaparadies.net/webdesign/jlog/> |
|---|
| 4 | * @author: Dennis Riehle <selfhtml@riehle-web.com> |
|---|
| 5 | * @version: 1.1 |
|---|
| 6 | * @date: 2006-04-20 |
|---|
| 7 | * @last change: 2008-10-25 by Jeena Paradies <jlog@jeenaparadies.net> |
|---|
| 8 | * @requires: MySQLDBExport <http://tutorial.riehle-web.com/scripts/index.php#mysql> |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | class DBExport extends JlogPlugin { |
|---|
| 12 | var $handling = "download"; ## "server" um Dump Files auf dem Server |
|---|
| 13 | ## zu speichern, "download" um die Dateien zum |
|---|
| 14 | ## Download anzubieten |
|---|
| 15 | function hook_adminContent($output) { |
|---|
| 16 | $output = ""; |
|---|
| 17 | if(isset($_POST['dbexport-init']) AND |
|---|
| 18 | $this->handling == "server") |
|---|
| 19 | { |
|---|
| 20 | $output .= "<pre>Verzeichnisse werden angelegt...\n"; |
|---|
| 21 | mkdir(JLOG_BASEPATH . "backup/"); |
|---|
| 22 | $output .= "Notwendige Dateien werden angelegt...\n"; |
|---|
| 23 | $fp = fopen(JLOG_BASEPATH . "backup/.htaccess", "x"); |
|---|
| 24 | flock($fp, LOCK_EX); |
|---|
| 25 | fwrite($fp, "Order deny,allow\r\nDeny from All"); |
|---|
| 26 | fclose($fp); |
|---|
| 27 | $output .= "Fertig.</pre>\n" |
|---|
| 28 | . "<p>Das Plugin wurde erfolgreich eingerichtet, sie es jetzt " |
|---|
| 29 | . "<a href=\"" . $_SERVER['REQUEST_URI'] . "\">nutzen</a></p>\n"; |
|---|
| 30 | } |
|---|
| 31 | elseif((!is_dir(JLOG_BASEPATH . "backup/") OR !file_exists(JLOG_BASEPATH . "backup/.htaccess")) |
|---|
| 32 | AND $this->handling == "server") |
|---|
| 33 | { |
|---|
| 34 | $output .= "<p>Dieses Plugin kann SQL-Dumps der MySQL Datenbank erstellen, " |
|---|
| 35 | . "damit im Zweifelsfall die Datenbank aus den Backupdateien wieder " |
|---|
| 36 | . "hergestellt werden kann.</p>\n" |
|---|
| 37 | . "<p>Das Plugin ist z.Z. so eingstellt, dass es die erzeugten " |
|---|
| 38 | . "Dumps auf dem Server im Verzeichnis <code>backup/</code> speichert.</p>\n" |
|---|
| 39 | . "<p>Es scheint, als wäre das Plugin noch nicht initialisiert " |
|---|
| 40 | . "worden. Damit das DBExport Plugin genutzt werden kann, muss " |
|---|
| 41 | . "ein entsprechendes Backup-Verzeichnis angelegt werden.</p>\n" |
|---|
| 42 | . "<p>Wollen Sie DBExport jetzt einrichten?</p>\n" |
|---|
| 43 | . "<form action=\"" . $_SERVER['REQUEST_URI'] . "\" method=\"post\">\n" |
|---|
| 44 | . "<input type=\"submit\" name=\"dbexport-init\" value=\"Einrichten\">\n" |
|---|
| 45 | . "</form>\n"; |
|---|
| 46 | } |
|---|
| 47 | else { |
|---|
| 48 | if(isset($_POST['dbexport-work'])) { |
|---|
| 49 | if(!file_exists(JLOG_BASEPATH . "scripts/MySQLDBExport.class.php") AND |
|---|
| 50 | !file_exists(JLOG_BASEPATH . "scripts/mysqldbexport.class.php")) { |
|---|
| 51 | $output .= "<p><strong>Schwerwiegender Fehler:</strong> " |
|---|
| 52 | . "Die Export-Library konnte nicht gefunden werden. " |
|---|
| 53 | . "Diese Library wird benötigt und muss im <code>scripts/</code> Verzeichnis " |
|---|
| 54 | . "unter dem Namen <code>MySQLDBExport.class.php</code> liegen. " |
|---|
| 55 | . "Sie können sich die Library " |
|---|
| 56 | . "<a href=\"http://tutorial.riehle-web.com/scripts/index.php#mysql\"> " |
|---|
| 57 | . "hier</a> besorgen.</p>\n"; |
|---|
| 58 | } |
|---|
| 59 | else { |
|---|
| 60 | if(file_exists(JLOG_BASEPATH . "scripts/MySQLDBExport.class.php")) { |
|---|
| 61 | require(JLOG_BASEPATH . "scripts/MySQLDBExport.class.php"); |
|---|
| 62 | } |
|---|
| 63 | else { |
|---|
| 64 | require(JLOG_BASEPATH . "scripts/mysqldbexport.class.php"); |
|---|
| 65 | } |
|---|
| 66 | $tables = array(JLOG_DB_PREFIX . "attributes", |
|---|
| 67 | JLOG_DB_PREFIX . "catassign", |
|---|
| 68 | JLOG_DB_PREFIX . "categories", |
|---|
| 69 | JLOG_DB_PREFIX . "comments", |
|---|
| 70 | JLOG_DB_PREFIX . "content"); |
|---|
| 71 | $export = new MySQLDBExport(); |
|---|
| 72 | $export->set_db(JLOG_DB); |
|---|
| 73 | $export->set_newline("\r\n"); |
|---|
| 74 | $dump = $export->make_dump($tables, true); |
|---|
| 75 | if($dump === false) { |
|---|
| 76 | $output .= "<p><strong>Fehler beim Export:</strong> " |
|---|
| 77 | . $export->get_error(); |
|---|
| 78 | } |
|---|
| 79 | else { |
|---|
| 80 | $filename = "export_" . date("Y-m-d_H:i:s") . ".sql"; |
|---|
| 81 | if($this->handling != "server") { |
|---|
| 82 | if(function_exists("gzencode")) { |
|---|
| 83 | $filename .= ".gz"; |
|---|
| 84 | $dump = gzencode($dump, 9); |
|---|
| 85 | $mime = "application/x-gzip"; |
|---|
| 86 | } |
|---|
| 87 | else { |
|---|
| 88 | $mime = "text/plain"; |
|---|
| 89 | } |
|---|
| 90 | $this->senddata($dump, $filename, $mime); |
|---|
| 91 | exit; |
|---|
| 92 | } |
|---|
| 93 | else { |
|---|
| 94 | $fp = fopen(JLOG_BASEPATH . "backup/" . $filename, "w"); |
|---|
| 95 | flock($fp, LOCK_EX); |
|---|
| 96 | fwrite($fp, $dump); |
|---|
| 97 | fclose($fp); |
|---|
| 98 | $output .= "<p>Export der Datenbank war erfolgreich, der Dump wurde in " |
|---|
| 99 | . "<code>/backup/$filename</code> gespeichert.</p>\n"; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | else { |
|---|
| 105 | $output .= "<p>Dieses Plugin kann SQL-Dumps der MySQL Datenbank erstellen, " |
|---|
| 106 | . "damit im Zweifelsfall die Datenbank aus den Backupdateien wieder " |
|---|
| 107 | . "hergestellt werden kann.</p>\n"; |
|---|
| 108 | if($this->handling != "server") { |
|---|
| 109 | $output .= "<p>Das Plugin ist z.Z. so eingestellt, dass es die erstellen " |
|---|
| 110 | . "Dumps zum Download anbietet.</p>\n" |
|---|
| 111 | . "<form action=\"" . $_SERVER['REQUEST_URI'] . "\" method=\"post\">\n" |
|---|
| 112 | . "<input type=\"submit\" name=\"dbexport-work\" value=\"Dump downloaden\">\n" |
|---|
| 113 | . "</form>\n"; |
|---|
| 114 | } |
|---|
| 115 | else { |
|---|
| 116 | $output .= "<p>Das Plugin ist z.Z. so eingstellt, dass es die erzeugten " |
|---|
| 117 | . "Dumps auf dem Server im Verzeichnis <code>backup/</code> speichert.</p>\n" |
|---|
| 118 | . "<form action=\"" . $_SERVER['REQUEST_URI'] . "\" method=\"post\">\n" |
|---|
| 119 | . "<input type=\"submit\" name=\"dbexport-work\" value=\"DB jetzt exportieren\">\n" |
|---|
| 120 | . "</form>\n"; |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | return $output; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | function senddata($data, $filename, $mime) { |
|---|
| 128 | $len = strlen($data); |
|---|
| 129 | header("Content-Type: $mime"); |
|---|
| 130 | header("Content-Disposition: attachment; filename=\"$filename\""); |
|---|
| 131 | header("Accept-Ranges: bytes"); |
|---|
| 132 | header("Content-Length: $len"); |
|---|
| 133 | echo $data; |
|---|
| 134 | return true; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | ?> |
|---|