index.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @author Tobias Reich
  4. * @copyright 2015 by Tobias Reich
  5. * @description This file takes a look at your Lychee-configuration and displays all errors it can find.
  6. */
  7. namespace Diagnostics;
  8. use Mysqli;
  9. use Imagick;
  10. use Lychee\Modules\Settings;
  11. $lychee = __DIR__ . '/../../';
  12. require($lychee . 'php/define.php');
  13. require($lychee . 'php/autoload.php');
  14. require($lychee . 'php/helpers/hasPermissions.php');
  15. // Start the session
  16. session_start();
  17. // Set content
  18. header('content-type: text/plain');
  19. // Declare
  20. $error = '';
  21. // Show separator
  22. echo('Diagnostics' . PHP_EOL);
  23. echo('-----------' . PHP_EOL);
  24. // PHP Version
  25. if (floatval(phpversion())<5.5) $error .= ('Error: Upgrade to PHP 5.5 or higher' . PHP_EOL);
  26. // Extensions
  27. if (!extension_loaded('session')) $error .= ('Error: PHP session extension not activated' . PHP_EOL);
  28. if (!extension_loaded('exif')) $error .= ('Error: PHP exif extension not activated' . PHP_EOL);
  29. if (!extension_loaded('mbstring')) $error .= ('Error: PHP mbstring extension not activated' . PHP_EOL);
  30. if (!extension_loaded('gd')) $error .= ('Error: PHP gd extension not activated' . PHP_EOL);
  31. if (!extension_loaded('mysqli')) $error .= ('Error: PHP mysqli extension not activated' . PHP_EOL);
  32. if (!extension_loaded('json')) $error .= ('Error: PHP json extension not activated' . PHP_EOL);
  33. if (!extension_loaded('zip')) $error .= ('Error: PHP zip extension not activated' . PHP_EOL);
  34. // Permissions
  35. if (hasPermissions(LYCHEE_UPLOADS_BIG)===false) $error .= ('Error: \'uploads/big\' is missing or has insufficient read/write privileges' . PHP_EOL);
  36. if (hasPermissions(LYCHEE_UPLOADS_MEDIUM)===false) $error .= ('Error: \'uploads/medium\' is missing or has insufficient read/write privileges' . PHP_EOL);
  37. if (hasPermissions(LYCHEE_UPLOADS_THUMB)===false) $error .= ('Error: \'uploads/thumb\' is missing or has insufficient read/write privileges' . PHP_EOL);
  38. if (hasPermissions(LYCHEE_UPLOADS_IMPORT)===false) $error .= ('Error: \'uploads/import\' is missing or has insufficient read/write privileges' . PHP_EOL);
  39. if (hasPermissions(LYCHEE_UPLOADS)===false) $error .= ('Error: \'uploads/\' is missing or has insufficient read/write privileges' . PHP_EOL);
  40. if (hasPermissions(LYCHEE_DATA)===false) $error .= ('Error: \'data/\' is missing or has insufficient read/write privileges' . PHP_EOL);
  41. // About GD
  42. $gdVersion = gd_info();
  43. if (!$gdVersion['JPEG Support']) $error .= ('Error: PHP gd extension without jpeg support' . PHP_EOL);
  44. if (!$gdVersion['PNG Support']) $error .= ('Error: PHP gd extension without png support' . PHP_EOL);
  45. if (!$gdVersion['GIF Read Support'] || !$gdVersion['GIF Create Support']) $error .= ('Error: PHP gd extension without full gif support' . PHP_EOL);
  46. // Load config
  47. if (!file_exists(LYCHEE_CONFIG_FILE)) exit('Error: Configuration not found. Please install Lychee for additional tests');
  48. require(LYCHEE_CONFIG_FILE);
  49. // Database
  50. $database = new Mysqli($dbHost, $dbUser, $dbPassword, $dbName);
  51. if (mysqli_connect_errno()!=0) $error .= ('Error: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error() . '' . PHP_EOL);
  52. // Config
  53. if (!isset($dbName)||$dbName==='') $error .= ('Error: No property for $dbName in config.php' . PHP_EOL);
  54. if (!isset($dbUser)||$dbUser==='') $error .= ('Error: No property for $dbUser in config.php' . PHP_EOL);
  55. if (!isset($dbPassword)) $error .= ('Error: No property for $dbPassword in config.php' . PHP_EOL);
  56. if (!isset($dbHost)||$dbHost==='') $error .= ('Error: No property for $dbHost in config.php' . PHP_EOL);
  57. // Load settings
  58. $settings = Settings::get();
  59. // Settings
  60. if (!isset($settings['username'])||$settings['username']=='') $error .= ('Error: Username empty or not set in database' . PHP_EOL);
  61. if (!isset($settings['password'])||$settings['password']=='') $error .= ('Error: Password empty or not set in database' . PHP_EOL);
  62. if (!isset($settings['sortingPhotos'])||$settings['sortingPhotos']=='') $error .= ('Error: Wrong property for sortingPhotos in database' . PHP_EOL);
  63. if (!isset($settings['sortingAlbums'])||$settings['sortingAlbums']=='') $error .= ('Error: Wrong property for sortingAlbums in database' . PHP_EOL);
  64. if (!isset($settings['plugins'])) $error .= ('Error: No property for plugins in database' . PHP_EOL);
  65. if (!isset($settings['imagick'])||$settings['imagick']=='') $error .= ('Error: No or wrong property for imagick in database' . PHP_EOL);
  66. if (!isset($settings['identifier'])||$settings['identifier']=='') $error .= ('Error: No or wrong property for identifier in database' . PHP_EOL);
  67. if (!isset($settings['skipDuplicates'])||$settings['skipDuplicates']=='') $error .= ('Error: No or wrong property for skipDuplicates in database' . PHP_EOL);
  68. if (!isset($settings['checkForUpdates'])||($settings['checkForUpdates']!='0'&&$settings['checkForUpdates']!='1')) $error .= ('Error: No or wrong property for checkForUpdates in database' . PHP_EOL);
  69. // Check dropboxKey
  70. if (!$settings['dropboxKey']) echo('Warning: Dropbox import not working. No property for dropboxKey.' . PHP_EOL);
  71. // Check php.ini Settings
  72. if (ini_get('max_execution_time')<200&&ini_set('upload_max_filesize', '20M')===false) echo('Warning: You may experience problems when uploading a large amount of photos. Take a look in the FAQ for details.' . PHP_EOL);
  73. if (!ini_get('allow_url_fopen')) echo('Warning: You may experience problems with the Dropbox- and URL-Import. Edit your php.ini and set allow_url_fopen to 1.' . PHP_EOL);
  74. // Check mysql version
  75. if ($database->server_version<50500) echo('Warning: Lychee uses the GBK charset to avoid sql injections on your MySQL version. Please update to MySQL 5.5 or higher to enable UTF-8 support.' . PHP_EOL);
  76. // Output
  77. if ($error==='') echo('No critical problems found. Lychee should work without problems!' . PHP_EOL);
  78. else echo $error;
  79. // Show separator
  80. echo(PHP_EOL . PHP_EOL . 'System Information' . PHP_EOL);
  81. echo('------------------' . PHP_EOL);
  82. // Ensure that user is logged in
  83. if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
  84. (isset($_SESSION['identifier'])&&$_SESSION['identifier']===$settings['identifier'])) {
  85. // Load json
  86. $json = file_get_contents(LYCHEE_SRC . 'package.json');
  87. $json = json_decode($json, true);
  88. // About imagick
  89. $imagick = extension_loaded('imagick');
  90. if ($imagick===true) $imagickVersion = @Imagick::getVersion();
  91. else $imagick = '-';
  92. if (!isset($imagickVersion, $imagickVersion['versionNumber'])||$imagickVersion==='') $imagickVersion = '-';
  93. else $imagickVersion = $imagickVersion['versionNumber'];
  94. // Output system information
  95. echo('Lychee Version: ' . $json['version'] . PHP_EOL);
  96. echo('DB Version: ' . $settings['version'] . PHP_EOL);
  97. echo('System: ' . PHP_OS . PHP_EOL);
  98. echo('PHP Version: ' . floatval(phpversion()) . PHP_EOL);
  99. echo('MySQL Version: ' . $database->server_version . PHP_EOL);
  100. echo('Imagick: ' . $imagick . PHP_EOL);
  101. echo('Imagick Active: ' . $settings['imagick'] . PHP_EOL);
  102. echo('Imagick Version: ' . $imagickVersion . PHP_EOL);
  103. echo('GD Version: ' . $gdVersion['GD Version'] . PHP_EOL);
  104. echo('Plugins: ' . implode($settings['plugins'], ', ') . PHP_EOL);
  105. } else {
  106. // Don't go further if the user is not logged in
  107. exit('You have to be logged in to see more information.');
  108. }
  109. ?>