added password oth
This commit is contained in:
1 parent
ef88655bad
commit
2099599770
2 files changed
+36
-23
No files matched your search
+24
-18
@@ -1,36 +1,42 @@
|
|||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
|
import getpass # This hides the password as you type
|
||||||
|
|
||||||
def start_calculator():
|
def start_calculator():
|
||||||
print("--- Welcome to the Calculator ---")
|
print("\n--- Calculator Unlocked ---")
|
||||||
try:
|
try:
|
||||||
num1 = float(input("Enter first number: "))
|
num1 = float(input("Enter first number: "))
|
||||||
op = input("Enter operator (+, -, *, /): ")
|
op = input("Enter operator (+, -, *, /): ")
|
||||||
num2 = float(input("Enter second number: "))
|
num2 = float(input("Enter second number: "))
|
||||||
|
# ... (rest of your math logic)
|
||||||
if op == "+": print(f"Result: {num1 + num2}")
|
print(f"Result: {num1 + num2}") # Simplified example
|
||||||
elif op == "-": print(f"Result: {num1 - num2}")
|
except Exception as e:
|
||||||
elif op == "*": print(f"Result: {num1 * num2}")
|
print(f"Error: {e}")
|
||||||
elif op == "/": print(f"Result: {num1 / num2}")
|
|
||||||
else: print("Invalid operator.")
|
|
||||||
except ValueError:
|
|
||||||
print("Please enter valid numbers.")
|
|
||||||
|
|
||||||
def check_server():
|
def check_server():
|
||||||
url = "http://localhost:6000/status"
|
url = "http://localhost:6000/status"
|
||||||
|
|
||||||
|
print("--- Server Authentication ---")
|
||||||
|
password = getpass.getpass("Enter Server Password: ")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url)
|
# Send the password in the headers
|
||||||
data = response.json()
|
headers = {'x-password': password}
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
|
||||||
if data.get("run") == "yes":
|
if response.status_code == 200:
|
||||||
print("Access granted by server.")
|
data = response.json()
|
||||||
start_calculator()
|
if data.get("run") == "yes":
|
||||||
|
start_calculator()
|
||||||
|
else:
|
||||||
|
print("Server is set to 'no'. Access denied.")
|
||||||
|
elif response.status_code == 401:
|
||||||
|
print("Access Denied: Incorrect Password.")
|
||||||
else:
|
else:
|
||||||
print("Access denied: The server said 'no'.")
|
print(f"Server returned status code: {response.status_code}")
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
print("Error: Could not connect to the server. Is it running?")
|
print("Could not connect to server.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
check_server()
|
check_server()
|
||||||
@@ -2,14 +2,21 @@ const express = require('express');
|
|||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 6000;
|
const PORT = 6000;
|
||||||
|
|
||||||
// Change this variable to "no" to stop the Python script
|
// Set your desired password here
|
||||||
let accessGranted = "no";
|
const SERVER_PASSWORD = "hi";
|
||||||
|
let accessGranted = "yes";
|
||||||
|
|
||||||
app.get('/status', (req, res) => {
|
app.get('/status', (req, res) => {
|
||||||
res.json({ run: accessGranted });
|
// Look for 'x-password' in the request headers
|
||||||
|
const clientPassword = req.headers['x-password'];
|
||||||
|
|
||||||
|
if (clientPassword === SERVER_PASSWORD) {
|
||||||
|
res.json({ run: accessGranted, message: "Authenticated!" });
|
||||||
|
} else {
|
||||||
|
res.status(401).json({ run: "no", message: "Invalid Password" });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Server is running at http://localhost:${PORT}`);
|
console.log(`Server running. Password is required to launch calculator.`);
|
||||||
console.log(`Current status: ${accessGranted}`);
|
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user