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.

482 lines
28 KiB

11 months ago
1 year ago
  1. /*
  2. *宝塔面板去除各种计算题与延时等待
  3. */
  4. if("undefined" != typeof bt && bt.hasOwnProperty("show_confirm")){
  5. bt.show_confirm = function(title, msg, callback, error) {
  6. layer.open({
  7. type: 1,
  8. title: title,
  9. area: "365px",
  10. closeBtn: 2,
  11. shadeClose: true,
  12. btn: [lan['public'].ok, lan['public'].cancel],
  13. content: "<div class='bt-form webDelete pd20'>\
  14. <p style='font-size:13px;word-break: break-all;margin-bottom: 5px;'>" + msg + "</p>" + (error || '') + "\
  15. </div>",
  16. yes: function (index, layero) {
  17. layer.close(index);
  18. if (callback) callback();
  19. }
  20. });
  21. }
  22. }
  23. if("undefined" != typeof bt && bt.hasOwnProperty("prompt_confirm")){
  24. bt.prompt_confirm = function (title, msg, callback) {
  25. layer.open({
  26. type: 1,
  27. title: title,
  28. area: "350px",
  29. closeBtn: 2,
  30. btn: ['确认', '取消'],
  31. content: "<div class='bt-form promptDelete pd20'>\
  32. <p>" + msg + "</p>\
  33. </div>",
  34. yes: function (layers, index) {
  35. layer.close(layers)
  36. if (callback) callback()
  37. }
  38. });
  39. }
  40. }
  41. if("undefined" != typeof bt && bt.hasOwnProperty("compute_confirm")){
  42. bt.compute_confirm = function (config, callback) {
  43. layer.open({
  44. type: 1,
  45. title: config.title,
  46. area: '430px',
  47. closeBtn: 2,
  48. shadeClose: true,
  49. btn: [lan['public'].ok, lan['public'].cancel],
  50. content:
  51. '<div class="bt-form hint_confirm pd30">\
  52. <div class="hint_title">\
  53. <i class="hint-confirm-icon"></i>\
  54. <div class="hint_con">' +
  55. config.msg +
  56. '</div>\
  57. </div>\
  58. </div>',
  59. yes: function (layers, index) {
  60. layer.close(layers)
  61. if (callback) callback()
  62. }
  63. });
  64. }
  65. }
  66. if("undefined" != typeof bt && bt.hasOwnProperty("input_confirm")){
  67. bt.input_confirm = function (config, callback) {
  68. layer.open({
  69. type: 1,
  70. title: config.title,
  71. area: '430px',
  72. closeBtn: 2,
  73. shadeClose: true,
  74. btn: [lan['public'].ok, lan['public'].cancel],
  75. content:
  76. '<div class="bt-form hint_confirm pd30">\
  77. <div class="hint_title">\
  78. <i class="hint-confirm-icon"></i>\
  79. <div class="hint_con">' +
  80. config.msg +
  81. '</div>\
  82. </div>\
  83. </div>',
  84. yes: function (layers, index) {
  85. layer.close(layers);
  86. if (callback) callback();
  87. },
  88. });
  89. }
  90. }
  91. if("undefined" != typeof database && database.hasOwnProperty("del_database")){
  92. database.del_database = function (wid, dbname, obj, callback) {
  93. var is_db_type = false, del_data = []
  94. if (typeof wid === 'object') {
  95. del_data = wid
  96. is_db_type = wid.some(function (item) {
  97. return item.db_type > 0
  98. })
  99. var ids = [];
  100. for (var i = 0; i < wid.length; i++) {
  101. ids.push(wid[i].id);
  102. }
  103. wid = ids
  104. }
  105. var type = $('.database-pos .tabs-item.active').data('type'),
  106. title = '',
  107. tips = '';
  108. title = typeof dbname === "function" ? '批量删除数据库' : '删除数据库 - [ ' + dbname + ' ]';
  109. tips = is_db_type || !recycle_bin_db_open || type !== 'mysql' ? '<span class="color-red">当前列表存在彻底删除后无法恢复的数据库</span>,请仔细查看列表,以防误删,是否继续操作?' : '当前列表数据库将迁移至数据库回收站,如需彻底删除请前往数据库回收站,是否继续操作?'
  110. var arrs = wid instanceof Array ? wid : [wid]
  111. var ids = JSON.stringify(arrs),
  112. countDown = 9;
  113. if (arrs.length == 1) countDown = 4
  114. var loadT = bt.load('正在检测数据库数据信息,请稍候...'),
  115. param = { url: 'database/' + bt.data.db_tab_name + '/check_del_data', data: { data: JSON.stringify({ ids: ids }) } }
  116. if (bt.data.db_tab_name == 'mysql') param = { url: 'database?action=check_del_data', data: { ids: ids } }
  117. bt_tools.send(param, function (res) {
  118. loadT.close()
  119. layer.open({
  120. type: 1,
  121. title: title,
  122. area: '740px',
  123. skin: 'verify_site_layer_info',
  124. closeBtn: 2,
  125. shadeClose: true,
  126. content: '<div class="check_delete_site_main hint_confirm pd30">' +
  127. "<div class='hint_title'>\
  128. <i class=\'hint-confirm-icon\'></i>\
  129. <div class=\'hint_con\'>"+ tips + "</div>\
  130. </div>"+
  131. '<div id="check_layer_content" class="ptb15">' +
  132. '</div>' +
  133. '<div class="check_layer_message">' +
  134. (is_db_type ? '<span class="color-red">注意:远程数据库暂不支持数据库回收站,选中的数据库将彻底删除</span><br>' : '') +
  135. (!recycle_bin_db_open ? '<span class="color-red">风险操作:当前数据库回收站未开启,删除数据库将永久消失</span><br>' : '')
  136. + '<span class="color-red">请仔细阅读以上要删除信息,防止数据库被误删</span></div>' +
  137. '</div>',
  138. btn: ['下一步', lan.public.cancel],
  139. success: function (layers) {
  140. setTimeout(function () { $(layers).css('top', ($(window).height() - $(layers).height()) / 2); }, 50)
  141. var rdata = res.data,
  142. newTime = parseInt(new Date().getTime() / 1000),
  143. t_icon = ' <span class="glyphicon glyphicon-info-sign" style="color: red;width:15px;height: 15px;;vertical-align: middle;"></span>';
  144. for (var j = 0; j < rdata.length; j++) {
  145. for (var i = 0; i < del_data.length; i++) {
  146. if (rdata[j].id == del_data[i].id) {
  147. var is_time_rule = (newTime - rdata[j].st_time) > (86400 * 30) && (rdata[j].total > 1024 * 10),
  148. is_database_rule = res.db_size <= rdata[j].total,
  149. database_time = bt.format_data(rdata[j].st_time, 'yyyy-MM-dd'),
  150. database_size = bt.format_size(rdata[j].total);
  151. var f_size = database_size
  152. var t_size = '注意:此数据库较大,可能为重要数据,请谨慎操作.\n数据库:' + database_size;
  153. if (rdata[j].total < 2048) t_size = '注意事项:当前数据库不为空,可能为重要数据,请谨慎操作.\n数据库:' + database_size;
  154. if (rdata[j].total === 0) t_size = '';
  155. rdata[j]['t_size'] = t_size
  156. rdata[j]['f_size'] = f_size
  157. rdata[j]['database_time'] = database_time
  158. rdata[j]['is_time_rule'] = is_time_rule
  159. rdata[j]['is_database_rule'] = is_database_rule
  160. rdata[j]['db_type'] = del_data[i].db_type
  161. rdata[j]['conn_config'] = del_data[i].conn_config
  162. }
  163. }
  164. }
  165. var filterData = rdata.filter(function (el) {
  166. return ids.indexOf(el.id) != -1
  167. })
  168. bt_tools.table({
  169. el: '#check_layer_content',
  170. data: filterData,
  171. height: '300px',
  172. column: [
  173. { fid: 'name', title: '数据库名称' },
  174. {
  175. title: '数据库大小', template: function (row) {
  176. return '<span class="' + (row.is_database_rule ? 'warning' : '') + '" style="width: 110px;" title="' + row.t_size + '">' + row.f_size + (row.is_database_rule ? t_icon : '') + '</span>'
  177. }
  178. },
  179. {
  180. title: '数据库位置', template: function (row) {
  181. var type_column = '-'
  182. switch (row.db_type) {
  183. case 0:
  184. type_column = '本地数据库'
  185. break;
  186. case 1:
  187. case 2:
  188. type_column = '远程数据库'
  189. break;
  190. }
  191. return '<span style="width: 110px;" title="' + type_column + '">' + type_column + '</span>'
  192. }
  193. },
  194. {
  195. title: '创建时间', template: function (row) {
  196. return '<span ' + (is_time_rule && row.total != 0 ? 'class="warning"' : '') + ' title="' + (row.is_time_rule && row.total != 0 ? '重要:此数据库创建时间较早,可能为重要数据,请谨慎操作.' : '') + '时间:' + row.database_time + '">' + row.database_time + '</span>'
  197. }
  198. },
  199. {
  200. title: '删除结果', align: 'right', template: function (row, index, ev, _that) {
  201. var _html = ''
  202. switch (row.db_type) {
  203. case 0:
  204. _html = type !== 'mysql' ? '彻底删除' : (!recycle_bin_db_open ? '彻底删除' : '移至回收站')
  205. break;
  206. case 1:
  207. case 2:
  208. _html = '彻底删除'
  209. break;
  210. }
  211. return '<span style="width: 110px;" class="' + (_html === '彻底删除' ? 'warning' + (row.db_type > 0 ? ' remote_database' : '') : '') + '">' + _html + '</span>'
  212. }
  213. }
  214. ],
  215. success: function () {
  216. $('#check_layer_content').find('.glyphicon-info-sign').click(function (e) {
  217. var msg = $(this).parent().prop('title')
  218. msg = msg.replace('数据库:','<br>数据库:')
  219. layer.tips(msg, $(this).parent(), { tips: [1, 'red'], time: 3000 })
  220. $(document).click(function (ev) {
  221. layer.closeAll('tips');
  222. $(this).unbind('click');
  223. ev.stopPropagation();
  224. ev.preventDefault();
  225. });
  226. e.stopPropagation();
  227. e.preventDefault();
  228. });
  229. if ($('.remote_database').length) {
  230. $('.remote_database').each(function (index, el) {
  231. var id = $(el).parent().parent().parent().index()
  232. $('#check_layer_content tbody tr').eq(id).css('background-color', '#ff00000a')
  233. })
  234. }
  235. }
  236. })
  237. },
  238. yes: function (indes, layers) {
  239. title = typeof dbname === "function" ? '二次验证信息,批量删除数据库' : '二次验证信息,删除数据库 - [ ' + dbname + ' ]';
  240. if (type !== 'mysql') {
  241. tips = '<span class="color-red">当前数据库暂不支持数据库回收站,删除后将无法恢复</span>,此操作不可逆,是否继续操作?';
  242. } else {
  243. tips = is_db_type ? '<span class="color-red">远程数据库不支持数据库回收站,删除后将无法恢复</span>,此操作不可逆,是否继续操作?' : recycle_bin_db_open ? '删除后如需彻底删除请前往数据库回收站,是否继续操作?' : '删除后可能会影响业务使用,此操作不可逆,是否继续操作?'
  244. }
  245. layer.open({
  246. type: 1,
  247. title: title,
  248. icon: 0,
  249. skin: 'delete_site_layer',
  250. area: "530px",
  251. closeBtn: 2,
  252. shadeClose: true,
  253. content: "<div class=\'bt-form webDelete hint_confirm pd30\' id=\'site_delete_form\'>" +
  254. "<div class='hint_title'>\
  255. <i class=\'hint-confirm-icon\'></i>\
  256. <div class=\'hint_con\'>"+ tips + "</div>\
  257. </div>"+
  258. "<div style=\'color:red;margin:18px 0 18px 18px;font-size:14px;font-weight: bold;\'>注意:数据无价,请谨慎操作!!!" + (type === 'mysql' && !recycle_bin_db_open ? '<br>风险操作:当前数据库回收站未开启,删除数据库将永久消失!' : '') + "</div>"+
  259. "</div>",
  260. btn: ['确认删除', '取消删除'],
  261. yes: function (indexs) {
  262. var data = {
  263. id: wid,
  264. name: dbname
  265. };
  266. if (typeof dbname === "function") {
  267. delete data.id;
  268. delete data.name;
  269. }
  270. layer.close(indexs)
  271. layer.close(indes)
  272. if (typeof dbname === "function") {
  273. dbname(data)
  274. } else {
  275. data.id = data.id[0]
  276. bt.database.del_database(data, function (rdata) {
  277. layer.closeAll()
  278. if (callback) callback(rdata);
  279. bt.msg(rdata);
  280. })
  281. }
  282. }
  283. })
  284. }
  285. })
  286. })
  287. }
  288. }
  289. if("undefined" != typeof site && site.hasOwnProperty("del_site")){
  290. site.del_site = function (wid, wname, callback) {
  291. title = typeof wname === "function" ? '批量删除站点' : '删除站点 [ ' + wname + ' ]';
  292. layer.open({
  293. type: 1,
  294. title: title,
  295. icon: 0,
  296. skin: 'delete_site_layer',
  297. area: "440px",
  298. closeBtn: 2,
  299. shadeClose: true,
  300. content: "<div class=\'bt-form webDelete pd30\' id=\'site_delete_form\'>" +
  301. '<i class="layui-layer-ico layui-layer-ico0"></i>' +
  302. "<div class=\'f13 check_title\'>是否要删除关联的FTP、数据库、站点目录!</div>" +
  303. "<div class=\"check_type_group\">" +
  304. "<label><input type=\"checkbox\" name=\"ftp\"><span>FTP</span></label>" +
  305. "<label><input type=\"checkbox\" name=\"database\"><span>数据库</span>" + (!recycle_bin_db_open ? '<span class="glyphicon glyphicon-info-sign" style="color: red"></span>' : '') + "</label>" +
  306. "<label><input type=\"checkbox\" name=\"path\"><span>站点目录</span>" + (!recycle_bin_open ? '<span class="glyphicon glyphicon-info-sign" style="color: red"></span>' : '') + "</label>" +
  307. "</div>" +
  308. "</div>",
  309. btn: [lan.public.ok, lan.public.cancel],
  310. success: function (layers, indexs) {
  311. $(layers).find('.check_type_group label').hover(function () {
  312. var name = $(this).find('input').attr('name');
  313. if (name === 'database' && !recycle_bin_db_open) {
  314. layer.tips('风险操作:当前数据库回收站未开启,删除数据库将永久消失!', this, { tips: [1, 'red'], time: 0 })
  315. } else if (name === 'path' && !recycle_bin_open) {
  316. layer.tips('风险操作:当前文件回收站未开启,删除站点目录将永久消失!', this, { tips: [1, 'red'], time: 0 })
  317. }
  318. }, function () {
  319. layer.closeAll('tips');
  320. });
  321. },
  322. yes: function (indexs) {
  323. var data = { id: wid, webname: wname };
  324. $('#site_delete_form input[type=checkbox]').each(function (index, item) {
  325. if ($(item).is(':checked')) data[$(item).attr('name')] = 1
  326. })
  327. var is_database = data.hasOwnProperty('database'), is_path = data.hasOwnProperty('path'), is_ftp = data.hasOwnProperty('ftp');
  328. if ((!is_database && !is_path) && (!is_ftp || is_ftp)) {
  329. if (typeof wname === "function") {
  330. wname(data)
  331. return false;
  332. }
  333. bt.site.del_site(data, function (rdata) {
  334. layer.close(indexs);
  335. if (callback) callback(rdata);
  336. bt.msg(rdata);
  337. })
  338. return false
  339. }
  340. if (typeof wname === "function") {
  341. delete data.id;
  342. delete data.webname;
  343. }
  344. layer.close(indexs)
  345. var ids = JSON.stringify(wid instanceof Array ? wid : [wid]), countDown = typeof wname === 'string' ? 4 : 9;
  346. title = typeof wname === "function" ? '二次验证信息,批量删除站点' : '二次验证信息,删除站点 [ ' + wname + ' ]';
  347. var loadT = bt.load('正在检测站点数据信息,请稍候...')
  348. bt.send('check_del_data', 'site/check_del_data', { ids: ids }, function (res) {
  349. loadT.close()
  350. layer.open({
  351. type: 1,
  352. title: title,
  353. closeBtn: 2,
  354. skin: 'verify_site_layer_info',
  355. area: '740px',
  356. content: '<div class="check_delete_site_main pd30">' +
  357. '<i class="layui-layer-ico layui-layer-ico0"></i>' +
  358. '<div class="check_layer_title">堡塔温馨提示您,请冷静几秒钟,确认以下要删除的数据。</div>' +
  359. '<div class="check_layer_content">' +
  360. '<div class="check_layer_item">' +
  361. '<div class="check_layer_site"></div>' +
  362. '<div class="check_layer_database"></div>' +
  363. '</div>' +
  364. '</div>' +
  365. '<div class="check_layer_error ' + (is_database && data['database'] && !recycle_bin_db_open ? '' : 'hide') + '"><span class="glyphicon glyphicon-info-sign"></span>风险事项:当前未开启数据库回收站功能,删除数据库后,数据库将永久消失!</div>' +
  366. '<div class="check_layer_error ' + (is_path && data['path'] && !recycle_bin_open ? '' : 'hide') + '"><span class="glyphicon glyphicon-info-sign"></span>风险事项:当前未开启文件回收站功能,删除站点目录后,站点目录将永久消失!</div>' +
  367. '<div class="check_layer_message"><span style="color:red">注意:请仔细阅读以上要删除信息,防止网站数据被误删</span></div>' +
  368. '</div>',
  369. // recycle_bin_db_open &&
  370. // recycle_bin_open &&
  371. btn: ['确认删除', '取消删除'],
  372. success: function (layers) {
  373. var html = '', rdata = res.data;
  374. for (var i = 0; i < rdata.length; i++) {
  375. var item = rdata[i], newTime = parseInt(new Date().getTime() / 1000),
  376. t_icon = '<span class="glyphicon glyphicon-info-sign" style="color: red;width:15px;height: 15px;;vertical-align: middle;"></span>';
  377. site_html = (function (item) {
  378. if (!is_path) return ''
  379. var is_time_rule = (newTime - item.st_time) > (86400 * 30) && (item.total > 1024 * 10),
  380. is_path_rule = res.file_size <= item.total,
  381. dir_time = bt.format_data(item.st_time, 'yyyy-MM-dd'),
  382. dir_size = bt.format_size(item.total);
  383. var f_html = '<i ' + (is_path_rule ? 'class="warning"' : '') + ' style = "vertical-align: middle;" > ' + (item.limit ? '大于50MB' : dir_size) + '</i> ' + (is_path_rule ? t_icon : '');
  384. var f_title = (is_path_rule ? '注意:此目录较大,可能为重要数据,请谨慎操作.\n' : '') + '目录:' + item.path + '(' + (item.limit ? '大于' : '') + dir_size + ')';
  385. return '<div class="check_layer_site">' +
  386. '<span title="站点:' + item.name + '">站点名:' + item.name + '</span>' +
  387. '<span title="' + f_title + '" >目录:<span style="vertical-align: middle;max-width: 160px;width: auto;">' + item.path + '</span> (' + f_html + ')</span>' +
  388. '<span title="' + (is_time_rule ? '注意:此站点创建时间较早,可能为重要数据,请谨慎操作.\n' : '') + '时间:' + dir_time + '">创建时间:<i ' + (is_time_rule ? 'class="warning"' : '') + '>' + dir_time + '</i></span>' +
  389. '</div>'
  390. }(item)),
  391. database_html = (function (item) {
  392. if (!is_database || !item.database) return '';
  393. var is_time_rule = (newTime - item.st_time) > (86400 * 30) && (item.total > 1024 * 10),
  394. is_database_rule = res.db_size <= item.database.total,
  395. database_time = bt.format_data(item.database.st_time, 'yyyy-MM-dd'),
  396. database_size = bt.format_size(item.database.total);
  397. var f_size = '<i ' + (is_database_rule ? 'class="warning"' : '') + ' style = "vertical-align: middle;" > ' + database_size + '</i> ' + (is_database_rule ? t_icon : '');
  398. var t_size = '注意:此数据库较大,可能为重要数据,请谨慎操作.\n数据库:' + database_size;
  399. return '<div class="check_layer_database">' +
  400. '<span title="数据库:' + item.database.name + '">数据库:' + item.database.name + '</span>' +
  401. '<span title="' + t_size + '">大小:' + f_size + '</span>' +
  402. '<span title="' + (is_time_rule && item.database.total != 0 ? '重要:此数据库创建时间较早,可能为重要数据,请谨慎操作.' : '') + '时间:' + database_time + '">创建时间:<i ' + (is_time_rule && item.database.total != 0 ? 'class="warning"' : '') + '>' + database_time + '</i></span>' +
  403. '</div>'
  404. }(item))
  405. if ((site_html + database_html) !== '') html += '<div class="check_layer_item">' + site_html + database_html + '</div>';
  406. }
  407. if (html === '') html = '<div style="text-align: center;width: 100%;height: 100%;line-height: 300px;font-size: 15px;">无数据</div>'
  408. $('.check_layer_content').html(html)
  409. },
  410. yes: function (indes, layers) {
  411. if (typeof wname === "function") {
  412. wname(data)
  413. } else {
  414. bt.site.del_site(data, function (rdata) {
  415. layer.closeAll()
  416. if (rdata.status) site.get_list();
  417. if (callback) callback(rdata);
  418. bt.msg(rdata);
  419. })
  420. }
  421. }
  422. })
  423. })
  424. }
  425. })
  426. }
  427. }
  428. if("undefined" != typeof bt && bt.hasOwnProperty("firewall") && bt.firewall.hasOwnProperty("add_accept_port")){
  429. bt.firewall.add_accept_port = function(type, port, ps, callback) {
  430. var action = "AddDropAddress";
  431. if (type == 'port') {
  432. ports = port.split(':');
  433. if (port.indexOf('-') != -1) ports = port.split('-');
  434. for (var i = 0; i < ports.length; i++) {
  435. if (!bt.check_port(ports[i])) {
  436. layer.msg('可用端口范围:1-65535', { icon: 2 });
  437. // layer.msg(lan.firewall.port_err, {
  438. // icon: 5
  439. // });
  440. return;
  441. }
  442. }
  443. action = "AddAcceptPort";
  444. }
  445. loading = bt.load();
  446. bt.send(action, 'firewall/' + action, { port: port, type: type, ps: ps }, function(rdata) {
  447. loading.close();
  448. if (callback) callback(rdata);
  449. })
  450. }
  451. }
  452. function SafeMessage(j, h, g, f) {
  453. if(f == undefined) {
  454. f = ""
  455. }
  456. var mess = layer.open({
  457. type: 1,
  458. title: j,
  459. area: "350px",
  460. closeBtn: 2,
  461. shadeClose: true,
  462. content: "<div class='bt-form webDelete pd20 pb70'><p>" + h + "</p>" + f + "<div class='bt-form-submit-btn'><button type='button' class='btn btn-danger btn-sm bt-cancel'>"+lan.public.cancel+"</button> <button type='button' id='toSubmit' class='btn btn-success btn-sm' >"+lan.public.ok+"</button></div></div>"
  463. });
  464. $(".bt-cancel").click(function(){
  465. layer.close(mess);
  466. });
  467. $("#toSubmit").click(function() {
  468. layer.close(mess);
  469. g();
  470. })
  471. }
  472. $(document).ready(function () {
  473. if($('#updata_pro_info').length>0){
  474. $('#updata_pro_info').html('');
  475. bt.set_cookie('productPurchase', 1);
  476. }
  477. })