admincp_patch.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: admincp_patch.php 29258 2012-03-31 03:56:17Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. cpheader();
  12. $operation = in_array($operation , array('patchsetting', 'fixpatch', 'checkpatch', 'recheckpatch')) ? $operation : 'checkpatch';
  13. $discuz_patch = new discuz_patch();
  14. if($operation == 'patchsetting') {
  15. $save_master = C::t('common_setting')->fetch_all(array('mastermobile', 'masterqq', 'masteremail'));
  16. $save_mastermobile = $save_master['mastermobile'];
  17. $save_mastermobile = !empty($save_mastermobile) ? authcode($save_mastermobile, 'DECODE', $_G['config']['security']['authkey']) : '';
  18. if(!submitcheck('settingsubmit')) {
  19. $view_mastermobile = !empty($save_mastermobile) ? substr($save_mastermobile, 0 , 3).'*****'.substr($save_mastermobile, -3) : '';
  20. shownav('founder', 'nav_founder_patch');
  21. showsubmenu('nav_founder_patch', array(
  22. array('founder_patch_list', 'patch&operation=fixpatch', 0),
  23. array('founder_patch_updatesetting', 'patch&operation=patchsetting', 1),
  24. ));
  25. showformheader('patch&operation=patchsetting');
  26. showtableheader();
  27. showsetting('founder_patch_autoupdate', 'settingnew[patch][autoopened]', $_G['setting']['patch']['autoopened'], 'radio');
  28. showsubmit('settingsubmit', 'submit');
  29. showtablefooter();
  30. showformfooter();
  31. } else {
  32. $settings = array();
  33. $settingnew = $_POST['settingnew'];
  34. if($settingnew) {
  35. if(!$discuz_patch->save_patch_setting($settingnew)) {
  36. cpmsg('patch_no_privilege_autoupdate', '', 'error');
  37. }
  38. }
  39. cpmsg('patch_updatesetting_successful', 'action=patch&operation='.$operation, 'succeed');
  40. }
  41. } elseif($operation == 'fixpatch') {
  42. if(!submitcheck('fixpatchsubmit', 1)) {
  43. shownav('founder', 'nav_founder_patch');
  44. showsubmenu('nav_founder_patch', array(
  45. array('founder_patch_list', 'patch&operation=fixpatch', 1),
  46. array('founder_patch_updatesetting', 'patch&operation=patchsetting', 0),
  47. ));
  48. showformheader('patch&operation=fixpatch');
  49. showtableheader('', 'fixpadding', '', 5);
  50. showtablerow('class="header"', array('class="td25"','class="td24"','', 'class="td31"', 'class="td25"'), array(
  51. '',
  52. $lang['founder_patch_serial'],
  53. $lang['founder_patch_note'],
  54. $lang['founder_patch_dateline'],
  55. $lang['founder_patch_status'],
  56. ));
  57. $patchlist = C::t('common_patch')->fetch_all();
  58. foreach($patchlist as $patch) {
  59. showtablerow($patch['status'] <= 0 ? 'title="'.$lang['founder_patchstatus_'.($patch['status'] < 0 ? 'error'.$patch['status'] : $patch['status'])].'"' : '', '', array(
  60. '<input class="checkbox" type="checkbox" value="'.$patch['serial'].'"'.($patch['status'] >= 1 ? ' disabled' : ' name="deletefix[]" checked').'>',
  61. $patch['serial'],
  62. $patch['note'],
  63. dgmdate($patch['dateline'], 'Y-m-d H:i:s'),
  64. '<em class="'.($patch['status'] <= 0 ? 'unfixed' : 'fixed').'">&nbsp;</em>',
  65. ));
  66. }
  67. showsubmit('fixpatchsubmit', 'founder_patch_fix', 'select_all', ' <input type="button" class="btn" onclick="window.location.href=\''.ADMINSCRIPT.'?action=patch&operation=recheckpatch'.'\';" value="'.$lang['founder_patch_rescan'].'">');
  68. showtablefooter();
  69. showformfooter();
  70. } else {
  71. $patchlist = $_GET['deletefix'];
  72. if(empty($patchlist)) {
  73. cpmsg('patch_please_select_patch', '', 'error');
  74. }
  75. $confirm = $_GET['confirm'];
  76. if(!$confirm) {
  77. if($_GET['siteftpsetting']) {
  78. $action = 'patch&operation=fixpatch&fixpatchsubmit=yes&confirm=ftp';
  79. foreach($patchlist as $serial) {
  80. $action .= '&deletefix[]='.$serial;
  81. }
  82. siteftp_form($action);
  83. exit;
  84. }
  85. $flag = 0;
  86. foreach(C::t('common_patch')->fetch_needfix_patch($patchlist) as $patch) {
  87. if(!$discuz_patch->test_patch_writable($patch)) {
  88. $flag = 1;
  89. break;
  90. }
  91. }
  92. if(!$flag) {
  93. $confirm = 'file';
  94. } else {
  95. $linkurl = ADMINSCRIPT.'?action=patch&operation='.$operation.'&fixpatchsubmit=yes';
  96. foreach($patchlist as $serial) {
  97. $linkurl .= '&deletefix[]='.$serial;
  98. }
  99. $ftplinkurl = $linkurl.'&siteftpsetting=1';
  100. cpmsg('patch_cannot_access_file',
  101. '',
  102. '',
  103. array(),
  104. '<br><input type="button" class="btn" onclick="window.location.href=\''.$ftplinkurl.'\'" value="'.$lang['founder_patch_set_ftpinfo'].'">'.
  105. '&nbsp;&nbsp;&nbsp;<input type="button" class="btn" onclick="window.location.href=\''.$linkurl.'\'" value="'.$lang['founder_patch_reset'].'"><br><br>'
  106. );
  107. }
  108. }
  109. $failed = array();
  110. if($patchlist) {
  111. $patchlist = C::t('common_patch')->fetch_needfix_patch($patchlist);
  112. foreach($patchlist as $patch) {
  113. $result = $discuz_patch->fix_patch($patch, $confirm);
  114. if($result < 0) {
  115. $failed[] = array('serial' => $patch['serial'], 'reason' => $lang['founder_patchstatus_'.($result < 0 ? 'error'.$result : $result)]);
  116. }
  117. }
  118. }
  119. if($failed) {
  120. $failstr = '';
  121. foreach($failed as $v) {
  122. $failstr .= $lang['founder_patch_fixpatch'].$v['serial'].'&nbsp;&nbsp;&nbsp;&nbsp;'.$lang['founder_patch_failedreason'].': '.$v['reason']."<br>\r\n";
  123. }
  124. cpmsg('patch_updatesetting_failed', 'action=patch&operation='.$operation, 'error', array('list' => $failstr));
  125. } else {
  126. cpmsg('patch_successful', 'action=patch&operation='.$operation, 'succeed', array(), '<script type="text/javascript">if(parent.document.getElementById(\'notice\')) parent.document.getElementById(\'notice\').style.display = \'none\';</script>');
  127. }
  128. }
  129. } elseif($operation == 'checkpatch') {
  130. if(!intval($_GET['checking'])) {
  131. cpmsg('patch_cheking', 'action=patch&operation=checkpatch&checking=1', 'loading', '', false);
  132. }
  133. $discuz_patch->check_patch(1);
  134. dheader('Location: '.ADMINSCRIPT.'?action=patch&operation=fixpatch');
  135. } elseif($operation == 'recheckpatch') {
  136. $discuz_patch->recheck_patch();
  137. cpmsg('patch_successful', 'action=patch&operation=fixpatch', 'succeed');
  138. }
  139. ?>