/** * Checks whether the server is up and running (accepting connections). * Will return true/false based on the server status. * * @return bool Returns true if server is running, false if not. * @access public */ public function isUp() { $addr = $this->config->getAddress(); $port = $this->config->getPort(); $sock = @fsockopen($addr, $port, $errno, $errstr, (int) Flux::config('ServerStatusTimeout')); if (is_resource($sock)) { fclose($sock); return true; } else { return false; } }
/** * Log the transaction details into the flux_paypal_transactions table. * * @param Flux_LoginAthenaGroup $servGroup * @param string $accountID * @param string $serverName * @access private */ private function logToPayPalTable(Flux_LoginAthenaGroup $servGroup, $accountID, $serverName, $trusted, $credits = 0) { if ($this->txnIsValid) { $holdUntil = null; if (!$trusted) { $email = $this->ipnVariables->get('payer_email'); $sql = "SELECT hold_until FROM {$servGroup->loginDatabase}.{$this->txnLogTable} "; $sql .= "WHERE account_id = ? AND payer_email = ? AND hold_until > NOW() AND payment_status = 'Completed' LIMIT 1"; $sth = $sth = $servGroup->connection->getStatement($sql); $sth->execute(array($accountID, $email)); $row = $sth->fetch(); if ($row && $row->hold_until) { $holdUntil = $row->hold_until; } else { $hours = +(int) Flux::config('HoldUntrustedAccount'); $holdUntil = date('Y-m-d H:i:s', time() + $hours * 60 * 60); } } $this->logPayPal('Saving transaction details to PayPal transactions table...'); $sql = "\n\t\t\t\tINSERT INTO {$servGroup->loginDatabase}.{$this->txnLogTable} (\n\t\t\t\t\taccount_id,\n\t\t\t\t\tserver_name,\n\t\t\t\t\tcredits,\n\t\t\t\t\treceiver_email,\n\t\t\t\t\titem_name,\n\t\t\t\t\titem_number,\n\t\t\t\t\tquantity,\n\t\t\t\t\tpayment_status,\n\t\t\t\t\tpending_reason,\n\t\t\t\t\tpayment_date,\n\t\t\t\t\tmc_gross,\n\t\t\t\t\tmc_fee,\n\t\t\t\t\ttax,\n\t\t\t\t\tmc_currency,\n\t\t\t\t\tparent_txn_id,\n\t\t\t\t\ttxn_id,\n\t\t\t\t\ttxn_type,\n\t\t\t\t\tfirst_name,\n\t\t\t\t\tlast_name,\n\t\t\t\t\taddress_street,\n\t\t\t\t\taddress_city,\n\t\t\t\t\taddress_state,\n\t\t\t\t\taddress_zip,\n\t\t\t\t\taddress_country,\n\t\t\t\t\taddress_status,\n\t\t\t\t\tpayer_email,\n\t\t\t\t\tpayer_status,\n\t\t\t\t\tpayment_type,\n\t\t\t\t\tnotify_version,\n\t\t\t\t\tverify_sign,\n\t\t\t\t\treferrer_id,\n\t\t\t\t\tprocess_date,\n\t\t\t\t\thold_until\n\t\t\t\t) VALUES (\n\t\t\t\t\t?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,\n\t\t\t\t\t?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(),\n\t\t\t\t\t?\n\t\t\t\t)\n\t\t\t"; $var = $this->ipnVariables; $sth = $servGroup->connection->getStatement($sql); $ret = $sth->execute(array($accountID, $serverName, $credits, $var->get('receiver_email'), $var->get('item_name'), $var->get('item_number'), $var->get('quantity'), $var->get('payment_status'), $var->get('pending_reason'), $var->get('payment_date'), $var->get('mc_gross'), $var->get('mc_fee'), $var->get('tax'), $var->get('mc_currency'), $var->get('parent_txn_id'), $var->get('txn_id'), $var->get('txn_type'), $var->get('first_name'), $var->get('last_name'), $var->get('address_street'), $var->get('address_city'), $var->get('address_state'), $var->get('address_zip'), $var->get('address_country'), $var->get('address_status'), $var->get('payer_email'), $var->get('payer_status'), $var->get('payment_type'), $var->get('notify_version'), $var->get('verify_sign'), $var->get('receiver_id'), $holdUntil)); if ($ret) { if (!trim($serverName)) { $serverName = '(unknown)'; } $this->logPayPal('Stored information in PayPal transactions table for server %s.', $serverName); } else { $errorInfo = implode('/', $sth->errorInfo()); $this->logPayPal('Failed to save information in PayPal transactions table. (%s)', $errorInfo); } } }
/** * Wrapper method for setting and getting values from the access config. * * @param string $key * @param mixed $value * @param arary $options * @access public */ public function config($key, $value = null, $options = array()) { if (!is_null($value)) { return $this->config->set($key, $value, $options); } else { return $this->config->get($key); } }
/** * */ public function reconnectAs($username, $password) { if ($this->pdoMain) { $this->pdoMain = null; } $this->dbConfig->setPersistent(false); $this->dbConfig->setUsername($username); $this->dbConfig->setPassword($password); return true; }
/** * Create a series of select fields matching a MySQL DATE format. * * @param string $name * @param string $value DATE formatted string. * @param int $fowardYears * @param int $backwardYears * @return string */ public function dateField($name, $value = null, $fowardYears = null, $backwardYears = null) { if (!isset($fowardYears)) { $fowardYears = (int) Flux::config('ForwardYears'); } if (!isset($backwardYears)) { $backwardYears = (int) Flux::config('BackwardYears'); } $ts = $value && !preg_match('/^0000-00-00(?: 00:00:00)?$/', $value) ? strtotime($value) : time(); $year = ($year = $this->params->get("{$name}_year")) ? $year : date('Y', $ts); $month = ($month = $this->params->get("{$name}_month")) ? $month : date('m', $ts); $day = ($day = $this->params->get("{$name}_day")) ? $day : date('d', $ts); $fw = $year + $fowardYears; $bw = $year - $backwardYears; // Get years. $years = sprintf('<select name="%s_year">', $name); for ($i = $fw; $i >= $bw; --$i) { if ($year == $i) { $years .= sprintf('<option value="%04d" selected="selected">%04d</option>', $i, $i); } else { $years .= sprintf('<option value="%04d">%04d</option>', $i, $i); } } $years .= '</select>'; // Get months. $months = sprintf('<select name="%s_month">', $name); for ($i = 1; $i <= 12; ++$i) { if ($month == $i) { $months .= sprintf('<option value="%02d" selected="selected">%02d</option>', $i, $i); } else { $months .= sprintf('<option value="%02d">%02d</option>', $i, $i); } } $months .= '</select>'; // Get days. $days = sprintf('<select name="%s_day">', $name); for ($i = 1; $i <= 31; ++$i) { if ($day == $i) { $days .= sprintf('<option value="%02d" selected="selected">%02d</option>', $i, $i); } else { $days .= sprintf('<option value="%02d">%02d</option>', $i, $i); } } $days .= '</select>'; return sprintf('<span class="date-field">%s-%s-%s</span>', $years, $months, $days); }
/** * Initialize char/map pair Flux_Athena pair. * * @param Flux_Connection $connection * @param Flux_Config $charMapConfig * @param Flux_LoginServer $loginServer * @param Flux_CharServer $charServer * @param Flux_MapServer $mapServer * @access public */ public function __construct(Flux_Config $charMapConfig, Flux_LoginServer $loginServer, Flux_CharServer $charServer, Flux_MapServer $mapServer) { $this->loginServer = $loginServer; $this->charServer = $charServer; $this->mapServer = $mapServer; $this->loginDatabase = $loginServer->config->getDatabase(); $this->serverName = $charMapConfig->getServerName(); $this->maxBaseLevel = (int) $charMapConfig->getMaxBaseLevel(); $this->expRates = $charMapConfig->getExpRates()->toArray(); $this->dropRates = $charMapConfig->getDropRates()->toArray(); $this->isRenewal = (bool) $charMapConfig->getRenewal(); $this->maxCharSlots = (int) $charMapConfig->getMaxCharSlots(); $this->dateTimezone = $charMapConfig->getDateTimezone(); $this->charMapDatabase = $charMapConfig->getDatabase(); $resetDenyMaps = $charMapConfig->getResetDenyMaps(); if (!$resetDenyMaps) { $this->resetDenyMaps = array('sec_pri'); } elseif (!is_array($resetDenyMaps)) { $this->resetDenyMaps = array($resetDenyMaps); } else { $this->resetDenyMaps = $resetDenyMaps->toArray(); } // Get WoE times specific in servers config. $woeDayTimes = $charMapConfig->getWoeDayTimes(); if ($woeDayTimes instanceof Flux_Config) { $woeDayTimes = $woeDayTimes->toArray(); foreach ($woeDayTimes as $dayTime) { if (!is_array($dayTime) || count($dayTime) < 4) { continue; } list($sDay, $sTime, $eDay, $eTime) = array_slice($dayTime, 0, 4); $sTime = trim($sTime); $eTime = trim($eTime); if ($sDay < 0 || $sDay > 6 || $eDay < 0 || $eDay > 6 || !preg_match('/^\\d{2}:\\d{2}$/', $sTime) || !preg_match('/^\\d{2}:\\d{2}$/', $eTime)) { continue; } $this->woeDayTimes[] = array('startingDay' => $sDay, 'startingTime' => $sTime, 'endingDay' => $eDay, 'endingTime' => $eTime); } } // Config used for disallowing access to certain modules during WoE. $woeDisallow = $charMapConfig->getWoeDisallow(); $_tempArray = array(); $this->woeDisallow = new Flux_Config($_tempArray); if ($woeDisallow instanceof Flux_Config) { $woeDisallow = $woeDisallow->toArray(); foreach ($woeDisallow as $disallow) { if (array_key_exists('module', $disallow)) { $module = $disallow['module']; if (array_key_exists('action', $disallow)) { $action = $disallow['action']; $this->woeDisallow->set("{$module}.{$action}", true); } else { $this->woeDisallow->set($module, true); } } } } }
/** * Parses a language configuration file, can also parse a language config * for any addon. * * @param string $addonName * @access public */ public static function parseLanguageConfigFile($addonName = null) { $default = $addonName ? FLUX_ADDON_DIR . "/{$addonName}/lang/en_us.php" : FLUX_LANG_DIR . '/en_us.php'; $current = $default; if ($lang = self::config('DefaultLanguage')) { $current = $addonName ? FLUX_ADDON_DIR . "/{$addonName}/lang/{$lang}.php" : FLUX_LANG_DIR . "/{$lang}.php"; } if (file_exists($default)) { $def = self::parseConfigFile($default); } else { $tmp = array(); $def = new Flux_Config($tmp); } if ($current != $default && file_exists($current)) { $cur = self::parseConfigFile($current); $def->merge($cur, false); } return $def; }
/** * Dispatch current request to the correct action and render the view. * * @param array $options Options for the dispatcher. * @access public */ public function dispatch($options = array()) { $config = new Flux_Config($options); $basePath = $config->get('basePath'); $paramsArr = $config->get('params'); $modulePath = $config->get('modulePath'); $themePath = $config->get('themePath'); $themeName = $config->get('themeName'); $defaultModule = $config->get('defaultModule'); $defaultAction = $config->get('defaultAction'); $missingActionModuleAction = $config->get('missingActionModuleAction'); $missingViewModuleAction = $config->get('missingViewModuleAction'); $useCleanUrls = $config->get('useCleanUrls'); if (!$defaultModule && $this->defaultModule) { $defaultModule = $this->defaultModule; } if (!$defaultAction && $this->defaultAction) { $defaultAction = $this->defaultAction; } if (!$defaultModule) { throw new Flux_Error('Please set the default module with $dispatcher->setDefaultModule()'); } elseif (!$defaultAction) { throw new Flux_Error('Please set the default action with $dispatcher->setDefaultAction()'); } if (!$paramsArr) { $paramsArr =& $_REQUEST; } // Provide easier access to parameters. $params = new Flux_Config($paramsArr); $baseURI = Flux::config('BaseURI'); if ($params->get('module')) { $safetyArr = array('..', '/', '\\'); $moduleName = str_replace($safetyArr, '', $params->get('module')); if ($params->get('action')) { $actionName = str_replace($safetyArr, '', $params->get('action')); } else { $actionName = $defaultAction; } } elseif (Flux::config('UseCleanUrls')) { $baseURI = preg_replace('&/+&', '/', rtrim($baseURI, '/')) . '/'; $requestURI = preg_replace('&/+&', '/', rtrim($_SERVER['REQUEST_URI'], '/')) . '/'; $requestURI = preg_replace('&\\?.*?$&', '', $requestURI); $components = explode('/', trim((string) substr($requestURI, strlen($baseURI)), '/')); $moduleName = empty($components[0]) ? $defaultModule : $components[0]; $actionName = empty($components[1]) ? $defaultAction : $components[1]; } elseif (!$params->get('module') && !$params->get('action')) { $moduleName = $defaultModule; $actionName = $defaultAction; } // Authorization handling. $auth = Flux_Authorization::getInstance(); if ($auth->actionAllowed($moduleName, $actionName) === false) { if (!Flux::$sessionData->isLoggedIn()) { Flux::$sessionData->setMessageData('Please log-in to continue.'); $this->loginRequired($baseURI); } else { $moduleName = 'unauthorized'; $actionName = $this->defaultAction; } } $params->set('module', $moduleName); $params->set('action', $actionName); $templateArray = array('params' => $params, 'basePath' => $basePath, 'modulePath' => $modulePath, 'moduleName' => $moduleName, 'themePath' => $themePath, 'themeName' => $themeName, 'actionName' => $actionName, 'viewName' => $actionName, 'headerName' => 'header', 'footerName' => 'footer', 'missingActionModuleAction' => $missingActionModuleAction, 'missingViewModuleAction' => $missingViewModuleAction, 'useCleanUrls' => $useCleanUrls); $templateConfig = new Flux_Config($templateArray); $template = new Flux_Template($templateConfig); // Default data available to all actions and views. $data = array('auth' => Flux_Authorization::getInstance(), 'session' => Flux::$sessionData, 'params' => $params); $template->setDefaultData($data); // Render template! :D $template->render(); }
/** * */ public function merge(Flux_Config $config, $recursive = true) { $mergeMethod = $recursive ? 'array_merge_recursive' : 'array_merge'; $this->configArr = $mergeMethod($this->configArr, $config->toArray()); }
/** * */ public function uploadShopItemImage($shopItemID, Flux_Config $file) { if ($file->get('error')) { return false; } $validexts = array_map('strtolower', Flux::config('ShopImageExtensions')->toArray()); $extension = strtolower(pathinfo($file->get('name'), PATHINFO_EXTENSION)); if (!in_array($extension, $validexts)) { return false; } $serverName = $this->server->loginAthenaGroup->serverName; $athenaServerName = $this->server->serverName; $dir = FLUX_DATA_DIR . "/itemshop/{$serverName}/{$athenaServerName}"; if (!is_dir(FLUX_DATA_DIR . "/itemshop/{$serverName}")) { mkdir(FLUX_DATA_DIR . "/itemshop/{$serverName}"); } if (!is_dir($dir)) { mkdir($dir); } $this->deleteShopItemImage($shopItemID); if (move_uploaded_file($file->get('tmp_name'), "{$dir}/{$shopItemID}.{$extension}")) { return true; } else { return false; } }