diff --git a/app/Configs.php b/app/Configs.php index 7021518498b..b7ff2470b54 100644 --- a/app/Configs.php +++ b/app/Configs.php @@ -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; @@ -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; diff --git a/app/Http/Controllers/DiagnosticsController.php b/app/Http/Controllers/DiagnosticsController.php index 2f3da8b3014..6f488fabbdd 100644 --- a/app/Http/Controllers/DiagnosticsController.php +++ b/app/Http/Controllers/DiagnosticsController.php @@ -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; @@ -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 @@ -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; @@ -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 @@ -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']); @@ -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; diff --git a/app/ModelFunctions/ConfigFunctions.php b/app/ModelFunctions/ConfigFunctions.php index 71c669a1402..3a3c6ba907d 100644 --- a/app/ModelFunctions/ConfigFunctions.php +++ b/app/ModelFunctions/ConfigFunctions.php @@ -4,6 +4,7 @@ use App\Configs; use App\Locale\Lang; +use Illuminate\Database\QueryException; class ConfigFunctions { @@ -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(); } } } diff --git a/database/migrations/2019_09_28_171753_config_fix.php b/database/migrations/2019_09_28_171753_config_fix.php index b4b23a60b87..b11fbf95683 100644 --- a/database/migrations/2019_09_28_171753_config_fix.php +++ b/database/migrations/2019_09_28_171753_config_fix.php @@ -308,7 +308,7 @@ public function up() ], [ 'key' => 'landing_page_enable', - 'value' => '1', + 'value' => '0', 'cat' => 'Mod Welcome', 'type_range' => BOOL, 'confidentiality' => '0',