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.

457 lines
26 KiB

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