gitea update

pull/494/head
midoks 2 years ago
parent 3a33a4c758
commit 24d3aeabb0
  1. 14
      plugins/gitea/hook/self_hook.tpl
  2. 3
      plugins/gitea/index.html
  3. 394
      plugins/gitea/index.py
  4. 401
      plugins/gitea/js/gitea.js

@ -0,0 +1,14 @@
#!/bin/bash
H_DIR={$HOOK_DIR}
HL_DIR={$HOOK_LOGS_DIR}
SH_LIST=`cd ${H_DIR} && ls | grep ".sh$"`
for sh_f in $SH_LIST; do
ABS_FILE=${H_DIR}/${sh_f}
ABS_LOGS=${HL_DIR}/${sh_f}.log
echo "sh ${ABS_FILE} 2>${ABS_LOGS}"
sh -x ${ABS_FILE} 2>${ABS_LOGS}
done

@ -3,11 +3,11 @@
<div class="bt-w-menu"> <div class="bt-w-menu">
<p class="bgw" onclick="pluginService('gitea');">服务</p> <p class="bgw" onclick="pluginService('gitea');">服务</p>
<p onclick="pluginInitD('gitea');">自启动</p> <p onclick="pluginInitD('gitea');">自启动</p>
<!-- <p onclick="pluginConfig('gitea',null, 'init_conf');">启动配置</p> -->
<p onclick="gogsEdit();">手动编辑</p> <p onclick="gogsEdit();">手动编辑</p>
<p onclick="pluginConfig('gitea',null, 'conf');">配置文件</p> <p onclick="pluginConfig('gitea',null, 'conf');">配置文件</p>
<p onclick="gogsSetConfig();">配置修改</p> <p onclick="gogsSetConfig();">配置修改</p>
<p onclick="giteaUserList();">用户列表</p> <p onclick="giteaUserList();">用户列表</p>
<p onclick="giteaRepoList();">项目列表</p>
<!-- <p onclick="pluginLogs('gitea',null,'run_log');">运行日志</p> --> <!-- <p onclick="pluginLogs('gitea',null,'run_log');">运行日志</p> -->
<!-- <p onclick="pluginLogs('gitea',null,'post_receive_log');" title="提交post-receive日志">提交日志</p> --> <!-- <p onclick="pluginLogs('gitea',null,'post_receive_log');" title="提交post-receive日志">提交日志</p> -->
<p onclick="giteaRead();">使用说明</p> <p onclick="giteaRead();">使用说明</p>
@ -18,6 +18,7 @@
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
resetPluginWinHeight(530);
$.getScript( "/plugins/file?name=gitea&f=js/gitea.js",function(){ $.getScript( "/plugins/file?name=gitea&f=js/gitea.js",function(){
pluginService('gitea'); pluginService('gitea');
}); });

@ -453,6 +453,13 @@ def submitGogsConf():
return mw.returnJson(True, '设置成功') return mw.returnJson(True, '设置成功')
def gogsEditTpl():
data = {}
data['post_receive'] = getPluginDir() + '/hook/post-receive.tpl'
data['commit'] = getPluginDir() + '/hook/commit.tpl'
return mw.getJson(data)
def userList(): def userList():
conf = getConf() conf = getConf()
@ -473,23 +480,81 @@ def userList():
page = int(args['page']) page = int(args['page'])
page_size = int(args['page_size']) page_size = int(args['page_size'])
tojs = args['tojs']
search = '' search = ''
if 'search' in args: if 'search' in args:
search = args['search'] search = args['search']
user_where1 = ''
user_where2 = ''
if search != '':
user_where1 = ' where name like "%' + search + '%"'
user_where2 = ' where name like "%' + search + '%"'
data = {} data = {}
data['root_url'] = getRootUrl() data['root_url'] = getRootUrl()
start = (page - 1) * page_size start = (page - 1) * page_size
list_count = pQuery('select count(id) as num from user') list_count = pQuery('select count(id) as num from user' + user_where1)
count = list_count[0]["num"] count = list_count[0]["num"]
list_data = pQuery( list_data = pQuery(
'select id,name,email from user order by id desc limit ' + str(start) + ',' + str(page_size)) 'select id,name,email from user ' + user_where2 + ' order by id desc limit ' + str(start) + ',' + str(page_size))
data['list'] = mw.getPage( data['list'] = mw.getPage({'count': count, 'p': page,
{'count': count, 'p': page, 'row': page_size, 'tojs': tojs}) 'row': page_size, 'tojs': 'gogsUserList'})
data['page'] = page
data['page_size'] = page_size
data['page_count'] = int(math.ceil(count / page_size))
data['data'] = list_data
return mw.returnJson(True, 'OK', data)
def repoList():
conf = getConf()
if not os.path.exists(conf):
return mw.returnJson(False, "请先安装初始化!<br/>默认地址:http://" + mw.getLocalIp() + ":3000")
conf = getDbConfValue()
gtype = getGogsDbType(conf)
if gtype != 'mysql':
return mw.returnJson(False, "仅支持mysql数据操作!")
import math
args = getArgs()
data = checkArgs(args, ['page', 'page_size'])
if not data[0]:
return data[1]
page = int(args['page'])
page_size = int(args['page_size'])
search = ''
if 'search' in args:
search = args['search']
data = {}
data['root_url'] = getRootUrl()
repo_where1 = ''
repo_where2 = ''
if search != '':
repo_where1 = ' where name like "%' + search + '%"'
repo_where2 = ' where r.name like "%' + search + '%"'
start = (page - 1) * page_size
list_count = pQuery(
'select count(id) as num from repository' + repo_where1)
count = list_count[0]["num"]
sql = 'select r.id,r.owner_id,r.name as repo, u.name from repository r left join user u on r.owner_id=u.id ' + repo_where2 + ' order by r.id desc limit ' + \
str(start) + ',' + str(page_size)
# print(sql)
list_data = pQuery(sql)
# print(list_data)
list_data = checkRepoListIsHasScript(list_data)
data['list'] = mw.getPage({'count': count, 'p': page,
'row': page_size, 'tojs': 'gogsRepoListPage'})
data['page'] = page data['page'] = page
data['page_size'] = page_size data['page_size'] = page_size
data['page_count'] = int(math.ceil(count / page_size)) data['page_count'] = int(math.ceil(count / page_size))
@ -670,11 +735,294 @@ def projectScriptDebug():
return mw.getJson(data) return mw.getJson(data)
def gogsEdit(): def projectScriptRun():
data = {} args = getArgs()
data['post_receive'] = getPluginDir() + '/hook/post-receive.tpl' data = checkArgs(args, ['user', 'name'])
data['commit'] = getPluginDir() + '/hook/commit.tpl' if not data[0]:
return mw.getJson(data) return data[1]
user = args['user']
name = args['name'] + '.git'
path = getRootPath() + '/' + user + '/' + name
commit_sh = path + '/custom_hooks/commit'
commit_log = path + '/custom_hooks/sh.log'
script_run = 'sh -x ' + commit_sh + ' 2>' + commit_log
if not os.path.exists(commit_sh):
return mw.returnJson(False, '脚本文件不存在!')
mw.execShell(script_run)
return mw.returnJson(True, '脚本文件执行成功,观察日志!')
def projectScriptSelf():
args = getArgs()
data = checkArgs(args, ['user', 'name'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
custom_hooks = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks'
self_path = custom_hooks + '/self'
if not os.path.exists(self_path):
os.mkdir(self_path)
self_logs_path = custom_hooks + '/self_logs'
if not os.path.exists(self_logs_path):
os.mkdir(self_logs_path)
self_hook_file = custom_hooks + '/self_hook.sh'
self_hook_exist = False
if os.path.exists(self_hook_file):
self_hook_exist = True
dlist = []
if os.path.exists(self_path):
for filename in os.listdir(self_path):
tmp = {}
filePath = self_path + '/' + filename
if os.path.isfile(filePath):
tmp['path'] = filePath
tmp['name'] = os.path.basename(filePath)
tmp['is_hidden'] = False
if tmp['name'].endswith('.txt'):
tmp['is_hidden'] = True
dlist.append(tmp)
dlist_sum = len(dlist)
# print(dlist)
rdata = {}
rdata['data'] = dlist
rdata['self_hook'] = self_hook_exist
rdata['list'] = mw.getPage(
{'count': dlist_sum, 'p': 1, 'row': 100, 'tojs': 'self_page'})
return mw.returnJson(True, 'ok', rdata)
def projectScriptSelf_Create():
args = getArgs()
data = checkArgs(args, ['user', 'name', 'file'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
file = args['file']
self_path = path = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks/self'
if not os.path.exists(self_path):
os.mkdir(self_path)
abs_file = self_path + '/' + file + '.sh'
if os.path.exists(abs_file):
return mw.returnJson(False, '脚本已经存在!')
mw.writeFile(abs_file, "#!/bin/bash\necho `date +'%Y-%m-%d %H:%M:%S'`\n")
rdata = {}
rdata['abs_file'] = abs_file
return mw.returnJson(True, '创建文件成功!', rdata)
def projectScriptSelf_Del():
args = getArgs()
data = checkArgs(args, ['user', 'name', 'file'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
file = args['file']
custom_hooks = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks'
self_path = custom_hooks + '/self'
if not os.path.exists(self_path):
os.mkdir(self_path)
abs_file = self_path + '/' + file
# print(abs_file)
if not os.path.exists(abs_file):
return mw.returnJson(False, '脚本已经删除!')
os.remove(abs_file)
# 日志也删除
log_file = custom_hooks + '/self_logs/' + file + '.log'
if os.path.exists(log_file):
os.remove(log_file)
return mw.returnJson(True, '脚本删除成功!')
def projectScriptSelf_Logs():
args = getArgs()
data = checkArgs(args, ['user', 'name', 'file'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
file = args['file']
self_path = path = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks/self_logs'
if not os.path.exists(self_path):
os.mkdir(self_path)
logs_file = self_path + '/' + file + '.log'
if os.path.exists(logs_file):
rdata = {}
rdata['path'] = logs_file
return mw.returnJson(True, 'ok', rdata)
return mw.returnJson(False, '日志不存在!')
def projectScriptSelf_Run():
args = getArgs()
data = checkArgs(args, ['user', 'name', 'file'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
file = args['file']
custom_hooks = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks'
self_path = custom_hooks + '/self/' + file
self_logs_path = custom_hooks + '/self_logs/' + file + '.log'
shell = "sh -x " + self_path + " 2>" + self_logs_path
mw.execShell(shell)
return mw.returnJson(True, '执行成功!')
def projectScriptSelf_Rename():
args = getArgs()
data = checkArgs(args, ['user', 'name', 'o_file', 'n_file'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
o_file = args['o_file']
n_file = args['n_file']
custom_hooks = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks'
self_path = custom_hooks + '/self'
if not os.path.exists(self_path):
os.mkdir(self_path)
o_file_abs = self_path + '/' + o_file + '.sh'
if not os.path.exists(o_file_abs):
return mw.returnJson(False, '原文件已经不存在了!')
n_file_abs = self_path + '/' + n_file + '.sh'
os.rename(o_file_abs, n_file_abs)
# 日志也删除
log_file = custom_hooks + '/self_logs/' + o_file + '.sh.log'
if os.path.exists(log_file):
os.remove(log_file)
return mw.returnJson(True, '重命名成功!')
def projectScriptSelf_Enable():
args = getArgs()
data = checkArgs(args, ['user', 'name', 'enable'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
enable = args['enable']
custom_path = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks'
# 替换commit配置
commit_path = custom_path + '/commit'
note = '#Gogs Script Don`t Remove and Change'
self_file = custom_path + '/self_hook.sh'
self_hook_tpl = getPluginDir() + '/hook/self_hook.tpl'
if enable == '1':
content = mw.readFile(self_hook_tpl)
content = content.replace('{$HOOK_DIR}', custom_path + '/self')
content = content.replace(
'{$HOOK_LOGS_DIR}', custom_path + '/self_logs')
mw.writeFile(self_file, content)
mw.execShell("chmod 777 " + self_file)
commit_content = mw.readFile(commit_path)
commit_content += "\n\n" + "bash " + self_file + " " + note
mw.writeFile(commit_path, commit_content)
return mw.returnJson(True, '开启成功!')
else:
commit_content = mw.readFile(commit_path)
rep = ".*" + note
commit_content = re.sub(rep, '', commit_content, re.M)
commit_content = commit_content.strip()
mw.writeFile(commit_path, commit_content)
if os.path.exists(self_file):
os.remove(self_file)
return mw.returnJson(True, '关闭成功!')
def projectScriptSelf_Status():
args = getArgs()
data = checkArgs(args, ['user', 'name', 'file', 'status'])
if not data[0]:
return data[1]
user = args['user']
name = args['name'] + '.git'
file = args['file']
status = args['status']
custom_hooks = getRootPath() + '/' + user + '/' + \
name + '/custom_hooks'
self_path = custom_hooks + '/self'
if not os.path.exists(self_path):
os.mkdir(self_path)
# 日志也删除
log_file = custom_hooks + '/self_logs/' + file + '.log'
if os.path.exists(log_file):
os.remove(log_file)
if status == '1':
file_abs = self_path + '/' + file
file_text_abs = self_path + '/' + file + '.txt'
os.rename(file_abs, file_text_abs)
return mw.returnJson(True, '开始禁用成功!')
else:
file_abs = self_path + '/' + file.strip('.txt')
file_text_abs = self_path + '/' + file
os.rename(file_text_abs, file_abs)
return mw.returnJson(True, '开始使用成功!')
return mw.returnJson(True, '禁用成功!')
def getRsaPublic(): def getRsaPublic():
@ -745,8 +1093,12 @@ if __name__ == "__main__":
print(getGogsConf()) print(getGogsConf())
elif func == 'submit_gogs_conf': elif func == 'submit_gogs_conf':
print(submitGogsConf()) print(submitGogsConf())
elif func == 'gogs_edit_tpl':
print(gogsEditTpl())
elif func == 'user_list': elif func == 'user_list':
print(userList()) print(userList())
elif func == 'repo_list':
print(repoList())
elif func == 'user_project_list': elif func == 'user_project_list':
print(userProjectList()) print(userProjectList())
elif func == 'project_script_edit': elif func == 'project_script_edit':
@ -757,8 +1109,24 @@ if __name__ == "__main__":
print(projectScriptUnload()) print(projectScriptUnload())
elif func == 'project_script_debug': elif func == 'project_script_debug':
print(projectScriptDebug()) print(projectScriptDebug())
elif func == 'gogs_edit': elif func == 'project_script_run':
print(gogsEdit()) print(projectScriptRun())
elif func == 'project_script_self':
print(projectScriptSelf())
elif func == 'project_script_self_create':
print(projectScriptSelf_Create())
elif func == 'project_script_self_del':
print(projectScriptSelf_Del())
elif func == 'project_script_self_logs':
print(projectScriptSelf_Logs())
elif func == 'project_script_self_run':
print(projectScriptSelf_Run())
elif func == 'project_script_self_rename':
print(projectScriptSelf_Rename())
elif func == 'project_script_self_enable':
print(projectScriptSelf_Enable())
elif func == 'project_script_self_status':
print(projectScriptSelf_Status())
elif func == 'get_rsa_public': elif func == 'get_rsa_public':
print(getRsaPublic()) print(getRsaPublic())
elif func == 'get_total_statistics': elif func == 'get_total_statistics':

@ -336,6 +336,403 @@ function projectScriptDebug(user,name,index){
}); });
} }
function gogsRepoListPage(page, search){
var _data = {};
if (typeof(page) =='undefined'){
var page = 1;
}
_data['page'] = page;
_data['page_size'] = 10;
if(typeof(search) != 'undefined'){
_data['search'] = search;
}
gogsPost('repo_list', _data, function(data){
var rdata = $.parseJSON(data.data);
if (!rdata.status){
layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']});
return;
}
var ulist = rdata['data']['data'];
var body = ''
for (i in ulist){
// console.log(ulist[i]);
var option = '';
if(ulist[i]['has_hook']){
option += '<a class="btlink unload" data-index="'+i+'">卸载脚本</a>' + ' | ';
option += '<a class="btlink load" data-index="'+i+'">重载</a>' + ' | ';
option += '<a class="btlink edit" data-index="'+i+'">编辑</a>' + ' | ';
option += '<a class="btlink debug" data-index="'+i+'">日志</a>' + ' | ';
option += '<a class="btlink run" data-index="'+i+'">手动</a>' + ' | ';
option += '<a class="btlink scripts" data-index="'+i+'" onclick="projectScriptSelf(\''+ulist[i]["name"]+'\',\''+ulist[i]["repo"]+'\')" >自定义</a>';
} else{
option += '<a data-index="'+i+'" class="btlink load">加载脚本</a>';
}
body += '<tr><td>'+ulist[i]["id"]+'</td>'+
'<td class="overflow_hide" style="width:70px;">' + ulist[i]["name"]+'</td>'+
'<td class="overflow_hide" style="width:70px;display: inline-block;">' + ulist[i]["repo"]+'</td>'+
'<td>' +
'<a class="btlink" target="_blank" href="'+rdata['data']['root_url']+ulist[i]["name"]+'/'+ulist[i]["repo"]+'">源码</a>' + ' | ' +
option +
'</td>' +
'</tr>';
}
$('#repo_list tbody').html(body);
$('#repo_list_page').html(rdata['data']['list']);
$('.find_repo').click(function(){
var find_repo = $('#find_repo').val();
gogsRepoListPage(page, find_repo);
});
$('#repo_list .load').click(function(){
var i = $(this).data('index');
var user = ulist[i]["name"];
var name = ulist[i]["repo"];
gogsPost('project_script_load', {'user':user,'name':name}, function(data){
if (data.data != 'ok'){
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
return;
}
layer.msg('加载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
setTimeout(function(){
gogsRepoListPage(page, search);
}, 2000);
});
});
$('#repo_list .unload').click(function(){
var i = $(this).data('index');
var user = ulist[i]["name"];
var name = ulist[i]["repo"];
gogsPost('project_script_unload', {'user':user,'name':name}, function(data){
if (data.data != 'ok'){
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
return;
}
layer.msg('卸载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
setTimeout(function(){
gogsRepoListPage(page, search);
}, 2000);
});
});
$('#repo_list .edit').click(function(){
var i = $(this).data('index');
var user = ulist[i]["name"];
var name = ulist[i]["repo"];
gogsPost('project_script_edit', {'user':user,'name':name}, function(data){
var rdata = $.parseJSON(data.data);
if (rdata['status']){
onlineEditFile(0, rdata['data']['path']);
} else {
layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']});
}
});
});
$('#repo_list .debug').click(function(){
var i = $(this).data('index');
var user = ulist[i]["name"];
var name = ulist[i]["repo"];
gogsPost('project_script_debug', {'user':user,'name':name}, function(data){
var rdata = $.parseJSON(data.data);
if (rdata['status']){
onlineEditFile(0, rdata['path']);
} else {
layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']});
}
});
});
$('#repo_list .run').click(function(){
var i = $(this).data('index');
var user = ulist[i]["name"];
var name = ulist[i]["repo"];
gogsPost('project_script_run', {'user':user,'name':name}, function(data){
var data = $.parseJSON(data.data);
layer.msg(data.msg,{icon:data.status?1:2,time:2000,shade: [0.3, '#000']});
});
});
//---------
});
}
function giteaRepoList() {
content = '<div class="finduser"><input class="bt-input-text mr5 outline_no" type="text" placeholder="查找项目" id="find_repo" style="height: 28px; border-radius: 3px;width: 435px;">';
content += '<button class="btn btn-success btn-sm find_repo">查找</button></div>';
content += '<div id="repo_list" class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
content += '<thead><tr>';
content += '<th style="width:50px;">序号</th>';
content += '<th style="width:80px;">用户/组织</th>';
content += '<th style="width:80px;">项目名</th>';
content += '<th>操作</th>';
content += '</tr></thead>';
content += '<tbody></tbody>';
content += '</table></div>';
var page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="repo_list_page" class="page"></ul></div>';
content += page;
$(".soft-man-con").html(content);
gogsRepoListPage(1);
}
function projectScriptSelfRender(user, name){
gogsPost('project_script_self', {'user':user,'name':name}, function(data){
var rdata = $.parseJSON(data.data);
var data = rdata['data']['data'];
if (rdata['data']['self_hook']){
$('#open_script').prop('checked',true);
}
var body = '';
if(data.length == 0 ){
body += '<tr><td colspan="3" style="text-align:center;">无脚本数据</td></tr>';
} else{
for (var i = 0; i < data.length; i++) {
var b_status = '<a class="btlink status" data-index="'+i+'" target="_blank">已使用</a>';
if (data[i]["is_hidden"]){
b_status = '<a class="btlink status" data-index="'+i+'" target="_blank">已隐藏</a>';
}
body += '<tr>'+
'<td>' + data[i]["name"]+'</td>'+
'<td>' + b_status + '</td>'+
'<td>' +
'<a class="btlink del" data-index="'+i+'" target="_blank">删除</a>' + ' | ' +
'<a class="btlink edit" data-index="'+i+'" target="_blank">编辑</a>' + ' | ' +
'<a class="btlink logs" data-index="'+i+'" target="_blank">日志</a>' + ' | ' +
'<a class="btlink run" data-index="'+i+'" target="_blank">手动</a>' + ' | ' +
'<a class="btlink rename" data-index="'+i+'" target="_blank">重命名</a>' +
'</td></tr>';
}
}
$('#gogs_self_table tbody').html(body);
$('#gogs_self_table .page').html(rdata['data']['list']);
$('#gogs_self_table .status').click(function(){
var i = $(this).data('index');
var file = data[i]["name"];
var status = '1';
if (data[i]["is_hidden"]){
status = '0';
}
gogsPost('project_script_self_status', {'user':user,'name':name,'file':file, status:status}, function(data){
var data = $.parseJSON(data.data);
showMsg(data.msg ,function(){
projectScriptSelfRender(user, name);
},{icon:data.code?2:1,time:2000,shade: [0.3, '#000']},2000);
});
});
$('#gogs_self_table .del').click(function(){
var i = $(this).data('index');
var file = data[i]["name"];
gogsPost('project_script_self_del', {'user':user,'name':name,'file':file}, function(data){
var data = $.parseJSON(data.data);
showMsg(data.msg ,function(){
projectScriptSelfRender(user, name);
},{icon:data.code?2:1,time:2000,shade: [0.3, '#000']},2000);
});
});
$('#gogs_self_table .edit').click(function(){
var i = $(this).data('index');
var path = data[i]["path"];
onlineEditFile(0,path);
});
$('#gogs_self_table .logs').click(function(){
var i = $(this).data('index');
var file = data[i]["name"];
gogsPost('project_script_self_logs', {'user':user,'name':name,'file':file}, function(data){
var rdata = $.parseJSON(data.data);
// console.log(rdata);
if (rdata['status']){
onlineEditFile(0, rdata['data']['path']);
} else {
layer.msg(rdata.msg,{icon:data.status?2:1,time:2000,shade: [0.3, '#000']});
}
});
});
$('#gogs_self_table .run').click(function(){
var i = $(this).data('index');
var file = data[i]["name"];
if (data[i]["is_hidden"]){
layer.msg("已经禁用,不能执行!",{icon:2,time:2000,shade: [0.3, '#000']});
return;
}
gogsPost('project_script_self_run', {'user':user,'name':name,'file':file}, function(data){
var rdata = $.parseJSON(data.data);
layer.msg(rdata.msg,{icon:data.status?1:2,time:2000,shade: [0.3, '#000']});
});
});
$('#gogs_self_table .rename').click(function(){
var i = $(this).data('index');
var file = data[i]["name"];
if (data[i]["is_hidden"]){
layer.msg("已经禁用,不能执行!",{icon:2,time:2000,shade: [0.3, '#000']});
return;
}
file = file.split('.sh')[0];
layer.open({
type: 1,
shift: 5,
closeBtn: 1,
area: '320px',
title: '重命名',
btn:['设置','关闭'],
content: '<div class="bt-form pd20">\
<div class="line">\
<input type="text" class="bt-input-text" name="Name" id="newFileName" value="'+file+'" placeholder="文件名" style="width:100%" />\
</div>\
</div>',
success:function(){
$("#newFileName").focus().keyup(function(e){
if(e.keyCode == 13) $(".layui-layer-btn0").click();
});
},
yes:function(){
var n_file = $("#newFileName").val();
var o_file = file;
gogsPost('project_script_self_rename', {'user':user,'name':name,'o_file':o_file,'n_file':n_file}, function(data){
var data = $.parseJSON(data.data);
showMsg(data.msg ,function(){
$(".layui-layer-btn1").click();
projectScriptSelfRender(user, name);
},{icon:data.code?2:1,time:2000,shade: [0.3, '#000']},2000);
});
}
});
//-----
});
//------
});
}
//新建文件
function createScriptFile(type, user, name, file) {
if (type == 1) {
gogsPost('project_script_self_create', {'user':user,'name':name,'file': file }, function(data){
var rdata = $.parseJSON(data.data);
if(!rdata['status']){
layer.msg(rdata.msg,{icon:2,time:2000,shade: [0.3, '#000']});
return;
}
showMsg(rdata.msg, function(){
$(".layui-layer-btn1").click();
onlineEditFile(0,rdata['data']['abs_file']);
projectScriptSelfRender(user, name);
}, {icon:1,shade: [0.3, '#000']},2000);
});
return;
}
layer.open({
type: 1,
shift: 5,
closeBtn: 1,
area: '320px',
title: '新建自定义脚本',
btn:['新建','关闭'],
content: '<div class="bt-form pd20">\
<div class="line">\
<input type="text" class="bt-input-text" name="Name" id="newFileName" value="" placeholder="文件名" style="width:100%" />\
</div>\
</div>',
success:function(){
$("#newFileName").focus().keyup(function(e){
if(e.keyCode == 13) $(".layui-layer-btn0").click();
});
},
yes:function(){
var file = $("#newFileName").val();;
createScriptFile(1, user, name, file);
}
});
}
function projectScriptSelf(user, name){
layer.open({
type: 1,
title: '项目('+user+'/'+name+')自定义脚本',
area: '500px',
content:"<div class='bt-form pd15'>\
<button id='create_script' class='btn btn-success btn-sm' type='button' style='margin-right: 5px;''>添加脚本</button>\
<div style='float:right;'>\
<span style='line-height: 23px;'>开启自定义脚本</span>\
<input class='btswitch btswitch-ios' id='open_script' type='checkbox'>\
<label id='script_hook_enable' class='btswitch-btn' for='open_script' style='display: inline-flex;line-height:38px;margin-left: 4px;float: right;'></label>\
</div>\
<div id='gogs_self_table' class='divtable' style='margin-top:5px;'>\
<table class='table table-hover'>\
<thead><tr><th style='width:100px;'>脚本文件名</th><th></th><th></th></tr></thead>\
<tbody></tbody>\
</table>\
<div class='dataTables_paginate paging_bootstrap pagination' style='margin-top:0px;'>\
<ul class='page'><div class='gogs_page'></div></ul>\
</div>\
</div>\
</div>",
success:function(){
projectScriptSelfRender(user, name);
$('#create_script').click(function(){
createScriptFile(0, user, name);
});
$('#script_hook_enable').click(function(){
var enable = $('#open_script').prop('checked');
var enable_option = '0';
if (!enable){
enable_option = '1';
}
gogsPost('project_script_self_enable', {'user':user,'name':name,'enable':enable_option}, function(data){
var data = $.parseJSON(data.data);
showMsg(data.msg ,function(){
projectScriptSelfRender(user, name);
},{icon:data.status?1:2,shade: [0.3, '#000']},2000);
});
});
}
});
}
function getRsaPublic(){ function getRsaPublic(){
gogsPost('get_rsa_public', {}, function(data){ gogsPost('get_rsa_public', {}, function(data){
var rdata = $.parseJSON(data.data); var rdata = $.parseJSON(data.data);
@ -361,8 +758,8 @@ function giteaRead(){
var readme = '<ul class="help-info-text c7">'; var readme = '<ul class="help-info-text c7">';
readme += '<li>默认使用MySQL,第一个启动加载各种配置,并修改成正确的数据库配置</li>'; readme += '<li>默认使用MySQL,第一个启动加载各种配置,并修改成正确的数据库配置</li>';
readme += '<li>邮件端口使用456,gogs仅支持使用STARTTLS的SMTP协议</li>'; readme += '<li>邮件端口使用456,gitea仅支持使用STARTTLS的SMTP协议</li>';
readme += '<li>如果使用项目中脚本本地同步,<a target="_blank" href="https://github.com/midoks/mdserver-web/wiki/%E6%8F%92%E4%BB%B6%E7%AE%A1%E7%90%86%5Bgogs%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%5D#%E5%90%AF%E5%8A%A8gogs%E5%90%8E%E5%A6%82%E6%9E%9C%E8%A6%81%E4%BD%BF%E7%94%A8hook%E8%84%9A%E6%9C%AC%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E9%9C%80%E8%A6%81%E5%BC%80%E5%90%AFssh%E7%AB%AF%E5%8F%A3">点击查看</></li>'; readme += '<li>项目【加载脚本】后,会自动同步到wwwroot目录下</li>';
readme += '<li><a href="#" onclick="getRsaPublic();">点击查看本机公钥</></li>'; readme += '<li><a href="#" onclick="getRsaPublic();">点击查看本机公钥</></li>';
readme += '</ul>'; readme += '</ul>';

Loading…
Cancel
Save