| 1 | <?php |
| 2 | require_once('config/config.inc'); //requiring main config file with path/database etc. constants |
| 3 | if(isset($realm) && isset($users)) require_once(INCLUDE_DIR.'http_auth.php'); //Ask for auth if enabled... |
| 4 | //echo($_SERVER['PATH_INFO']."\n<pre>"); var_dump(preg_split('/\//', $_SERVER['PATH_INFO'])); die(); //PATH_INFO Debug (usefull when messing with mod_rewrite) |
| 5 | // output buffering forcing (mx) |
| 6 | if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_start(); |
| 7 | |
| 8 | //header("Location: http://web.archive.org/web/20020925021139/http://kyberia.sk"); |
| 9 | //echo "je to uz uplne v pici. vsetky data su stratene, prajem pekny den :)"; |
| 10 | //exit; |
| 11 | |
| 12 | //starting timer for benchmarking purposes |
| 13 | $timer_start=Time()+SubStr(MicroTime(),0,8); |
| 14 | //setting PHPSESSID cookie and starting user session |
| 15 | session_start(); |
| 16 | |
| 17 | error_reporting(1); |
| 18 | //$_SESSION['debugging']=1; |
| 19 | //unset($_SESSION['debugging']); //Well... we should make some event or JavaScript page to turning this on/off... |
| 20 | //exit; |
| 21 | |
| 22 | |
| 23 | if ($_SESSION['debugging']) { |
| 24 | |
| 25 | error_reporting(E_ALL); |
| 26 | echo 'GET VARIABLES::<br/>'; |
| 27 | print_r($_GET); |
| 28 | echo 'POST VARIABLES::<br/>'; |
| 29 | print_r($_POST); |
| 30 | echo '<b>SESSION VARIABLES::</b><br/>'; |
| 31 | print_r($_SESSION); |
| 32 | } |
| 33 | |
| 34 | @ini_set('magic_quotes_gpc' , 'off'); |
| 35 | if(get_magic_quotes_gpc()) die("Error: magic_quotes_gpc needs to be disabled! F00K!\n"); |
| 36 | |
| 37 | //Smarty from DB |
| 38 | $smarty_resource = 'kyberia'; |
| 39 | //$smarty_resource = ''; //same as 'file' (fallback) |
| 40 | /* I have moved old templates to DB using following lame script: |
| 41 | * for i in *.tpl; do j=$(echo "$i" | cut -d . -f 1); echo UPDATE nodes SET node_content = "'$(php -r "echo mysql_escape_string(file_get_contents('$i'));")'" WHERE node_id = "'$j'" COLLATE utf8_bin LIMIT '1;'; done | mysql --user=kyberia --password=PASSSSSSS kyberia |
| 42 | * In future we should have some mechanism for distributing templates because they are very important part of kyberia source... |
| 43 | */ |
| 44 | |
| 45 | //Path info (Experimental - this replaced most of mod_rewrites...) |
| 46 | @$PATH_INFO=trim($_SERVER[PATH_INFO]); |
| 47 | if($PATH_INFO != '') { |
| 48 | $PATH_CHUNKS = preg_split('/\//', $PATH_INFO); |
| 49 | if(isset($PATH_CHUNKS[1])) switch($PATH_CHUNKS[1]) { |
| 50 | case 'k': |
| 51 | if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_kid'] = $PATH_CHUNKS[2]; |
| 52 | if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_kid'] = $PATH_CHUNKS[3]; |
| 53 | break; |
| 54 | case 'id': |
| 55 | if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_id'] = $PATH_CHUNKS[2]; |
| 56 | if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_id'] = $PATH_CHUNKS[3]; |
| 57 | |
| 58 | //Base36 fascism redirect |
| 59 | if($_GET['template_id'] == 'download') break; //Fix ugly download hack... |
| 60 | if(!count($_POST)) { |
| 61 | header('Location: /k/'.base_convert($_GET['node_id'], 10, 36). |
| 62 | (isset($_GET['template_id'])?'/'.base_convert($_GET['template_id'], 10, 36):'') |
| 63 | ); |
| 64 | die("Base36 fascism...\n"); //If you want to be a fascist you have to die imediatelly... |
| 65 | } |
| 66 | |
| 67 | break; |
| 68 | default: |
| 69 | if($PATH_CHUNKS[1] != '') $_GET['node_name'] = $PATH_CHUNKS[1]; |
| 70 | if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['template_kid'] = $PATH_CHUNKS[2]; |
| 71 | break; |
| 72 | } |
| 73 | } |
| 74 | if( |
| 75 | (!isset($_GET['node_kid']) || trim($_GET['node_kid']) == '') && |
| 76 | (!isset($_GET['node_id']) || trim($_GET['node_id']) == '') |
| 77 | ) $_GET['node_kid'] = 1; |
| 78 | |
| 79 | //Base36 http://en.wikipedia.org/wiki/Base_36 (Initial support only :-) |
| 80 | if(isset($_GET['node_kid'])) $_GET['node_id'] = base_convert($_GET['node_kid'], 36, 10); |
| 81 | if(isset($_GET['template_kid'])) $_GET['template_id'] = base_convert($_GET['template_kid'], 36, 10); |
| 82 | |
| 83 | if (isset($_SERVER['HTTP_REFERER'])) { |
| 84 | preg_match('/(k|id)\/([0-9]*)\//',$_SERVER['HTTP_REFERER'],$ref_match); |
| 85 | $referer_id=$ref_match[1]; |
| 86 | } |
| 87 | |
| 88 | //connecting to database and creating universal $db object |
| 89 | require_once(INCLUDE_DIR.'senate.inc'); |
| 90 | require_once(INCLUDE_DIR.'log.inc'); |
| 91 | require_once(INCLUDE_DIR.'ubik.inc'); |
| 92 | require_once(INCLUDE_DIR.'nodes.inc'); |
| 93 | require_once(INCLUDE_DIR.'error_messages.inc'); |
| 94 | require_once(INCLUDE_DIR.'database.inc'); |
| 95 | require_once(INCLUDE_DIR.'transports.inc'); |
| 96 | |
| 97 | $db = new CLASS_DATABASE(); |
| 98 | |
| 99 | if (!empty($_GET['template_id'])) { |
| 100 | $template_id=$_GET['template_id']; |
| 101 | } else { |
| 102 | $template_id=false; |
| 103 | } |
| 104 | |
| 105 | //initializing node methods |
| 106 | if (!empty($_GET['node_name'])) { |
| 107 | $node = nodes::redirByName($_GET['node_name']); |
| 108 | } elseif (!empty($_GET['node_id'])) { |
| 109 | $node = nodes::getNodeById($_GET['node_id'], |
| 110 | (isset($_SESSION['user_id']))?$_SESSION['user_id']:''); |
| 111 | } |
| 112 | |
| 113 | //XXX Paths are wrong (!) |
| 114 | //loading smarty template engine and setting main parameters |
| 115 | require(SMARTY_DIR.'Smarty.class.php'); |
| 116 | $smarty = new Smarty; |
| 117 | require(INCLUDE_DIR.'smarty/resource.kyberia.php'); |
| 118 | $smarty->default_resource_type=$smarty_resource; |
| 119 | |
| 120 | //$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX |
| 121 | $smarty->template_dir = TEMPLATE_DIR; |
| 122 | //echo TEMPLATE_DIR.TEMPLATE_SET; |
| 123 | //echo $smarty->template_dir; |
| 124 | $smarty->compile_dir = SYSTEM_DATA.'templates_c/'; |
| 125 | $smarty->config_dir = SMARTY_DIR.'configs/'; //XXX neexistuje |
| 126 | $smarty->cache_dir = SMARTY_DIR.'cache/'; |
| 127 | $smarty->plugins_dir = SMARTY_PLUGIN_DIR ; |
| 128 | if ($_SESSION['debugging']) $smarty->debugging=true; |
| 129 | |
| 130 | // initializing variables |
| 131 | // preg_replace prevents LFI |
| 132 | if (empty($_POST['event'])) $event='display'; |
| 133 | else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']); |
| 134 | |
| 135 | |
| 136 | if ($_SESSION['debugging']) { |
| 137 | echo "<pre><b>NODE::"; |
| 138 | print_r($node); |
| 139 | echo "</pre>"; |
| 140 | } |
| 141 | |
| 142 | if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) { |
| 143 | $node['node_permission']='owner'; |
| 144 | } |
| 145 | |
| 146 | if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) { |
| 147 | if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) { |
| 148 | echo "node::".$node['node_vector']; |
| 149 | echo "cube_Vector::".$_SESSION['cube_vector']; |
| 150 | echo "you are out of allowed cwbe. access forbidden"; |
| 151 | die(); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | //if not existent node show our own 404 |
| 156 | if (empty($node)) { |
| 157 | $nodes= nodes::getNodesByName($_GET['node_name']); |
| 158 | if ($nodes) { |
| 159 | $smarty->assign('nodes',$nodes); |
| 160 | $content=$smarty->display('404.tpl'); |
| 161 | die(); |
| 162 | } |
| 163 | elseif ($_SESSION['user_id']) { |
| 164 | $smarty->assign('node_name',$_GET['node_name']); |
| 165 | $content=$smarty->display("modules/addnode.tpl"); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | //modifying node glass pearl //XXX WTF |
| 170 | //if (is_array($children_types[$node['node_type']])) { |
| 171 | // $smarty->assign('children_types',$children_types[$node['node_type']]); |
| 172 | //} |
| 173 | |
| 174 | //smarty->assign('types',$types); |
| 175 | //$node['node_type']=$types[$node['node_type']]; |
| 176 | |
| 177 | @include_once(INCLUDE_DIR.'mail_rss.inc'); //haluz... |
| 178 | |
| 179 | //checking permissions |
| 180 | function _checkPermissions() |
| 181 | { |
| 182 | global $permissions, $node; |
| 183 | require(INCLUDE_DIR.'permissions.inc'); |
| 184 | $permissions=permissions::checkPermissions($node); |
| 185 | $permissions['h']=permissions::isHierarch($node); |
| 186 | } |
| 187 | _checkPermissions(); |
| 188 | |
| 189 | //entering the node (executing the eventz) |
| 190 | if (($permissions['r']) || ($event != 'register')) { |
| 191 | //performing node_events (based on update/insert/delete db queries) |
| 192 | if ($event) { |
| 193 | require(INCLUDE_DIR.'eventz.inc'); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if (isset($_POST['FORCE_OB'])) ob_end_flush(); //output buffering forcing (mx) |
| 198 | |
| 199 | ?> |