Skip to content

Commit 3171670

Browse files
authored
Merge pull request #172 from Steffen-MLR/master
PHP8 Support
2 parents e0ff612 + f942c49 commit 3171670

19 files changed

+146
-67
lines changed

404.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
define("NAME", "");
3+
define("TITLE", "");
4+
define("WEB_URL", "");
25
require_once("template.php");
36
if (!file_exists("config.php"))
47
{

Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM php:8.2-apache
2+
RUN docker-php-ext-install mysqli
3+
RUN docker-php-ext-enable mysqli
4+
RUN apt-get update
5+
RUN apt-get install libzip-dev -y
6+
RUN docker-php-ext-install zip
7+
RUN docker-php-ext-enable zip
8+
RUN a2enmod rewrite
9+
RUN touch /usr/local/etc/php/conf.d/ssp.ini
10+
RUN echo "output_buffering = 16384" >> /usr/local/etc/php/conf.d/ssp.ini
11+
RUN echo "display_errors = off" >> /usr/local/etc/php/conf.d/ssp.ini
12+
RUN echo "error_reporting = E_ERROR" >> /usr/local/etc/php/conf.d/ssp.ini
13+
RUN apt install git -y
14+
WORKDIR /var/www/html
15+
RUN docker-php-ext-install gettext
16+
RUN docker-php-ext-install pdo_mysql
17+
RUN apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev && docker-php-ext-configure gd --with-freetype --with-jpeg && docker-php-ext-install -j$(nproc) gd
18+
RUN apt-get install -y locales
19+
RUN locale-gen en_GB.UTF-8
20+
RUN sed -i '/en_GB.UTF-8/s/^# //g' /etc/locale.gen && \
21+
locale-gen
22+
RUN apt-get install -y curl
23+
# And clean up the image
24+
RUN rm -rf /var/lib/apt/lists/*
25+
26+
RUN curl -Lsf 'https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz' | tar -C '/usr/local' -xvzf -
27+
ENV PATH /usr/local/go/bin:$PATH
28+
RUN go get github.com/mailhog/mhsendmail
29+
RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail
30+
RUN echo 'sendmail_path = /usr/bin/mhsendmail --smtp-addr mailhog:1025' > /usr/local/etc/php/php.ini
31+
32+

admin/user.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
?>
4848
<div class="text-center">
4949
<h1><?php
50-
if ($_SESSION['user'] == $_GET['id'])
50+
if (isset($_GET['id']) && isset($_SESSION['user']) && $_SESSION['user'] == $_GET['id'])
5151
{
5252
echo _("User settings");
5353
}else{

classes/constellation.php

+3-18
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function render_incidents($future=false, $offset=0, $limit = 5, $admin =
6969
* @param boolean $admin
7070
* @return array of services
7171
*/
72-
public function render_status($admin = false, $heading = true){
72+
public function render_status($admin = false, $heading = true): array{
7373
global $mysqli;
7474

7575
//$query = $mysqli->query("SELECT id, name, description FROM services");
@@ -104,27 +104,12 @@ public function render_status($admin = false, $heading = true){
104104
}
105105
if (!$admin)
106106
{
107-
?>
108-
<script>
109-
$(document).ready(function(){
110-
$('[data-toggle="tooltip"]').tooltip();
111-
});
112-
</script>
113-
<?php
114-
//echo '<div id="status-container" class="clearfix">';
115-
//$arrCompletedGroups = array();
107+
116108
foreach($array as $service){
117-
//print_r($service);
118-
//if ( !empty($service->group_name) && !in_array($service->group_name, $arrCompletedGroups)) {
119-
//print $service->name;
120-
// $arrCompletedGroups[] = $service['group_name'];
121-
// $service->render(true);
122-
//} else {
123109
$service->render();
124-
//}
125110
}
126111
echo '</ul>';
127-
//echo '</div>';
112+
return $array;
128113
}
129114
else{
130115
return $array;

classes/incident.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function render($admin=0){
223223
<?php
224224
}
225225

226-
public function jsonSerialize() {
226+
public function jsonSerialize():mixed {
227227
return [
228228
"id" => $this->id,
229229
"date" => $this->timestamp,

classes/locale-negotiator.php

-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ class LocaleNegotiator
150150
'nl_BE' => 'Nederlands',
151151
'nl_NL' => 'Nederlands',
152152
'nn_NO' => 'Nynorsk',
153-
'nb_NO' => 'Norsk Bokmål',
154153
'nso_ZA' => 'Northern sotho',
155154
'oc_FR' => 'Occitan',
156155
'or_IN' => 'ଓଡ଼ିଆ',

classes/notification.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function notify_subscribers()
6060
$sql = "SELECT DISTINCT subscriberIDFK FROM services_subscriber WHERE serviceIDFK IN (" . $this->serviceids . ")";
6161
$query = $mysqli->query($sql);
6262

63+
if (0 === $query->num_rows) {
64+
// skip processing if no one needs to be notified
65+
return;
66+
}
67+
6368
// Create the queue tasks for email/telegram notifications
6469
$queue = new Queue();
6570
$queue->status = $queue->all_status['populating'];
@@ -125,7 +130,7 @@ public function notify_subscribers()
125130
* @param string $msg Body of message
126131
* @return boolean true = Sent / False = failed
127132
*/
128-
public function submit_queue_telegram($userID, $firstname, $msg)
133+
public static function submit_queue_telegram($userID, $firstname, $msg)
129134
{
130135
// TODO Handle limitations (Max 30 different subscribers per second)
131136
// TODO Error handling
@@ -150,7 +155,7 @@ public function submit_queue_telegram($userID, $firstname, $msg)
150155
* @param String $uthkey Users token for managing subscription
151156
* @return void
152157
*/
153-
public function submit_queue_email($subscriber, $subject, $msg)
158+
public static function submit_queue_email($subscriber, $subject, $msg): bool
154159
{
155160
// TODO Error handling
156161
$mailer = new Mailer();

classes/queue.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function add_task() {
4949
* Remove task from the queue
5050
* @return void
5151
*/
52-
public function delete_task($task_id){
52+
public static function delete_task($task_id){
5353
global $mysqli;
5454
$stmt = $mysqli->prepare("DELETE FROM queue_task WHERE id = ?");
5555
$stmt->bind_param("i", $task_id);
@@ -98,14 +98,14 @@ public function add_notification($arr_data) {
9898
$this->set_task_status($this->all_status['ready']); // Make task available for release
9999
}
100100

101-
public function update_notification_retries($task_id, $subscriber_id) {
101+
public static function update_notification_retries($task_id, $subscriber_id) {
102102
global $mysqli;
103103
$stmt = $mysqli->prepare("UPDATE queue_notify SET retries = retries+1 WHERE task_id = ? AND subscriber_id = ?");
104104
$stmt->bind_param("ii", $task_id, $subscriber_id);
105105
$stmt->execute();
106106
}
107107

108-
public function delete_notification($task_id, $subscriber_id) {
108+
public static function delete_notification($task_id, $subscriber_id) {
109109
global $mysqli;
110110
$stmt = $mysqli->prepare("DELETE FROM queue_notify WHERE task_id = ? AND subscriber_id = ?");
111111
$stmt->bind_param("ii", $task_id, $subscriber_id);
@@ -114,7 +114,7 @@ public function delete_notification($task_id, $subscriber_id) {
114114
}
115115

116116
// TODO: Fix max attempts for notifications
117-
public function process_queue(){
117+
public static function process_queue(){
118118
global $mysqli;
119119
$stmt = $mysqli->query("SELECT qn.id, qn.task_id, qn.status, qn.subscriber_id, qn.retries, sub.firstname, sub.userID, sub.token FROM queue_notify AS qn INNER JOIN subscribers AS sub ON qn.subscriber_id = sub.subscriberID WHERE qn.status NOT LIKE 2 AND sub.active=1");
120120
while ( $result = $stmt->fetch_assoc() ) {

classes/service-group.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ServiceGroup
88
private $name;
99
private $description;
1010
private $visibility_id;
11+
private $status;
1112

1213
/**
1314
* Constructs servicegroup from its data.
@@ -16,7 +17,7 @@ class ServiceGroup
1617
* @param String $description tooltip text
1718
* @param int $visibility_id how to display group items
1819
*/
19-
function __construct($id, $name, $description, $visibility_id)
20+
function __construct($id, $name, $description, $visibility_id, $status)
2021

2122
{
2223
//TODO: Maybe get data from ID?
@@ -153,7 +154,7 @@ public static function delete()
153154
* Get list of services groups.
154155
* @return array $groups
155156
*/
156-
public function get_groups() {
157+
public static function get_groups() {
157158
global $mysqli;
158159
$stmt = $mysqli->query("SELECT id, name FROM services_groups ORDER by name ASC");
159160

classes/service.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static function delete()
180180
* @param Service[] $array array of services
181181
* @return void
182182
*/
183-
public static function current_status($array){
183+
public static function current_status($array): void{
184184
global $all, $some, $classes;
185185
$statuses = array(0,0,0,0);
186186
$worst = 5;
@@ -258,7 +258,7 @@ public function render(){
258258
}
259259
}
260260

261-
public function jsonSerialize() {
261+
public function jsonSerialize(): mixed {
262262
global $statuses;
263263
return [
264264
"id" => $this->id,

classes/subscriber.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function is_active_subscriber($token)
190190
{
191191
global $mysqli;
192192

193-
193+
// error_log(print_r($token, TRUE));
194194
$stmt = $mysqli->prepare("SELECT subscriberID, token, userID, active, expires FROM subscribers WHERE token LIKE ? LIMIT 1");
195195
$stmt->bind_param("s", $token );
196196
$stmt->execute();
@@ -202,7 +202,7 @@ public function is_active_subscriber($token)
202202
// No data found, fail gently...
203203
return false;
204204
}
205-
205+
// error_log(print_r($row, TRUE));
206206
// If account is not already active, check if we are within timeframe of exipre +2h
207207
// and active if so, otherwise,delete account and return falsev
208208
if ( $row['active'] <> 1 ) {

classes/user.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ public static function add()
210210
public static function login()
211211
{
212212
global $message, $mysqli;
213-
if (!isset($_POST['email']) && !isset($_POST['email']))
213+
if (!isset($_POST['email']) && !isset($_POST['pass']))
214214
{
215215
return;
216216
}
217217

218-
if ((!isset($_POST['email']) || !isset($_POST['email'])))
218+
if ((!isset($_POST['email']) || !isset($_POST['pass'])))
219219
{
220220
$message = _("Please fill in your email and password!");
221221
return;

create-server-config.php

+19-10
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,26 @@
77
// This is needed because some hosts do not either unzip hidden files
88
// or neither GitHub puts that file inside the zips.
99
/********************************************************************/
10+
$apacheExampleName = "ApacheHtaccess";
11+
$apacheProductionName = ".htaccess";
12+
$iisExampleName = "IISWebConfig";
13+
$iisProductionName = "web.config";
1014
if(stripos($_SERVER['SERVER_SOFTWARE'],'apache')!== false){
11-
$f = fopen(".htaccess", "a+");
12-
$f2 = fopen("ApacheHtaccess","r");
13-
fwrite($f, fread($f2, filesize("ApacheHtaccess")));
14-
fclose($f);
15-
fclose($f2);
15+
if(!file_exists($apacheProductionName)) {
16+
$f = fopen($apacheProductionName, "a+");
17+
$f2 = fopen($apacheExampleName,"r");
18+
fwrite($f, fread($f2, filesize($apacheExampleName)));
19+
fclose($f);
20+
fclose($f2);
21+
}
22+
// skipping renaming file if it already exists
1623
} else {
17-
$f = fopen("web.config", "a+");
18-
$f2 = fopen("IISWebConfig","r");
19-
fwrite($f, fread($f2, filesize("IISWebConfig")));
20-
fclose($f);
21-
fclose($f2);
24+
if(!file_exists($iisProductionName)) {
25+
$f = fopen($iisProductionName, "a+");
26+
$f2 = fopen($iisExampleName,"r");
27+
fwrite($f, fread($f2, filesize($iisExampleName)));
28+
fclose($f);
29+
fclose($f2);
30+
}
2231
}
2332
?>

css/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ div.center {
9595
#wrapper
9696
{
9797
max-width: 1024px;
98-
min-height: calc(100vh - 157px);
98+
min-height: calc(100vh - 139px);
9999
padding-right: 15px;
100100
padding-left: 15px
101101
}

docker-compose.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3'
2+
3+
networks:
4+
status-db:
5+
6+
services:
7+
server-status:
8+
build: .
9+
volumes:
10+
- ./:/var/www/html
11+
ports:
12+
- 4000:80
13+
networks:
14+
- status-db
15+
dbserver:
16+
image: mysql
17+
command: --default-authentication-plugin=mysql_native_password
18+
environment:
19+
MYSQL_ROOT_PASSWORD: e347h43cve89
20+
MYSQL_DATABASE: server_status
21+
volumes:
22+
- ./database:/var/lib/mysql
23+
networks:
24+
- status-db
25+
mailhog:
26+
image: mailhog/mailhog
27+
ports:
28+
- "1025:1025"
29+
- "8025:8025"
30+
networks:
31+
- status-db

index.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@
4040
define("WEB_URL", $db->getSetting($mysqli,"url"));
4141
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
4242
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
43-
44-
define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli,"subscribe_email"));
45-
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli,"subscribe_telegram"));
46-
define("TG_BOT_USERNAME", $db->getSetting($mysqli,"tg_bot_username"));
47-
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli,"tg_bot_api_token"));
48-
define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli,"google_recaptcha"));
49-
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli,"google_recaptcha_sitekey"));
50-
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli,"google_recaptcha_secret"));
43+
define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli,"subscribe_email") ?: "");
44+
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli,"subscribe_telegram") ?: "");
45+
define("TG_BOT_USERNAME", $db->getSetting($mysqli,"tg_bot_username") ?: "");
46+
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli,"tg_bot_api_token") ?: "");
47+
define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli,"google_recaptcha") ?: "");
48+
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli,"google_recaptcha_sitekey") ?: "");
49+
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli,"google_recaptcha_secret") ?: "");
5150
$offset = 0;
5251

5352
if (isset($_GET['ajax']))
@@ -101,7 +100,7 @@
101100
<?php $constellation->render_status();?>
102101
</div>
103102

104-
<?php if ($mysqli->query("SELECT count(*) FROM status")->num_rows)
103+
<?php if ($mysqli->query("SELECT count(*) FROM status"))
105104
{
106105
?>
107106
<div id="timeline">
@@ -119,3 +118,10 @@
119118

120119
Template::render_footer();
121120
}
121+
?>
122+
<script>
123+
$(document).ready(function(){
124+
$('[data-toggle="tooltip"]').tooltip();
125+
});
126+
</script>
127+
<?php

0 commit comments

Comments
 (0)