diff --git a/plugins/gitea/hook/commit.tpl b/plugins/gitea/hook/commit.tpl new file mode 100755 index 000000000..7070accf5 --- /dev/null +++ b/plugins/gitea/hook/commit.tpl @@ -0,0 +1,39 @@ +#!/bin/bash + +echo `date` + +GITADDR="{$GITROOTURL}/{$USERNAME}/{$PROJECT}.git" +GIT_SDIR="{$CODE_DIR}" + +GIT_USER_DIR="${GIT_SDIR}/{$USERNAME}" +GIT_PROJECT_DIR="${GIT_USER_DIR}/{$PROJECT}" + + +git config --global credential.helper store + +# echo $GIT_PROJECT_DIR +if [ ! -d $GIT_PROJECT_DIR ];then + mkdir -p $GIT_USER_DIR && cd $GIT_USER_DIR + git clone $GITADDR +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 \ No newline at end of file diff --git a/plugins/gitea/hook/commit.tpl.ssh b/plugins/gitea/hook/commit.tpl.ssh new file mode 100755 index 000000000..6aac78ca8 --- /dev/null +++ b/plugins/gitea/hook/commit.tpl.ssh @@ -0,0 +1,36 @@ +#!/bin/bash + +echo `date` + +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_PROJECT_DIR ];then + mkdir -p $GIT_USER_DIR && cd $GIT_USER_DIR + git clone $GITADDR +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 \ No newline at end of file diff --git a/plugins/gitea/hook/post-receive.tpl b/plugins/gitea/hook/post-receive.tpl new file mode 100755 index 000000000..0c747ce2f --- /dev/null +++ b/plugins/gitea/hook/post-receive.tpl @@ -0,0 +1,3 @@ +#!/bin/bash + +sh -x {$PATH}/commit 2>{$PATH}/sh.log \ No newline at end of file diff --git a/plugins/gitea/ico.png b/plugins/gitea/ico.png new file mode 100644 index 000000000..5dacd7735 Binary files /dev/null and b/plugins/gitea/ico.png differ diff --git a/plugins/gitea/index.html b/plugins/gitea/index.html new file mode 100755 index 000000000..8d9fe51d4 --- /dev/null +++ b/plugins/gitea/index.html @@ -0,0 +1,24 @@ +
+
+
+

服务

+

自启动

+ +

手动编辑

+

配置文件

+

配置修改

+

用户列表

+

运行日志

+

提交日志

+

使用说明

+
+
+
+
+
+
+ \ No newline at end of file diff --git a/plugins/gogs/bak/index_2022_6_19.py b/plugins/gitea/index.py similarity index 74% rename from plugins/gogs/bak/index_2022_6_19.py rename to plugins/gitea/index.py index 9bfc0b2a7..c01ca1f94 100755 --- a/plugins/gogs/bak/index_2022_6_19.py +++ b/plugins/gitea/index.py @@ -11,11 +11,10 @@ sys.path.append(os.getcwd() + "/class/core") import mw -cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' -info = mw.execShell(cmd) -p = "/usr/local/lib/" + info[0].strip() + "/site-packages" -sys.path.append(p) -import psutil +# cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' +# info = mw.execShell(cmd) +# p = "/usr/local/lib/" + info[0].strip() + "/site-packages" +# sys.path.append(p) app_debug = False @@ -24,15 +23,12 @@ if mw.isAppleSystem(): def getPluginName(): - return 'gogs' + return 'gitea' def getPluginDir(): return mw.getPluginDir() + '/' + getPluginName() -sys.path.append(getPluginDir() + "/class") -import mysqlDb - def getServerDir(): return mw.getServerDir() + '/' + getPluginName() @@ -61,18 +57,28 @@ def getArgs(): return tmp +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, mw.returnJson(True, 'ok')) + + def getInitdConfTpl(): - path = getPluginDir() + "/init.d/gogs.tpl" + path = getPluginDir() + "/init.d/gitea.tpl" return path def getInitdConf(): - path = getServerDir() + "/init.d/gogs" + path = getServerDir() + "/init.d/gitea" return path def getConf(): path = getServerDir() + "/custom/conf/app.ini" + + if not os.path.exists(path): + return mw.returnJson(False, "请先安装初始化!
默认地址:http://" + mw.getLocalIp() + ":3000") return path @@ -140,13 +146,16 @@ def initDreplace(): mw.writeFile(file_bin, content) mw.execShell('chmod +x ' + file_bin) - conf_bin = getConf() - if not os.path.exists(conf_bin): - mw.execShell('mkdir -p ' + getServerDir() + '/custom/conf') - conf_tpl = getConfTpl() - content = mw.readFile(conf_tpl) - content = contentReplace(content) - mw.writeFile(conf_bin, content) + # systemd + systemDir = mw.systemdCfgDir() + systemService = systemDir + '/gitea.service' + systemServiceTpl = getPluginDir() + '/init.d/gitea.service.tpl' + if os.path.exists(systemDir) and not os.path.exists(systemService): + service_path = mw.getServerDir() + se_content = mw.readFile(systemServiceTpl) + se_content = se_content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(systemService, se_content) + mw.execShell('systemctl daemon-reload') log_path = getServerDir() + '/log' if not os.path.exists(log_path): @@ -159,9 +168,14 @@ def getRootUrl(): content = mw.readFile(getConf()) rep = 'ROOT_URL\s*=\s*(.*)' tmp = re.search(rep, content) - if not tmp: - return '' - return tmp.groups()[0] + if tmp: + return tmp.groups()[0] + + rep = 'EXTERNAL_URL\s*=\s*(.*)' + tmp = re.search(rep, content) + if tmp: + return tmp.groups()[0] + return '' def getSshPort(): @@ -192,8 +206,11 @@ def getRootPath(): def getDbConfValue(): - content = mw.readFile(getConf()) + conf = getConf() + if not os.path.exists(conf): + return {} + content = mw.readFile(conf) rep_scope = "\[database\](.*?)\[" tmp = re.findall(rep_scope, content, re.S) @@ -207,18 +224,72 @@ def getDbConfValue(): return r -def pMysqlDb(): - conf = getDbConfValue() - +def pMysqlDb(conf): host = conf['HOST'].split(':') - conn = mysqlDb.mysqlDb() + # pymysql + db = mw.getMyORM() + # MySQLdb | + # db = mw.getMyORMDb() + + db.setPort(int(host[1])) + db.setUser(conf['USER']) + + if 'PASSWD' in conf: + db.setPwd(conf['PASSWD']) + else: + db.setPwd(conf['PASSWORD']) + + db.setDbName(conf['NAME']) + # db.setSocket(getSocketFile()) + db.setCharset("utf8") + return db + + +def pSqliteDb(conf): + # print(conf) + import db + psDb = db.Sql() + + # 默认 + gsdir = getServerDir() + '/data' + dbname = 'gitea' + if conf['PATH'][0] == '/': + # 绝对路径 + pass + else: + path = conf['PATH'].split('/') + gsdir = getServerDir() + '/' + path[0] + dbname = path[1].split('.')[0] - conn.setHost(host[0]) - conn.setUser(conf['USER']) - conn.setPwd(conf['PASSWD']) - conn.setPort(int(host[1])) - conn.setDb(conf['NAME']) - return conn + # print(gsdir, dbname) + psDb.dbPos(gsdir, dbname) + return psDb + + +def getGiteaDbType(conf): + + if 'DB_TYPE' in conf: + return conf['DB_TYPE'] + + if 'TYPE' in conf: + return conf['TYPE'] + + return 'NONE' + + +def pQuery(sql): + conf = getDbConfValue() + gtype = getGiteaDbType(conf) + if gtype == 'sqlite3': + db = pSqliteDb(conf) + data = db.query(sql, []).fetchall() + return data + elif gtype == 'mysql': + db = pMysqlDb(conf) + return db.query(sql) + + print("仅支持mysql|sqlite3配置") + exit(0) def isSqlError(mysqlMsg): @@ -244,93 +315,66 @@ def isSqlError(mysqlMsg): return mw.returnData(True, 'OK') -def start(): - - is_frist = True - conf_bin = getConf() - if os.path.exists(conf_bin): - is_frist = False - +def appOp(method): file = initDreplace() - if is_frist: - return "第一次启动Gogs,默认使用MySQL连接!
可以在配置文件中重新设置,再启动!" - - conn = pMysqlDb() - list_table = conn.query('show tables') - data = isSqlError(list_table) - if not data['status']: - return data['msg'] + if not mw.isAppleSystem(): + data = mw.execShell('systemctl ' + method + ' gogs') + if data[1] == '': + return 'ok' + return 'fail' - data = mw.execShell(__SR + file + ' start') + data = mw.execShell(__SR + file + ' ' + method) if data[1] == '': return 'ok' return data[0] +def start(): + return appOp('start') + + def stop(): - file = initDreplace() - data = mw.execShell(__SR + file + ' stop') - if data[1] == '': - return 'ok' - return data[1] + return appOp('stop') def restart(): - file = initDreplace() - data = mw.execShell(__SR + file + ' restart') - if data[1] == '': - return 'ok' - return data[1] + return appOp('restart') def reload(): - file = initDreplace() - data = mw.execShell(__SR + file + ' reload') - if data[1] == '': - return 'ok' - return data[1] + return appOp('reload') def initdStatus(): - if not app_debug: - os_name = mw.getOs() - if os_name == 'darwin': - return "Apple Computer does not support" - initd_bin = getInitDFile() - if os.path.exists(initd_bin): - return 'ok' - return 'fail' + if mw.isAppleSystem(): + return "Apple Computer does not support" + + shell_cmd = 'systemctl status gitea | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' def initdInstall(): - import shutil - if not app_debug: - os_name = mw.getOs() - if os_name == 'darwin': - return "Apple Computer does not support" - - mem_bin = initDreplace() - initd_bin = getInitDFile() - shutil.copyfile(mem_bin, initd_bin) - mw.execShell('chmod +x ' + initd_bin) - mw.execShell('chkconfig --add ' + getPluginName()) + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl enable gitea') return 'ok' def initdUinstall(): - if not app_debug: - os_name = mw.getOs() - if os_name == 'darwin': - return "Apple Computer does not support" - initd_bin = getInitDFile() - os.remove(initd_bin) - mw.execShell('chkconfig --del ' + getPluginName()) + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl disable gitea') return 'ok' def runLog(): - log_path = getServerDir() + '/log/gogs.log' + log_path = getServerDir() + '/log/gitea.log' return log_path @@ -340,6 +384,10 @@ def postReceiveLog(): def getGogsConf(): + conf = getConf() + if not os.path.exists(conf): + return mw.returnJson(False, "请先安装初始化!
默认地址:http://" + mw.getLocalIp() + ":3000") + gets = [ {'name': 'DOMAIN', 'type': -1, 'ps': '服务器域名'}, {'name': 'ROOT_URL', 'type': -1, 'ps': '公开的完整URL路径'}, @@ -360,7 +408,7 @@ def getGogsConf(): {'name': 'SHOW_FOOTER_VERSION', 'type': 2, 'ps': 'Gogs版本信息'}, {'name': 'SHOW_FOOTER_TEMPLATE_LOAD_TIME', 'type': 2, 'ps': 'Gogs模板加载时间'}, ] - conf = mw.readFile(getConf()) + conf = mw.readFile(conf) result = [] for g in gets: @@ -370,7 +418,7 @@ def getGogsConf(): continue g['value'] = tmp.groups()[0] result.append(g) - return mw.getJson(result) + return mw.returnJson(True, 'OK', result) def submitGogsConf(): @@ -402,18 +450,27 @@ def submitGogsConf(): def userList(): + + conf = getConf() + if not os.path.exists(conf): + return mw.returnJson(False, "请先安装初始化!
默认地址:http://" + mw.getLocalIp() + ":3000") + + conf = getDbConfValue() + gtype = getGiteaDbType(conf) + if gtype != 'mysql': + return mw.returnJson(False, "仅支持mysql数据操作!") + import math args = getArgs() - page = 1 - page_size = 10 - search = '' - if 'page' in args: - page = int(args['page']) - - if 'page_size' in args: - page_size = int(args['page_size']) + data = checkArgs(args, ['page', 'page_size']) + if not data[0]: + return data[1] + page = int(args['page']) + page_size = int(args['page_size']) + tojs = args['tojs'] + search = '' if 'search' in args: search = args['search'] @@ -421,17 +478,14 @@ def userList(): 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_count = pQuery('select count(id) as num from user') - list_data = pm.query( + count = list_count[0]["num"] + list_data = pQuery( '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'] = mw.getPage(page_info) + data['list'] = mw.getPage( + {'count': count, 'p': page, 'row': page_size, 'tojs': tojs}) data['page'] = page data['page_size'] = page_size data['page_count'] = int(math.ceil(count / page_size)) @@ -556,8 +610,8 @@ def projectScriptLoad(): cc_content = mw.readFile(commit_tpl) - sshUrl = 'http://127.0.0.1:' + getHttpPort() - cc_content = cc_content.replace('{$GITROOTURL}', sshUrl) + gitPath = getRootPath() + cc_content = cc_content.replace('{$GITROOTURL}', gitPath) cc_content = cc_content.replace('{$CODE_DIR}', codeDir) cc_content = cc_content.replace('{$USERNAME}', user) cc_content = cc_content.replace('{$PROJECT}', args['name']) @@ -570,11 +624,9 @@ def projectScriptLoad(): def projectScriptUnload(): args = getArgs() - if not 'user' in args: - return mw.returnJson(True, 'username missing') - - if not 'name' in args: - return mw.returnJson(True, 'project name missing') + data = checkArgs(args, ['user', 'name']) + if not data[0]: + return data[1] user = args['user'] name = args['name'] + '.git' @@ -591,11 +643,10 @@ def projectScriptUnload(): def projectScriptDebug(): args = getArgs() - if not 'user' in args: - return mw.returnJson(True, 'username missing') + data = checkArgs(args, ['user', 'name']) + if not data[0]: + return data[1] - if not 'name' in args: - return mw.returnJson(True, 'project name missing') user = args['user'] name = args['name'] + '.git' commit_log = getRootPath() + '/' + user + '/' + name + \ @@ -634,14 +685,8 @@ def getTotalStatistics(): st = status() data = {} if st.strip() == 'start': - pm = pMysqlDb() - list_count = pm.query('select count(id) as num from repository') - - if list_count.find("error") > -1: - data['status'] = False - data['count'] = 0 - return mw.returnJson(False, 'fail', data) - + list_count = pQuery('select count(id) as num from repository') + count = list_count[0]["num"] data['status'] = True data['count'] = count data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip() diff --git a/plugins/gitea/info.json b/plugins/gitea/info.json new file mode 100755 index 000000000..2eac70638 --- /dev/null +++ b/plugins/gitea/info.json @@ -0,0 +1,16 @@ +{ + "ps": "Gitea 是一个开源社区驱动的轻量级代码托管解决方案。", + "name": "gitea", + "title": "Gitea", + "versions": ["1.17.2"], + "tip": "soft", + "checks": "server/gitea", + "path":"server/gitea", + "author": "gitea", + "date": "2022-10-03", + "home": "https://dl.gitea.io/", + "type": "Git服务器", + "shell": "install.sh", + "pid": "3", + "sort": 7 +} \ No newline at end of file diff --git a/plugins/gitea/init.d/gitea.service.tpl b/plugins/gitea/init.d/gitea.service.tpl new file mode 100644 index 000000000..62f37d069 --- /dev/null +++ b/plugins/gitea/init.d/gitea.service.tpl @@ -0,0 +1,12 @@ +[Unit] +Description=Gogs +After=network.target + +[Service] +Type=forking +ExecStart={$SERVER_PATH}/gitea/init.d/gitea start +ExecStop={$SERVER_PATH}/gitea/init.d/gitea stop +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/plugins/gitea/init.d/gitea.tpl b/plugins/gitea/init.d/gitea.tpl new file mode 100644 index 000000000..b00abdf6f --- /dev/null +++ b/plugins/gitea/init.d/gitea.tpl @@ -0,0 +1,110 @@ +#!/bin/sh +# +# /etc/rc.d/init.d/Gitea +# +# Runs the Gogs +# +# +# chkconfig: - 85 15 +# + +### BEGIN INIT INFO +# Provides: Gitea +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Should-Start: mysql postgresql +# Should-Stop: mysql postgresql +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start Gitea at boot time. +# Description: Control Gitea. +### END INIT INFO + +# Source function library. +if [ -f /etc/init.d/functions ];then + . /etc/init.d/functions +fi + +if [ -f /etc/rc.d/init.d/functions ];then + . /etc/rc.d/init.d/functions +fi + +# Default values +export HOME={$HOME_DIR} +export USER={$RUN_USER} +NAME=gitea +GOGS_HOME={$SERVER_PATH}/gitea +GOGS_PATH=${GOGS_HOME}/$NAME +GOGS_USER={$RUN_USER} +SERVICENAME="gitea" +LOCKFILE=/tmp/gitea.lock +LOGPATH=${GOGS_HOME}/log +LOGFILE=${LOGPATH}/gitea.log +RETVAL=0 + + +[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME +DAEMON_OPTS="--check $NAME" +[ ! -z "$GOGS_USER" ] && DAEMON_OPTS="$DAEMON_OPTS --user=${GOGS_USER}" + + +status(){ + isStart=`ps -ef|grep 'gitea web' |grep -v grep|awk '{print $2}'` + if [ "$isStart" == '' ];then + echo -e "${SERVICENAME} not running" + else + echo -e "${SERVICENAME}(pid $(echo $isStart)) already running" + fi +} + +start() { + isStart=`ps -ef|grep 'gitea web' |grep -v grep|awk '{print $2}'` + if [ "$isStart" != '' ];then + echo "${SERVICENAME}(pid $(echo $isStart)) already running" + return $RETVAL + fi + + cd ${GOGS_HOME} + echo -e "Starting ${SERVICENAME}: \c" + ${GOGS_PATH} web > ${LOGFILE} 2>&1 & + RETVAL=$? + [ $RETVAL = 0 ] && touch ${LOCKFILE} && echo -e "\033[32mdone\033[0m" + return $RETVAL +} + +stop() { + + pids=`ps -ef|grep 'gitea web' |grep -v grep|awk '{print $2}'` + arr=($pids) + echo -e "Stopping gitea... \c" + for p in ${arr[@]} + do + kill -9 $p + done + echo -e "\033[32mdone\033[0m" +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + restart) + stop + start + ;; + reload) + stop + start + ;; + *) + echo "Usage: ${NAME} {start|stop|status|restart}" + exit 1 + ;; +esac +exit $RETVAL diff --git a/plugins/gitea/install.sh b/plugins/gitea/install.sh new file mode 100755 index 000000000..eccb221af --- /dev/null +++ b/plugins/gitea/install.sh @@ -0,0 +1,98 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + + +install_tmp=${rootPath}/tmp/mw_install.pl +if [ -f ${rootPath}/bin/activate ];then + source ${rootPath}/bin/activate +fi + + +URL_DOWNLOAD=https://dl.gitea.io/ + +getOs(){ + os=`uname` + if [ "Darwin" == "$os" ];then + echo 'darwin' + else + echo 'linux' + fi + return 0 +} + +getBit(){ + echo `getconf LONG_BIT` +} + + +Install_App() +{ + mkdir -p $serverPath/source/gitea + + echo '正在安装脚本文件...' > $install_tmp + version=$1 + os=`getOs` + + git config --global push.default simple + + if [ "darwin" == "$os" ];then + file=gitea-${version}-darwin-10.12-amd64 + else + file=gitea-${version}-linux-amd64 + fi + + file_xz="${file}.xz" + echo "wget -O $serverPath/source/gitea/$file_xz ${URL_DOWNLOAD}/gitea/${version}/${file_xz}" + if [ ! -f $serverPath/source/gitea/$file_xz ];then + wget -O $serverPath/source/gitea/$file_xz ${URL_DOWNLOAD}/gitea/${version}/${file_xz} + fi + + cd $serverPath/source/gitea && xz -k -d $file_xz + if [ -f $file ];then + mkdir -p $serverPath/gitea + mv $serverPath/source/gitea/$file $serverPath/gitea/gitea + chmod +x $serverPath/gitea/gitea + fi + + if [ -d $serverPath/gitea ];then + echo $version > $serverPath/gitea/version.pl + + cd ${rootPath} && python3 plugins/gitea/index.py start + cd ${rootPath} && python3 plugins/gitea/index.py initd_install + fi + + echo 'install success' > $install_tmp +} + +Uninstall_App() +{ + + if [ -f /usr/lib/systemd/system/gitea.service ];then + systemctl stop gitea + systemctl disable gitea + rm -rf /usr/lib/systemd/system/gitea.service + systemctl daemon-reload + fi + + if [ -f $serverPath/gitea/initd/gitea ];then + $serverPath/gitea/initd/gitea stop + fi + + rm -rf $serverPath/gitea + echo 'uninstall success' > $install_tmp +} + + +action=$1 +version=$2 +if [ "${1}" == 'install' ];then + Install_App $version +else + Uninstall_App $version +fi diff --git a/plugins/gitea/js/gitea.js b/plugins/gitea/js/gitea.js new file mode 100755 index 000000000..8f0a6071a --- /dev/null +++ b/plugins/gitea/js/gitea.js @@ -0,0 +1,353 @@ + +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:'gitea', 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){ + var rrdata = $.parseJSON(data.data); + if (!rrdata.status){ + layer.msg(rrdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + var rdata = rrdata.data; + var mlist = ''; + for (var i = 0; i < rdata.length; i++) { + var w = '140'; + if (rdata[i].name == 'error_reporting') w = '250'; + var ibody = ''; + switch (rdata[i].type) { + case 0: + var selected_1 = (rdata[i].value == 1) ? 'selected' : ''; + var selected_0 = (rdata[i].value == 0) ? 'selected' : ''; + ibody = ''; + break; + case 1: + var selected_1 = (rdata[i].value == 'On') ? 'selected' : ''; + var selected_0 = (rdata[i].value == 'Off') ? 'selected' : ''; + ibody = '' + break; + case 2: + var selected_1 = (rdata[i].value == 'true') ? 'selected' : ''; + var selected_0 = (rdata[i].value == 'false') ? 'selected' : ''; + ibody = '' + break; + } + mlist += '

' + rdata[i].name + '' + ibody + ', ' + rdata[i].ps + '

' + } + var html = '
\ + ' + mlist + '\ +
\ + \ +
\ +
'; + $(".soft-man-con").html(html); + }); +} + + +//提交PHP配置 +function submitGogsConf() { + var data = { + DOMAIN: $("input[name='DOMAIN']").val(), + ROOT_URL: $("input[name='ROOT_URL']").val(), + HTTP_ADDR: $("select[name='HTTP_ADDR']").val(), + HTTP_PORT: $("input[name='HTTP_PORT']").val(), + START_SSH_SERVER: $("select[name='START_SSH_SERVER']").val() || 'false', + SSH_PORT: $("input[name='SSH_PORT']").val(), + REQUIRE_SIGNIN_VIEW: $("select[name='REQUIRE_SIGNIN_VIEW']").val() || 'false', + ENABLE_CAPTCHA: $("select[name='ENABLE_CAPTCHA']").val() || 'true', + DISABLE_REGISTRATION: $("select[name='DISABLE_REGISTRATION']").val() || 'false', + ENABLE_NOTIFY_MAIL: $("select[name='ENABLE_NOTIFY_MAIL']").val() || 'false', + FORCE_PRIVATE: $("select[name='FORCE_PRIVATE']").val() || 'false', + SHOW_FOOTER_BRANDING: $("select[name='SHOW_FOOTER_BRANDING']").val() || 'false', + SHOW_FOOTER_VERSION: $("select[name='SHOW_FOOTER_VERSION']").val() || 'false', + SHOW_FOOTER_TEMPLATE_LOAD_TIME: $("select[name='SHOW_FOOTER_TEMPLATE_LOAD_TIME']").val() || 'false', + }; + + gogsPost('submit_gogs_conf', data, function(ret_data){ + var rdata = $.parseJSON(ret_data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + gogsSetConfig(); + }); +} + +function gogsEdit(){ + + gogsPost('gogs_edit',{} , function(data){ + // console.log(data); + var rdata = $.parseJSON(data.data); + var edit = '

通用的手动编辑:

'; + edit +='
\ + \ + \ +
'; + $(".soft-man-con").html(edit); + }); + +} + +function giteaUserList(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; + } + _data['tojs'] = 'giteaUserList'; + + gogsPost('user_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; + } + content = '
'; + content += '
'; + + content += '
'; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + + content += ''; + + ulist = rdata['data']['data']; + for (i in ulist){ + email = ulist[i]["email"] == '' ? '无' : ulist[i]["email"]; + content += ''+ + ''+ + ''+ + ''+ + ''; + } + + content += ''; + content += '
序号用户或组织邮件地址操作(WEB管理)
'+ulist[i]["id"]+''+ulist[i]["name"]+''+email+'项目管理
'; + + var page = ''; + + content += page; + + $(".soft-man-con").html(content); + }); +} + +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 += ''+name+'\ + \ + 源码 | \ + 脚本\ + \ + '; + } + + var page = ''; + + var loadOpen = layer.open({ + type: 1, + title: '用户('+user+')项目列表', + area: '500px', + content:"
\ +
\ +
\ + \ + \ + " + list + "\ +
项目操作
" + + page + + "
" + }); + }); +} + + +function projectScript(user, name,has_hook){ + // console.log(user,name,has_hook); + var html = ''; + if (has_hook){ + html += ''; + html += ''; + html += ''; + html += ''; + } else { + html += ''; + } + + var loadOpen = layer.open({ + type: 1, + title: '['+user+']['+name+']脚本设置', + area: '240px', + content:'
'+html+'
' + }); +} + +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 getRsaPublic(){ + gogsPost('get_rsa_public', {}, function(data){ + var rdata = $.parseJSON(data.data); + var con = '
\ +
\ + \ +
\ + \ +
' + layer.open({ + type: 1, + area: "600px", + title: '本机公钥', + closeBtn: 2, + shift: 5, + shadeClose: false, + content:con + }); + }); +} + +function giteaRead(){ + + var readme = ''; + + $('.soft-man-con').html(readme); +} \ No newline at end of file diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py index 4193d04c3..822a48198 100755 --- a/plugins/gogs/index.py +++ b/plugins/gogs/index.py @@ -462,6 +462,11 @@ def userList(): if not os.path.exists(conf): return mw.returnJson(False, "请先安装初始化!
默认地址:http://" + mw.getLocalIp() + ":3000") + conf = getDbConfValue() + gtype = getGiteaDbType(conf) + if gtype != 'mysql': + return mw.returnJson(False, "仅支持mysql数据操作!") + import math args = getArgs() diff --git a/plugins/gogs/install.sh b/plugins/gogs/install.sh index 73c8eeb8d..47a264866 100755 --- a/plugins/gogs/install.sh +++ b/plugins/gogs/install.sh @@ -29,7 +29,6 @@ getBit(){ Install_gogs() { - pip3 install mysqlclient mkdir -p $serverPath/source/gogs diff --git a/route/static/app/public.js b/route/static/app/public.js index c2a1f072e..3ff15253e 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -1598,6 +1598,18 @@ function remove_ssh_menu() { } /*** 其中功能,针对插件通过库使用 start ***/ + +//字符串转数组对象 +function toArrayObject(str){ + var data = {}; + kv = str.split('&'); + for(i in kv){ + v = kv[i].split('='); + data[v[0]] = v[1]; + } + return data; +} + function pluginService(_name, version){ var data = {name:_name, func:'status'} if ( typeof(version) != 'undefined' ){ diff --git a/scripts/install/debian.sh b/scripts/install/debian.sh index 33144e7bd..368e7feee 100644 --- a/scripts/install/debian.sh +++ b/scripts/install/debian.sh @@ -30,7 +30,7 @@ apt install -y expect apt install -y locate locale-gen en_US.UTF-8 localedef -v -c -i en_US -f UTF-8 en_US.UTF-8 -# sudo localedef -i en_US -f UTF-8 en_US.UTF-8 +sudo localedef -i en_US -f UTF-8 en_US.UTF-8 if [ ! -d /root/.acme.sh ];then curl https://get.acme.sh | sh