Added HTTPS

This commit is contained in:
Francesco Manghi
2025-05-30 11:39:52 +02:00
parent 9cc55fea2b
commit c9738d58d7
3 changed files with 60 additions and 4 deletions

View File

@@ -92,13 +92,25 @@ function install_py_deps {
python3 -m venv "$VENV_DIR"
"$VENV_DIR/bin/python3" -m pip install --upgrade pip
if [ "$1" == "neuron" ]; then
"$VENV_DIR/bin/python3" -m pip install flask==2.2.5 werkzeug==2.2.2 flask-login==0.6.2 pyserial pymodbus==2.5.3
"$VENV_DIR/bin/python3" -m pip install flask==2.2.5 werkzeug==3.0.1 flask-login==0.6.3 flask-wtf==1.2.1 pyserial pymodbus==2.5.3 pycryptodome pyopenssl
else
"$VENV_DIR/bin/python3" -m pip install flask==2.3.3 werkzeug==2.3.7 flask-login==0.6.2 pyserial pymodbus==2.5.3
"$VENV_DIR/bin/python3" -m pip install flask==2.3.3 werkzeug==3.0.1 flask-login==0.6.3 flask-wtf==1.2.1 pyserial pymodbus==2.5.3 pycryptodome pyopenssl
fi
python3 -m pip install pymodbus==2.5.3
echo "[CREATING ENCRYPTION KEY]"
cd webserver
"$VENV_DIR/bin/python3" ./key_create.py
if [ $? -ne 0 ]; then
echo "Error creating encryption key"
echo "OpenPLC was NOT installed!"
exit 1
fi
cd ../
}
function swap_on {
echo "creating swapfile..."
@@ -239,6 +251,9 @@ function install_all_libs {
}
function finalize_install {
echo "[CREATE SSL KEY WEBSITE]"
cd "$OPENPLC_DIR/webserver/"
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"
echo "[FINALIZING]"
cd "$OPENPLC_DIR/webserver/scripts"
if [ "$1" == "win" ]; then
@@ -306,7 +321,7 @@ elif [ "$1" == "win_msys2" ]; then
#Setting up venv
python3 -m venv "$VENV_DIR"
"$VENV_DIR/bin/python3" get-pip3.py
"$VENV_DIR/bin/python3" -m pip install flask==2.3.3 werkzeug==2.3.7 flask-login==0.6.2 pyserial pymodbus==2.5.3
"$VENV_DIR/bin/python3" -m pip install flask==2.3.3 werkzeug==3.0.1 flask-login==0.6.3 pyserial pymodbus==2.5.3
echo ""
echo "[MATIEC COMPILER]"

40
webserver/key_create.py Normal file
View File

@@ -0,0 +1,40 @@
import os
KEYSIZE = 16
BLOCKSIZE = 16
def createKey(keysize):
key = os.urandom(keysize)
return key
def createIV(blocksize):
iv = os.urandom(blocksize)
return iv
def ivcheck():
ivexists = os.path.exists('./iv.bin')
return ivexists
def keycheck():
keyexists = os.path.exists('./key.bin')
return keyexists
def main():
check1 = keycheck()
check2 = ivcheck()
if check1 == False or check2 == False:
key = createKey(KEYSIZE)
iv = createIV(BLOCKSIZE)
with open("key.bin", 'wb') as keyfile:
keyfile.write(key)
keyfile.close()
with open('iv.bin', 'wb') as ivfile:
ivfile.write(iv)
ivfile.close()
else:
pass
if __name__ == '__main__':
main()

View File

@@ -12,6 +12,7 @@ import openplc
import monitoring as monitor
import sys
import ctypes
import key_create
import socket
import mimetypes
@@ -2527,7 +2528,7 @@ if __name__ == '__main__':
configure_runtime()
monitor.parse_st(openplc_runtime.project_file)
app.run(debug=False, host='0.0.0.0', threaded=True, port=8080)
app.run(sl_context=("cert.pem", "key.pem"), debug=False, host='0.0.0.0', threaded=True, port=8080)
except Error as e:
print("error connecting to the database" + str(e))