2020-11-19 23:12:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'dbutils.php';
|
|
|
|
require_once 'config.php';
|
2020-11-19 23:12:39 +01:00
|
|
|
defined('DB') || define ( 'DB','mysql' );
|
2020-11-19 23:12:37 +01:00
|
|
|
|
|
|
|
class OsSystem {
|
|
|
|
private static function outputEmptyImage() {
|
|
|
|
$my_img = imagecreate( 1,1 );
|
|
|
|
$background = imagecolorallocate( $my_img, 0, 0, 255 );
|
|
|
|
$black = imagecolorallocate($im, 0, 0, 0);
|
|
|
|
imagecolortransparent($my_img, $black);
|
|
|
|
header( "Content-type: image/png" );
|
|
|
|
imagepng( $my_img );
|
|
|
|
imagecolordeallocate( $background );
|
|
|
|
imagedestroy( $my_img );
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
public static function getlogo($pdo) {
|
|
|
|
$img = DbUtils::getImageData($pdo, 'logo', null);
|
|
|
|
self::outputImage($pdo, $img);
|
2020-11-19 23:12:37 +01:00
|
|
|
}
|
|
|
|
public static function getprodimage($pdo,$prodid) {
|
2020-11-19 23:12:39 +01:00
|
|
|
$img = DbUtils::getImageData($pdo, '', $prodid);
|
|
|
|
self::outputImage($pdo, $img);
|
2020-11-19 23:12:37 +01:00
|
|
|
}
|
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
private static function outputImage($pdo,$imgDataInBase64) {
|
2020-11-19 23:12:37 +01:00
|
|
|
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
|
|
|
header("Pragma: no-cache");
|
|
|
|
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
|
|
|
|
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_PNG));
|
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
if (!is_null($imgDataInBase64)) {
|
|
|
|
$img = base64_decode($imgDataInBase64);
|
|
|
|
$php_img = imagecreatefromstring($img);
|
|
|
|
|
|
|
|
imagesavealpha($php_img, true);
|
|
|
|
$color = imagecolorallocatealpha($php_img, 0, 0, 0, 127);
|
|
|
|
|
|
|
|
imagepng($php_img, NULL);
|
|
|
|
imagecolordeallocate( $color );
|
|
|
|
imagedestroy($php_img);
|
|
|
|
return;
|
2020-11-19 23:12:37 +01:00
|
|
|
}
|
|
|
|
self::outputEmptyImage();
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
private static function checkIndividualFileWriteStatus($filename) {
|
|
|
|
if (file_exists($filename)) {
|
|
|
|
if (is_writable($filename)) {
|
|
|
|
return array("writeable" => 1);
|
|
|
|
} else {
|
|
|
|
return array("writeable" => 0,"file" => "Datei $filename nicht beschreibbar", "reason" => '');
|
|
|
|
}
|
2020-11-19 23:12:46 +01:00
|
|
|
} else {
|
|
|
|
return array("writeable" => 1);
|
2020-11-19 23:12:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private static function checkFileDbWriteStatus() {
|
|
|
|
$dir = dirname(__FILE__) . '/../db';
|
|
|
|
if (!file_exists($dir)) {
|
|
|
|
return array("writeable" => 0,"file" => $dir, "reason" => "Verzeichnis existiert nicht");
|
|
|
|
} else if (!is_writable($dir)) {
|
|
|
|
return array("writeable" => 0,"file" => $dir, "reason" => '');
|
|
|
|
}
|
|
|
|
$filesToCheck = array(STATUS_FILE,OSSYSTEM_FILE,IMAGES_FILE,QUEUE_FILE);
|
|
|
|
foreach ($filesToCheck as $aFile) {
|
|
|
|
$filename = $dir . '/' . $aFile;
|
|
|
|
$writeStatus = self::checkIndividualFileWriteStatus($filename);
|
|
|
|
if ($writeStatus["writeable"] == 0) {
|
|
|
|
return $writeStatus;
|
|
|
|
}
|
|
|
|
}
|
2020-11-19 23:12:46 +01:00
|
|
|
return array("writeable" => 1);
|
2020-11-19 23:12:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getsystemstatus($pdo) {
|
|
|
|
$timezone = DbUtils::getConfigItem($pdo, "timezone", "Europe/Berlin");
|
2020-11-19 23:12:37 +01:00
|
|
|
date_default_timezone_set($timezone);
|
|
|
|
|
2020-11-19 23:12:46 +01:00
|
|
|
$writeStatus = array("writeable" => 1);
|
2020-11-19 23:12:39 +01:00
|
|
|
$lastaccess = null;
|
|
|
|
if (DB == "mysql") {
|
|
|
|
$sql = "SELECT date FROM %gueststatus% WHERE item=?";
|
|
|
|
$result = DbUtils::fetchSqlAll($pdo, $sql, array('lastosaccess'));
|
|
|
|
|
|
|
|
if (count($result) > 0) {
|
|
|
|
$lastaccess = $result[0]["date"];
|
|
|
|
}
|
2020-11-19 23:12:37 +01:00
|
|
|
} else {
|
2020-11-19 23:12:39 +01:00
|
|
|
try {
|
|
|
|
$writeStatus = self::checkFileDbWriteStatus();
|
|
|
|
$lastaccess = file_get_contents("../db/" . STATUS_FILE);
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$lastaccess = null;
|
|
|
|
}
|
2020-11-19 23:12:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-19 23:12:37 +01:00
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
$date = new DateTime();
|
|
|
|
$currentTimeStamp = $date->getTimestamp();
|
2020-11-19 23:12:37 +01:00
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
if (!is_null($lastaccess)) {
|
2020-11-19 23:12:37 +01:00
|
|
|
if (($currentTimeStamp - $lastaccess) > 60) {
|
2020-11-19 23:12:39 +01:00
|
|
|
$lastaccessok = 0;
|
2020-11-19 23:12:37 +01:00
|
|
|
} else {
|
2020-11-19 23:12:39 +01:00
|
|
|
$lastaccessok = 1;
|
2020-11-19 23:12:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-11-19 23:12:39 +01:00
|
|
|
$lastaccessok = 0;
|
2020-11-19 23:12:37 +01:00
|
|
|
}
|
2020-11-19 23:12:39 +01:00
|
|
|
|
|
|
|
return array("status" => "OK","msg" => array("lastaccessok" => $lastaccessok,"dbwritestatus" => $writeStatus));
|
2020-11-19 23:12:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_GET["command"])) {
|
|
|
|
$command = $_GET["command"];
|
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
$pdo = null;
|
|
|
|
if (DB == "mysql") {
|
|
|
|
$pdo = DbUtils::openDbAndReturnPdoStatic();
|
|
|
|
}
|
2020-11-19 23:12:37 +01:00
|
|
|
|
|
|
|
switch ($command) {
|
2020-11-19 23:12:39 +01:00
|
|
|
case "getsystemstatus":
|
|
|
|
$ret = OsSystem::getsystemstatus($pdo);
|
2020-11-19 23:12:37 +01:00
|
|
|
echo json_encode($ret);
|
|
|
|
break;
|
|
|
|
case "getlogo":
|
|
|
|
OsSystem::getlogo($pdo);
|
|
|
|
break;
|
|
|
|
case "getprodimage":
|
|
|
|
OsSystem::getprodimage($pdo,$_GET["prodid"]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|