pull/109/head
Mr Chen 6 years ago
parent 7b1ce60307
commit c97a40efbb
  1. 4
      plugins/gogs/index.html
  2. 39
      plugins/gogs/index.py
  3. 2
      plugins/gogs/info.json
  4. 98
      plugins/gogs/js/gogs.js

@ -4,7 +4,8 @@
<p class="bgw" onclick="pluginService('gogs');">服务</p> <p class="bgw" onclick="pluginService('gogs');">服务</p>
<p onclick="pluginInitD('gogs');">自启动</p> <p onclick="pluginInitD('gogs');">自启动</p>
<p onclick="pluginConfig('gogs',null, 'init_conf');">自启动配置</p> <p onclick="pluginConfig('gogs',null, 'init_conf');">自启动配置</p>
<p onclick="pluginConfig('gogs',null, 'conf');">运行配置</p> <p onclick="pluginConfig('gogs',null, 'conf');">配置文件</p>
<p onclick="gogsSetConfig();">配置修改</p>
<p onclick="pluginLogs('gogs',null,'run_log');">运行日志</p> <p onclick="pluginLogs('gogs',null,'run_log');">运行日志</p>
</div> </div>
<div class="bt-w-con pd15"> <div class="bt-w-con pd15">
@ -13,5 +14,6 @@
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$.getScript( "/plugins/file?name=gogs&f=js/gogs.js");
pluginService('gogs'); pluginService('gogs');
</script> </script>

@ -4,6 +4,7 @@
import time import time
import os import os
import sys import sys
import re
sys.path.append("/usr/local/lib/python2.7/site-packages") sys.path.append("/usr/local/lib/python2.7/site-packages")
import psutil import psutil
@ -200,6 +201,40 @@ def runLog():
log_path = getServerDir() + '/log/gogs.log' log_path = getServerDir() + '/log/gogs.log'
return log_path return log_path
def getGogsConf():
gets = [
{'name': 'HOST', 'type': -1, 'ps': '主机地址'},
{'name': 'NAME', 'type': -1, 'ps': '数据库名称'},
{'name': 'USER', 'type': -1, 'ps': '数据库用户名'},
{'name': 'REQUIRE_SIGNIN_VIEW', 'type': 2, 'ps': '强制登录浏览'},
]
conf = public.readFile(getConf())
result = []
for g in gets:
rep = g['name'] + '\s*=\s*(.*)'
tmp = re.search(rep, conf)
if not tmp:
continue
g['value'] = tmp.groups()[0]
result.append(g)
return public.getJson(result)
def submitGogsConf():
gets = ['REQUIRE_SIGNIN_VIEW']
args = getArgs()
# print args
filename = getConf()
conf = public.readFile(filename)
for g in gets:
if g in args:
rep = g + '\s*=\s*(.*)'
val = g + ' = ' + args[g] + '\n'
conf = re.sub(rep, val, conf)
public.writeFile(filename, conf)
return public.returnJson(True, '设置成功')
if __name__ == "__main__": if __name__ == "__main__":
func = sys.argv[1] func = sys.argv[1]
if func == 'status': if func == 'status':
@ -224,5 +259,9 @@ if __name__ == "__main__":
print getConf() print getConf()
elif func == 'init_conf': elif func == 'init_conf':
print getInitdConf() print getInitdConf()
elif func == 'get_gogs_conf':
print getGogsConf()
elif func == 'submit_gogs_conf':
print submitGogsConf()
else: else:
print 'fail' print 'fail'

@ -2,7 +2,7 @@
"ps": "Gogs是一款极易搭建的自助Git服务", "ps": "Gogs是一款极易搭建的自助Git服务",
"name": "gogs", "name": "gogs",
"title": "Gogs", "title": "Gogs",
"versions": ["0.11.79","0.11.66"], "versions": ["0.11.86","0.11.79"],
"tip": "soft", "tip": "soft",
"checks": "server/gogs", "checks": "server/gogs",
"author": "midoks", "author": "midoks",

@ -0,0 +1,98 @@
function str2Obj(str){
var data = {};
kv = str.split('&');
for(i in kv){
v = kv[i].split('=');
data[v[0]] = v[1];
}
return data;
}
function gogsPost(method,args,callback, title){
var _args = null;
if (typeof(args) == 'string'){
_args = JSON.stringify(str2Obj(args));
} else {
_args = JSON.stringify(args);
}
var _title = '正在获取...';
if (typeof(title) != 'undefined'){
_title = title;
}
var loadT = layer.msg(_title, { icon: 16, time: 0, shade: 0.3 });
$.post('/plugins/run', {name:'gogs', func:method, args:_args}, function(data) {
layer.close(loadT);
if (!data.status){
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
return;
}
if(typeof(callback) == 'function'){
callback(data);
}
},'json');
}
function gogsSetConfig(){
gogsPost('get_gogs_conf', '', function(data){
console.log(data);
var rdata = $.parseJSON(data.data);
console.log(rdata);
var mlist = '';
for (var i = 0; i < rdata.length; i++) {
var w = '140';
if (rdata[i].name == 'error_reporting') w = '250';
var ibody = '<input style="width: ' + w + 'px;" class="bt-input-text mr5" name="' + rdata[i].name + '" value="' + rdata[i].value + '" type="text" >';
switch (rdata[i].type) {
case 0:
var selected_1 = (rdata[i].value == 1) ? 'selected' : '';
var selected_0 = (rdata[i].value == 0) ? 'selected' : '';
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\
<option value="1" ' + selected_1 + '>开启</option>\
<option value="0" ' + selected_0 + '>关闭</option>\
</select>';
break;
case 1:
var selected_1 = (rdata[i].value == 'On') ? 'selected' : '';
var selected_0 = (rdata[i].value == 'Off') ? 'selected' : '';
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\
<option value="On" ' + selected_1 + '>开启</option>\
<option value="Off" ' + selected_0 + '>关闭</option></select>'
break;
case 2:
var selected_1 = (rdata[i].value == 'true') ? 'selected' : '';
var selected_0 = (rdata[i].value == 'false') ? 'selected' : '';
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\
<option value="true" ' + selected_1 + '>开启</option>\
<option value="false" ' + selected_0 + '>关闭</option></select>'
break;
}
mlist += '<p><span>' + rdata[i].name + '</span>' + ibody + ', <font>' + rdata[i].ps + '</font></p>'
}
var html = '<style>.conf_p p{margin-bottom: 2px}</style><div class="conf_p" style="margin-bottom:0">\
' + mlist + '\
<div style="margin-top:10px; padding-right:15px" class="text-right">\
<button class="btn btn-success btn-sm mr5" onclick="gogsSetConfig()">刷新</button>\
<button class="btn btn-success btn-sm" onclick="submitGogsConf()">保存</button></div>\
</div>';
$(".soft-man-con").html(html);
});
}
//提交PHP配置
function submitGogsConf() {
var data = {
REQUIRE_SIGNIN_VIEW: $("select[name='REQUIRE_SIGNIN_VIEW']").val() || 'false',
};
gogsPost('submit_gogs_conf', data, function(ret_data){
var rdata = $.parseJSON(ret_data.data);
console.log(rdata);
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
});
}
Loading…
Cancel
Save