commit c1b4875f4ebad1c37d42855897d93bf33fae1538 Author: Felix Albrigtsen Date: Sat Jan 21 18:39:28 2023 +0100 Initial upload, docker environment diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd732d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/phpdocker/postgres-data + diff --git a/README.md b/README.md new file mode 100644 index 0000000..cd7a342 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# PVVMDB +## A new attempt to keep records of PVV members + +The projects should keep track of some basic member information: +- Usernames of all existing users +- Basic contact information +- Membership payments +- Disk Quota payments + +This will help us keep track of: +- Active and inactive members (based on payment of the membership fee) +- Total disk quota +- Date of registration + +This information gives us the ability to lock inactive user accounts, and keep statistics of our userbase. +Locking inactive accounts is useful for security reasons and to incentivize actually paying the fee. + +## Requirements + +There are two recommended ways of running the application: + +### Docker-compose / dev +The development environment is available through docker, as described below. +This includes a database and all required runtimes. +Requires: + +- Docker +- Docker-compose + +## Production / native +As the application is a normal PHP application, you will need: + +- PHP (Tested with 8.2) +- A web server (e.g. nginx) +- php-pgsql +- A PostgreSQL server + + +## Development + +The project is written in basic PHP, without external frameworks. +The dev environment is built with docker-compose, and contains a PostgreSQL database, php-fpm and nginx. + +Start it by running `docker-compose up -d`. + +You can then view the page at [localhost:3010](http://localhost:3010). + +The database can be administered with [adminer](http://localhost:3010/adminer-4.8.1.php). + +Some docs should probably be written in /docs + +Some tools should probably be made in /utils + +## TODO: + +- Start Web interface +- Input methods: + - [ ] Web form + - [ ] Import from bank statements (PDF/CSV) + - [ ] Import from GNUCash +- Make admin system + - Save list of admins or integrate with www.pvv.ntnu.no/admin/ + - Auth / login, one of: + - SSO with idp.pvv.ntnu.no + - PAM / Unix auth +- Integrate with PVV "New user" scripts +- Allow normal users to update their own contact info? +- ... + + diff --git a/dev.sh b/dev.sh new file mode 100755 index 0000000..7c3e05c --- /dev/null +++ b/dev.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# test -e composer.phar || curl -O https://getcomposer.org/composer.phar + +php -S ${DOCKER_HOST:-[::1]}:${DOCKER_PORT:-1080} -d error_reporting=E_ALL -d display_errors=1 -t src/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..611af42 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +############################################################################### +# Generated on phpdocker.io # +############################################################################### +version: '3.1' +services: + postgres: + image: 'postgres:11.1-alpine' + working_dir: /docker + volumes: + - ./phpdocker/postgres-data:/var/lib/postgresql/data + environment: + - POSTGRES_USER=pvvmdb + - POSTGRES_PASSWORD=pvvmdb + - POSTGRES_DB=pvvmdb + ports: + - '3014:5432' + + webserver: + image: 'nginx:alpine' + working_dir: /docker + volumes: + - ./src:/docker + - ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf + ports: + - '3010:80' + + php-fpm: + build: phpdocker/php-fpm + working_dir: /docker + volumes: + - ./src:/docker + - ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/8.2/fpm/conf.d/99-overrides.ini diff --git a/docs/database_model.png b/docs/database_model.png new file mode 100644 index 0000000..c696957 Binary files /dev/null and b/docs/database_model.png differ diff --git a/docs/database_model.puml b/docs/database_model.puml new file mode 100644 index 0000000..6c55761 --- /dev/null +++ b/docs/database_model.puml @@ -0,0 +1,50 @@ +@startuml + +entity "User" as user { + id: int + -- + * username: string + name: string + phone: string + external_email: string + first_created: date + locked: boolean + comment: string +} + +entity "Purchase" as purchase { + id: int + -- + * _user_id_: int + * amount_paid: number + * date: date + comment: string +} + +entity "Disk Purchase" as disk_purchase { + -- + * size_mb: int +} + +entity "Membership Type" as membership_type { + id: int + -- + * name: string + * price: number + comment: string +} + +entity "Membership Purchase" as membership_purchase { + -- + * _membership_type_id_: int +} + + +user "1..1" -- "0..*" purchase : makes +disk_purchase --|> purchase +membership_purchase --|> purchase + +membership_type "1..1" -- "0..*" membership_purchase : is + + +@enduml diff --git a/phpdocker/README.html b/phpdocker/README.html new file mode 100644 index 0000000..c796f74 --- /dev/null +++ b/phpdocker/README.html @@ -0,0 +1,208 @@ + + + PHPDocker.io Readme + + + + + + +
+
+
+

PHPDocker.io generated environment

+ +

Add to your project

+ +

Simply, unzip the file into your project, this will create docker-compose.yml on the root of your project and a folder +named phpdocker containing nginx and php-fpm config for it.

+ +

Ensure the webserver config on phpdocker/nginx/nginx.conf is correct for your project. PHPDocker.io will have +customised this file according to the front controller location relative to the docker-compose file you chose on the +generator (by default public/index.php).

+ +

Note: you may place the files elsewhere in your project. Make sure you modify the locations for the php-fpm dockerfile, +the php.ini overrides and nginx config on docker-compose.yml if you do so.

+ +

How to run

+ +

Dependencies:

+ + + +

Once you're done, simply cd to your project and run docker-compose up -d. This will initialise and start all the +containers, then leave them running in the background.

+ +

Services exposed outside your environment

+ +

You can access your application via localhost. Mailhog and nginx both respond to any hostname, in case you want to +add your own hostname on your /etc/hosts

+ + + + + + + + + + + + + + + + + + +
ServiceAddress outside containers
Webserverlocalhost:3010
PostgreSQLhost: localhost; port: 3014
+ +

Hosts within your environment

+ +

You'll need to configure your application to use any services you enabled:

+ + + + + + + + + + + + + + + + + + + + + +
ServiceHostnamePort number
php-fpmphp-fpm9000
Postgrespostgres5432 (default)
+ +

Docker compose cheatsheet

+ +

Note: you need to cd first to where your docker-compose.yml file lives.

+ +
    +
  • Start containers in the background: docker-compose up -d
  • +
  • Start containers on the foreground: docker-compose up. You will see a stream of logs for every container running. +ctrl+c stops containers.
  • +
  • Stop containers: docker-compose stop
  • +
  • Kill containers: docker-compose kill
  • +
  • View container logs: docker-compose logs for all containers or docker-compose logs SERVICE_NAME for the logs of +all containers in SERVICE_NAME.
  • +
  • Execute command inside of container: docker-compose exec SERVICE_NAME COMMAND where COMMAND is whatever you want +to run. Examples: + +
      +
    • Shell into the PHP container, docker-compose exec php-fpm bash
    • +
    • Run symfony console, docker-compose exec php-fpm bin/console
    • +
    • Open a mysql shell, docker-compose exec mysql mysql -uroot -pCHOSEN_ROOT_PASSWORD
    • +
  • +
+ +

Application file permissions

+ +

As in all server environments, your application needs the correct file permissions to work properly. You can change the +files throughout the container, so you won't care if the user exists or has the same ID on your host.

+ +

docker-compose exec php-fpm chown -R www-data:www-data /docker/public

+ +

Recommendations

+ +

It's hard to avoid file permission issues when fiddling about with containers due to the fact that, from your OS point +of view, any files created within the container are owned by the process that runs the docker engine (this is usually +root). Different OS will also have different problems, for instance you can run stuff in containers +using docker exec -it -u $(id -u):$(id -g) CONTAINER_NAME COMMAND to force your current user ID into the process, but +this will only work if your host OS is Linux, not mac. Follow a couple of simple rules and save yourself a world of +hurt.

+ +
    +
  • Run composer outside of the php container, as doing so would install all your dependencies owned by root within your +vendor folder.
  • +
  • Run commands (ie Symfony's console, or Laravel's artisan) straight inside of your container. You can easily open a +shell as described above and do your thing from there.
  • +
+ +

Simple basic Xdebug configuration with integration to PHPStorm

+ +

Xdebug 2

+ +

To configure Xdebug 2 you need add these lines in php-fpm/php-ini-overrides.ini:

+ +

For linux:

+ +
xdebug.remote_enable = 1
+xdebug.remote_connect_back = 1
+xdebug.remote_autostart = 1
+
+ +

For macOS and Windows:

+ +
xdebug.remote_enable = 1
+xdebug.remote_host = host.docker.internal
+xdebug.remote_autostart = 1
+
+ +

Xdebug 3

+ +

To configure Xdebug 3 you need add these lines in php-fpm/php-ini-overrides.ini:

+ +

For linux:

+ +
xdebug.mode = debug
+xdebug.remote_connect_back = true
+xdebug.start_with_request = yes
+
+ +

For macOS and Windows:

+ +
xdebug.mode = debug
+xdebug.remote_host = host.docker.internal
+xdebug.start_with_request = yes
+
+ +

Add the section “environment” to the php-fpm service in docker-compose.yml:

+ +
environment:
+  PHP_IDE_CONFIG: "serverName=Docker"
+
+ +

Create a server configuration in PHPStorm:

+ +
    +
  • In PHPStorm open Preferences | Languages & Frameworks | PHP | Servers
  • +
  • Add new server
  • +
  • The “Name” field should be the same as the parameter “serverName” value in “environment” in docker-compose.yml (i.e. * +Docker* in the example above)
  • +
  • A value of the "port" field should be the same as first port(before a colon) in "webserver" service in +docker-compose.yml
  • +
  • Select "Use path mappings" and set mappings between a path to your project on a host system and the Docker container.
  • +
  • Finally, add “Xdebug helper” extension in your browser, set breakpoints and start debugging
  • +
+
+
+
+ + + + diff --git a/phpdocker/README.md b/phpdocker/README.md new file mode 100644 index 0000000..349fac0 --- /dev/null +++ b/phpdocker/README.md @@ -0,0 +1,144 @@ +PHPDocker.io generated environment +================================== + +# Add to your project # + +Simply, unzip the file into your project, this will create `docker-compose.yml` on the root of your project and a folder +named `phpdocker` containing nginx and php-fpm config for it. + +Ensure the webserver config on `phpdocker/nginx/nginx.conf` is correct for your project. PHPDocker.io will have +customised this file according to the front controller location relative to the docker-compose file you chose on the +generator (by default `public/index.php`). + +Note: you may place the files elsewhere in your project. Make sure you modify the locations for the php-fpm dockerfile, +the php.ini overrides and nginx config on `docker-compose.yml` if you do so. + +# How to run # + +Dependencies: + +* docker. See [https://docs.docker.com/engine/installation](https://docs.docker.com/engine/installation) +* docker-compose. See [docs.docker.com/compose/install](https://docs.docker.com/compose/install/) + +Once you're done, simply `cd` to your project and run `docker-compose up -d`. This will initialise and start all the +containers, then leave them running in the background. + +## Services exposed outside your environment ## + +You can access your application via **`localhost`**. Mailhog and nginx both respond to any hostname, in case you want to +add your own hostname on your `/etc/hosts` + +Service|Address outside containers +-------|-------------------------- +Webserver|[localhost:3010](http://localhost:3010) +PostgreSQL|**host:** `localhost`; **port:** `3014` + +## Hosts within your environment ## + +You'll need to configure your application to use any services you enabled: + +Service|Hostname|Port number +------|---------|----------- +php-fpm|php-fpm|9000 +Postgres|postgres|5432 (default) + +# Docker compose cheatsheet # + +**Note:** you need to cd first to where your docker-compose.yml file lives. + +* Start containers in the background: `docker-compose up -d` +* Start containers on the foreground: `docker-compose up`. You will see a stream of logs for every container running. + ctrl+c stops containers. +* Stop containers: `docker-compose stop` +* Kill containers: `docker-compose kill` +* View container logs: `docker-compose logs` for all containers or `docker-compose logs SERVICE_NAME` for the logs of + all containers in `SERVICE_NAME`. +* Execute command inside of container: `docker-compose exec SERVICE_NAME COMMAND` where `COMMAND` is whatever you want + to run. Examples: + * Shell into the PHP container, `docker-compose exec php-fpm bash` + * Run symfony console, `docker-compose exec php-fpm bin/console` + * Open a mysql shell, `docker-compose exec mysql mysql -uroot -pCHOSEN_ROOT_PASSWORD` + +# Application file permissions # + +As in all server environments, your application needs the correct file permissions to work properly. You can change the +files throughout the container, so you won't care if the user exists or has the same ID on your host. + +`docker-compose exec php-fpm chown -R www-data:www-data /docker/public` + +# Recommendations # + +It's hard to avoid file permission issues when fiddling about with containers due to the fact that, from your OS point +of view, any files created within the container are owned by the process that runs the docker engine (this is usually +root). Different OS will also have different problems, for instance you can run stuff in containers +using `docker exec -it -u $(id -u):$(id -g) CONTAINER_NAME COMMAND` to force your current user ID into the process, but +this will only work if your host OS is Linux, not mac. Follow a couple of simple rules and save yourself a world of +hurt. + +* Run composer outside of the php container, as doing so would install all your dependencies owned by `root` within your + vendor folder. +* Run commands (ie Symfony's console, or Laravel's artisan) straight inside of your container. You can easily open a + shell as described above and do your thing from there. + +# Simple basic Xdebug configuration with integration to PHPStorm + +## Xdebug 2 + +To configure **Xdebug 2** you need add these lines in php-fpm/php-ini-overrides.ini: + +### For linux: + +``` +xdebug.remote_enable = 1 +xdebug.remote_connect_back = 1 +xdebug.remote_autostart = 1 +``` + +### For macOS and Windows: + +``` +xdebug.remote_enable = 1 +xdebug.remote_host = host.docker.internal +xdebug.remote_autostart = 1 +``` + +## Xdebug 3 + +To configure **Xdebug 3** you need add these lines in php-fpm/php-ini-overrides.ini: + +### For linux: + +``` +xdebug.mode = debug +xdebug.remote_connect_back = true +xdebug.start_with_request = yes +``` + +### For macOS and Windows: + +``` +xdebug.mode = debug +xdebug.remote_host = host.docker.internal +xdebug.start_with_request = yes +``` + +## Add the section “environment” to the php-fpm service in docker-compose.yml: + +``` +environment: + PHP_IDE_CONFIG: "serverName=Docker" +``` + +### Create a server configuration in PHPStorm: + +* In PHPStorm open Preferences | Languages & Frameworks | PHP | Servers +* Add new server +* The “Name” field should be the same as the parameter “serverName” value in “environment” in docker-compose.yml (i.e. * + Docker* in the example above) +* A value of the "port" field should be the same as first port(before a colon) in "webserver" service in + docker-compose.yml +* Select "Use path mappings" and set mappings between a path to your project on a host system and the Docker container. +* Finally, add “Xdebug helper” extension in your browser, set breakpoints and start debugging + + + diff --git a/phpdocker/nginx/nginx.conf b/phpdocker/nginx/nginx.conf new file mode 100644 index 0000000..a852d4c --- /dev/null +++ b/phpdocker/nginx/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80 default; + + client_max_body_size 108M; + + access_log /var/log/nginx/application.access.log; + + root /docker/.; + index index.php; + + # try to serve file directly, fallback to index.php + location / { + try_files $uri /index.php$is_args$args; + } + + if (!-e $request_filename) { + rewrite ^.*$ /index.php last; + } + + location ~ \.php$ { + fastcgi_pass php-fpm:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log"; + fastcgi_buffers 16 16k; + fastcgi_buffer_size 32k; + include fastcgi_params; + } +} diff --git a/phpdocker/php-fpm/Dockerfile b/phpdocker/php-fpm/Dockerfile new file mode 100644 index 0000000..7c4649d --- /dev/null +++ b/phpdocker/php-fpm/Dockerfile @@ -0,0 +1,8 @@ +FROM phpdockerio/php:8.2-fpm +WORKDIR "/docker" + +RUN apt-get update; \ + apt-get -y --no-install-recommends install \ + php8.2-pgsql; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* diff --git a/phpdocker/php-fpm/php-ini-overrides.ini b/phpdocker/php-fpm/php-ini-overrides.ini new file mode 100644 index 0000000..850ae11 --- /dev/null +++ b/phpdocker/php-fpm/php-ini-overrides.ini @@ -0,0 +1,2 @@ +upload_max_filesize = 100M +post_max_size = 108M diff --git a/src/adminer-4.8.1.php b/src/adminer-4.8.1.php new file mode 100644 index 0000000..762aaaf --- /dev/null +++ b/src/adminer-4.8.1.php @@ -0,0 +1,1795 @@ +$W){unset($tg[$z][$he]);if(is_array($W)){$tg[$z][stripslashes($he)]=$W;$tg[]=&$tg[$z][stripslashes($he)];}else$tg[$z][stripslashes($he)]=($ad?$W:stripslashes($W));}}}}function +bracket_escape($v,$Na=false){static$ui=array(':'=>':1',']'=>':2','['=>':3','"'=>':4');return +strtr($v,($Na?array_flip($ui):$ui));}function +min_version($Zi,$De="",$h=null){global$g;if(!$h)$h=$g;$nh=$h->server_info;if($De&&preg_match('~([\d.]+)-MariaDB~',$nh,$C)){$nh=$C[1];$Zi=$De;}return(version_compare($nh,$Zi)>=0);}function +charset($g){return(min_version("5.5.3",0,$g)?"utf8mb4":"utf8");}function +script($yh,$ti="\n"){return"$yh$ti";}function +script_src($Ni){return"\n";}function +nonce(){return' nonce="'.get_nonce().'"';}function +target_blank(){return' target="_blank" rel="noreferrer noopener"';}function +h($P){return +str_replace("\0","�",htmlspecialchars($P,ENT_QUOTES,'utf-8'));}function +nl_br($P){return +str_replace("\n","
",$P);}function +checkbox($D,$Y,$db,$me="",$uf="",$hb="",$ne=""){$I="".($uf?script("qsl('input').onclick = function () { $uf };",""):"");return($me!=""||$hb?"$I".h($me)."":$I);}function +optionlist($_f,$gh=null,$Ri=false){$I="";foreach($_f +as$he=>$W){$Af=array($he=>$W);if(is_array($W)){$I.='';$Af=$W;}foreach($Af +as$z=>$X)$I.=''.h($X);if(is_array($W))$I.='';}return$I;}function +html_select($D,$_f,$Y="",$tf=true,$ne=""){if($tf)return"".(is_string($tf)?script("qsl('select').onchange = function () { $tf };",""):"");$I="";foreach($_f +as$z=>$X)$I.="";return$I;}function +select_input($Ia,$_f,$Y="",$tf="",$fg=""){$Yh=($_f?"select":"input");return"<$Yh$Ia".($_f?">