APmanageur Wi-Fi V1.0 : conteneur Debian + Apache
This commit is contained in:
1 parent
c705504e5d
commit
2d3f8d8b3c
5 files changed
+66
-47
No files matched your search
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
import base64, hashlib, hmac, json, os, re, secrets, socket, sqlite3, subprocess, threading, time, urllib.parse
|
||||
import base64, hashlib, hmac, json, os, re, secrets, socket, sqlite3, subprocess, threading, time, urllib.parse, socketserver, shutil
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
INTERFACE = os.environ.get('AP_INTERFACE', 'wls16b1')
|
||||
HOST, PORT = '0.0.0.0', 8080
|
||||
SOCKET_PATH = os.environ.get('AP_SOCKET', '/run/ap-api.sock')
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
DB_FILE = os.environ.get('AP_DB_FILE', os.path.join(BASE_DIR, 'ap-dashboard.sqlite3'))
|
||||
CONNECTION_FILE = os.environ.get('AP_CONNECTION_FILE', os.path.join(BASE_DIR, 'ap-dashboard-connection'))
|
||||
@@ -501,5 +501,19 @@ def monitor():
|
||||
except Exception: pass
|
||||
time.sleep(2)
|
||||
|
||||
class UnixServer(ThreadingHTTPServer):
|
||||
address_family = socket.AF_UNIX
|
||||
daemon_threads = True
|
||||
def server_bind(self):
|
||||
socketserver.TCPServer.server_bind(self)
|
||||
self.server_name, self.server_port = 'localhost', 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
db(); threading.Thread(target=monitor,daemon=True).start(); print(f'API AP sur http://0.0.0.0:{PORT}'); ThreadingHTTPServer((HOST,PORT),Handler).serve_forever()
|
||||
db(); threading.Thread(target=monitor,daemon=True).start()
|
||||
try: os.remove(SOCKET_PATH)
|
||||
except OSError: pass
|
||||
server = UnixServer(SOCKET_PATH, Handler)
|
||||
os.chmod(SOCKET_PATH, 0o660)
|
||||
try: shutil.chown(SOCKET_PATH, user='root', group='www-data')
|
||||
except (LookupError, OSError): os.chmod(SOCKET_PATH, 0o666)
|
||||
print(f'API AP sur le socket {SOCKET_PATH} (aucun port TCP)'); server.serve_forever()
|
||||
Reference in new issue
Block a user