Advertisement
Guest User

Untitled

a guest
May 29th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from bottle import route, run, get, request
  3. import sqlite3
  4.  
  5. PASSWORD = "very_long_unique_string__you_dont_have_to_remember_this"
  6.  
  7. def db(query):
  8. cur.execute(query)
  9. conn.commit()
  10. return cur.fetchone()
  11.  
  12. conn = sqlite3.connect('ip_addresses.db')
  13. cur = conn.cursor()
  14. db('CREATE TABLE IF NOT EXISTS addresses (id integer primary key autoincrement, date datetime, ip4 text, ip6 text)')
  15.  
  16. @route('/insert')
  17. def insert():
  18. ip4 = request.query.ip4
  19. ip6 = request.query.ip6
  20. remotePassword = request.query.password
  21. if remotePassword == PASSWORD:
  22. db("INSERT INTO addresses (date, ip4, ip6) VALUES (datetime('now'), '%s', '%s')" % (ip4, ip6))
  23. return 'Updated.'
  24. else:
  25. return 'No.'
  26.  
  27.  
  28. @route('/')
  29. def index():
  30.  
  31. body = """<html>
  32. <head>
  33. <style>
  34. table {
  35. width: 100%;
  36. text-align: center;
  37. }
  38.  
  39. td, th {
  40. width: 33%;
  41. }
  42. </style>
  43. </head>
  44.  
  45. <body>
  46. <table>
  47. <tr>
  48. <th>erfasst am/um</th>
  49. <th>IPv4</th>
  50. <th>IPv6</th>
  51. </tr>"""
  52.  
  53. end = """
  54. </tr>
  55. </table>
  56. </body>
  57. </html>"""
  58.  
  59.  
  60. try:
  61. last_id = db("SELECT MAX(id) as id FROM addresses LIMIT 1")
  62. entry = db("SELECT date, ip4, ip6 FROM addresses WHERE id = '%d'" % last_id)
  63. body += """
  64. <tr>"""
  65.  
  66. for val in entry:
  67. body += """
  68. <td>""" + str(val) + "</td>"
  69. except:
  70. return body, end
  71.  
  72. return body, end
  73.  
  74.  
  75. run(host='127.0.0.1', port=63564, debug=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement