You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. #!/usr/bin/python3
  2. # coding=utf-8
  3. from bottle import route, run, static_file, template
  4. import MySQLdb
  5. HOST = 'localhost'
  6. @route('/static/')
  7. def server_static(filepath):
  8. return static_file(filepath, root='/home/mix/PycharmProjects/kea_for_miners/static/')
  9. @route('/')
  10. def server_homepage():
  11. dbhost = '10.5.1.248'
  12. dbuser = 'kea'
  13. dbpass = 'kea1234'
  14. dbbase = 'dhcp4'
  15. sql = "SELECT " \
  16. " expire, " \
  17. " INET_NTOA(address) as ip4, " \
  18. " HEX(hwaddr)as hw_addr, " \
  19. " hostname " \
  20. " FROM lease4 " \
  21. "where INET_NTOA(address) like '10.5.0%'" \
  22. " ORDER BY expire DESC;"
  23. try:
  24. conn = MySQLdb.connect(host=dbhost, user=dbuser,
  25. passwd=dbpass, db=dbbase)
  26. except MySQLdb.Error as err:
  27. print("Connection error: {}".format(err))
  28. conn.close()
  29. try:
  30. cur = conn.cursor(MySQLdb.cursors.DictCursor)
  31. cur.execute(sql)
  32. data = cur.fetchall()
  33. except MySQLdb.Error as err:
  34. print("Query error: {}".format(err))
  35. conn.close()
  36. data_list = []
  37. for row in data:
  38. temp = []
  39. temp.append(row['expire'])
  40. temp.append(row['ip4'])
  41. temp.append(row['hw_addr'])
  42. temp.append(row['hostname'])
  43. data_list.append(temp)
  44. return template('main.tpl', A=data_list)
  45. run(host='10.5.1.248', port=8080, debug=True)

Powered by TurnKey Linux.