docker container is working
This commit is contained in:
20
Dockerfile
20
Dockerfile
@ -2,25 +2,35 @@
|
|||||||
# Base image - PHP + Apache
|
# Base image - PHP + Apache
|
||||||
FROM php:apache
|
FROM php:apache
|
||||||
|
|
||||||
# Install Python, NGINX, Supervisor and pip
|
# Install Python
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
python3 \
|
python3 \
|
||||||
python3-pip \
|
python3-pip \
|
||||||
|
python3-dev \
|
||||||
|
python3-setuptools \
|
||||||
|
python3-venv \
|
||||||
python3-flask \
|
python3-flask \
|
||||||
python3-yaml \
|
python3-yaml
|
||||||
|
|
||||||
|
# Install Other Stuff
|
||||||
|
RUN apt-get install -y \
|
||||||
nginx \
|
nginx \
|
||||||
supervisor \
|
supervisor \
|
||||||
net-tools \
|
net-tools \
|
||||||
iputils-ping \
|
iputils-ping \
|
||||||
|
nano \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy your application code & config files
|
# remove default nginx config
|
||||||
|
RUN rm -rf /etc/nginx/sites-enabled/default
|
||||||
|
|
||||||
|
# Copy application files
|
||||||
# Website Files
|
# Website Files
|
||||||
COPY www/ /var/www/html
|
COPY www/ /var/www/html
|
||||||
# Python files
|
# Python files
|
||||||
COPY api/ /usr/src/app/
|
COPY api/ /usr/src/app/
|
||||||
# Config Files
|
# Config Files
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY apache_ports.conf /etc/apache2/ports.conf
|
COPY apache_ports.conf /etc/apache2/ports.conf
|
||||||
COPY apache_vhost.conf /etc/apache2/sites-available/000-default.conf
|
COPY apache_vhost.conf /etc/apache2/sites-available/000-default.conf
|
||||||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||||
@ -28,5 +38,7 @@ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
|||||||
# Expose the ports you care about
|
# Expose the ports you care about
|
||||||
EXPOSE 80 8080 5000
|
EXPOSE 80 8080 5000
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Start Supervisor
|
# Start Supervisor
|
||||||
CMD ["/usr/bin/supervisord", "-n"]
|
CMD ["/usr/bin/supervisord", "-n"]
|
||||||
@ -1,4 +1,6 @@
|
|||||||
# pwd.matt-cloud.com
|
# pwd.matt-cloud.com
|
||||||
Password Generator I built a while ago because I was sick of doing it manually. I have now updated it to use a Python API backend, tidied up the PHP code, and added some CSS to make it look nicer.
|
Password Generator I built a while ago because I was sick of doing it manually. I have now updated it to use a Python API backend, tidied up the PHP code, and added some CSS to make it look nicer.
|
||||||
|
|
||||||
I am still testing the docker image.
|
This works with a Python API backend for password generation and tracking with a PHP-based front-end for selecting the password type and rating its strength.
|
||||||
|
|
||||||
|
There is still a lot of logic in the PHP site, though I think I will offload more processing to the python back-end to allow future extensibility. I think if I moved all the information about all the passwords to the Python service, I could change the PHP site to dynamically generate itself based on the amount of password types from the server.
|
||||||
@ -18,7 +18,7 @@ simple_words = []
|
|||||||
|
|
||||||
password_hashes =set()
|
password_hashes =set()
|
||||||
SPECIAL_SET = "!@#$%^&*(),.<>?~`;:|][}{=-+_"
|
SPECIAL_SET = "!@#$%^&*(),.<>?~`;:|][}{=-+_"
|
||||||
WORDS_FILE = "dict.yaml"
|
WORDS_FILE = "/usr/src/app/dict.yaml"
|
||||||
password_types = [
|
password_types = [
|
||||||
"generate_standard_password",
|
"generate_standard_password",
|
||||||
"generate_windows_ad_password",
|
"generate_windows_ad_password",
|
||||||
|
|||||||
@ -6,8 +6,19 @@ services:
|
|||||||
image: pwdgen_v2:latest
|
image: pwdgen_v2:latest
|
||||||
container_name: pwd.matt-cloud.com
|
container_name: pwd.matt-cloud.com
|
||||||
ports:
|
ports:
|
||||||
- "8080:80"
|
- "10.19.1.1:80:80"
|
||||||
volumes:
|
volumes:
|
||||||
|
# hash file goes here for count and uniqueness
|
||||||
- ./pwdgen:/opt/pwdgen
|
- ./pwdgen:/opt/pwdgen
|
||||||
network_mode: bridge
|
networks:
|
||||||
|
- net
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
networks:
|
||||||
|
net:
|
||||||
|
driver: bridge
|
||||||
|
ipam:
|
||||||
|
driver: default
|
||||||
|
config:
|
||||||
|
-
|
||||||
|
subnet: 10.19.1.0/24
|
||||||
|
|||||||
91
nginx.conf
91
nginx.conf
@ -1,67 +1,44 @@
|
|||||||
# nginx.conf
|
# /etc/nginx/conf.d/default.conf
|
||||||
# This file will be mounted into /etc/nginx/conf.d/default.conf inside the container
|
# This file is mounted into the container at the same location.
|
||||||
|
|
||||||
# Enable proxy buffers (optional but recommended)
|
# ------------------------------------------------------------------
|
||||||
proxy_buffering on;
|
# 1. Common proxy-headers (set once, use everywhere)
|
||||||
proxy_buffers 16 16k;
|
# ------------------------------------------------------------------
|
||||||
proxy_buffer_size 32k;
|
# These are forwarded to *every* upstream that Nginx talks to.
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 2. Server block
|
||||||
|
# ------------------------------------------------------------------
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80 default_server;
|
||||||
server_name pwdgwn_v2;
|
server_name _; # Catch-all - change to your domain if you need a specific name.
|
||||||
|
|
||||||
# ---------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# API Routes
|
# 3. API routes - all hit the same Flask app (localhost:5000)
|
||||||
# ---------------------------------------
|
# ------------------------------------------------------------------
|
||||||
location = /get_password {
|
# A single location with a regex is cleaner than five almost-identical
|
||||||
proxy_pass http://localhost:5000/get_password;
|
# blocks. The regex matches the exact paths you listed.
|
||||||
proxy_set_header Host $host;
|
location ~ ^/(get_password|verbose_password|custom_password|get_count|get_info)$ {
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_pass http://localhost:5000; # Forward *exactly* the same URI
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_redirect off; # Preserve any redirects from Flask
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /verbose_password {
|
# ------------------------------------------------------------------
|
||||||
proxy_pass http://localhost:5000/verbose_password;
|
# 4. All other requests go to Apache/PHP (localhost:8080)
|
||||||
proxy_set_header Host $host;
|
# ------------------------------------------------------------------
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
location = /custom_password {
|
|
||||||
proxy_pass http://localhost:5000/custom_password;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
location = /get_count {
|
|
||||||
proxy_pass http://localhost:5000/get_count;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
location = /get_info {
|
|
||||||
proxy_pass http://localhost:5000/get_info;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------
|
|
||||||
# All other paths → Apache (PHP)
|
|
||||||
# ---------------------------------------
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://localhost:8080;
|
proxy_pass http://localhost:8080;
|
||||||
proxy_set_header Host $host;
|
proxy_redirect off; # (optional but safe)
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 5. Optional timeout tuning - adjust to your workload
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
proxy_connect_timeout 10s;
|
||||||
|
proxy_send_timeout 60s;
|
||||||
|
proxy_read_timeout 60s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ redirect_stderr=true
|
|||||||
|
|
||||||
[program:python]
|
[program:python]
|
||||||
command=python3 /usr/src/app/app.py
|
command=python3 /usr/src/app/app.py
|
||||||
|
directory=/usr/src/app
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
stdout_logfile=/dev/stdout ; Python → stdout
|
stdout_logfile=/dev/stdout ; Python → stdout
|
||||||
|
|||||||
@ -71,12 +71,14 @@ function curlHelper($url, $APIKey){
|
|||||||
// Handle cURL errors
|
// Handle cURL errors
|
||||||
if ($response === false) {
|
if ($response === false) {
|
||||||
$error = curl_error($ch);
|
$error = curl_error($ch);
|
||||||
curl_close($ch);
|
// Deprecated: Function curl_close() is deprecated since 8.5, as it has no effect since PHP 8.0 in /var/www/html/index.php on line 79
|
||||||
|
//curl_close($ch);
|
||||||
throw new Exception("cURL error while calling API: {$error}");
|
throw new Exception("cURL error while calling API: {$error}");
|
||||||
}
|
}
|
||||||
// Check HTTP status code
|
// Check HTTP status code
|
||||||
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
// Deprecated: Function curl_close() is deprecated since 8.5, as it has no effect since PHP 8.0 in /var/www/html/index.php on line 79
|
||||||
|
//curl_close($ch);
|
||||||
|
|
||||||
if ($httpStatus !== 200) {
|
if ($httpStatus !== 200) {
|
||||||
throw new Exception("API returned HTTP status {$httpStatus} (expected 200).");
|
throw new Exception("API returned HTTP status {$httpStatus} (expected 200).");
|
||||||
@ -92,7 +94,7 @@ function curlHelper($url, $APIKey){
|
|||||||
|
|
||||||
// Password Generator API Function
|
// Password Generator API Function
|
||||||
function getStandardPasswordFromAPI($passType){
|
function getStandardPasswordFromAPI($passType){
|
||||||
$apiUrl = "http://localhost:8189/get_password";
|
$apiUrl = "http://0.0.0.0:5000/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 +103,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://localhost:8189/custom_password';
|
$url = 'http://0.0.0.0:5000/custom_password';
|
||||||
|
|
||||||
// Initialise a cURL handle
|
// Initialise a cURL handle
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
@ -159,7 +161,7 @@ function getCustomPasswordFromAPI($passType, $payload){
|
|||||||
|
|
||||||
// Password Count API Function
|
// Password Count API Function
|
||||||
function getPasswordCountFromAPI(){
|
function getPasswordCountFromAPI(){
|
||||||
$apiUrl = "http://localhost:8189/get_count";
|
$apiUrl = "http://0.0.0.0:5000/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");
|
||||||
@ -248,7 +250,7 @@ $rating = passwordTest_strength($final);
|
|||||||
<strong>Matt-Cloud Password API</strong><p>
|
<strong>Matt-Cloud Password API</strong><p>
|
||||||
To get passwords, you may:<p>
|
To get passwords, you may:<p>
|
||||||
<code>
|
<code>
|
||||||
curl -s https://<?php echo $_SERVER['SERVER_NAME'] ?>/get_password?pwd_index=N<br>
|
curl -s <?php echo (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://" . $_SERVER['SERVER_NAME'] ?>/get_password?pwd_index=N<br>
|
||||||
{<br>
|
{<br>
|
||||||
"password": "-`(UncoloredSwiftly2099"<br>
|
"password": "-`(UncoloredSwiftly2099"<br>
|
||||||
}
|
}
|
||||||
@ -256,7 +258,7 @@ $rating = passwordTest_strength($final);
|
|||||||
Where N is an integer 0,1, or 2 for now.<p>
|
Where N is an integer 0,1, or 2 for now.<p>
|
||||||
To get verbose passwords, you may:<p>
|
To get verbose passwords, you may:<p>
|
||||||
<code>
|
<code>
|
||||||
curl -s https://<?php echo $_SERVER['SERVER_NAME'] ?>/verbose_password?pwd_index=N<br>
|
curl -s <?php echo (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://" . $_SERVER['SERVER_NAME'] ?>/verbose_password?pwd_index=N<br>
|
||||||
{<br>
|
{<br>
|
||||||
"descriptor": {<br>
|
"descriptor": {<br>
|
||||||
"description": "This simple password is in the following format: !Password123 - this pulls from a list of 1291 simple words.",<br>
|
"description": "This simple password is in the following format: !Password123 - this pulls from a list of 1291 simple words.",<br>
|
||||||
@ -269,7 +271,7 @@ $rating = passwordTest_strength($final);
|
|||||||
</code><p>
|
</code><p>
|
||||||
To get custom passwords, you may:<p>
|
To get custom passwords, you may:<p>
|
||||||
<code>
|
<code>
|
||||||
curl -X POST https://<?php echo $_SERVER['SERVER_NAME'] ?>/custom_password \ <br>
|
curl -X POST <?php echo (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://" . $_SERVER['SERVER_NAME'] ?>/custom_password \ <br>
|
||||||
H "Content-Type: application/json" \ <br>
|
H "Content-Type: application/json" \ <br>
|
||||||
d '{ <br>
|
d '{ <br>
|
||||||
"w_min":5, <br>
|
"w_min":5, <br>
|
||||||
@ -284,14 +286,14 @@ $rating = passwordTest_strength($final);
|
|||||||
</code><p>
|
</code><p>
|
||||||
To get the API password count (but why tho?), you may:<p>
|
To get the API password count (but why tho?), you may:<p>
|
||||||
<code>
|
<code>
|
||||||
curl -s https://<?php echo $_SERVER['SERVER_NAME'] ?>/get_count<br>
|
curl -s <?php echo (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://" . $_SERVER['SERVER_NAME'] ?>/get_count<br>
|
||||||
{<br>
|
{<br>
|
||||||
"total_passwords": 10<br>
|
"total_passwords": 10<br>
|
||||||
}
|
}
|
||||||
</code><p>
|
</code><p>
|
||||||
To view the password descriptor, you may <br>
|
To view the password descriptor, you may <br>
|
||||||
<code>
|
<code>
|
||||||
curl -s https://<?php echo $_SERVER['SERVER_NAME'] ?>/get_info<br>
|
curl -s <?php echo (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://" . $_SERVER['SERVER_NAME'] ?>/get_info<br>
|
||||||
</code>
|
</code>
|
||||||
This will return the entire JSON descriptor variable <br>
|
This will return the entire JSON descriptor variable <br>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user