',
end: function () {
bt.clear_cookie('pay_source');
},
success: function ($layer, index) {
$.getScript('https://js.stripe.com/v3/');
var layerThat = this;
layerThat.renderUserInfo();
layerThat.renderProductMenu();
var init = function () {
var removeLoad = layerThat.addLoading('.libPay-layer-item');
layerThat.renderFeature();
layerThat.renderAuthList(function (rdata) {
if (rdata.length > 0) {
cutTab('authorization');
layerThat.renderProductPrice(function () {
removeLoad();
});
} else {
layerThat.renderVoucher(function (rdata) {
if (rdata.length > 0) {
cutTab('voucher');
}
layerThat.renderProductPrice(function () {
removeLoad();
});
});
}
});
};
init();
$('.switch-cycle-right').click(function () {
var num = $(this).prev().children().length;
var totalWidth = 80;
$.each($('.pay-pro-cycle .pay-cycle-btns'), function (i, elem) {
totalWidth += elem.offsetWidth;
});
var libPayWidht = $('.libPay-line-item').width();
var width = totalWidth - libPayWidht + 40;
var remainder = num % 4; // 获取余数
$(this)
.prev()
.css('transform', 'translateX(-' + remainder * width + 'px)');
$('.switch-cycle-left').removeClass('hide');
$('#libPay-theme-price').css('padding-left', '30px');
$(this).addClass('hide');
});
$('.switch-cycle-left').click(function (ev) {
if (bt.del_seven_coupon) {
var $children = $('.pay-pro-cycle').children();
if ($($children[0]).data('data').nums.length == 1) {
$($children[0]).remove();
bt.del_seven_coupon = false;
}
}
$('#libPay-theme-price').removeAttr('style');
$('.switch-cycle-right').removeClass('hide');
$(this).next().removeAttr('style');
$(this).addClass('hide');
});
$('.pay-btn-group').on('click', 'li', function () {
$(this).addClass('active').siblings('.active').removeClass('active');
});
// 切换菜单
$('.libPay-menu').on('click', '.libPay-menu-type', function () {
$(this).addClass('active').siblings('.active').removeClass('active');
var data = $('.libPay-menu .libPay-menu-type.active').data();
if (data.title !== 'PRO') {
$('.pay-pro-cycle').css('transform', 'translateX(-27px)');
}
layerThat.renderProductPrice();
layerThat.renderAuthNums();
init();
});
// 产品周期切换
$('#libPay-theme-price .pay-pro-cycle').on('click', 'li', function () {
$(this).addClass('active').siblings('.active').removeClass('active');
layerThat.renderAuthNums();
var numConfig = $('#authorization .auth-num .active').data();
var condition = $('.libPay-qcode-left .pay-type-btn.active').data('condition');
if (condition === 'stripe') {
layerThat.renderTotalPrice(numConfig.num, false);
} else if (condition === 'paypal') {
layerThat.renderPaypal(numConfig.num, false);
}
});
// 多台授权切换
$('#authorization .auth-num').on('click', 'li', function () {
$(this).addClass('active').siblings('.active').removeClass('active');
var numConfig = $('#authorization .auth-num .active').data();
var condition = $('.libPay-qcode-left .pay-type-btn.active').data('condition');
if (condition === 'stripe') {
layerThat.renderTotalPrice(numConfig.num, true);
} else if (condition === 'paypal') {
layerThat.renderPaypal(numConfig.num, true);
}
});
// 点击支付
$('#checkout-button').click(function () {
var config = $(this).data('data');
var loadT = bt.load('Getting the session ID,Please waiting!');
var stripe = Stripe(config.stripe_publishable_key);
var subscribe = config.subscription_price > 0 && $('.pay-subscription input').prop('checked') ? 1 : 0;
that.pro.get_check_out_info(
{
order_no: config.order_no,
subscribe: subscribe,
},
function (res) {
loadT.close();
if (res.id) {
stripe.redirectToCheckout({ sessionId: res.id });
} else {
layer.msg('Payment order failed, please contact administrator!', { icon: 2 });
}
}
);
});
// 切换tab
function cutTab(condition) {
var $el = $('.libPay-qcode-left .pay-type-btn[data-condition="' + condition + '"]');
var index = $el.index();
$el.addClass('active').siblings('.active').removeClass('active');
$('.libPay-qcode-right .libPay-qcode-item').eq(index).removeClass('hide').siblings('.libPay-qcode-item').addClass('hide');
}
// 支付方式切换
$('.libPay-qcode-left .pay-type-btn').click(function () {
var condition = $(this).data('condition');
cutTab(condition);
var condition = $(this).data('condition');
var numConfig = $('#authorization .auth-num .active').data();
switch (condition) {
case 'stripe':
layerThat.renderTotalPrice(numConfig.num || 1);
break;
case 'paypal':
layerThat.renderPaypal(numConfig.num || 1);
break;
case 'voucher':
layerThat.renderVoucher();
break;
case 'authorization':
layerThat.renderAuthList();
break;
}
});
// 切换用户
$('.libPay-qcode-item .userinfo a').click(function () {
bt.pub.bind_btname(function () {
// bt.soft.product_pay_view(config);
window.location.reload();
});
});
// 使用抵扣卷
$('#use-voucher').click(function () {
if ($(this).hasClass('disabled')) return false;
var data = $('.voucher-group .active').data();
if (!data.serial_no) {
layer.msg('No vouchers');
return false;
}
bt.soft.pro.create_order_voucher(data.pid, data.code, data.id, data.cycle, data.cycle_unit, data.charge_type, function (rdata) {
layer.closeAll();
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
bt.msg(rdata);
if (rdata.status) {
getPaymentStatus();
}
});
});
// 授权
$('#use-auth').click(function () {
if ($(this).hasClass('disabled')) return false;
var _serial_no = $('.auth-group .active').attr('data-id');
if (typeof _serial_no == 'undefined') return false;
var loadU = bt.load('Under licensing!');
bt.send('auth_activate', 'auth/auth_activate', { serial_no: _serial_no }, function (res) {
loadU.close();
if (res) {
layer.msg(res.msg, { icon: res.status ? 1 : 2 });
if (res.status) {
window.location.reload();
}
}
});
});
var layerIndex = -1;
$('.pay-subscription .bt-ico-ask').hover(
function () {
layerIndex = layer.tips('
', $(this), {
tips: [1, '#999'],
time: 0,
area: '410px',
});
},
function () {
layer.close(layerIndex);
}
);
},
addLoading: function (elem) {
var $el = $(elem);
$el.children().addClass('hide');
if ($el.children('.cloading').length === 0) {
$el.append('
');
}
return function removeLoad() {
$el.children('.cloading').remove();
$el.children().removeClass('hide');
};
},
getConfig: function () {
var data = $('.libPay-menu .libPay-menu-type.active').data();
return data;
},
// 渲染菜单
renderProductMenu: function () {
var menus = [];
if (config.plugin) {
menus.push({
title: config.name,
name: config.name,
ps: 'Plug-in only',
desc: config.ps,
pid: config.pid,
renew: config.renew || false,
is_pro: false,
active: (config.pro < 0 && config.ltd < 0) || (config.type == 12 && config.ltd < 0) ? true : false,
});
}
if (
(((config.pro > 0 || config.pro == -2 || config.ltd < 0) && ((config.ltd > 0 && config.ltd != config.pro) || config.ltd < 0) && config.type != 12) ||
config.limit == 'pro' ||
(config.ltd < 0 && config.pro == -1)) &&
config.type != 12 &&
((config.ltd < 0 && config.pro > 0) || (config.ltd < 0 && config.pro < 0))
) {
menus.push({
title: 'PRO',
name: '',
pid: '100000058',
ps: 'Recommended',
renew: config.renew || false,
is_pro: true,
active:
((config.type == 8 && !config.plugin) || config.limit == 'pro' || config.pro > 0 || config.pro == -2) &&
config.ltd < 0 &&
(config.ltd == -2 ? (config.pro == -2 ? false : true) : true),
});
}
var $el = null;
$.each(menus, function (index, item) {
$el = $(
''
).data(item);
$('.libPay-menu').append($el);
});
},
renderFeature: function () {
var config = this.getConfig();
if (config.is_pro) {
$('.pro-left-introduce .pro-left-title>div').html('
');
$('.pro-left-introduce .pro-left-title>span').removeClass('hide').html(config.ps);
$('.pro-left-list-title').text('Pro Feature: ');
$('.pro-price-herf').removeClass('hide');
bt.send('get_plugin_remarks', 'auth/get_plugin_remarks', { product_id: '100000058' }, function (rdata) {
var html = '';
$.each(rdata.res, function (index, item) {
html += '
';
});
$('.pro-left-list-content').removeAttr('style').html(html);
});
} else {
$('.pro-left-introduce .pro-left-title>div').html('
');
$('.pro-left-introduce .pro-left-title>span').addClass('hide').html(config.ps);
$('.pro-left-list-title').text('Plug-in description: ');
$('.pro-left-list-content')
.css({
width: '186px',
'line-height': '23px',
})
.html(config.desc);
$('.pro-price-herf').addClass('hide');
}
},
// 默认选中的套餐索引
// defaultPackageIndex: 0,
// // 默认选中的授权台数索引
// defaultAuthIndex: 0,
// 渲染产品价格
renderProductPrice: function (callback) {
var layerThat = this;
// 获取产品价格数据
var config = layerThat.getConfig();
that.get_product_discount_cache(config, function (rdata) {
if (callback) callback(rdata);
// 大于4个显示左右切换按钮
var num = rdata.length;
if (num > 4) {
$('.switch-cycle-right').removeClass('hide');
} else {
$('.switch-cycle-right,.switch-cycle-left').addClass('hide');
}
// 遍历渲染产品价格
var html = '';
var htmlNum = '';
$('#libPay-theme-price .pay-pro-cycle').empty();
$('#authorization .auth-num').empty();
that.each(rdata, function (key, item) {
const priceItem = item.children[0]; // 默认选中的授权台数索引
var keys = item.cycle;
var unit = item.cycle_unit;
var priceByDay = (priceItem.price / ((priceItem.cycle / (priceItem.cycle_unit === 'year' ? 1 : 12)) * 365)).toFixed(2);
// 产品周期
var cycleUnit = '';
// 每天低至XX$
var dayPrice = '';
if (item.cycle === '999') {
cycleUnit = 'Lifetime';
dayPrice = 'Best value';
} else {
cycleUnit = item.cycle + ' ' + item.cycle_unit + (item.cycle > 1 ? 's' : '');
dayPrice = 'As low as $' + priceByDay + '/day';
}
const authNum = item.children;
if (key === 0) {
that.each(authNum, function (key1, numItem) {
htmlNum =
'\
';
$('#authorization .auth-num').append(
$(htmlNum).data(
$.extend(
{
pid: config.pid,
dom_index: key,
},
numItem
)
)
);
});
}
html =
'\
';
$('#libPay-theme-price .pay-pro-cycle').append(
$(html).data(
$.extend(
{
pid: config.pid,
dom_index: key,
},
priceItem
)
)
);
});
layerThat.renderTotalPrice();
});
layerThat.renderAuthNums();
},
// 渲染授权数量选项
renderAuthNums: function () {
var layerThat = this;
// 获取产品价格数据
var config = layerThat.getConfig();
var selectedCycle = $('#libPay-theme-price .pay-pro-cycle li.active').data('type');
var selectedunit = $('#libPay-theme-price .pay-pro-cycle li.active').data('unit');
var selectedAuthIndex = $('#authorization .auth-num li.active').index();
that.get_product_discount_cache(config, function (rdata) {
// 查找对应周期的授权数量数据
var authNumData = null;
for (var i = 0; i < rdata.length; i++) {
if (rdata[i].cycle == selectedCycle && rdata[i].cycle_unit == selectedunit) {
authNumData = rdata[i].children;
break;
}
}
if (authNumData) {
// 清空授权数量选项
$('#authorization .auth-num').empty();
// 遍历渲染授权数量选项
for (var j = 0; j < authNumData.length; j++) {
var authNumItem = authNumData[j];
var htmlNum =
'
';
var numItem = {
pid: config.pid,
dom_index: j,
};
var authNumElement = $(htmlNum).data($.extend(numItem, authNumItem));
$('#authorization .auth-num').append(authNumElement);
}
}
});
},
// 渲染用户信息
renderUserInfo: function () {
var bt_user_info = bt.get_cookie('bt_user_info');
if (!bt_user_info) {
bt.pub.get_user_info(function (res) {
$('.libPay-qcode-right .userinfo .info_value').html(res.data.username);
});
} else {
$('.libPay-qcode-right .userinfo .info_value').html(JSON.parse(bt_user_info).data.username);
}
},
renderEndTime: function () {
var endTime = null;
if (!config.is_alone) {
// 条件:当前为插件
if (config.plugin) {
title = (!config.renew ? 'Buy ' : '续费') + config.name;
ndTime = !config.renew ? config.renew : null;
} else if (config.pro == -1 && config.ltd == -1) {
// 条件:专业版和企业版都没有购买过
title = 'Upgrade to Pro, all plugins are free to use';
} else if (config.ltd > 0) {
// 条件:企业版续费
title = 'Renew ' + (config.name == '' ? '宝塔专业版' : config.name);
endTime = config.ltd;
} else if (config.pro > 0 || config.pro == -2) {
// 条件:专业版续费
title = 'Renew ' + (config.name == '' ? '宝塔专业版' : config.name);
endTime = config.pro;
} else if (config.ltd == -2) {
title = 'Renew ' + (config.name == '' ? '宝塔专业版' : config.name);
endTime = config.ltd;
}
} else {
title = (config.ltd > 0 ? '续费' : '购买') + '宝塔企业版';
}
if (endTime != null) {
$('.endTime span').html(endTime > parseInt(new Date().getTime() / 1000) ? bt.format_data(endTime) : '
');
} else {
$('.endTime').hide();
}
},
// 渲染总价格
renderTotalPrice: function (num, isNum) {
var condition = $('.libPay-qcode-left .pay-type-btn.active').data('condition');
if (condition !== 'stripe') {
return;
}
var layerThat = this;
var removeLoad = layerThat.addLoading('.libPay-qcode-item:not(.hide)');
var numActive = $('#authorization .auth-num .active').data();
var priceActive = $('#libPay-theme-price .pay-pro-cycle li.active').data();
var config = null;
if (isNum === true) {
config = $('#authorization .auth-num .active').data();
} else {
config = $('#libPay-theme-price .pay-pro-cycle .active').data();
}
config = priceActive;
config.num = numActive;
var param = { pid: config.pid, cycle: config.cycle, cycle_unit: config.cycle_unit, charge_type: config.charge_type, num: num || 1 };
param.source = parseInt(bt.get_cookie('pay_source') || 0);
if (param.source === 0) {
if ($('.btpro-gray').length == 1) {
// 是否免费版
param.source = 27;
} else {
param.source = 28;
}
}
if (!param.pid) delete param.pid;
if (bt.get_cookie('serial_no') != null) param.serial_no = config.serial_no || bt.get_cookie('serial_no');
that.pro.create_order(param, function (rdata) {
removeLoad();
if (rdata.status === false) {
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
layer.msg(rdata.msg, { icon: 2 });
return;
}
var cycle = '';
if (config.cycle === 999) {
cycle = 'Lifetime';
} else {
cycle = config.cycle + ' ' + config.cycle_unit + (config.cycle > 1 ? 's' : '');
}
// var unit = config.num + ' unit' + (config.num > 1 ? 's' : '');
// 改成接口请求后获取到的价格 rdata
$('.libPayTotal').html('
' + rdata.price); //
$('.pay-price .org_price').text('$' + rdata.market_price + '/' + cycle); //
$('.pay-price .libPayCycle').html('/' + cycle);
if (rdata.subscription_price > 0) {
//
$('.pay-subscription').removeClass('hide');
if (config.first_subscription_price > 0) {
$('.pay-subscription .org-price').removeClass('hide');
// 改成接口请求后获取到的价格 rdata
$('.pay-subscription .org-price').text('$' + rdata.subscription_price + '/' + config.cycle_unit); //
$('.pay-subscription .first-price .num').text(config.first_subscription_price); //
$('.pay-subscription .cycle-unit').text('/first ' + config.cycle_unit); //
} else {
$('.pay-subscription .org-price').addClass('hide');
$('.pay-subscription .first-price .num').text(rdata.subscription_price); //
$('.pay-subscription .cycle-unit').text('/' + config.cycle_unit); //
}
} else {
$('.pay-subscription').addClass('hide');
}
$('#checkout-button').data('data', rdata);
});
},
// 渲染paypal
renderPaypal: function (num, isNum) {
var layerThat = this;
var removeLoad = layerThat.addLoading('.libPay-qcode-item:not(.hide)');
// var config = $('#libPay-theme-price .pay-pro-cycle .active').data();
var numActive = $('#authorization .auth-num .active').data();
var priceActive = $('#libPay-theme-price .pay-pro-cycle li.active').data();
var config = null;
if (isNum === true) {
config = $('#authorization .auth-num .active').data();
} else {
config = $('#libPay-theme-price .pay-pro-cycle .active').data();
}
config = priceActive;
config.num = numActive;
var param = { pid: config.pid, cycle: config.cycle, cycle_unit: config.cycle_unit, charge_type: config.charge_type, num: num || 1 };
param.source = parseInt(bt.get_cookie('pay_source') || 0);
if (param.source === 0) {
if ($('.btpro-gray').length == 1) {
// 是否免费版
param.source = 27;
} else {
param.source = 28;
}
}
if (!param.pid) delete param.pid;
if (bt.get_cookie('serial_no') != null) param.serial_no = config.serial_no || bt.get_cookie('serial_no');
that.pro.create_order(param, function (rdata) {
removeLoad();
if (rdata.status === false) {
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
layer.msg(rdata.msg, { icon: 2 });
return;
}
var cycle = '';
if (config.cycle === 999) {
cycle = 'Lifetime';
} else {
cycle = config.cycle + ' ' + config.cycle_unit + (config.cycle > 1 ? 's' : '');
}
// var unit = config.num + ' unit' + (config.num > 1 ? 's' : '');
$('.libPayTotal').html('
' + rdata.price);
$('.pay-price .org_price').text('$' + rdata.market_price + '/' + cycle);
$('.pay-price .libPayCycle').html('/' + cycle);
layerThat.renderPaypalBtn(rdata);
});
},
renderPaypalBtn: function (rdata) {
$('#paypal-button-container').empty();
jQuery
.ajax({
url: '/static/js/polyfill.min.js?v=1715756461542',
dataType: 'script',
cache: true,
})
.done(function () {
var httpPromise = function (config) {
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: config.url,
data: config.data,
success: function (res) {
resolve(res);
},
error: function (err) {
reject(err);
},
});
});
};
var check_response = function (response) {
return new Promise((resolve, reject) => {
if (response.status) {
return resolve(response.res);
}
bt.msg(response);
reject(response.res);
});
};
jQuery
.ajax({
url: 'https://www.paypal.com/sdk/js?client-id=' + rdata.paypal_client_id,
dataType: 'script',
cache: true,
})
.done(function () {
var buttons = paypal.Buttons({
// 只渲染paypal支付按钮
fundingSource: paypal.FUNDING.PAYPAL,
// 绑定PayPal订单创建事件处理函数,请求paypal订单创建接口
// 注意: 该函数必须返回Promise对象, 若使用 JQuery.ajax() 函数
// 请使用 new Promise(fn(resolve(), reject())) 创建Promise对象并将其返回
// Promise必须返回从接口获取的id
createOrder: () => {
return httpPromise({
url: '/auth?action=get_paypal_session_id',
data: { oid: rdata.order_id },
})
.then(check_response)
.then(res => res);
},
// 绑定支付确认事件,请求paypal订单支付确认接口并传递orderId
// 注意: 该函数必须返回Promise对象,若使用 JQuery.ajax() 函数 请参照 step3
// Promise最终请展示支付结果
onApprove: data => {
return (
httpPromise({
url: '/auth?action=check_paypal_status',
data: { paypal_order_id: data.orderID },
})
// res是支付成功跳转的url
.then(check_response)
.then(res => {
layer.msg('Payment successful', { icon: 1 });
setTimeout(() => {
location.reload();
}, 1500);
})
);
},
});
buttons.render('#paypal-button-container');
});
});
},
// 渲染抵扣卷
renderVoucher: function (callback) {
var layerThat = this;
var config = layerThat.getConfig();
var removeLoad = layerThat.addLoading('.libPay-qcode-item:not(.hide)');
bt.soft.pro.get_voucher(config.pid, function (rdata) {
removeLoad();
if (callback) callback(rdata);
$('.voucher-group').empty();
if (rdata == null && !Array.isArray(rdata)) rdata = [];
if (rdata.length == 0) {
$('.voucher-group').addClass('hide');
$('#use-voucher').addClass('disabled').text('No vouchers');
return;
}
var $li = null;
that.each(rdata, function (index, item) {
var name = item.cycle_unit == 'month' && item.cycle == 999 ? 'Lifetime' : item.cycle + that.pro.conver_unit(item.cycle_unit);
$li = $('
').data($.extend({ pid: config.pid }, item));
$('.voucher-group').append($li);
});
$('.voucher-group').removeClass('hide');
$('#use-voucher').removeClass('disabled').text('Pay');
});
},
// 渲染授权列表
renderAuthList: function (callback) {
var layerThat = this;
var config = layerThat.getConfig();
var removeLoad = layerThat.addLoading('.libPay-qcode-item:not(.hide)');
bt.send('get_product_auth', 'auth/get_product_auth', { page: 1, pageSize: 15, pid: config.pid }, function (rdata) {
removeLoad();
if (callback) callback(rdata);
$('.auth-group').empty();
if (rdata == null && !Array.isArray(rdata)) rdata = [];
if (rdata.length == 0) {
$('.auth-group').addClass('hide');
$('#use-auth').addClass('disabled').text('No authorization');
return;
}
var html = '';
$.each(rdata, function (index, item) {
if (config.pid == item.product_id) {
html +=
'
';
}
});
$('.auth-group').append(html);
$('.auth-group').removeClass('hide');
$('#use-auth').removeClass('disabled').text('Authorization');
});
},
});
});
// if (!bt.get_cookie('bt_user_info')) {
// bt.pub.bind_btname(function () {
// window.location.reload();
// });
// return false;
// }
},
product_cache: {}, //产品周期缓存
order_cache: {},
// 获取产品周期 ,并进行对象缓存
get_product_discount_cache: function (config, callback) {
var that = this;
if (typeof this.product_cache[config.pid] != 'undefined') {
if (callback) callback(this.product_cache[config.pid]);
} else {
bt.soft.pro.get_product_discount_by(config.pid, function (rdata) {
//rdata = {"36": {"discount": 1, "did": 0, "price": 3564, "name": "正常", "sprice": 3564}, "24": {"discount": 1, "did": 0, "price": 2376, "name": "正常", "sprice": 2376}, "12": {"discount": 1, "did": 0, "price": 1188, "name": "正常", "sprice": 1188}, "6": {"discount": 1, "did": 0, "price": 594, "name": "正常", "sprice": 594}, "3": {"discount": 1, "did": 0, "price": 297, "name": "正常", "sprice": 297}, "1": {"discount": 1, "did": 0, "price": 99, "name": "正常", "sprice": 99}, "pid": "100000045"};
if (typeof rdata.status === 'boolean') {
if (!rdata.status) {
bt.msg(rdata);
return false;
}
}
that.product_cache[config.pid] = rdata;
setTimeout(function () {
delete that.product_cache[config.pid];
}, 60000);
if (callback) callback(rdata);
});
}
},
// 产品页面刷新
product_pay_page_refresh: function (config) {
var that = this;
var condition = config.condition;
switch (condition) {
case 1:
var loadT = bt.load();
bt.send('get_product_auth', 'auth/get_product_auth', { page: 1, pageSize: 15, pid: config.pid }, function (res) {
bt.soft.pro.get_voucher(config.pid, function (rdata) {
loadT.close();
var _arry = [
{ title: '微信支付', condition: 2 },
{ title: 'Stripe', condition: 3 },
{ title: 'voucher', condition: 4 },
{ title: 'Authorization', condition: 7, _pid: config.pid },
];
// if (config.renew) {
// _arry.splice(_arry.length - 1, 1);
// _arry[rdata.length > 0 ? '2' : '1'].active = true;
// config.condition = rdata.length > 0 ? 4 : 2;
// } else {
_arry[res.length > 0 ? '3' : rdata.length > 0 ? '2' : '1'].active = true;
config.condition = res.length > 0 ? 7 : rdata.length > 0 ? 4 : 3;
// }
if (res == null) res = [];
if (rdata == null) rdata = [];
$('#libPay-mode .li-con')
.empty()
.append(
that.product_pay_swicth('payment', {
name: config.name,
pid: config.pid,
data: _arry,
voucher_data: rdata,
})
);
if (config.renew) {
if (rdata.length > 0) config.voucher_data = rdata;
} else {
if (rdata.length > 0) config.voucher_data = rdata;
if (res.length > 0) config.voucher_data = res;
}
that.product_pay_page_refresh(config);
});
});
break;
case 2:
case 3:
$('#libPay-content .li-tit').text('Choose your plan');
config.pay = condition;
if (config.pid == '100000030') {
$('#libPay-tips').show();
} else {
$('#libPay-tips').hide();
}
var loadT = bt.load();
bt.soft.get_product_discount_cache(config, function (rdata) {
loadT.close();
var _arry = [];
var index = 0;
try {
delete rdata.pid;
} catch (error) {
console.log(rdata.pid);
}
that.each(rdata, function (key, item) {
_arry.push($.extend({ cycle: parseInt(key) }, item));
});
_arry[index].active = true;
$('#libPay-content .li-con')
.empty()
.append(
that.product_pay_swicth('time', {
name: config.name,
pid: config.pid,
data: _arry,
})
);
config.condition = 5;
config = $.extend(config, _arry[index]);
that.product_pay_page_refresh(config);
});
break;
case 4:
var loadP = bt.load('Getting deduction volume information!');
clearInterval(bt.soft.pub.wxpayTimeId);
$('#libPay-content').empty().append('
');
$('#libPay-pay').empty();
$('#libPay-content .li-tit').text('Vouchers');
$('#libPay-pay').removeAttr('data-qecode');
$('#libPay-tips').hide();
function callback(rdata) {
loadP.close();
if (rdata == null && !Array.isArray(rdata)) rdata = [];
if (rdata.length == 0) {
$('#libPay-content .li-con').empty();
that.product_pay_page_refresh({ condition: 6, pid: '', code: false });
return false;
}
rdata[0].active = true;
$('#libPay-content .li-con').append(
that.product_pay_swicth('voucher', {
name: config.name,
pid: config.pid,
data: rdata,
})
);
config.condition = 6;
that.product_pay_page_refresh($.extend(config, rdata[0]));
}
if (config.voucher_data) {
callback(config.voucher_data);
} else {
bt.soft.pro.get_voucher(config.pid, function (rdata) {
callback(rdata);
});
}
break;
case 5:
$('#libPay-content .li-con').css('height', 'auto');
$('.libPay-mask').show();
if ($('#libPay-pay').attr('data-qecode')) {
var qcode = $('#libPay-content li').eq(config.dom_index).data('qrcode-url');
$('#libPay-pay').find('.sale-price').html(config.price.toFixed(2));
$('#libPay-pay')
.find('.cost-price')
.css('display', config.sprice > config.price ? 'inline-block' : 'none')
.html('$ ' + config.sprice.toFixed(2));
$('#libPay-pay').find('#PayQcode').html('
');
if (qcode) {
$('#libPay-pay').find('#PayQcode').empty().qrcode(qcode);
that.product_pay_monitor({ pid: config.pid, name: config.name });
$('.libPay-mask').hide();
return false;
}
} else {
$('#libPay-pay').html('
');
}
var paream = { pid: config.pid, cycle: config.cycle };
paream.source = parseInt(bt.get_cookie('pay_source') || 0);
console.log(paream.source);
if (paream.source === 0) {
if ($('.btpro-gray').length == 1) {
// 是否免费版
paream.source = 27;
} else {
paream.source = 28;
}
}
if (!paream.pid) delete paream.pid;
if (bt.get_cookie('serial_no') != null) paream.serial_no = config.serial_no || bt.get_cookie('serial_no');
that.pro.create_order(paream, function (rdata) {
if (rdata.status === false) {
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
layer.msg(rdata.msg, { icon: 2 });
return;
}
config.pay = parseInt($('#libPay-mode .pay-cycle-btn.active').data('condition'));
// 二维码显示界面
$('#libPay-pay')
.empty()
.append(that.product_pay_swicth(config.pay == 2 ? 'wechat' : 'alipay', $.extend({ order_no: rdata.order_no, stripe_publishable_key: rdata.stripe_publishable_key }, config)));
});
$('#libPay-pay').on('click', '#checkout-button', function () {
var loadT = bt.load('Getting the session ID,Please waiting!');
var stripe = Stripe($(this).data('keys'));
that.pro.get_check_out_info($(this).data('code'), function (res) {
loadT.close();
if (res.id) {
stripe.redirectToCheckout({ sessionId: res.id });
} else {
layer.msg('Payment order failed, please contact administrator!', { icon: 2 });
}
});
});
break;
case 6:
var _html = $('
'
);
_button.click(function (ev) {
if (!config.serial_no) {
layer.msg('No vouchers');
return false;
}
bt.soft.pro.create_order_voucher(config.pid, config.code, config.id, config.cycle, config.cycle_unit, config.charge_type, function (rdata) {
layer.closeAll();
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
bt.msg(rdata.res);
});
});
$('#libPay-pay').empty().append(_html.append(_button));
break;
case 7:
if (config.renew) return false;
var loadA = bt.load('Obtaining authorization information!');
$('#libPay-content').empty().append('
');
$('#libPay-pay').empty();
var _pid = config.pid;
$('#libPay-content .li-tit').text('Authorization information');
bt.send('get_product_auth', 'auth/get_product_auth', { page: 1, pageSize: 15, pid: config.pid }, function (res) {
loadA.close();
if (res.status == false) {
layer.msg(res.msg, { icon: res.status ? 1 : 2 });
return false;
}
_html = $('
'));
}
var authorization_flag = false;
$.each(res, function (index, item) {
if (_pid == item.product_id) {
_html.append(
$('
')
);
authorization_flag = true;
}
if (authorization_flag == false && index == res.length - 1) {
_html.append($('
'));
}
});
$('#libPay-content .li-con').empty().append(_html);
$('#libPay-content ul li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
});
$('#libPay-pay')
.empty()
.append($('
'));
//授权
$('#authorization').unbind();
var html = $('#libPay-content .li-con ul li span').html() || '';
if (html.indexOf('No authorization') > 0) {
$('#authorization').attr('disabled', 'disabled');
} else {
$('#authorization').removeAttr('disabled');
$('#authorization').on('click', function (e) {
var _serial_no = $('#libPay-content .active').attr('data-id');
if (typeof _serial_no == 'undefined') return false;
var loadU = bt.load('Under licensing!');
bt.send('auth_activate', 'auth/auth_activate', { serial_no: _serial_no }, function (res) {
loadU.close();
if (res) {
layer.msg(res.msg, { icon: res.status ? 1 : 2 });
if (res.status) {
window.location.reload();
}
}
});
});
}
});
break;
}
},
// 产品购买,渲染方法
product_pay_swicth: function (type, config) {
var _html = '',
that = this;
switch (type) {
case 'type': // 产品类型(配置参数)
_html = $('
');
this.each(config, function (index, item) {
_html.append(
$(
'
'
)
.data(item)
.click(function (ev) {
var data = $(this).data();
if (!$(this).hasClass('active')) that.product_pay_page_refresh($.extend({ condition: 1 }, data));
$(this).addClass('active').siblings().removeClass('active');
})
);
});
break;
case 'payment': // 产品付款方式
_html = $('
');
this.each(config.data, function (index, item) {
if (item.title != '微信支付') {
_html.append(
$('
')
.data($.extend({ pid: config.pid, name: config.name }, item))
.click(function (ev) {
var data = $(this).data();
if (!$(this).hasClass('active')) that.product_pay_page_refresh($.extend({ condition: $(this).attr('data-condition') }, data));
$(this).addClass('active').siblings().removeClass('active');
})
);
}
});
break;
case 'time': // 产品开通时长(配置参数)
_html = $('
');
this.each(config.data, function (index, item) {
_html.append(
$(
'
'
)
.data(
$.extend(
{
pid: config.pid,
dom_index: index,
},
item
)
)
.click(function (ev) {
var data = $(this).data();
if (!$(this).hasClass('active')) that.product_pay_page_refresh($.extend({ condition: 5 }, data));
$(this).addClass('active').siblings().removeClass('active');
})
);
});
break;
case 'voucher': // 产品抵扣卷(配置参数)
_html = $('
');
this.each(config.data, function (index, item) {
_html.append(
$(
'
'
)
.data($.extend({ pid: config.pid }, item))
.click(function (ev) {
var data = $(this).data();
$(this).addClass('active').siblings().removeClass('active');
that.product_pay_page_refresh($.extend({ condition: 6 }, data));
})
);
});
break;
case 'wechat':
case 'alipay':
_html = $(
'
' +
'
'
);
// $(_html).find('#PayQcode').qrcode(config.data);
$('.libPay-mask').hide();
// that.product_pay_monitor({ pid: config.pid, name: config.name });
break;
}
return _html;
},
// 支付状态监听
product_pay_monitor: function (config) {
var that = this;
function callback(rdata) {
if (rdata.status) {
clearInterval(bt.soft.pub.wxpayTimeId);
layer.closeAll();
var title = '';
if (config.pid == 100000032 || config.pid === '') {
title = config.pid === '' ? '专业版支付成功!' : '企业版支付成功!';
setTimeout(function () {
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
location.reload(true);
}, 2000); // 需要重服务端重新获取软件列表,并刷新软件管理浏览器页面
} else {
title = config.name + '插件支付成功!';
setTimeout(function () {
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
location.reload(true);
}, 2000); // 需要重服务端重新获取软件列表,
}
bt.msg({ msg: title, icon: 1, shade: [0.3, '#000'] });
}
}
clearInterval(bt.soft.pub.wxpayTimeId);
function intervalFun() {
if (config.pid) {
that.pro.get_plugin_coupon(config.pid, callback);
} else {
that.pro.get_re_order_status(callback);
}
}
intervalFun();
bt.soft.pub.wxpayTimeId = setInterval(function () {
intervalFun();
}, 2500);
},
updata_ltd: function (is_alone) {
var param = { name: '宝塔面板企业版', pid: 100000032, limit: 'ltd' };
if (is_alone || false) $.extend(param, { source: 5, is_alone: true });
bt.soft.product_pay_view(param);
},
//遍历数组和对象
each: function (obj, fn) {
var key,
that = this;
if (typeof fn !== 'function') return that;
obj = obj || [];
if (obj.constructor === Object) {
for (key in obj) {
if (fn.call(obj[key], key, obj[key])) break;
}
} else {
for (key = 0; key < obj.length; key++) {
if (fn.call(obj[key], key, obj[key])) break;
}
}
return that;
},
/**
* @description 升级专业版
*/
updata_pro: function (num) {
var param = {
name: 'Pro',
pid: 100000058,
limit: 'pro',
};
if (num) param['totalNum'] = num;
bt.set_cookie('pay_source', num);
bt.soft.product_pay_view(param);
},
/**
* @description 续费专业版
*/
renew_pro: function () {
var config = { name: 'Pro', pid: '100000058', limit: 'pro', renew: true };
if (!bt.get_cookie('serial_no')) delete config.renew;
bt.soft.product_pay_view(config);
},
// updata_pro: function() {
// bt.pub.get_user_info(function(rdata) {
// if (!rdata.status) {
// bt.pub.bind_btname(0, function(rdata) {
// if (rdata.status) bt.soft.updata_pro();
// })
// return;
// }
// var payhtml = '
';
// bt.open({
// type: 1,
// title: lan.public_backup.up_pro_use_allplug_free,
// area: ['616px', '540px'],
// closeBtn: 2,
// shadeClose: false,
// content: payhtml
// });
// setTimeout(function() {
// bt.soft.get_product_discount('', 0);
// $(".pay-btn-group > li").click(function() {
// $(this).addClass("active").siblings().removeClass("active");
// });
// }, 100)
// })
// },
re_plugin_pay: function (pluginName, pid, type) {
bt.pub.get_user_info(function (rdata) {
if (!rdata.status) {
bt.pub.bind_btname(0, function (rdata) {
if (rdata.status) bt.soft.re_plugin_pay(pluginName, pid, type);
});
return;
}
var txt = lan.public_backup.buy;
if (type) txt = lan.public_backup.renew;
var payhtml =
'
\
\
' +
lan.public_backup.type +
'
\
\
\
- ' +
pluginName +
'' +
lan.public_backup.apiece_of_plug +
'
\
- ' +
lan.public_backup.up_pro +
'' +
lan.public_backup.use_allplug_free +
'
\
\
\
\
\
\
';
layer.open({
type: 1,
title: txt + pluginName,
area: ['616px', '680px'],
closeBtn: 2,
shadeClose: false,
content: payhtml,
});
setTimeout(function () {
bt.soft.get_product_discount(pluginName, pid);
$('.li-c-item li').click(function () {
var i = $(this).index();
$(this).addClass('active').siblings().removeClass('active');
if (i == 0) {
bt.soft.get_product_discount(pluginName, pid);
$('.pro-info').hide();
} else {
bt.soft.get_product_discount('', 0);
$('.pro-info').show();
}
});
$('.pay-btn-group > li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
});
}, 100);
});
},
re_plugin_pay_other: function (pluginName, pid, type, price) {
bt.pub.get_user_info(function (rdata) {
if (!rdata.status) {
bt.pub.bind_btname(0, function (rdata) {});
return;
}
var txt = lan.public_backup.buy;
if (type) txt = lan.public_backup.renew;
var payhtml =
'
\
\
\
\
\
' +
txt +
lan.public_backup.duration +
'
\
\
- ' +
lan.public_backup.month1 +
'
\
- ' +
lan.public_backup.month3 +
'
\
- ' +
lan.public_backup.month6 +
'
\
- ' +
lan.public_backup.year +
'
\
\
\
' +
lan.public_backup.total +
'' +
lan.public_backup.rmb +
'
\
\
\
' +
lan.public_backup.pay_by_wechatqrcore +
'
\
\
\
\
\
';
layer.open({
type: 1,
title: txt + pluginName,
area: ['616px', '450px'],
closeBtn: 2,
shadeClose: false,
content: payhtml,
});
bt.soft.get_rscode_other(pid, price, 1, type);
setTimeout(function () {
$('.pay-btn-group > li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
});
}, 100);
});
},
get_rscode_other: function (pid, price, cycle, type) {
var loadT = layer.msg(lan.public_backup.get_payment_info, { icon: 16, time: 0, shade: 0.3 });
$.post('/auth?action=create_plugin_other_order', { pid: pid, cycle: cycle, type: type }, function (rdata) {
layer.close(loadT);
if (!rdata.status) {
layer.closeAll();
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
return;
}
if (!rdata.msg.code) {
layer.closeAll();
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
soft.flush_cache();
return;
}
$('.sale-price').text((price * cycle).toFixed(2));
$('.pay-wx').html('');
$('.pay-wx').qrcode(rdata.msg.code);
bt.set_cookie('other_oid', rdata.msg.oid);
bt.soft.get_order_stat(rdata.msg.oid, type);
});
},
get_order_stat: function (order_id, type) {
if (bt.get_cookie('other_oid') != order_id) return;
setTimeout(function () {
$.post('/auth?action=get_order_stat', { oid: order_id, type: type }, function (stat) {
if (stat == 1) {
layer.closeAll();
soft.flush_cache();
return;
}
if ($('.pay-btn-group').length > 0) {
bt.soft.get_order_stat(order_id, type);
}
});
}, 1000);
},
get_voucher_list: function (pid) {
$('#couponlist').html("
" + lan.public_backup.loading + '
');
bt.soft.pro.get_voucher(pid, function (rdata) {
if (rdata != null && rdata.length > 0) {
var con = '';
var len = rdata.length;
for (var i = 0; i < len; i++) {
if (rdata[i].status != 1) {
var cyc = rdata[i].cycle + bt.soft.pro.conver_unit(rdata[i].unit);
if (rdata[i].cycle == 999) {
cyc = lan.public_backup.permanent;
}
con += '
' + cyc + '';
}
}
$('#couponlist').html('
');
$('.pay-btn-group > li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
$('.paymethod-submit button').css({ 'background-color': '#20a53a', 'border-color': '#20a53a' });
});
$('.paymethod-submit button').click(function () {
var _active = $('#couponlist .pay-btn-group .active'),
code = _active.attr('data-code'),
coupon_id = _active.attr('data-coupon-id'),
charge_type = _active.attr('data-charge-type');
var _span = $('#couponlist .pay-btn-group .active span'),
cycle = parseInt(_span.html()),
cycle_unit = _span.html.indexOf('Month') ? 'month' : 'year';
if (code == undefined) {
layer.msg(lan.public_backup.choose_cash_coupon);
} else {
bt.soft.pro.create_order_voucher(pid, code, coupon_id, cycle, cycle_unit, charge_type, function (rdata) {
layer.closeAll();
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
bt.msg(rdata.res);
});
}
});
} else {
$('#couponlist').html("
" + lan.public_backup.no_cash_coupon + '
');
}
});
},
get_rscode: function (pid, price, sprice, cycle) {
$('.sale-price').text(price);
if (price == sprice) {
$('.cost-price')
.text(sprice + lan.public_backup.rmb)
.hide();
} else {
$('.cost-price')
.text(sprice + lan.public_backup.rmb)
.show();
}
$('.pay-wx').html('
' + lan.public_backup.loading + '');
$('.libPay').append('
');
bt.soft.pro.create_order(pid, cycle, function (rdata) {
$('.payloadingmask').remove();
if (rdata.status === false) {
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
layer.msg(rdata.msg, { icon: 2 });
return;
}
$('.pay-wx').html('');
$('.pay-wx').qrcode(rdata.msg);
clearInterval(bt.soft.pub.wxpayTimeId);
if (pid) {
bt.soft.pub.wxpayTimeId = setInterval(function () {
bt.soft.pro.get_plugin_coupon(pid, function (rdata) {
if (rdata.status) {
layer.closeAll();
clearInterval(bt.soft.pub.wxpayTimeId);
bt.msg({ msg: lan.public_backup.pay_plug_success, icon: 16, time: 0, shade: [0.3, '#000'] });
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
return;
}
});
}, 3000);
} else {
bt.soft.pub.wxpayTimeId = setInterval(function () {
bt.soft.pro.get_re_order_status(function (rdata) {
if (rdata.status) {
layer.closeAll();
clearInterval(bt.soft.pub.wxpayTimeId);
bt.msg({ msg: lan.public_backup.pay_pro_success, icon: 16, time: 0, shade: [0.3, '#000'] });
bt.set_cookie('force', 1);
if (soft) soft.flush_cache();
return;
}
});
}, 3000);
}
});
},
get_product_discount: function (pluginName, pid) {
if (pluginName == undefined) pluginName = '';
if (pid == undefined) pid = 0;
var con =
'
\
' +
lan.public_backup.pay_method +
'
\
- ' +
lan.public_backup.pay_by_wechat +
'
- ' +
lan.public_backup.cash_coupon +
'
\
\
\
\
\
' +
lan.public_backup.opening_time +
'
\
\
\
' +
lan.public_backup.total +
'' +
lan.public_backup.rmb +
'
\
\
\
' +
lan.public_backup.pay_by_wechatqrcore +
'
\
\
\
\
\
' +
lan.public_backup.cash_coupon_list +
'
\
\
\
\
\
\
\
';
$('.libpay-con').html("
" + lan.public_backup.loading + '
');
bt.soft.pro.get_product_discount_by(pluginName, function (rdata) {
if (rdata != null) {
var coucon = '';
var qarr = Object.keys(rdata);
var qlen = qarr.length;
if (pluginName) qlen = qlen - 1;
//折扣列表
for (var i = 0; i < qlen; i++) {
var j = qarr[i];
var a = rdata[j].price.toFixed(2);
var b = rdata[j].sprice.toFixed(2);
var c = rdata[j].discount;
coucon +=
'
' +
bt.soft.pro.conver_unit(j) +
'' +
(c == 1 ? '' : '' + c * 10 + lan.public_backup.discount + '') +
'';
}
$('.libpay-con').html(con);
$('#PayCycle').html('
');
$('.pay-btn-group li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
});
$('.pay-cycle li').click(function () {
var i = $(this).index();
$(this).addClass('active').siblings().removeClass('active');
$('.payment-con > div').eq(i).show().siblings().hide();
});
$('#PayCycle .pay-btn-group li').eq(0).click();
}
});
},
get_index_list: function (callback) {
bt.send('get_index_list', 'plugin/get_index_list', {}, function (rdata) {
if (callback) callback(rdata);
});
},
set_sort_index: function (data, callback) {
var loading = bt.load();
bt.send('sort_index', 'plugin/sort_index', { ssort: data }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_soft_list: function (p, type, search, callback) {
if (p == undefined) p = 1;
if (type == undefined) type = 0;
if (search == undefined) search = '';
var force = bt.get_cookie('force');
if (force == undefined) force = 0;
p = p + '';
if (p.indexOf('not_load') == -1) {
var loading = bt.load(lan.public.the, 1);
} else {
var loading = null;
p = p.split('not_load')[0];
}
bt.send('get_soft_list', 'plugin/get_soft_list', { p: p, type: type, tojs: 'soft.get_list', force: force, query: search }, function (rdata) {
if (loading) loading.close();
bt.set_cookie('force', 0);
if (rdata.pro_authorization_sn != null) {
bt.set_cookie('serial_no', rdata.pro_authorization_sn);
} else {
bt.clear_cookie('serial_no');
}
bt.set_cookie('pro_end', rdata.pro);
if (callback) callback(rdata);
});
},
to_index: function (name, callback) {
var status = $('#index_' + name).prop('checked') ? '0' : '1';
if (name.indexOf('php-') >= 0) {
var verinfo = name.replace(/\./, '');
status = $('#index_' + verinfo).prop('checked') ? '0' : '1';
}
if (status == 1) {
bt.send('add_index', 'plugin/add_index', { sName: name }, function (rdata) {
rdata.time = 1000;
if (!rdata.status) bt.msg(rdata);
if (callback) callback(rdata);
});
} else {
bt.send('remove_index', 'plugin/remove_index', { sName: name }, function (rdata) {
rdata.time = 1000;
if (!rdata.status) bt.msg(rdata);
if (callback) callback(rdata);
});
}
},
add_make_args: function (name, init) {
name = bt.soft.get_name(name);
pdata = {
name: name,
args_name: $("input[name='make_name']").val(),
init: init,
ps: $("input[name='make_ps']").val(),
args: $("input[name='make_args']").val(),
};
if (pdata.args_name.length < 1 || pdata.args.length < 1) {
layer.msg('Custom module name and parameter cannot be empty!');
return;
}
loadT = bt.load('Adding custom module...');
bt.send('add_make_args', 'plugin/add_make_args', pdata, function (rdata) {
loadT.close();
bt.soft.get_make_args(name);
bt.msg(rdata);
if (rdata.status === true) bt.soft.loadOpen.close();
});
},
show_make_args: function (name) {
name = bt.soft.get_name(name);
var _aceEditor = '';
bt.soft.loadOpen = bt.open({
type: 1,
title: 'Add custom module',
area: '500px',
btn: [lan.public.submit, lan.public.close],
content:
'
',
success: function (layer, index) {
_aceEditor = ace.edit('preposition_shell', {
theme: 'ace/theme/chrome', //主题
mode: 'ace/mode/sh', // 语言类型
wrap: true,
showInvisibles: false,
showPrintMargin: false,
showFoldWidgets: false,
useSoftTabs: true,
tabSize: 2,
showPrintMargin: false,
readOnly: false,
});
_aceEditor.setValue('# The shell script content executed before compilation is usually prepared for the dependent installation and source download of the third-party module');
},
yes: function () {
bt.soft.add_make_args(name, _aceEditor.getValue());
},
});
},
modify_make_args: function (name, args_name) {
name = bt.soft.get_name(name);
var _aceEditor = '';
bt.soft.loadOpen = bt.open({
type: 1,
title: 'Edit custom option module[' + name + ':' + args_name + ']',
area: '500px',
btn: [lan.public.submit, lan.public.close],
content:
'
',
success: function (layer, index) {
_aceEditor = ace.edit('preposition_shell', {
theme: 'ace/theme/chrome', //主题
mode: 'ace/mode/sh', // 语言类型
wrap: true,
showInvisibles: false,
showPrintMargin: false,
showFoldWidgets: false,
useSoftTabs: true,
tabSize: 2,
showPrintMargin: false,
readOnly: false,
});
_aceEditor.setValue(bt.soft.make_data[args_name].init);
},
yes: function () {
bt.soft.add_make_args(name, _aceEditor.getValue());
},
});
},
set_make_args: function (_this, name, args_name) {
name = bt.soft.get_name(name);
if ($('.args_' + args_name)[0].checked) {
bt.soft.make_config.push(args_name);
} else {
index = bt.soft.make_config.indexOf(args_name);
if (index === -1) return;
bt.soft.make_config.splice(index, 1);
}
index = bt.soft.make_config.indexOf('');
if (index !== -1) bt.soft.make_config.splice(index, 1);
bt.send('set_make_args', 'plugin/set_make_args', { name: name, args_names: bt.soft.make_config.join('\n') }, function (rdata) {
if (!rdata.status) {
bt.msg(rdata);
}
});
},
//遍历数组和对象
each: function (obj, fn) {
var key,
that = this;
if (typeof fn !== 'function') return that;
obj = obj || [];
if (obj.constructor === Object) {
for (key in obj) {
if (fn.call(obj[key], key, obj[key])) break;
}
} else {
for (key = 0; key < obj.length; key++) {
if (fn.call(obj[key], key, obj[key])) break;
}
}
return that;
},
del_make_args: function (name, args_name) {
name = bt.soft.get_name(name);
bt.confirm({ msg: 'Confirm delete[' + name + ':' + args_name + ']module?', title: 'Delete[' + name + ':' + args_name + ']module!' }, function () {
loadT = bt.load('Removing module[' + args_name + ']...');
bt.send('del_make_args', 'plugin/del_make_args', { name: name, args_name: args_name }, function (rdata) {
bt.soft.get_make_args(name);
bt.msg(rdata);
});
});
},
get_make_args: function (name) {
name = bt.soft.get_name(name);
loadT = bt.load('Getting optional modules...');
bt.send('get_make_args', 'plugin/get_make_args', { name: name }, function (rdata) {
loadT.close();
var module_html = '';
bt.soft.make_config = rdata.config.split('\n');
bt.soft.make_data = {};
for (var i = 0; i < rdata.args.length; i++) {
bt.soft.make_data[rdata.args[i].name] = rdata.args[i];
var checked_str = bt.soft.make_config.indexOf(rdata.args[i].name) == -1 ? '' : 'checked="checked"';
module_html +=
'
\
| \
\
| \
' +
rdata.args[i].name +
' | ' +
rdata.args[i].ps +
' | \
\
Edit\
| Del\
| \
';
}
$('.modules_list').html(module_html);
});
},
check_make_is: function (name) {
name = bt.soft.get_name(name);
var shows = ['nginx', 'apache', 'mysql', 'php'];
for (var i = 0; i < shows.length; i++) {
if (name.indexOf(shows[i]) === 0) {
return true;
}
}
return false;
},
get_name: function (name) {
if (name.indexOf('php-') === 0) {
return 'php';
}
return name;
},
install: function (name, that) {
var _this = this;
if (bt.soft.is_install) {
layer.msg('Installing other software, please operate later!', { icon: 0 });
return false;
}
_this.get_soft_find(name, function (rdata) {
var arrs = ['apache', 'nginx', 'mysql'];
if ($.inArray(name, arrs) >= 0 || name.indexOf('php-') >= 0) {
var SelectVersion = '',
shtml = name;
if (rdata.versions.length > 1) {
for (var i = 0; i < rdata.versions.length; i++) {
var item = rdata.versions[i];
SelectVersion += '
';
}
shtml = "
';
} else {
shtml = "
" + name + '';
}
var loadOpen = bt.open({
type: 1,
title: name + lan.soft.install_title,
area: '400px',
content:
"
',
success: function ($layer, index) {
$layer.find('.btn-close').click(function () {
layer.close(index);
});
},
});
$('.fangshi input').click(function () {
$(this).attr('checked', 'checked').parent().siblings().find('input').removeAttr('checked');
var type = $('.fangshi input:eq(0)').prop('checked') ? '0' : '1';
if (type === '1') {
$('.install_modules').hide();
return;
}
if (bt.soft.check_make_is(name)) {
$('.install_modules').show();
bt.soft.get_make_args(name);
}
});
$('#bi-btn').click(function () {
loadOpen.close();
var info = $('#SelectVersion').val().toLowerCase();
name = info.split(' ')[0];
version = info.split(' ')[1];
var type = $('.fangshi input:eq(0)').prop('checked') ? '0' : '1';
if (rdata.versions.length > 1) {
_this.install_soft(rdata, version, type);
} else {
_this.install_soft(rdata, rdata.versions[0].m_version, type, that);
}
});
} else if (rdata.versions.length > 1) {
var SelectVersion = '';
for (var i = 0; i < rdata.versions.length; i++) {
var item = rdata.versions[i];
var v_type = parseInt(item.beta) === 1 ? ' Beta' : ' Stable';
// SelectVersion += '
';
var version = parseInt(rdata.type) === 5 ? item.m_version : item.full_version;
SelectVersion += '
';
}
var loadOpen = bt.open({
type: 1,
title: name + lan.soft.install_title,
area: '350px',
content:
"
',
});
$('#bi-btn').click(function () {
loadOpen.close();
var info = $('#SelectVersion').val().toLowerCase();
name = info.split(' ')[0];
version = info.split(' ')[1];
_this.install_soft(rdata, version, 0, that);
});
} else {
// _this.install_soft(rdata, rdata.versions[0].full_version, 0, that);
_this.install_soft(rdata, parseInt(rdata.type) == 5 ? rdata.versions[0].m_version : rdata.versions[0].full_version, 0, that);
}
});
},
is_loop_speed: true,
is_install: false,
//显示进度
show_speed: function () {
bt.send(
'get_lines',
'ajax/get_lines',
{
num: 10,
filename: '/tmp/panelShell.pl',
},
function (rdata) {
if ($('#install_show').length < 1) return;
if (rdata.status === true) {
$('#install_show').text(rdata.msg);
$('#install_show').scrollTop(1000000000);
}
setTimeout(function () {
bt.soft.show_speed();
}, 1000);
}
);
},
loadT: null,
speed_msg: "
[MSG]
",
//显示进度窗口
// show_speed_window: function(msg, callback) {
// bt.soft.loadT = layer.open({
// title: false,
// type: 1,
// closeBtn: 0,
// shade: 0.3,
// area: "500px",
// offset: "30%",
// content: bt.soft.speed_msg.replace('[MSG]', msg),
// success: function(layers, index) {
// setTimeout(function() {
// bt.soft.show_speed();
// }, 1000);
// if (callback) callback();
// }
// });
// },
show_speed_window: function (config, callback) {
if (!config.soft) config['soft'] = { type: 10 };
if (config.soft.type == 5) {
//使用消息盒子安装
if (callback) callback();
return false;
} else if (config.soft.type == 10 && !config.status) {
//第三方安装, 非安装,仅下载安装脚本
if (callback) callback();
return false;
}
layer.closeAll();
bt.soft.loadT = layer.open({
title: config.title || 'Executing setup script, please wait...',
type: 1,
closeBtn: false,
maxmin: true,
shade: false,
skin: 'install_soft',
area: ['500px', '300px'],
content:
"
" +
config.msg +
'
',
success: function (layers, index) {
if (typeof config.event === 'string') {
$(config.event).removeAttr('onclick').html('Installing');
}
$('.layui-layer-max').hide();
bt.soft.is_loop_speed = true;
bt.soft.is_install = true;
bt.soft.show_speed();
if (callback) callback();
},
end: function () {
bt.soft.is_install = false;
bt.soft.is_loop_speed = false;
},
min: function () {
$('.layui-layer-max').show();
},
restore: function () {
$('.layui-layer-max').hide();
},
});
},
// install_soft: function(item, version, type,that) { //安装单版本
// if (type == undefined) type = 0;
// item.title = bt.replace_all(item.title, '-' + version, '');
// var msg = item.type != 5 ? lan.soft.lib_insatll_confirm.replace('{1}', item.title) : lan.get('install_confirm', [item.title, version]);
// bt.confirm({ msg: '
'+msg+'
', title: item.type != 5 ? lan.soft.lib_install : lan.soft.install_title }, function() {
// bt.soft.show_speed_window(lan.soft.lib_install_the, function() {
// bt.send('install_plugin', 'plugin/install_plugin', { sName: item.name, version: version, type: type }, function(rdata) {
// if (rdata.size) {
// layer.close(bt.soft.loadT);
// _this.install_other(rdata)
// return;
// }
// layer.close(bt.soft.loadT);
// bt.pub.get_task_count();
// if (soft) soft.get_list();
// bt.msg(rdata);
// })
// })
// })
// },
install_soft: function (item, version, type, that) {
//安装单版本
if (type == undefined) type = 0;
var loadT = '';
item.title = bt.replace_all(item.title, '-' + version, '');
layer.confirm(
item.type != 5 ? lan.soft.lib_insatll_confirm.replace('{1}', item.title) : lan.get('install_confirm', [item.title, version]),
{
btn: [lan.public.confirm, lan.public.close],
title: item.type != 5 ? lan.soft.lib_install : lan.soft.install_title,
icon: 0,
closeBtn: 2,
},
function () {
layer.closeAll();
bt.soft.show_speed_window(
{
title: 'Installing ' + item.title + ', please wait...',
msg: lan.soft.lib_install_the,
soft: item,
event: that,
},
function () {
if (item.type == 10)
loadT = layer.msg('Getting third party installation information, please wait

', {
icon: 16,
time: 0,
shade: [0.3, '#000'],
});
bt.send(
'install_plugin',
'plugin/install_plugin',
{
sName: item.name,
version: version,
type: type,
},
function (rdata) {
if (rdata.size) {
layer.close(loadT);
bt.soft.install_other(rdata, status, that);
return;
}
layer.close(bt.soft.loadT);
bt.pub.get_task_count(function (rdata) {
if (rdata > 0 && item.type === 5) messagebox();
});
if (!rdata.status) {
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
} else {
if (window.location.pathname != '/soft') {
window.location.reload();
}
}
setTimeout(function () {
if (typeof soft != 'undefined') soft.get_list();
}, 2000);
}
);
}
);
}
);
},
install_other: function (data, status, callback) {
layer.closeAll();
var loadT = layer.open({
type: 1,
area: '500px',
title: (data.update ? lan.public_backup.update : lan.public_backup.install) + lan.public_backup.third_party_plug,
closeBtn: 2,
shift: 5,
shadeClose: false,
btn: [data.update ? lan.public_backup.update : lan.public_backup.install, lan.public_backup.cancel],
content:
'\
',
yes: function (index, event) {
soft.input_zip(data.name, data.tmp_path, data, callback);
},
});
},
update_soft: function (name, title, version, min_version, update_msg, type,callback) {
var _this = this;
var msg = '
' + lan.public_backup.update_tips + '';
if (name == 'mysql')
msg = "
- " + lan.public_backup.db_update_tips + '
- ' + lan.public_backup.update_tips1 + '
- ' + lan.public_backup.update_tips + '
';
if (update_msg)
msg +=
'
Update description:
' +
update_msg.replace(/(_bt_)/g, '\n') +
'
';
bt.show_confirm(
lan.public_backup.update + '[' + title + ']',
lan.public_backup.update_tips2.replace('{1}', title).replace('{2}', version).replace('{3}', min_version),
function () {
// bt.soft.show_speed_window('Updating to [' + title + '-' + version + '.' + min_version + '],Please wait...', function() {
// bt.send('install_plugin', 'plugin/install_plugin', { sName: name, version: version, upgrade: version }, function(rdata) {
// if (rdata.size) {
// _this.install_other(rdata)
// return;
// }
// layer.close(bt.soft.loadT);
// bt.pub.get_task_count(function(rdata){
// if(rdata > 0 && item.type === 5) messagebox();
// });
// if (soft) soft.get_list();
// if (rdata.status === true && rdata.msg.indexOf('queue') === -1) rdata.msg = 'Update completed!';
// bt.msg(rdata);
// })
// })
// bt.soft.show_speed_window({ title: 'Updating to [' + title + '-' + version + '.' + min_version + '],Please wait...', status: true, soft: { type: parseInt(type) } }, function () {
// bt.send('install_plugin', 'plugin/install_plugin', { sName: name, version: version + '.' + min_version, upgrade: version + '.' + min_version }, function (rdata) {
// console.log(rdata);
// if (rdata.size) {
// _this.install_other(rdata);
// return;
// }
// layer.close(bt.soft.loadT);
// bt.pub.get_task_count(function (rdata) {
// if (rdata > 0 && item.type === 5) messagebox();
// });
// if (typeof soft != 'undefined') soft.get_list();
// bt.msg(rdata);
// });
// });
_this.get_soft_find(name, function (item) {
var full_version = parseInt(item.type) === 5 ? version : version + '.' + min_version;
bt.soft.show_speed_window({ title: 'Updating to [' + title + '-' + version + '.' + min_version + '],Please wait...', status: true, soft: { type: parseInt(type) } }, function () {
bt.send('install_plugin', 'plugin/install_plugin', { sName: name, version: full_version, upgrade: full_version }, function (rdata) {
console.log(rdata);
if (rdata.size) {
_this.install_other(rdata);
return;
}
layer.close(bt.soft.loadT);
bt.pub.get_task_count(function (rdata) {
if (rdata > 0 && parseInt(item.type) === 5) messagebox();
});
if (typeof soft != 'undefined') {
callback && callback()
soft.get_list()
};
bt.msg(rdata);
});
});
});
},
msg
);
},
un_install: function (name) {
var _this = this;
_this.get_soft_find(name, function (item) {
var version = '';
for (var i = 0; i < item.versions.length; i++) {
if (item.versions[i].setup && bt.contains(item.version, item.versions[i].m_version)) {
version = item.versions[i].m_version;
if (version.indexOf('.') < 0) version += '.' + item.versions[i].version;
break;
}
}
var title = bt.replace_all(item.title, '-' + version, '');
bt.confirm({ msg: lan.soft.uninstall_confirm.replace('{1}', title).replace('{2}', version), title: lan.soft.uninstall, icon: 3, closeBtn: 2 }, function () {
var loadT = bt.load(lan.soft.lib_uninstall_the);
bt.send('uninstall_plugin', 'plugin/uninstall_plugin', { sName: name, version: version }, function (rdata) {
loadT.close();
bt.pub.get_task_count();
if (soft) soft.get_list();
bt.msg(rdata);
});
});
});
},
get_soft_find: function (name, callback) {
var loadT = bt.load();
bt.send('get_soft_find', 'plugin/get_soft_find', { sName: name }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_config_path: function (name) {
var fileName = '';
if (bt.os == 'Linux') {
switch (name) {
case 'mysql':
case 'mysqld':
fileName = '/etc/my.cnf';
break;
case 'nginx':
fileName = '/www/server/nginx/conf/nginx.conf';
break;
case 'pureftpd':
fileName = '/www/server/pure-ftpd/etc/pure-ftpd.conf';
break;
case 'apache':
fileName = '/www/server/apache/conf/httpd.conf';
break;
case 'tomcat':
fileName = '/www/server/tomcat/conf/server.xml';
break;
case 'memcached':
fileName = '/etc/init.d/memcached';
break;
case 'redis':
fileName = '/www/server/redis/redis.conf';
break;
case 'openlitespeed':
fileName = '/usr/local/lsws/conf/httpd_config.conf';
break;
default:
fileName = '/www/server/php/' + name + '/etc/php.ini';
break;
}
}
return fileName;
},
set_lib_config: function (name, title) {
var loadT = bt.load(lan.soft.menu_temp);
bt.send('getConfigHtml', 'plugin/getConfigHtml', { name: name }, function (rhtml) {
loadT.close();
if (rhtml.status === false) {
if (name == 'phpguard') {
layer.msg(lan.soft.menu_phpsafe, { icon: 1 });
} else {
layer.msg(rhtml.msg, { icon: 2 });
}
return;
}
bt.open({
type: 1,
shift: 5,
offset: '20%',
closeBtn: 2,
area: '700px',
title: '' + title,
content: rhtml.replace('"javascript/text"', '"text/javascript"'),
});
/*rtmp = rhtml.split('','');
setTimeout(function(){
if(!!(window.attachEvent && !window.opera)){
execScript(rcode);
}else{
window.eval(rcode);
}
},200)*/
});
},
save_config: function (fileName, data) {
var encoding = 'utf-8';
var loadT = bt.load(lan.soft.the_save);
bt.send('SaveFileBody', 'files/SaveFileBody', { data: data, path: fileName, encoding: encoding }, function (rdata) {
loadT.close();
bt.msg(rdata);
});
},
};
bt.database = {
get_list: function (page, search, callback) {
if (page == undefined) page = 1;
search = search == undefined ? '' : search;
var order = bt.get_cookie('order') ? '&order=' + bt.get_cookie('order') : '';
var data = 'tojs=database.get_list&table=databases&limit=15&p=' + page + '&search=' + search + order;
bt.pub.get_data(data, function (rdata) {
if (callback) callback(rdata);
});
},
get_root_pass: function (callback) {
bt.send('getKey', 'data/getKey', { table: 'config', key: 'mysql_root', id: 1 }, function (rdata) {
if (callback) callback(rdata);
});
},
set_root: function (type) {
if (type == 'mongo' || type == 'pgsql') {
var t = bt.data.database.getType();
bt_tools.send('database/' + t + '/get_root_pwd', function (rdata) {
if (type == 'pgsql') bt.data.database.mongo['list'][0]['title'] = lan.database.admin_password;
var bs = bt.render_form(bt.data.database.mongo);
$('.password' + bs).val(rdata.msg);
});
} else {
bt.database.get_root_pass(function (rdata) {
var bs = bt.render_form(bt.data.database.root);
$('.password' + bs).val(rdata);
});
}
},
set_data_pass: function (callback) {
var bs = bt.render_form(bt.data.database.data_pass, function (rdata) {
if (callback) callback(rdata);
});
return bs;
},
set_data_access: function (name) {
var loading = bt.load();
bt.send('GetDatabaseAccess', 'database/GetDatabaseAccess', { name: name }, function (rdata) {
loading.close();
var bs = bt.render_form(bt.data.database.data_access);
$('.name' + bs).val(name);
$('.bt-form .line .tname').css('width', '125px');
setTimeout(function () {
if (rdata.msg.permission == '127.0.0.1' || rdata.msg.permission == '%') {
$('.dataAccess' + bs).val(rdata.msg.permission);
} else {
$('.dataAccess' + bs)
.val('ip')
.trigger('change');
$('#dataAccess_subid').val(rdata.msg.permission);
}
$('#force_ssl').prop('checked', rdata.msg.ssl ? true : false);
$('#force_ssl').change(function () {
var open_type = $('#force_ssl').prop('checked');
if (open_type) {
var t =
'
\
Warning! This feature requires Advanced Knowledge!
\
\
- After enabling the forced SSL connection, it may affect your application connection and database performance.
\
\
';
var loadP = layer.confirm(
t,
{
btn: ['Confirm', 'Cancel'],
icon: 3,
area: '561px',
closeBtn: 2,
title: 'Confirm Open?',
},
function () {
$('#force_ssl').prop('checked', true);
layer.close(loadP);
},
function () {
$('#force_ssl').prop('checked', false);
layer.close(loadP);
}
);
}
});
}, 100);
});
},
add_database: function (cloudList, callback) {
var type = bt.data.database.getType();
if (type === 'mysql') {
bt.data.database.data_add.list[2].items[0].value = bt.get_random(16);
bt.data.database.data_add.list[4].items[0].items = cloudList;
bt.render_form(bt.data.database.data_add, function (rdata) {
if (callback) callback(rdata);
});
} else {
var copyDataAdd = $.extend(true, {}, bt.data.database.data_add);
copyDataAdd.list[2].items[0].value = bt.get_random(16);
switch (type) {
case 'sqlserver':
case 'mongodb':
case 'pgsql':
delete copyDataAdd.list[0].items[1];
copyDataAdd.list.splice(3);
copyDataAdd.list.push(bt.data.database.data_add.list[4]);
copyDataAdd.list.push(bt.data.database.data_add.list[5]);
copyDataAdd.list[3].items[0].items = cloudList;
break;
}
// 没有本地或者远程数据库
if (cloudList.length == 0) {
copyDataAdd.list[copyDataAdd.list.length - 1].hide = true;
}
bt.render_form($.extend(true, {}, copyDataAdd), function (rdata) {
if (callback) callback(rdata);
});
}
},
del_database: function (data, callback) {
var loadT = bt.load(lan.get('del_all_task_the', [data.name]));
var type = bt.data.database.getType();
var params = { url: 'database?action=DeleteDatabase', data: data };
if (type != 'mysql') {
params.url = 'database/' + type + '/DeleteDatabase';
params.data = { data: JSON.stringify(data) };
}
bt_tools.send(params, function (rdata) {
loadT.close();
bt.msg(rdata);
if (callback) callback(rdata);
});
},
sync_database: function (sid, callback) {
var loadT = bt.load(lan.database.sync_the);
var type = bt.data.database.getType();
var params = { url: 'database?action=SyncGetDatabases', data: { sid: sid } };
if (type != 'mysql') {
params.url = 'database/' + type + '/SyncGetDatabases';
params.data = { data: JSON.stringify({ sid: sid }) };
}
bt_tools.send(params, function (rdata) {
loadT.close();
bt.msg(rdata);
if (callback) callback(rdata);
});
},
sync_to_database: function (data, callback) {
var loadT = bt.load(lan.database.sync_the);
var type = bt.data.database.getType();
var params = { url: 'database?action=SyncToDatabases', data: data };
if (type != 'mysql') {
params.url = 'database/' + type + '/SyncToDatabases';
params.data = { data: JSON.stringify(data) };
}
bt_tools.send(params, function (rdata) {
loadT.close();
if (callback) callback(rdata);
bt.msg(rdata);
});
},
open_phpmyadmin: function (name, username, password) {
if ($('#toPHPMyAdmin').attr('action').indexOf('phpmyadmin') == -1) {
layer.msg(lan.database.phpmyadmin_err, { icon: 2, shade: [0.3, '#000'] });
setTimeout(function () {
window.location.href = '/soft';
}, 3000);
return;
}
$('#toPHPMyAdmin').attr('action', $('#toPHPMyAdmin').attr('public-data'));
var murl = $('#toPHPMyAdmin').attr('action');
$('#pma_username').val(username);
$('#pma_password').val(password);
$('#db').val(name);
layer.msg(lan.database.phpmyadmin, { icon: 16, shade: [0.3, '#000'], time: 1000 });
setTimeout(function () {
$('#toPHPMyAdmin').submit();
layer.closeAll();
}, 200);
},
submit_phpmyadmin: function (name, username, password, pub) {
if (pub === true) {
$('#toPHPMyAdmin').attr('action', $('#toPHPMyAdmin').attr('public-data'));
} else {
$('#toPHPMyAdmin').attr('action', '/phpmyadmin/index.php');
}
var murl = $('#toPHPMyAdmin').attr('action');
$('#pma_username').val(username);
$('#pma_password').val(password);
$('#db').val(name);
layer.msg(lan.database.phpmyadmin, { icon: 16, shade: [0.3, '#000'], time: 1000 });
setTimeout(function () {
$('#toPHPMyAdmin').submit();
layer.closeAll();
}, 200);
},
input_sql: function (fileName, dataName) {
bt.confirm({ msg: lan.database.input_confirm, title: lan.database.input_title }, function (index) {
var loading = bt.load(lan.database.input_the);
var type = bt.data.database.getType();
var params = { url: 'database?action=InputSql', data: { file: fileName, name: dataName } };
if (type != 'mysql') {
params.url = 'database/' + type + '/InputSql';
params.data = { data: JSON.stringify({ file: fileName, name: dataName }) };
}
bt_tools.send(params, function (rdata) {
loading.close();
bt.msg(rdata);
});
});
},
backup_data: function (id, callback) {
var loadT = bt.load(lan.database.backup_the);
var type = bt.data.database.getType();
var params = { url: 'database?action=ToBackup', data: { id: id } };
if (type != 'mysql') {
params.url = 'database/' + type + '/ToBackup';
params.data = { data: JSON.stringify({ id: id }) };
}
bt_tools.send(params, function (rdata) {
loadT.close();
bt.msg(rdata);
if (callback) callback(rdata);
});
},
del_backup: function (id, success, error) {
bt.confirm({ msg: lan.database.backup_del_confirm, title: lan.database.backup_del_title }, function (index) {
var loadT = bt.load();
bt.send('DelBackup', 'database/DelBackup', { id: id }, function (frdata) {
loadT.close();
bt.msg(frdata);
if (frdata.status) {
success && success(frdata);
} else {
error && error(frdata);
}
});
});
},
};
bt.send('get_config', 'config/get_config', {}, function (rdata) {
bt.config = rdata;
});
bt.plugin = {
get_plugin_byhtml: function (name, callback) {
bt.send('getConfigHtml', 'plugin/getConfigHtml', { name: name }, function (rdata) {
if (callback) callback(rdata);
});
},
get_firewall_state: function (callback) {
var typename = getCookie('serverType');
var name = 'btwaf_httpd';
if (typename == 'nginx') name = 'btwaf';
bt.send('a', 'plugin/a', { name: name, s: 'get_total_all' }, function (rdata) {
if (callback) callback(rdata);
});
},
};
bt.site = {
get_list: function (page, search, type, callback) {
if (page == undefined) page = 1;
type = type == undefined ? '&type=-1' : '&type=' + type;
search = search == undefined ? '' : search;
var order = bt.get_cookie('order') ? '&order=' + bt.get_cookie('order') : '';
var data = 'tojs=site.get_list&table=sites&limit=15&p=' + page + '&search=' + search + order + type;
bt.pub.get_data(data, function (rdata) {
if (callback) callback(rdata);
});
},
get_domains: function (id, callback) {
var data = 'table=domain&list=True&search=' + id;
bt.pub.get_data(
data,
function (rdata) {
if (callback) callback(rdata);
},
1
);
},
get_type: function (callback) {
bt.send('get_site_types', 'site/get_site_types', '', function (rdata) {
if (callback) callback(rdata);
});
},
add_type: function (name, callback) {
bt.send('add_site_type', 'site/add_site_type', { name: name }, function (rdata) {
if (callback) callback(rdata);
});
},
edit_type: function (data, callback) {
bt.send('modify_site_type_name', 'site/modify_site_type_name', { id: data.id, name: data.name }, function (rdata) {
if (callback) callback(rdata);
});
},
del_type: function (id, callback) {
bt.send('remove_site_type', 'site/remove_site_type', { id: id }, function (rdata) {
if (callback) callback(rdata);
});
},
set_site_type: function (data, callback) {
bt.send('set_site_type', 'site/set_site_type', { id: data.id, site_ids: data.site_array }, function (rdata) {
if (callback) callback(rdata);
});
},
get_site_domains: function (id, callback) {
var loading = bt.load();
bt.send('GetSiteDomains', 'site/GetSiteDomains', { id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
add_domains: function (id, webname, domains, callback) {
var loading = bt.load();
bt.send('AddDomain', 'site/AddDomain', { domain: domains, webname: webname, id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
bt.msg(rdata);
});
},
del_domain: function (siteId, siteName, domain, port, callback) {
var loading = bt.load();
bt.send('DelDomain', 'site/DelDomain', { id: siteId, webname: siteName, domain: domain, port: port }, function (rdata) {
loading.close();
if (callback) callback(rdata);
bt.msg(rdata);
});
},
get_dirbind: function (id, callback) {
var loading = bt.load();
bt.send('GetDirBinding', 'site/GetDirBinding', { id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
add_dirbind: function (id, domain, dirName, callback) {
var loading = bt.load();
bt.send('AddDirBinding', 'site/AddDirBinding', { id: id, domain: domain, dirName: dirName }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
del_dirbind: function (id, callback) {
var loading = bt.load();
bt.send('DelDirBinding', 'site/DelDirBinding', { id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_dir_rewrite: function (data, callback) {
var loading = bt.load();
bt.send('GetDirRewrite', 'site/GetDirRewrite', data, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_site_path: function (id, callback) {
bt.send('getKey', 'data/getKey', { table: 'sites', key: 'path', id: id }, function (rdata) {
if (callback) callback(rdata);
});
},
get_dir_userini: function (id, path, callback) {
bt.send('GetDirUserINI', 'site/GetDirUserINI', { id: id, path: path }, function (rdata) {
if (callback) callback(rdata);
});
},
set_dir_userini: function (path, id, callback) {
var loading = bt.load();
bt.send('SetDirUserINI', 'site/SetDirUserINI', { path: path, id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_logs_status: function (id, callback) {
var loading = bt.load();
bt.send('logsOpen', 'site/logsOpen', { id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_site_runpath: function (id, path, callback) {
var loading = bt.load();
bt.send('SetSiteRunPath', 'site/SetSiteRunPath', { id: id, runPath: path }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_site_path: function (id, path, callback) {
var loading = bt.load();
bt.send('SetPath', 'site/SetPath', { id: id, path: path }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_site_path_new: function (id, path, name, callback) {
var loading = bt.load();
bt.send('SetPath', 'site/SetPath', { id: id, path: path, name: name }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_site_pwd: function (id, username, password, callback) {
var loading = bt.load();
bt.send('SetHasPwd', 'site/SetHasPwd', { id: id, username: username, password: password }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
close_site_pwd: function (id, callback) {
var loading = bt.load();
bt.send('SetHasPwd', 'site/CloseHasPwd', { id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_limitnet: function (id, callback) {
bt.send('GetLimitNet', 'site/GetLimitNet', { id: id }, function (rdata) {
if (callback) callback(rdata);
});
},
set_limitnet: function (id, perserver, perip, limit_rate, callback) {
var loading = bt.load();
bt.send('SetLimitNet', 'site/SetLimitNet', { id: id, perserver: perserver, perip: perip, limit_rate: limit_rate }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
close_limitnet: function (id, callback) {
var loading = bt.load();
bt.send('CloseLimitNet', 'site/CloseLimitNet', { id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_rewrite_list: function (siteName, callback) {
bt.send('GetRewriteList', 'site/GetRewriteList', { siteName: siteName }, function (rdata) {
if (callback) callback(rdata);
});
},
set_rewrite_tel: function (name, data, callback) {
var loading = bt.load(lan.site.saving_txt);
bt.send('SetRewriteTel', 'site/SetRewriteTel', { name: name, data: data }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_index: function (id, callback) {
bt.send('GetIndex', 'site/GetIndex', { id: id }, function (rdata) {
if (callback) callback(rdata);
});
},
set_index: function (id, index, callback) {
var loading = bt.load();
bt.send('SetIndex', 'site/SetIndex', { id: id, Index: index }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_site_config: function (siteName, callback) {
if (bt.os == 'Linux') {
var sPath = '/www/server/panel/vhost/' + bt.get_cookie('serverType') + '/' + siteName + '.conf';
bt.files.get_file_body(sPath, function (rdata) {
if (callback) callback(rdata);
});
}
},
set_site_config: function (siteName, data, encoding, callback) {
var loading = bt.load(lan.site.saving_txt);
if (bt.os == 'Linux') {
var sPath = '/www/server/panel/vhost/' + bt.get_cookie('serverType') + '/' + siteName + '.conf';
bt.files.set_file_body(sPath, data, 'utf-8', function (rdata) {
loading.close();
if (callback) callback(rdata);
});
}
},
set_phpversion: function (siteName, version, other, callback) {
var loading = bt.load();
bt.send('SetPHPVersion', 'site/SetPHPVersion', { siteName: siteName, version: version, other: other }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
// 重定向列表
get_redirect_list: function (name, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('GetRedirectList', 'site/GetRedirectList', { sitename: name }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
// 重定向列表
get_redirect_list: function (name, callback) {
var loadT = layer.load();
bt.send('GetRedirectList', 'site/GetRedirectList', { sitename: name }, function (rdata) {
layer.close(loadT);
if (callback) callback(rdata);
});
},
create_redirect: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('CreateRedirect', 'site/CreateRedirect', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
modify_redirect: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('ModifyRedirect', 'site/ModifyRedirect', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
remove_redirect: function (sitename, redirectname, callback) {
bt.show_confirm(lan.public_backup.del_rep + '[' + redirectname + ']', lan.public_backup.sure_del_rep, function () {
var loadT = bt.load(lan.site.the_msg);
bt.send('DeleteRedirect', 'site/DeleteRedirect', { sitename: sitename, redirectname: redirectname }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
});
},
get_redirect_config: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('GetRedirectFile', 'site/GetRedirectFile', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
save_redirect_config: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('SaveProxyFile', 'site/SaveRedirectFile', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_site_proxy: function (siteName, callback) {
bt.send('GetProxy', 'site/GetProxy', { name: siteName }, function (rdata) {
if (callback) callback(rdata);
});
},
set_site_proxy: function (siteName, type, proxyUrl, toDomain, sub1, sub2, callback) {
var loading = bt.load();
bt.send('SetProxy', 'site/SetProxy', { name: siteName, type: type, proxyUrl: proxyUrl, toDomain: toDomain, sub1: sub1, sub2: sub2 }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_open_proxy_cache: function (siteName, callback) {
var loading = bt.load();
bt.send('ProxyCache', 'site/ProxyCache', { siteName: siteName }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_proxy_list: function (name, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('GetProxyList', 'site/GetProxyList', { sitename: name }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
create_proxy: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('CreateProxy', 'site/CreateProxy', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
remove_proxy: function (sitename, proxyname, callback) {
bt.show_confirm(lan.public_backup.del_proxy + '[' + proxyname + ']', lan.public_backup.sure_del_proxy, function () {
var loadT = bt.load(lan.site.the_msg);
bt.send('RemoveProxy', 'site/RemoveProxy', { sitename: sitename, proxyname: proxyname }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
bt.msg(rdata);
});
});
},
modify_proxy: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('ModifyProxy', ' site/ModifyProxy', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_proxy_config: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('GetProxyFile', 'site/GetProxyFile', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
save_proxy_config: function (obj, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('SaveProxyFile', 'site/SaveProxyFile', obj, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_site_security: function (id, name, callback) {
bt.send('GetSecurity', 'site/GetSecurity', { id: id, name: name }, function (rdata) {
if (callback) callback(rdata);
});
},
set_site_security: function (id, name, fix, domains, status, return_rule, callback) {
var loading = bt.load(lan.site.the_msg);
bt.send('SetSecurity', 'site/SetSecurity', { id: id, name: name, fix: fix, domains: domains, status: status, return_rule: return_rule }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_site_301: function (siteName, callback) {
bt.send('Get301Status', 'site/Get301Status', { siteName: siteName }, function (rdata) {
if (callback) callback(rdata);
});
},
set_site_301: function (siteName, srcDomain, toUrl, type, callback) {
var loading = bt.load();
bt.send('Set301Status', 'site/Set301Status', { siteName: siteName, toDomain: toUrl, srcDomain: srcDomain, type: type }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_tomcat: function (siteName, callback) {
var loading = bt.load(lan.public.config);
bt.send('SetTomcat', 'site/SetTomcat', { siteName: siteName }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_site_logs: function (siteName, callback) {
var loading = bt.load();
bt.send('GetSiteLogs', 'site/GetSiteLogs', { siteName: siteName }, function (rdata) {
loading.close();
if (rdata.status !== true) rdata.msg = '';
if (rdata.msg == '') rdata.msg = lan.public_backup.no_log;
if (callback) callback(rdata);
});
},
get_site_error_logs: function (siteName, callback) {
var loading = bt.load();
bt.send(
'get_site_err_log',
'site/get_site_err_log',
{
siteName: siteName,
},
function (rdata) {
loading.close();
if (rdata.status !== true) rdata.msg = '';
if (rdata.msg == '') rdata.msg = lan.public_backup.no_log;
if (callback) callback(rdata);
}
);
},
get_site_ssl: function (siteName, callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('GetSSL', 'site/GetSSL', { siteName: siteName }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
create_let: function (data, callback) {
var loadT = layer.open({
title: false,
type: 1,
closeBtn: 0,
shade: 0.3,
area: '500px',
offset: '30%',
content:
"
" + lan.public_backup.preparing_for_cert + '...
',
success: function (layers, index) {
bt.site.get_let_logs();
bt.send('CreateLet', 'site/CreateLet', data, function (rdata) {
layer.close(loadT);
if (callback) callback(rdata);
});
},
});
},
get_let_logs: function () {
bt.send(
'get_lines',
'ajax/get_lines',
{
num: 10,
filename: '/www/server/panel/logs/letsencrypt.log',
},
function (rdata) {
if ($('#create_lst').text() === '') return;
if (rdata.status === true) {
$('#create_lst').text(rdata.msg);
$('#create_lst').scrollTop($('#create_lst')[0].scrollHeight);
}
setTimeout(function () {
bt.site.get_let_logs();
}, 1000);
}
);
},
get_dns_api: function (callback) {
var loadT = bt.load();
bt.send('GetDnsApi', 'site/GetDnsApi', {}, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
set_dns_api: function (data, callback) {
var loadT = bt.load();
bt.send('SetDnsApi', 'site/SetDnsApi', data, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
verify_domain: function (partnerOrderId, siteName, callback) {
var loadT = bt.load(lan.site.ssl_apply_2);
bt.send('Completed', 'ssl/Completed', { partnerOrderId: partnerOrderId, siteName: siteName }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_dv_ssl: function (domain, path, callback) {
var loadT = bt.load(lan.site.ssl_apply_1);
bt.send('GetDVSSL', 'ssl/GetDVSSL', { domain: domain, path: path }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_module_config: function (param, callback) {
var loadT = bt.load('Obtaining the alarm configuration, please wait...');
bt.send(
'get_module_config',
'push/get_module_config',
{
name: param.name,
type: param.type,
},
function (rdata) {
loadT.close();
if (callback) callback(rdata);
}
);
},
// 设置
set_push_config: function (param, callback) {
var loadT = bt.load('Please wait while setting alarm configuration...');
bt.send(
'set_push_config',
'push/set_push_config',
{
name: param.name,
id: param.id,
data: param.data,
},
function (rdata) {
loadT.close();
if (callback) callback(rdata);
}
);
},
// 获取消息推送配置
get_msg_configs: function (callback) {
var loadT = bt.load('Getting the message push configuration, please wait...');
bt.send('get_msg_configs', 'config/get_msg_configs', {}, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
// 下载证书
download_cert: function (param, callback) {
var loadT = bt.load('Please wait while downloading the certificate...');
bt.send(
'download_cert',
'site/download_cert',
{
siteName: param.siteName,
ssl_type: param.ssl_type || 'csr',
pem: param.pem,
key: param.key,
pwd: param.pwd || '', //密码,非必填
},
function (rdata) {
loadT.close();
if (callback) callback(rdata);
}
);
},
get_ssl_info: function (partnerOrderId, siteName, callback) {
var loadT = bt.load(lan.site.ssl_apply_3);
bt.send('GetSSLInfo', 'ssl/GetSSLInfo', { partnerOrderId: partnerOrderId, siteName: siteName }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
set_cert_ssl: function (certName, siteName, callback) {
var loadT = bt.load(lan.public_backup.deploy_cert);
bt.send('SetCertToSite', 'ssl/SetCertToSite', { certName: certName, siteName: siteName }, function (rdata) {
loadT.close();
site.reload();
if (callback) callback(rdata);
setTimeout(() => {
bt.msg(rdata);
}, 100);
});
},
remove_cert_ssl: function (certName, callback) {
bt.show_confirm(lan.public_backup.del_cert, lan.public_backup.sure_del_cert, function () {
var loadT = bt.load(lan.site.the_msg);
bt.send('RemoveCert', 'ssl/RemoveCert', { certName: certName }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
bt.msg(rdata);
});
});
},
set_http_to_https: function (siteName, callback) {
var loading = bt.load();
bt.send('HttpToHttps', 'site/HttpToHttps', { siteName: siteName }, function (rdata) {
loading.close();
if (callback) callback(rdata);
bt.msg(rdata);
});
},
close_http_to_https: function (siteName, callback) {
var loading = bt.load();
bt.send('CloseToHttps', 'site/CloseToHttps', { siteName: siteName }, function (rdata) {
loading.close();
if (callback) callback(rdata);
bt.msg(rdata);
});
},
set_ssl: function (siteName, data, callback) {
if (data.path) {
//iis导入证书
} else {
var loadT = bt.load(lan.site.saving_txt);
bt.send('SetSSL', 'site/SetSSL', { type: 1, siteName: siteName, key: data.key, csr: data.csr }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
}
},
set_ssl_status: function (action, siteName, callback) {
var loadT = bt.load(lan.site.get_ssl_list);
bt.send(action, 'site/' + action, { updateOf: 1, siteName: siteName }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_cer_list: function (callback) {
var loadT = bt.load(lan.site.the_msg);
bt.send('GetCertList', 'ssl/GetCertList', {}, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_order_list: function (siteName, callback) {
bt.send('GetOrderList', 'ssl/GetOrderList', { siteName: siteName }, function (rdata) {
if (callback) callback(rdata);
});
},
del_site: function (data, callback) {
var loadT = bt.load(lan.get('del_all_task_the', [data.webname]));
bt.send('DeleteSite', 'site/DeleteSite', data, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
add_site: function (callback) {
var _form = $.extend(true, {}, bt.data.site.add);
bt.site.get_all_phpversion(function (rdata) {
bt.site.get_type(function (tdata) {
for (var i = 0; i < _form.list.length; i++) {
if (_form.list[i].name == 'version') {
var items = [];
for (var j = rdata.length - 1; j >= 0; j--) {
var o = rdata[j];
o.value = o.version;
o.title = o.name;
items.push(o);
}
_form.list[i].items = items;
} else if (_form.list[i].name == 'type_id') {
for (var x = 0; x < tdata.length; x++) _form.list[i].items.push({ value: tdata[x].id, title: tdata[x].name });
}
}
var bs = bt.render_form(_form, function (rdata) {
if (callback) callback(rdata);
});
$('.placeholder').click(function () {
$(this).hide();
$('.webname' + bs).focus();
});
$('.path' + bs).val($('#defaultPath').text());
$('.webname' + bs).focus(function () {
$('.placeholder').hide();
});
$('.webname' + bs).blur(function () {
if ($(this).val().length == 0) {
$('.placeholder').show();
}
});
$('.webname' + bs).focus(function () {
var _this = $(this),
tips =
'www will not add by default, if you need to access,please add it like:\
hostname.com\
www.hostname.com';
_this.attr('placeholder', '');
var loadT = layer.tips(tips, _this, {
tips: [1, '#20a53a'],
time: 0,
area: _this[0].clientWidth + 'px',
});
$(this).one('blur', function () {
layer.close(loadT);
});
});
$('.line').on('mouseenter', '.bt-ico-ask', function () {
var idd = $(this).attr('class').split(' ')[1],
tip = $(this).attr('tip');
layer.tips(tip, '.' + idd + '', { tips: [1, '#d4d4d4'], time: 0, area: '300px' });
});
$('.line').on('mouseleave', '.bt-ico-ask', function () {
layer.closeAll('tips');
});
$('.domain_textarea').parents('.bt-form').css({ 'max-height': '565px', overflow: 'auto' });
});
});
},
get_all_phpversion: function (callback) {
bt.send('GetPHPVersion', 'site/GetPHPVersion', {}, function (rdata) {
if (callback) callback(rdata);
});
},
get_site_phpversion: function (siteName, callback) {
bt.send('GetSitePHPVersion', 'site/GetSitePHPVersion', { siteName: siteName }, function (rdata) {
if (callback) callback(rdata);
});
},
stop: function (id, name, callback) {
bt.confirm({ title: lan.public_backup.stop_site + ' 【' + name + '】', msg: lan.site.site_stop_txt }, function (index) {
if (index > 0) {
var loadT = bt.load();
bt.send('SiteStop', 'site/SiteStop', { id: id, name: name }, function (ret) {
loadT.close();
if (site && typeof callback == 'undefined') {
site.get_list();
} else {
if (callback) callback(ret);
}
bt.msg(ret);
});
}
});
},
start: function (id, name, callback) {
bt.confirm({ title: lan.public_backup.start_site + ' 【' + name + '】', msg: lan.site.site_start_txt }, function (index) {
if (index > 0) {
var loadT = bt.load();
bt.send('SiteStart', 'site/SiteStart', { id: id, name: name }, function (ret) {
loadT.close();
if (site && typeof callback == 'undefined') {
site.get_list();
} else {
if (callback) callback(ret);
}
bt.msg(ret);
});
}
});
},
backup_data: function (id, callback) {
var loadT = bt.load(lan.database.backup_the);
bt.send('ToBackup', 'site/ToBackup', { id: id }, function (rdata) {
loadT.close();
bt.msg(rdata);
if (callback) callback(rdata);
});
},
del_backup: function (id, siteId, siteName) {
bt.confirm({ msg: lan.site.webback_del_confirm, title: lan.site.del_bak_file }, function (index) {
var loadT = bt.load();
bt.send('DelBackup', 'site/DelBackup', { id: id }, function (frdata) {
loadT.close();
if (frdata.status) {
if (site) site.site_detail(siteId, siteName);
}
bt.msg(frdata);
});
});
},
set_endtime: function (id, dates, callback) {
var loadT = bt.load(lan.site.saving_txt);
bt.send('SetEdate', 'site/SetEdate', { id: id, edate: dates }, function (rdata) {
loadT.close();
if (callback) callback(rdata);
});
},
get_default_path: function (type, callback) {
var vhref = '';
if (bt.os == 'Linux') {
switch (type) {
case 0:
vhref = '/www/server/panel/data/defaultDoc.html';
break;
case 1:
vhref = '/www/server/panel/data/404.html';
break;
case 2:
var serverType = bt.get_cookie('serverType');
vhref = '/www/server/apache/htdocs/index.html';
if (serverType == 'nginx') vhref = '/www/server/nginx/html/index.html';
break;
case 3:
vhref = '/www/server/stop/index.html';
break;
}
}
if (callback) callback(vhref);
},
get_default_site: function (callback) {
var loading = bt.load();
bt.send('GetDefaultSite', 'site/GetDefaultSite', {}, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
set_default_site: function (name, callback) {
var loading = bt.load();
bt.send('SetDefaultSite', 'site/SetDefaultSite', { name: name }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_dir_auth: function (id, callback) {
var loading = bt.load();
bt.send('get_dir_auth', 'site/get_dir_auth', { id: id }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
get_php_deny: function (website, callback) {
var loading = bt.load();
bt.send('get_file_deny', 'config/get_file_deny', { website: website }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
edit_php_deny: function (data, callback) {
var loading = bt.load();
bt.send('set_file_deny', 'config/set_file_deny', data, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
del_php_deny: function (data, callback) {
var loading = bt.load();
bt.send('del_file_deny', 'config/del_file_deny', data, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
create_dir_guard: function (data, callback) {
var loading = bt.load();
bt.send('set_dir_auth', 'site/set_dir_auth', { id: data.id, name: data.name, site_dir: data.site_dir, username: data.username, password: data.password }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
edit_dir_account: function (data, callback) {
var loading = bt.load();
bt.send('modify_dir_auth_pass', 'site/modify_dir_auth_pass', { id: data.id, name: data.name, username: data.username, password: data.password }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
},
delete_dir_guard: function (id, data, callback) {
var loading = bt.load();
bt.show_confirm(lan.public_backup.del + '[' + data + ']', lan.public_backup.del_dir, function () {
bt.send('delete_dir_auth', 'site/delete_dir_auth', { id: id, name: data }, function (rdata) {
loading.close();
if (callback) callback(rdata);
});
});
},
};
bt.form = {
btn: {
close: function (title, callback) {
var obj = { title: lan.public_backup.turn_off, name: 'btn-danger' };
if (title) obj.title = title;
if (callback) obj['callback'] = callback;
return obj;
},
submit: function (title, callback) {
var obj = { title: lan.public_backup.submit, name: 'submit', css: 'btn-success' };
if (title) obj.title = title;
if (callback) obj['callback'] = callback;
return obj;
},
},
item: {
data_access: {
title: 'Permission',
items: [
{
name: 'dataAccess',
type: 'select',
width: '100px',
items: [
{ title: lan.public_backup.local_server, value: '127.0.0.1' },
{ title: lan.public_backup.every_one, value: '%' },
{ title: lan.public_backup.specify_ip, value: 'ip' },
],
callback: function (obj) {
var subid = obj.attr('name') + '_subid';
$('#' + subid).remove();
if (obj.val() == 'ip') {
obj
.parent()
.append(
'
'
);
}
},
},
],
},
password: {
title: lan.public_backup.pass,
name: 'password',
items: [
{
type: 'text',
width: '311px',
value: bt.get_random(16),
event: {
css: 'glyphicon-repeat',
callback: function (obj) {
bt.refresh_pwd(16, obj);
},
},
},
],
},
},
};
bt.data = {
database: {
getType: function () {
return bt.get_cookie('db_page_model') || 'mysql';
},
root: {
title: lan.database.edit_pass_title,
area: '530px',
list: [
{
title: lan.public_backup.rootpass,
name: 'password',
items: [
{
type: 'text',
width: '311px',
event: {
css: 'glyphicon-repeat',
callback: function (obj) {
bt.refresh_pwd(16, obj);
},
},
},
],
},
],
btns: [
bt.form.btn.close(),
bt.form.btn.submit(lan.public_backup.submit, function (rdata, load) {
var loading = bt.load();
var type = bt.data.database.getType();
var params = { url: 'database?action=SetupPassword', data: rdata };
if (type != 'mysql') {
params.url = 'database/' + type + '/SetupPassword';
params.data = { data: JSON.stringify(rdata) };
}
bt_tools.send(params, function (rRet) {
loading.close();
bt.msg(rRet);
if (rRet.status) load.close();
});
}),
],
},
mongo: {
title: lan.database.edit_pass_title,
area: '530px',
list: [
{
title: lan.public_backup.rootpass,
name: 'password',
items: [
{
type: 'text',
width: '311px',
event: {
css: 'glyphicon-repeat',
callback: function (obj) {
bt.refresh_pwd(16, obj);
},
},
},
],
},
],
btns: [
bt.form.btn.close(),
bt.form.btn.submit(lan.public_backup.submit, function (rdata, load) {
var loading = bt.load();
var type = bt.data.database.getType();
var url = 'database/' + type + '/set_auth_status';
if (type == 'pgsql') url = 'database/' + type + '/set_root_pwd';
bt_tools.send(
{
url: url,
data: { data: JSON.stringify($.extend(rdata, { status: 1 })) },
},
function (rRet) {
loading.close();
bt.msg(rRet);
load.close();
}
);
}),
],
},
data_add: {
title: lan.database.add_title,
area: '530px',
list: [
{
title: 'DBName',
items: [
{
name: 'name',
placeholder: lan.public_backup.new_db_name,
type: 'text',
width: '65%',
callback: function (obj) {
$('input[name="db_user"]').val(obj.val());
},
},
{
name: 'codeing',
type: 'select',
width: '27%',
items: [
{ title: 'utf-8', value: 'utf8' },
{ title: 'utf8mb4', value: 'utf8mb4' },
{ title: 'gbk', value: 'gbk' },
{ title: 'big5', value: 'big5' },
],
},
],
},
{
name: 'db_user',
title: lan.public_backup.user_name,
placeholder: lan.public_backup.db_user,
width: '65%',
},
bt.form.item.password,
bt.form.item.data_access,
{
title: lan.public_backup.add_to,
items: [
{
name: 'sid',
width: '65%',
type: 'select',
items: [],
},
],
},
{
html: '\
\
',
},
],
btns: [
bt.form.btn.close(),
bt.form.btn.submit(lan.public_backup.submit, function (rdata, load, callback) {
if (!rdata.address) rdata.address = rdata.dataAccess;
if (!rdata.ps) rdata.ps = rdata.name;
if (!rdata.ssl) rdata.ssl = $('#check_ssl').prop('checked') ? 'REQUIRE SSL' : '';
var loading = bt.load();
var type = bt.data.database.getType();
var param = {
url: 'database/' + type + '/AddDatabase',
data: { data: JSON.stringify(rdata) },
};
if (type == 'mysql') {
rdata['dtype'] = 'MySQL';
param = { url: 'database?action=AddDatabase', data: rdata };
}
bt_tools.send(param, function (rRet) {
loading.close();
if (rRet.status) load.close();
if (callback) callback(rRet);
bt.msg(rRet);
});
}),
],
success: function () {
$('[name=sid]').after('
' + lan.public.manage_cloud_server + '');
var type = bt.data.database.getType();
// 当前类型为mongodb
if (type == 'mongodb') {
// 是否开启安全认证,没开启隐藏用户名跟密码
if (!mongodb.mongoDBAccessStatus) {
$('.layui-layer.layui-layer-page .line').eq(1).hide();
$('.layui-layer.layui-layer-page .line').eq(2).hide();
}
// 远程服务器类型判断
$('[name=sid]').change(function () {
// 为远程服务器时,默认开启安全认证
if ($(this).val() != 0) {
$('.layui-layer.layui-layer-page .line').eq(1).show();
$('.layui-layer.layui-layer-page .line').eq(2).show();
} else {
if (!mongodb.mongoDBAccessStatuss) {
$('.layui-layer.layui-layer-page .line').eq(1).hide();
$('.layui-layer.layui-layer-page .line').eq(2).hide();
}
}
});
}
},
},
data_access: {
title: lan.public_backup.set_db_permissions,
area: '480px',
list: [
{ title: 'name', name: 'name', hide: true },
bt.form.item.data_access,
{
title: 'Force SSL',
items: [
{
name: 'force_ssl',
type: 'switch',
value: 'false',
},
],
},
],
btns: [
bt.form.btn.close(),
{
title: lan.public_backup.submit,
name: 'submit',
css: 'btn-success',
callback: function (rdata, load) {
var loading = bt.load();
rdata.access = rdata.dataAccess;
if (rdata.access == 'ip') rdata.access = rdata.address;
rdata.ssl = $('#force_ssl').prop('checked') ? 'REQUIRE SSL' : '';
bt.send('SetDatabaseAccess', 'database/SetDatabaseAccess', rdata, function (rRet) {
loading.close();
bt.msg(rRet);
if (rRet.status) load.close();
});
},
},
],
},
data_pass: {
title: lan.public_backup.change_db_pass,
area: '530px',
list: [
{ title: 'id', name: 'id', hide: true },
{ title: lan.public_backup.user_name, name: 'name', disabled: true },
{
title: lan.public_backup.pass,
name: 'password',
items: [
{
type: 'text',
event: {
css: 'glyphicon-repeat',
callback: function (obj) {
bt.refresh_pwd(16, obj);
},
},
},
],
},
],
btns: [
{ title: lan.public_backup.turn_off, name: 'close' },
{
title: lan.public_backup.submit,
name: 'submit',
css: 'btn-success',
callback: function (rdata, load, callback) {
var loading = bt.load();
var type = bt.data.database.getType();
var params = { url: 'database?action=ResDatabasePassword', data: rdata };
if (type != 'mysql') {
params.url = 'database/' + type + '/ResDatabasePassword';
params.data = { data: JSON.stringify(rdata) };
}
bt_tools.send(params, function (rRet) {
loading.close();
bt.msg(rRet);
if (rRet.status) load.close();
if (callback) callback(rRet);
});
},
},
],
},
},
site: {
add: {
title: lan.site.site_add,
area: '680px',
list: [
{
title: lan.public_backup.domain,
name: 'webname',
class: 'domain_textarea',
items: [
{
type: 'textarea',
width: '420px',
height: '80px',
style: 'padding:10px;line-height: 15px;',
callback: function (obj) {
var array = obj.val().split('\n');
var ress = array[0].split(':')[0];
var res = bt.strim(ress.replace(new RegExp(/([-.])/g), '_'));
var ftp_user = res;
var data_user = res;
if (!isNaN(res.substr(0, 1))) {
ftp_user = 'ftp_' + ftp_user;
data_user = 'sql_' + data_user;
}
if (data_user.length > 16) data_user = data_user.substr(0, 16);
obj.data('ftp', ftp_user);
obj.data('database', data_user);
$('.ftp_username').val(ftp_user);
$('.datauser').val(data_user);
var _form = obj.parents('div.bt-form');
var _path_obj = _form.find('input[name="path"]');
var path = _path_obj.val();
var defaultPath = $('#defaultPath').text();
var dPath = bt.rtrim(defaultPath, '/');
if (path.substr(0, dPath.length) == dPath) _path_obj.val(dPath + '/' + ress);
_form.find('input[name="ps"]').val(ress);
clearTimeout(bt.setTimeouts);
bt.setTimeouts = setTimeout(function () {
if (bt.check_domain(ress)) {
if (ress.indexOf('www.') !== 0) {
$('.redirect_checkbox label').html('Add [
www.' + ress + '] domain name to the main domain name');
} else if (ress.indexOf('www.') === 0) {
$('.redirect_checkbox label').html('Add
' + ress.replace(/^www\./, '') + ' to the main domain');
}
$('.redirect_checkbox').show();
} else {
$('.redirect_checkbox,redirect_tourl').hide();
}
}, 100);
},
placeholder: lan.public_backup.domian_tips,
},
],
},
{
title: '',
name: 'redirect',
class: 'redirect_checkbox',
hide: true,
items: [
{
type: 'checkbox',
text: '',
callback: function (obj) {
var domain = $('.redirect_checkbox').find('span').text(),
domain_textarea = $('.domain_textarea textarea'),
domainList = domain_textarea.val().split('\n'),
domain_one = domainList[0].split(':')[0];
if (obj.redirect) {
domain_textarea.val(domain_textarea.val() + '\r' + domain);
var line = $(
bt.render_form_line({
title: 'Redirect',
name: 'tourl',
class: 'redirect_tourl',
items: [
{
type: 'radio_group',
value: 0,
list: [
{ value: 0, text: 'No' },
{
value: 1,
text: 'Redirect the main domain name [
' + domain_one + '] to [
' + domain + '] domain name',
},
{
value: 2,
text: 'Redirect the [
' + domain + '] domain name to the main domain [
' + domain_one + ']',
},
],
},
],
}).html
);
$('.redirect_checkbox.line').after(line);
} else {
for (var i = domainList.length - 1; i >= 0; i--) {
if (domainList[i] === domain) domainList.splice(i, 1);
}
domain_textarea.val(domainList.join('\n'));
$('.redirect_checkbox').next('.redirect_tourl').remove();
}
},
},
],
},
{ title: lan.public_backup.ps, name: 'ps', placeholder: lan.public_backup.site_ps },
{
title: lan.public_backup.root_dir,
name: 'path',
items: [
{
type: 'text',
width: '330px',
event: {
css: 'glyphicon-folder-open',
callback: function (obj) {
bt.select_path(obj);
},
},
},
],
},
{
title: 'FTP',
items: [
{
name: 'ftp',
type: 'select',
items: [
{ value: 'false', title: lan.public_backup.dont_create },
{ value: 'true', title: lan.public_backup.create },
],
callback: function (obj) {
var subid = obj.attr('name') + '_subid';
$('#' + subid).remove();
if (obj.val() == 'true') {
var _bs = obj.parents('div.bt-form').attr('data-id');
var ftp_user = $('textarea[name="webname"]').data('ftp');
var item = {
title: lan.public_backup.set_ftp,
class: 'pb0',
name: 'ftp_tips',
items: [
{ name: 'ftp_username', title: lan.public_backup.user_name, width: '160px', value: ftp_user },
{ name: 'ftp_password', title: lan.public_backup.pass, width: '160px', value: bt.get_random(16) },
],
ps_help: lan.public_backup.ftp_tips,
};
var _tr = bt.render_form_line(item);
obj.parents('div.line').append('
' + _tr.html + '
');
}
},
},
],
},
{
title: lan.public_backup.db,
items: [
{
name: 'sql',
type: 'select',
items: [
{ value: 'false', title: lan.public_backup.dont_create },
{ value: 'MySQL', title: 'MySQL' },
{ value: 'SQLServer', title: 'SQLServer' },
],
callback: function (obj) {
var subid = obj.attr('name') + '_subid';
$('#' + subid).remove();
if (obj.val() != 'false') {
if (bt.os == 'Linux' && obj.val() == 'SQLServer') {
obj.val('false');
bt.msg({ msg: lan.public_backup.unsupport_sqlserver, icon: 2 });
return;
}
var _bs = obj.parents('div.bt-form').attr('data-id');
var data_user = $('textarea[name="webname"]').data('database');
var item = {
title: lan.public_backup.db_set,
class: 'pb0',
name: 'sql_tips',
items: [
{ name: 'datauser', title: lan.public_backup.user_name, width: '160px', value: data_user },
{ name: 'datapassword', title: lan.public_backup.pass, width: '160px', value: bt.get_random(16) },
],
ps_help: lan.public_backup.create_site_tips,
};
var _tr = bt.render_form_line(item);
obj.parents('div.line').append('
' + _tr.html + '
');
}
},
},
{
name: 'codeing',
type: 'select',
items: [
{ value: 'utf8', title: 'utf-8' },
{ value: 'utf8mb4', title: 'utf8mb4' },
{ value: 'gbk', title: 'gbk' },
{ value: 'big5', title: 'big5' },
],
},
],
},
{
title: 'Program type',
type: 'select',
name: 'type',
disabled: bt.contains(bt.get_cookie('serverType'), 'IIS') ? false : true,
items: [
{ value: 'PHP', title: 'PHP' },
{ value: 'Asp', title: 'Asp' },
{ value: 'Aspx', title: 'Aspx' },
],
callback: function (obj) {
if (obj.val() == 'Asp' || obj.val() == 'Aspx') {
obj.parents('div.line').next().hide();
} else {
obj.parents('div.line').next().show();
}
},
},
{
title: lan.public_backup.php_v,
name: 'version',
type: 'select',
items: [{ value: '00', title: lan.public_backup.sitic }],
},
{
title: lan.public_backup.site_classification,
name: 'type_id',
type: 'select',
width: 'auto',
items: [],
},
{
title: 'SSL',
class: 'ssl_checkbox',
items: [
{
type: 'checkbox',
name: 'set_ssl',
text: 'Apply for SSL',
callback: function (obj) {
if (!obj.set_ssl) {
$('[name="force_ssl"]').prop('checked', false);
}
},
},
{
type: 'checkbox',
name: 'force_ssl',
text: 'HTTP redirect to HTTPS',
callback: function (obj) {
if (obj.force_ssl) {
$('[name="set_ssl"]').prop('checked', true);
}
},
},
{
type: 'html',
html: '
- If you need to apply for SSL, please make sure that the domain name has added A record resolution for the domain name
',
},
],
},
],
btns: [
{ title: lan.public_backup.turn_off, name: 'close' },
{
title: lan.public_backup.submit,
name: 'submit',
css: 'btn-success',
callback: function (rdata, load, callback) {
var loading = bt.load();
if (!rdata.webname) {
bt.msg({ msg: lan.public_backup.domain_format_not_right, icon: 2 });
return;
}
var webname = bt.replace_all(rdata.webname, 'http:\\/\\/', '');
webname = bt.replace_all(webname, 'https:\\/\\/', '');
var arrs = webname.split('\n');
var list = [];
var domain_name, port;
for (var i = 0; i < arrs.length; i++) {
if (arrs[i]) {
var temp = arrs[i].split(':');
var item = {};
item['name'] = temp[0];
item['port'] = temp.length > 1 ? temp[1] : 80;
if (!bt.check_domain(item.name)) {
bt.msg({ msg: lan.site.domain_err_txt, icon: 2 });
return;
}
if (i > 0) {
list.push(arrs[i]);
} else {
domain_name = item.name;
port = item.port;
}
}
}
var domain = {};
domain['domain'] = domain_name;
domain['domainlist'] = list;
domain['count'] = list.length;
rdata.webname = JSON.stringify(domain);
rdata.port = port;
rdata.tourl = parseInt($('[name="tourl"]:checked').val());
if (rdata.redirect) {
if (rdata.tourl) {
var domains = $('#tourl_' + rdata.tourl)
.next()
.find('span');
rdata.redirect = $(domains[0]).text();
rdata.tourl = $(domains[1]).text();
} else {
delete rdata.redirect;
delete rdata.tourl;
}
} else {
delete rdata.redirect;
delete rdata.tourl;
}
rdata.set_ssl = rdata.set_ssl ? 1 : 0;
rdata.force_ssl = rdata.force_ssl ? 1 : 0;
bt.send('AddSite', 'site/AddSite', rdata, function (rRet) {
loading.close();
if (rRet.siteStatus) load.close();
if (callback) callback(rRet);
});
},
},
],
},
},
ftp: {
add: {
title: lan.ftp.add_title,
area: '530px',
list: [
{
title: lan.public_backup.user_name,
name: 'ftp_username',
callback: function (obj) {
var defaultPath = $('#defaultPath').text();
var wootPath = bt.rtrim(defaultPath, '/');
if (bt.contains($('input[name="path"]').val(), wootPath)) {
$('input[name="path"]').val(wootPath + '/' + obj.val());
}
},
},
{
title: lan.public_backup.pass,
name: 'ftp_password',
items: [
{
type: 'text',
width: '330px',
value: bt.get_random(16),
event: {
css: 'glyphicon-repeat',
callback: function (obj) {
bt.refresh_pwd(16, obj);
},
},
},
],
},
{
title: lan.public_backup.root_dir,
name: 'path',
items: [
{
type: 'text',
event: {
css: 'glyphicon-folder-open',
callback: function (obj) {
bt.select_path(obj);
},
},
},
],
},
],
btns: [
{ title: lan.public_backup.turn_off, name: 'close' },
{
title: lan.public_backup.submit,
name: 'submit',
css: 'btn-success',
callback: function (rdata, load, callback) {
var loading = bt.load();
if (!rdata.ps) rdata.ps = rdata.ftp_username;
bt.send('AddUser', 'ftp/AddUser', rdata, function (rRet) {
loading.close();
if (rRet.status) load.close();
if (callback) callback(rRet);
bt.msg(rRet);
});
},
},
],
},
set_port: {
title: lan.ftp.port_title,
skin: '',
area: '500px',
list: [{ title: lan.public_backup.default_port, name: 'port', width: '250px' }],
btns: [
{ title: lan.public_backup.turn_off, name: 'close' },
{
title: lan.public_backup.submit,
name: 'submit',
css: 'btn-success',
callback: function (rdata, load, callback) {
var loading = bt.load();
bt.send('setPort', 'ftp/setPort', rdata, function (rRet) {
loading.close();
if (rRet.status) load.close();
//if(callback) callback(rRet);
bt.msg(rRet);
});
},
},
],
},
set_password: {
title: lan.ftp.pass_title,
area: '530px',
list: [
{ title: 'id', name: 'id', hide: true },
{ title: lan.public_backup.user_name, name: 'ftp_username', disabled: true },
{
title: lan.public_backup.pass,
name: 'new_password',
items: [
{
type: 'text',
event: {
css: 'glyphicon-repeat',
callback: function (obj) {
bt.refresh_pwd(16, obj);
},
},
},
],
},
],
btns: [
{ title: lan.public_backup.turn_off, name: 'close' },
{
title: lan.public_backup.submit,
name: 'submit',
css: 'btn-success',
callback: function (rdata, load, callback) {
bt.confirm({ msg: lan.ftp.pass_confirm, title: lan.ftp.stop_title }, function () {
var loading = bt.load();
bt.send('SetUserPassword', 'ftp/SetUserPassword', rdata, function (rRet) {
loading.close();
if (rRet.status) load.close();
if (callback) callback(rRet);
bt.msg(rRet);
});
});
},
},
],
},
},
};
var form_group = {
select_all: function (_arry) {
for (var j = 0; j < _arry.length; j++) {
this.select(_arry[j]);
}
},
select: function (elem) {
$(elem).after(
'
'
);
var _html = '',
select_el = $(elem),
select_group = select_el.next(),
select_ul = select_group.find('.bt_select_ul'),
select_val = select_group.find('.select_val'),
select_icon = select_group.find('.glyphicon');
select_el.find('option').each(function (index, el) {
var active = select_el.val() === $(el).val(),
_val = $(el).val(),
_name = $(el).text();
_html += '
' + _name + '';
if (active) {
select_val.text(_name);
_val !== '' ? select_val.removeClass('default') : select_val.addClass('default');
}
});
select_el.hide();
select_ul.html(_html);
$(elem)
.next('.bt_select_group')
.find('.bt_select_active')
.unbind('click')
.click(function (e) {
if (!$(this).next().hasClass('active')) {
$(this)
.parents()
.find('li')
.siblings()
.find('.bt_select_ul.active')
.each(function () {
is_show_slect_parent(this);
});
$(this)
.parents('.rec-box')
.siblings()
.find('.bt_select_ul.active')
.each(function () {
is_show_slect_parent(this);
});
}
is_show_select_ul($(this).next().hasClass('active'));
$(document).click(function (ev) {
is_show_select_ul(true);
$(this).unbind('click');
ev.stopPropagation();
ev.preventDefault();
});
e.stopPropagation();
e.preventDefault();
});
$(elem)
.next('.bt_select_group')
.find('.bt_select_ul li')
.unbind('click')
.click(function () {
var _val = $(this).attr('data-val'),
_name = $(this).text();
$(this).addClass('active').siblings().removeClass('active');
_val !== '' ? select_val.removeClass('default') : select_val.addClass('default');
select_val.text(_name);
select_el.val(_val);
$(elem)
.find('option[value="' + _val + '"]')
.change();
is_show_select_ul(true);
});
function is_show_slect_parent(that) {
$(that).removeClass('active fadeInUp animated');
$(that).prev().find('.glyphicon').removeAttr('style');
$(that).parent().removeAttr('style');
}
function is_show_select_ul(active) {
if (active) {
select_group.removeAttr('style');
select_icon.css({ transform: 'rotate(0deg)' });
select_ul.removeClass('active fadeInUp animated');
} else {
select_group.css('borderColor', '#20a53a');
select_icon.css({ transform: 'rotate(180deg)' });
select_ul.addClass('active fadeInUp animated');
}
}
},
checkbox: function () {
$('input[type="checkbox"]').each(function (index, el) {
$(el).hide();
$(el).after('
');
});
$('.bt_checkbox_group').click(function () {
$(this).prev().click();
if ($(this).hasClass('active')) {
$(this).removeClass('active');
$(this).prev().removeAttr('checked');
} else {
$(this).addClass('active');
$(this).prev().attr('checked', 'checked');
}
});
},
};
bt.public = {
// 设置目录配额
modify_path_quota: function (data, callback) {
var loadT = bt.load(lan.public.modify_path_quota);
$.post('/project/quota/modify_path_quota', data, function (res) {
loadT.close();
if (callback) callback(res);
});
},
// 设置mysql配额
modify_mysql_quota: function (data, callback) {
var loadT = bt.load(lan.public.modify_mysql_quota);
$.post('/project/quota/modify_mysql_quota', data, function (res) {
loadT.close();
if (callback) callback(res);
});
},
/**
* @description 获取quoto容量
*/
get_quota_config: function (type) {
return {
fid: 'quota',
title: lan.public.capacity,
width: 120,
template: function (row, index) {
var quota = row.quota;
if (!quota.size) return '
' + lan.public.notConfigured + '';
var size = quota.size * 1024 * 1024;
var speed = ((quota.used / size) * 100).toFixed(2);
var quotaFull = false;
if (quota.size > 0 && quota.used >= size) quotaFull = true;
return (
'
'
);
},
event: function (row, index, ev) {
var quota = row.quota;
var size = quota.size * 1024 * 1024;
var usedList = bt.format_size(quota.used).split(' ');
var quotaFull = false;
if (quota.size > 0 && quota.used >= size) quotaFull = true;
var types = {
site: lan.site.website,
ftp: lan.site.add_site.ftp,
database: lan.site.database,
};
layer.open({
type: 1,
title: '[' + row.name + '] ' + types[type] + ' ' + lan.public.quotaCapacity,
area: '476px',
closeBtn: 2,
btn: [lan.public.save, lan.public.cancel],
content:
'
',
yes: function (indexs) {
var quota_size = $('[name="quota_size"]').val();
if (type === 'site' || type === 'ftp') {
bt.public.modify_path_quota({ data: JSON.stringify({ size: quota_size, path: row.path }) }, function (res) {
if (res.status) {
bt.msg(res);
layer.close(indexs);
setTimeout(function () {
location.reload();
}, 200);
} else {
layer.msg(res.msg, { icon: res.status ? 1 : 2, area: '650px', time: 0, shade: 0.3, closeBtn: 2 });
}
});
} else {
bt.public.modify_mysql_quota({ data: JSON.stringify({ size: quota_size, db_name: row.name }) }, function (res) {
bt.msg(res);
if (res.status) {
layer.close(indexs);
setTimeout(function () {
location.reload();
}, 200);
}
});
}
},
});
},
};
},
};
//设置面板SSL
function setPanelSSL() {
var loadT = layer.msg(lan.config.ssl_msg, { icon: 16, time: 0, shade: [0.3, '#000'] });
bt.send('get_cert_source', 'config/get_cert_source', {}, function (rdata) {
layer.close(loadT);
var sdata = rdata;
var _data = {
title: 'Panel SSL',
area: '630px',
class: 'ssl_cert_from',
list: [
{
html:
'
' +
lan.config.ssl_open_ps +
'
- ' +
lan.config.ssl_open_ps_1 +
'
- ' +
lan.config.ssl_open_ps_2 +
'
- ' +
lan.config.ssl_open_ps_3 +
'
',
},
{
title: 'Cert Type',
name: 'cert_type',
type: 'select',
width: '200px',
value: sdata.cert_type,
items: [
{ value: '1', title: 'Self-signed certificate' },
{ value: '2', title: "Let's Encrypt" },
],
callback: function (obj) {
var subid = obj.attr('name') + '_subid';
$('#' + subid).remove();
if (obj.val() == '2') {
var _tr = bt.render_form_line({
title: 'Admin E-Mail',
name: 'email',
width: '320px',
placeholder: 'Admin E-Mail',
value: sdata.email,
});
obj.parents('div.line').append('
' + _tr.html + '
');
}
},
},
{
html:
'
',
},
],
btns: [
{
title: 'Close',
name: 'close',
callback: function (rdata, load, callback) {
load.close();
$('#panelSSL').prop('checked', false);
},
},
{
title: 'Submit',
name: 'submit',
css: 'btn-success',
callback: function (rdata, load, callback) {
if (!$('#checkSSL').is(':checked')) {
bt.msg({ status: false, msg: 'Please confirm the risk first!' });
return;
}
var confirm = layer.confirm('Whether to open the panel SSL certificate', { title: 'Tips', btn: ['Confirm', 'Cancel'], icon: 0, closeBtn: 2 }, function () {
var loading = bt.load();
bt.send('SetPanelSSL', 'config/SetPanelSSL', rdata, function (rdata) {
loading.close();
if (rdata.status) {
layer.msg(rdata.msg, { icon: 1 });
$.get('/system?action=ReWeb', function () {});
setTimeout(function () {
window.location.href = (window.location.protocol.indexOf('https') != -1 ? 'http://' : 'https://') + window.location.host + window.location.pathname;
}, 1500);
} else {
layer.msg(rdata.msg, { icon: 2 });
}
});
});
},
},
],
end: function () {},
};
var _bs = bt.render_form(_data);
// setTimeout(function () {
// $('.cert_type' + _bs).trigger('change')
// }, 200);
});
}
var dynamic = {
loadList: [],
fileFunList: {},
load: false,
callback: null,
// 初始化执行
execution: function () {
for (var i = 0; i < this.loadList.length; i++) {
var fileName = this.loadList[i];
if (fileName in this.fileFunList) this.fileFunList[fileName]();
}
},
/**
* @description 动态加载js,css文件
* @param urls {string|array} 文件路径或文件数组
* @param fn {function|undefined} 回调函数
*/
require: function (urls, fn) {
if (!Array.isArray(urls)) urls = [urls];
this.fileFunList = {};
var i = 0;
var that = this;
var total = urls.length;
var callback = function () {
i++;
if (i < total) {
that.loadFile(urls[i], callback);
} else {
fn && fn();
}
};
this.loadFile(urls[i], callback);
},
/**
* @description 加载js,css文件
* @param {string} url 文件路径
* @param {function} fn 回调函数
*/
loadFile: function (url, fn) {
this.load = true;
var that = this;
var element = this.createElement(url);
if (element.readyState) {
element.onreadystatechange = function (ev) {
if (element.readyState === 'loaded' || element.readyState === 'complete') {
element.onreadystatechange = null;
that.execution();
fn && fn.call(that);
that.load = false;
}
};
} else {
element.onload = function (ev) {
that.execution();
fn && fn.call(that);
that.load = false;
};
}
document.getElementsByTagName('head')[0].appendChild(element);
},
/**
* @description 创建元素
* @param {string} url 文件路径
* @returns
*/
createElement: function (url) {
var element = null;
if (url.indexOf('.js?v=1715756461542') > -1) {
element = document.createElement('script');
element.type = 'text/javascript';
element.src = bt.url_merge('/vue/' + url);
} else if (url.indexOf('.css?v=1715756461542') > -1) {
element = document.createElement('link');
element.rel = 'stylesheet';
element.href = bt.url_merge('/vue/' + url);
}
return element;
},
/**
* @default 执行延迟文件内容执行
* @param fileName {string} 文件名称,不要加文件后缀
* @param callback {function} 回调行数
*/
delay: function delay(fileName, callback) {
if (!this.load) {
callback();
return false;
}
this.fileFunList[fileName] = callback;
},
};
// 过滤编码
bt.htmlEncode = {
/**
* @description 正则转换特殊字符
* @param {string} layid 字符内容
*/
htmlEncodeByRegExp: function (str) {
if (typeof str == 'undefined' || str.length == 0) return '';
return str
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/ /g, ' ')
.replace(/\'/g, ''')
.replace(/\"/g, '"')
.replace(/\(/g, '(')
.replace(/\)/g, ')')
.replace(/`/g, '`')
.replace(/=/g, '=');
},
};