gogs base ok
This commit is contained in:
parent
8efc7d040a
commit
1ff1844bd9
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
GITADDR="{$GITROOTURL}{$USERNAME}/{$PROJECT}"
|
||||
GIT_SDIR="{$CODE_DIR}"
|
||||
|
||||
GIT_USER_DIR="${GIT_SDIR}/{$USERNAME}"
|
||||
GIT_PROJECT_DIR="${GIT_USER_DIR}/{$PROJECT}"
|
||||
|
||||
# echo $GIT_PROJECT_DIR
|
||||
if [ ! -d $GIT_USER_DIR ];then
|
||||
mkdir -p $GIT_USER_DIR && cd $GIT_USER_DIR
|
||||
git clone $GIT_PROJECT_DIR
|
||||
exit 0
|
||||
fi
|
||||
|
||||
unset GIT_DIR
|
||||
cd $GIT_PROJECT_DIR && git pull
|
||||
|
||||
# func 2
|
||||
# cd $GIT_PROJECT_DIR && env -i git pull origin master
|
||||
|
||||
|
||||
|
||||
WEB_PATH={$WEB_ROOT}/{$USERNAME}/{$PROJECT}
|
||||
mkdir -p $WEB_PATH
|
||||
|
||||
rsync -vauP --delete --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
|
||||
sysName=`uname`
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
USER=$(who | sed -n "2,1p" |awk '{print $1}')
|
||||
chown -R $USER:staff $WEB_PATH
|
||||
else
|
||||
chown -R www:www $WEB_PATH
|
||||
fi
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
sh -x {$PATH}/commit 2>{$PATH}/sh.log
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
<p onclick="gogsSetConfig();">配置修改</p>
|
||||
<p onclick="gogsUserList();">用户列表</p>
|
||||
<p onclick="pluginLogs('gogs',null,'run_log');">运行日志</p>
|
||||
<p onclick="pluginLogs('gogs',null,'post_receive_log');" title="提交post-receive日志">提交日志</p>
|
||||
<p onclick="gogsRead();">使用说明</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
|
|
|
|||
|
|
@ -132,6 +132,24 @@ def initDreplace():
|
|||
return file_bin
|
||||
|
||||
|
||||
def getRootUrl():
|
||||
content = public.readFile(getConf())
|
||||
rep = 'ROOT_URL\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
if not tmp:
|
||||
return ''
|
||||
return tmp.groups()[0]
|
||||
|
||||
|
||||
def getRootPath():
|
||||
content = public.readFile(getConf())
|
||||
rep = 'ROOT\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
if not tmp:
|
||||
return ''
|
||||
return tmp.groups()[0]
|
||||
|
||||
|
||||
def getDbConfValue():
|
||||
content = public.readFile(getConf())
|
||||
|
||||
|
|
@ -273,6 +291,11 @@ def runLog():
|
|||
return log_path
|
||||
|
||||
|
||||
def postReceiveLog():
|
||||
log_path = getServerDir() + '/log/hooks/post-receive.log'
|
||||
return log_path
|
||||
|
||||
|
||||
def getGogsConf():
|
||||
gets = [
|
||||
{'name': 'DOMAIN', 'type': -1, 'ps': '服务器域名'},
|
||||
|
|
@ -308,11 +331,19 @@ def getGogsConf():
|
|||
|
||||
|
||||
def submitGogsConf():
|
||||
gets = ['DOMAIN', 'ROOT_URL', 'HTTP_ADDR',
|
||||
'HTTP_PORT', 'START_SSH_SERVER', 'SSH_PORT',
|
||||
'REQUIRE_SIGNIN_VIEW', 'FORCE_PRIVATE',
|
||||
'ENABLE_CAPTCHA', 'DISABLE_REGISTRATION', 'ENABLE_NOTIFY_MAIL',
|
||||
'SHOW_FOOTER_BRANDING', 'SHOW_FOOTER_VERSION',
|
||||
gets = ['DOMAIN',
|
||||
'ROOT_URL',
|
||||
'HTTP_ADDR',
|
||||
'HTTP_PORT',
|
||||
'START_SSH_SERVER',
|
||||
'SSH_PORT',
|
||||
'REQUIRE_SIGNIN_VIEW',
|
||||
'FORCE_PRIVATE',
|
||||
'ENABLE_CAPTCHA',
|
||||
'DISABLE_REGISTRATION',
|
||||
'ENABLE_NOTIFY_MAIL',
|
||||
'SHOW_FOOTER_BRANDING',
|
||||
'SHOW_FOOTER_VERSION',
|
||||
'SHOW_FOOTER_TEMPLATE_LOAD_TIME']
|
||||
args = getArgs()
|
||||
filename = getConf()
|
||||
|
|
@ -328,7 +359,9 @@ def submitGogsConf():
|
|||
|
||||
|
||||
def userList():
|
||||
import math
|
||||
args = getArgs()
|
||||
|
||||
page = 1
|
||||
page_size = 10
|
||||
search = ''
|
||||
|
|
@ -341,8 +374,197 @@ def userList():
|
|||
if 'search' in args:
|
||||
search = args['search']
|
||||
|
||||
return public.returnJson(True, '设置成功')
|
||||
data = {}
|
||||
|
||||
data['root_url'] = getRootUrl()
|
||||
|
||||
pm = pMysqlDb()
|
||||
start = (page - 1) * page_size
|
||||
list_count = pm.query('select count(id) as num from user')
|
||||
count = list_count[0][0]
|
||||
|
||||
list_data = pm.query(
|
||||
'select id,name,email from user order by id desc limit ' + str(start) + ',' + str(page_size))
|
||||
|
||||
page_info = {'count': count, 'p': page,
|
||||
'row': page_size, 'tojs': 'gogsUserList'}
|
||||
data['list'] = public.getPage(page_info)
|
||||
data['page'] = page
|
||||
data['page_size'] = page_size
|
||||
data['page_count'] = int(math.ceil(count / page_size))
|
||||
data['data'] = list_data
|
||||
return public.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def getAllUserProject(user, search=''):
|
||||
path = getRootPath() + '/' + user
|
||||
dlist = []
|
||||
if os.path.exists(path):
|
||||
for filename in os.listdir(path):
|
||||
tmp = {}
|
||||
filePath = path + '/' + filename
|
||||
if os.path.isdir(filePath):
|
||||
if search == '':
|
||||
tmp['name'] = filename.replace('.git', '')
|
||||
dlist.append(tmp)
|
||||
else:
|
||||
if filename.find(search) != -1:
|
||||
tmp['name'] = filename.replace('.git', '')
|
||||
dlist.append(tmp)
|
||||
return dlist
|
||||
|
||||
|
||||
def checkProjectListIsHasScript(user, data):
|
||||
path = getRootPath() + '/' + user
|
||||
for x in range(len(data)):
|
||||
name = data[x]['name'] + '.git'
|
||||
path_tmp = path + '/' + name + '/custom_hooks/post-receive'
|
||||
if os.path.exists(path_tmp):
|
||||
data[x]['has_hook'] = True
|
||||
else:
|
||||
data[x]['has_hook'] = False
|
||||
return data
|
||||
|
||||
|
||||
def userProjectList():
|
||||
import math
|
||||
args = getArgs()
|
||||
# print args
|
||||
|
||||
page = 1
|
||||
page_size = 5
|
||||
search = ''
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(False, '缺少参数name')
|
||||
if 'page' in args:
|
||||
page = int(args['page'])
|
||||
|
||||
if 'page_size' in args:
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
if 'search' in args:
|
||||
search = args['search']
|
||||
|
||||
data = {}
|
||||
|
||||
ulist = getAllUserProject(args['name'])
|
||||
dlist_sum = len(ulist)
|
||||
|
||||
start = (page - 1) * page_size
|
||||
ret_data = ulist[start:start + page_size]
|
||||
ret_data = checkProjectListIsHasScript(args['name'], ret_data)
|
||||
|
||||
data['root_url'] = getRootUrl()
|
||||
data['data'] = ret_data
|
||||
data['args'] = args
|
||||
data['list'] = public.getPage(
|
||||
{'count': dlist_sum, 'p': page, 'row': page_size, 'tojs': 'userProjectList'})
|
||||
|
||||
return public.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def projectScriptEdit():
|
||||
args = getArgs()
|
||||
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
post_receive = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/post-receive'
|
||||
if os.path.exists(post_receive):
|
||||
return public.returnJson(True, 'OK', {'path': post_receive})
|
||||
else:
|
||||
return public.returnJson(False, 'file does not exist')
|
||||
|
||||
|
||||
def projectScriptLoad():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
|
||||
path = getRootPath() + '/' + user + '/' + name
|
||||
post_receive_tpl = getPluginDir() + '/hook/post-receive.tpl'
|
||||
post_receive = path + '/custom_hooks/post-receive'
|
||||
|
||||
if not os.path.exists(path + '/custom_hooks'):
|
||||
public.execShell('mkdir -p ' + path + '/custom_hooks')
|
||||
|
||||
pct_content = public.readFile(post_receive_tpl)
|
||||
pct_content = pct_content.replace('{$PATH}', path + '/custom_hooks')
|
||||
public.writeFile(post_receive, pct_content)
|
||||
public.execShell('chmod 777 ' + post_receive)
|
||||
|
||||
commit_tpl = getPluginDir() + '/hook/commit.tpl'
|
||||
commit = path + '/custom_hooks/commit'
|
||||
|
||||
codeDir = public.getRootDir() + '/git'
|
||||
|
||||
cc_content = public.readFile(commit_tpl)
|
||||
cc_content = cc_content.replace('{$GITROOTURL}', getRootUrl())
|
||||
cc_content = cc_content.replace('{$CODE_DIR}', codeDir)
|
||||
cc_content = cc_content.replace('{$USERNAME}', user)
|
||||
cc_content = cc_content.replace('{$PROJECT}', args['name'])
|
||||
cc_content = cc_content.replace('{$WEB_ROOT}', public.getWwwDir())
|
||||
public.writeFile(commit, cc_content)
|
||||
public.execShell('chmod 777 ' + commit)
|
||||
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectScriptUnload():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
|
||||
post_receive = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/post-receive'
|
||||
public.execShell('rm -f ' + post_receive)
|
||||
|
||||
commit = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/commit'
|
||||
public.execShell('rm -f ' + commit)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectScriptDebug():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
commit_log = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/sh.log'
|
||||
|
||||
data = {}
|
||||
if os.path.exists(commit_log):
|
||||
data['status'] = True
|
||||
data['path'] = commit_log
|
||||
else:
|
||||
data['status'] = False
|
||||
data['msg'] = '没有日志文件'
|
||||
|
||||
return public.getJson(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
|
|
@ -364,6 +586,8 @@ if __name__ == "__main__":
|
|||
print initdUinstall()
|
||||
elif func == 'run_log':
|
||||
print runLog()
|
||||
elif func == 'post_receive_log':
|
||||
print postReceiveLog()
|
||||
elif func == 'conf':
|
||||
print getConf()
|
||||
elif func == 'init_conf':
|
||||
|
|
@ -374,5 +598,15 @@ if __name__ == "__main__":
|
|||
print submitGogsConf()
|
||||
elif func == 'user_list':
|
||||
print userList()
|
||||
elif func == 'user_project_list':
|
||||
print userProjectList()
|
||||
elif func == 'project_script_edit':
|
||||
print projectScriptEdit()
|
||||
elif func == 'project_script_load':
|
||||
print projectScriptLoad()
|
||||
elif func == 'project_script_unload':
|
||||
print projectScriptUnload()
|
||||
elif func == 'project_script_debug':
|
||||
print projectScriptDebug()
|
||||
else:
|
||||
print 'fail'
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ function gogsPost(method,args,callback, title){
|
|||
|
||||
function gogsSetConfig(){
|
||||
gogsPost('get_gogs_conf', '', function(data){
|
||||
console.log(data);
|
||||
// console.log(data);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
console.log(rdata);
|
||||
// console.log(rdata);
|
||||
var mlist = '';
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
var w = '140';
|
||||
|
|
@ -134,24 +134,29 @@ function gogsUserList(page, search) {
|
|||
|
||||
content += '<div class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
|
||||
content += '<thead><tr>';
|
||||
content += '<th>用户名</th>';
|
||||
content += '<th>操作(<a class="btlink" onclick="csvnAddUser();">管理</a>)</th>';
|
||||
content += '<th>序号</th>';
|
||||
content += '<th>用户或组织</th>';
|
||||
content += '<th>邮件地址</th>';
|
||||
content += '<th>操作(<a href="'+rdata['data']['root_url']+'" class="btlink" target="_blank">WEB管理</a>)</th>';
|
||||
content += '</tr></thead>';
|
||||
|
||||
content += '<tbody>';
|
||||
|
||||
ulist = rdata.data;
|
||||
ulist = rdata['data']['data'];
|
||||
for (i in ulist){
|
||||
content += '<tr><td>'+ulist[i]+'</td><td>'+
|
||||
'<a class="btlink" onclick="csvnDelUser(\''+ulist[i]+'\')">删除</a> | ' +
|
||||
'<a class="btlink" onclick="csvnModPwdUser(\''+ulist[i]+'\')">改密</a></td></tr>';
|
||||
email = ulist[i][2] == '' ? '无' : ulist[i][2];
|
||||
content += '<tr><td>'+ulist[i][0]+'</td>'+
|
||||
'<td>'+ulist[i][1]+'</td>'+
|
||||
'<td>'+email+'</td>'+
|
||||
'<td><a class="btlink" onclick="userProjectList(\''+ulist[i][1]+'\')">项目管理</a></td>'+
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
content += '</tbody>';
|
||||
content += '</table></div>';
|
||||
|
||||
page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata.list;
|
||||
var page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata['data']['list'];
|
||||
page += '</div></ul></div>';
|
||||
|
||||
content += page;
|
||||
|
|
@ -160,6 +165,139 @@ function gogsUserList(page, search) {
|
|||
});
|
||||
}
|
||||
|
||||
function userProjectList(user, search){
|
||||
var req = {};
|
||||
if (!isNaN(user)){
|
||||
req['page'] = user;
|
||||
req['name'] = user = getCookie('gogsUserSelected');
|
||||
} else {
|
||||
req['page'] = 1;
|
||||
req['name'] = user;
|
||||
setCookie('gogsUserSelected', user);
|
||||
}
|
||||
|
||||
req['page_size'] = 5;
|
||||
req['search'] = '';
|
||||
if(typeof(search) != 'undefined'){
|
||||
req['search'] = search;
|
||||
}
|
||||
|
||||
$('.layui-layer-close1').click();
|
||||
gogsPost('user_project_list', req, function(data){
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
} catch(e){}
|
||||
|
||||
if (!rdata['status']){
|
||||
layer.msg(rdata['msg'], { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
var list = '';
|
||||
// console.log(rdata);
|
||||
var project_list = rdata['data']['data'];
|
||||
for (i in project_list) {
|
||||
var name = project_list[i]['name'];
|
||||
list += '<tr><td>'+name+'</td>\
|
||||
<td>\
|
||||
<a class="btlink" target="_blank" href="'+rdata['data']['root_url']+user+'/'+name+'">源码</a> | \
|
||||
<a class="btlink" onclick="projectScript(\''+user+'\',\''+name+'\','+project_list[i]['has_hook']+');">脚本</a>\
|
||||
</td>\
|
||||
</tr>';
|
||||
}
|
||||
|
||||
var page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata['data']['list'];
|
||||
page += '</div></ul></div>';
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '用户('+user+')项目列表',
|
||||
area: '300px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div>\
|
||||
<div class='divtable' style='margin-top:5px;'>\
|
||||
<table class='table table-hover'>\
|
||||
<thead><tr><th>项目</th><th>操作</th></tr></thead>\
|
||||
<tbody>" + list + "</tbody>\
|
||||
</table>" +
|
||||
page +
|
||||
"</div></div></div>"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function projectScript(user, name,has_hook){
|
||||
// console.log(user,name,has_hook);
|
||||
var html = '';
|
||||
if (has_hook){
|
||||
html += '<button onclick="projectScriptEdit(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">手动编辑</button>';
|
||||
html += '<button onclick="projectScriptDebug(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">调试日志</button>';
|
||||
html += '<button onclick="projectScriptLoad(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">重新加载</button>';
|
||||
html += '<button onclick="projectScriptUnload(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">卸载脚本</button>';
|
||||
} else {
|
||||
html += '<button onclick="projectScriptLoad(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">加载脚本</button>';
|
||||
}
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '['+user+']['+name+']脚本设置',
|
||||
area: '240px',
|
||||
content:'<div class="change-default pd20">'+html+'</div>'
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptEdit(user,name){
|
||||
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']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptLoad(user,name){
|
||||
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(){
|
||||
userProjectList(1);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptUnload(user,name){
|
||||
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(){
|
||||
userProjectList(1);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptDebug(user,name){
|
||||
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']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function gogsRead(){
|
||||
var readme = '<p>* 默认使用MySQL,第一个启动加载各种配置,并修改成正确的数据库配置</p>';
|
||||
|
|
|
|||
Loading…
Reference in New Issue