aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2025-02-01 17:06:10 +0200
committerSyndamia <kamen@syndamia.com>2025-02-01 17:06:10 +0200
commit02995bfe9827c0c329c9c397411d83bd6918d096 (patch)
tree5b44dfb3c18000e201da40976f2f51158c8fc423
parent61c5b503352c983d4e532b5a59e2ae913e53e70c (diff)
downloadnowayforward_human-02995bfe9827c0c329c9c397411d83bd6918d096.tar
nowayforward_human-02995bfe9827c0c329c9c397411d83bd6918d096.tar.gz
nowayforward_human-02995bfe9827c0c329c9c397411d83bd6918d096.zip
feat: Add XAMPP setup
-rw-r--r--apache/httpd.conf.tpl4
-rw-r--r--apache/sites/nowayforward_human.conf.tpl15
-rw-r--r--controllers/archive.php2
-rw-r--r--migrations/01-default-data.sql2
-rw-r--r--models/database.php19
-rw-r--r--views/global/router.php9
-rw-r--r--xampp/setup.php44
7 files changed, 82 insertions, 13 deletions
diff --git a/apache/httpd.conf.tpl b/apache/httpd.conf.tpl
index 950ff21..5dafc78 100644
--- a/apache/httpd.conf.tpl
+++ b/apache/httpd.conf.tpl
@@ -30,7 +30,3 @@ User ${USER}
Group users
AddType application/javascript .js
-
-SetEnv MYSQL_UNIX_SOCKET ${MYSQL_UNIX_SOCKET}
-SetEnv USER ${USER}
-SetEnv ARCHIVES_DIR ${ARCHIVES_DIR}
diff --git a/apache/sites/nowayforward_human.conf.tpl b/apache/sites/nowayforward_human.conf.tpl
index 2a5f58f..637ee4f 100644
--- a/apache/sites/nowayforward_human.conf.tpl
+++ b/apache/sites/nowayforward_human.conf.tpl
@@ -4,9 +4,21 @@
Alias /archives "${ARCHIVES_DIR}"
<FilesMatch \.php$>
- SetHandler "proxy:unix:${PHP_FPM_SOCKET}|fcgi://localhost/"
+ <If "'${PHP_FPM_SOCKET}' != ''">
+ SetHandler "proxy:unix:${PHP_FPM_SOCKET}|fcgi://localhost/"
+ </If>
</FilesMatch>
+ # Database
+ SetEnv SERVER ${SERVER}
+ SetEnv PORT ${PORT}
+ SetEnv USER ${USER}
+ SetEnv PASSWORD ${PASSWORD}
+ SetEnv MYSQL_UNIX_SOCKET ${MYSQL_UNIX_SOCKET}
+
+ # Project
+ SetEnv ARCHIVES_DIR ${ARCHIVES_DIR}
+
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
@@ -14,6 +26,5 @@
RewriteCond %{REQUEST_URI} !/archives.*
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
- RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /global/router.php
</VirtualHost>
diff --git a/controllers/archive.php b/controllers/archive.php
index 70f2b6d..ae25482 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -380,7 +380,7 @@ class DownloadPage {
// Add the header for the archives
$phpTag = $dom->createElement('script', '
</script>
- <?php require_once "' . __DIR__ . '/../views/archive/topbar.php" ?>
+ <?php require_once \'' . __DIR__ . '/../views/archive/topbar.php\' ?>
<script>
');
$body = $dom->getElementsByTagName('body')->item(0);
diff --git a/migrations/01-default-data.sql b/migrations/01-default-data.sql
index ba8ed97..5168d41 100644
--- a/migrations/01-default-data.sql
+++ b/migrations/01-default-data.sql
@@ -1,4 +1,4 @@
USE nwfh;
-INSERT INTO Users (Username, Password, Role)
+INSERT IGNORE INTO Users (Username, Password, Role)
VALUES ("Anon", "", "User");
diff --git a/models/database.php b/models/database.php
index dc177e8..8efd20c 100644
--- a/models/database.php
+++ b/models/database.php
@@ -62,10 +62,21 @@ abstract class Table {
}
static protected function connect() : PDO {
- $conn = new PDO(
- "mysql:unix_socket=" . getenv('MYSQL_UNIX_SOCKET') . ";dbname=nwfh",
- getenv('USER'),
- "");
+ $unix_socket = getenv('MYSQL_UNIX_SOCKET');
+ $conn = null;
+ // Windows support
+ if ($unix_socket == '') {
+ $conn = new PDO(
+ "mysql:host=" . getenv('SERVER') . ";port=" . getenv('PORT') . ";dbname=nwfh",
+ getenv('USER'),
+ getenv('PASSWORD'));
+ }
+ else {
+ $conn = new PDO(
+ "mysql:unix_socket=$unix_socket;dbname=nwfh",
+ getenv('USER'),
+ getenv('PASSWORD'));
+ }
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
diff --git a/views/global/router.php b/views/global/router.php
index ea5aa42..9025113 100644
--- a/views/global/router.php
+++ b/views/global/router.php
@@ -4,7 +4,14 @@ $VIEWS_DIR = __DIR__ . '/..';
$CONTROLLERS_DIR = __DIR__ . '/../../controllers';
$MODELS_DIR = __DIR__ . '/../../models';
-$uri = rtrim($_SERVER['REQUEST_URI'], '/');
+$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
+
+if ($uri === '/nowayforward_human/xampp/setup.php') {
+ http_response_code(301); // Permanent redirect
+ header('Location: /');
+ exit;
+}
+
$exploded = @explode('/', $uri, 4);
$root = '/' . @$exploded[1];
$subroot = '/' . @$exploded[2];
diff --git a/xampp/setup.php b/xampp/setup.php
new file mode 100644
index 0000000..6f8946f
--- /dev/null
+++ b/xampp/setup.php
@@ -0,0 +1,44 @@
+<?php
+$SERVER = 'localhost';
+$PORT = 3306;
+$USER = 'root';
+$PASSWORD = '';
+
+$REPOSITORY = dirname(__DIR__);
+$ARCHIVES_DIR = $REPOSITORY . '/.archives';
+$PHP_FPM_SOCKET = '';
+$MYSQL_UNIX_SOCKET = '';
+
+echo "Preparing database...";
+$conn = new PDO(
+ "mysql:host=$SERVER;port=$PORT",
+ $USER,
+ $PASSWORD
+);
+
+$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+foreach (glob(__DIR__ . '/../migrations/*.sql') as $migration) {
+ $query = file_get_contents($migration);
+ $conn->exec($query);
+ echo ".";
+}
+
+echo "Success";
+
+echo "</br>Preparing Apache...";
+
+$vhost = file_get_contents(__DIR__ . '/../apache/sites/nowayforward_human.conf.tpl');
+$vhost = str_replace(8000, 80, $vhost);
+preg_match_all('/\${([^}]*)}/', $vhost, $envVars);
+
+foreach ($envVars[1] as $var) {
+ $vhost = str_replace("\${{$var}}", $$var, $vhost);
+ echo '.';
+}
+
+file_put_contents('../../../apache/conf/extra/httpd-vhosts.conf', $vhost);
+
+echo 'Success';
+
+echo '<h1>Setup complete! Restart apache!</h1>';