An PHP based Image Database
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.3 KiB

  1. <?
  2. //
  3. // Copyright (c) 2013 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/
  4. //
  5. // Permission to use, copy, modify, and/or distribute this software for any purpose
  6. // with or without fee is hereby granted, provided that the above copyright notice
  7. // and this permission notice appear in all copies.
  8. //
  9. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  10. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  11. // FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  12. // OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  14. // ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. //
  16. error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT);
  17. $_MGM = array();
  18. $_MGM['version'] = "2";
  19. $_MGM['title'] = "Image Database";
  20. $_MGM['DBType'] = "SQLITE"; // MYSQL, POSTGRESQL, SQLITE.
  21. $_MGM['DBPersistent'] = NO;
  22. $_MGM['DBHost'] = "localhost";
  23. $_MGM['DBUser'] = "";
  24. $_MGM['DBPassword'] = "";
  25. $_MGM['DBName'] = "databases/main.db"; // File location for SQLite.
  26. $_MGM['DBPort'] = 0; // 3306 = MySQL Default, 5432 = PostgreSQL Default.
  27. $_MGM['DBPrefix'] = "";
  28. $_MGM['adminEmail'] = "default@domain.com";
  29. require_once("db{$_MGM['DBType']}.php");
  30. $_MGM['imagemagick'] = ""; // Path to ImageMagick bin folder.
  31. putenv("TZ=US/Central");
  32. $_MGM['time'] = time();
  33. $_MGM['domain'] = $_SERVER['HTTP_HOST'];
  34. $_MGM['domainname'] = str_replace("www.", "", $_MGM['domain']);
  35. $_MGM['port'] = $_SERVER['SERVER_PORT'];
  36. $_MGM['ssl'] = ($_MGM['port']==443);
  37. if ($_SERVER['REMOTE_ADDR'])
  38. $_MGM['ip'] = $_SERVER['REMOTE_ADDR'];
  39. if ($_SERVER['HTTP_PC_REMOTE_ADDR'])
  40. $_MGM['ip'] = $_SERVER['HTTP_PC_REMOTE_ADDR'];
  41. if ($_SERVER['HTTP_CLIENT_IP'])
  42. $_MGM['ip'] = $_SERVER['HTTP_CLIENT_IP'];
  43. if ($_SERVER['HTTP_X_FORWARDED_FOR'])
  44. $_MGM['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
  45. $_MGM['installPath'] = substr($_SERVER['SCRIPT_NAME'], 0, strlen($_SERVER['SCRIPT_NAME'])-strlen(end(explode("/", $_SERVER['SCRIPT_NAME']))));
  46. if (!isset($_GET['d'])) {
  47. $tmp = explode("?", substr($_SERVER['REQUEST_URI'], strlen($_MGM['installPath'])));
  48. $tmp = urldecode($tmp[0]);
  49. if (substr($tmp, 0, 9)=="index.php")
  50. $tmp = substr($tmp, 10, strlen($tmp)-10);
  51. $_MGM['fullPath'] = $tmp;
  52. } else {
  53. $tmp = $_GET['d'];
  54. if (substr($tmp, 0, 1)=="/")
  55. $tmp = substr($tmp, 1, strlen($tmp)-1);
  56. $_MGM['fullPath'] = $tmp;
  57. }
  58. if (strlen($_MGM['fullPath'])>255) error("The URI you entered is to large");
  59. $_MGM['path'] = explode("/", strtolower($_MGM['fullPath']));
  60. $_MGM['CookiePrefix'] = "";
  61. $_MGM['CookiePath'] = $_MGM['installPath'];
  62. $_MGM['CookieDomain'] = ".".$_MGM['domainname'];
  63. function generateURL($path) {
  64. global $_MGM;
  65. return "http".($_MGM['ssl'] ? "s" : "")."://".$_MGM['domain'].(((!$_MGM['ssl'] && $_MGM['port']==80) || ($_MGM['ssl'] && $_MGM['port']==443)) ? "" : ":{$_MGM['port']}").$_MGM['installPath'].$path;
  66. }
  67. function hashPassword($password, $salt) {
  68. $hashed = hash("sha512", $salt.$password);
  69. for ($i=0; $i<10000; $i++) {
  70. $hashed = hash("sha512", $salt.hex2bin($hashed));
  71. }
  72. return $hashed;
  73. }
  74. connectToDatabase();
  75. if (file_exists("code/setup.php")) {
  76. require("code/setup.php");
  77. }
  78. if (isset($_COOKIE["{$_MGM['CookiePrefix']}user_email"])) {
  79. $result = databaseQuery("SELECT * FROM users WHERE email=%s AND level!=0", $_COOKIE["{$_MGM['CookiePrefix']}user_email"]);
  80. $user = databaseFetchAssoc($result);
  81. if ($user!=NULL && hash("sha512", $user['password'].$user['time'])==$_COOKIE["{$_MGM['CookiePrefix']}user_password"]) {
  82. $_MGM['user'] = $user;
  83. }
  84. }
  85. if (!isset($_MGM['user']) && $_MGM['path'][0]=="login") {
  86. require("code/login.php");
  87. }
  88. if (isset($_MGM['user']) && $_MGM['path'][0]=="logout") {
  89. require("code/logout.php");
  90. }
  91. if ($_MGM['path'][0]=="re-ocr") {
  92. require("code/re-ocr.php");
  93. }
  94. if (isset($_MGM['user']) && $_MGM['path'][0]=="upload") {
  95. require("code/upload.php");
  96. }
  97. if ($_MGM['path'][0]=="api") {
  98. require("code/api.php");
  99. }
  100. if (isset($_MGM['user']) && $_MGM['user']['level']==1 && $_MGM['path'][0]=="users") {
  101. require("code/users.php");
  102. }
  103. if (isset($_MGM['user']) && $_MGM['path'][0]=="tagless") {
  104. require("code/tagless.php");
  105. }
  106. if ($_MGM['path'][0]=="hash") {
  107. require("code/hash.php");
  108. }
  109. if ($_MGM['path'][0]!="") {
  110. require("code/404.php");
  111. }
  112. require("code/index.php");
  113. ?>