diff --git a/Dockerfile b/Dockerfile index d2d3d19..5d3c023 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,8 @@ FROM php:8.2-apache as builder -# RUN mkdir -p /var/www -# WORKDIR /var/www - RUN apt update && apt dist-upgrade -y RUN apt install -y \ -# php-xdebug \ git \ curl \ zip \ @@ -23,28 +19,14 @@ RUN apt install -y \ libzip-dev \ net-tools \ iputils-ping \ - nano - -# RUN apk add --update --no-cache --virtual .build-deps \ -# autoconf g++ make \ -# curl \ -# git \ -# zip \ -# libxml2-dev \ -# libzip-dev \ -# sqlite \ -# sqlite-dev \ -# icu-dev \ -# gettext-dev \ -# nano + nano \ + sudo \ + openssl -# RUN docker-php-ext-install intl && docker-php-ext-enable intl RUN docker-php-ext-install gettext && docker-php-ext-enable gettext RUN docker-php-ext-install pdo_mysql && docker-php-ext-enable pdo_mysql RUN docker-php-ext-install pdo_sqlite && docker-php-ext-enable pdo_sqlite -# RUN docker-php-ext-install sockets && docker-php-ext-enable sockets RUN pecl install -f xdebug -# RUN docker-php-ext-enable xdebug RUN yes | pecl install ${XDEBUG_VERSION} \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ @@ -52,12 +34,14 @@ RUN yes | pecl install ${XDEBUG_VERSION} \ && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini COPY config/php.ini /usr/local/etc/php/conf.d/local.ini +COPY config/000-default.conf /etc/apache2/sites-enabled/000-default.conf +COPY config/apache2.conf /etc/apache2/apache2.conf +RUN a2enmod ssl +RUN a2enmod socache_shmcb RUN a2enmod rewrite RUN a2enmod deflate -RUN apachectl -M - FROM builder as dependencies RUN echo $(php -v) WORKDIR / @@ -65,6 +49,14 @@ RUN mkdir -p /usr/bin/ RUN cp $(which php) /usr/bin/ WORKDIR /tmp +RUN openssl genrsa -out apache-selfsigned.pem 2048 +RUN openssl req \ + -new \ + -sha256 \ + -subj "/emailAddress=email@localhost/C=CO/ST=bogota/L=bogota/O=latuteca/OU=development/CN=localhost" \ + -key apache-selfsigned.pem \ + -out apache-selfsigned.cert +RUN openssl x509 -req -in apache-selfsigned.cert -signkey apache-selfsigned.pem -out apache-selfsigned-full.pem RUN git clone https://github.com/rantes/DumboPHP.git WORKDIR /tmp/DumboPHP @@ -72,14 +64,15 @@ WORKDIR /tmp/DumboPHP RUN php install.php FROM dependencies as release + +COPY --chown=www-data --from=dependencies /tmp/apache-selfsigned.pem /etc/apache2/ +COPY --chown=www-data --from=dependencies /tmp/apache-selfsigned-full.pem /etc/apache2/ +RUN ls +RUN apache2ctl configtest +RUN apache2ctl start + WORKDIR /var/www/html USER www-data -RUN echo 'Running migrations...' -RUN php /usr/local/bin/dumbo migration run all -RUN echo 'Running sowing seeds...' -RUN php /usr/local/bin/dumbo migration sow - EXPOSE 80 - -# CMD ["sh", "./docker-startup.sh"] +EXPOSE 443 \ No newline at end of file diff --git a/README.md b/README.md index c238b73..05a1d2f 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,15 @@ ![Basilisk](app/webroot/images/basilisk.svg "Basilisk") ## Summary ## Simple Project Manager + +## SETUP ## +with the docker daemon running (docker desktop), run in the console: +``` +docker-compose up --build --always-recreate-deps --force-recreate --attach-dependencies +``` + +Once the image is built, get into the image shell and run: + +``` +./docker-startup.sh +``` \ No newline at end of file diff --git a/app/controllers/common_trait.php b/app/controllers/common_trait.php index ca5aedc..a64e98b 100644 --- a/app/controllers/common_trait.php +++ b/app/controllers/common_trait.php @@ -25,6 +25,7 @@ public function signinAction() { */ public function logoutAction() { $this->layout = false; + $this->render['action'] = false; php_sapi_name() !== 'cli' and session_destroy(); $_SESSION = null; unset($_SESSION); diff --git a/app/models/translation.php b/app/models/translation.php index f9758bc..ba74232 100644 --- a/app/models/translation.php +++ b/app/models/translation.php @@ -11,11 +11,13 @@ public function _init_() { } public function setDomain() { - empty($this->domain) and ($this->domain = explode('.', $this->keyid)[0]); + !empty($this->keyid) and empty($this->domain) and ($this->domain = explode('.', $this->keyid)[0]); } public function sanitize() { - $this->translation = htmlentities($this->translation, ENT_QUOTES, 'UTF-8', false); + if (!empty($this->translation)): + $this->translation = htmlentities($this->translation, ENT_QUOTES, 'UTF-8', false); + endif; } public function checkKeyID() { diff --git a/app/models/user.php b/app/models/user.php index 287fa52..3df82dd 100644 --- a/app/models/user.php +++ b/app/models/user.php @@ -27,8 +27,12 @@ public function _init_(){ } public function sanitize() { - $this->firstname = htmlentities($this->firstname, ENT_QUOTES, 'UTF-8',false); - $this->lastname = htmlentities($this->lastname, ENT_QUOTES, 'UTF-8',false); + if (!empty($this->firstname)): + $this->firstname = htmlentities($this->firstname, ENT_QUOTES, 'UTF-8',false); + endif; + if (!empty($this->lastname)): + $this->lastname = htmlentities($this->lastname, ENT_QUOTES, 'UTF-8',false); + endif; } public function encryptPassword() { diff --git a/config/000-default.conf b/config/000-default.conf new file mode 100644 index 0000000..0cd7171 --- /dev/null +++ b/config/000-default.conf @@ -0,0 +1,54 @@ +Define site /var/www/html + + + Protocols h2 h2c http/1.1 + ServerName localhost + ServerAlias localhost + + ServerAdmin webmaster@localhost + DocumentRoot ${site} + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + + #LogLevel info ssl:warn + + # ErrorLog ${site}/error.log + # CustomLog ${site}/access.log combined + + RewriteEngine on + RewriteCond %{SERVER_NAME} =localhost + RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] + + + + Protocols h2 h2c http/1.1 + ServerName localhost + ServerAlias localhost + + ServerAdmin webmaster@localhost + DocumentRoot ${site} + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + + #LogLevel info ssl:warn + + # ErrorLog ${site}/error.log + # CustomLog ${site}/access.log combined + + + +SSLCertificateFile /etc/apache2/apache-selfsigned-full.pem +SSLCertificateKeyFile /etc/apache2/apache-selfsigned.pem + +#Include /etc/letsencrypt/options-ssl-apache.conf + + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet \ No newline at end of file diff --git a/config/apache2.conf b/config/apache2.conf new file mode 100644 index 0000000..0b91f0a --- /dev/null +++ b/config/apache2.conf @@ -0,0 +1,228 @@ +# This is the main Apache server configuration file. It contains the +# configuration directives that give the server its instructions. +# See http://httpd.apache.org/docs/2.4/ for detailed information about +# the directives and /usr/share/doc/apache2/README.Debian about Debian specific +# hints. +# +# +# Summary of how the Apache 2 configuration works in Debian: +# The Apache 2 web server configuration in Debian is quite different to +# upstream's suggested way to configure the web server. This is because Debian's +# default Apache2 installation attempts to make adding and removing modules, +# virtual hosts, and extra configuration directives as flexible as possible, in +# order to make automating the changes and administering the server as easy as +# possible. + +# It is split into several files forming the configuration hierarchy outlined +# below, all located in the /etc/apache2/ directory: +# +# /etc/apache2/ +# |-- apache2.conf +# | `-- ports.conf +# |-- mods-enabled +# | |-- *.load +# | `-- *.conf +# |-- conf-enabled +# | `-- *.conf +# `-- sites-enabled +# `-- *.conf +# +# +# * apache2.conf is the main configuration file (this file). It puts the pieces +# together by including all remaining configuration files when starting up the +# web server. +# +# * ports.conf is always included from the main configuration file. It is +# supposed to determine listening ports for incoming connections which can be +# customized anytime. +# +# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ +# directories contain particular configuration snippets which manage modules, +# global configuration fragments, or virtual host configurations, +# respectively. +# +# They are activated by symlinking available configuration files from their +# respective *-available/ counterparts. These should be managed by using our +# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See +# their respective man pages for detailed information. +# +# * The binary is called apache2. Due to the use of environment variables, in +# the default configuration, apache2 needs to be started/stopped with +# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not +# work with the default configuration. + + +# Global configuration +# + +# +# ServerRoot: The top of the directory tree under which the server's +# configuration, error, and log files are kept. +# +# NOTE! If you intend to place this on an NFS (or otherwise network) +# mounted filesystem then please read the Mutex documentation (available +# at ); +# you will save yourself a lot of trouble. +# +# Do NOT add a slash at the end of the directory path. +# +#ServerRoot "/etc/apache2" + +# +# The accept serialization lock file MUST BE STORED ON A LOCAL DISK. +# +#Mutex file:${APACHE_LOCK_DIR} default + +# +# The directory where shm and other runtime files will be stored. +# + +DefaultRuntimeDir ${APACHE_RUN_DIR} + +# +# PidFile: The file in which the server should record its process +# identification number when it starts. +# This needs to be set in /etc/apache2/envvars +# +PidFile ${APACHE_PID_FILE} + +# +# Timeout: The number of seconds before receives and sends time out. +# +Timeout 300 + +# +# KeepAlive: Whether or not to allow persistent connections (more than +# one request per connection). Set to "Off" to deactivate. +# +KeepAlive On + +# +# MaxKeepAliveRequests: The maximum number of requests to allow +# during a persistent connection. Set to 0 to allow an unlimited amount. +# We recommend you leave this number high, for maximum performance. +# +MaxKeepAliveRequests 100 + +# +# KeepAliveTimeout: Number of seconds to wait for the next request from the +# same client on the same connection. +# +KeepAliveTimeout 5 + + +# These need to be set in /etc/apache2/envvars +User ${APACHE_RUN_USER} +Group ${APACHE_RUN_GROUP} + +# +# HostnameLookups: Log the names of clients or just their IP addresses +# e.g., www.apache.org (on) or 204.62.129.132 (off). +# The default is off because it'd be overall better for the net if people +# had to knowingly turn this feature on, since enabling it means that +# each client request will result in AT LEAST one lookup request to the +# nameserver. +# +HostnameLookups Off + +# ErrorLog: The location of the error log file. +# If you do not specify an ErrorLog directive within a +# container, error messages relating to that virtual host will be +# logged here. If you *do* define an error logfile for a +# container, that host's errors will be logged there and not here. +# +ErrorLog ${APACHE_LOG_DIR}/error.log + +# +# LogLevel: Control the severity of messages logged to the error_log. +# Available values: trace8, ..., trace1, debug, info, notice, warn, +# error, crit, alert, emerg. +# It is also possible to configure the log level for particular modules, e.g. +# "LogLevel info ssl:warn" +# +LogLevel warn + +# Include module configuration: +IncludeOptional mods-enabled/*.load +IncludeOptional mods-enabled/*.conf + +# Include list of ports to listen on +Include ports.conf + + +# Sets the default security model of the Apache2 HTTPD server. It does +# not allow access to the root filesystem outside of /usr/share and /var/www. +# The former is used by web applications packaged in Debian, +# the latter may be used for local directories served by the web server. If +# your system is serving content from a sub-directory in /srv you must allow +# access here, or in any related virtual host. + + Options FollowSymLinks + AllowOverride None + Require all denied + + + + AllowOverride None + Require all granted + + + + Options Indexes FollowSymLinks + AllowOverride None + Require all granted + + +# +# Options Indexes FollowSymLinks +# AllowOverride None +# Require all granted +# + + + + +# AccessFileName: The name of the file to look for in each directory +# for additional configuration directives. See also the AllowOverride +# directive. +# +AccessFileName .htaccess + +# +# The following lines prevent .htaccess and .htpasswd files from being +# viewed by Web clients. +# + + Require all denied + + + +# +# The following directives define some format nicknames for use with +# a CustomLog directive. +# +# These deviate from the Common Log Format definitions in that they use %O +# (the actual bytes sent including headers) instead of %b (the size of the +# requested file), because the latter makes it impossible to detect partial +# requests. +# +# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended. +# Use mod_remoteip instead. +# +LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined +LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined +LogFormat "%h %l %u %t \"%r\" %>s %O" common +LogFormat "%{Referer}i -> %U" referer +LogFormat "%{User-agent}i" agent + +# Include of directories ignores editors' and dpkg's backup files, +# see README.Debian for details. + +# Include generic snippets of statements +IncludeOptional conf-enabled/*.conf + +# Include the virtual host configurations: +IncludeOptional sites-enabled/*.conf +ServerName localhost + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/config/cli-php.ini b/config/cli-php.ini index ee94896..8429e05 100644 --- a/config/cli-php.ini +++ b/config/cli-php.ini @@ -1956,3 +1956,8 @@ ldap.max_links = -1 ; List of headers files to preload, wildcard patterns allowed. ;ffi.preload= + +[xdebug] +# zend_extension="xdebug.so" +xdebug.mode=develop,coverage,profile +xdebug.start_with_request = yes \ No newline at end of file diff --git a/config/php.ini b/config/php.ini index fef29d2..afbbeaa 100644 --- a/config/php.ini +++ b/config/php.ini @@ -1975,3 +1975,8 @@ opcache.preload_user=rantes ; List of headers files to preload, wildcard patterns allowed. ;ffi.preload= + +[xdebug] +# zend_extension="xdebug.so" +xdebug.mode=develop,coverage,profile +xdebug.start_with_request = yes \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8b20d3e..9be72e7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,24 +22,32 @@ services: MYSQL_PASSWORD: 'Ba21l1sk%' MYSQL_ROOT_PASSWORD: 'basilisk' MYSQL_ROOT_HOST: '%' + healthcheck: + test: mysqladmin ping -h db -u $$MYSQL_USER --password=$$MYSQL_PASSWORD + interval: 10s + timeout: 10s + retries: 5 + start_period: 10s basilisk: build: . volumes: - ./:/var/www/html container_name: basilisk - restart: always + restart: on-failure tty: true depends_on: - - db + db: + condition: service_healthy links: - db ports: - 80:80 + - 443:443 environment: DB_HOST: db phpmyadmin: image: phpmyadmin - restart: always + restart: on-failure depends_on: - db links: diff --git a/docker-startup.sh b/docker-startup.sh new file mode 100755 index 0000000..e307727 --- /dev/null +++ b/docker-startup.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +echo "Running migrations..." +php /usr/local/bin/dumbo migration run all +echo "Sowing the seeds..." +php /usr/local/bin/dumbo migration sow +echo "Running unit tests..." +php /usr/local/bin/dumboTest diff --git a/stub.php b/stub.php new file mode 100644 index 0000000..1397d2f --- /dev/null +++ b/stub.php @@ -0,0 +1,14 @@ +assertTrue($code === HTTP_401, 'Should set a 401 response code on signin try for wrong user.'); $testUser = [ - 'id' => 1, 'firstname' => 'test', 'lastname' => 'test', 'identification_kind_id' => '1', diff --git a/tests/testTranslationModel.php b/tests/testTranslationModel.php index 88a6fee..c389b9c 100644 --- a/tests/testTranslationModel.php +++ b/tests/testTranslationModel.php @@ -32,7 +32,8 @@ public function saveOkTest() { $t = $this->Translation->Niu([ 'keyid' => 'test.key', 'domain' => 'domain', - 'locale' => 'en_US' + 'locale' => 'en_US', + 'translation' => 'test' ]); $result = $t->Save(); $errors = $t->_error->errFields(); @@ -45,7 +46,8 @@ public function ensureDomainFieldTest() { $this->describe('Should set domain field if is empty'); $t = $this->Translation->Niu([ 'keyid' => 'domain.test.key', - 'locale' => 'en_US' + 'locale' => 'en_US', + 'translation' => 'test' ]); $result = $t->Save(); $errors = $t->_error->errFields(); @@ -77,12 +79,14 @@ public function duplicatedKeyTest() { $t = $this->Translation->Niu([ 'keyid' => 'domain.test.key', - 'locale' => 'en_US' + 'locale' => 'en_US', + 'translation' => 'test' ]); $tok = $this->Translation->Niu([ 'keyid' => 'domain.test.key', - 'locale' => 'es_CO' + 'locale' => 'es_CO', + 'translation' => 'test' ]); $tbad = $this->Translation->Niu([