diff --git a/404.php b/404.php index 1f01ea7..d3c6ced 100644 --- a/404.php +++ b/404.php @@ -1,4 +1,7 @@ > /usr/local/etc/php/conf.d/ssp.ini +RUN echo "display_errors = off" >> /usr/local/etc/php/conf.d/ssp.ini +RUN echo "error_reporting = E_ERROR" >> /usr/local/etc/php/conf.d/ssp.ini +RUN apt install git -y +WORKDIR /var/www/html +RUN docker-php-ext-install gettext +RUN docker-php-ext-install pdo_mysql +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 +RUN apt-get install -y locales +RUN locale-gen en_GB.UTF-8 +RUN sed -i '/en_GB.UTF-8/s/^# //g' /etc/locale.gen && \ + locale-gen +RUN apt-get install -y curl +# And clean up the image +RUN rm -rf /var/lib/apt/lists/* + +RUN curl -Lsf 'https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz' | tar -C '/usr/local' -xvzf - +ENV PATH /usr/local/go/bin:$PATH +RUN go get github.com/mailhog/mhsendmail +RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail +RUN echo 'sendmail_path = /usr/bin/mhsendmail --smtp-addr mailhog:1025' > /usr/local/etc/php/php.ini + + diff --git a/admin/user.php b/admin/user.php index 04c7ca4..315a501 100644 --- a/admin/user.php +++ b/admin/user.php @@ -47,7 +47,7 @@ Template::render_header(_("User"), true); ?>

query("SELECT id, name, description FROM services"); @@ -104,27 +104,12 @@ class Constellation } if (!$admin) { - ?> - - '; - //$arrCompletedGroups = array(); + foreach($array as $service){ - //print_r($service); - //if ( !empty($service->group_name) && !in_array($service->group_name, $arrCompletedGroups)) { -//print $service->name; - // $arrCompletedGroups[] = $service['group_name']; - // $service->render(true); - //} else { $service->render(); - //} } echo ''; - //echo '

'; + return $array; } else{ return $array; diff --git a/classes/incident.php b/classes/incident.php index 3a3cd0a..af7a695 100644 --- a/classes/incident.php +++ b/classes/incident.php @@ -223,7 +223,7 @@ class Incident implements JsonSerializable $this->id, "date" => $this->timestamp, diff --git a/classes/locale-negotiator.php b/classes/locale-negotiator.php index b13ee23..94060c4 100644 --- a/classes/locale-negotiator.php +++ b/classes/locale-negotiator.php @@ -150,7 +150,6 @@ class LocaleNegotiator 'nl_BE' => 'Nederlands', 'nl_NL' => 'Nederlands', 'nn_NO' => 'Nynorsk', - 'nb_NO' => 'Norsk Bokmål', 'nso_ZA' => 'Northern sotho', 'oc_FR' => 'Occitan', 'or_IN' => 'ଓଡ଼ିଆ', diff --git a/classes/notification.php b/classes/notification.php index 762bbd7..cf11ce7 100644 --- a/classes/notification.php +++ b/classes/notification.php @@ -60,6 +60,11 @@ class Notification $sql = "SELECT DISTINCT subscriberIDFK FROM services_subscriber WHERE serviceIDFK IN (" . $this->serviceids . ")"; $query = $mysqli->query($sql); + if (0 === $query->num_rows) { + // skip processing if no one needs to be notified + return; + } + // Create the queue tasks for email/telegram notifications $queue = new Queue(); $queue->status = $queue->all_status['populating']; @@ -125,7 +130,7 @@ class Notification * @param string $msg Body of message * @return boolean true = Sent / False = failed */ - public function submit_queue_telegram($userID, $firstname, $msg) + public static function submit_queue_telegram($userID, $firstname, $msg) { // TODO Handle limitations (Max 30 different subscribers per second) // TODO Error handling @@ -150,7 +155,7 @@ class Notification * @param String $uthkey Users token for managing subscription * @return void */ - public function submit_queue_email($subscriber, $subject, $msg) + public static function submit_queue_email($subscriber, $subject, $msg): bool { // TODO Error handling $mailer = new Mailer(); diff --git a/classes/queue.php b/classes/queue.php index dd8187c..adb6653 100644 --- a/classes/queue.php +++ b/classes/queue.php @@ -49,7 +49,7 @@ class Queue * Remove task from the queue * @return void */ - public function delete_task($task_id){ + public static function delete_task($task_id){ global $mysqli; $stmt = $mysqli->prepare("DELETE FROM queue_task WHERE id = ?"); $stmt->bind_param("i", $task_id); @@ -98,14 +98,14 @@ class Queue $this->set_task_status($this->all_status['ready']); // Make task available for release } - public function update_notification_retries($task_id, $subscriber_id) { + public static function update_notification_retries($task_id, $subscriber_id) { global $mysqli; $stmt = $mysqli->prepare("UPDATE queue_notify SET retries = retries+1 WHERE task_id = ? AND subscriber_id = ?"); $stmt->bind_param("ii", $task_id, $subscriber_id); $stmt->execute(); } - public function delete_notification($task_id, $subscriber_id) { + public static function delete_notification($task_id, $subscriber_id) { global $mysqli; $stmt = $mysqli->prepare("DELETE FROM queue_notify WHERE task_id = ? AND subscriber_id = ?"); $stmt->bind_param("ii", $task_id, $subscriber_id); @@ -114,7 +114,7 @@ class Queue } // TODO: Fix max attempts for notifications - public function process_queue(){ + public static function process_queue(){ global $mysqli; $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"); while ( $result = $stmt->fetch_assoc() ) { diff --git a/classes/service-group.php b/classes/service-group.php index 933571a..fef8934 100644 --- a/classes/service-group.php +++ b/classes/service-group.php @@ -8,6 +8,7 @@ class ServiceGroup private $name; private $description; private $visibility_id; + private $status; /** * Constructs servicegroup from its data. @@ -16,7 +17,7 @@ class ServiceGroup * @param String $description tooltip text * @param int $visibility_id how to display group items */ - function __construct($id, $name, $description, $visibility_id) + function __construct($id, $name, $description, $visibility_id, $status) { //TODO: Maybe get data from ID? @@ -153,7 +154,7 @@ class ServiceGroup * Get list of services groups. * @return array $groups */ - public function get_groups() { + public static function get_groups() { global $mysqli; $stmt = $mysqli->query("SELECT id, name FROM services_groups ORDER by name ASC"); diff --git a/classes/service.php b/classes/service.php index 268715c..5ed577e 100644 --- a/classes/service.php +++ b/classes/service.php @@ -180,7 +180,7 @@ class Service implements JsonSerializable * @param Service[] $array array of services * @return void */ - public static function current_status($array){ + public static function current_status($array): void{ global $all, $some, $classes; $statuses = array(0,0,0,0); $worst = 5; @@ -258,7 +258,7 @@ class Service implements JsonSerializable } } - public function jsonSerialize() { + public function jsonSerialize(): mixed { global $statuses; return [ "id" => $this->id, diff --git a/classes/subscriber.php b/classes/subscriber.php index 0fef6fd..9984513 100644 --- a/classes/subscriber.php +++ b/classes/subscriber.php @@ -190,7 +190,7 @@ Class Subscriber { global $mysqli; - + // error_log(print_r($token, TRUE)); $stmt = $mysqli->prepare("SELECT subscriberID, token, userID, active, expires FROM subscribers WHERE token LIKE ? LIMIT 1"); $stmt->bind_param("s", $token ); $stmt->execute(); @@ -202,7 +202,7 @@ Class Subscriber // No data found, fail gently... return false; } - + // error_log(print_r($row, TRUE)); // If account is not already active, check if we are within timeframe of exipre +2h // and active if so, otherwise,delete account and return falsev if ( $row['active'] <> 1 ) { diff --git a/classes/user.php b/classes/user.php index f613373..71c8576 100644 --- a/classes/user.php +++ b/classes/user.php @@ -210,12 +210,12 @@ class User public static function login() { global $message, $mysqli; - if (!isset($_POST['email']) && !isset($_POST['email'])) + if (!isset($_POST['email']) && !isset($_POST['pass'])) { return; } - if ((!isset($_POST['email']) || !isset($_POST['email']))) + if ((!isset($_POST['email']) || !isset($_POST['pass']))) { $message = _("Please fill in your email and password!"); return; diff --git a/create-server-config.php b/create-server-config.php index c3130da..f87c2aa 100644 --- a/create-server-config.php +++ b/create-server-config.php @@ -7,17 +7,26 @@ // This is needed because some hosts do not either unzip hidden files // or neither GitHub puts that file inside the zips. /********************************************************************/ +$apacheExampleName = "ApacheHtaccess"; +$apacheProductionName = ".htaccess"; +$iisExampleName = "IISWebConfig"; +$iisProductionName = "web.config"; if(stripos($_SERVER['SERVER_SOFTWARE'],'apache')!== false){ -$f = fopen(".htaccess", "a+"); -$f2 = fopen("ApacheHtaccess","r"); -fwrite($f, fread($f2, filesize("ApacheHtaccess"))); -fclose($f); -fclose($f2); + if(!file_exists($apacheProductionName)) { + $f = fopen($apacheProductionName, "a+"); + $f2 = fopen($apacheExampleName,"r"); + fwrite($f, fread($f2, filesize($apacheExampleName))); + fclose($f); + fclose($f2); + } +// skipping renaming file if it already exists } else { -$f = fopen("web.config", "a+"); -$f2 = fopen("IISWebConfig","r"); -fwrite($f, fread($f2, filesize("IISWebConfig"))); -fclose($f); -fclose($f2); + if(!file_exists($iisProductionName)) { + $f = fopen($iisProductionName, "a+"); + $f2 = fopen($iisExampleName,"r"); + fwrite($f, fread($f2, filesize($iisExampleName))); + fclose($f); + fclose($f2); + } } ?> diff --git a/css/main.css b/css/main.css index 41fad38..76bb956 100644 --- a/css/main.css +++ b/css/main.css @@ -95,7 +95,7 @@ div.center { #wrapper { max-width: 1024px; - min-height: calc(100vh - 157px); + min-height: calc(100vh - 139px); padding-right: 15px; padding-left: 15px } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..addea76 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3' + +networks: + status-db: + +services: + server-status: + build: . + volumes: + - ./:/var/www/html + ports: + - 4000:80 + networks: + - status-db + dbserver: + image: mysql + command: --default-authentication-plugin=mysql_native_password + environment: + MYSQL_ROOT_PASSWORD: e347h43cve89 + MYSQL_DATABASE: server_status + volumes: + - ./database:/var/lib/mysql + networks: + - status-db + mailhog: + image: mailhog/mailhog + ports: + - "1025:1025" + - "8025:8025" + networks: + - status-db \ No newline at end of file diff --git a/index.php b/index.php index c05380e..239ad7b 100644 --- a/index.php +++ b/index.php @@ -40,14 +40,13 @@ define("TITLE", $db->getSetting($mysqli,"title")); define("WEB_URL", $db->getSetting($mysqli,"url")); define("MAILER_NAME", $db->getSetting($mysqli,"mailer")); define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email")); - -define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli,"subscribe_email")); -define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli,"subscribe_telegram")); -define("TG_BOT_USERNAME", $db->getSetting($mysqli,"tg_bot_username")); -define("TG_BOT_API_TOKEN", $db->getSetting($mysqli,"tg_bot_api_token")); -define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli,"google_recaptcha")); -define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli,"google_recaptcha_sitekey")); -define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli,"google_recaptcha_secret")); +define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli,"subscribe_email") ?: ""); +define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli,"subscribe_telegram") ?: ""); +define("TG_BOT_USERNAME", $db->getSetting($mysqli,"tg_bot_username") ?: ""); +define("TG_BOT_API_TOKEN", $db->getSetting($mysqli,"tg_bot_api_token") ?: ""); +define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli,"google_recaptcha") ?: ""); +define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli,"google_recaptcha_sitekey") ?: ""); +define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli,"google_recaptcha_secret") ?: ""); $offset = 0; if (isset($_GET['ajax'])) @@ -101,7 +100,7 @@ Template::render_header("Status"); render_status();?> -query("SELECT count(*) FROM status")->num_rows) +query("SELECT count(*) FROM status")) { ?>
@@ -119,3 +118,10 @@ Template::render_header("Status"); Template::render_footer(); } +?> + += $len) return false; - $h = ord($c{$index}); + $h = ord($c[$index]); if ($h <= 0x7F) { $bytes = 1; return $h; @@ -21,18 +21,18 @@ function ordUTF8($c, $index = 0, &$bytes = null) return false; else if ($h <= 0xDF && $index < $len - 1) { $bytes = 2; - return ($h & 0x1F) << 6 | (ord($c{$index + 1}) & 0x3F); + return ($h & 0x1F) << 6 | (ord($c[$index + 1]) & 0x3F); } else if ($h <= 0xEF && $index < $len - 2) { $bytes = 3; - return ($h & 0x0F) << 12 | (ord($c{$index + 1}) & 0x3F) << 6 - | (ord($c{$index + 2}) & 0x3F); + return ($h & 0x0F) << 12 | (ord($c[$index + 1]) & 0x3F) << 6 + | (ord($c[$index + 2]) & 0x3F); } else if ($h <= 0xF4 && $index < $len - 3) { $bytes = 4; - return ($h & 0x0F) << 18 | (ord($c{$index + 1}) & 0x3F) << 12 - | (ord($c{$index + 2}) & 0x3F) << 6 - | (ord($c{$index + 3}) & 0x3F); + return ($h & 0x0F) << 18 | (ord($c[$index + 1]) & 0x3F) << 12 + | (ord($c[$index + 2]) & 0x3F) << 6 + | (ord($c[$index + 3]) & 0x3F); } else return false; diff --git a/libs/templates/email_status_update.html b/libs/templates/email_status_update.html index dea833e..8cbde2e 100644 --- a/libs/templates/email_status_update.html +++ b/libs/templates/email_status_update.html @@ -52,5 +52,5 @@ -

%unsubscribe%

+

%unsubscribe%

 %powered_by% Server-Status

\ No newline at end of file diff --git a/template.php b/template.php index ba89407..fb2532a 100644 --- a/template.php +++ b/template.php @@ -1,4 +1,11 @@ '; // If subscriber is not logged on, display subscriber menus @@ -56,9 +64,9 @@ class Template{ - +