Example #1
1
File: home.php Project: sherdog/wnd
 /**
  * PAGE: index
  * This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
  */
 public function index()
 {
     $redirected = false;
     //check if there is an error
     if ($_GET['error'] != '') {
         //load error page!
         die("<h1>Whoops, something went wrong, you can refresh to see if it fixes it otherwise check back later.</h1>");
     }
     if (isset($_GET['appSource'])) {
         $redirected = true;
         $appSource = (int) $_GET['appSource'];
     }
     if (!$redirected) {
         if (isset($_GET['id']) && $_GET['id'] != "") {
             $extraParameters['id'] = $_GET['id'];
         }
         if (isset($_GET['fbSource'])) {
             $extraParameters['appSource'] = $_GET['appSource'];
         }
         if (isset($_GET['traffic_source']) && $_GET['traffic_source'] != '') {
             $extraParameters['traffic_source'] = $_GET['traffic_source'];
         }
     }
     $signedRequest = null;
     if (isset($_POST['signed_request'])) {
         $signedRequest = self::parseSignedRequest($_POST['signed_request']);
     }
     Log::add('Signed request: ' . $signedRequest);
     //check if user_id
     if ($signedRequest === null) {
         //we need to get one!
         $url = Config::get('facebook.appurl') . "?" . http_build_query($_GET);
         header("location: " . $url);
         exit;
     }
     if (!isset($signedRequest['user_id']) || $signedRequest['user_id'] == '') {
         $redirectUrl = self::buildUrl($extraParameters);
         $oAuthUrl = "https://www.facebook.com/dialog/oauth?";
         $oAuthUrl .= http_build_query(array_filter(array('client_id' => Config::Get('facebook.appid'), 'redirect_uri' => self::buildUrl($extraParameters), 'scope' => 'user_friends,email')));
         die("<script>top.location.href = '" . $oAuthUrl . "';</script>");
     }
     $fbCurlReq = new Curl();
     $fbCurlReq->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $fbCurlReq->get('https://graph.facebook.com/me?access_token=' . $signedRequest['oauth_token']);
     if ($fbCurlReq->error) {
         Log::add('Error fb user profile ' . $fbCurlReq->error_code . ': ' . $fbCurlReq->error_message);
     } else {
         $dataArray = $fbCurlReq->response;
     }
     Log::add('dataArray = ' . print_r($dataArray, true));
     //check too see if this is a post :)
     $game = new Game();
     $game->loadGame((array) $dataArray, 'facebook', $extraParameters);
 }
Example #2
0
 public static function add($type, $message, $sender = NULL)
 {
     if (is_null(self::$default_log)) {
         self::$default_log = new Logger_Blackhole();
     }
     if (!in_array($sender, Kohana::$config->load('logger')->ignored_senders)) {
         self::$default_log->add($type, $message, $sender);
     }
 }
Example #3
0
 public function index()
 {
     $this->_postLog->add('run', 'succ');
     for ($i = 0; $i < 100; $i++) {
         $this->_postLog->add('test', array("aaaasdsadsdasda", "adasdasdsadsa", "1213623213", "3213213"));
     }
     $this->_postLog->add('test', array("aaaasdsadsdasada", "adasdasdasadsa", "12136232a13", "321a3213"));
     echo 'aa';
 }
 /**
  * Logs with an arbitrary level.
  *
  * @param string  $level  a PSR LogLevel constant
  * @param string $message
  * @param array  $context
  *
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     $level = $this->convert_psr_to_kohana_level($level);
     if ($exception = $this->get_exception_from_context($context)) {
         $message .= \PHP_EOL . \Kohana_Exception::text($exception);
     } elseif ($message instanceof \Exception) {
         $context['exception'] = $message;
         $message = \Kohana_Exception::text($message);
     }
     $this->log->add($level, $message, array(), $context);
 }
Example #5
0
File: shop.php Project: sherdog/wnd
 public function getprice()
 {
     //we are going to get the item and return the required data to facebook.
     if (!$_POST['signed_request']) {
         Log::add('Signed request missing');
     }
     $req = Util::parseSignedRequest($_POST['signed_request']);
     $payment = $req['payment'];
     $product = $payment['product'];
     $quantity = $payment['quantity'];
     $currency = $payment['user_currency'];
     $requestID = $payment['request_id'];
     $method = $_POST['method'];
     $user = $req['user'];
     $country = $user['country'];
     $locale = $user['locale'];
     $age = $user['age']['min'];
     $facebookUserID = $req['user_id'];
     $itemID = substr(strrchr($product, '/'), 1);
     if (!$itemID) {
         Log::add('itemID was not found');
     }
     $storeModel = new StoreModel();
     $item = $storeModel->getItem($itemID);
     $return['content'] = array('product' => $product, 'amount' => $item->price / 100 * $quantity, 'currency' => $currency);
     $return['method'] = $method;
     $this->printJson($return);
 }
Example #6
0
 public function lives($playerID)
 {
     //we'll have a payload will have the hash key.
     Validate::player($playerID);
     Validate::payload($_POST['payload']);
     //so we passed the inital validation
     if ($_POST['payload'] == 'true') {
         $_POST['payload'] = Util::hashPost($_POST);
     }
     if (!$_POST) {
         throw new NInjaException("Error in request");
     }
     if (!$_POST['payload']) {
         throw new NinjaException("No data was received");
     }
     $data = str_replace(' ', '+', $_POST['payload']);
     $playerModel = new PlayerModel();
     if ($ack = $playerModel->collectGifts($playerID, $data)) {
         $response['status'] = 'ok';
         $response['value'] = $ack['lives'];
         $response['requests'] = $ack['requestCount'];
         $response['remaining'] = 0;
         //since we cap the # they can request to max lives of 8.
     } else {
         $response['status'] = 'error';
         $response['message'] = "error saving data";
         Log::add('Error updating lives');
     }
     $this->printJson($response);
 }
Example #7
0
 public function __construct($message, $code)
 {
     Log::add($message . 'URI: ' . $_SERVER['REQUEST_URI'], $code);
     if (!DEV) {
         switch ($code) {
             case 500:
                 Fw_Request::setGet('hard_controller', 'err');
                 Fw_Request::setGet('hard_action', 'error' . $code);
                 $error_app = new Application();
                 $error_app->run();
                 die;
                 break;
             case 404:
             default:
                 Fw_Request::setGet('hard_controller', 'err');
                 Fw_Request::setGet('hard_action', 'error' . $code);
                 $error_app = new Application();
                 $error_app->run();
                 die;
                 break;
         }
     }
     $code = 0;
     parent::__construct($message);
 }
Example #8
0
 public function deleteRequests($requests = array())
 {
     if (is_array($requests) && count($requests)) {
         Log::add('deleteRequests .. requests was array and has some.. the data was: ' . print_r($requests, true));
         $this->db->query('DELETE FROM player_gifts WHERE request_id IN ( ' . implode(',', $requests) . ') AND type = 2');
     } else {
         Log::add('Either requests was empty: ' . print_r($requests, true) . ' or it didnt have any: ' . count($requests));
     }
 }
Example #9
0
 public function loadClass($class_name)
 {
     if (file_exists(CLASS_PATH . $class_name . '.php')) {
         require CLASS_PATH . $class_name . '.php';
         return new $class_name();
     } else {
         Log::add("Errror loading class: " . $class_name . " - " . CLASS_PATH . $class_name . '.php');
     }
 }
Example #10
0
 private function confirm_query($query = "")
 {
     if (!$query) {
         $output = "Database Query Failed : " . mysqli_error($this->connection) . "\n";
         $output .= "\nLast Sql Query: " . $this->last_query . " Time: " . Database::date();
         Log::add($output, LOG_DB);
         die($output);
         return false;
     }
 }
Example #11
0
 public function checkAssetUpdate()
 {
     $this->db->select('asset_update_date');
     $this->db->from('game_settings');
     $this->db->where('id', 1);
     $query = $this->db->get();
     $row = $query->row();
     Log::add('Checking asset last update ' . $row->asset_update_date);
     return $row->asset_update_date;
 }
 public function get($index)
 {
     $temp = $this->memcache->get($index);
     if ($temp == array()) {
         //[DEBUG]
         if (defined('LOGX_DEBUG')) {
             Log::add('[' . __FILE__ . '] [' . __LINE__ . '] ' . L('_USE_ILLEGAL_INDEX_') . ' ' . $index, E_USER_NOTICE);
         }
         //[/DEBUG]
         return NULL;
     }
     return $temp;
 }
Example #13
0
File: http.php Project: pihizi/qf
 function &request($url, $timeout = 5)
 {
     $ch = curl_init();
     curl_setopt_array($ch, array(CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_URL => $url, CURLOPT_HEADER => TRUE, CURLOPT_AUTOREFERER => TRUE, CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_MAXREDIRS => 10, CURLOPT_CONNECTTIMEOUT => $timeout, CURLOPT_TIMEOUT => $timeout, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_FRESH_CONNECT => TRUE, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'] ?: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)', CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
     if ($this->_cookie_file) {
         curl_setopt_array($ch, array(CURLOPT_COOKIEFILE => $this->_cookie_file, CURLOPT_COOKIEJAR => $this->_cookie_file));
     }
     if ($this->_proxy) {
         curl_setopt_array($ch, array(CURLOPT_HTTPPROXYTUNNEL => TRUE, CURLOPT_PROXY => $this->_proxy, CURLOPT_PROXYTYPE => $this->_proxy_type));
     }
     if ($this->_header) {
         $curl_header = array();
         foreach ($this->_header as $k => $v) {
             $curl_header[] = $k . ': ' . $v;
         }
         curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header);
     }
     if ($this->_post) {
         curl_setopt($ch, CURLOPT_POST, TRUE);
         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->_post));
     }
     $data = curl_exec($ch);
     $this->clean();
     $errno = curl_errno($ch);
     if ($errno || !$data) {
         $err = curl_error($ch);
         Log::add("CURL ERROR({$errno} {$err}): {$url} ", 'error');
         curl_close($ch);
         return NULL;
     }
     $info = curl_getinfo($ch);
     curl_close($ch);
     $response = (object) [];
     $response->header = [];
     $response->body = NULL;
     $response->error = FALSE;
     list($header, $body) = explode("\n\n", str_replace("\r", "", $data), 2);
     $response = new HTTP_Response();
     $response->body = trim($body);
     $header = explode("\n", $header);
     $status = array_shift($header);
     $response->status = $info['http_code'];
     foreach ($header as $h) {
         list($k, $v) = explode(': ', $h, 2);
         if ($k) {
             $response->header[$k] = $v;
         }
     }
     return $response;
 }
Example #14
0
 public function delete()
 {
     $url = Registry::getUrl();
     $id = $_REQUEST["id"] ? $_REQUEST["id"] : $url->vars[0];
     $mosca = new Mosca($id);
     if ($mosca->id) {
         if ($mosca->delete()) {
             Registry::addMessage("Mosca eliminada satisfactoriamente", "success");
             //Log
             Log::add(LOG_DELETE_MOSCA, $mosca);
         }
     }
     Url::redirect(Url::site("moscas"));
 }
Example #15
0
 public function create($playerID)
 {
     Log::add('made it to incentive create');
     Validate::player($playerID);
     $hash = filter_input(INPUT_POST, "key");
     $type = filter_input(INPUT_POST, "incType");
     //for this to work, there has to be a player record with the last sessionID == hash
     $incentiveModel = new IncentiveModel();
     if ($incentiveModel->create($hash, $playerID, $type)) {
         $this->printJson(array('status' => 'ok', 'key' => $hash));
     } else {
         $this->printJson(array('status' => 'error'));
     }
 }
Example #16
0
 private static function dehashize($str)
 {
     Log::add("str = " . $str);
     $decodedStr = base64_decode($str);
     Log::add('decoded string: ' . $decodedStr);
     $chunks = explode("&", $decodedStr);
     Log::add('chunks value is: ' . print_r($chunks, true));
     $tmpObject = new StdClass();
     foreach ($chunks as $key => $val) {
         $chunksArr = explode('>', $val);
         $tmpObject->{$chunksArr[0]} = $chunksArr[1];
     }
     return $tmpObject;
 }
Example #17
0
 private function processPayment($objectID)
 {
     $playerModel = new PlayerModel();
     $storeModel = new StoreModel();
     $error = false;
     $newOrder = false;
     $graphUrl = sprintf('https://graph.facebook.com/%s?access_token=%s|%s', $objectID, Config::get('facebook.appid'), Config::get('facebook.appsecret'));
     $curl = new Curl();
     $curl->get($graphUrl);
     if ($curl->error) {
         Log::add('Error in requesting object ' . $curl->error_code . ' : ' . $curl->error_message);
         throw new NinjaException("Error Processing Request");
     }
     $res = $curl->response;
     $facebookID = $res->user->id;
     $playerArray = $playerModel->getPlayerIDFromUID($facebookID, null, false);
     $playerID = $playerArray[0];
     $orderDetails = $storeModel->addOrder($playerID, $objectID, $res);
     if ($res->actions[0]->status == 'completed') {
         $status = 'ok';
         Log::add('payment ok charged status is good');
     } else {
         if ($res->actions[0]->status == 'failed') {
             $error = true;
             $status = 'error';
             $message = 'Payment Declined';
             Log::add('Payment failed ' . print_r($res, true));
         } else {
             if ($res->actions[0]->status == 'initiated') {
                 $error = false;
                 Log::add('Payment failed ' . print_r($res, true));
             } else {
                 $error = true;
                 $status = 'error';
                 $message = 'User canceled payment';
             }
         }
     }
     //ANALYTICS
     if (!$error) {
         $array['status'] = 'ok';
         $array['player'] = $playerModel->getPlayerData($playerID);
         $array['order'] = $orderDetails;
         $this->printJson($array);
     } else {
         $array['status'] = 'error';
         $array['message'] = $message;
         $this->printJson($array);
     }
 }
Example #18
0
 /**
  * Adds a message to the log. Replacement values must be passed in to be
  * replaced using [strtr](http://php.net/strtr).
  *
  *     $log->add(Log::ERROR, 'Could not locate user: :user', array(
  *         ':user' => $username,
  *     ));
  *
  * @param   string  $level      level of message
  * @param   string  $message    message body
  * @param   array   $values     values to replace in the message
  * @return  Minion_Log
  */
 public function add($level, $message, array $values = NULL, array $additional = NULL)
 {
     parent::add($level, $message, $values, $additional);
     if (!empty($this->_on_add_writers)) {
         // Get the last message
         $msg = end($this->_messages);
         reset($this->_messages);
         foreach ($this->_on_add_writers as $writer) {
             if (empty($writer['levels']) or in_array($msg['level'], $writer['levels'])) {
                 $writer['object']->write(array($msg));
             }
         }
     }
     return $this;
 }
Example #19
0
 /**
  * Class constructor
  *
  * @param Log $log
  */
 public function __construct(Log $log)
 {
     if (!empty($this->data)) {
         return;
     }
     if (isset($log->geodata)) {
         $this->data = $log->geodata;
         return;
     }
     $ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
     if ($this->is_public_ip($ip)) {
         $this->data = $this->get_geodata($ip);
     }
     $log->add('geodata', $this->data);
 }
Example #20
0
 public static function hash($player, $key = null)
 {
     if ($key == null) {
         Log::add('Validating key failed');
         throw new NinjaException("Error Key Validation Failed");
         return false;
     }
     //create server key:
     $serverKey = md5(Config::get('salt') . $player->player_id . $player->uid);
     if ($key != $serverKey) {
         Log::add("Validating key failed did not match");
         throw new NinjaException("Error Key Validation Failed");
         return false;
     } else {
         return true;
     }
 }
Example #21
0
 public function writeControl()
 {
     $database = new Database();
     $query = "UPDATE " . self::$table;
     $this->high = abs($this->high);
     $this->low = -abs($this->low);
     $query .= " SET low_v = " . $this->low . " , high_v= " . $this->high . " , override=" . $this->override . " , over_value=" . $this->over_value;
     $query .= " WHERE sc_id=" . $this->sc_id;
     $run = $database->query($query);
     if ($run) {
         unset($database);
         return true;
     } else {
         Log::add("StockControl : Add to {$sc_id} : {$this->low},{$this->high},{$this->override},{$this->over_value} .", LOG_MANUAL);
         unset($database);
         return false;
     }
 }
Example #22
0
 public function connect($host, $user, $pwd, $dbname = false)
 {
     if (is_resource($this->conn)) {
         return $this->conn;
     }
     if (!($this->conn = @mysql_connect($host, $user, $pwd, TRUE))) {
         Log::add('mysql connect error : ' . mysql_error());
         return false;
     }
     // todo : i need some drawback compatibility :/ for now
     $GLOBALS['dbConn'] = $this->conn;
     $this->log('mysql connected to : ' . $host);
     $this->set_timezone();
     // set connection tz
     if ($dbname !== false) {
         return $this->select_db($dbname);
     }
     return $this->conn;
 }
Example #23
0
File: Util.php Project: sherdog/wnd
 public static function parseSignedRequest($signedRequest)
 {
     Log::add('parseSignedRequest:: ' . $signedRequest);
     list($encodedSig, $payload) = explode('.', $signedRequest, 2);
     // decode the data
     $sig = self::base64UrlDecode($encodedSig);
     $data = json_decode(self::base64UrlDecode($payload), true);
     Log::add('sign: ' . $sig);
     Log::add('data: ' . print_r($data, true));
     // confirm the signature
     $expectedSig = hash_hmac('sha256', $payload, Config::get('facebook.appsecret'), $raw = true);
     Log::add('expected sig: ' . $expectedSig);
     if ($sig !== $expectedSig) {
         Log::add('Bad signed JSON Signature');
         throw new NinjaException('Bad Signed JSON Signature!');
         return null;
     }
     return $data;
 }
Example #24
0
 public function remitAction()
 {
     if ($this->isAjax()) {
         $data = $this->request->getPost();
         $uid = $data['uid'];
         !$uid and $this->error('参数错误');
         $model = new LoanForm('remit');
         if ($result = $model->validate($data)) {
             if ($model->remit()) {
                 Log::add($uid, $this->getOperatorId(), \App\Config\Log::loanOperate('remit_certify'));
                 $this->success('操作成功');
             } else {
                 $this->error('操作失败');
             }
         } else {
             $this->error('验证失败');
         }
         exit;
     }
 }
 public static function query($sql, $cache = true, $unbuffer = false)
 {
     if ($cache && isset(self::$buffer[$sql])) {
         $query = self::$buffer[$sql];
     } else {
         $runtime = microtime(TRUE);
         if ($unbuffer && function_exists('mysql_unbuffered_query')) {
             $query = @mysql_unbuffered_query($sql, self::$link);
         } else {
             $query = self::$buffer[$sql] = @mysql_query($sql, self::$link);
         }
         $runtime = microtime(TRUE) - $runtime;
         //[DEBUG]
         if (defined('LOGX_DEBUG')) {
             Log::add('SQL: ' . $sql . ' TIME: ' . number_format($runtime, 4) * 1000 . 'ms.', E_USER_WARNING);
         }
         //[/DEBUG]
         self::$querynum++;
         self::$querytime += $runtime;
     }
     !$query && self::halt('SQL Error!', $sql);
     return $query;
 }
Example #26
0
<?php

/**
 * This class is useful for logging things. Use ::add to add a message, the microtime will be associated with it.
 *
 * This log lasts the duration of the request.
 */
class Log
{
    private static $log;
    /**
     * Add a message to the log.
     *
     * @param mixed $val Something to be logged with the microtime attached to it.
     */
    public static function add($val)
    {
        self::$log[] = array('time' => microtime(true), 'val' => $val);
    }
    /**
     * Gets the raw log.
     *
     * @return array An array of all of the things logged. Each item looks like this: array('time'=> 1231203.2322, 'val' => 'some log val') .
     */
    public static function getLog()
    {
        return self::$log;
    }
}
Log::add('Logging library loaded!');
Example #27
-1
 function &getInstance($param = false)
 {
     if ($param == false) {
         Log::add('used default urlamanager');
         if (!isset($GLOBALS["url_manager"]['default'])) {
             $GLOBALS["url_manager"]['default'] = new UrlManager();
         }
         return $GLOBALS["url_manager"]['default'];
     }
     if (!isset($GLOBALS["url_manager"][$param])) {
         $GLOBALS["url_manager"][$param] = new UrlManager();
     }
     return $GLOBALS["url_manager"][$param];
 }
Example #28
-2
 public function delete()
 {
     $url = Registry::getUrl();
     $id = $_REQUEST["id"] ? $_REQUEST["id"] : $url->vars[0];
     $entrada = new Entrada($id);
     if ($entrada->id) {
         if ($entrada->delete()) {
             Registry::addMessage("Entrada eliminada satisfactoriamente", "success");
             //Log
             Log::add(LOG_DELETE_ENTRADA, $entrada);
         }
     }
     Url::redirect(Url::site("entradas"));
 }
Example #29
-2
 /**
  * 确认放款
  */
 public function confirmAction($uid)
 {
     if ($this->isAjax()) {
         !$uid and $this->error('参数错误');
         if (Loan::updateStatus($uid, \App\LoanStatus::getStatusRunConfirm())) {
             Log::add($uid, $this->getOperatorId(), \App\Config\Log::loanOperate('runconfirm'));
             $this->success('操作成功');
         }
         $this->error('操作失败');
     }
     $loan = Loan::findByUid($uid);
     $user = User::findFirst($uid)->toArray();
     $this->view->setVars(['loan' => $loan, 'user' => $user]);
     $this->view->pick('run/detail');
 }
Example #30
-2
 public function select_db($dbname)
 {
     if (!@mysqli_select_db($dbname, $this->conn)) {
         Log::add('mysql select db error');
         Util::fatal('Cannot connect to the database server.');
         return false;
     }
     $this->log('mysql db selected ');
     // change charset for utf8 (or other if user config in another way)
     // connection with the server
     $charset = Get::cfg('db_charset', 'utf8');
     $this->query("SET NAMES '" . $charset . "'", $this->conn);
     $this->query("SET CHARACTER SET '" . $charset . "'", $this->conn);
     return true;
 }