add password control
This commit is contained in:
parent
c82fea480d
commit
6cae892d24
12
README.md
12
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.
|
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.
|
**Security reminder** Do not run this service if you do not need to share screen.
|
||||||
|
|
||||||
## Requirements
|
## 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.
|
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.
|
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
|
python screenshare.py
|
||||||
|
|
||||||
\# host screenshots on port 80
|
\# host screenshots on port 80 and password "abcdef"
|
||||||
python screenshare.py 80
|
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**".
|
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".
|
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".
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Screen():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.FPS = 10
|
self.FPS = 10
|
||||||
self.screenbuf = ""
|
self.screenbuf = ""
|
||||||
|
self.password = ""
|
||||||
if ver==2:
|
if ver==2:
|
||||||
self.screenfile = StringIO.StringIO()
|
self.screenfile = StringIO.StringIO()
|
||||||
elif ver==3:
|
elif ver==3:
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask, request, flash, session
|
||||||
from flask_bootstrap import Bootstrap
|
from flask_bootstrap import Bootstrap
|
||||||
from flask.templating import render_template
|
from flask.templating import render_template
|
||||||
import json
|
import json, argparse
|
||||||
from screen import screenlive
|
from screen import screenlive
|
||||||
|
from werkzeug.utils import redirect
|
||||||
|
|
||||||
secret_key = u'f71b10b68b1bc00019cfc50d6ee817e75d5441bd5db0bd83453b398225cede69'
|
secret_key = u'f71b10b68b1bc00019cfc50d6ee817e75d5441bd5db0bd83453b398225cede69'
|
||||||
|
|
||||||
|
@ -16,17 +17,45 @@ Bootstrap(app)
|
||||||
###### general ##########################################
|
###### general ##########################################
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def welcome():
|
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"])
|
@app.route('/screenfeed/', methods=["POST"])
|
||||||
def screenfeed():
|
def screenfeed():
|
||||||
return json.dumps([True, screenlive.gen()])
|
if 'access' in session and session['access']:
|
||||||
|
return json.dumps([True, screenlive.gen()])
|
||||||
|
else:
|
||||||
|
redirect('/')
|
||||||
|
|
||||||
### main ###
|
### main ###
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from sys import argv
|
parser = argparse.ArgumentParser()
|
||||||
if len(argv) <= 1:
|
parser.add_argument("-p", "--port", help="port, default 18331", type=int, default=18331)
|
||||||
port = 18331
|
parser.add_argument("-w", "--password", help="password, default no password", default="")
|
||||||
else:
|
parser.print_help()
|
||||||
port = int(argv[1])
|
args = parser.parse_args()
|
||||||
|
port = args.port
|
||||||
|
screenlive.password = args.password
|
||||||
|
|
||||||
app.run(host='0.0.0.0', port=port, threaded=True)
|
app.run(host='0.0.0.0', port=port, threaded=True)
|
||||||
|
|
53
templates/login.html
Executable file
53
templates/login.html
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
{% extends "bootstrap/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Screen Share{% endblock %}
|
||||||
|
|
||||||
|
{% block metas %}
|
||||||
|
{{super()}}
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block styles %}
|
||||||
|
{{super()}}
|
||||||
|
<link rel="stylesheet" href="{{url_for('static', filename='css/jquery-confirm.min.css')}}"/>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="{{url_for('static', filename='css/common.css')}}?ver=2"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
{{super()}}
|
||||||
|
<script src="{{url_for('static', filename='js/jquery-confirm.min.js')}}"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body_attribs %}
|
||||||
|
ontouchstart=""
|
||||||
|
class="homepage"
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block navbar %}
|
||||||
|
<header id="header">
|
||||||
|
</header>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<section id="feature" class="fullwidth">
|
||||||
|
<div class="container fullwidth">
|
||||||
|
<div class="center fullwidth">
|
||||||
|
<form action="/login" method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password : </label>
|
||||||
|
<input type="password" class="form-control" placeholder="Enter password" id="password" name="password">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
|
{% for message in get_flashed_messages() %}
|
||||||
|
<div class="alert alert-warning alert-dismissible" role="alert">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<strong> {{ message }} </strong>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user