Advertisement
Guest User

Untitled

a guest
Sep 1st, 2017
249
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. if( isset($_GET["noscript"]) )
  3. {
  4.     $_SESSION["lk"] = "";
  5.     showmessage("<div style=\"border: 3px solid red; text-align: center; font-size: 18px; font-weight: bold; padding: 10px; width: 600px; height: 65px; margin: 100px auto; font-family: 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 1.7;\">Your Browser does not support JavaScript, or it is disabled.<br/>To run this application, you must enable JavaScript!!</div>");
  6. }
  7.  
  8. aaaaov();
  9. $viaPost = (strtoupper($_SERVER["REQUEST_METHOD"]) == "POST" ? 1 : 0);
  10. $isAjax = (isset($_POST["isAjax"]) ? 1 : 0);
  11. $stepCount = (isset($_POST["stepCount"]) ? intval($_POST["stepCount"]) : 1);
  12. $submitForm = (isset($_POST["submitForm"]) && $_POST["submitForm"] == "yes" ? 1 : 0);
  13. $doAction = (isset($_POST["doAction"]) ? trim($_POST["doAction"]) : "");
  14. $ERROR = "";
  15. $TSUE = array(  );
  16. aaaaow();
  17. if( $isAjax && $viaPost )
  18. {
  19.     if( $doAction == "requirementsCheck" )
  20.     {
  21.         clearstatcache();
  22.         if( file_exists(DATAPATH . "cache/install.lock") )
  23.         {
  24.             aaaaox("This installation has been locked. Please read <a href=\"http://templateshares-ue.net/customers/faq/\" target=\"_blank\">this</a>.");
  25.         }
  26.  
  27.         if( !file_exists(LIBRARYPATH . "config/database_config.php") )
  28.         {
  29.             aaaaox("Database configuration file does not exists. Please follow <a href=\"http://templateshares-ue.net/customers/manual/installation/\" target=\"_blank\">this</a> steps.");
  30.         }
  31.  
  32.         $errors = array(  );
  33.         if( !session_id() )
  34.         {
  35.             $errors["session"] = "PHP Session support does not exists. Please ask your host to enable this feature.";
  36.         }
  37.  
  38.         $phpVersion = phpversion();
  39.         if( version_compare($phpVersion, "5.2.0", "<") )
  40.         {
  41.             $errors["phpVersion"] = "PHP 5.2.0 or newer is required. " . $phpVersion . " does not meet this requirement. Please ask your host to upgrade PHP.";
  42.         }
  43.  
  44.         if( @ini_get("safe_mode") == 1 || strtolower(@ini_get("safe_mode")) == "on" )
  45.         {
  46.             $errors["safe_mode"] = "PHP must not be running in safe_mode. Please ask your host to disable the PHP safe_mode setting.";
  47.         }
  48.  
  49.         if( !ini_get("allow_url_fopen") || strtolower(ini_get("allow_url_fopen")) == "off" )
  50.         {
  51.             $errors["allow_url_fopen"] = "The PHP allow_url_fopen setting is disabled. Please ask your host to enable the PHP allow_url_fopen setting.";
  52.         }
  53.  
  54.         if( !function_exists("curl_init") || function_exists("curl_init") && !($ch = curl_init()) )
  55.         {
  56.             $errors["curl"] = "The required PHP library CURL could not be found. Please ask your host to install this library.";
  57.         }
  58.  
  59.         if( !function_exists("mysqli_connect") )
  60.         {
  61.             $errors["mysqlPhp"] = "The required PHP extension MySQLi could not be found. Please ask your host to install this extension.";
  62.         }
  63.         else
  64.         {
  65.             $TSUE["TSUE_Database"] = new TSUE_Database(false);
  66.             if( $TSUE["TSUE_Database"]->error )
  67.             {
  68.                 $errors["mysqlPhp"] = "Database Connection Failed! Please follow <a href=\"http://templateshares-ue.net/customers/manual/installation/\" target=\"_blank\">this</a> steps.";
  69.             }
  70.             else
  71.             {
  72.                 $TSUE["TSUE_Settings"] = new TSUE_Settings();
  73.                 $detectedTSUEVersion = $TSUE["TSUE_Settings"]->settings["global_settings"]["tsue_version"];
  74.                 if( $detectedTSUEVersion == V )
  75.                 {
  76.                     $errors["mysqlPhp"] = "<b>Fatal Error:</b> You are already running the latest version of TSUE and so cannot upgrade.";
  77.                 }
  78.  
  79.             }
  80.  
  81.         }
  82.  
  83.         if( !function_exists("preg_replace") )
  84.         {
  85.             $errors["pcre"] = "The required PHP extension PCRE could not be found. Please ask your host to install this extension.";
  86.         }
  87.  
  88.         if( function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc() )
  89.         {
  90.             $errors["get_magic_quotes_gpc"] = "Warning: Magic Quotes GPC is enabled.";
  91.         }
  92.  
  93.         if( function_exists("get_magic_quotes_runtime") && get_magic_quotes_runtime() )
  94.         {
  95.             $errors["get_magic_quotes_runtime"] = "Warning: Magic Quotes Runtime is enabled.";
  96.         }
  97.  
  98.         if( !function_exists("gd_info") )
  99.         {
  100.             $errors["gd"] = "The required PHP extension GD could not be found. Please ask your host to install this extension.";
  101.         }
  102.         else
  103.         {
  104.             if( !function_exists("imagecreatefromjpeg") )
  105.             {
  106.                 $errors["gdJpeg"] = "The required PHP extension GD was found, but JPEG support is missing. Please ask your host to add support for JPEG images.";
  107.             }
  108.             else
  109.             {
  110.                 if( !function_exists("imagecreatefromgif") )
  111.                 {
  112.                     $errors["gdJpeg"] = "The required PHP extension GD was found, but GIF support is missing. Please ask your host to add support for GIF images.";
  113.                 }
  114.                 else
  115.                 {
  116.                     if( !function_exists("imagecreatefrompng") )
  117.                     {
  118.                         $errors["gdJpeg"] = "The required PHP extension GD was found, but PNG support is missing. Please ask your host to add support for PNG images.";
  119.                     }
  120.  
  121.                 }
  122.  
  123.             }
  124.  
  125.         }
  126.  
  127.         if( !function_exists("json_encode") )
  128.         {
  129.             $errors["json"] = "The required PHP extension JSON could not be found. Please ask your host to install this extension.";
  130.         }
  131.  
  132.         if( !function_exists("mb_check_encoding") )
  133.         {
  134.             $errors["mb_check_encoding"] = "The required PHP extension mb_check_encoding could not be found. Please ask your host to install this extension.";
  135.         }
  136.  
  137.         if( !class_exists("DOMDocument") || !class_exists("SimpleXMLElement") )
  138.         {
  139.             $errors["xml"] = "The required PHP extensions for XML handling (DOM and SimpleXML) could not be found. Please ask your host to install this extension.";
  140.         }
  141.  
  142.         if( $errors )
  143.         {
  144.             $errorList = "";
  145.             foreach( $errors as $error )
  146.             {
  147.                 $errorList .= "<li>" . $error . "</li>";
  148.             }
  149.             $Result = "\r\n\t\t\t<div class=\"failure\">\r\n\t\t\t\t<h2>\r\n\t\t\t\t\t<span style=\"float: right; font-weight: normal; font-size: 11px; color: #999; margin-top: -30px; margin-right: -5px;\">DB: " . MYSQL_DB . "</span>\r\n\t\t\t\t\tRequirements Not Met\r\n\t\t\t\t</h2>\r\n\t\t\t\t<p>The following TSUE requirements were not met. Please contact your host for help.</p>\r\n\t\t\t\t<ol>\r\n\t\t\t\t\t" . $errorList . "\r\n\t\t\t\t</ol>\r\n\t\t\t\t<p class=\"mysql\">\r\n\t\t\t\t\tCan't install yourself? Please purchase a professional installation at: <a href=\"http://templateshares-ue.net/customers/services/\">http://templateshares-ue.net/customers/services/</a>\r\n\t\t\t\t</p>\r\n\t\t\t</div>";
  150.         }
  151.         else
  152.         {
  153.             $LADivHeight = 250;
  154.             $licenseAgreement = @file_get_contents("http://templateshares-ue.net/licenseAgreement.html");
  155.             if( !$licenseAgreement )
  156.             {
  157.                 $LADivHeight = 50;
  158.                 $licenseAgreement = "Unable to fetch TSUE License Agreement. Please click <a href=\"http://templateshares-ue.net/licenseAgreement.html\" target=\"_blank\">here</a> to view HTML version.";
  159.             }
  160.  
  161.             $Result = "\r\n\t\t\t<div class=\"success\" id=\"requirementsMet\">\r\n\t\t\t\t<h2>\r\n\t\t\t\t\t<span style=\"float: right; font-weight: normal; font-size: 11px; color: #999; margin-top: -30px; margin-right: -5px;\">DB: " . MYSQL_DB . "</span>\r\n\t\t\t\t\tRequirements Met: Detected TSUE version: " . $detectedTSUEVersion . "\r\n\t\t\t\t</h2>\r\n\t\t\t\t<p>Your server meets all of TSUE requirements and you are now ready to begin upgrade.</p>\r\n\t\t\t\t<p class=\"warning\">Just make sure that you have made a backup of your database first. I will update Languages, Styles and Templates.</p>\r\n\t\t\t\t<p class=\"mysql\">TSUE also requires MySQL 5.0 or newer. Please manually check that you meet this requirement.</p>\r\n\t\t\t</div>\r\n\t\t\t\r\n\t\t\t<div class=\"success\" id=\"licenseAgreement\">\r\n\t\t\t\t<div style=\"padding: 5px; margin: 5px; border: 1px solid #ccc; height: " . $LADivHeight . "px; overflow: auto; font-size: 11px;\">\r\n\t\t\t\t\t<h1>License Agreement</h1>\r\n\t\t\t\t\t" . $licenseAgreement . "\r\n\t\t\t\t</div>\r\n\t\t\t</div>";
  162.         }
  163.  
  164.         showmessage($Result);
  165.     }
  166.  
  167.     if( $stepCount )
  168.     {
  169.         switch( $stepCount )
  170.         {
  171.             case 1:
  172.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  173.                 $TSUE["TSUE_Settings"] = new TSUE_Settings();
  174.                 if( !isset($TSUE["TSUE_Settings"]->settings["global_settings"]["website_active"]) )
  175.                 {
  176.                     showerror("Unable to read Global Settings.");
  177.                 }
  178.  
  179.                 $TSUE["TSUE_Settings"]->settings["global_settings"]["website_active"] = 0;
  180.                 $TSUE["TSUE_Database"]->update("tsue_themes", array( "active" => 0 ));
  181.                 $Theme = $TSUE["TSUE_Database"]->query_result("SELECT themeid FROM tsue_themes WHERE themeid=1 AND themename=\"default\"");
  182.                 if( !$Theme )
  183.                 {
  184.                     if( !isset($TSUE["TSUE_Settings"]->settings["global_settings"]["d_themeid"]) || !$TSUE["TSUE_Settings"]->settings["global_settings"]["d_themeid"] )
  185.                     {
  186.                         $TSUE["TSUE_Settings"]->settings["global_settings"]["d_themeid"] = 1;
  187.                     }
  188.  
  189.                     $Theme = $TSUE["TSUE_Database"]->query_result("SELECT themeid FROM tsue_themes WHERE themeid=" . $TSUE["TSUE_Settings"]->settings["global_settings"]["d_themeid"]);
  190.                 }
  191.  
  192.                 if( !$Theme )
  193.                 {
  194.                     showerror("There is no a default theme.");
  195.                 }
  196.  
  197.                 $TSUE["TSUE_Settings"]->settings["global_settings"]["d_themeid"] = $Theme["themeid"];
  198.                 $TSUE["TSUE_Database"]->update("tsue_themes", array( "active" => 1 ), "themeid=" . $Theme["themeid"]);
  199.                 $TSUE["TSUE_Database"]->update("tsue_members", array( "themeid" => $Theme["themeid"] ));
  200.                 updatesettings("global_settings", $TSUE["TSUE_Settings"]->settings["global_settings"]);
  201.                 showmessage("Your website has been taken offline.");
  202.                 break;
  203.             case 2:
  204.                 $TSUESystemDirectories = aaaaoy();
  205.                 $searchDirectories = aaaaoz(DATAPATH);
  206.                 if( count($searchDirectories) < 7 )
  207.                 {
  208.                     showerror("Required TSUE system directory does not exists in " . DATAPATH);
  209.                 }
  210.  
  211.                 foreach( $TSUESystemDirectories as $TSUESystemDirectory )
  212.                 {
  213.                     if( !checkdirectorypermissions(DATAPATH . $TSUESystemDirectory) )
  214.                     {
  215.                         showerror("The following TSUE System directory is not writable: " . DATAPATH . $TSUESystemDirectory);
  216.                     }
  217.  
  218.                 }
  219.                 showmessage("Directory Permissions has been checked & confirmed. Database connection is being checked...");
  220.                 break;
  221.             case 3:
  222.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  223.                 showmessage("Database Connection has been confirmed. MySQL Tables are being updated, please be patient during this procedure...");
  224.                 break;
  225.             case 4:
  226.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  227.                 $TSUE["TSUE_Settings"] = new TSUE_Settings();
  228.                 if( !isset($TSUE["TSUE_Settings"]->settings["global_settings"]["tsue_version"]) || !$TSUE["TSUE_Settings"]->settings["global_settings"]["tsue_version"] )
  229.                 {
  230.                     showerror("Unable to read Global Settings.");
  231.                 }
  232.  
  233.                 $sqlContents = aaaapa(4, $TSUE["TSUE_Settings"]->settings["global_settings"]["tsue_version"]);
  234.                 if( !$sqlContents )
  235.                 {
  236.                     showerror("Could not get SQL commands.");
  237.                 }
  238.  
  239.                 $sqlCommands = explode("[TSUE_UPGRADE_QUERY]", $sqlContents);
  240.                 if( $sqlCommands )
  241.                 {
  242.                     foreach( $sqlCommands as $sqlCommand )
  243.                     {
  244.                         $sqlCommand = trim($sqlCommand);
  245.                         if( $sqlCommand )
  246.                         {
  247.                             if( preg_match("#ALTER TABLE (.*) ADD INDEX (.*)#i", $sqlCommand, $SQL) )
  248.                             {
  249.                                 if( count($SQL) == 3 )
  250.                                 {
  251.                                     $tableName = trim($SQL["1"]);
  252.                                     $indexName = trim($SQL["2"]);
  253.                                     if( strstr($indexName, ",") !== false )
  254.                                     {
  255.                                         $indexName = explode(",", $indexName);
  256.                                         $indexName = trim($indexName["0"]);
  257.                                     }
  258.  
  259.                                     $indexName = preg_replace("#[^a-zA-Z_-]#", "", $indexName);
  260.                                     $checkIndex = $TSUE["TSUE_Database"]->query_result("SHOW INDEX FROM " . $tableName . " WHERE KEY_NAME = '" . $indexName . "'");
  261.                                     if( $checkIndex )
  262.                                     {
  263.                                         $TSUE["TSUE_Database"]->query("ALTER TABLE " . $tableName . " DROP INDEX `" . $indexName . "`");
  264.                                     }
  265.  
  266.                                 }
  267.  
  268.                             }
  269.                             else
  270.                             {
  271.                                 if( preg_match("#ALTER TABLE (.*) ADD FULLTEXT (.*)#i", $sqlCommand, $SQL) )
  272.                                 {
  273.                                     if( count($SQL) == 3 )
  274.                                     {
  275.                                         $tableName = trim($SQL["1"]);
  276.                                         $indexName = trim($SQL["2"]);
  277.                                         if( strstr($indexName, "(") !== false )
  278.                                         {
  279.                                             $indexName = explode(" ", $indexName);
  280.                                             $indexName = trim($indexName["0"]);
  281.                                         }
  282.  
  283.                                         $indexName = preg_replace("#[^a-zA-Z_-]#", "", $indexName);
  284.                                         $checkIndex = $TSUE["TSUE_Database"]->query_result("SHOW INDEX FROM " . $tableName . " WHERE KEY_NAME = '" . $indexName . "'");
  285.                                         if( $checkIndex )
  286.                                         {
  287.                                             $TSUE["TSUE_Database"]->query("ALTER TABLE " . $tableName . " DROP INDEX `" . $indexName . "`");
  288.                                         }
  289.  
  290.                                     }
  291.  
  292.                                 }
  293.                                 else
  294.                                 {
  295.                                     if( preg_match("#ALTER TABLE (.*) DROP INDEX (.*)#i", $sqlCommand, $SQL) )
  296.                                     {
  297.                                         if( count($SQL) == 3 )
  298.                                         {
  299.                                             $tableName = trim($SQL["1"]);
  300.                                             $indexName = trim($SQL["2"]);
  301.                                             $indexName = preg_replace("#[^a-zA-Z_-]#", "", $indexName);
  302.                                             $checkIndex = $TSUE["TSUE_Database"]->query_result("SHOW INDEX FROM " . $tableName . " WHERE KEY_NAME = '" . $indexName . "'");
  303.                                             if( !$checkIndex )
  304.                                             {
  305.                                                 continue;
  306.                                             }
  307.  
  308.                                         }
  309.  
  310.                                     }
  311.                                     else
  312.                                     {
  313.                                         if( preg_match("#CREATE TABLE (.*)\\s?\\(#", $sqlCommand, $dropTable) && isset($dropTable["1"]) )
  314.                                         {
  315.                                             $dropTable = "DROP TABLE IF EXISTS " . $dropTable["1"];
  316.                                             $TSUE["TSUE_Database"]->query($dropTable);
  317.                                         }
  318.  
  319.                                     }
  320.  
  321.                                 }
  322.  
  323.                             }
  324.  
  325.                             $TSUE["TSUE_Database"]->query($sqlCommand);
  326.                         }
  327.  
  328.                     }
  329.                 }
  330.  
  331.                 showmessage("MySQL Tables has been updated. Language Packages are being updated...");
  332.                 break;
  333.             case 5:
  334.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  335.                 $orjPhrases = @unserialize(@trim(@file_get_contents("http://templateshares-ue.net/getPhrase.php?scriptVersion=" . V . "&contentLanguage=en-us")));
  336.                 if( !$orjPhrases )
  337.                 {
  338.                     showerror("Unable to read TSUE v" . V . " phrases.");
  339.                 }
  340.  
  341.                 $installedLanguages = $TSUE["TSUE_Database"]->query("SELECT languageid, phrase_global FROM tsue_languages ORDER BY languageid ASC");
  342.                 if( !$TSUE["TSUE_Database"]->num_rows($installedLanguages) )
  343.                 {
  344.                     showerror("Unable to read installed phrases.");
  345.                 }
  346.  
  347.                 while( $L = $TSUE["TSUE_Database"]->fetch_assoc($installedLanguages) )
  348.                 {
  349.                     $phrase_global = @unserialize($L["phrase_global"]);
  350.                     if( $phrase_global )
  351.                     {
  352.                         foreach( $orjPhrases as $phraseName => $phraseValue )
  353.                         {
  354.                             if( !isset($phrase_global[$phraseName]) )
  355.                             {
  356.                                 $phrase_global[$phraseName] = $phraseValue;
  357.                             }
  358.  
  359.                         }
  360.                         $TSUE["TSUE_Database"]->update("tsue_languages", array( "phrase_global" => serialize($phrase_global) ), "languageid=" . $L["languageid"]);
  361.                     }
  362.  
  363.                 }
  364.                 showmessage("Language Packages has been updated. Styles are being updated...");
  365.                 break;
  366.             case 6:
  367.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  368.                 clearstatcache();
  369.                 $cssPath = "./sql/css/";
  370.                 $cssFiles = scandir($cssPath);
  371.                 if( $cssFiles )
  372.                 {
  373.                     $newCSS = array(  );
  374.                     foreach( $cssFiles as $cssFile )
  375.                     {
  376.                         if( file_extension($cssFile) == "css" )
  377.                         {
  378.                             $newCSS[$cssFile] = file_get_contents($cssPath . $cssFile);
  379.                         }
  380.  
  381.                     }
  382.                     $Themes = $TSUE["TSUE_Database"]->query("SELECT * FROM tsue_themes");
  383.                     while( $Theme = $TSUE["TSUE_Database"]->fetch_assoc($Themes) )
  384.                     {
  385.                         foreach( $newCSS as $styleName => $CSS )
  386.                         {
  387.                             $TSUE["TSUE_Database"]->delete("tsue_styles", "themeid=" . $Theme["themeid"] . " AND stylename = " . $TSUE["TSUE_Database"]->escape($styleName));
  388.                             $buildQuery = array( "stylename" => $styleName, "themeid" => $Theme["themeid"], "css" => $CSS, "last_updated" => TIMENOW, "orj_css" => $CSS );
  389.                             $TSUE["TSUE_Database"]->insert("tsue_styles", $buildQuery);
  390.                         }
  391.                     }
  392.                 }
  393.  
  394.                 $Result = $TSUE["TSUE_Database"]->query("SELECT styleid, css FROM tsue_styles WHERE stylename = \"style.css\"");
  395.                 while( $Row = $TSUE["TSUE_Database"]->fetch_assoc($Result) )
  396.                 {
  397.                     $css = $Row["css"] . "\r\na.active{text-decoration: underline; font-weight: bold;}\r\n#sidebar .widget2, #content .widget2\r\n{\r\n\tposition: relative;\r\n\tmargin-bottom: 10px;\r\n\tpadding: 0;\r\n\theight: auto;\r\n}\r\n#sidebar .widget2 p, #content .widget2 p\r\n{\r\n\tmargin: 0;\r\n\tpadding: 5px 10px;\r\n}\r\n.widget2 table\r\n{\r\n\tpadding: 0 5px;\r\n}";
  398.                     $TSUE["TSUE_Database"]->update("tsue_styles", array( "css" => $css, "orj_css" => $css, "last_updated" => TIMENOW ), "styleid=" . $Row["styleid"]);
  399.                 }
  400.                 showmessage("Styles has been updated. Templates are being updated...");
  401.                 break;
  402.             case 7:
  403.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  404.                 clearstatcache();
  405.                 $templatePath = "./sql/templates/";
  406.                 $templateFiles = scandir($templatePath);
  407.                 if( $templateFiles )
  408.                 {
  409.                     $newTemplates = array(  );
  410.                     foreach( $templateFiles as $templateFile )
  411.                     {
  412.                         if( file_extension($templateFile) == "htm" )
  413.                         {
  414.                             $newTemplates[$templateFile] = file_get_contents($templatePath . $templateFile);
  415.                         }
  416.  
  417.                     }
  418.                     $Themes = $TSUE["TSUE_Database"]->query("SELECT * FROM tsue_themes");
  419.                     while( $Theme = $TSUE["TSUE_Database"]->fetch_assoc($Themes) )
  420.                     {
  421.                         foreach( $newTemplates as $templateName => $TEMPLATE )
  422.                         {
  423.                             $templateName = str_replace(".htm", "", $templateName);
  424.                             $TSUE["TSUE_Database"]->delete("tsue_templates", "themeid=" . $Theme["themeid"] . " AND templatename = " . $TSUE["TSUE_Database"]->escape($templateName));
  425.                             $buildQuery = array( "themeid" => $Theme["themeid"], "templatename" => $templateName, "template" => $TEMPLATE, "last_updated" => TIMENOW, "orj_template" => $TEMPLATE );
  426.                             $TSUE["TSUE_Database"]->insert("tsue_templates", $buildQuery);
  427.                         }
  428.                     }
  429.                 }
  430.  
  431.                 $Result = $TSUE["TSUE_Database"]->query("SELECT templateid, template FROM tsue_templates WHERE templatename = \"main\"");
  432.                 while( $Row = $TSUE["TSUE_Database"]->fetch_assoc($Result) )
  433.                 {
  434.                     $template = str_replace(",plugin_torrent_categories", ",plugin_torrent_categories,members,donations", $Row["template"]);
  435.                     $TSUE["TSUE_Database"]->update("tsue_templates", array( "template" => $template, "orj_template" => $template, "last_updated" => TIMENOW ), "templateid=" . $Row["templateid"]);
  436.                 }
  437.                 showmessage("Templates has been updated. TSUE Settings are being updated...");
  438.                 break;
  439.             case 8:
  440.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  441.                 $TSUE["TSUE_Settings"] = new TSUE_Settings();
  442.                 if( !isset($TSUE["TSUE_Settings"]->settings["global_settings"]["tsue_version"]) || !$TSUE["TSUE_Settings"]->settings["global_settings"]["tsue_version"] )
  443.                 {
  444.                     showerror("Unable to read Global Settings.");
  445.                 }
  446.  
  447.                 $TSUE["TSUE_Settings"]->settings["global_settings"]["tsue_version"] = V;
  448.                 $TSUE["TSUE_Settings"]->settings["global_settings"]["security_ip_history"] = 1;
  449.                 updatesettings("global_settings", $TSUE["TSUE_Settings"]->settings["global_settings"]);
  450.                 showmessage("TSUE Settings has been updated. Rebuilding TSUE Cache...");
  451.                 break;
  452.             case 9:
  453.                 $TSUE["TSUE_Database"] = new TSUE_Database();
  454.                 $TSUE["TSUE_Settings"] = new TSUE_Settings();
  455.                 handleprune();
  456.                 handlerebuildcaches();
  457.                 showmessage("TSUE Cache has been updated. Finishig Upgrade...");
  458.                 break;
  459.             case 10:
  460.                 file_put_contents(DATAPATH . "cache/install.lock", TIMENOW);
  461.                 showmessage("\r\n\t\t\t\t<div id=\"installationComplete\">\r\n\t\t\t\t\t<div class=\"success\"><h2>Upgrade Complete</h2></div>\r\n\t\t\t\t\t<b>Here's what you should do next:</b>\r\n\t\t\t\t\t<br />\r\n\t\t\t\t\t<ol>\r\n\t\t\t\t\t\t<li>\r\n\t\t\t\t\t\t\tDelete the Install Folder<br />\r\n\t\t\t\t\t\t\tYou should now delete the install directory from your web server.<br />\r\n\t\t\t\t\t\t\t<span class=\"mysql\">For security reasons, this script has been locked.</span>\r\n\t\t\t\t\t\t</li>\r\n\r\n\t\t\t\t\t\t<li>\r\n\t\t\t\t\t\t\tConfigure TSUE<br />\r\n\t\t\t\t\t\t\tNow it's time to configure your TSUE Upgrade.<br />\r\n\t\t\t\t\t\t\tClick <a href=\"" . TSUE_FRONT_URL . "/admincp/\">here</a> to go to the admin area now.\r\n\t\t\t\t\t\t</li>\r\n\t\t\t\t\t</ol>\r\n\r\n\t\t\t\t\t<div class=\"thankYou\">\r\n\t\t\t\t\t\tThank you for choosing TSUE!<br />\r\n\t\t\t\t\t\twww.templateshares-ue.net\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t");
  462.                 break;
  463.             default:
  464.                 exit();
  465.         }
  466.     }
  467.  
  468. }
  469.  
  470. printoutput("\r\n\t<div id=\"welcomeScreen\">\r\n\t\t<img src=\"./images/ajax-loader.gif\" id=\"loader\" alt=\"\" title=\"\" border=\"0\" /> Please wait... Checking TSUE System Requirements...\r\n\t</div>\r\n\t<div id=\"beginInstall\">\r\n\t\t<div id=\"progressbar\"><div id=\"progress\"></div></div>\r\n\t\t<div id=\"buttons\">\r\n\t\t\t<input type=\"button\" name=\"start\" id=\"start\" class=\"submit\" value=\"If you Read & Agree TSUE License Agreement above, please click here to Begin Upgrade.\" />\r\n\t\t\t<input type=\"button\" name=\"reload\" id=\"reload\" class=\"submit\" value=\"Reload!\" />\r\n\t\t</div>\r\n\t\t<div id=\"result\"></div>\r\n\t</div>\r\n", true);
  471.  
  472. class TSUE_Settings
  473. {
  474.     public $settings = array(  );
  475.  
  476.     public function TSUE_Settings()
  477.     {
  478.         global $TSUE;
  479.         $fetchSettings = $TSUE["TSUE_Database"]->query("SELECT settingname, settingvalues FROM tsue_settings ORDER BY settingname");
  480.         if( $TSUE["TSUE_Database"]->num_rows($fetchSettings) )
  481.         {
  482.             while( $Setting = $TSUE["TSUE_Database"]->fetch_assoc($fetchSettings) )
  483.             {
  484.                 $this->settings[$Setting["settingname"]] = unserialize($Setting["settingvalues"]);
  485.             }
  486.         }
  487.  
  488.     }
  489.  
  490. }
  491.  
  492.  
  493. class TSUE_Database
  494. {
  495.     public $querycount = 0;
  496.     public $query = NULL;
  497.     public $query_cache = array(  );
  498.     public $shutdown_queries = array(  );
  499.     public $error = NULL;
  500.     public $connection = NULL;
  501.     public $locked = false;
  502.  
  503.     public function TSUE_Database($halt = true)
  504.     {
  505.         if( !is_file(LIBRARYPATH . "config/database_config.php") )
  506.         {
  507.             exit( "<h1>Fatal Error: The database configuration file does not exists.</h1>" );
  508.         }
  509.  
  510.         require(LIBRARYPATH . "config/database_config.php");
  511.         if( !($this->connection = @mysqli_init()) )
  512.         {
  513.             $this->error = "mysqli_init failed!";
  514.             if( $halt )
  515.             {
  516.                 $this->halt();
  517.             }
  518.  
  519.         }
  520.  
  521.         if( !defined("MYSQL_HOST") || !defined("MYSQL_USER") || !defined("MYSQL_PASS") || !defined("MYSQL_DB") || !defined("MYSQL_PORT") || !defined("MYSQL_SOCKET") )
  522.         {
  523.             exit( "<h1>Fatal Error: Invalid variables in the database configuration file.</h1>" );
  524.         }
  525.  
  526.         if( !@mysqli_real_connect($this->connection, MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, MYSQL_PORT, MYSQL_SOCKET) )
  527.         {
  528.             $this->error = "MySQLi connection error!";
  529.             if( $halt )
  530.             {
  531.                 $this->halt();
  532.             }
  533.  
  534.         }
  535.  
  536.         if( MYSQL_CHARSET != "" )
  537.         {
  538.             if( function_exists("mysqli_set_charset") )
  539.             {
  540.                 mysqli_set_charset($this->connection, MYSQL_CHARSET);
  541.                 return NULL;
  542.             }
  543.  
  544.             $this->execute_query("SET NAMES " . MYSQL_CHARSET);
  545.         }
  546.  
  547.     }
  548.  
  549.     public function execute_query($query, $buffered = true)
  550.     {
  551.         $this->querycount++;
  552.         $this->query = $query;
  553.         $this->query_cache[] = $query;
  554.         if( $queryresult = mysqli_query($this->connection, $this->query, ($buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) )
  555.         {
  556.             return $queryresult;
  557.         }
  558.  
  559.         $this->error = mysqli_error($this->connection);
  560.         if( !preg_match("#Duplicate column name#isU", $this->error) )
  561.         {
  562.             $this->halt();
  563.         }
  564.  
  565.     }
  566.  
  567.     public function query($query, $buffered = true)
  568.     {
  569.         return $this->execute_query($query, $buffered);
  570.     }
  571.  
  572.     public function replace($table, $buildQuery, $isShutDownQuery = false)
  573.     {
  574.         $Query = array(  );
  575.         foreach( $buildQuery as $field => $value )
  576.         {
  577.             $Query[] = "`" . $field . "` = " . $this->escape($value);
  578.         }
  579.         $SET = implode(",", $Query);
  580.         if( $isShutDownQuery )
  581.         {
  582.             return $this->shutdown_query("REPLACE INTO `" . $table . "` SET " . $SET);
  583.         }
  584.  
  585.         return $this->query("REPLACE INTO `" . $table . "` SET " . $SET);
  586.     }
  587.  
  588.     public function insert($table, $buildQuery, $isShutDownQuery = false, $EXTRA = "", $IGNORE = "")
  589.     {
  590.         $Query = array(  );
  591.         foreach( $buildQuery as $field => $value )
  592.         {
  593.             $Query[] = "`" . $field . "` = " . $this->escape($value);
  594.         }
  595.         $SET = implode(",", $Query);
  596.         if( $isShutDownQuery )
  597.         {
  598.             return $this->shutdown_query("INSERT" . (($IGNORE ? " IGNORE" : "")) . " INTO `" . $table . "` SET " . $SET . $EXTRA);
  599.         }
  600.  
  601.         return $this->query("INSERT" . (($IGNORE ? " IGNORE" : "")) . " INTO `" . $table . "` SET " . $SET . $EXTRA);
  602.     }
  603.  
  604.     public function update($table, $buildQuery, $where = "", $isShutDownQuery = false)
  605.     {
  606.         $Query = array(  );
  607.         foreach( $buildQuery as $field => $value )
  608.         {
  609.             if( is_array($value) )
  610.             {
  611.                 if( $value["escape"] == 0 )
  612.                 {
  613.                     $Query[] = "`" . $field . "` = " . $value["value"];
  614.                 }
  615.                 else
  616.                 {
  617.                     $Query[] = "`" . $field . "` = " . $this->escape($value["value"]);
  618.                 }
  619.  
  620.             }
  621.             else
  622.             {
  623.                 $Query[] = "`" . $field . "` = " . $this->escape($value);
  624.             }
  625.  
  626.         }
  627.         $SET = implode(",", $Query);
  628.         if( $isShutDownQuery )
  629.         {
  630.             return $this->shutdown_query("UPDATE `" . $table . "` SET " . $SET . (($where ? " WHERE " . $where : "")));
  631.         }
  632.  
  633.         return $this->query("UPDATE `" . $table . "` SET " . $SET . (($where ? " WHERE " . $where : "")));
  634.     }
  635.  
  636.     public function delete($table, $WHERE)
  637.     {
  638.         $this->execute_query("DELETE FROM " . $table . (($WHERE ? " WHERE " . $WHERE : "")));
  639.         return $this->affected_rows();
  640.     }
  641.  
  642.     public function truncate($table)
  643.     {
  644.         return $this->execute_query("TRUNCATE TABLE `" . $table . "`");
  645.     }
  646.  
  647.     public function query_result($query, $buffered = true)
  648.     {
  649.         $returnarray = false;
  650.         $queryresult = $this->execute_query($query, $buffered);
  651.         if( $this->num_rows($queryresult) )
  652.         {
  653.             $returnarray = $this->fetch_assoc($queryresult);
  654.             $this->free($queryresult);
  655.         }
  656.  
  657.         return $returnarray;
  658.     }
  659.  
  660.     public function exec_shutdown_queries()
  661.     {
  662.         if( $this->shutdown_queries && count($this->shutdown_queries) )
  663.         {
  664.             foreach( $this->shutdown_queries as $query )
  665.             {
  666.                 $this->execute_query($query);
  667.             }
  668.         }
  669.  
  670.     }
  671.  
  672.     public function row_count($query, $buffered = true)
  673.     {
  674.         return $this->num_rows($this->execute_query($query, $buffered));
  675.     }
  676.  
  677.     public function shutdown_query($query)
  678.     {
  679.         $this->shutdown_queries[] = $query;
  680.     }
  681.  
  682.     public function lock_tables($tablelist = "")
  683.     {
  684.         if( !empty($tablelist) && is_array($tablelist) )
  685.         {
  686.             $sql = "";
  687.             foreach( $tablelist as $name => $type )
  688.             {
  689.                 $sql .= ((!empty($sql) ? ", " : "")) . $name . " " . $type;
  690.             }
  691.             $this->query("LOCK TABLES " . $sql);
  692.             $this->locked = true;
  693.         }
  694.  
  695.     }
  696.  
  697.     public function unlock_tables()
  698.     {
  699.         if( $this->locked )
  700.         {
  701.             $this->query("UNLOCK TABLES");
  702.             $this->locked = false;
  703.         }
  704.  
  705.     }
  706.  
  707.     public function affected_rows()
  708.     {
  709.         return mysqli_affected_rows($this->connection);
  710.     }
  711.  
  712.     public function insert_id()
  713.     {
  714.         return mysqli_insert_id($this->connection);
  715.     }
  716.  
  717.     public function fetch_assoc($query)
  718.     {
  719.         return mysqli_fetch_array($query, MYSQLI_ASSOC);
  720.     }
  721.  
  722.     public function fetch_row($query)
  723.     {
  724.         return mysqli_fetch_row($query);
  725.     }
  726.  
  727.     public function num_rows($query)
  728.     {
  729.         return mysqli_num_rows($query);
  730.     }
  731.  
  732.     public function free($query)
  733.     {
  734.         mysqli_free_result($query);
  735.     }
  736.  
  737.     public function escape($string)
  738.     {
  739.         return "'" . mysqli_real_escape_string($this->connection, $string) . "'";
  740.     }
  741.  
  742.     public function escape_no_quotes($string)
  743.     {
  744.         return mysqli_real_escape_string($this->connection, $string);
  745.     }
  746.  
  747.     public function halt()
  748.     {
  749.         showerror($this->error);
  750.     }
  751.  
  752.     public function close()
  753.     {
  754.         mysqli_close($this->connection);
  755.     }
  756.  
  757. }
  758.  
  759. function aaaaov()
  760. {
  761.     @date_default_timezone_set("GMT");
  762.     define("TIMENOW", time());
  763.     if( function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc() )
  764.     {
  765.         require("./../library/functions/functions_undoMagicQuotes.php");
  766.     }
  767.  
  768.     if( function_exists("get_magic_quotes_runtime") && get_magic_quotes_runtime() )
  769.     {
  770.         @set_magic_quotes_runtime(false);
  771.     }
  772.  
  773.     @ini_set("memory_limit", "256M");
  774.     @set_time_limit(0);
  775.     @ignore_user_abort(true);
  776.     @ini_set("pcre.backtrack_limit", -1);
  777.     @ini_set("output_buffering", false);
  778.     while( ob_get_level() )
  779.     {
  780.         @ob_end_clean();
  781.     }
  782.     define("SCRIPT_NAME", "upgrade.php");
  783.     define("REALPATH", str_replace("\\", "/", realpath(".")) . "/");
  784.     define("ROOTPATH", str_replace("\\", "/", realpath("./../")) . "/");
  785.     define("DATAPATH", ROOTPATH . "data/");
  786.     define("JSPATH", ROOTPATH . "js/");
  787.     define("LIBRARYPATH", ROOTPATH . "library/");
  788.     define("STYLEPATH", ROOTPATH . "styles/");
  789.     @error_reporting(30719);
  790.     @ini_set("display_errors", "Off");
  791.     @set_error_handler("UpgradeErrorHandler");
  792.     define("IN_INSTALL", true);
  793.     define("TSUE_ADMINCP_URL", aaaapc());
  794.     define("TSUE_FRONT_URL", str_replace("/tsue_install/", "", TSUE_ADMINCP_URL));
  795.     define("TSUE_URL", "i5fow4%2BUe93I0t7fxrfN2MvMpJWkX4WM7oLJ2MHOktGc482z");
  796.     define("TSUE_URL3", "aHR0cDovL3RlbXBsYXRlc2hhcmVzLmJpei9pcC5waHA=");
  797.     define("U", (!empty($_SERVER["SERVER_NAME"]) ? fixurl($_SERVER["SERVER_NAME"]) : (!empty($_SERVER["HTTP_HOST"]) ? fixurl($_SERVER["HTTP_HOST"]) : "")));
  798.     define("I", getserverip());
  799.     define("V", "2.2");
  800. }
  801.  
  802. function upgradeerrorhandler($errno, $errstr, $errfile, $errline)
  803. {
  804.     $Message = "\r\n------------------------------------------\r\n" . date("d-m-Y H:i:s") . "\r\n[" . $errno . "] " . $errstr . "\r\nPHP Error on line " . number_format($errline) . " in file " . $errfile . "\r\n" . PHP_VERSION . " " . PHP_OS . "\r\n------------------------------------------";
  805.     @file_put_contents(DATAPATH . "errors/" . SCRIPT_NAME . ".log", $Message, FILE_APPEND);
  806. }
  807.  
  808. function getserverip()
  809. {
  810.     $ipFile = DATAPATH . "cache/ip.srv";
  811.     if( isset($_SERVER["SERVER_ADDR"]) && !empty($_SERVER["SERVER_ADDR"]) && is_valid_ip($_SERVER["SERVER_ADDR"]) )
  812.     {
  813.         $ip = $_SERVER["SERVER_ADDR"];
  814.     }
  815.     else
  816.     {
  817.         if( isset($_SERVER["LOCAL_ADDR"]) && !empty($_SERVER["LOCAL_ADDR"]) && is_valid_ip($_SERVER["LOCAL_ADDR"]) )
  818.         {
  819.             $ip = $_SERVER["LOCAL_ADDR"];
  820.         }
  821.         else
  822.         {
  823.             if( file_exists($ipFile) && TIMENOW < filemtime($ipFile) + 1800 )
  824.             {
  825.                 $ip = file_get_contents($ipFile);
  826.             }
  827.             else
  828.             {
  829.                 if( function_exists("curl_init") && ($ch = curl_init()) )
  830.                 {
  831.                     curl_setopt($ch, CURLOPT_URL, base64_decode(TSUE_URL3));
  832.                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  833.                     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  834.                     curl_setopt($ch, CURLOPT_HEADER, 0);
  835.                     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0");
  836.                     $ip = curl_exec($ch);
  837.                     curl_close($ch);
  838.                     if( is_writable(DATAPATH . "cache/") )
  839.                     {
  840.                         @file_put_contents($ipFile, $ip);
  841.                     }
  842.  
  843.                 }
  844.  
  845.             }
  846.  
  847.         }
  848.  
  849.     }
  850.  
  851.     if( is_valid_ip($ip) )
  852.     {
  853.         return $ip;
  854.     }
  855.  
  856.     if( file_exists($ipFile) )
  857.     {
  858.         @unlink($ipFile);
  859.     }
  860.  
  861. }
  862.  
  863. function is_valid_ip($ip)
  864. {
  865.     return $ip != "127.0.0.1" && $ip != "::1" && filter_var($ip, FILTER_VALIDATE_IP);
  866. }
  867.  
  868. function aaaaoy()
  869. {
  870.     return array( "announceLog/", "avatars/l/", "avatars/m/", "avatars/s/", "backups/", "cache/", "countryFlags/", "downloads/files/", "downloads/previews/", "errors/", "gallery/l/", "gallery/s/", "languageFlags/", "posts/", "smilies/", "subTitles/", "torrents/auto_uploader/", "torrents/category_images/", "torrents/imdb/", "torrents/nfo/", "torrents/torrent_files/", "torrents/torrent_genres/", "torrents/torrent_images/l/", "torrents/torrent_images/m/", "torrents/torrent_images/s/" );
  871. }
  872.  
  873. function aaaaoz($path = "")
  874. {
  875.     if( !$path || !is_dir($path) )
  876.     {
  877.         return false;
  878.     }
  879.  
  880.     clearstatcache();
  881.     $Directories = scandir($path);
  882.     if( !$Directories )
  883.     {
  884.         return false;
  885.     }
  886.  
  887.     $aaaapd = array(  );
  888.     foreach( $Directories as $directory )
  889.     {
  890.         if( is_dir($path . $directory) && $directory != "." && $directory != ".." )
  891.         {
  892.             $aaaapd[] = $path . $directory . "/";
  893.         }
  894.  
  895.     }
  896.     return $aaaapd;
  897. }
  898.  
  899. function aaaapc()
  900. {
  901.     $port = (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] ? intval($_SERVER["SERVER_PORT"]) : 0);
  902.     $port = (in_array($port, array( 80, 443 )) ? "" : ":" . $port);
  903.     $scheme = (":443" == $port || isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] && $_SERVER["HTTPS"] != "off" ? "https://" : "http://");
  904.     $host = fetch_server_value("HTTP_HOST");
  905.     $name = fetch_server_value("SERVER_NAME");
  906.     $host = (substr_count($name, ".") < substr_count($host, ".") ? $host : $name);
  907.     define("_HTTP_HOST", $host);
  908.     if( !($scriptpath = fetch_server_value("PATH_INFO")) && !($scriptpath = fetch_server_value("REDIRECT_URL")) && !($scriptpath = fetch_server_value("URL")) && !($scriptpath = fetch_server_value("PHP_SELF")) )
  909.     {
  910.         $scriptpath = fetch_server_value("SCRIPT_NAME");
  911.     }
  912.  
  913.     $url = $scheme . $host . "/" . str_replace(SCRIPT_NAME, "", ltrim($scriptpath, "/\\"));
  914.     return $url;
  915. }
  916.  
  917. function fetch_server_value($name)
  918. {
  919.     if( isset($_SERVER[$name]) && $_SERVER[$name] )
  920.     {
  921.         return $_SERVER[$name];
  922.     }
  923.  
  924.     if( isset($_ENV[$name]) && $_ENV[$name] )
  925.     {
  926.         return $_ENV[$name];
  927.     }
  928.  
  929.     return false;
  930. }
  931.  
  932. function showmessage($message = "")
  933. {
  934.     sleep(2);
  935.     exit( $message );
  936. }
  937.  
  938. function checkdirectorypermissions($Directory = "")
  939. {
  940.     clearstatcache();
  941.     return !empty($Directory) && is_dir($Directory) && is_writable($Directory);
  942. }
  943.  
  944. function showerror($error)
  945. {
  946.     showmessage("-ERROR-Fatal Error: " . $error);
  947. }
  948.  
  949. function aaaaox($error)
  950. {
  951.     showmessage("<div id=\"error\">" . $error . "</div>");
  952. }
  953.  
  954. function showdialog($dialog)
  955. {
  956.     showmessage("-DIALOG-" . $dialog);
  957. }
  958.  
  959. function aaaape($error = "", $useDIV = true)
  960. {
  961.     global $isAjax;
  962.     $_SESSION["lk"] = "";
  963.     if( $isAjax )
  964.     {
  965.         showmessage("-ERROR-" . $error);
  966.     }
  967.     else
  968.     {
  969.         printoutput(($useDIV ? "<div id=\"error\">" . $error . "</div>" : $error));
  970.     }
  971.  
  972. }
  973.  
  974. function printoutput($HTML, $useInstallJS = false)
  975. {
  976.     $Output = "\r\n\t<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n\t<html>\r\n\t\t<head>\r\n\t\t\t<noscript><meta http-equiv=refresh content=\"0; URL=" . TSUE_ADMINCP_URL . SCRIPT_NAME . "?noscript=1\" /></noscript>\r\n\t\t\t<meta charset=\"utf-8\" />\r\n\t\t\t<title>TSUE Upgrade System</title>\r\n\t\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/install.css\" />\r\n\t\t\t<script type=\"text/javascript\">var TSUEPhrases = {}</script>\r\n\t\t\t<script type=\"text/javascript\" src=\"" . TSUE_FRONT_URL . "/js/tsue/jquery.js\"></script>\r\n\t\t</head>\r\n\t\t\r\n\t\t<body>\r\n\r\n\t\t\t<div id=\"dialog\"></div>\r\n\t\t\t<div id=\"header\"></div>\r\n\t\t\t<div id=\"wrapper\">\t\t\t\r\n\t\t\t\t<div id=\"container\">" . $HTML . "</div>\t\t\t\r\n\t\t\t</div>\r\n\r\n\t\t\t<div id=\"footer\"></div>\r\n\t\t\t\r\n\t\t\t<div id=\"copyright\">\r\n                <div class=\"tsue dotted-bottom-gray\">Software by TSUE&trade; &copy;2014 <a href=\"http://www.templateshares-ue.net\" target=\"_blank\">www.templateshares-ue.net</a></div>\r\n            </div>\r\n\r\n\t\t\t" . (($useInstallJS ? "\r\n\t\t\t<script type=\"text/javascript\">\r\n\t\t\t\tvar stepCount = 0,\r\n\t\t\t\t\$totalSteps = 10,\r\n\t\t\t\t\$progressbar = \$(\"#progressbar\"),\r\n\t\t\t\t\$progress = \$(\"#progress\"),\r\n\t\t\t\t\$result = \$(\"#welcomeScreen\"),\r\n\t\t\t\t\$dialog = \$(\"#dialog\"),\r\n\t\t\t\t\$loader = \$('<img src=\"images/ajax-loader.gif\" alt=\"loading..\" title=\"loading..\" border=\"0\" id=\"loader\" />'),\r\n\t\t\t\t\$bigLoader = \$('<img src=\"images/ajax-loader-big.gif\" alt=\"loading..\" title=\"loading..\" border=\"0\" id=\"bigLoader\" />'),\r\n\t\t\t\t\$adminAccount = null;\r\n\r\n\t\t\t\tvar openDialog = function(text, onFinish)\r\n\t\t\t\t{\r\n\t\t\t\t\t\$dialog.html(text);\r\n\t\t\t\t\t\$dialog.overlay\r\n\t\t\t\t\t({\r\n\t\t\t\t\t\tmask: {color: \"#ccc\",loadSpeed:200,opacity:0.7},\r\n\t\t\t\t\t\tcloseOnClick: false,\r\n\t\t\t\t\t\tcloseOnEsc: false,\r\n\t\t\t\t\t\tload: true,\r\n\t\t\t\t\t\tonClose: onFinish,\r\n\t\t\t\t\t\tonBeforeLoad: function(){},\r\n\t\t\t\t\t\tonBeforeClose: function(){}\r\n\t\t\t\t\t}).load();\r\n\t\t\t\t};\r\n\r\n\t\t\t\t\$(document).on(\"submit\", \"#dialogForm\", function(e)\r\n\t\t\t\t{\r\n\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\tvar \$thisForm = \$(this),  \$serialize = \$thisForm.serialize();\r\n\r\n\t\t\t\t\t\$(\"#error\").remove();\r\n\t\t\t\t\t\r\n\t\t\t\t\t\$bigLoader.appendTo(\"#formDIV\");\r\n\r\n\t\t\t\t\t\$.ajax\r\n\t\t\t\t\t({\r\n\t\t\t\t\t\ttype: \"POST\",\r\n\t\t\t\t\t\tdata: \$serialize,\r\n\t\t\t\t\t\turl: \"" . SCRIPT_NAME . "\",\r\n\t\t\t\t\t\tsuccess: function(formResults)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\$bigLoader.remove();\r\n\t\t\t\t\t\t\tif(formResults && formResults.match(/\"error\"/))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\$thisForm.find(\"#formResults\").remove();\r\n\t\t\t\t\t\t\t\t\$('<div id=\"formResults\">'+formResults+'</div>').prependTo(\$thisForm);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse if(formResults)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\$dialog.empty().overlay().close();\r\n\t\t\t\t\t\t\t\t\$result.html(formResults);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t});\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t});\r\n\r\n\t\t\t\tvar ajaxProgress = function()\r\n\t\t\t\t{\r\n\t\t\t\t\tstepCount++;\r\n\r\n\t\t\t\t\tvar pWidth = Math.round((stepCount/\$totalSteps*100));\r\n\t\t\t\t\tif(pWidth > 100 || stepCount >= \$totalSteps)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpWidth = 100;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif(\$progress.width() < 100)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t\$progress.animate({width: pWidth+\"%\"}, 3000);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\$.ajax\r\n\t\t\t\t\t({\r\n\t\t\t\t\t\ttype: \"POST\",\r\n\t\t\t\t\t\tdata: \"isAjax=1&stepCount=\"+stepCount,\r\n\t\t\t\t\t\turl: \"" . SCRIPT_NAME . "\",\r\n\t\t\t\t\t\tsuccess: function(serverResult)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif(serverResult.match(/-ERROR-/))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tserverResult = '<div id=\"error\">'+serverResult.replace(/-ERROR-/, '')+'</div>';\r\n\t\t\t\t\t\t\t\t\$result.html(serverResult);\r\n\t\t\t\t\t\t\t\t\$progressbar.hide();\r\n\t\t\t\t\t\t\t\t\$loader.hide();\r\n\t\t\t\t\t\t\t\tstepCount = 0;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse if(serverResult.match(/-DIALOG-/))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tserverResult = serverResult.replace(/-DIALOG-/, \"\");\r\n\r\n\t\t\t\t\t\t\t\tvar onFinish = function()\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tajaxProgress();\r\n\t\t\t\t\t\t\t\t};\r\n\t\t\t\t\t\t\t\topenDialog(serverResult, onFinish);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse if(serverResult)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\$result.html(serverResult);\r\n\t\t\t\t\t\t\t\tajaxProgress();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse//finished?\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tstepCount=0;\r\n\t\t\t\t\t\t\t\t\$progress.animate({width: \"100%\"}, 100, function(){\$loader.remove()});\r\n\t\t\t\t\t\t\t\t\$progressbar.hide();\r\n\t\t\t\t\t\t\t\t\$loader.hide();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t});\r\n\t\t\t\t};\r\n\r\n\t\t\t\tvar welcomeScreen = function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\$.ajax\r\n\t\t\t\t\t({\r\n\t\t\t\t\t\ttype: \"POST\",\r\n\t\t\t\t\t\tdata: \"isAjax=1&doAction=requirementsCheck\",\r\n\t\t\t\t\t\turl: \"" . SCRIPT_NAME . "\",\r\n\t\t\t\t\t\tsuccess: function(serverResult)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\$(\"#welcomeScreen\").html(serverResult);\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tif(serverResult.match(/Requirements Met/))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\$(\"#beginInstall\").show();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar enableButtons = function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\$(\"body :input\").attr(\"disabled\", false);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar disableButtons = function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\$(\"body :input\").attr(\"disabled\", true);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar initTipsy = function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\$(\".hint\").tipsy({title: \"id\", gravity: \"sw\", html: true});\r\n\t\t\t\t}\r\n\r\n\t\t\t\t\$(document).ready(function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\$.ajaxSetup({timeout: 600000});\r\n\t\t\t\t\t\$(document).ajaxStart(function(){disableButtons()}).ajaxComplete(function(){enableButtons(); initTipsy();});\r\n\r\n\t\t\t\t\twelcomeScreen();\r\n\t\t\t\t\t\r\n\t\t\t\t\t\$(document).on(\"click\", \"#start\", function(e)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t\$(\"#start,#reload\").remove();\r\n\t\t\t\t\t\t\$(\"#requirementsMet,#licenseAgreement\").remove();\r\n\t\t\t\t\t\t\$progressbar.show();\r\n\t\t\t\t\t\t\$loader.appendTo(\"#buttons\");\r\n\t\t\t\t\t\t\$result.html(\"Initializing...\");\r\n\t\t\t\t\t\tajaxProgress();\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\$(document).on(\"click\", \"#reload\", function(e)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\twindow.location.reload();\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t</script>" : "")) . "\r\n\r\n\t\t</body>\r\n\t</html>";
  977.     exit( $Output );
  978. }
  979.  
  980. function getpostvar($name = "")
  981. {
  982.     return ($name && isset($_POST[$name]) ? $_POST[$name] : "");
  983. }
  984.  
  985. function showhint($hint = "", $link = "help")
  986. {
  987.     return "<span class=\"hint\" id=\"" . $hint . "\">" . $link . "</span>";
  988. }
  989.  
  990. function aaaapf($hint = "")
  991. {
  992.     return "<span class=\"inputHint\">" . $hint . "</span>";
  993. }
  994.  
  995. function aaaapg()
  996. {
  997.     return "<span class=\"okMessage\">CONFIRMED!</span>";
  998. }
  999.  
  1000. function showtitle($title = "")
  1001. {
  1002.     return "<span class='title'>" . $title . "</span>";
  1003. }
  1004.  
  1005. function generatepasskey($length = 30)
  1006. {
  1007.     $passkey = "";
  1008.     for( $i = 0; $i < $length; $i++ )
  1009.     {
  1010.         $passkey .= chr(rand(33, 126));
  1011.     }
  1012.     return sha1($passkey);
  1013. }
  1014.  
  1015. function file_extension($filename)
  1016. {
  1017.     return substr(strrchr($filename, "."), 1);
  1018. }
  1019.  
  1020. function updatesettings($settingname, $settingvalues)
  1021. {
  1022.     global $TSUE;
  1023.     $BuildQuery = array( "settingname" => $settingname, "settingvalues" => serialize($settingvalues) );
  1024.     $TSUE["TSUE_Database"]->delete("tsue_settings", "settingname = " . $TSUE["TSUE_Database"]->escape($settingname));
  1025.     return $TSUE["TSUE_Database"]->insert("tsue_settings", $BuildQuery);
  1026. }
  1027.  
  1028. function handleprune()
  1029. {
  1030.     global $TSUE;
  1031.     $TSUE["TSUE_Database"]->truncate("tsue_file_caches");
  1032.     $cacheFolder = DATAPATH . "cache/";
  1033.     if( !is_dir($cacheFolder) || !is_writable($cacheFolder) )
  1034.     {
  1035.         showerror("Cache folder is not writable: " . $cacheFolder);
  1036.     }
  1037.  
  1038.     $cacheFiles = scandir($cacheFolder);
  1039.     if( count($cacheFiles) <= 2 )
  1040.     {
  1041.         showerror("Cache files does not exists in: " . $cacheFolder);
  1042.     }
  1043.  
  1044.     foreach( $cacheFiles as $cacheFile )
  1045.     {
  1046.         $_ext = file_extension($cacheFile);
  1047.         if( in_array($_ext, array( "tsue", "gz", "js", "gif", "jpg", "png", "jpeg", "zip", "srv" )) )
  1048.         {
  1049.             @unlink($cacheFolder . $cacheFile);
  1050.         }
  1051.  
  1052.     }
  1053. }
  1054.  
  1055. function handlerebuildcaches($logANDreturn = true)
  1056. {
  1057.     global $TSUE;
  1058.     $content = "";
  1059.     $cacheContents = array(  );
  1060.     $Announcement = $TSUE["TSUE_Database"]->query_result("SELECT a.*, m.membername FROM tsue_announcements a LEFT JOIN tsue_members m USING(memberid) WHERE a.active = 1 ORDER BY a.date DESC LIMIT 1");
  1061.     if( $Announcement )
  1062.     {
  1063.         $cacheContents["active_announcements_cache"] = array( "aid" => $Announcement["aid"], "memberid" => $Announcement["memberid"], "date" => $Announcement["date"], "title" => $Announcement["title"], "content" => $Announcement["content"] );
  1064.     }
  1065.     else
  1066.     {
  1067.         $cacheContents["active_announcements_cache"] = array(  );
  1068.     }
  1069.  
  1070.     $News = $TSUE["TSUE_Database"]->query("SELECT n.*, m.membername FROM tsue_news n LEFT JOIN tsue_members m USING(memberid) WHERE n.active = 1 ORDER BY n.date DESC");
  1071.     if( $TSUE["TSUE_Database"]->num_rows($News) )
  1072.     {
  1073.         while( $nItem = $TSUE["TSUE_Database"]->fetch_assoc($News) )
  1074.         {
  1075.             $cacheContents["active_news_cache"][] = array( "nid" => $nItem["nid"], "memberid" => $nItem["memberid"], "date" => $nItem["date"], "title" => $nItem["title"], "content" => $nItem["content"] );
  1076.         }
  1077.     }
  1078.     else
  1079.     {
  1080.         $cacheContents["active_news_cache"] = array(  );
  1081.     }
  1082.  
  1083.     $aaaaph = $TSUE["TSUE_Database"]->query("SELECT * FROM tsue_ban_country ORDER BY 'country'");
  1084.     if( $TSUE["TSUE_Database"]->num_rows($aaaaph) )
  1085.     {
  1086.         while( $nItem = $TSUE["TSUE_Database"]->fetch_assoc($aaaaph) )
  1087.         {
  1088.             $cacheContents["banned_countries_cache"][] = $nItem["country"];
  1089.         }
  1090.     }
  1091.     else
  1092.     {
  1093.         $cacheContents["banned_countries_cache"] = array(  );
  1094.     }
  1095.  
  1096.     $aaaapi = $TSUE["TSUE_Database"]->query("SELECT * FROM tsue_ban_email ORDER BY 'banned_email'");
  1097.     if( $TSUE["TSUE_Database"]->num_rows($aaaapi) )
  1098.     {
  1099.         while( $nItem = $TSUE["TSUE_Database"]->fetch_assoc($aaaapi) )
  1100.         {
  1101.             $cacheContents["banned_emails_cache"][] = $nItem["banned_email"];
  1102.         }
  1103.     }
  1104.     else
  1105.     {
  1106.         $cacheContents["banned_emails_cache"] = array(  );
  1107.     }
  1108.  
  1109.     $bannedIPs = $TSUE["TSUE_Database"]->query("SELECT * FROM tsue_ip_match WHERE match_type = 'banned'");
  1110.     if( $TSUE["TSUE_Database"]->num_rows($bannedIPs) )
  1111.     {
  1112.         while( $nItem = $TSUE["TSUE_Database"]->fetch_assoc($bannedIPs) )
  1113.         {
  1114.             $cacheContents["banned_ips_cache"][$nItem["first_octet"]][] = array( $nItem["start_range"], $nItem["end_range"] );
  1115.         }
  1116.     }
  1117.     else
  1118.     {
  1119.         $cacheContents["banned_ips_cache"] = array(  );
  1120.     }
  1121.  
  1122.     $Smilies = $TSUE["TSUE_Database"]->query("SELECT smilie_text, smilie_title, smilie_file FROM tsue_smilies");
  1123.     if( $TSUE["TSUE_Database"]->num_rows($Smilies) )
  1124.     {
  1125.         while( $Smilie = $TSUE["TSUE_Database"]->fetch_assoc($Smilies) )
  1126.         {
  1127.             $cacheContents["dialog_smilies_cache"][] = $Smilie;
  1128.         }
  1129.     }
  1130.     else
  1131.     {
  1132.         $cacheContents["dialog_smilies_cache"] = array(  );
  1133.     }
  1134.  
  1135.     $permissions = $TSUE["TSUE_Database"]->query("SELECT * FROM tsue_forums_permissions ORDER BY forumid ASC");
  1136.     if( $TSUE["TSUE_Database"]->num_rows($permissions) )
  1137.     {
  1138.         while( $nItem = $TSUE["TSUE_Database"]->fetch_assoc($permissions) )
  1139.         {
  1140.             $cacheContents["forums_permissions_cache"][] = array( "forumid" => $nItem["forumid"], "membergroupid" => $nItem["membergroupid"], "permissions" => $nItem["permissions"] );
  1141.         }
  1142.     }
  1143.     else
  1144.     {
  1145.         $cacheContents["forums_permissions_cache"] = array(  );
  1146.     }
  1147.  
  1148.     $prefixes = $TSUE["TSUE_Database"]->query("SELECT * FROM tsue_forums_thread_prefixes ORDER BY pname ASC");
  1149.     if( $TSUE["TSUE_Database"]->num_rows($prefixes) )
  1150.     {
  1151.         while( $nItem = $TSUE["TSUE_Database"]->fetch_assoc($prefixes) )
  1152.         {
  1153.             $cacheContents["forums_thread_prefixes"][] = array( "pid" => $nItem["pid"], "pname" => $nItem["pname"], "cssname" => $nItem["cssname"], "viewpermissions" => $nItem["viewpermissions"] );
  1154.         }
  1155.     }
  1156.     else
  1157.     {
  1158.         $cacheContents["forums_thread_prefixes"] = array(  );
  1159.     }
  1160.  
  1161.     $Plugins = $TSUE["TSUE_Database"]->query("SELECT pluginid, name, filename, contents, viewpermissions, pluginOptions FROM tsue_plugins WHERE `active` = 1");
  1162.     if( $TSUE["TSUE_Database"]->num_rows($Plugins) )
  1163.     {
  1164.         while( $nItem = $TSUE["TSUE_Database"]->fetch_assoc($Plugins) )
  1165.         {
  1166.             $cacheContents["tsue_plugins_cache"][] = $nItem;
  1167.         }
  1168.     }
  1169.     else
  1170.     {
  1171.         $cacheContents["tsue_plugins_cache"] = array(  );
  1172.     }
  1173.  
  1174.     $Genres = $TSUE["TSUE_Database"]->query("SELECT gid, gname, gicon, categories FROM tsue_torrents_genres WHERE active = 1 ORDER BY gname ASC");
  1175.     if( $TSUE["TSUE_Database"]->num_rows($Genres) )
  1176.     {
  1177.         while( $Genre = $TSUE["TSUE_Database"]->fetch_assoc($Genres) )
  1178.         {
  1179.             $cacheContents["tsue_torrents_genres_cache"][] = $Genre;
  1180.         }
  1181.     }
  1182.     else
  1183.     {
  1184.         $cacheContents["tsue_torrents_genres_cache"] = array(  );
  1185.     }
  1186.  
  1187.     $Themes = $TSUE["TSUE_Database"]->query("SELECT themeid FROM tsue_themes WHERE active = 1");
  1188.     if( $TSUE["TSUE_Database"]->num_rows($Themes) )
  1189.     {
  1190.         while( $Theme = $TSUE["TSUE_Database"]->fetch_assoc($Themes) )
  1191.         {
  1192.             $aaaapj[] = $Theme["themeid"];
  1193.         }
  1194.         $TSUE["TSUE_Settings"]->settings["global_settings"]["available_themes"] = implode(",", $aaaapj);
  1195.     }
  1196.  
  1197.     $Languages = $TSUE["TSUE_Database"]->query("SELECT languageid FROM tsue_languages WHERE active = 1");
  1198.     if( $TSUE["TSUE_Database"]->num_rows($Languages) )
  1199.     {
  1200.         while( $Language = $TSUE["TSUE_Database"]->fetch_assoc($Languages) )
  1201.         {
  1202.             $languageCache[] = $Language["languageid"];
  1203.         }
  1204.         $TSUE["TSUE_Settings"]->settings["global_settings"]["available_languages"] = implode(",", $languageCache);
  1205.     }
  1206.  
  1207.     updatesettings("global_settings", $TSUE["TSUE_Settings"]->settings["global_settings"]);
  1208.     if( !empty($cacheContents) )
  1209.     {
  1210.         foreach( $cacheContents as $settingname => $settingvalues )
  1211.         {
  1212.             updatesettings($settingname, $settingvalues);
  1213.         }
  1214.     }
  1215.  
  1216. }
  1217.  
  1218. function fixurl($url = "")
  1219. {
  1220.     return strtolower(str_replace(array( "http://", "https://", "www.", "http://www.", "https://www." ), "", $url));
  1221. }
  1222.  
  1223. function encodestring($String = "", $AnahtarKelime = "I3RTVWVMaWNlbnNlQ2hlY2syMDExIw==")
  1224. {
  1225.     $AnahtarKelime = base64_decode($AnahtarKelime);
  1226.     $result = "";
  1227.     for( $i = 0; $i < strlen($String); $i++ )
  1228.     {
  1229.         $char = substr($String, $i, 1);
  1230.         $keychar = substr($AnahtarKelime, $i % strlen($AnahtarKelime) - 1, 1);
  1231.         $char = chr(ord($char) + ord($keychar));
  1232.         $result .= $char;
  1233.     }
  1234.     return urlencode(base64_encode($result));
  1235. }
  1236.  
  1237. function decodestring($String = "", $AnahtarKelime = "I3RTVWVMaWNlbnNlQ2hlY2syMDExIw==")
  1238. {
  1239.     $AnahtarKelime = base64_decode($AnahtarKelime);
  1240.     $String = urldecode($String);
  1241.     $result = "";
  1242.     $String = urldecode(base64_decode($String));
  1243.     for( $i = 0; $i < strlen($String); $i++ )
  1244.     {
  1245.         $char = substr($String, $i, 1);
  1246.         $keychar = substr($AnahtarKelime, $i % strlen($AnahtarKelime) - 1, 1);
  1247.         $char = chr(ord($char) - ord($keychar));
  1248.         $result .= $char;
  1249.     }
  1250.     return $result;
  1251. }
  1252.  
  1253. function compare_key($installkey = "")
  1254. {
  1255.     return strlen($installkey) === 36 && preg_match(str_replace("#", "[0-9,A-F]", "{########-####-####-####-############}"), $installkey);
  1256. }
  1257.  
  1258. function is_valid_url($url = "")
  1259. {
  1260.     return (!empty($url) && !preg_match("#^[a-z0-9-\\.]+\$#", $url) ? false : true);
  1261. }
  1262.  
  1263. function aaaapa($type = 0, $db_tsue_version = "")
  1264. {
  1265.     $serverResponse = "";
  1266.     if( function_exists("curl_init") && ($ch = curl_init()) )
  1267.     {
  1268.         curl_setopt($ch, CURLOPT_URL, decodestring(TSUE_URL));
  1269.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1270.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  1271.         curl_setopt($ch, CURLOPT_HEADER, 0);
  1272.         curl_setopt($ch, CURLOPT_USERAGENT, "d3bJmHWuutzXxtrfxrfR1NE%3D");
  1273.         curl_setopt($ch, CURLOPT_REFERER, U);
  1274.         curl_setopt($ch, CURLOPT_POST, 1);
  1275.         curl_setopt($ch, CURLOPT_POSTFIELDS, "t=" . $type . "&u=" . encodestring(U) . "&i=" . encodestring(I) . "&v=" . V . (($db_tsue_version ? "&dv=" . $db_tsue_version : "")));
  1276.         $serverResponse = curl_exec($ch);
  1277.         curl_close($ch);
  1278.         if( $serverResponse )
  1279.         {
  1280.             $serverResponse = decodestring($serverResponse);
  1281.         }
  1282.  
  1283.     }
  1284.  
  1285.     return $serverResponse;
  1286. }
  1287.  
  1288. function aaaaow()
  1289. {
  1290.     global $isAjax;
  1291.     $ERROR = "";
  1292.     session_name("tsueinstallation");
  1293.     session_start();
  1294.     clearstatcache();
  1295.     return true;
  1296.     if( file_exists($_SERVER["DOCUMENT_ROOT"] . "/tsue/l.php") )
  1297.     {
  1298.         aaaape("Critical Security Error.");
  1299.     }
  1300.  
  1301.     $serverResponse = aaaapa(1);
  1302.     if( !$serverResponse )
  1303.     {
  1304.         aaaape("Could not connect to TSUE license server.");
  1305.     }
  1306.  
  1307.     if( !preg_match("#\\[lk\\](.*)\\[\\/lk\\]#", $serverResponse, $licenseKey) )
  1308.     {
  1309.         $serverResponse = str_replace(array( "margin: 50px auto 0 auto;", "width: 600px;" ), array( "margin: 0 auto;", "width: 100%;" ), $serverResponse);
  1310.         aaaape($serverResponse, false);
  1311.     }
  1312.  
  1313.     $licenseKey = (isset($licenseKey["1"]) ? $licenseKey["1"] : "");
  1314.     if( !compare_key($licenseKey) )
  1315.     {
  1316.         aaaape("Could not fetch the correct license key.");
  1317.     }
  1318.  
  1319.     if( strtoupper($_SERVER["REQUEST_METHOD"]) === "POST" && isset($_POST["licenseKey"]) && !empty($_POST["licenseKey"]) )
  1320.     {
  1321.         if( isset($_POST["CSRFKey"]) && $_POST["CSRFKey"] && isset($_SESSION["CSRFKey"]) && $_SESSION["CSRFKey"] && $_POST["CSRFKey"] === $_SESSION["CSRFKey"] )
  1322.         {
  1323.             if( compare_key($_POST["licenseKey"]) && $_POST["licenseKey"] === $licenseKey )
  1324.             {
  1325.                 $_SESSION["lk"] = $_POST["licenseKey"];
  1326.             }
  1327.             else
  1328.             {
  1329.                 $_SESSION["lk"] = "";
  1330.                 $ERROR = "<div id=\"error\">The entered License Key could not be verified.</div>";
  1331.             }
  1332.  
  1333.         }
  1334.         else
  1335.         {
  1336.             $_SESSION["lk"] = "";
  1337.             $_SESSION["CSRFKey"] = "";
  1338.             $ERROR = "<div id=\"error\">Invalid Security Token.</div>";
  1339.         }
  1340.  
  1341.     }
  1342.  
  1343.     if( !isset($_SESSION["lk"]) || !compare_key($_SESSION["lk"]) || $_SESSION["lk"] != $licenseKey )
  1344.     {
  1345.         $_SESSION["lk"] = "";
  1346.         $CSRFKey = sha1(microtime());
  1347.         $_SESSION["CSRFKey"] = $CSRFKey;
  1348.         if( $isAjax )
  1349.         {
  1350.             showmessage("-ERROR-Please refresh page and re-enter your License Key.");
  1351.         }
  1352.  
  1353.         printoutput("\r\n\t\t\t" . $ERROR . "\r\n\t\t\t<form method=\"post\" id=\"checkLicense\">\r\n\t\t\t<input type=\"hidden\" name=\"CSRFKey\" value=\"" . $CSRFKey . "\" />\r\n\t\t\t\t<div id=\"licenseKey\">\r\n\t\t\t\t\t" . showhint("For security reasons, you must verify your license key.<br />You can find your license key in our Client Area.") . "\r\n\t\t\t\t\tEnter License Key Here: <input type=\"text\" name=\"licenseKey\" class=\"key\" value=\"\" /> <input type=\"submit\" value=\"verifiy\" class=\"submit\" />\r\n\t\t\t\t</div>\r\n\t\t\t</form>\r\n\t\t\t<script type=\"text/javascript\">\r\n\t\t\t\t\$(document).ready(function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\$(\".hint\").tipsy({title: \"id\", gravity: \"sw\", html: true});\r\n\t\t\t\t\t\$(\"#checkLicense\").submit(function(e)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t\$(\"input[type='submit']\").val(\"checking...\");\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t</script>\r\n\t\t");
  1354.     }
  1355.  
  1356. }
Advertisement
RAW Paste Data Copied
Advertisement