diff --git a/.dockerignore b/.dockerignore index 5c4b692e..c32acde3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,3 +11,4 @@ README.md .gitattributes .gitignore debug.sh +public/impressum.html diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..1d953f4b --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore index 121d0d6d..98948b21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .env -.env.dev +dev.env discordguild.php f.php test.php @@ -23,3 +23,5 @@ buildpush.sh html/install-php-extensions composer.lock info.php +*.env +!example.*.env diff --git a/README.md b/README.md index 99a72b25..0347a5fd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,23 @@ # DevCord Devmarkt ## setup dev environment -- copy .env.dev.example to .env.dev +- copy example.dev.env to dev.env - enter all properties - add the bot to your server - run `docker compose -f compose.debug.yaml up` + +## Impressum +To provide an impressum, you can either: + +1. **Use the default template**: Fill in the following environment variables in your `.env` file: + - `IMPRESSUM_NAME` + - `IMPRESSUM_STREET` + - `IMPRESSUM_CITY` + - `IMPRESSUM_EMAIL` + +2. **Mount a custom file**: Create an `impressum.html` file in the `public` directory or mount it via docker-compose: +```yaml +volumes: + - ./impressum.html:/var/www/public/impressum.html +``` +If `public/impressum.html` exists (either in the image or mounted), it will be used instead of the template. diff --git a/compose.debug.yaml b/compose.debug.yaml index bde2943e..76d1ab06 100644 --- a/compose.debug.yaml +++ b/compose.debug.yaml @@ -1,8 +1,7 @@ services: mysql: container_name: mysql_dev - image: mysql - command: --default-authentication-plugin=mysql_native_password + image: mysql:9.7 environment: MYSQL_ROOT_PASSWORD: test MYSQL_DATABASE: test @@ -15,6 +14,9 @@ services: - "8080:80" volumes: - ./:/var/www/ + # - ./impressum.html:/var/www/public/impressum.html + depends_on: + - mysql environment: MYSQL_HOST: mysql_dev MYSQL_DATABASE: test @@ -22,4 +24,4 @@ services: MYSQL_PASSWORD: test BOT_REDIRECT_URI: http://localhost:8080/login.php? BOT_BASE_URI: http://localhost:8080 - env_file: .env.dev + env_file: dev.env diff --git a/compose.yaml b/compose.yaml index b56755ea..d39571fa 100644 --- a/compose.yaml +++ b/compose.yaml @@ -6,6 +6,7 @@ services: dockerfile: Dockerfile volumes: - ./:/var/www/ + # - ./impressum.html:/var/www/public/impressum.html ports: - "8080:80" env_file: .env diff --git a/debug.Dockerfile b/debug.Dockerfile index 5901d11a..2a67964f 100644 --- a/debug.Dockerfile +++ b/debug.Dockerfile @@ -39,5 +39,6 @@ RUN chown -R www-data:www-data /var/www COPY docker/start-apache /usr/local/bin ENV APP_PATH=/var/www +COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf CMD ["start-apache"] diff --git a/docker/000-default.conf b/docker/000-default.conf index ab07a88d..e18959d1 100644 --- a/docker/000-default.conf +++ b/docker/000-default.conf @@ -1,8 +1,8 @@ ServerAdmin webmaster@localhost - DocumentRoot /var/www + DocumentRoot /var/www/public - + Options Indexes FollowSymLinks AllowOverride All Require all granted diff --git a/docker/start-apache b/docker/start-apache index f68e5d6f..66b30d85 100755 --- a/docker/start-apache +++ b/docker/start-apache @@ -1,4 +1,15 @@ #!/usr/bin/env bash + +# Generate impressum from template if it doesn't exist +if [ ! -f /var/www/public/impressum.html ]; then + echo "Generating /var/www/public/impressum.html from template..." + cp /var/www/docker/templates/impressum.html.template /var/www/public/impressum.html + sed -i "s/IMPRESSUM_NAME/${IMPRESSUM_NAME:-}/g" /var/www/public/impressum.html + sed -i "s/IMPRESSUM_STREET/${IMPRESSUM_STREET:-}/g" /var/www/public/impressum.html + sed -i "s/IMPRESSUM_CITY/${IMPRESSUM_CITY:-}/g" /var/www/public/impressum.html + sed -i "s/IMPRESSUM_EMAIL/${IMPRESSUM_EMAIL:-}/g" /var/www/public/impressum.html +fi + sed -i "s/Listen 80/Listen ${PORT:-80}/g" /etc/apache2/ports.conf sed -i "s/:80/:${PORT:-80}/g" /etc/apache2/sites-enabled/* apache2-foreground \ No newline at end of file diff --git a/impressum.html b/docker/templates/impressum.html.template similarity index 94% rename from impressum.html rename to docker/templates/impressum.html.template index b7486f01..7b78028e 100644 --- a/impressum.html +++ b/docker/templates/impressum.html.template @@ -2,7 +2,7 @@ - Datenschutzerklärung - DevCord + Impressum - DevCord @@ -13,9 +13,9 @@

Impressum

Angaben gemäß § 5 TMG

- Max Schlosser
- Großbrösern 4
- 02627 Radibor + IMPRESSUM_NAME
+ IMPRESSUM_STREET
+ IMPRESSUM_CITY

@@ -24,7 +24,7 @@

Angaben gemäß § 5 TMG

Kontakt

-

E-Mail: kontakt@max-schlosser.de

+

E-Mail: IMPRESSUM_EMAIL

Wir sind nicht bereit oder verpflichtet, an Streitbeilegungsverfahren vor einer diff --git a/.env.dev.example b/example.dev.env similarity index 68% rename from .env.dev.example rename to example.dev.env index e49ebf82..f825b917 100644 --- a/.env.dev.example +++ b/example.dev.env @@ -1,6 +1,7 @@ BOT_TOKEN="" BOT_CLIENT_SECRET="" BOT_CLIENT_ID="" + GUILD_DEVMARKT_REQUEST_CHANNEL="" GUILD_DEVMARKT_CHANNEL="" GUILD_ID="" @@ -10,4 +11,9 @@ CHECK_EMOTE="" BLOCK_EMOTE="" BOT_ACCESS_TOKEN="" THREAD_TYPE="" -MAX_DESCRIPTION_SIZE="" \ No newline at end of file +MAX_DESCRIPTION_SIZE="" + +IMPRESSUM_NAME="" +IMPRESSUM_STREET="" +IMPRESSUM_CITY="" +IMPRESSUM_EMAIL="" \ No newline at end of file diff --git a/.env.example b/example.env similarity index 76% rename from .env.example rename to example.env index c609a684..2b347a66 100644 --- a/.env.example +++ b/example.env @@ -19,4 +19,9 @@ BOT_REDIRECT_URI="" BOT_BASE_URI="" BOT_ACCESS_TOKEN="" -MAX_DESCRIPTION_SIZE="" \ No newline at end of file +MAX_DESCRIPTION_SIZE="" + +IMPRESSUM_NAME="" +IMPRESSUM_STREET="" +IMPRESSUM_CITY="" +IMPRESSUM_EMAIL="" \ No newline at end of file diff --git a/pdo.php b/pdo.php deleted file mode 100644 index 37b60511..00000000 --- a/pdo.php +++ /dev/null @@ -1,87 +0,0 @@ -host = getenv("MYSQL_HOST"); - $this->database = getenv("MYSQL_DATABASE"); - $this->username = getenv("MYSQL_USER"); - $this->password = getenv("MYSQL_PASSWORD"); - $options = array( - PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, - PDO::ATTR_PERSISTENT => false, - ); - $this->pdo = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->database, $this->username, $this->password, $options); - $this->loadTables(); - - } - - public function loadTables() - { - - $pdoConnection = $this->getPDO(); - - $stmt = 'CREATE TABLE IF NOT EXISTS `dc_users` ( `id` INT NOT NULL AUTO_INCREMENT , `discord_id` VARCHAR(255) NOT NULL , `auth_code` VARCHAR(255) NOT NULL , `refresh_code` VARCHAR(255) NOT NULL , `rang` VARCHAR(50) NOT NULL , `login_token` VARCHAR(255),`blocked` BOOLEAN, `thread` VARCHAR(200) NULL DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;'; - $qry = $pdoConnection->prepare($stmt); - $qry->execute(); - - $stmt1 = 'CREATE TABLE `anfragen` ( `id` INT NOT NULL AUTO_INCREMENT , `by_discord_id` VARCHAR(255) NOT NULL , `title` VARCHAR(100) NOT NULL , `type` VARCHAR(20) NOT NULL , `description` VARCHAR(' . getenv("MAX_DESCRIPTION_SIZE") . ') NOT NULL , `link` VARCHAR(100) NOT NULL , `req_id` VARCHAR(100) NOT NULL , `status` VARCHAR(100) NOT NULL , `processed_by` VARCHAR(100) NOT NULL ,`message_id` VARCHAR(100),`date` VARCHAR(100),`date_processed` VARCHAR(100),`color` VARCHAR(100),`reason` VARCHAR(500),`options` VARCHAR(200), PRIMARY KEY (`id`)) ENGINE = InnoDB;'; - $qry1 = $pdoConnection->prepare($stmt1); - $qry1->execute(); - - } - - public function getPDO() - { - - return $this->pdo; - - } - - public function close() - { - - $this->pdo->close(); - - } - - public function query($qry) - { - return $this->pdo->query($qry); - - } - - public function inTable($table, $column, $user) - { - - $pdoConnection = $this->pdo; - - $stmt = "SELECT * FROM `" . $table . "` WHERE `" . $column . "`=:user"; - $qry = $pdoConnection->prepare($stmt); - $qry->bindParam(":user", $user); - $qry->execute(); - - if ($qry->fetchColumn() == 0) { - return false; - } - return true; - } - -} - -?> diff --git a/php/devmarkt.inc.php b/php/devmarkt.inc.php index 402aacf1..b40e8830 100644 --- a/php/devmarkt.inc.php +++ b/php/devmarkt.inc.php @@ -1,5 +1,5 @@ isBlocked()) { - header('Location: index.php'); + header('Location: ' . $base_url . '/index.php'); } if ($login->isOnCoolDown() && !($login->isModerator())) { - header('Location: index.php'); + header('Location: ' . $base_url . '/index.php'); } if (!(isset($_POST['titel'], $_POST['type'], $_POST['beschreibung'], $_POST['color']))) { diff --git a/php/pdo.php b/php/pdo.php index 22b73bfc..37b60511 100644 --- a/php/pdo.php +++ b/php/pdo.php @@ -1,2 +1,87 @@ host = getenv("MYSQL_HOST"); + $this->database = getenv("MYSQL_DATABASE"); + $this->username = getenv("MYSQL_USER"); + $this->password = getenv("MYSQL_PASSWORD"); + $options = array( + PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, + PDO::ATTR_PERSISTENT => false, + ); + $this->pdo = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->database, $this->username, $this->password, $options); + $this->loadTables(); + + } + + public function loadTables() + { + + $pdoConnection = $this->getPDO(); + + $stmt = 'CREATE TABLE IF NOT EXISTS `dc_users` ( `id` INT NOT NULL AUTO_INCREMENT , `discord_id` VARCHAR(255) NOT NULL , `auth_code` VARCHAR(255) NOT NULL , `refresh_code` VARCHAR(255) NOT NULL , `rang` VARCHAR(50) NOT NULL , `login_token` VARCHAR(255),`blocked` BOOLEAN, `thread` VARCHAR(200) NULL DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;'; + $qry = $pdoConnection->prepare($stmt); + $qry->execute(); + + $stmt1 = 'CREATE TABLE `anfragen` ( `id` INT NOT NULL AUTO_INCREMENT , `by_discord_id` VARCHAR(255) NOT NULL , `title` VARCHAR(100) NOT NULL , `type` VARCHAR(20) NOT NULL , `description` VARCHAR(' . getenv("MAX_DESCRIPTION_SIZE") . ') NOT NULL , `link` VARCHAR(100) NOT NULL , `req_id` VARCHAR(100) NOT NULL , `status` VARCHAR(100) NOT NULL , `processed_by` VARCHAR(100) NOT NULL ,`message_id` VARCHAR(100),`date` VARCHAR(100),`date_processed` VARCHAR(100),`color` VARCHAR(100),`reason` VARCHAR(500),`options` VARCHAR(200), PRIMARY KEY (`id`)) ENGINE = InnoDB;'; + $qry1 = $pdoConnection->prepare($stmt1); + $qry1->execute(); + + } + + public function getPDO() + { + + return $this->pdo; + + } + + public function close() + { + + $this->pdo->close(); + + } + + public function query($qry) + { + return $this->pdo->query($qry); + + } + + public function inTable($table, $column, $user) + { + + $pdoConnection = $this->pdo; + + $stmt = "SELECT * FROM `" . $table . "` WHERE `" . $column . "`=:user"; + $qry = $pdoConnection->prepare($stmt); + $qry->bindParam(":user", $user); + $qry->execute(); + + if ($qry->fetchColumn() == 0) { + return false; + } + return true; + } + +} + +?> diff --git a/assets/css/style.css b/public/assets/css/style.css similarity index 100% rename from assets/css/style.css rename to public/assets/css/style.css diff --git a/assets/css/styles.css b/public/assets/css/styles.css similarity index 100% rename from assets/css/styles.css rename to public/assets/css/styles.css diff --git a/assets/fonts/Inter-Medium.ttf b/public/assets/fonts/Inter-Medium.ttf similarity index 100% rename from assets/fonts/Inter-Medium.ttf rename to public/assets/fonts/Inter-Medium.ttf diff --git a/assets/fonts/Raleway-Black.ttf b/public/assets/fonts/Raleway-Black.ttf similarity index 100% rename from assets/fonts/Raleway-Black.ttf rename to public/assets/fonts/Raleway-Black.ttf diff --git a/assets/fonts/Roboto-Light.ttf b/public/assets/fonts/Roboto-Light.ttf similarity index 100% rename from assets/fonts/Roboto-Light.ttf rename to public/assets/fonts/Roboto-Light.ttf diff --git a/assets/img/favicon.png b/public/assets/img/favicon.png similarity index 100% rename from assets/img/favicon.png rename to public/assets/img/favicon.png diff --git a/assets/img/favicon_christmas.png b/public/assets/img/favicon_christmas.png similarity index 100% rename from assets/img/favicon_christmas.png rename to public/assets/img/favicon_christmas.png diff --git a/assets/img/favicon_old.png b/public/assets/img/favicon_old.png similarity index 100% rename from assets/img/favicon_old.png rename to public/assets/img/favicon_old.png diff --git a/assets/img/pattern_christmas.png b/public/assets/img/pattern_christmas.png similarity index 100% rename from assets/img/pattern_christmas.png rename to public/assets/img/pattern_christmas.png diff --git a/assets/img/snow.svg b/public/assets/img/snow.svg similarity index 100% rename from assets/img/snow.svg rename to public/assets/img/snow.svg diff --git a/assets/img/trianglify.svg b/public/assets/img/trianglify.svg similarity index 100% rename from assets/img/trianglify.svg rename to public/assets/img/trianglify.svg diff --git a/assets/js/index.js b/public/assets/js/index.js similarity index 100% rename from assets/js/index.js rename to public/assets/js/index.js diff --git a/case.php b/public/case.php similarity index 97% rename from case.php rename to public/case.php index 1b5476a1..0661c287 100644 --- a/case.php +++ b/public/case.php @@ -1,10 +1,9 @@ -

+ diff --git a/user.php b/public/user.php similarity index 97% rename from user.php rename to public/user.php index 57d858cd..34aebbef 100644 --- a/user.php +++ b/public/user.php @@ -1,9 +1,9 @@ {}, ... }: + +pkgs.mkShell { + packages = with pkgs; [php85 php85Packages.composer]; +}