Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import ssl
|
|
| 9 |
from OpenSSL import crypto
|
| 10 |
import subprocess
|
| 11 |
import sys
|
|
|
|
| 12 |
|
| 13 |
# Function to check and install required packages
|
| 14 |
def install_requirements():
|
|
@@ -109,6 +110,19 @@ def check_and_generate_cert():
|
|
| 109 |
else:
|
| 110 |
print("SSL certificates found, continuing...")
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
# Main route for processing data
|
| 113 |
@app.route('/', methods=['POST'])
|
| 114 |
def process_data():
|
|
@@ -154,7 +168,9 @@ def process_data():
|
|
| 154 |
# Route to serve the home page
|
| 155 |
@app.route('/index')
|
| 156 |
def index():
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
|
| 159 |
if __name__ == '__main__':
|
| 160 |
install_requirements() # Ensure all dependencies are installed
|
|
|
|
| 9 |
from OpenSSL import crypto
|
| 10 |
import subprocess
|
| 11 |
import sys
|
| 12 |
+
import socket
|
| 13 |
|
| 14 |
# Function to check and install required packages
|
| 15 |
def install_requirements():
|
|
|
|
| 110 |
else:
|
| 111 |
print("SSL certificates found, continuing...")
|
| 112 |
|
| 113 |
+
# Function to get the server's IP address
|
| 114 |
+
def get_server_ip():
|
| 115 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 116 |
+
s.settimeout(0)
|
| 117 |
+
try:
|
| 118 |
+
s.connect(('10.254.254.254', 1))
|
| 119 |
+
ip = s.getsockname()[0]
|
| 120 |
+
except Exception:
|
| 121 |
+
ip = '127.0.0.1'
|
| 122 |
+
finally:
|
| 123 |
+
s.close()
|
| 124 |
+
return ip
|
| 125 |
+
|
| 126 |
# Main route for processing data
|
| 127 |
@app.route('/', methods=['POST'])
|
| 128 |
def process_data():
|
|
|
|
| 168 |
# Route to serve the home page
|
| 169 |
@app.route('/index')
|
| 170 |
def index():
|
| 171 |
+
server_ip = get_server_ip() # Get the server's IP address
|
| 172 |
+
log_stats = sum(1 for line in open('accesslog.txt', 'r')) # Count log entries
|
| 173 |
+
return render_template('index.html', ip_address=server_ip, log_stats=log_stats)
|
| 174 |
|
| 175 |
if __name__ == '__main__':
|
| 176 |
install_requirements() # Ensure all dependencies are installed
|