123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import time
- from flask import Flask
- from flask import request
- from core import runcmd
- from core import allow_exec
- from core import allow_path
- from core import getrepo
- from config import HOST
- from config import PORT
- from config import DEBUG
- from config import SYNC_PATH
- from config import GIT_SERVER
- app = Flask(__name__)
- status = {}
- repo = getrepo()
- def gettime():
- return time.time()
- confsync = gettime()
- @app.route('/')
- def hello_world():
- return 'Hello World!\n',403
- @app.route('/{SYNC_PATH}/<token>'.format(SYNC_PATH=SYNC_PATH))
- def sync(token):
- ip = request.remote_addr.strip()
- global repo
- if token not in repo:
-
- return u'Hello %s token error !!\n'%(ip),403
- if (ip not in repo[token]['ip']) and (ip not in GIT_SERVER):
-
- return u'Hello %s ip error!!!\n'%(ip),403
- interval = repo[token]['interval']
- path = repo[token]['path']
- cmd = repo[token]['cmd']
- cmd = ' '.join(cmd.split())
- user = repo[token]['user']
- name = repo[token]['name']
- if path.endswith('/'):
- syndir = path.split('/')[-2]
- else:
- syndir = path.split('/')[-1]
- if token in status:
- end_time = gettime()
- if end_time - status[token] < interval:
- return u'同步太频繁,请稍后\n\n\n\n'
- status[token]=gettime()
-
- if not allow_exec(cmd):
- return 'the cmd not in exec white list',403
-
- if not allow_path(path):
- return 'The path is not allow access',403
-
- tmp = runcmd(cmd, path) + '\n\n'
-
- tmp += runcmd('chown -R {user}:{user} *'.format(user=user), path)
-
- showchar ='name: {name}\nsyndir is: {syndir}\n\n{tmp}\n'.format(
- name=name,syndir=syndir,tmp=tmp)
- return showchar
- @app.errorhandler(404)
- def page_error(error):
- return 'Hello World!\n',403
- if __name__ == '__main__':
- app.run(host=HOST,port=PORT,debug=DEBUG)
|