Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGillam committed Aug 14, 2024
2 parents bb15f87 + c1e4c3c commit 175dc0b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ jobs:
docker build . --file .shogun/Dockerfile.dojo-basic-lite --tag dojo-basic-lite
docker tag dojo-basic-lite $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name : Build and push scavanger-lite image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/dojo-scavenger-lite
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker build . --file .shogun/Dockerfile.dojo-scavenger-lite --tag dojo-scavenger-lite
docker tag dojo-scavenger-lite $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
29 changes: 29 additions & 0 deletions .shogun/Dockerfile.dojo-scavenger-lite
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Dockerfile.dojo-scavenger
FROM php:7.4-apache

# Install SQLite and PHP SQLite extension
RUN apt-get update && apt-get install -y sqlite3 libsqlite3-dev
RUN docker-php-ext-install pdo pdo_sqlite

# Set environment variable for database type
ENV DOJO_DB_TYPE sqlite

# Create the db directory and set permissions
RUN mkdir -p /var/www/html/db && \
chmod 755 /var/www/html/db

# Copy application files
COPY ./src/scavenger /var/www/html

# Add error logging
RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/php.ini && \
echo "display_errors = On" >> /usr/local/etc/php/php.ini && \
echo "log_errors = On" >> /usr/local/etc/php/php.ini && \
echo "error_log = /var/log/php_errors.log" >> /usr/local/etc/php/php.ini

# Run init db script
RUN php /var/www/html/init_lite_db.php

LABEL org.opencontainers.image.source=https://github.com/SamuraiWTF/samurai-dojo
LABEL org.opencontainers.image.description="Basic PHP 7.4-apache image with dojo-scavenger and SQLite/MySQL support."
LABEL org.opencontainers.image.licenses="lgpl"
10 changes: 10 additions & 0 deletions .shogun/docker-compose-dojo-scavenger-lite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'
services:
dojo-scavenger-lite:
build:
context: ..
dockerfile: .shogun/Dockerfile.dojo-scavenger-lite
ports:
- "8081:80"
environment:
- DOJO_DB_TYPE=sqlite
21 changes: 21 additions & 0 deletions src/scavenger/init_lite_db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
$sqlite_db = '/var/www/html/db/scavenger.sqlite';
$db = new SQLite3($sqlite_db);

// Create table
$db->exec("CREATE TABLE IF NOT EXISTS partners_data (
partner_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT,
password TEXT
)");

// Insert initial data
$db->exec("INSERT OR IGNORE INTO partners_data (username, password) VALUES
('kevin', 'brenna'),
('justin', 'meeas'),
('key13', 'ed265bc903a5a097f61d3ec064d96d2e'),
('key', 'boomerang')");

echo "Database initialized successfully.";
$db->close();
?>
33 changes: 31 additions & 2 deletions src/scavenger/partners.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
$db_type = getenv('DOJO_DB_TYPE') ?: 'mysql';

if ($db_type === 'mysql') {
// Original MySQL code (unchanged)
if (!empty($_POST["username"])) {
$dbconn = mysqli_connect("scavengerdb", "root", "samurai") or die(mysqli_error());
mysqli_select_db($dbconn, "samurai_dojo_scavenger");
Expand All @@ -9,9 +13,34 @@
exit();
}
}
} else {
if (!empty($_POST["username"])) {
$sqlite_db = '/var/www/html/db/scavenger.sqlite';
$db = new SQLite3($sqlite_db);

$query = "SELECT * FROM partners_data WHERE username = '" . $_POST["username"] . "'";
$resultset = $db->query($query);

$result = $resultset->fetchArray(SQLITE3_ASSOC);

if ($result !== false) {
if ($_POST["password"] == $result["password"]) {
header("Location: partner_main.php?username=".$result["username"]);
exit();
} else {
$error = "Invalid password";
}
} else {
$error = "User not found";
}

$db->close();
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- ========================================================== -->
<!-- Created by Devit Schizoper -->
<!-- Created HomePages http://LoadFoo.starzonewebhost.com -->
Expand Down Expand Up @@ -80,4 +109,4 @@
</div>

</body>
</html>
</html>

0 comments on commit 175dc0b

Please sign in to comment.