mirror of
https://github.com/iiab/iiab.git
synced 2025-02-13 19:52:06 +00:00
rebase bassed upon copy in cut out obvious dead code working on put-204 make users a sqlite db sqlite db has users, and agent info android timeouts not yet working android 5 and 6 both work. lost mac return to a working version for the MAC. Missing the splash android,mac,windows all appear to work sqlite get status of execute row == Null initialize lasttimestamp with ajax call when home is triggered remove commented code, move towards logging vs print statements add logging with the -l flag no changes to default_vars.yml drop iptables captive portal stuff not using port 8090, and dnsmasq missed deleting trap_enabled fixes for 6.7 defaults add in template dir rebase bassed upon copy in cut out obvious dead code working on put-204 make users a sqlite db sqlite db has users, and agent info android timeouts not yet working android 5 and 6 both work. lost mac return to a working version for the MAC. Missing the splash android,mac,windows all appear to work sqlite get status of execute row == Null initialize lasttimestamp with ajax call when home is triggered remove commented code, move towards logging vs print statements drop iptables captive portal stuff not using port 8090, and dnsmasq missed deleting trap_enabled fixes for 6.7 defaults dispense with apache logs for captive portal, use the rotating portal.log instead bring in clean defaults and py Squash debugging details remove backup file still cannot dispense with cna on iphone. mac escape from cna broke with these changes captive comes after iiab in apache config one filename wrong logging used for debug, lost mac escape from cna typos got mac/iphone full browser back remove dead code python was not creating db, or putting ip when first encountered
97 lines
3.2 KiB
Django/Jinja
Executable file
97 lines
3.2 KiB
Django/Jinja
Executable file
#!/usr/bin/python
|
|
|
|
# Captive portal script adapted from https://github.com/nikosft/captive-portal
|
|
|
|
import subprocess
|
|
import BaseHTTPServer
|
|
import cgi
|
|
|
|
# These variables are used as settings
|
|
PORT = int("{{ py_captive_portal_port }}") # the port in which the captive portal web server listens
|
|
IFACE = "{{ iiab_lan_iface }}" # the interface that captive portal protects
|
|
IP_ADDRESS = "{{ lan_ip }}" # the ip address of the captive portal (it can be the IP of IFACE)
|
|
|
|
'''
|
|
This it the http server used by the the captive portal
|
|
'''
|
|
class CaptivePortal(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
#this is the index of the captive portal
|
|
#it simply redirects the user to the to login page
|
|
html_redirect = """
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="refresh" content="0; url=http://%s:%s/login" />
|
|
</head>
|
|
<body>
|
|
<b>Redirecting to login page</b>
|
|
</body>
|
|
</html>
|
|
"""%(IP_ADDRESS, PORT)
|
|
#the login page
|
|
html_login = """
|
|
<html>
|
|
<body>
|
|
<b>Login Form</b>
|
|
<form method="POST" action="do_login">
|
|
Username: <input type="text" name="username"><br>
|
|
Password: <input type="password" name="password"><br>
|
|
<input type="submit" value="Submit">
|
|
</form>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
'''
|
|
if the user requests the login page show it, else
|
|
use the redirect page
|
|
'''
|
|
def do_GET(self):
|
|
path = self.path
|
|
self.send_response(200)
|
|
self.send_header("Content-type", "text/html")
|
|
self.end_headers()
|
|
if path == "/login":
|
|
self.wfile.write(self.html_login)
|
|
else:
|
|
self.wfile.write(self.html_redirect)
|
|
'''
|
|
this is called when the user submits the login form
|
|
'''
|
|
def do_POST(self):
|
|
self.send_response(200)
|
|
self.send_header("Content-type", "text/html")
|
|
self.end_headers()
|
|
form = cgi.FieldStorage(
|
|
fp=self.rfile,
|
|
headers=self.headers,
|
|
environ={'REQUEST_METHOD':'POST',
|
|
'CONTENT_TYPE':self.headers['Content-Type'],
|
|
})
|
|
username = form.getvalue("username")
|
|
password = form.getvalue("password")
|
|
#dummy security check
|
|
if username == '{{ py_captive_portal_username }}' and password == '{{ py_captive_portal_password }}':
|
|
#authorized user
|
|
remote_IP = self.client_address[0]
|
|
print 'New authorization from '+ remote_IP
|
|
print 'Updating IP tables'
|
|
subprocess.call(["iptables","-t", "nat", "-I", "PREROUTING","1", "-s", remote_IP, "-j" ,"ACCEPT"])
|
|
subprocess.call(["iptables", "-I", "FORWARD", "-s", remote_IP, "-j" ,"ACCEPT"])
|
|
self.wfile.write("You are now authorized. Navigate to any URL")
|
|
else:
|
|
#show the login form
|
|
self.wfile.write(self.html_login)
|
|
|
|
#the following function makes server produce no output
|
|
#comment it out if you want to print diagnostic messages
|
|
#def log_message(self, format, *args):
|
|
# return
|
|
|
|
print "Starting captive portal web server"
|
|
httpd = BaseHTTPServer.HTTPServer(('', PORT), CaptivePortal)
|
|
|
|
try:
|
|
httpd.serve_forever()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
httpd.server_close()
|