change IPs in code
This commit is contained in:
@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y \
|
|||||||
nginx \
|
nginx \
|
||||||
supervisor \
|
supervisor \
|
||||||
net-tools \
|
net-tools \
|
||||||
|
iputils-ping \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy your application code & config files
|
# Copy your application code & config files
|
||||||
|
|||||||
12
api/app.py
12
api/app.py
@ -27,9 +27,11 @@ password_types = [
|
|||||||
#################################################
|
#################################################
|
||||||
# Hash Record Functions
|
# Hash Record Functions
|
||||||
#################################################
|
#################################################
|
||||||
|
# Create the file if it doesn’t exist
|
||||||
if not HASH_FILE.exists():
|
if not HASH_FILE.exists():
|
||||||
# Nothing to load – create an empty file for future use
|
|
||||||
HASH_FILE.touch(exist_ok=True)
|
HASH_FILE.touch(exist_ok=True)
|
||||||
|
|
||||||
|
# Read the hashes
|
||||||
try:
|
try:
|
||||||
with HASH_FILE.open("r", encoding="utf-8") as fh:
|
with HASH_FILE.open("r", encoding="utf-8") as fh:
|
||||||
password_hashes = {line.strip() for line in fh if line.strip()}
|
password_hashes = {line.strip() for line in fh if line.strip()}
|
||||||
@ -125,7 +127,7 @@ def get_password():
|
|||||||
"password_types": password_types
|
"password_types": password_types
|
||||||
}), 404 # 404 Not Found
|
}), 404 # 404 Not Found
|
||||||
|
|
||||||
# Success – return the password
|
# Success - return the password
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"password": get_password_by_index(index)
|
"password": get_password_by_index(index)
|
||||||
}), 200
|
}), 200
|
||||||
@ -151,7 +153,7 @@ def verbose_password():
|
|||||||
"error": f"Index {index} is out of bounds (0 ≤ index < {len(password_types)})",
|
"error": f"Index {index} is out of bounds (0 ≤ index < {len(password_types)})",
|
||||||
"password_types": password_types
|
"password_types": password_types
|
||||||
}), 404 # 404 Not Found
|
}), 404 # 404 Not Found
|
||||||
# Success – return the result
|
# Success - return the result
|
||||||
result = {
|
result = {
|
||||||
"password": get_password_by_index(index),
|
"password": get_password_by_index(index),
|
||||||
"descriptor": password_function_descriptor[password_types[index]],
|
"descriptor": password_function_descriptor[password_types[index]],
|
||||||
@ -166,7 +168,7 @@ def custom_password():
|
|||||||
|
|
||||||
payload = request.get_json()
|
payload = request.get_json()
|
||||||
|
|
||||||
# Basic presence check – you can relax this if you want defaults
|
# Basic presence check - you can relax this if you want defaults
|
||||||
required_keys = {"w_min", "w_max", "w_count", "s_char", "num_len"}
|
required_keys = {"w_min", "w_max", "w_count", "s_char", "num_len"}
|
||||||
missing = required_keys - payload.keys()
|
missing = required_keys - payload.keys()
|
||||||
if missing:
|
if missing:
|
||||||
@ -411,7 +413,7 @@ def check_and_add_hash(password: str) -> bool:
|
|||||||
hash_value = sha256_hex(password)
|
hash_value = sha256_hex(password)
|
||||||
if hash_value in password_hashes:
|
if hash_value in password_hashes:
|
||||||
return False
|
return False
|
||||||
# Hash was missing – add it and report that it was newly inserted.
|
# Hash was missing - add it and report that it was newly inserted.
|
||||||
password_hashes.add(hash_value)
|
password_hashes.add(hash_value)
|
||||||
save_hashes()
|
save_hashes()
|
||||||
return True
|
return True
|
||||||
|
|||||||
2
build.sh
2
build.sh
@ -1 +1 @@
|
|||||||
docker build -t pwdgen-v2 /opt/containers/pwdgen-v2
|
docker build -t pwdgen-v2 .
|
||||||
|
|||||||
@ -6,7 +6,8 @@ services:
|
|||||||
image: pwdgen_v2:latest
|
image: pwdgen_v2:latest
|
||||||
container_name: pwd.matt-cloud.com
|
container_name: pwd.matt-cloud.com
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "8080:80"
|
||||||
volumes:
|
volumes:
|
||||||
- ./pwdgen:/opt/pwdgen
|
- ./pwdgen:/opt/pwdgen
|
||||||
|
network_mode: bridge
|
||||||
restart: always
|
restart: always
|
||||||
|
|||||||
@ -92,7 +92,7 @@ function curlHelper($url, $APIKey){
|
|||||||
|
|
||||||
// Password Generator API Function
|
// Password Generator API Function
|
||||||
function getStandardPasswordFromAPI($passType){
|
function getStandardPasswordFromAPI($passType){
|
||||||
$apiUrl = "http://172.17.0.1:8189/get_password";
|
$apiUrl = "http://0.0.0.0:8189/get_password";
|
||||||
// Build the query string and full URL
|
// Build the query string and full URL
|
||||||
$query = http_build_query(['pwd_index' => $passType]);
|
$query = http_build_query(['pwd_index' => $passType]);
|
||||||
$url = rtrim($apiUrl, '?') . '?' . $query;
|
$url = rtrim($apiUrl, '?') . '?' . $query;
|
||||||
@ -101,7 +101,7 @@ function getStandardPasswordFromAPI($passType){
|
|||||||
|
|
||||||
// Password Generator API Function for Custom Password
|
// Password Generator API Function for Custom Password
|
||||||
function getCustomPasswordFromAPI($passType, $payload){
|
function getCustomPasswordFromAPI($passType, $payload){
|
||||||
$url = 'http://172.17.0.1:8189/custom_password';
|
$url = 'http://0.0.0.0:8189/custom_password';
|
||||||
|
|
||||||
// Initialise a cURL handle
|
// Initialise a cURL handle
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
@ -159,7 +159,7 @@ function getCustomPasswordFromAPI($passType, $payload){
|
|||||||
|
|
||||||
// Password Count API Function
|
// Password Count API Function
|
||||||
function getPasswordCountFromAPI(){
|
function getPasswordCountFromAPI(){
|
||||||
$apiUrl = "http://172.17.0.1:8189/get_count";
|
$apiUrl = "http://0.0.0.0:8189/get_count";
|
||||||
// Build the query string and full URL
|
// Build the query string and full URL
|
||||||
$url = rtrim($apiUrl, '?') ;
|
$url = rtrim($apiUrl, '?') ;
|
||||||
return curlHelper($url, "total_passwords");
|
return curlHelper($url, "total_passwords");
|
||||||
|
|||||||
Reference in New Issue
Block a user