Newer
Older
#!/usr/bin/env python2
# coding=utf-8
import cgi
import cgitb
import re
import subprocess
cgitb.enable()
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
CODE_PATTERN = '^[a-zA-Z0-9]{64}$'
KEY_DIR='/home/kasalehlia/keys/'
KEY_SCRIPT = '/home/kasalehlia/bin/ffbs_keys'
GIT_DIR = '/home/kasalehlia/peers'
print "Content-Type: text/html;charset=utf-8"
print ""
form = cgi.FieldStorage()
try:
name = form['name'].value
code = form['code'].value
if re.match(NAME_PATTERN, name) and re.match(CODE_PATTERN, code) and name not in ['.','..']:
with open(KEY_DIR+'codes/'+code, 'r') as f:
validate = f.read()
if validate == name:
try:
print subprocess.check_output([KEY_SCRIPT, 'approve', name])
_ = subprocess.check_output(['/usr/bin/git', 'pull'], cwd=GIT_DIR)
_ = subprocess.check_output(['/usr/bin/git', 'add', 'peers/'+name], cwd=GIT_DIR)
_ = subprocess.check_output(['/usr/bin/git', 'commit', '-m', 'automated commit'], cwd=GIT_DIR)
_ = subprocess.check_output(['/usr/bin/git', 'push'], cwd=GIT_DIR)
except subprocess.CalledProcessError as e:
print e.output
else:
print "invalid request"
else:
print "invalid request"
except Exception as e:
print "Die Anfrage ist ungültig"