PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backwpup/job/job_run.php

https://bitbucket.org/sanders_nick/legacy-media
PHP | 173 lines | 167 code | 0 blank | 6 comment | 15 complexity | e701bb5c8fbae23d6b810ecc2baedafa MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0, BSD-3-Clause, GPL-3.0
  1. <?PHP
  2. //Set a constance for not direkt loding in other files
  3. define('BACKWPUP_JOBRUN_FOLDER', str_replace('\\','/',dirname(__FILE__).'/'));
  4. //set temp dir
  5. $STATIC['TEMPDIR']=BACKWPUP_JOBRUN_FOLDER.'../tmp/';
  6. $STATIC['TEMPDIR']=realpath($STATIC['TEMPDIR']).'/';
  7. //check temp dir
  8. if (empty($STATIC['TEMPDIR']) || !is_dir($STATIC['TEMPDIR']) || !is_writable($STATIC['TEMPDIR']))
  9. die($STATIC['TEMPDIR'].'Temp dir not writable!!! Job aborted!');
  10. //write PHP log
  11. @ini_set( 'error_log', $STATIC['TEMPDIR'].'php_error.log' );
  12. @ini_set( 'display_errors', 'Off' );
  13. @ini_set( 'log_errors', 'On' );
  14. // get needed functions for the jobrun
  15. require_once(BACKWPUP_JOBRUN_FOLDER.'job_functions.php');
  16. //read runningfile and config
  17. $runningfile=get_working_file();
  18. if ($runningfile['JOBID']>0 and $runningfile['WORKING']['NONCE']==$_POST['nonce']) {
  19. if ($staticfile=file_get_contents($STATIC['TEMPDIR'].'.static')) {
  20. $STATIC=unserialize(trim($staticfile));
  21. } else {
  22. delete_working_file();
  23. die('No config file found');
  24. }
  25. $WORKING=$runningfile['WORKING'];
  26. unset($runningfile);
  27. unset($staticfile);
  28. } else {
  29. die('Hack ?');
  30. }
  31. ob_end_clean();
  32. header("Connection: close");
  33. ob_start();
  34. header("Content-Length: 0");
  35. ob_end_flush();
  36. flush();
  37. // set memory limit to the same as WP.
  38. if ( function_exists( 'memory_get_usage' ) ) {
  39. $current_limit = @ini_get( 'memory_limit' );
  40. if ( -1 != $current_limit && ( -1 == $STATIC['WP']['MEMORY_LIMIT'] || ( intval( $current_limit ) < abs( intval( $STATIC['WP']['MEMORY_LIMIT'] ) ) ) ) )
  41. @ini_set( 'memory_limit', $STATIC['WP']['MEMORY_LIMIT'] );
  42. }
  43. //check existing Logfile
  44. if (empty($STATIC) or !is_file($STATIC['LOGFILE'])) {
  45. delete_working_file();
  46. die('No logfile found!');
  47. }
  48. //load translation
  49. if (is_file(dirname(__FILE__).'/../lang/backwpup-'.$STATIC['WP']['WPLANG'].'.mo')) {
  50. require($STATIC['WP']['ABSPATH'].$STATIC['WP']['WPINC'].'/pomo/mo.php');
  51. $TRANSLATE = new MO();
  52. $TRANSLATE->import_from_file(dirname(__FILE__).'/../lang/backwpup-'.$STATIC['WP']['WPLANG'].'.mo');
  53. } else {
  54. require($STATIC['WP']['ABSPATH'].$STATIC['WP']['WPINC'].'/pomo/translations.php');
  55. $TRANSLATE = new NOOP_Translations;
  56. }
  57. //set ticks
  58. declare(ticks=1);
  59. //set timezone
  60. date_default_timezone_set('UTC');
  61. // set charakter encoding
  62. if ( function_exists( 'mb_internal_encoding' ) ) {
  63. if (!@mb_internal_encoding($STATIC['WP']['CHARSET']))
  64. mb_internal_encoding('UTF-8');
  65. }
  66. //set function for PHP user defineid error handling
  67. set_error_handler('joberrorhandler',E_ALL | E_STRICT);
  68. //Get type and check job runs
  69. $runningfile=get_working_file();
  70. $revtime=time()-$STATIC['CFG']['jobscriptruntimelong']-10;
  71. if ($WORKING['PID']!=getmypid() and $runningfile['timestamp']>$revtime and $_POST['type']=='restarttime') {
  72. trigger_error(__('Job restart terminated, bcause old job runs again!','backwpup'),E_USER_ERROR);
  73. die();
  74. } elseif($_POST['type']=='restarttime') {
  75. trigger_error(__('Job restarted, bcause inactivity!','backwpup'),E_USER_ERROR);
  76. } elseif ($WORKING['PID']!=getmypid() and $WORKING['PID']!=0 and $runningfile['timestamp']>$revtime) {
  77. trigger_error(sprintf(__('Second Prozess is running, bcause old job runs! Start type is %s','backwpup'),$_POST['type']),E_USER_ERROR);
  78. die();
  79. }
  80. unset($runningfile);
  81. //set Pid
  82. $WORKING['PID']=getmypid();
  83. // execute function on job shutdown
  84. register_shutdown_function('job_shutdown');
  85. if (function_exists('pcntl_signal')) {
  86. pcntl_signal(SIGTERM, 'job_shutdown');
  87. }
  88. //try to disable safe mode
  89. @ini_set('safe_mode','0');
  90. // Now user abrot allowed
  91. @ini_set('ignore_user_abort','0');
  92. //disable user abort
  93. ignore_user_abort(true);
  94. //update running file
  95. update_working_file(true);
  96. //mysql connect
  97. mysql_update();
  98. //Load needed files
  99. foreach($WORKING['STEPS'] as $step) {
  100. $stepfile=strtolower($step).'.php';
  101. if ($step!='JOB_END') {
  102. if (is_file(BACKWPUP_JOBRUN_FOLDER.$stepfile)) {
  103. require_once(BACKWPUP_JOBRUN_FOLDER.$stepfile);
  104. } else {
  105. trigger_error(sprintf(__('Can not find job step file: %s','backwpup'),$stepfile),E_USER_ERROR);
  106. }
  107. }
  108. }
  109. // Working step by step
  110. foreach($WORKING['STEPS'] as $step) {
  111. //display some info massages bevor fist step
  112. if (count($WORKING['STEPSDONE'])==0) {
  113. trigger_error(sprintf(__('[INFO]: BackWPup version %1$s, WordPress version %4$s Copyright &copy; %2$s %3$s','backwpup'),$STATIC['BACKWPUP']['VERSION'],date('Y',time()+$STATIC['WP']['TIMEDIFF']),'<a href="http://danielhuesken.de" target="_blank">Daniel H&uuml;sken</a>',$STATIC['WP']['VERSION']),E_USER_NOTICE);
  114. trigger_error(__('[INFO]: BackWPup comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.','backwpup'),E_USER_NOTICE);
  115. trigger_error(__('[INFO]: BackWPup job:','backwpup').' '.$STATIC['JOB']['jobid'].'. '.$STATIC['JOB']['name'].'; '.$STATIC['JOB']['type'],E_USER_NOTICE);
  116. if ($STATIC['JOB']['activated'])
  117. trigger_error(__('[INFO]: BackWPup cron:','backwpup').' '.$STATIC['JOB']['cron'].'; '.date('D, j M Y @ H:i',$STATIC['JOB']['cronnextrun']),E_USER_NOTICE);
  118. if ($STATIC['CRONSTART'])
  119. trigger_error(__('[INFO]: BackWPup job started by cron','backwpup'),E_USER_NOTICE);
  120. else
  121. trigger_error(__('[INFO]: BackWPup job started manualy','backwpup'),E_USER_NOTICE);
  122. trigger_error(__('[INFO]: PHP ver.:','backwpup').' '.phpversion().'; '.php_sapi_name().'; '.PHP_OS,E_USER_NOTICE);
  123. if ((bool)ini_get('safe_mode'))
  124. trigger_error(sprintf(__('[INFO]: PHP Safe mode is ON! Maximum script execution time is %1$d sec.','backwpup'),ini_get('max_execution_time')),E_USER_NOTICE);
  125. trigger_error(__('[INFO]: MySQL ver.:','backwpup').' '.mysql_result(mysql_query("SELECT VERSION() AS version"),0),E_USER_NOTICE);
  126. if (function_exists('curl_init')) {
  127. $curlversion=curl_version();
  128. trigger_error(__('[INFO]: curl ver.:','backwpup').' '.$curlversion['version'].'; '.$curlversion['ssl_version'],E_USER_NOTICE);
  129. }
  130. trigger_error(__('[INFO]: Temp folder is:','backwpup').' '.$STATIC['TEMPDIR'],E_USER_NOTICE);
  131. if(!empty($STATIC['backupfile']))
  132. trigger_error(__('[INFO]: Backup file is:','backwpup').' '.$STATIC['JOB']['backupdir'].$STATIC['backupfile'],E_USER_NOTICE);
  133. //test for destinations
  134. if (in_array('DB',$STATIC['TODO']) or in_array('WPEXP',$STATIC['TODO']) or in_array('FILE',$STATIC['TODO'])) {
  135. $desttest=false;
  136. foreach($WORKING['STEPS'] as $deststeptest) {
  137. if (substr($deststeptest,0,5)=='DEST_') {
  138. $desttest=true;
  139. break;
  140. }
  141. }
  142. if (!$desttest)
  143. trigger_error(__('No destination defineid for backup!!! Please correct job settings','backwpup'),E_USER_ERROR);
  144. }
  145. }
  146. //Set next step
  147. if (!isset($WORKING[$step]['STEP_TRY']) or empty($WORKING[$step]['STEP_TRY'])) {
  148. $WORKING[$step]['STEP_TRY']=0;
  149. $WORKING['STEPDONE']=0;
  150. $WORKING['STEPTODO']=0;
  151. }
  152. //update running file
  153. update_working_file(true);
  154. //Run next step
  155. if (!in_array($step,$WORKING['STEPSDONE'])) {
  156. if (function_exists(strtolower($step))) {
  157. while ($WORKING[$step]['STEP_TRY']<$STATIC['CFG']['jobstepretry']) {
  158. if (in_array($step,$WORKING['STEPSDONE']))
  159. break;
  160. $WORKING[$step]['STEP_TRY']++;
  161. update_working_file(true);
  162. call_user_func(strtolower($step));
  163. }
  164. if ($WORKING[$step]['STEP_TRY']>=$STATIC['CFG']['jobstepretry'])
  165. trigger_error(__('Step arborted has too many trys!','backwpup'),E_USER_ERROR);
  166. } else {
  167. trigger_error(sprintf(__('Can not find job step function %s!','backwpup'),strtolower($step)),E_USER_ERROR);
  168. $WORKING['STEPSDONE'][]=$step;
  169. }
  170. }
  171. }
  172. //close mysql
  173. mysql_close($mysqlconlink);