Skip to content
Snippets Groups Projects
Commit 9a65204a authored by chrissi^'s avatar chrissi^
Browse files

cgi: Remove scripts unused in parker

parent 8915912d
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python2
# coding=utf-8
import cgi
import cgitb
import re
import subprocess
cgitb.enable()
NAME_PATTERN = '^[a-zA-Z0-9-_\. äÄöÖüÜß]+$'
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"
#!/usr/bin/env python2
# coding=utf-8
import cgi
import cgitb
import re
import subprocess
cgitb.enable()
NAME_PATTERN = '^[a-zA-Z0-9-_\. äÄöÖüÜß]+$'
CODE_PATTERN = '^[a-zA-Z0-9]{64}$'
KEY_DIR='/home/kasalehlia/keys/'
KEY_SCRIPT = '/home/kasalehlia/bin/ffbs_keys'
print "Content-Type: text/html"
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, 'deny', name])
except subprocess.CalledProcessError as e:
print e.output
else:
print "invalid request"
else:
print "invalid request"
except Exception as e:
print template % "Die Anfrage ist ungültig"
#!/usr/bin/env python2
# coding=utf-8
import cgi
import cgitb
import datetime
import json
SECRET = "ahqu2Choshi7sahDme8aePh4iegh8Wee"
print "Content-Type: text/html"
print ""
params = cgi.FieldStorage()
if 'secret' in params and params['secret'].value == SECRET:
info = dict()
info['updated'] = datetime.datetime.now().isoformat()
for i in xrange(100): # be prepared for many gateways
key = "gw"+str(i).zfill(2)
if key in params:
try:
info[key] = int(params[key].value)
except ValueError: # value is not a number
pass
print "accepted status for "+str(len(info))+" gateways"
with open('/home/kasalehlia/ffbs-website/gatewaystatus.json','w') as f:
json.dump(info, f)
else:
print "nothing to see here"
#!/usr/bin/env python2
# coding=utf-8
import cgi
import cgitb
import os
import random
import re
import smtplib
import string
import time
from email.mime.text import MIMEText
from subprocess import Popen, PIPE, check_output, CalledProcessError
cgitb.enable()
KEY_DIR='/home/kasalehlia/keys/'
CONTACT_FILE='/home/kasalehlia/contacts.txt'
KEY_PATTERN = r'# ([a-zA-Z0-9-_\. äÄöÖüÜß]+) ?#? ?([\S ]+)?\r?\n([0-9a-f]{64})$';
#KEY_PATTERN = r'# ([\w.- ]+) ?#? ?([\S ]+)?\r?\n([0-9a-f]{64})$';
EMAIL_FROM = 'keys@freifunk-bs.de'
EMAIL_TO = 'ffbs-admin@stratum0.org'
#EMAIL_TO = 'kasa@shakik.de'
EMAIL_TEXT = """Key approval request: {name} with key {key}.\n
To approve: http://www.freifunk-bs.de/approve_key?name={name}&code={code}\n
To deny: http://www.freifunk-bs.de/deny_key?name={name}&code={code}\n
\n`{quote}`"""
QUOTES = list(open('/home/kasalehlia/portal.quotes'))
print "Content-Type: application/json; charset=utf-8"
print ""
form = cgi.FieldStorage()
try:
inp = form['key'].value.strip()
contact = form.getfirst('contact','').strip()
match = re.match(KEY_PATTERN, inp)
if match:
name,_contact,key = match.groups()
name = name.strip()
if not contact:
contact = _contact
code = ''.join(random.choice(string.letters + string.digits) for _ in xrange(64))
if os.path.isfile(KEY_DIR+name):
print '{"success":false, "message":"Dieser Name oder dieser Schlüssel ist bereits eingetragen"}'
else:
try:
res = check_output(['/bin/grep','-r','--exclude-dir=codes',key,KEY_DIR])
except CalledProcessError as e:
res = e.output
if len(res):
print '{"success":false, "message":"Dieser Name oder dieser Schlüssel ist bereits eingetragen"}'
else:
with open(KEY_DIR+name,'w') as f:
f.write('key "%s";\n' % key)
with open(KEY_DIR+'/codes/'+code,'w') as f:
f.write(name)
with open(CONTACT_FILE, 'a') as f:
f.write('{},{},{},{}\n'.format(time.time(),key,name,contact))
#s = smtplib.SMTP('localhost')
if 'NOMAIL' not in name:
msg = MIMEText(EMAIL_TEXT.format(name=name.replace(' ', '%20'), key=key, code=code, quote=random.choice(QUOTES)[:-1]),'plain','utf-8')
msg['From'] = EMAIL_FROM
msg['To'] = EMAIL_TO
msg['Subject'] = 'Key approval request for %s' % name
#s.sendmail(EMAIL_FROM, [EMAIL_TO], msg.as_string())
#s.quit()
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(msg.as_string())
print '{"success":true, "message":"Dein Schlüssel wurde eingetragen, muss aber noch von einem Administrator bestätigt werden"}'
else:
print '{"success":true, "message":"debug input accepted"}'
else:
print '{"success":false, "message":"Die Eingabe ist fehlerhaft"}'
except Exception as e:
print '{"success":false, "message":"Die Eingabe ist fehlerhaft", "err":"'+repr(e)+'"}'
#raise e
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment