Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.45 KB | None | 0 0
  1. <?php
  2. /*=======================================================================
  3. | UberCMS - Advanced Website and Content Management System for uberEmu
  4. | #######################################################################
  5. | Copyright (c) 2010, Roy 'Meth0d' & Jonty McIntyre
  6. | http://www.meth0d.org
  7. | #######################################################################
  8. | This program is free software: you can redistribute it and/or modify
  9. | it under the terms of the GNU General Public License as published by
  10. | the Free Software Foundation, either version 3 of the License, or
  11. | (at your option) any later version.
  12. | #######################################################################
  13. | This program is distributed in the hope that it will be useful,
  14. | but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. | GNU General Public License for more details.
  17. \======================================================================*/
  18.  
  19. class uberCore
  20. {
  21.     public $config;
  22.     public $execStart;
  23.    
  24.     public function __construct()
  25.     {
  26.         $this->execStart = microtime(true);
  27.     }  
  28.    
  29.     public static function CheckBetaKey($keyCode)
  30.     {
  31.         return (mysql_num_rows(dbquery("SELECT null FROM betakeys WHERE keyc = '" . filter($keyCode) . "' AND qty > 0 LIMIT 1")) > 0) ? true : false;
  32.     }
  33.    
  34.     public static function EatBetaKey($keyCode)
  35.     {
  36.         dbquery("UPDATE betakeys SET qty = qty - 1 WHERE keyc = '" . filter($keyCode) . "' LIMIT 1");
  37.     }
  38.     public static function zapHash($text)
  39.     {
  40.         return md5($text);
  41.     }
  42.     public static function CheckCookies()
  43.     {
  44.         if (LOGGED_IN)
  45.         {
  46.             return;
  47.         }
  48.    
  49.         if (isset($_COOKIE['rememberme']) && $_COOKIE['rememberme'] == "true" && isset($_COOKIE['rememberme_token']) && isset($_COOKIE['rememberme_name']))
  50.         {
  51.             $name = filter($_COOKIE['rememberme_name']);
  52.             $token = filter($_COOKIE['rememberme_token']);
  53.             $find = dbquery("SELECT id,username FROM users WHERE username = '" . $name . "' AND password = '" . $token . "' LIMIT 1");
  54.            
  55.             if (mysql_num_rows($find) > 0)
  56.             {
  57.                 $data = mysql_fetch_assoc($find);
  58.                
  59.                 $_SESSION['UBER_USER_N'] = $data['username'];
  60.                 $_SESSION['UBER_USER_H'] = $token;
  61.                 $_SESSION['set_cookies'] = true; // renew cookies
  62.                
  63.                 header("Location: " . WWW . "/security_check");
  64.                 exit;              
  65.             }
  66.         }
  67.     }
  68.    
  69.     public static function FormatDate()
  70.     {
  71.         return date('j F Y, h:i:s A');
  72.     }
  73.    
  74.     public function UberHash($input = '')
  75.     {
  76.         return md5($input);
  77.     }
  78.    
  79.     public static function GenerateTicket($seed = '')
  80.     {
  81.         $ticket = "ST-";
  82.         $ticket .= sha1($seed . 'Uber' . rand(118,283));
  83.         $ticket .= '-' . rand(100, 255);
  84.         $ticket .= '-uber-fe' . rand(0, 5);
  85.        
  86.         return $ticket;
  87.     }
  88.  
  89.     public static function FilterInputString($strInput = '')
  90.     {
  91.         return mysql_real_escape_string(stripslashes(trim($strInput)));
  92.     }
  93.    
  94.     public static function FilterSpecialChars($strInput, $allowLB = false)
  95.     {
  96.         $strInput = str_replace(chr(1), ' ', $strInput);
  97.         $strInput = str_replace(chr(2), ' ', $strInput);
  98.         $strInput = str_replace(chr(3), ' ', $strInput);
  99.         $strInput = str_replace(chr(9), ' ', $strInput);
  100.          
  101.         if (!$allowLB)
  102.         {
  103.             $strInput = str_replace(chr(13), ' ', $strInput);
  104.         }
  105.          
  106.         $strInput = filter_var($strInput, FILTER_SANITIZE_STRING);
  107.  
  108.          
  109.         return $strInput;
  110.     }  
  111.    
  112.     public static function CleanStringForOutput($strInput = '', $ignoreHtml = false, $nl2br = false)
  113.     {
  114.         $strInput = stripslashes(trim($strInput));
  115.  
  116.         if (!$ignoreHtml)
  117.         {
  118.             $strInput = htmlentities($strInput);
  119.         }
  120.        
  121.         if ($nl2br)
  122.         {
  123.             $strInput = nl2br($strInput);
  124.         }
  125.  
  126.         return $strInput;
  127.     }
  128.  
  129.     public static function SystemError($title, $text)
  130.     {
  131.         echo "<font face='verdana'><center>UberCMS has encountered an error <br /> " . $text . " </font></center>";
  132.         exit;      
  133.     }
  134.    
  135.     public function ParseConfig()
  136.     {
  137.         $configPath = config_directory . 'system_config.php';
  138.        
  139.         if (!file_exists($configPath))
  140.         {
  141.             $this->systemError('Configuration Error', 'The configuration file could not be located at ' . $configPath);
  142.         }
  143.        
  144.         require_once $configPath;
  145.        
  146.         if (!isset($config) || count($config) < 2)
  147.         {
  148.             $this->systemError('Configuration Error', 'The configuration file was located, but is in an invalid format. Data is missing or in the wrong format.');
  149.         }
  150.        
  151.         $this->config = $config;
  152.        
  153.         define('WWW', $this->config['Site']['www']);
  154.     }
  155.    
  156.     public static function GetSystemStatusString($statsFig)
  157.     {
  158.         $amt = number_format(mysql_result(dbquery("SELECT count(*) FROM `users` WHERE `online` = '1'"), 0));
  159.        
  160.         switch (uberCore::getSystemStatus())
  161.         {
  162.             case 2:
  163.             case 0: return $amt . " " . regOnlineText;
  164.                
  165.             case 1:
  166.            
  167.                 if (!$statsFig)
  168.                 {
  169.                     return $amt . " " . regOnlineText;
  170.                 }
  171.                 else
  172.                 {
  173.                     return  "<b><font color='black'> " . $amt  . '</font color></b> ' . regOnlineText;
  174.                 }
  175.        
  176.             default:
  177.            
  178.                 return "Unknown";
  179.         }
  180.     }
  181.    
  182.     public static function GetSystemStatus()
  183.     {
  184.         return intval(mysql_result(dbquery("SELECT status FROM server_status LIMIT 1"), 0));
  185.     }
  186.    
  187.     public static function GetUsersOnline()
  188.     {
  189.         return intval(mysql_result(dbquery("SELECT count(*) FROM `users` WHERE `online` = '1'"), 0));
  190.     }
  191.    
  192.     public static function GetMaintenanceStatus()
  193.     {
  194.         return mysql_result(dbquery("SELECT maintenance FROM site_config LIMIT 1"), 0);
  195.     }
  196.    
  197.     public function Mus($header, $data = '')
  198.     {
  199.         if ($this->config['MUS']['enabled'] == "false" || $this->getSystemStatus() == "0")
  200.         {
  201.             return;
  202.         }
  203.        
  204.         $musData = $header . chr(1) . $data;
  205.        
  206.         $sock = @socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
  207.         @socket_connect($sock, $this->config['MUS']['ip'], intval($this->config['MUS']['port']));
  208.         @socket_send($sock, $musData, strlen($musData), MSG_DONTROUTE);
  209.         @socket_close($sock);
  210.     }
  211.  
  212.    
  213.     public static function AddBan($type, $value, $reason, $expireTime, $addedBy, $blockAppeal)
  214.     {
  215.         dbquery("INSERT INTO bans (id,bantype,value,reason,expire,added_by,added_date,appeal_state) VALUES (NULL,'" . $type . "','" . $value . "','" . $reason . "','" . $expireTime . "','" . $addedBy . "','" . date('d/m/Y H:i') . "','" . (($blockAppeal) ? '0' : '1') . "')");
  216.     }
  217.      public static function fixText($str, $quotes = true, $clean = false, $ltgt = false, $transform = false, $guestbook = false)
  218.     {
  219.         $str = str_replace("&Acirc;", "Â", $str);
  220.         $str = str_replace("¡", "¡", $str);
  221.         $str = str_replace("¿", "¿", $str);
  222.         $str = str_replace("í‘", "Ñ", $str);
  223.         $str = str_replace("ñ", "ñ", $str);
  224.         $str = str_replace("í", "Á", $str);
  225.         $str = str_replace("á", "á", $str);
  226.         $str = str_replace("í‰", "É", $str);
  227.         $str = str_replace("é", "é", $str);
  228.         $str = str_replace("í“", "Ó", $str);
  229.         $str = str_replace("ó", "ó", $str);
  230.         $str = str_replace("íš", "Ú", $str);
  231.         $str = str_replace("ú", "ú", $str);
  232.         $str = str_replace("í", "Í", $str);
  233.         $str = str_replace("ä", "ä", $str);
  234.         $str = str_replace("­", "", $str);
  235.         $str = str_replace("Ã", "í", $str);
  236.         $str = str_replace(")", "&#x29;", $str);
  237.         $str = str_replace("(", "&#x28;", $str);
  238.         $str = str_replace("Â¥", "¥", $str);
  239.         $str = str_replace("\\\\r\\\\n", "<br />", $str);
  240.         $str = str_replace("\\\\\\\\r\\\\\\\\n", "<br />", $str);
  241.         $str = str_replace("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'", "&apos;", $str);
  242.         $str = str_replace("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\&quot;", "&#x22;", $str);
  243.         $str = str_replace("\'", "'", $str);
  244.         $str = str_replace('\"', '"', $str);
  245.         $str = str_replace("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"", "&#x22;", $str);
  246.         $str = str_replace("\\\\\\\\\\\\\\\\r\\\\\\\\\\\\\\\\n", "<br />", $str);
  247.         $str = str_replace('\\\\n', "<br />", $str);
  248.         $str = str_replace('\\\\\\\\\\\\"', '"', $str);
  249.         $str = str_replace('\\\\r\\\\n', "<br />", $str);
  250.         $str = str_replace('\\\\\\\\r\\\\\\\\n', "<br />", $str);
  251.         $str = str_replace('\r\n', "<br />", $str);
  252.         $str = str_replace('\\', "", $str);
  253.        
  254.         if ($quotes) {
  255.             $str = str_replace('"', "&#x22;", $str);
  256.             $str = str_replace("'", "&apos;", $str);
  257.         }
  258.        
  259.        
  260.        
  261.         if ($clean) {
  262.             $str = str_replace("Ñ", "N", $str);
  263.             $str = str_replace("ñ", "n", $str);
  264.             $str = str_replace("Á", "A", $str);
  265.             $str = str_replace("á", "a", $str);
  266.             $str = str_replace("É", "E", $str);
  267.             $str = str_replace("é", "e", $str);
  268.             $str = str_replace("Ó", "O", $str);
  269.             $str = str_replace("ó", "o", $str);
  270.             $str = str_replace("Ú", "U", $str);
  271.             $str = str_replace("ú", "u", $str);
  272.             $str = str_replace("Í", "I", $str);
  273.             $str = str_replace("í", "i", $str);
  274.         }
  275.        
  276.         if ($ltgt) {
  277.             $str = str_replace("<", "&lt;", $str);
  278.             $str = str_replace(">", "&gt;", $str);
  279.         }
  280.        
  281.         if ($transform) {
  282.             $str = str_replace("'", '"', $str);
  283.         }
  284.        
  285.         if($guestbook) {
  286.             $str = str_replace("&lt;br /&gt;", '<br />', $str);
  287.             $str = str_replace("&lt;b&gt;", '<b>', $str);
  288.             $str = str_replace("&lt;/b&gt;", '</b>', $str);
  289.             $str = str_replace("&lt;u&gt;", '<u>', $str);
  290.             $str = str_replace("&lt;/u&gt;", '</u>', $str);
  291.             $str = str_replace("&lt;i&gt;", '<i>', $str);
  292.             $str = str_replace("&lt;/i&gt;", '</i>', $str);
  293.             $str = str_replace("&lt;/i&gt;", '<br />', $str);
  294.             $str = preg_replace("/\&lt;a href=\"(.*?)\"\&gt;(.*?)\&lt;\/a&gt;/is", "<a href=\"$1\" target=\"_blank\">$2</a>", $str);
  295.             $str = preg_replace("/\&lt;div class=\"bbcode-quote\"\&gt;(.*?)\&lt;\/div&gt;/is", "<div class=\"bbcode-quote\">$1</div>", $str);
  296.             $str = preg_replace("/\&lt;span style=\"(.*?)\"\&gt;(.*?)\&lt;\/span&gt;/is", "<span style=\"$1\">$2</span>", $str);
  297.             $str = preg_replace("/\&lt;span style=\"font-size: 14px\"\&gt;(.*?)\&lt;\/span&gt;/is", "<span style=\"font-size: 14px\">$1</span>", $str);
  298.         }
  299.        
  300.        
  301.        
  302.         return $str;
  303.     }
  304.    
  305.     public static function CheckComment($comment = '')
  306.     {
  307.         $comment = strtolower($comment);
  308.    
  309.         $denied  = array(
  310.             'puto',
  311.             'puta',
  312.             'mierda',
  313.             'aaaaaaaaaaaaaaaaaaaaaaaa',
  314.             'cabrones',
  315.             'http',
  316.             '.com',
  317.             '.org',
  318.             '.net',
  319.             '.info'
  320.         );
  321.         $allowed = array(
  322.             'youtube',
  323.             'facebook',
  324.             'xukys',
  325.             'google'
  326.         );
  327.        
  328.         foreach ($denied as $deny) {
  329.             if (strstr($comment, $deny)) {
  330.                 foreach ($allowed as $allow) {
  331.                     if (strstr($comment, $allow)) {
  332.                         return true;
  333.                     }
  334.                 }
  335.                
  336.                 uberCore::AddPermBan('user', $_SESSION['UBER_USER_N'], $comment);
  337.                 return false;
  338.             }
  339.            
  340.         }
  341.        
  342.         return true;
  343.     }
  344.    
  345.    
  346.    
  347.     public static function GenRandom()
  348.     {
  349.         return substr(md5(uniqid(rand())), 0, 15);
  350.     }
  351.    
  352.    
  353.     public static function BBcode($texto)
  354.     {
  355.         $texto = htmlentities($texto);
  356.         $a     = array(
  357.             "/\[i\](.*?)\[\/i\]/is",
  358.             "/\[b\](.*?)\[\/b\]/is",
  359.             "/\[u\](.*?)\[\/u\]/is",
  360.             "/\[quote\](.*?)\[\/quote\]/is",
  361.             "/\[url=(.*?)\](.*?)\[\/url\]/is",
  362.             "/\[color=red\](.*?)\[\/color\]/is",
  363.             "/\[color=orange\](.*?)\[\/color\]/is",
  364.             "/\[color=yellow\](.*?)\[\/color\]/is",
  365.             "/\[color=green\](.*?)\[\/color\]/is",
  366.             "/\[color=cyan\](.*?)\[\/color\]/is",
  367.             "/\[color=blue\](.*?)\[\/color\]/is",
  368.             "/\[color=gray\](.*?)\[\/color\]/is",
  369.             "/\[color=black\](.*?)\[\/color\]/is",
  370.             "/\[size=large\](.*?)\[\/size\]/is",
  371.             "/\[size=small\](.*?)\[\/size\]/is"
  372.         );
  373.         $b     = array(
  374.             "<i>$1</i>",
  375.             "<b>$1</b>",
  376.             "<u>$1</u>",
  377.             "<div class=\"bbcode-quote\">$1</div>",
  378.             "<a href=\"$1\" target=\"_blank\">$2</a>",
  379.             "<span style=\"color: #d80000\">$1</span>",
  380.             "<span style=\"color: #fe6301\">$1</span>",
  381.             "<span style=\"color: #ffce00\">$1</span>",
  382.             "<span style=\"color: #6cc800\">$1</span>",
  383.             "<span style=\"color: #00c6c4\">$1</span>",
  384.             "<span style=\"color: #0070d7\">$1</span>",
  385.             "<span style=\"color: #828282\">$1</span>",
  386.             "<span style=\"color: #000000\">$1</span>",
  387.             "<span style=\"font-size: 14px\">$1</span>",
  388.             "<span style=\"font-size: 9px\">$1</span>"
  389.         );
  390.         $texto = preg_replace($a, $b, $texto);
  391.         $texto = nl2br($texto);
  392.         return $texto;
  393.     }
  394.  
  395.     public static function GenerateRandom($length = 0, $letters = true, $numbers = false, $other = false)
  396.     {
  397.         $data = "";
  398.         $possible = "";
  399.         $i = 0;
  400.        
  401.         if($letters)
  402.         {
  403.             $possible .= "abcdefhijkl";
  404.         }
  405.        
  406.         if($numbers)
  407.         {
  408.             $possible .= "0123456789";
  409.         }
  410.        
  411.         if($other)
  412.         {
  413.             $possible .= "ABCDEFHIJKL@%&^*/(){}";
  414.         }
  415.        
  416.         while ($i < $length)
  417.         {
  418.             $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
  419.             $data .= $char;
  420.             $i++;
  421.         }
  422.         return $data;
  423.     }
  424. }
  425. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement