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.

432 lines
26 KiB

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