설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upgrade.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. // 系统升级 js 文件
  2. $(document).ready(function(){
  3. $("#a_upgrade").click(function(){
  4. btn_upgrade(this, 0);
  5. });
  6. });
  7. function btn_upgrade(obj, type)
  8. {
  9. var v = '';
  10. var filelist = $("#upgrade_filelist").html();
  11. if (undefined == filelist || !filelist) {
  12. parent.layer.closeAll();
  13. var alert1 = layer.alert("请清除后台缓存以及Ctrl+F5强制刷新页面,再尝试升级!", {icon: 7, title:false}, function(){
  14. layer.close(alert1);
  15. var url = eyou_basefile + "?m="+module_name+"&c=System&a=clear_cache";
  16. var iframe = $(obj).data('iframe');
  17. if ('parent' == iframe) {
  18. workspace.window.location.href = url;
  19. } else {
  20. window.location.href = url;
  21. }
  22. });
  23. return false;
  24. }
  25. var version = $(obj).data('version');
  26. var max_version = $(obj).data('max_version');
  27. var curent_version = $(obj).data('curent_version');
  28. var intro = $("#upgrade_intro").html();
  29. var notice = $("#upgrade_notice").html();
  30. intro += '<style type="text/css">.layui-layer-content{height:270px!important;text-align:left!important;}</style>';
  31. // 截图前50个文件记录
  32. var filelist_arr = filelist.split('<br>');
  33. if (filelist_arr.length > 50) {
  34. filelist_arr = filelist_arr.slice(0,50);
  35. filelist_arr.push("……");
  36. filelist_arr.push("<a href='https://www.eyoucms.com/plus/upgrade.php?version="+curent_version+"-"+version+"' target='_blank'>此次更新涉及的全部文件,点击这里查看!</a>");
  37. filelist = filelist_arr.join('<br>');
  38. }
  39. v = notice + intro + '<br/>' + filelist;
  40. var title = '检测系统最新版本:'+version;
  41. var btn = [];
  42. if (0 == type) {
  43. btn = ['升级','忽略'];
  44. } else if (1 == type) {
  45. btn = ['升级','忽略','不再提醒'];
  46. }
  47. if (1 == VarSecurityPatch) {
  48. btn = ['升级','忽略'];
  49. title = '检测系统安全补丁最新版本:'+version;
  50. }
  51. /*显示顶部导航更新提示*/
  52. $("#upgrade_filelist", window.parent.document).html($("#upgrade_filelist").html());
  53. $("#upgrade_intro", window.parent.document).html($("#upgrade_intro").html());
  54. $("#upgrade_notice", window.parent.document).html($("#upgrade_notice").html());
  55. $('#a_upgrade', window.parent.document).attr('data-version',version)
  56. .attr('data-max_version',max_version)
  57. .show();
  58. /*--end*/
  59. //询问框
  60. parent.layer.confirm(v, {
  61. title: title
  62. ,shade: layer_shade
  63. ,area: ['580px','400px']
  64. ,btn: btn //按钮
  65. ,success: function () {
  66. $(".layui-layer-content").css('text-align', 'left');
  67. }
  68. ,btn3: function(index){
  69. var url = $(obj).data('tips_url');
  70. $.getJSON(url, {show_popup_upgrade:-1,_ajax:1}, function(){});
  71. parent.layer.msg('【核心设置】里可以开启该提醒', {
  72. btnAlign: 'c',
  73. time: 20000, //20s后自动关闭
  74. btn: ['知道了']
  75. });
  76. return false;
  77. }
  78. }, function(){
  79. parent.layer.closeAll();
  80. setTimeout(function(){
  81. checkdir(obj); // 请求后台
  82. },200);
  83. }, function(){
  84. parent.layer.msg('不升级可能有安全隐患', {
  85. btnAlign: 'c',
  86. time: 20000, //20s后自动关闭
  87. btn: ['明白了']
  88. });
  89. return false;
  90. }
  91. );
  92. }
  93. /**
  94. * 检测升级文件的目录权限
  95. */
  96. function checkdir(obj) {
  97. layer_loading2('检测系统');
  98. $.ajax({
  99. type : "POST",
  100. url : $(obj).data('check_authority'),
  101. timeout : 360000, //超时时间设置,单位毫秒 设置了 1小时
  102. data : {filelist:0,_ajax:1},
  103. error: function(e) {
  104. var msg = e.responseText;
  105. if (msg.indexOf('错误代码') == -1) {
  106. msg = "检测不通过,可能被服务器防火墙拦截,请添加白名单!";
  107. }
  108. parent.layer.closeAll();
  109. parent.layer.alert(msg, {icon: 2, title:false}, function(){
  110. top.location.reload();
  111. });
  112. },
  113. success: function(res) {
  114. parent.layer.closeAll();
  115. if (1 == res.code) {
  116. upgrade($(obj));
  117. } else {
  118. //提示框
  119. if (2 == res.data.code) {
  120. var alert = parent.layer.alert(res.msg, {icon: 2, title:false, btn: ['立即查看']}, function(){
  121. window.parent.open('https://www.eyoucms.com/plus/view.php?aid=9105');
  122. });
  123. } else {
  124. var confirm = parent.layer.confirm(res.msg, {
  125. title: '检测系统结果'
  126. ,area: ['580px','400px']
  127. ,btn: ['关闭'] //按钮
  128. }, function(){
  129. parent.layer.close(confirm);
  130. return false;
  131. }
  132. );
  133. }
  134. }
  135. }
  136. });
  137. }
  138. /**
  139. * 升级系统
  140. */
  141. function upgrade(obj){
  142. layer_loading2('升级<font id="upgrade_speed">中</font>');
  143. var version = $(obj).data('version');
  144. var max_version = $(obj).data('max_version');
  145. var timer = '';
  146. var speed = 0.01;
  147. $.ajax({
  148. type : "GET",
  149. url : $(obj).data('upgrade_url'),
  150. timeout : 360000, //超时时间设置,单位毫秒 设置了 1小时
  151. data : {_ajax:1},
  152. beforeSend:function(){
  153. timer = setInterval(function(){
  154. random = Math.floor(Math.random()*89+10);
  155. random = random.toString();
  156. random = '1.' + random;
  157. speed = speed + parseFloat(random);
  158. speed = Math.floor(speed * 100) / 100;
  159. if (speed >= 98) {
  160. speed = 98;
  161. }
  162. $('#upgrade_speed', window.parent.document).html(speed+'%');
  163. }, 500);
  164. },
  165. error: function(request) {
  166. parent.layer.closeAll();
  167. parent.layer.alert("空间超时请稍后再试,或手工升级!", {icon: 2, title:false}, function(){
  168. top.location.reload();
  169. });
  170. },
  171. success: function(res) {
  172. $('#upgrade_speed', window.parent.document).html('100%');
  173. clearInterval(timer);
  174. if(1 == res.code){
  175. // setTimeout(function(){
  176. setTimeout(function(){
  177. var finish = false; // 是否升到最新版
  178. if (2 == res.data.code) {
  179. var title = res.msg;
  180. var btn = ['关闭'];
  181. }else if (version < max_version) { // 当前升级之后的版本还不是官方最新版本,将继续连续更新
  182. var title = '已升级版本:'+version+',官方最新版本:'+max_version+'。';
  183. var btn = ['开始检测'];
  184. } else { // 升级版本是官方最新版本,将引导到备份新数据
  185. finish = true;
  186. var title = '已升级最新版本!';
  187. var btn = ['关闭'];
  188. $('#a_upgrade', window.parent.document).hide(); // 隐藏顶部的更新提示
  189. }
  190. if (true == finish) {
  191. parent.layer.closeAll();
  192. var full = parent.layer.alert(title, {
  193. title: false,
  194. icon: 1,
  195. closeBtn: 0,
  196. btn: btn //按钮
  197. }, function(){
  198. parent.layer.close(full);
  199. top.location.href = eyou_basefile;
  200. }
  201. );
  202. // export_data();
  203. } else {
  204. var full = parent.layer.alert(title, {
  205. title: false,
  206. icon: 1,
  207. closeBtn: 0,
  208. btn: btn //按钮
  209. }, function(){
  210. if (version < max_version) { // 当前升级之后的版本还不是官方最新版本,将继续连续更新
  211. top.location.reload();
  212. } else { // 升级版本是官方最新版本,将引导到备份新数据
  213. parent.layer.close(full);
  214. var url = eyou_basefile + "?m="+module_name+"&c=Tools&a=index";
  215. var iframe = $(obj).data('iframe');
  216. if ('parent' == iframe) {
  217. top.location.href = eyou_basefile;
  218. // workspace.window.location.href = url;
  219. } else {
  220. top.location.href = eyou_basefile;
  221. // window.location.href = url;
  222. }
  223. }
  224. }
  225. );
  226. }
  227. },500);
  228. // },40000); // 睡眠1分钟,让复制文件执行完
  229. }
  230. else if (-2 == res.data.code) {
  231. parent.layer.closeAll();
  232. parent.layer.alert(res.msg, {icon: 2, title:false, btn: ['立即查看']}, function(){
  233. window.parent.open('https://www.eyoucms.com/plus/view.php?aid=9105');
  234. });
  235. }
  236. else if (-3 == res.data.code) {
  237. parent.layer.closeAll();
  238. var msg = '<style type="text/css">.layui-layer-content{text-align:left!important;}</style>' + res.msg;
  239. parent.layer.alert(msg, {
  240. shade: layer_shade,
  241. area: ['480px', '230px'],
  242. move: false,
  243. title: '温馨提示',
  244. btnAlign:'r',
  245. closeBtn: 3,
  246. btn: ['购买授权', '确定'],
  247. success: function(){
  248. $(".layui-layer-btn", window.parent.document).find('a.layui-layer-btn1').removeClass('layui-layer-btn1').addClass('layui-layer-btn2');
  249. $(".layui-layer-btn", window.parent.document).find('a.layui-layer-btn0').removeClass('layui-layer-btn0').addClass('layui-layer-btn1');
  250. $(".layui-layer-btn", window.parent.document).find('a.layui-layer-btn2').removeClass('layui-layer-btn2').addClass('layui-layer-btn0');
  251. }
  252. }, function(){
  253. window.open('https://www.eyoucms.com/buy');
  254. });
  255. }
  256. else {
  257. parent.layer.closeAll();
  258. parent.layer.alert(res.msg, {icon: 2, title:false}, function(){
  259. top.location.reload();
  260. });
  261. }
  262. }
  263. });
  264. }
  265. function layer_loading2(msg){
  266. var loading = parent.layer.msg(
  267. msg+'...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请勿刷新页面',
  268. {
  269. icon: 1,
  270. time: 3600000, //1小时后后自动关闭
  271. shade: [0.2] //0.1透明度的白色背景
  272. });
  273. //loading层
  274. var index = parent.layer.load(3, {
  275. shade: [0.1,'#fff'] //0.1透明度的白色背景
  276. });
  277. return loading;
  278. }
  279. function export_data(){
  280. parent.layer.msg('已完成升级,正在备份数据,请勿刷新页面!',
  281. {
  282. icon: 1,
  283. time: 3600000, //1小时后后自动关闭
  284. shade: [0.2] //0.1透明度的白色背景
  285. });
  286. setTimeout(function(){
  287. var url = eyou_basefile + "?m="+module_name+"&c=Tools&a=export&_ajax=1";
  288. $.ajax({
  289. url: url,
  290. data: {tables:'all'},
  291. type:'post',
  292. dataType:'json',
  293. success:function(res){
  294. parent.layer.closeAll();
  295. if(res.code){
  296. tables = res.tables;
  297. var loading = parent.layer.msg('正在备份表(<font id="upgrade_backup_table">'+res.tab.table+'</font>)……<font id="upgrade_backup_speed">0.01</font>%',
  298. {
  299. icon: 1,
  300. time: 3600000, //1小时后后自动关闭
  301. shade: [0.2] //0.1透明度的白色背景
  302. });
  303. backup_data(res.tab);
  304. } else {
  305. var _parent = parent;
  306. _parent.layer.alert('已升级最新版本,自动备份数据库失败,请立即前往备份!', {icon: 1, title:false}, function(){
  307. _parent.layer.closeAll();
  308. var url = eyou_basefile + "?m="+module_name+"&c=Tools&a=index";
  309. _parent.workspace.window.location.href = url;
  310. });
  311. }
  312. },
  313. error : function() {
  314. var _parent = parent;
  315. _parent.layer.alert('已升级最新版本,自动备份数据库失败,请立即前往备份!', {icon: 1, title:false}, function(){
  316. _parent.layer.closeAll();
  317. var url = eyou_basefile + "?m="+module_name+"&c=Tools&a=index";
  318. _parent.workspace.window.location.href = url;
  319. });
  320. }
  321. });
  322. }, 1500);
  323. }
  324. function backup_data(tab){
  325. var url = eyou_basefile + "?m="+module_name+"&c=Tools&a=export&_ajax=1";
  326. $.ajax({
  327. url: url,
  328. data: tab,
  329. type:'post',
  330. dataType:'json',
  331. success:function(res){
  332. if(res.code){
  333. if (tab.table) {
  334. $('#upgrade_backup_table', window.parent.document).html(tab.table);
  335. $('#upgrade_backup_speed', window.parent.document).html(tab.speed);
  336. }
  337. if(!$.isPlainObject(res.tab)){
  338. var loading = parent.layer.msg('备份完成……100%,请勿刷新页面!',
  339. {
  340. icon: 1,
  341. time: 2000, //1小时后后自动关闭
  342. shade: [0.2] //0.1透明度的白色背景
  343. });
  344. setTimeout(function(){
  345. parent.layer.closeAll();
  346. var full = parent.layer.alert('已升级最新版本!', {
  347. title: false,
  348. icon: 1,
  349. closeBtn: 0,
  350. btn: ['关闭'] //按钮
  351. }, function(){
  352. parent.layer.close(full);
  353. top.location.href = eyou_basefile;
  354. }
  355. );
  356. }, 1000);
  357. return;
  358. }
  359. setTimeout(function () {
  360. backup_data(res.tab);
  361. }, 350);
  362. } else {
  363. var full = parent.layer.alert('已升级最新版本!', {
  364. title: false,
  365. icon: 1,
  366. closeBtn: 0,
  367. btn: ['关闭'] //按钮
  368. }, function(){
  369. parent.layer.close(full);
  370. top.location.href = eyou_basefile;
  371. }
  372. );
  373. }
  374. },
  375. error : function() {
  376. var _parent = parent;
  377. _parent.layer.alert('已升级最新版本,自动备份数据库失败,请立即前往备份!', {icon: 1, title:false}, function(){
  378. _parent.layer.closeAll();
  379. var url = eyou_basefile + "?m="+module_name+"&c=Tools&a=index";
  380. _parent.workspace.window.location.href = url;
  381. });
  382. }
  383. });
  384. }