Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from bottle import route, run, get, request
- import sqlite3
- PASSWORD = "very_long_unique_string__you_dont_have_to_remember_this"
- def db(query):
- cur.execute(query)
- conn.commit()
- return cur.fetchone()
- conn = sqlite3.connect('ip_addresses.db')
- cur = conn.cursor()
- db('CREATE TABLE IF NOT EXISTS addresses (id integer primary key autoincrement, date datetime, ip4 text, ip6 text)')
- @route('/insert')
- def insert():
- ip4 = request.query.ip4
- ip6 = request.query.ip6
- remotePassword = request.query.password
- if remotePassword == PASSWORD:
- db("INSERT INTO addresses (date, ip4, ip6) VALUES (datetime('now'), '%s', '%s')" % (ip4, ip6))
- return 'Updated.'
- else:
- return 'No.'
- @route('/')
- def index():
- body = """<html>
- <head>
- <style>
- table {
- width: 100%;
- text-align: center;
- }
- td, th {
- width: 33%;
- }
- </style>
- </head>
- <body>
- <table>
- <tr>
- <th>erfasst am/um</th>
- <th>IPv4</th>
- <th>IPv6</th>
- </tr>"""
- end = """
- </tr>
- </table>
- </body>
- </html>"""
- try:
- last_id = db("SELECT MAX(id) as id FROM addresses LIMIT 1")
- entry = db("SELECT date, ip4, ip6 FROM addresses WHERE id = '%d'" % last_id)
- body += """
- <tr>"""
- for val in entry:
- body += """
- <td>""" + str(val) + "</td>"
- except:
- return body, end
- return body, end
- run(host='127.0.0.1', port=63564, debug=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement