Commit 3f93c24d authored by Bernhard Heinloth's avatar Bernhard Heinloth
Browse files

Webfrontend via Docker

parent 1649e54a
Pipeline #79928 passed with stage
in 7 minutes and 25 seconds
version: '3.7'
services:
web:
image: inf4/timecube
volumes:
# Adjust domain
- ./nginx.conf:/etc/nginx/sites-enabled/default
# Adjust database user and password
- ./www/config.php:/timecube/server/www/config.php
ports:
- 80:80
restart: always
command: sh -c '/etc/init.d/php7.4-fpm start ; nginx -g "daemon off;"'
depends_on:
- db
db:
image: postgres:10.5
restart: always
environment:
- PGUSER=postgres
# must be identical to www/config.php (and credentials should be changed!)
- POSTGRES_DB=timelog
- POSTGRES_USER=timelog
- POSTGRES_PASSWORD=YOUR_PASSWORD!
ports:
- 5438:5432
volumes:
# lokal volume
- db:/var/lib/postgresql/data
# create the database tables
- ./docker.sql:/docker-entrypoint-initdb.d/0-docker.sql
# create the database tables
- ./database.sql:/docker-entrypoint-initdb.d/database.sql
# fill in user and timecube mac
- ./insert_new_user.sql:/docker-entrypoint-initdb.d/insert_new_user.sql
volumes:
db:
driver: local
-- Our docker compose will create a user, but not the default postgres one.
-- Let's do it here.
CREATE ROLE postgres;
<?php
$DBHOST="localhost";
$DBHOST="db";
$DBNAME="timelog";
$DBUSER="USER";
$DBPASS="PASS";
$DBUSER="postgres";
$DBPASS="YOUR_PASSWORD!";
?>
......@@ -38,7 +38,7 @@ WITH data ( name , email , alias , mac
), addside6 AS (
INSERT INTO cubesides (mac, side, category) SELECT mac, 6, id FROM addcat6 CROSS JOIN data
)
INSERT INTO connection (mac, side, voltage, time)
INSERT INTO connection (mac, id, voltage, time)
SELECT mac, id, 0, extract(epoch from now()) FROM data CROSS JOIN addside0;
COMMIT;
server {
listen 80 default_server;
server_name _;
root /timecube/server/www/;
index index.php;
location ~ /?config.php$ {
return 403;
}
if (!-e $request_filename){
rewrite ^/([^/]*)$ /$1/ redirect;
rewrite "^/([A-Fa-f0-9]{12})/?(.*)$" /index.php?mac=$1&alias=$1&site=$2 break;
rewrite ^/([^/]*)/?(.*)$ /index.php?alias=$1&site=$2 break;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location / {
try_files $uri $uri/ =404;
}
}
......@@ -123,18 +123,18 @@ switch ($site){
status('Eingetragen.', 200, 'OK');
break;
case 'data.csv':
header('Content-type: text/comma-separated-values');
echo "From;To;Duration;FromISO;ToISO;name;hidden;MAC\n";
$stmt_log = $pdo->prepare('SELECT data.begin AS begin, data.stop AS stop, categories.name AS name, categories.hidden AS hidden, data.mac AS mac FROM data JOIN categories ON (data.category = categories.id) WHERE categories.uid = ? ORDER BY begin, stop');
if ($stmt_log->execute(array($user['uid'])))
while ($row_log = $stmt_log->fetch(PDO::FETCH_ASSOC))
echo $row_log['begin'].';'.$row_log['stop'].';'.($row_log['stop']-$row_log['begin']).';'.date('c;',$row_log['begin']).date('c;',$row_log['stop']).$row_log['name'].';'.$row_log['hidden'].';'.$row_log['mac']."\r\n";
break;
case 'data.csv':
header('Content-type: text/comma-separated-values');
echo "From;To;Duration;FromISO;ToISO;name;hidden;MAC\n";
$stmt_log = $pdo->prepare('SELECT data.begin AS begin, data.stop AS stop, categories.name AS name, categories.hidden AS hidden, data.mac AS mac FROM data JOIN categories ON (data.category = categories.id) WHERE categories.uid = ? ORDER BY begin, stop');
if ($stmt_log->execute(array($user['uid'])))
while ($row_log = $stmt_log->fetch(PDO::FETCH_ASSOC))
echo $row_log['begin'].';'.$row_log['stop'].';'.($row_log['stop']-$row_log['begin']).';'.date('c;',$row_log['begin']).date('c;',$row_log['stop']).$row_log['name'].';'.$row_log['hidden'].';'.$row_log['mac']."\r\n";
break;
case 'dashboard':
case 'update':
default:
include('dashboard.html');
readfile('dashboard.html');
}
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment