#!/usr/bin/env python

import cgi

form = cgi.FieldStorage()
ipaddr = form.getfirst("IPAD", "no")
username = form.getfirst("UserN", "no")
kontora = form.getfirst("kontora", "no")



print("Content-type: text/html\n")
print("""<!DOCTYPE HTML>
        <html>
        <head>
            <meta charset="utf-8">
            <title>Form processing</title>
        </head>
        <body>""")

print("<h1>User added!</h1>")
print("<p>IP: {}</p>".format(ipaddr))
print("<p>UserName: {}</p>".format(username))
print("<p>Kontora: {}</p>".format(kontora))

print("""</body>
        </html>""")
SRCFile = open("/home/ruler/reconfig/users.txt", "a")
SRCFile.write(ipaddr + "," + username + "," + kontora + "\n")
SRCFile.close()
print("Done!")
print("""<p><a href="main.py">Return back</a></p>""")
print("""<meta http-equiv="refresh" content="5;main.py">""")

