Skip to content

Commit

Permalink
Fix a few issues. (#512)
Browse files Browse the repository at this point in the history
* fixes #510
* fixes #508

* landing page is disabled by default

This will fix some complains but this will generate new complains: 'why do I get API NOT FOUND when I access for the first time?' as we cannot highlight the 404 bug anymore
  • Loading branch information
ildyria authored Apr 28, 2020
1 parent bba6a03 commit 130f2ae
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 48 deletions.
32 changes: 22 additions & 10 deletions app/Configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,19 @@ public static function hasExiftool()

// value not yet set -> let's see if exiftool is available
if ($has_exiftool == 2) {
$path = exec('command -v exiftool');
if ($path == '') {
try {
$path = exec('command -v exiftool');
if ($path == '') {
self::set('has_exiftool', 0);
$has_exiftool = false;
} else {
self::set('has_exiftool', 1);
$has_exiftool = true;
}
} catch (Exception $e) {
self::set('has_exiftool', 0);
$has_exiftool = false;
} else {
self::set('has_exiftool', 1);
$has_exiftool = true;
Logs::warning(__METHOD__, __LINE__, 'exec is disabled, has_exiftool has been set to 0.');
}
} elseif ($has_exiftool == 1) {
$has_exiftool = true;
Expand All @@ -290,13 +296,19 @@ public static function hasFFmpeg()

// value not yet set -> let's see if ffmpeg is available
if ($has_ffmpeg == 2) {
$path = exec('command -v ffmpeg');
if ($path == '') {
try {
$path = exec('command -v ffmpeg');
if ($path == '') {
self::set('has_ffmpeg', 0);
$has_ffmpeg = false;
} else {
self::set('has_ffmpeg', 1);
$has_ffmpeg = true;
}
} catch (Exception $e) {
self::set('has_ffmpeg', 0);
$has_ffmpeg = false;
} else {
self::set('has_ffmpeg', 1);
$has_ffmpeg = true;
Logs::warning(__METHOD__, __LINE__, 'exec is disabled, set_ffmpeg has been set to 0.');
}
} elseif ($has_ffmpeg == 1) {
$has_ffmpeg = true;
Expand Down
90 changes: 58 additions & 32 deletions app/Http/Controllers/DiagnosticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use App\ModelFunctions\Helpers;
use App\ModelFunctions\SessionFunctions;
use Config;
use Exception;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
use Imagick;
Expand Down Expand Up @@ -134,8 +134,22 @@ public function get_errors()
$errors[] = 'Error: PHP ' . $extension . ' extension not activated';
}
}
if (!extension_loaded('mysqli') && !DB::getDriverName() == 'pgsql') {
$errors[] = 'Error: PHP mysqli extension not activated';

$db_possibilities = [
['mysql', 'mysqli'],
['mysql', 'pdo_mysql'],
['pgsql', 'pgsql'],
['pgsql', 'pdo_pgsql'],
['sqlite', 'sqlite3'],
];
try {
foreach ($db_possibilities as $db_possibility) {
if (DB::getDriverName() == $db_possibility[0] && !extension_loaded($db_possibility[1])) {
$errors[] = 'Error: ' . $db_possibility[0] . ' db driver selected and PHP ' . $db_possibility[1] . ' extension not activated';
}
}
} catch (QueryException $e) {
$errors[] = 'Error: ' . $e->getMessage();
}

// Permissions
Expand Down Expand Up @@ -227,6 +241,11 @@ public function get_errors()
}
}

if (!function_exists('exec')) {
$errors[]
= 'Warning: exec function has been disabled. You may experience some error 500, please report them to us.';
}

// @codeCoverageIgnoreEnd

return $errors;
Expand Down Expand Up @@ -276,32 +295,35 @@ public function get_info()

// About SQL version
// @codeCoverageIgnoreStart
switch (DB::getDriverName()) {
case 'mysql':
$results = DB::select(DB::raw('select version()'));
$dbver = $results[0]->{'version()'};
$dbtype = 'MySQL';
break;
case 'sqlite':
$results = DB::select(DB::raw('select sqlite_version()'));
$dbver = $results[0]->{'sqlite_version()'};
$dbtype = 'SQLite';
break;
case 'pgsql':
$results = DB::select(DB::raw('select version()'));
$dbver = $results[0]->{'version'};
$dbtype = 'PostgreSQL';
break;
default:
try {
try {
switch (DB::getDriverName()) {
case 'mysql':
$dbtype = 'MySQL';
$results = DB::select(DB::raw('select version()'));
$dbver = $results[0]->{'version()'};
} catch (Exception $e) {
$dbver = 'unknown';
}
$dbtype = DB::getDriverName();
break;
break;
case 'sqlite':
$dbtype = 'SQLite';
$results = DB::select(DB::raw('select sqlite_version()'));
$dbver = $results[0]->{'sqlite_version()'};
break;
case 'pgsql':
$dbtype = 'PostgreSQL';
$results = DB::select(DB::raw('select version()'));
$dbver = $results[0]->{'version'};
break;
default:
$dbtype = DB::getDriverName();
$results = DB::select(DB::raw('select version()'));
$dbver = $results[0]->{'version()'};
break;
}
} catch (QueryException $e) {
$errors[] = 'Error: ' . $e->getMessage();
$dbtype = 'Unknown SQL';
$dbver = 'unknown';
}

// @codeCoverageIgnoreEnd

// Output system information
Expand All @@ -317,7 +339,7 @@ public function get_info()
$infos[] = $this->line($dbtype . ' Version:', $dbver);
$infos[] = '';
$infos[] = $this->line('Imagick:', $imagick);
$infos[] = $this->line('Imagick Active:', $settings['imagick']);
$infos[] = $this->line('Imagick Active:', $settings['imagick'] ?? 'key not found in settings');
$infos[] = $this->line('Imagick Version:', $imagickVersion);
$infos[] = $this->line('GD Version:', $gdVersion['GD Version']);

Expand Down Expand Up @@ -352,12 +374,16 @@ public function get_config()
// Declare
$configs = [];

// Load settings
$settings = $this->configFunctions->min_info();
foreach ($settings as $key => $value) {
if (!is_array($value)) {
$configs[] = $this->line($key . ':', $value);
try {
// Load settings
$settings = $this->configFunctions->min_info();
foreach ($settings as $key => $value) {
if (!is_array($value)) {
$configs[] = $this->line($key . ':', $value);
}
}
} catch (QueryException $e) {
$configs[] = 'Error: ' . $e->getMessage();
}

return $configs;
Expand Down
15 changes: 10 additions & 5 deletions app/ModelFunctions/ConfigFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Configs;
use App\Locale\Lang;
use Illuminate\Database\QueryException;

class ConfigFunctions
{
Expand Down Expand Up @@ -83,13 +84,17 @@ public function admin()
*/
public function sanity(array &$return)
{
$configs = Configs::all(['key', 'value', 'type_range']);
try {
$configs = Configs::all(['key', 'value', 'type_range']);

foreach ($configs as $config) {
$message = $config->sanity($config->value);
if ($message != '') {
$return[] = $message;
foreach ($configs as $config) {
$message = $config->sanity($config->value);
if ($message != '') {
$return[] = $message;
}
}
} catch (QueryException $e) {
$return[] = 'Error: ' . $e->getMessage();
}
}
}
2 changes: 1 addition & 1 deletion database/migrations/2019_09_28_171753_config_fix.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function up()
],
[
'key' => 'landing_page_enable',
'value' => '1',
'value' => '0',
'cat' => 'Mod Welcome',
'type_range' => BOOL,
'confidentiality' => '0',
Expand Down

0 comments on commit 130f2ae

Please sign in to comment.