Updated JSON to MIT

Cleaned up sanity.php
Cleaning up random bugs and cretura
This commit is contained in:
Michał Gdula 2022-11-06 16:31:22 +00:00
parent 5da0da06fd
commit c9b81414b0
10 changed files with 251 additions and 242 deletions

View file

@ -1,5 +1,5 @@
{
"license": "GPL 3.0",
"version": "22.11.05",
"license": "MIT",
"version": "22.11.06",
"branch": "main"
}

19
app/sanity/check/_dir.php Normal file
View file

@ -0,0 +1,19 @@
<?php
if (defined('ROOT') && $_SESSION['id'] == 1) {
$files = array(
'usr/images',
'usr/images/pfp',
'usr/images/previews',
'usr/images/thumbnails'
);
foreach ($files as $file) {
if (!is_dir(__DIR__."/../../../$file")) {
$results[] = array(
'type'=>'critical',
'message'=>"$file is missing",
'fix'=>'auto'
);
}
}
}

View file

@ -0,0 +1,83 @@
<?php
if (defined('ROOT') && $_SESSION['id'] == 1) {
if (!is_file(__DIR__."/../../../usr/conf/msg.json")) {
$results[] = array(
'type'=>'warning',
'message'=>'msg.json is missing',
'fix'=>'auto'
);
}
if (!is_file(__DIR__."/../../../usr/conf/conf.json")) {
if (is_file(__DIR__."/../../../usr/conf/manifest.json")) {
$results[] = array(
'type'=>'warning',
'message'=>'manifest.json is deprecated, the file should be renamed to conf.json if you dont want errors in the future',
'fix'=>'manual'
);
} elseif (is_file(__DIR__."/../../../app/settings/manifest.json")) {
$results[] = array(
'type'=>'warning',
'message'=>'manifest.json is deprecated, the file should be renamed to conf.json and move it to usr/conf if you dont want errors in the future',
'fix'=>'manual'
);
} else {
$results[] = array(
'type'=>'critical',
'message'=>'conf.json is missing, using conf.default.json instead',
'fix'=>'auto'
);
}
} else {
$manifest = json_decode(file_get_contents(__DIR__."/../../../usr/conf/conf.json"), true);
if (empty($manifest['user_name']) || $manifest['user_name'] == "[your name]") {
$results[] = array(
'type'=>'warning',
'message'=>'conf.json is missing your name',
'fix'=>'manual'
);
}
if ($manifest['upload']['rename_on_upload']) {
if (empty($manifest['upload']['rename_to'])) {
$results[] = array(
'type'=>'critical',
'message'=>'conf.json doesnt know what to rename your files to',
'fix'=>'manual'
);
} else {
$rename_to = $manifest['upload']['rename_to'];
$rename_rate = 0;
if (str_contains($rename_to, '{{autoinc}}')) $rename_rate = 5;
if (str_contains($rename_to, '{{time}}')) $rename_rate = 5;
if (str_contains($rename_to, '{{date}}')) $rename_rate += 2;
if (str_contains($rename_to, '{{filename}}')) $rename_rate += 2;
if (str_contains($rename_to, '{{username}}') || str_contains($rename_to, '{{userid}}')) $rename_rate += 1;
if ($rename_rate < 2) {
$results[] = array(
'type'=>'critical',
'message'=>'You will encounter errors when uploading images due to filenames, update your conf.json',
'fix'=>'manual'
);
} elseif ($rename_rate < 5 && $rename_rate > 2) {
$results[] = array(
'type'=>'warning',
'message'=>'You may encounter errors when uploading images due to filenames, concider modifying your conf.json',
'fix'=>'manual'
);
}
}
}
if ($manifest['is_testing']) {
$results[] = array(
'type'=>'warning',
'message'=>'You are currently in testing mode, errors will be displayed to the user. This is not recommended for production use.'
);
}
}
}

View file

@ -0,0 +1,32 @@
<?php
if (defined('ROOT') && $_SESSION['id'] == 1) {
$files = array(
'usr/images',
'usr/images/pfp',
'usr/images/previews',
'usr/images/thumbnails',
'usr/conf/conf.json',
'usr/conf/msg.json',
'usr/conf.default.json'
);
foreach ($files as $file) {
if (!is_writable(__DIR__."/../../../$file")) {
$results[] = array(
'type'=>'critical',
'message'=>"$file is not writable",
'fix'=>'manual'
);
}
}
foreach ($files as $file) {
if (!fileperms(__DIR__."/../../../$file")) {
$results[] = array(
'type'=>'critical',
'message'=>"PHP does not have permitions for $file",
'fix'=>'manual'
);
}
}
}

View file

@ -0,0 +1,52 @@
<?php
if (defined('ROOT') && $_SESSION['id'] == 1) {
// Local app info
$app_local = json_decode(file_get_contents(__DIR__."/../../gallery.json"), true);
// Repo app info
$curl_url = "https://raw.githubusercontent.com/Fluffy-Bean/image-gallery/".$app_local['branch']."/app/settings/manifest.json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $curl_url);
$result = curl_exec($curl);
curl_close($curl);
$app_repo = json_decode($result, true);
// Go to newer file location to prevent errors once the old location is removed
if (!$app_repo || empty($app_repo)) {
$curl_url = "https://raw.githubusercontent.com/Fluffy-Bean/image-gallery/".$app_local['branch']."/app/gallery.json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $curl_url);
$result = curl_exec($curl);
curl_close($curl);
$app_repo = json_decode($result, true);
}
if ($app_local['version'] < $app_repo['version']) {
$results[] = array(
'type'=>'critical',
'message'=>'You are not running the latest version of the app v'.$app_repo['version'],
'link'=>'https://github.com/Fluffy-Bean/image-gallery',
'fix'=>'manual'
);
} elseif ($app_local['version'] > $app_repo['version']) {
$results[] = array(
'type'=>'critical',
'message'=>'You are running a version of the app that is newer than the latest release v'.$app_repo['version'],
'link'=>'https://github.com/Fluffy-Bean/image-gallery',
'fix'=>'manual'
);
}
if (PHP_VERSION_ID < 80000) {
$results[] = array(
'type'=>'warning',
'message'=>'Your current version of PHP is '.PHP_VERSION.' The reccomended version is 8.0.0 or higher',
'link'=>'https://www.php.net/downloads.php',
'fix'=>'manual'
);
}
}

View file

@ -1,6 +1,6 @@
<?php
if (defined('ROOT') && $_SESSION['id'] == 1) {
if (is_dir(__DIR__."/../../usr")) {
if (is_dir(__DIR__."/../../../usr")) {
echo "<p><span style='color: var(--accent);'>[INFO]</span> Found usr/ folder!</p>";
} else {
echo "<p><span style='color: var(--warning);'>[ERRO]</span> usr/ folder not found</p>";
@ -9,7 +9,7 @@ if (defined('ROOT') && $_SESSION['id'] == 1) {
mkdir("usr");
}
if (is_dir(__DIR__."/../../usr/images")) {
if (is_dir(__DIR__."/../../../usr/images")) {
echo "<p><span style='color: var(--accent);'>[INFO]</span> Found usr/images/ folder!</p>";
} else {
echo "<p><span style='color: var(--warning);'>[ERRO]</span> usr/images/ folder not found</p>";
@ -17,36 +17,36 @@ if (defined('ROOT') && $_SESSION['id'] == 1) {
mkdir("usr/images");
}
if (!is_dir(__DIR__."/../../usr/images/thumbnails")) {
if (!is_dir(__DIR__."/../../../usr/images/thumbnails")) {
echo "<p><span style='color: var(--warning);'>[ERRO]</span> usr/images/thumbnails/ folder not found</p>";
echo "<p><span style='color: var(--accent);'>[INFO]</span> Creating usr/images/thumbnails/ folder...</p>";
mkdir("usr/images/thumbnails");
}
if (!is_dir(__DIR__."/../../usr/images/previews")) {
if (!is_dir(__DIR__."/../../../usr/images/previews")) {
echo "<p><span style='color: var(--warning);'>[ERRO]</span> usr/images/previews/ folder not found</p>";
echo "<p><span style='color: var(--accent);'>[INFO]</span> Creating usr/images/previews/ folder...</p>";
mkdir("usr/images/previews");
}
if (!is_dir(__DIR__."/../../usr/conf")) {
if (!is_dir(__DIR__."/../../../usr/conf")) {
echo "<p><span style='color: var(--warning);'>[ERRO]</span> usr/conf/ folder not found</p>";
echo "<p><span style='color: var(--accent);'>[INFO]</span> Creating usr/conf/ folder...</p>";
mkdir("usr/conf");
}
if (is_file("../../usr/conf/conf.json")) {
if (is_file(__DIR__."/../../../usr/conf/conf.json")) {
echo "<p><span style='color: var(--accent);'>[INFO]</span> Found usr/conf/conf.json file!</p>";
} else {
echo "<p><span style='color: var(--warning);'>[ERRO]</span> usr/conf/conf.json file not found</p>";
echo "<p><span style='color: var(--accent);'>[INFO]</span> Creating usr/conf/conf.json file...</p>";
try {
$conf = file_get_contents(__DIR__."/../../usr/conf.default.json");
$conf = file_get_contents(__DIR__."/../../../usr/conf.default.json");
$conf_new = fopen(__DIR__."/../../usr/conf/conf.json", "w");
$conf_new = fopen(__DIR__."/../../../usr/conf/conf.json", "w");
if ($conf_new) {
fwrite($conf_new, $conf);

View file

@ -19,10 +19,10 @@ if (isset($_POST['fix'])) {
define('ROOT', true); // Only run scripts from this file
echo "<p>==== Databases ====</p>";
include_once "database.php";
require_once "fix/_database.php";
echo "<p>==== Folders ====</p>";
include_once "folders.php";
require_once "fix/_folders.php";
$autofix_end = microtime(true);
$autofix_time = ($autofix_end - $autofix_start);
@ -32,233 +32,50 @@ if (isset($_POST['fix'])) {
}
if (isset($_POST['check'])) {
function check_json(): array
{
$results = array();
if (!is_file(__DIR__."/../../usr/conf/msg.json")) {
$results[] = array(
'type'=>'warning',
'message'=>'msg.json is missing',
'fix'=>'auto'
);
}
if (!is_file(__DIR__."/../../usr/conf/conf.json")) {
if (is_file(__DIR__."/../../usr/conf/manifest.json")) {
$results[] = array(
'type'=>'critical',
'message'=>'manifest.json is deprecated, please rename it to conf.json',
'fix'=>'manual'
);
} else {
$results[] = array(
'type'=>'critical',
'message'=>'conf.json is missing, using conf.default.json instead',
'fix'=>'auto'
);
}
} else {
$manifest = json_decode(file_get_contents(__DIR__."/../../usr/conf/conf.json"), true);
if (empty($manifest['user_name']) || $manifest['user_name'] == "[your name]") {
$results[] = array(
'type'=>'warning',
'message'=>'conf.json is missing your name',
'fix'=>'manual'
);
}
if ($manifest['upload']['rename_on_upload']) {
if (empty($manifest['upload']['rename_to'])) {
$results[] = array(
'type'=>'critical',
'message'=>'conf.json doesnt know what to rename your files to',
'fix'=>'manual'
);
} else {
$rename_to = $manifest['upload']['rename_to'];
$rename_rate = 0;
if (str_contains($rename_to, '{{autoinc}}')) $rename_rate = 5;
if (str_contains($rename_to, '{{time}}')) $rename_rate = 5;
if (str_contains($rename_to, '{{date}}')) $rename_rate += 2;
if (str_contains($rename_to, '{{filename}}')) $rename_rate += 2;
if (str_contains($rename_to, '{{username}}') || str_contains($rename_to, '{{userid}}')) $rename_rate += 1;
if ($rename_rate < 2) {
$results[] = array(
'type'=>'critical',
'message'=>'You will encounter errors when uploading images due to filenames, update your conf.json',
'fix'=>'manual'
);
} elseif ($rename_rate < 5 && $rename_rate > 2) {
$results[] = array(
'type'=>'warning',
'message'=>'You may encounter errors when uploading images due to filenames, concider modifying your conf.json',
'fix'=>'manual'
);
}
}
}
if ($manifest['is_testing']) {
$results[] = array(
'type'=>'warning',
'message'=>'You are currently in testing mode, errors will be displayed to the user. This is not recommended for production use.'
);
}
}
return $results;
if (empty($_SESSION['id'])) {
echo "<p><span style='color: var(--warning);'>[ERROR]</span> You are not logged in</p>";
exit();
} elseif ($_SESSION['id'] != 1) {
echo "<p><span style='color: var(--warning);'>[ERRO]</span> You cannot use Autofix as an Admin currently.</p>";
exit();
}
function check_dir(): array
{
$results = array();
define('ROOT', true); // Only run scripts from this file
$results = array(); // Array to store results
$files = array(
'usr/images',
'usr/images/pfp',
'usr/images/previews',
'usr/images/thumbnails'
);
require_once "check/_dir.php";
require_once "check/_json.php";
require_once "check/_perms.php";
require_once "check/_versions.php";
foreach ($files as $file) {
if (!is_dir(__DIR__."/../../$file")) {
$results[] = array(
'type'=>'critical',
'message'=>"$file is missing",
'fix'=>'auto'
);
}
}
return $results;
}
function check_version(): array
{
$results = array();
// Local app info
$app_local = json_decode(file_get_contents(__DIR__."/../gallery.json"), true);
// Repo app info
$curl_url = "https://raw.githubusercontent.com/Fluffy-Bean/image-gallery/".$app_local['branch']."/app/settings/manifest.json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $curl_url);
$result = curl_exec($curl);
curl_close($curl);
$app_repo = json_decode($result, true);
if ($app_local['version'] < $app_repo['version']) {
$results[] = array(
'type'=>'critical',
'message'=>'You are not running the latest version of the app v'.$app_repo['version'],
'link'=>'https://github.com/Fluffy-Bean/image-gallery',
'fix'=>'manual'
);
} elseif ($app_local['version'] > $app_repo['version']) {
$results[] = array(
'type'=>'critical',
'message'=>'You are running a version of the app that is newer than the latest release v'.$app_repo['version'],
'link'=>'https://github.com/Fluffy-Bean/image-gallery',
'fix'=>'manual'
);
}
if (PHP_VERSION_ID < 80000) {
$results[] = array(
'type'=>'warning',
'message'=>'Your current version of PHP is '.PHP_VERSION.' The reccomended version is 8.0.0 or higher',
'link'=>'https://www.php.net/downloads.php',
'fix'=>'manual'
);
}
return $results;
}
function check_permissions(): array
{
$results = array();
$files = array(
'usr/images',
'usr/images/pfp',
'usr/images/previews',
'usr/images/thumbnails',
'usr/conf/conf.json',
'usr/conf/msg.json',
'usr/conf.default.json'
);
foreach ($files as $file) {
if (!is_writable(__DIR__."/../../$file")) {
$results[] = array(
'type'=>'critical',
'message'=>"$file is not writable",
'fix'=>'manual'
);
}
}
foreach ($files as $file) {
if (!fileperms(__DIR__."/../../$file")) {
$results[] = array(
'type'=>'critical',
'message'=>"PHP does not have permitions for $file",
'fix'=>'manual'
);
}
}
return $results;
}
if ($_SESSION['id'] == 1) {
$results = array();
foreach (check_json() as $result) $results[] = $result;
foreach (check_dir() as $result) $results[] = $result;
foreach (check_permissions() as $result) $results[] = $result;
foreach (check_version() as $result) $results[] = $result;
if (empty($results)) {
echo "<p class='alert alert-good'>No errors! Lookin' good :3</p>";
} else {
foreach ($results as $result) {
if ($result['type'] == 'critical') {
echo "<p class='alert alert-bad'><span class='badge badge-critical'>Critical</span> ";
} else {
echo "<p class='alert alert-warning'><span class='badge badge-warning'>Warning</span> ";
}
if ($result['fix'] == 'auto') {
echo "<span class='badge badge-primary'>Auto fix available</span> ";
$autofix_enable = true;
} elseif ($result['fix'] == 'manual') {
echo "<span class='badge badge-critical'>Manual fix required</span> ";
}
if (isset($result['link'])) {
echo "<a class='link badge badge-primary' href='".$result['link']."'>Recources</a> ";
}
echo $result['message']."</p>";
}
if ($autofix_enable) {
echo "<button class='btn btn-bad' onclick=\"$('#sanityCheck').load('app/sanity/sanity.php', {fix: 'true'});\">
Attempt Autofix
</button>";
}
}
if (empty($results)) {
echo "<p class='alert alert-good'>No errors! Lookin' good :3</p>";
} else {
echo "<p class='alert alert-bad'>You do not have permission todo this action!!!!!</p>";
}
foreach ($results as $result) {
if ($result['type'] == 'critical') {
echo "<p class='alert alert-bad'><span class='badge badge-critical'>Critical</span> ";
} else {
echo "<p class='alert alert-warning'><span class='badge badge-warning'>Warning</span> ";
}
if ($result['fix'] == 'auto') {
echo "<span class='badge badge-primary'>Auto fix available</span> ";
$autofix_enable = true;
} elseif ($result['fix'] == 'manual') {
echo "<span class='badge badge-critical'>Manual fix required</span> ";
}
if (isset($result['link'])) {
echo "<a class='link badge badge-primary' href='".$result['link']."'>Recources</a> ";
}
echo $result['message']."</p>";
}
if ($autofix_enable) {
echo "<button class='btn btn-bad' onclick=\"$('#sanityCheck').load('app/sanity/sanity.php', {fix: 'true'});\">
Attempt Autofix
</button>";
}
}
}

View file

@ -10,14 +10,19 @@
*/
if (is_file(__DIR__."/../usr/conf/conf.json")) {
$user_settings = json_decode(file_get_contents(__DIR__."/../usr/conf/conf.json"), true);
if (is_file(__DIR__."/../usr/conf/msg.json")) {
$user_welcome = json_decode(file_get_contents(__DIR__."/../usr/conf/msg.json"), true)['welcome'];
}
} elseif (is_file(__DIR__."/../usr/conf/manifest.json")) {
$user_settings = json_decode(file_get_contents(__DIR__."/../usr/conf/manifest.json"), true);
$user_welcome = $user_settings['welcome_msg'];
} elseif (is_file(__DIR__."/manifest.json")) {
$user_settings = json_decode(file_get_contents(__DIR__."/manifest.json"), true);
$user_welcome = $user_settings['welcome_msg'];
} else {
$user_settings = json_decode(file_get_contents(__DIR__."/../usr/conf.default.json"), true);
}
if (is_file(__DIR__."/../usr/conf/msg.json")) {
$user_welcome = json_decode(file_get_contents(__DIR__."/../usr/conf/msg.json"), true);
$user_welcome = $user_welcome['welcome'];
}
$web_info = json_decode(file_get_contents(__DIR__."/gallery.json"), true);
$upload_conf = $user_settings['upload'];

View file

@ -14,5 +14,6 @@
"png",
"webp"
]
}
},
"manifest": "3"
}