index.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // Setup includes to work right. Much of this is duped in Config.inc, but gotta get this info to include it, so..
  3. $user_info = posix_getpwuid(posix_geteuid());
  4. $dir = ( $user_info['dir'] ? $user_info['dir'] : '/var/www/' );
  5. $basedir = ( file_exists( $dir . "/.tCMS_basedir") ? file_get_contents("$dir/.tCMS_basedir") : "$dir/.tCMS" );
  6. set_include_path(get_include_path() . PATH_SEPARATOR . "$basedir/lib");
  7. require_once "tCMS/Config.inc";
  8. // Get the config, set the theme (also set the basedir so we don't have to fetch it again).
  9. $conf_obj = new Config;
  10. $conf_obj->set_base_dir($basedir);
  11. $config = $conf_obj->get();
  12. $theme = ( !array_key_exists( 'theme', $config ) || empty($config['theme']) ? 'default' : $config['theme'] );
  13. $themedir = "$basedir/templates/$theme";
  14. // Begin dispatch
  15. $args = ( $_SERVER['REQUEST_METHOD'] == 'POST' ? $_POST : $_GET );
  16. if( !empty($args['app']) && $args['app'] == 'login' ) {
  17. include "$themedir/admin/login.inc";
  18. die();
  19. } elseif( !empty($args['app']) && $args['app'] == 'logout' ) {
  20. include "$themedir/admin/logout.inc";
  21. die();
  22. } else {
  23. require_once "tCMS/Auth.inc";
  24. $auth = new Auth;
  25. $auth->ensure_auth();
  26. }
  27. if( empty($args['app']) || $args['app'] == 'config' ) {
  28. $kontent = "$themedir/admin/settings.inc";
  29. } elseif ($args['app'] == 'blog') {
  30. if(!empty($args['get_fragment'])) {
  31. # Need to sanitize
  32. $path = realpath("$basedir/blog/".$args['get_fragment']);
  33. if(strpos($path, "$basedir/blog") !== 0 ) die("Forbidden: Tried to load $path, but $basedir/blog is not the start of the real path.");
  34. die(file_get_contents("$basedir/blog/".$args['get_fragment']));
  35. }
  36. $kontent = "$themedir/admin/bengine.inc";
  37. } elseif ($args['app'] == 'microblog') {
  38. $kontent = "$themedir/admin/mbengine.inc";
  39. } elseif ($args['app'] == 'users' ) {
  40. $kontent = "$themedir/admin/users.inc";
  41. } else {
  42. $kontent = "$themedir/admin/settings.inc";
  43. }
  44. ?>
  45. <!doctype html>
  46. <html dir="ltr" lang="en-US">
  47. <head>
  48. <meta charset="utf-8" />
  49. <meta name="description" content="tCMS Control Panel"/>
  50. <meta name="viewport" content="width=device-width">
  51. <?php
  52. $links = '<link rel="stylesheet" type="text/css" href="../../themed/' . $theme . '/css/structure.css" />';
  53. $links .= '<link rel="stylesheet" type="text/css" href="../../themed/' . $theme . '/css/screen.css" media="screen" />';
  54. $links .= '<link rel="stylesheet" type="text/css" href="../../themed/' . $theme . '/css/print.css" media="print" />';
  55. $links .= '<link rel="icon" type="image/vnd.microsoft.icon" href="../../themed/' . $theme . '/img/icon/favicon.ico" />';
  56. echo $links;
  57. // TODO inject avatars these via style tags based on config
  58. ?>
  59. <title>tCMS Admin</title>
  60. <?php
  61. ?>
  62. </head>
  63. <body>
  64. <div id="topkek" style="text-align: center; vertical-align: middle;">
  65. <button title="Menu" id="clickme">&#9776;</button>
  66. <span id="configbar">
  67. <a class="topbar" title="Edit Various Settings" href="index.php?app=config">Settings</a>
  68. <a class="topbar" title="Blog Writer" href="index.php?app=blog">Blog Writer</a>
  69. <a class="topbar" title="Pop off about Stuff" href="index.php?app=microblog">MicroBlogger</a>
  70. <a class="topbar" title="Logout" href="index.php?app=logout">Logout</a>
  71. </span>
  72. </div>
  73. <div id="kontent" style="display: block;">
  74. <?php
  75. include $kontent;
  76. ?>
  77. </div>
  78. </body>
  79. </html>