preserved.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php return array (
  2. 'e22eb7bc89867792aee422bd4f9a12ed' =>
  3. array (
  4. 'criteria' =>
  5. array (
  6. 'name' => 'backupmodx',
  7. ),
  8. 'object' =>
  9. array (
  10. 'name' => 'backupmodx',
  11. 'path' => '{core_path}components/backupmodx/',
  12. 'assets_path' => '{assets_path}components/backupmodx/',
  13. ),
  14. ),
  15. '14564e7dadd27b0e1019825798fd3bde' =>
  16. array (
  17. 'criteria' =>
  18. array (
  19. 'category' => 'BackupMODX',
  20. ),
  21. 'object' =>
  22. array (
  23. 'id' => 18,
  24. 'parent' => 0,
  25. 'category' => 'BackupMODX',
  26. 'rank' => 0,
  27. ),
  28. ),
  29. '81e469d37cdc7a80ae053ae74cdf5164' =>
  30. array (
  31. 'criteria' =>
  32. array (
  33. 'name' => 'BackupMODXWidget',
  34. ),
  35. 'object' =>
  36. array (
  37. 'id' => 50,
  38. 'source' => 0,
  39. 'property_preprocess' => 0,
  40. 'name' => 'BackupMODXWidget',
  41. 'description' => 'Backup MODX Dashboard widget',
  42. 'editor_type' => 0,
  43. 'category' => 18,
  44. 'cache_type' => 0,
  45. 'snippet' => '/**
  46. * BackupMODXWidget snippet for backupmodx extra
  47. *
  48. * Copyright 2015 by Quadro - Jan Dähne info@quadro-system.de
  49. * Created on 12-16-2015
  50. *
  51. * backupmodx is free software; you can redistribute it and/or modify it under the
  52. * terms of the GNU General Public License as published by the Free Software
  53. * Foundation; either version 2 of the License, or (at your option) any later
  54. * version.
  55. *
  56. * backupmodx is distributed in the hope that it will be useful, but WITHOUT ANY
  57. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  58. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  59. *
  60. * You should have received a copy of the GNU General Public License along with
  61. * backupmodx; if not, write to the Free Software Foundation, Inc., 59 Temple
  62. * Place, Suite 330, Boston, MA 02111-1307 USA
  63. *
  64. * @package backupmodx
  65. */
  66. /**
  67. * Description
  68. * -----------
  69. * Backup MODX Dashboard widget
  70. *
  71. * Variables
  72. * ---------
  73. * @var $modx modX
  74. * @var $scriptProperties array
  75. *
  76. * @package backupmodx
  77. **/
  78. // Returns an empty string if user shouldn\'t see the widget
  79. $groups = $modx->getOption(\'groups\', $scriptProperties, \'Administrator\', true);
  80. if (strpos($groups, \',\') !== false) {
  81. $groups = explode(\',\', $groups);
  82. }
  83. if (!$modx->user->isMember($groups)) {
  84. return \'\';
  85. }
  86. //Check if server supports shell-commands
  87. if (!shell_exec("type type")) { return \'Your server does not support shell-commands. Backup not possible.\'; }
  88. $config = $modx->getConfig();
  89. //Get Properties
  90. $tarAlias = $modx->getOption(\'tarAlias\', $scriptProperties, \'tar\', true); //some websites may need a different alias for tar
  91. $excludes = $modx->getOption(\'excludes\', $scriptProperties);
  92. $targetPath = str_replace("{assets_path}", MODX_ASSETS_PATH, $modx->getOption(\'targetPath\', $scriptProperties)); //directory to place the backup
  93. $targetPath = rtrim($targetPath, \'/\').\'/backup\'; //removing trailing slash and adding backup-folder
  94. if(!function_exists("fileLink")) {
  95. function fileLink($file, $title) {
  96. $file_root = MODX_BASE_PATH.str_replace(MODX_BASE_PATH, "", $file);
  97. $file_absolute = MODX_SITE_URL.str_replace(MODX_BASE_PATH, "", $file);
  98. $size = round(filesize($file) / 1000000, 2);
  99. if (file_exists($file_root)){
  100. $file = \'<a href="\'.$file_absolute.\'" target="_blank" download>\'.basename($file).\'</a>\';
  101. }else {
  102. $file = basename($file);
  103. }
  104. return \'<span style="display: inline-block; width: 90px;">\'.$title.\':</span>\'.$file.\' (\'.$size.\' MB)\';
  105. }
  106. }
  107. if (isset($_POST[\'backupMODX\'])) {
  108. set_time_limit(0);
  109. ini_set(\'max_execution_time\', 0);
  110. if (!empty($_POST["mysql"]) or !empty($_POST["files"])){
  111. $base_path = MODX_BASE_PATH;
  112. $core_path = MODX_CORE_PATH;
  113. $date = date("Ymd-His");
  114. $dbase = $modx->getOption(\'dbname\');
  115. $database_server = $config[host];
  116. $database_user = $config[username];
  117. $database_password = $config[password];
  118. $targetSql = "{$targetPath}/{$dbase}_{$date}_mysql.sql";
  119. $targetTar = "{$targetPath}/{$dbase}_{$date}_files.tar";
  120. $targetCom = "{$targetPath}/{$dbase}_{$date}_combined.tar";
  121. $targetTxt = "{$targetPath}/{$dbase}_{$date}_readme.txt";
  122. //Create Folder
  123. system("mkdir $targetPath");
  124. //Create Readme
  125. if (!empty($_POST["note"])){
  126. $fp = fopen($targetTxt,"wb");
  127. fwrite($fp,$_POST["note"]);
  128. fclose($fp);
  129. }
  130. //MySQL- Backup
  131. if (!empty($_POST["mysql"])){
  132. system("mysqldump --host=$database_server --user=$database_user --password=$database_password --databases $dbase --no-create-db --default-character-set=utf8 --result-file={$targetSql}");
  133. //If no mysqldump was possible try:
  134. if (file_exists($targetSql) or filesize($targetSql) <= 0) {
  135. system(sprintf(\'mysqldump --no-tablespaces --opt -h%s -u%s -p"%s" %s --result-file=%s\', $database_server, $database_user, $database_password, $dbase, $targetSql));
  136. }
  137. }
  138. //File-Backup
  139. if (!empty($_POST["files"])){
  140. //creating exclude-files command
  141. if (!empty($excludes)) {
  142. $excludes_array = explode(",", $excludes);
  143. unset($excludes);
  144. foreach ($excludes_array as $exclude){
  145. $excludes .= \' --exclude=\'.$exclude;
  146. }
  147. }
  148. //tar files
  149. system("$tarAlias cf {$targetTar} --exclude=$targetPath --exclude={$core_path}cache/* {$excludes} $base_path $core_path");
  150. //If a note exists add it to the tar-archive
  151. if (file_exists($targetTxt)) {
  152. system("$tarAlias uf {$targetTar} -C $targetPath {$dbase}_{$date}_readme.txt"); //adding note in the root
  153. }
  154. }
  155. //Combine SQL and Files in one archive
  156. if (file_exists($targetSql) and file_exists($targetTar) and filesize($targetSql) > 0) {
  157. system("cp {$targetTar} {$targetCom}"); //copy files-archive
  158. system("$tarAlias uf {$targetCom} -C $targetPath {$dbase}_{$date}_mysql.sql"); //adding sql-file in the root
  159. }
  160. $backup = true;
  161. //Output
  162. if (file_exists($targetSql) and filesize($targetSql) > 0) {
  163. $mysql_link = fileLink($targetSql, \'MySQL\');
  164. }else {
  165. $mysql_link = \'<span style="display: inline-block; width: 90px;">MySQL:</span>No Backup!\';
  166. }
  167. if (file_exists($targetTar)) {
  168. $files_link = fileLink($targetTar, \'Files\');
  169. }else {
  170. $files_link = \'<span style="display: inline-block; width: 90px;">Files:</span>No Backup!\';
  171. }
  172. if (file_exists($targetCom)) {
  173. $combi_link = fileLink($targetCom, \'MySQL & Files\');
  174. }
  175. }
  176. }
  177. //Remove Backups
  178. if (!empty($_POST["removeBackup"])){
  179. if (!empty($_POST["removeBackup"])) {
  180. foreach(glob("$targetPath/*") as $file) {
  181. $extension = pathinfo($file, PATHINFO_EXTENSION);
  182. if (in_array($extension, array("tar", "sql", "txt"))) {
  183. unlink($file);
  184. }
  185. }
  186. rmdir($targetPath);
  187. }
  188. }
  189. if ($backup != true) {
  190. echo \'
  191. <form method="post" action="">
  192. <p>
  193. Backup your MODX-Site:<br><br>
  194. <input type="checkbox" name="mysql" id="mysql" value="1" checked><label for="mysql"> MySQL Database</label><br />
  195. <input type="checkbox" name="files" id="files" value="1" checked><label for="files"> Files</label>
  196. </p>
  197. <br>
  198. <p>
  199. Folder to place files: <strong>\'.$targetPath.\'</strong> <span style="color: grey;">(Editable via Snippet-Properties)</span><br>
  200. </p><br>
  201. <p>Add a readme file: <span style="color: grey;">(txt-file placed in the root)</span></p>
  202. <textarea name="note" style="width:90%; height:40px; display: block; border: 1px solid #ccc; margin: 5px 0 20px 0; padding: 5px;" placeholder="place your notes here..."></textarea>
  203. <input class="x-btn x-btn-small x-btn-icon-small-left primary-button x-btn-noicon" type="submit" name="backupMODX" value="Backup Site!">
  204. </form>\';
  205. }else {
  206. if ($backup == true) {
  207. echo\'
  208. <form method="post" action="">
  209. <h3 style="color:grey">Backup Finished!</h3>
  210. <p>
  211. \'.$mysql_link.\'<br>
  212. \'.$files_link.\'<br>
  213. \'.$combi_link.\'
  214. </p><br>
  215. <input class="x-btn x-btn-small x-btn-icon-small-left primary-button x-btn-noicon" type="submit" name="removeBackup" value="Remove Backups">
  216. </form>\';
  217. }
  218. }',
  219. 'locked' => 0,
  220. 'properties' => 'a:4:{s:8:"excludes";a:7:{s:4:"name";s:8:"excludes";s:4:"desc";s:156:"file/folder, or comma-separated list of files/folders who will be excluded of the backup. Using file-path from the root. Example: /html/assets,/html/manager";s:4:"type";s:8:"textarea";s:7:"options";a:0:{}s:5:"value";s:0:"";s:7:"lexicon";N;s:4:"area";s:0:"";}s:6:"groups";a:7:{s:4:"name";s:6:"groups";s:4:"desc";s:65:"group, or comma-separated list of groups, who will see the widget";s:4:"type";s:9:"textfield";s:7:"options";a:0:{}s:5:"value";s:13:"Administrator";s:7:"lexicon";s:21:"backupmodx:properties";s:4:"area";s:0:"";}s:8:"tarAlias";a:7:{s:4:"name";s:8:"tarAlias";s:4:"desc";s:51:"some server need an alias for tar like "/bin/pktar"";s:4:"type";s:9:"textfield";s:7:"options";a:0:{}s:5:"value";s:3:"tar";s:7:"lexicon";N;s:4:"area";s:0:"";}s:10:"targetPath";a:7:{s:4:"name";s:10:"targetPath";s:4:"desc";s:144:"Directory of the backup files. No trailing slash! You can use {assets_path} as a placeholder for the assets folder. Example: {assets_path}folder";s:4:"type";s:9:"textfield";s:7:"options";a:0:{}s:5:"value";s:13:"{assets_path}";s:7:"lexicon";N;s:4:"area";s:0:"";}}',
  221. 'moduleguid' => '',
  222. 'static' => 0,
  223. 'static_file' => '',
  224. 'content' => '/**
  225. * BackupMODXWidget snippet for backupmodx extra
  226. *
  227. * Copyright 2015 by Quadro - Jan Dähne info@quadro-system.de
  228. * Created on 12-16-2015
  229. *
  230. * backupmodx is free software; you can redistribute it and/or modify it under the
  231. * terms of the GNU General Public License as published by the Free Software
  232. * Foundation; either version 2 of the License, or (at your option) any later
  233. * version.
  234. *
  235. * backupmodx is distributed in the hope that it will be useful, but WITHOUT ANY
  236. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  237. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  238. *
  239. * You should have received a copy of the GNU General Public License along with
  240. * backupmodx; if not, write to the Free Software Foundation, Inc., 59 Temple
  241. * Place, Suite 330, Boston, MA 02111-1307 USA
  242. *
  243. * @package backupmodx
  244. */
  245. /**
  246. * Description
  247. * -----------
  248. * Backup MODX Dashboard widget
  249. *
  250. * Variables
  251. * ---------
  252. * @var $modx modX
  253. * @var $scriptProperties array
  254. *
  255. * @package backupmodx
  256. **/
  257. // Returns an empty string if user shouldn\'t see the widget
  258. $groups = $modx->getOption(\'groups\', $scriptProperties, \'Administrator\', true);
  259. if (strpos($groups, \',\') !== false) {
  260. $groups = explode(\',\', $groups);
  261. }
  262. if (!$modx->user->isMember($groups)) {
  263. return \'\';
  264. }
  265. //Check if server supports shell-commands
  266. if (!shell_exec("type type")) { return \'Your server does not support shell-commands. Backup not possible.\'; }
  267. $config = $modx->getConfig();
  268. //Get Properties
  269. $tarAlias = $modx->getOption(\'tarAlias\', $scriptProperties, \'tar\', true); //some websites may need a different alias for tar
  270. $excludes = $modx->getOption(\'excludes\', $scriptProperties);
  271. $targetPath = str_replace("{assets_path}", MODX_ASSETS_PATH, $modx->getOption(\'targetPath\', $scriptProperties)); //directory to place the backup
  272. $targetPath = rtrim($targetPath, \'/\').\'/backup\'; //removing trailing slash and adding backup-folder
  273. if(!function_exists("fileLink")) {
  274. function fileLink($file, $title) {
  275. $file_root = MODX_BASE_PATH.str_replace(MODX_BASE_PATH, "", $file);
  276. $file_absolute = MODX_SITE_URL.str_replace(MODX_BASE_PATH, "", $file);
  277. $size = round(filesize($file) / 1000000, 2);
  278. if (file_exists($file_root)){
  279. $file = \'<a href="\'.$file_absolute.\'" target="_blank" download>\'.basename($file).\'</a>\';
  280. }else {
  281. $file = basename($file);
  282. }
  283. return \'<span style="display: inline-block; width: 90px;">\'.$title.\':</span>\'.$file.\' (\'.$size.\' MB)\';
  284. }
  285. }
  286. if (isset($_POST[\'backupMODX\'])) {
  287. set_time_limit(0);
  288. ini_set(\'max_execution_time\', 0);
  289. if (!empty($_POST["mysql"]) or !empty($_POST["files"])){
  290. $base_path = MODX_BASE_PATH;
  291. $core_path = MODX_CORE_PATH;
  292. $date = date("Ymd-His");
  293. $dbase = $modx->getOption(\'dbname\');
  294. $database_server = $config[host];
  295. $database_user = $config[username];
  296. $database_password = $config[password];
  297. $targetSql = "{$targetPath}/{$dbase}_{$date}_mysql.sql";
  298. $targetTar = "{$targetPath}/{$dbase}_{$date}_files.tar";
  299. $targetCom = "{$targetPath}/{$dbase}_{$date}_combined.tar";
  300. $targetTxt = "{$targetPath}/{$dbase}_{$date}_readme.txt";
  301. //Create Folder
  302. system("mkdir $targetPath");
  303. //Create Readme
  304. if (!empty($_POST["note"])){
  305. $fp = fopen($targetTxt,"wb");
  306. fwrite($fp,$_POST["note"]);
  307. fclose($fp);
  308. }
  309. //MySQL- Backup
  310. if (!empty($_POST["mysql"])){
  311. system("mysqldump --host=$database_server --user=$database_user --password=$database_password --databases $dbase --no-create-db --default-character-set=utf8 --result-file={$targetSql}");
  312. //If no mysqldump was possible try:
  313. if (file_exists($targetSql) or filesize($targetSql) <= 0) {
  314. system(sprintf(\'mysqldump --no-tablespaces --opt -h%s -u%s -p"%s" %s --result-file=%s\', $database_server, $database_user, $database_password, $dbase, $targetSql));
  315. }
  316. }
  317. //File-Backup
  318. if (!empty($_POST["files"])){
  319. //creating exclude-files command
  320. if (!empty($excludes)) {
  321. $excludes_array = explode(",", $excludes);
  322. unset($excludes);
  323. foreach ($excludes_array as $exclude){
  324. $excludes .= \' --exclude=\'.$exclude;
  325. }
  326. }
  327. //tar files
  328. system("$tarAlias cf {$targetTar} --exclude=$targetPath --exclude={$core_path}cache/* {$excludes} $base_path $core_path");
  329. //If a note exists add it to the tar-archive
  330. if (file_exists($targetTxt)) {
  331. system("$tarAlias uf {$targetTar} -C $targetPath {$dbase}_{$date}_readme.txt"); //adding note in the root
  332. }
  333. }
  334. //Combine SQL and Files in one archive
  335. if (file_exists($targetSql) and file_exists($targetTar) and filesize($targetSql) > 0) {
  336. system("cp {$targetTar} {$targetCom}"); //copy files-archive
  337. system("$tarAlias uf {$targetCom} -C $targetPath {$dbase}_{$date}_mysql.sql"); //adding sql-file in the root
  338. }
  339. $backup = true;
  340. //Output
  341. if (file_exists($targetSql) and filesize($targetSql) > 0) {
  342. $mysql_link = fileLink($targetSql, \'MySQL\');
  343. }else {
  344. $mysql_link = \'<span style="display: inline-block; width: 90px;">MySQL:</span>No Backup!\';
  345. }
  346. if (file_exists($targetTar)) {
  347. $files_link = fileLink($targetTar, \'Files\');
  348. }else {
  349. $files_link = \'<span style="display: inline-block; width: 90px;">Files:</span>No Backup!\';
  350. }
  351. if (file_exists($targetCom)) {
  352. $combi_link = fileLink($targetCom, \'MySQL & Files\');
  353. }
  354. }
  355. }
  356. //Remove Backups
  357. if (!empty($_POST["removeBackup"])){
  358. if (!empty($_POST["removeBackup"])) {
  359. foreach(glob("$targetPath/*") as $file) {
  360. $extension = pathinfo($file, PATHINFO_EXTENSION);
  361. if (in_array($extension, array("tar", "sql", "txt"))) {
  362. unlink($file);
  363. }
  364. }
  365. rmdir($targetPath);
  366. }
  367. }
  368. if ($backup != true) {
  369. echo \'
  370. <form method="post" action="">
  371. <p>
  372. Backup your MODX-Site:<br><br>
  373. <input type="checkbox" name="mysql" id="mysql" value="1" checked><label for="mysql"> MySQL Database</label><br />
  374. <input type="checkbox" name="files" id="files" value="1" checked><label for="files"> Files</label>
  375. </p>
  376. <br>
  377. <p>
  378. Folder to place files: <strong>\'.$targetPath.\'</strong> <span style="color: grey;">(Editable via Snippet-Properties)</span><br>
  379. </p><br>
  380. <p>Add a readme file: <span style="color: grey;">(txt-file placed in the root)</span></p>
  381. <textarea name="note" style="width:90%; height:40px; display: block; border: 1px solid #ccc; margin: 5px 0 20px 0; padding: 5px;" placeholder="place your notes here..."></textarea>
  382. <input class="x-btn x-btn-small x-btn-icon-small-left primary-button x-btn-noicon" type="submit" name="backupMODX" value="Backup Site!">
  383. </form>\';
  384. }else {
  385. if ($backup == true) {
  386. echo\'
  387. <form method="post" action="">
  388. <h3 style="color:grey">Backup Finished!</h3>
  389. <p>
  390. \'.$mysql_link.\'<br>
  391. \'.$files_link.\'<br>
  392. \'.$combi_link.\'
  393. </p><br>
  394. <input class="x-btn x-btn-small x-btn-icon-small-left primary-button x-btn-noicon" type="submit" name="removeBackup" value="Remove Backups">
  395. </form>\';
  396. }
  397. }',
  398. ),
  399. ),
  400. );