add https

This commit is contained in:
Qijun Gu 2021-10-05 11:20:52 -05:00
parent 6cae892d24
commit d486ae5868
2 changed files with 57 additions and 8 deletions

View File

@ -8,7 +8,11 @@ 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. ## Updates:
2. (10/5/2021) Add https to screen sharing
1. (10/4/2021) Add a feature to 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.
@ -20,24 +24,54 @@ This tool can run on Linux, Windows and MAC.
+ Know issue: In Linux, this tool does not work with Wayland because of a <a href="https://fedoraproject.org/wiki/How_to_debug_Wayland_problems#Screen_capture_is_not_available_with_usual_apps">security reason</a>. You must use Xorg (by selecting Xorg on login). + Know issue: In Linux, this tool does not work with Wayland because of a <a href="https://fedoraproject.org/wiki/How_to_debug_Wayland_problems#Screen_capture_is_not_available_with_usual_apps">security reason</a>. You must use Xorg (by selecting Xorg on login).
## Install and Run ## Install
1. pip install flask-bootstrap pyscreenshot 1. pip install flask-bootstrap pyscreenshot pyopenssl
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 [-p port] [-w password]**". ## Run as http
1. To start the screen sharing service, run "**python screenshare.py [-p port] [-w password] [-s [-c cert.pem -k key.pem]]**".
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 and no password \# host screenshots on port 18331 and no password
python screenshare.py python screenshare.py
\# host screenshots on port 80 and password "abcdef" \# host screenshots on port 80 and password "abcdef"
python screenshare.py -p 80 -w abcdef python screenshare.py -p 80 -w abcdef
python screenshare.py --port 80 --password abcdef python screenshare.py --port 80 --password abcdef
4. On other computers, open a web browser and browse "**http://serverip:port**". 2. 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".
## Run as https
1. (Optional) Create a self-signed certificate and a private key. Or, obtain a signed certificate and private key.
\# openssl req -x509 -newkey rsa:2048 -nodes -out **cert.pem** -keyout **key.pem** -days 9999
2. To start the screen sharing service with https, run "**python screenshare.py -s [-p port] [-w password] [-c cert.pem -k key.pem]**".
The default service port is 18331. Example commands are below.
\# host screenshots on port 18331 and no password, https with default built-in certificate and private key
python screenshare.py **-s**
\# host screenshots on port 443 and password "abcdef", https with default built-in certificate and private key
python screenshare.py **-s** -p 443 -w abcdef
python screenshare.py **-s** --port 443 --password abcdef
\# host screenshots on port 18331 and no password, https with a certificate file and a private key file
python screenshare.py **-s** -c cert.pem -k key.pem
3. On other computers, open a web browser and browse "**https://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 "https://192.168.0.101:18331".
You will see a warning about the self-signed certificate in the web browser. Accept the warning and continue.

View File

@ -53,9 +53,24 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", help="port, default 18331", type=int, default=18331) 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.add_argument("-w", "--password", help="password, default no password", default="")
parser.add_argument("-s", "--https", help="enable https, default http", action="store_true")
parser.add_argument("-c", "--cert", help="certificate file")
parser.add_argument("-k", "--key", help="private key file")
parser.print_help() parser.print_help()
args = parser.parse_args() args = parser.parse_args()
port = args.port port = args.port
screenlive.password = args.password screenlive.password = args.password
app.run(host='0.0.0.0', port=port, threaded=True) try:
if args.https:
if args.cert and args.key:
app.run(host='0.0.0.0', port=port, threaded=True, ssl_context=(args.cert, args.key))
else:
app.run(host='0.0.0.0', port=port, threaded=True, ssl_context='adhoc')
else:
app.run(host='0.0.0.0', port=port, threaded=True)
except Exception as e:
print(e.message)
print("Some errors in the command, fall back to the default http screen sharing!!!\n")
app.run(host='0.0.0.0', port=port, threaded=True)