upgrade.ctrl.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('cloud');
  8. load()->func('communication');
  9. load()->func('db');
  10. load()->model('system');
  11. $cloud_ready = cloud_prepare();
  12. if (is_error($cloud_ready)) {
  13. message($cloud_ready['message'], url('cloud/diagnose'), 'error');
  14. }
  15. $dos = array('upgrade', 'get_upgrade_info', 'get_error_file_list');
  16. $do = in_array($do, $dos) ? $do : 'upgrade';
  17. if ($do == 'upgrade') {
  18. if (empty($_W['setting']['cloudip']) || $_W['setting']['cloudip']['expire'] < TIMESTAMP) {
  19. // $cloudip = gethostbyname('api-upgrade.w7.cc');
  20. $cloudip = '127.0.0.1';
  21. if (empty($cloudip) || !preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $cloudip)) {
  22. itoast('云服务域名解析失败,请查看服务器DNS设置或是在“云服务诊断”中手动设置云服务IP', url('cloud/diagnose'), 'error');
  23. }
  24. setting_save(array('ip' => $cloudip, 'expire' => TIMESTAMP + 3600), 'cloudip');
  25. }
  26. $path = IA_ROOT . '/data/patch/' . date('Ymd') . '/';
  27. if (is_dir($path)) {
  28. if ($handle = opendir($path)) {
  29. while (false !== ($patchpath = readdir($handle))) {
  30. if ($patchpath != '.' && $patchpath != '..') {
  31. if(is_dir($path.$patchpath)){
  32. $patchs[] = $patchpath;
  33. }
  34. }
  35. }
  36. }
  37. if (!empty($patchs)) {
  38. sort($patchs, SORT_NUMERIC);
  39. }
  40. }
  41. $scrap_file = system_scrap_file();
  42. $have_no_permission_file = array();
  43. foreach ($scrap_file as $key => $file) {
  44. if (!file_exists(IA_ROOT . $file)) {
  45. continue;
  46. }
  47. $result = @unlink(IA_ROOT . $file);
  48. if (!$result) {
  49. $have_no_permission_file[] = $file;
  50. }
  51. }
  52. if ($have_no_permission_file) {
  53. itoast(implode('<br>', $have_no_permission_file) . '<br>以上废弃文件删除失败,可尝试将文件权限设置为777,再行删除!', referer(), 'error');
  54. }
  55. }
  56. if ($do == 'get_error_file_list') {
  57. $error_file_list = array();
  58. cloud_file_permission_pass($error_file_list);
  59. iajax(0, !empty($error_file_list) ? $error_file_list : '');
  60. }
  61. if ($do == 'get_upgrade_info') {
  62. $notice_str = '<div class="content text-left we7-margin-left"><div class="we7-margin-bottom-sm">云服务向您的服务器传输数据过程中发生错误!</div><div class=" we7-margin-bottom-sm color-gray">尝试解决以下已知问题后再试:</div>';
  63. if ($_W['config']['setting']['timezone'] != 'Asia/Shanghai') {
  64. iajax(-1, $notice_str . '<div class="color-red">请把服务器时间修改为北京时间,即修改config.php中timezone为Asia/Shanghai</div></div>');
  65. }
  66. if (empty($_W['setting']['site']) || empty($_W['setting']['site']['url'])) {
  67. iajax(-1, $notice_str . '<div class="color-red">站点信息不完整,请重置站点 <a href="./index.php?c=cloud&a=diagnose" class="color-default" target="_blank"> 去重置</a></div></div>');
  68. }
  69. if (parse_url($_W['siteroot'], PHP_URL_HOST) != parse_url($_W['setting']['site']['url'], PHP_URL_HOST)) {
  70. iajax(-1, $notice_str . '<div class="color-red">1. 请使用微擎授权域名进行更新,授权域名为:' . $_W['setting']['site']['url'] . '<br>2. 重置站点 <a href="./index.php?c=cloud&a=diagnose" class="color-default" target="_blank"> 去重置</a></div></div>');
  71. }
  72. $upgrade = cloud_build();
  73. if (is_error($upgrade)) {
  74. iajax(-1, $notice_str . '<div class="color-red">1.请关闭服务器的防火墙,杀毒软件,cdn,云锁,云盾,安全狗之类的软件后再重试;<br>2.下载最新的cloud.mod.php覆盖到/framework/model/cloud.mod.php <a href="//cdn.w7.cc/we7/cloud.mod.php" class="color-default" target="_blank"> 点击下载</a>;<br>3.重置站点 <a href="./index.php?c=cloud&a=diagnose" class="color-default" target="_blank"> 去重置</a></div></div>');
  75. }
  76. if (!$upgrade['upgrade']) {
  77. cache_delete(cache_system_key('checkupgrade'));
  78. cache_delete(cache_system_key('cloud_transtoken'));
  79. iajax(1, '检查结果: 恭喜, 你的程序已经是最新版本. ');
  80. }
  81. if (!empty($upgrade['schemas'])) {
  82. $upgrade['database'] = cloud_build_schemas($upgrade['schemas']);
  83. }
  84. if (!empty($upgrade['files'])) {
  85. foreach ($upgrade['files'] as &$file) {
  86. if (is_file(IA_ROOT . $file)) {
  87. $file = 'M ' . $file;
  88. } else {
  89. $file = 'A ' . $file;
  90. }
  91. }
  92. unset($value);
  93. }
  94. iajax(0, $upgrade);
  95. }
  96. template('cloud/upgrade');