Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit c4967ec

Browse files
committed
Ressource versioning, NGINX fixes (error pages), API add fix
1 parent 9b10565 commit c4967ec

9 files changed

Lines changed: 62 additions & 38 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ FROM kimbtechnologies/php_nginx:latest
44
COPY --chown=www-data:www-data ./php/ /php-code/
55
COPY --chown=www-data:www-data ./start/ /start/
66
COPY ./nginx.conf /etc/nginx/more-server-conf.conf
7-
COPY /startup-before.sh /
7+
COPY ./startup-before.sh /
8+
COPY ./VERSION /php-code/VERSION

nginx.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
error_page 404 /index.php?err=404;
22
error_page 403 /index.php?err=403;
33

4-
location / {
5-
try_files $uri $uri/ @nofile;
6-
}
7-
84
location ~ ^/(data|core){
95
deny all;
106
return 403;

php/core/Template.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function getOutputString(){
159159
}
160160

161161
$this->placeholder['%%SERVERURL%%'] = Config::getBaseUrl();
162+
$this->placeholder['%%VERSIONSEED%%'] = is_file('/php-code/VERSION') ? sha1_file('/php-code/VERSION') : uniqid();
162163

163164
if( $this->inner !== null ){
164165
$this->placeholder['%%INNERCONTAINER%%'] = $this->inner->getOutputString();

php/core/WebGUI.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ public function home() : void {
255255
$home->setMultipleContent('Links', $tasks);
256256
}
257257

258+
public function errorPage(int $code) : void {
259+
$this->mainTemp->setContent('TITLE', 'Error ' . $code );
260+
$error = new Template('error');
261+
$this->mainTemp->includeTemplate($error);
262+
}
263+
258264
public function loginForm() : void {
259265
$this->mainTemp->setContent('TITLE', 'Login');
260266
$login = new Template('login');

php/core/api/APIAdd.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ protected function handleAPITask() : void{
2121
&& InputParser::checkNameInput( $a['name'] )
2222
&& InputParser::checkCategoryInput( $a['category'] );
2323
}));
24-
if(empty($array) || !isset($this->requestData['day'])
25-
|| !is_int($this->requestData['day']) || $this->requestData['day'] < 0 ){
24+
if(!isset($this->requestData['day']) || !is_int($this->requestData['day']) || $this->requestData['day'] < 0 ){
2625
$this->error('Invalid data.');
2726
return;
2827
}
@@ -36,12 +35,23 @@ protected function handleAPITask() : void{
3635
}
3736

3837
$filename = $groupDir . '/' . date('Y-m-d', $this->requestData['day']) . '.json';
39-
if(file_put_contents( $filename, json_encode( $array, JSON_PRETTY_PRINT ))){
40-
$this->output = array( 'ok' );
38+
39+
if( !empty($array) ){
40+
if(file_put_contents( $filename, json_encode( $array, JSON_PRETTY_PRINT ))){
41+
$this->output = array( 'ok' );
42+
}
43+
else{
44+
$this->error('Error saving data.');
45+
}
4146
}
4247
else{
43-
$this->error('Error saving data.');
44-
}
48+
if( unlink( $filename) ){
49+
$this->output = array( 'ok' );
50+
}
51+
else{
52+
$this->error('Error saving data.');
53+
}
54+
}
4555
}
4656
}
4757
?>

php/core/templates/error.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

php/core/templates/error_en.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="alert alert-danger" role="alert">
2+
<h4 class="alert-heading">Error</h4>
3+
<p>The request could not be fulfilled!</p>
4+
</div>

php/core/templates/main_en.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
<link rel="icon" href="%%SERVERURL%%/favicon.ico" type="image/x-icon; charset=binary">
2323
<link rel="apple-touch-icon" href="%%SERVERURL%%/load/icon.png">
2424

25-
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/jquery-ui.min.css">
26-
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/jquery-ui-light.theme.min.css">
27-
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/bootstrap.min.css">
28-
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/main.css">
25+
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/jquery-ui.min.css?%%VERSIONSEED%%">
26+
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/jquery-ui-light.theme.min.css?%%VERSIONSEED%%">
27+
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/bootstrap.min.css?%%VERSIONSEED%%">
28+
<link rel="stylesheet" type="text/css" href="%%SERVERURL%%/load/main.css?%%VERSIONSEED%%">
2929

30-
<script src="%%SERVERURL%%/load/jquery.min.js"></script>
31-
<script src="%%SERVERURL%%/load/jquery-ui.min.js"></script>
32-
<script src="%%SERVERURL%%/load/chart.min.js"></script>
30+
<script src="%%SERVERURL%%/load/jquery.min.js?%%VERSIONSEED%%"></script>
31+
<script src="%%SERVERURL%%/load/jquery-ui.min.js?%%VERSIONSEED%%"></script>
32+
<script src="%%SERVERURL%%/load/chart.min.js?%%VERSIONSEED%%"></script>
3333
%%MOREHEADER%%
3434
</head>
3535
<body>

php/index.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,32 @@
2323
}
2424
$gui = new WebGUI($param, $login);
2525

26-
if( $login->isLoggedIn() ){
27-
switch ($param->getTask()) {
28-
case ParamParser::TASK_ACCOUNT:
29-
$gui->accountManage();
30-
break;
31-
case ParamParser::TASK_DEVICES:
32-
$gui->deviceManage();
33-
break;
34-
case ParamParser::TASK_RECORD:
35-
$gui->addTaskRecord();
36-
break;
37-
case ParamParser::TASK_STATS:
38-
$gui->showStats();
39-
break;
40-
case ParamParser::TASK_HOME:
41-
case ParamParser::TASK_NONE:
42-
default:
43-
$gui->home();
44-
}
26+
if( isset($_GET['err']) && in_array($_GET['err'], array(404, 403)) ){
27+
$gui->errorPage($_GET['err']);
4528
}
4629
else{
47-
$gui->loginForm();
30+
if( $login->isLoggedIn() ){
31+
switch ($param->getTask()) {
32+
case ParamParser::TASK_ACCOUNT:
33+
$gui->accountManage();
34+
break;
35+
case ParamParser::TASK_DEVICES:
36+
$gui->deviceManage();
37+
break;
38+
case ParamParser::TASK_RECORD:
39+
$gui->addTaskRecord();
40+
break;
41+
case ParamParser::TASK_STATS:
42+
$gui->showStats();
43+
break;
44+
case ParamParser::TASK_HOME:
45+
case ParamParser::TASK_NONE:
46+
default:
47+
$gui->home();
48+
}
49+
}
50+
else{
51+
$gui->loginForm();
52+
}
4853
}
4954
?>

0 commit comments

Comments
 (0)