diff --git a/README.md b/README.md index eb8983f..4b788f6 100755 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ In short, the computer to share screen runs this Python script that captures scr Of course, if you want to share your screen on the Internet, all you need to do is offering this service on the Internet as any other regular services. +You can set a password to control who can access the screens. + **Security reminder** Do not run this service if you do not need to share screen. ## Requirements @@ -24,16 +26,18 @@ This tool can run on Linux, Windows and MAC. 2. In a directory, run "**git clone https://github.com/qijungu/screenshare.git**". You will have a new directory "screenshare" with code inside. -3. To start the screen sharing service, run "**python screenshare.py [port]**". +3. To start the screen sharing service, run "**python screenshare.py [-p port] [-w password]**". The default service port is 18331. Example commands are below. - \# host screenshots on port 18331 + \# host screenshots on port 18331 and no password python screenshare.py - \# host screenshots on port 80 - python screenshare.py 80 + \# host screenshots on port 80 and password "abcdef" + python screenshare.py -p 80 -w abcdef + python screenshare.py --port 80 --password abcdef 4. On other computers, open a web browser and browse "**http://serverip:port**". For example, if the server ip is 192.168.0.101 and the service port is 18331, then the URL to browse is "http://192.168.0.101:18331". + diff --git a/screen.py b/screen.py index f8c336d..2c9c470 100755 --- a/screen.py +++ b/screen.py @@ -15,6 +15,7 @@ class Screen(): def __init__(self): self.FPS = 10 self.screenbuf = "" + self.password = "" if ver==2: self.screenfile = StringIO.StringIO() elif ver==3: diff --git a/screenshare.py b/screenshare.py index 964c71a..72f87c8 100755 --- a/screenshare.py +++ b/screenshare.py @@ -1,11 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from flask import Flask +from flask import Flask, request, flash, session from flask_bootstrap import Bootstrap from flask.templating import render_template -import json +import json, argparse from screen import screenlive +from werkzeug.utils import redirect secret_key = u'f71b10b68b1bc00019cfc50d6ee817e75d5441bd5db0bd83453b398225cede69' @@ -16,17 +17,45 @@ Bootstrap(app) ###### general ########################################## @app.route('/') def welcome(): - return render_template("screen.html") + session.clear() + if len(screenlive.password) == 0 : + session['access'] = True + return render_template("screen.html") + else : + return render_template("login.html") + +@app.route('/login', methods = ['POST']) +def login(): + # password is not required + session.clear() + if len(screenlive.password) == 0 : + session['access'] = True + return render_template("screen.html") + + p = request.form["password"] + if p == screenlive.password : + session['access'] = True + return render_template("screen.html") + else : + session.clear() + flash("Wrong password") + return render_template("login.html") @app.route('/screenfeed/', methods=["POST"]) def screenfeed(): - return json.dumps([True, screenlive.gen()]) + if 'access' in session and session['access']: + return json.dumps([True, screenlive.gen()]) + else: + redirect('/') ### main ### if __name__ == '__main__': - from sys import argv - if len(argv) <= 1: - port = 18331 - else: - port = int(argv[1]) + parser = argparse.ArgumentParser() + parser.add_argument("-p", "--port", help="port, default 18331", type=int, default=18331) + parser.add_argument("-w", "--password", help="password, default no password", default="") + parser.print_help() + args = parser.parse_args() + port = args.port + screenlive.password = args.password + app.run(host='0.0.0.0', port=port, threaded=True) diff --git a/templates/login.html b/templates/login.html new file mode 100755 index 0000000..bf35863 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,53 @@ + +{% extends "bootstrap/base.html" %} + +{% block title %}Screen Share{% endblock %} + +{% block metas %} +{{super()}} + +{% endblock %} + +{% block styles %} +{{super()}} + + + +{% endblock %} + +{% block scripts %} +{{super()}} + +{% endblock %} + +{% block body_attribs %} +ontouchstart="" +class="homepage" +{% endblock %} + +{% block navbar %} + +{% endblock %} + +{% block content %} +
+
+
+
+
+ + +
+ +
+ {% for message in get_flashed_messages() %} + + {% endfor %} +
+
+
+{% endblock %} \ No newline at end of file