start(); /////////////////////// function dump($var) { print "
".print_r($var,1)."
"; } /////////////////////////////////// //$db->debug_all = true; //$db->benchmark = true; /////////////////////////////////// require($INCLUDE_FOLDER."s_e404.inc.jsp"); require($INCLUDE_FOLDER."s_loadenv.inc.jsp"); header('Pragma: no-cache'); if (substr($REQUEST_URI, 0, 1) != "/") $REQUEST_URI="/".$REQUEST_URI; switch ($PHP_TYPE) { case 'module': header('HTTP/1.1 200 OK'); break; } $HTTP_FILES_PATH_PREG = str_replace("/", "\/", $HTTP_FILES_PATH); if (preg_match("/^".$HTTP_FILES_PATH_PREG."([0-9uct]+)\/([0-9]+\/)?h_([0-9A-Z]{32})+$/i", $parsed_url['path'], $matches)) { if ($matches[1] != "u" && $matches[1] != "c" && $matches[1] != "t") $matches[1] = intval($matches[1]); if (strlen($matches[2])) // cc $File_Path = "{$matches[1]}/{$matches[2]}"; else $File_Path = "{$matches[1]}/"; $sql = "SELECT Real_Name, File_Type, File_Size FROM Filetable WHERE Virt_Name = '{$matches[3]}' AND File_Path = '/{$File_Path}' LIMIT 1 "; $q = $db->get_row($sql, ARRAY_N); if ($db->num_rows != 0) { list($Real_Name, $File_Type, $File_Size) = $q; if (!strlen($File_Type)) $File_Type = 'application/octet-stream'; @ob_end_clean(); if ($use_gzip_compression) header("Content-Encoding: "); // sic (remove header) header("Content-type: {$File_Type}"); header("Content-Disposition: attachment; filename=\"".urldecode($Real_Name)."\""); header('Content-Transfer-Encoding: binary'); if ($File_Size) header("Content-Length: {$File_Size}"); @readfile($FILES_FOLDER.$File_Path.$matches[3]); exit; } } $client_source_url = $parsed_url['scheme']."://".($parsed_url['user']?$parsed_url['user']:"").($parsed_url['pass']?":".$parsed_url['pass']:"").(($parsed_url['user'] || $parsed_url['pass'])?"@":"").$parsed_url['host'].($parsed_url['port']?":".$parsed_url['port']:"").$parsed_url['path']; $catalogue = ""; $sub = ""; $cc = ""; $classID = ""; $user_table_mode = false; $admin_mode = false; $current_catalogue = GetCatalogueByHostName($_SERVER["HTTP_HOST"]); $catalogue = $current_catalogue["Catalogue_ID"]; // no catalogues? database is empty? system is not installed? if (!$catalogue) { $count_tables = $db->get_var("SHOW TABLES LIKE 'Settings'"); if (!$count_tables) { header("Location: /install/"); die(); } } LoadModuleEnv(); $e404_sub = $current_catalogue["E404_Sub_ID"]; $title_sub = $current_catalogue["Title_Sub_ID"]; if (($req_file = strrchr($parsed_url['path'],"/")) <> "/") { $req_file = substr($req_file,1,strlen($req_file) - 1); $req_file_parts = explode(".",$req_file); $fname = $req_file_parts[0]; $fext = strtolower($req_file_parts[count($req_file_parts)-1]); if ($fext == "html") { $parsed_url['path'] = substr ($parsed_url['path'], 0, strlen($parsed_url['path']) - strlen($req_file)); preg_match("| / (\d{4}) / (?: (\d{2}) / )? (?: (\d{2}) / )? |x", $parsed_url['path'], $regs); if ($regs) { $parsed_url_pathtmp = str_replace($regs[0], "/", $parsed_url['path']); array_shift($regs); $date_tmp = join("-", $regs); } $sql = "SELECT a.Subdivision_ID, b.Sub_Class_ID, b.Class_ID, c.System_Table_ID FROM Subdivision AS a, Sub_Class AS b, Class AS c WHERE (a.Hidden_URL='".$parsed_url['path']."' OR a.Hidden_URL='".$parsed_url_pathtmp."') AND a.Catalogue_ID=".$catalogue." AND a.Subdivision_ID=b.Subdivision_ID AND b.Class_ID=c.Class_ID ORDER BY b.Checked, b.Priority "; $res = $db->get_results($sql,ARRAY_N); if ($db->num_rows) { foreach ($res as $row) { list($subdivisionID,$subClassID,$classID,$sysTbl) = $row; if ($result=ObjectExists($classID,$sysTbl,$subClassID,$fname)) { $action = "full"; $message = $result; $cc = $subClassID; $sub = $subdivisionID; break; } } } if (!$message) { if (ereg ("([-[:alnum:]]+)_([0-9]+)", $fname, $regs) && ($fname == $regs[1]."_".$regs[2])) { $cc_keyword = $regs[1]; $message = $regs[2]; $action = "full"; } elseif (ereg ("([[:alnum:]]+)_([-[:alnum:]]+)",$fname, $regs) && ($fname == $regs[1]."_".$regs[2]) && ($regs[1]=="add" || $regs[1]=="search" || $regs[1]=="subscribe")) { $action = $regs[1]; $cc_keyword = $regs[2]; } else { $cc_keyword = $fname; } } } else { $parsed_url['path'] .= "/"; $redirect_to_url = $client_source_url."/".($parsed_url[query]?"?".$parsed_url[query]:"").($parsed_url[fragment]?"#".$parsed_url[fragment]:""); } } preg_match("| / (\d{4}) / (?: (\d{2}) / )? (?: (\d{2}) / )? |x", $parsed_url['path'], $regs); if ($regs) { $parsed_url_pathtmp = str_replace($regs[0], "/", $parsed_url['path']); array_shift($regs); $date_tmp = join("-", $regs); } if ($parsed_url['path'] == "/") $sub = $title_sub; else $sub = GetSubdivisionID ($catalogue, $parsed_url['path']); if (!$sub) { $sub = GetSubdivisionID ($catalogue, $parsed_url_pathtmp); if ($sub) $date = $date_tmp; } if ($sub && $redirect_to_url) { if ($REDIRECT_STATUS == "on") { if ($AUTHORIZATION_TYPE=='session') { if (substr($redirect_to_url,-1)!='l' && substr($redirect_to_url,-1)!='/') {$redirect_to_url .= ("&".session_name()."=".session_id()); } else { $redirect_to_url .= ("?".session_name()."=".session_id()); } } header("Location: ${redirect_to_url}"); exit; } } AttemptToRedirect($client_source_url); if ($sub) { $cc_array = array(); // used in loadenv(); if ($cc_in_sub = $db->get_results("SELECT sc.*, c.System_Table_ID FROM Sub_Class as sc, Class as c WHERE sc.Subdivision_ID='".$sub."' AND sc.Class_ID = c.Class_ID ORDER BY sc.Priority", ARRAY_A)) { foreach ($cc_in_sub as $row) { if (($cc_keyword && $row['EnglishName']==$cc_keyword) // we've got keyword || (!$cc_keyword && !$cc && $row['Checked'])) // or class is active and we don't know $cc yet { $cc = $row["Sub_Class_ID"]; // current class $classID = $row["Class_ID"]; $default_action = $row["DefaultAction"]; $system_table = $row["System_Table_ID"]; } // $cc_array, used in loadenv() $cc_array[] = $row["Sub_Class_ID"]; } } if (!$action) $action = $default_action; if ($system_table) $user_table_mode = true; // $last_updated используется при выдаче заголовков if ($classID && !$user_table_mode) $last_updated = $db->get_var("SELECT UNIX_TIMESTAMP(LastUpdated) FROM Message".$classID." WHERE Subdivision_ID='".$sub."' AND Sub_Class_ID='".$cc."' AND Checked=1 ORDER BY LastUpdated DESC LIMIT 1"); if ($cc && $date) { $FieldID = $db->get_var("SELECT Field_ID FROM Field WHERE Format='event' AND TypeOfData_ID=8 AND Class_ID='".$classID."' LIMIT 1"); if (!$FieldID) $sub = $e404_sub; } if ((($cc_keyword && !$message) || (!$cc && !$cc_keyword)) && $date) $sub = $e404_sub; if ($message && $action=="full") { $res = $db->query("SELECT ".($user_table_mode?"User":"Message")."_ID FROM ".($user_table_mode?"User":"Message$classID")." WHERE Checked=1 AND ".($user_table_mode?"User":"Message")."_ID='".$message."'"); $msg_count = $db->num_rows; if (!$msg_count) $sub = $e404_sub; } } else { $sub = $e404_sub; } // Front user mode if ($action != 'index' && $action != 'full' && $action != 'add' && $action != 'search' && $action != 'subscribe') $action = 'index'; if ($sub == $MODULE_VARS['auth']['USER_MODIFY_SUB']) { $action = 'message'; $user_table_mode = true; } if (!$action) $action = 'index'; if (!$catalogue || !$sub) exit; if ($sub == $e404_sub) { header('HTTP/1.1 404 Not Found'); $cc = ""; $date = ""; $action = "index"; } else { header('HTTP/1.1 200 OK'); switch ($_SERVER['SERVER_PROTOCOL']) { case 'HTTP/1.0': header('Pragma: no-cache'); break; default: header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); break; } if ($last_updated && $sub != $title_sub) header('Last-Modified: '.@gmdate('D, d M Y H:i:s T', $last_updated)); else header('Last-Modified: '. gmdate('D, d M Y H:i:s T', time() - 86400)); } if ($AUTHORIZATION_TYPE == 'session') { $sname = session_name(); if ($$sname != "") { if (!ereg("^[a-f0-9]{32}$",$$sname)) { header ("Location: /"); } $_GET[session_name()] = $$sname; $_POST[session_name()] = $$sname; } else { srand((double)microtime()*1000000); $randval = rand(); $session_id=md5(uniqid($randval)); session_id($session_id); } session_start(); if ($_SESSION['User']['IsLogin']=="1") { if ($_SESSION['User']['IP'] != getenv("REMOTE_ADDR")) { header ("Location: /"); } if ((time()-$_SESSION['User']['datetime']) > ini_get('session.gc_maxlifetime')) { unset($_SESSION['User']); session_destroy(); } } $_SESSION['User']['datetime'] = time(); } $passed_thru_404 = true; require $ROOT_FOLDER.$action.".jsp"; if ($nccttimer) { $nccttimer->stop(); $nccttimer->display(); dump($db->groupped_queries); } ?>