2020-07-10 01:18:23 +02:00
|
|
|
<?php
|
2020-08-12 17:50:25 +00:00
|
|
|
require_once 'RequestBase.php';
|
2020-10-21 19:14:45 +00:00
|
|
|
require_once __DIR__ . '/../VideoParser.php';
|
2020-07-10 01:18:23 +02:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Class Settings
|
|
|
|
* Backend for the Settings page
|
|
|
|
*/
|
2020-07-29 23:42:36 +02:00
|
|
|
class Settings extends RequestBase {
|
2020-07-31 01:03:51 +02:00
|
|
|
function initHandlers() {
|
2020-08-12 17:50:25 +00:00
|
|
|
$this->getFromDB();
|
|
|
|
$this->saveToDB();
|
2020-10-21 19:14:45 +00:00
|
|
|
$this->reIndexHandling();
|
2020-08-12 17:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* handle settings stuff to load from db
|
|
|
|
*/
|
2020-10-19 21:12:07 +00:00
|
|
|
private function getFromDB() {
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* load currently set settings form db for init of settings page
|
|
|
|
*/
|
2020-07-31 01:03:51 +02:00
|
|
|
$this->addActionHandler("loadGeneralSettings", function () {
|
2020-10-19 21:12:07 +00:00
|
|
|
// query settings and infotile values
|
|
|
|
$query = "
|
|
|
|
SELECT (
|
|
|
|
SELECT COUNT(*)
|
|
|
|
FROM videos
|
|
|
|
) AS videonr,
|
|
|
|
(
|
|
|
|
SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS Size
|
|
|
|
FROM information_schema.TABLES
|
|
|
|
WHERE TABLE_SCHEMA = '" . Database::getInstance()->getDatabaseName() . "'
|
|
|
|
GROUP BY table_schema
|
|
|
|
) AS dbsize,
|
|
|
|
(
|
|
|
|
SELECT COUNT(*)
|
|
|
|
FROM tags
|
|
|
|
) AS difftagnr,
|
|
|
|
(
|
|
|
|
SELECT COUNT(*)
|
|
|
|
FROM video_tags
|
|
|
|
) AS tagsadded,
|
|
|
|
settings.*
|
|
|
|
FROM settings
|
|
|
|
LIMIT 1
|
|
|
|
";
|
2020-07-10 01:18:23 +02:00
|
|
|
|
2020-07-29 23:42:36 +02:00
|
|
|
$result = $this->conn->query($query);
|
2020-07-10 01:18:23 +02:00
|
|
|
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
2020-07-18 01:10:04 +02:00
|
|
|
// booleans need to be set manually
|
2020-08-04 18:53:11 +02:00
|
|
|
$r['passwordEnabled'] = $r['password'] != "-1";
|
2020-07-18 01:10:04 +02:00
|
|
|
$r['TMDB_grabbing'] = ($r['TMDB_grabbing'] != '0');
|
|
|
|
|
2020-07-10 01:18:23 +02:00
|
|
|
echo json_encode($r);
|
2020-07-29 23:42:36 +02:00
|
|
|
});
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* load initial data for home page load to check if pwd is set
|
|
|
|
*/
|
|
|
|
$this->addActionHandler("loadInitialData", function () {
|
|
|
|
$query = "SELECT * from settings";
|
|
|
|
|
|
|
|
$result = $this->conn->query($query);
|
|
|
|
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
$r['passwordEnabled'] = $r['password'] != "-1";
|
|
|
|
unset($r['password']);
|
|
|
|
$r['DarkMode'] = (bool)($r['DarkMode'] != '0');
|
|
|
|
$this->commitMessage(json_encode($r));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* handle setting stuff to save to db
|
|
|
|
*/
|
2020-10-19 21:12:07 +00:00
|
|
|
private function saveToDB() {
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* save changed settings to db
|
|
|
|
*/
|
2020-07-31 01:03:51 +02:00
|
|
|
$this->addActionHandler("saveGeneralSettings", function () {
|
2020-07-10 19:13:40 +02:00
|
|
|
$mediacentername = $_POST['mediacentername'];
|
|
|
|
$password = $_POST['password'];
|
|
|
|
$videopath = $_POST['videopath'];
|
|
|
|
$tvshowpath = $_POST['tvshowpath'];
|
2020-07-18 01:10:04 +02:00
|
|
|
$tmdbsupport = $_POST['tmdbsupport'];
|
2020-07-29 23:00:37 +02:00
|
|
|
$darkmodeenabled = $_POST['darkmodeenabled'];
|
2020-07-10 19:13:40 +02:00
|
|
|
|
|
|
|
$query = "UPDATE settings SET
|
|
|
|
video_path='$videopath',
|
|
|
|
episode_path='$tvshowpath',
|
|
|
|
password='$password',
|
2020-07-18 01:10:04 +02:00
|
|
|
mediacenter_name='$mediacentername',
|
2020-07-29 23:00:37 +02:00
|
|
|
TMDB_grabbing=$tmdbsupport,
|
|
|
|
DarkMode=$darkmodeenabled
|
2020-07-10 19:13:40 +02:00
|
|
|
WHERE 1";
|
|
|
|
|
2020-07-29 23:42:36 +02:00
|
|
|
if ($this->conn->query($query) === true) {
|
2021-01-22 21:05:21 +00:00
|
|
|
$this->commitMessage('{"result": "success"}');
|
2020-07-10 19:13:40 +02:00
|
|
|
} else {
|
2021-01-22 21:05:21 +00:00
|
|
|
$this->commitMessage('{"result": "success"}');
|
2020-07-10 19:13:40 +02:00
|
|
|
}
|
2020-07-29 23:42:36 +02:00
|
|
|
});
|
2020-07-10 01:18:23 +02:00
|
|
|
}
|
2020-10-21 19:14:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* methods for handling reindexing and cleanup of db gravity
|
|
|
|
*/
|
|
|
|
private function reIndexHandling() {
|
|
|
|
$this->addActionHandler("startReindex", function () {
|
|
|
|
$indexrunning = false;
|
|
|
|
if (file_exists("/tmp/output.log")) {
|
|
|
|
|
|
|
|
$out = file_get_contents("/tmp/output.log");
|
|
|
|
if (substr($out, -strlen("-42")) == "-42") {
|
|
|
|
unlink("/tmp/output.log");
|
|
|
|
} else {
|
|
|
|
$indexrunning = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$indexrunning) {
|
|
|
|
// start extraction of video previews in background
|
|
|
|
|
|
|
|
$cmd = 'php extractvideopreviews.php';
|
|
|
|
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, '/dev/zero', '/tmp/openmediacenterpid'));
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
$this->commitMessage('{"result": "success"}');
|
2020-10-21 19:14:45 +00:00
|
|
|
} else {
|
2021-01-22 21:05:21 +00:00
|
|
|
$this->commitMessage('{"result": "success"}');
|
2020-10-21 19:14:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->addActionHandler("cleanupGravity", function () {
|
|
|
|
$vp = new VideoParser();
|
|
|
|
$vp->cleanUpGravity();
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->addActionHandler("getStatusMessage", function () {
|
|
|
|
$return = new stdClass();
|
|
|
|
if (file_exists("/tmp/output.log")) {
|
|
|
|
$out = file_get_contents("/tmp/output.log");
|
|
|
|
// clear log file
|
|
|
|
file_put_contents("/tmp/output.log", "");
|
|
|
|
$return->message = $out;
|
|
|
|
$return->contentAvailable = true;
|
|
|
|
|
|
|
|
if (substr($out, -strlen("-42")) == "-42") {
|
|
|
|
unlink("/tmp/output.log");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$return->contentAvailable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->commitMessage(json_encode($return));
|
|
|
|
});
|
|
|
|
}
|
2020-07-10 01:18:23 +02:00
|
|
|
}
|