public function __construct(Authorizer $authorizer)
 {
     parent::__construct($authorizer);
     $this->middleware('oauth', ['except' => 'store']);
     $this->middleware('disconnect:mongodb', ['only' => ['show', 'myComment']]);
     $this->middleware('oauth.checkClient', ['only' => 'store']);
 }
Пример #2
0
 public function __construct(Authorizer $authorizer)
 {
     parent::__construct($authorizer);
     $this->middleware('oauth', ['except' => 'store']);
     $this->middleware('disconnect:mongodb', ['only' => ['modify', 'notice', 'removeNotice']]);
     $this->middleware('oauth.checkClient', ['only' => 'store']);
     $this->middleware('validation');
 }
Пример #3
0
 public function __construct(Authorizer $authorizer)
 {
     parent::__construct($authorizer);
     $this->middleware('disconnect:sqlsrv', ['only' => ['report', 'index', 'show', 'search', 'moreArticle', 'myStar', 'team']]);
     $this->middleware('disconnect:sqlsrv2', ['only' => ['product']]);
     $this->middleware('disconnect:mongodb', ['only' => ['favour', 'show', 'commentList', 'myComment', 'myStar', 'myInformation']]);
     $this->middleware('oauth', ['except' => ['index', 'show', 'report', 'anonymousComment', 'anonymousReply', 'commentList', 'search', 'moreArticle', 'product', 'team']]);
     $this->middleware('validation');
 }
 public function __construct(Authorizer $authorizer)
 {
     parent::__construct($authorizer);
     $this->middleware('disconnect:sqlsrv', ['only' => ['comment', 'index', 'show', 'report', 'team']]);
     $this->middleware('disconnect:sqlserver', ['only' => ['product']]);
     $this->middleware('disconnect:mongodb', ['only' => ['comment', 'index', 'show', 'commentList', 'reply', 'favour', 'unfavour']]);
     $this->middleware('oauth', ['except' => ['index', 'show', 'report', 'commentList', 'product', 'report', 'team']]);
     $this->middleware('validation.required:content', ['only' => ['comment', 'reply']]);
 }
 public function __construct()
 {
     $this->middleware('auth');
     //获取导航
     $backNavs = Config::get('member-nav');
     $tree = new Tree($backNavs, 'parent_id', 'title');
     //$backNavs = $tree->getTreeView(1);
     View::share('tree', $tree);
     parent::__construct();
 }
 public function __construct(Authorizer $authorizer)
 {
     parent::__construct($authorizer);
     $this->middleware('oauth', ['except' => ['todo']]);
     $this->middleware('validation');
 }
Пример #7
0
 /**
  * Create a new controller instance.
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     //		$this->middleware('auth');
 }
Пример #8
0
 public function updateUser(Request $request)
 {
     $data = $request->all();
     $obj = new CommonController();
     DB::beginTransaction();
     try {
         $check = User::where(['USERNAME' => $data['username']])->get();
         if (count($check) > 0) {
             $user = new User();
             $user->USERNAME = $data['username'];
             $user->LAST_NAME = $data['lastname'];
             $user->MIDDLE_NAME = $data['middlename'];
             $user->FIRST_NAME = $data['firstname'];
             $user->EMAIL = $data['email'];
             $user->EXPIRE_DATE = date('Y/m/d', strtotime($data['expireDate']));
             $user->ACTIVE = $data['active'];
             User::where(['ID' => $data['ID']])->update(json_decode(json_encode($user), true));
             if ($data['pass'] != "") {
                 $pUser = new User();
                 $now = Carbon::now('Europe/London');
                 $pUser->PASSWORD_CHANGED = date('Y-m-d H:i:s', strtotime($now));
                 $pUser->PASSWORD = $obj->myencrypt($data['pass']);
                 \DB::enableQueryLog();
                 User::where(['ID' => $data['ID']])->update(json_decode(json_encode($pUser), true));
                 \Log::info(\DB::getQueryLog());
             }
             UserDataScope::where(['USER_ID' => $data['ID']])->delete();
             UserUserRole::where(['USER_ID' => $data['ID']])->delete();
             $userDataScope = new UserDataScope();
             $userDataScope->USER_ID = $data['ID'];
             $userDataScope->PU_ID = $data['pu_id'] == 0 ? null : $data['pu_id'];
             $userDataScope->AREA_ID = $data['area_id'] == 0 ? null : $data['area_id'];
             $userDataScope->FACILITY_ID = $data['fa_id'] == 0 ? null : $data['fa_id'];
             UserDataScope::insert(json_decode(json_encode($userDataScope), true));
             $roles = explode(',', $data['roles']);
             if (count($roles) > 0) {
                 foreach ($roles as $role) {
                     $userUserRole = new UserUserRole();
                     $userUserRole->USER_ID = $data['ID'];
                     $userUserRole->ROLE_ID = $role;
                     UserUserRole::insert(json_decode(json_encode($userUserRole), true));
                 }
             }
         }
     } catch (\Exception $e) {
         DB::rollback();
     }
     DB::commit();
     return response()->json(array('Message' => 'Update successfully'));
 }
 /**
  * Respond with values for corresponding rule
  * POST /extract-rule-engine
  *
  * @return Response
  */
 public function index()
 {
     //get mongo connection
     $mongoConnection = CommonController::getMongoConnection();
     //set log environment
     $this->setLogEnvironment();
     set_time_limit(0);
     ini_set('memory_limit', '800M');
     define('API_ID', 2);
     $invalid_hash = false;
     $auth_failed = true;
     $dataset_id = strip_tags(trim(Input::get('dataset_id', '')));
     $rule = strip_tags(trim(Input::get('rule', '')));
     $hash = trim(Input::get('hash', ''));
     $client_id = strip_tags(trim(Input::get('client_id', '')));
     $client_secret = trim(Input::get('client_secret', ''));
     if ($dataset_id != '' && $rule != '' && $client_id != '' && $client_secret != '') {
         if (env('RULE_ENGINE_API_DEV_MODE') != true) {
             //call oAuth server
             $url = url('auth');
             $post_param = array('api_id' => API_ID, 'client_id' => $client_id, 'client_secret' => $client_secret);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post_param);
             curl_setopt($ch, CURLOPT_HEADER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
             curl_setopt($ch, CURLOPT_NOBODY, false);
             // remove body
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
             $res = curl_exec($ch);
             curl_close($ch);
             $auth_response = json_decode($res, true);
             if (isset($auth_response['error']) && $auth_response['error'] == true) {
                 $data[0]['error'] = 'true';
                 $data[0]['message'] = $auth_response['message'];
                 return response()->json($data);
             } else {
                 if ($auth_response['authentication'] && $auth_response['authentication'] == true) {
                     $auth_failed = false;
                     $secret_key = $auth_response['api_secret_key'];
                     //calculate hash
                     $calculated_hash = md5($dataset_id . $rule . $client_id . $client_secret . $secret_key);
                     $invalid_hash = $hash === $calculated_hash ? false : true;
                 }
             }
         } else {
             $client_id = 1;
             $invalid_hash = false;
             $auth_failed = false;
         }
         if ($invalid_hash == false && $auth_failed == false) {
             // select a mongo database
             $mongodb = $mongoConnection->analytics_db;
             // select a mongo collection (analogous to a relational database's table)
             $collection = '';
             if ($dataset_id == 'email_dataset') {
                 $collection = $mongodb->usr_score_profile;
             } else {
                 if ($dataset_id == 'mobile_dataset') {
                     $collection = $mongodb->ph_score_profile;
                 } else {
                     if ($dataset_id == 'ph_zone') {
                         $collection = $mongodb->ph_zone;
                     }
                 }
             }
             $arrRules = explode(',', $rule);
             if ($collection != '' && !empty($arrRules)) {
                 foreach ($arrRules as $key => $value) {
                     $finalArrRules[] = "'" . $value . "'";
                 }
                 if (!empty($finalArrRules)) {
                     $ruleStringInput = implode(',', $finalArrRules);
                 }
                 //call API
                 $url = env('ANALYTICS_IN_API_HOST') . 'get_valid_rules.php';
                 $parameters = 'rule=' . $ruleStringInput . '&hash=' . md5($ruleStringInput . env('IN_ANALYTICS_API_SECRET_KEY'));
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $url);
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
                 curl_setopt($ch, CURLOPT_HEADER, false);
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                 curl_setopt($ch, CURLOPT_NOBODY, false);
                 // remove body
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                 $res = curl_exec($ch);
                 if ($res === false) {
                     echo curl_error($ch);
                 }
                 curl_close($ch);
                 $arrValidRules = json_decode($res, true);
                 if (!empty($arrValidRules)) {
                     $totalRuleArray = array();
                     $totalRuleArrayOr = array();
                     foreach ($arrValidRules as $key => $value) {
                         $cursorQueryCount = $collection->count(json_decode($value['rule'], true));
                         $data['rules'][$value['rule_secret']] = $cursorQueryCount;
                         $totalRuleArray = array_merge($this->getParsedArray(json_decode($value['rule'], true)), $totalRuleArray);
                         $totalRuleArrayOr[] = $this->getParsedArray(json_decode($value['rule'], true));
                     }
                     $orTotalQueryArray = array('$or' => $totalRuleArrayOr);
                     //get any rule data count
                     $cursorAnyRuleCount = $collection->count($orTotalQueryArray);
                     //get total data count
                     $cursorTotalCount = $collection->count();
                     //get all rule data count
                     $cursorAllRuleCount = $collection->count($totalRuleArray);
                     $data['total_count'] = $cursorTotalCount;
                     $data['any_rule_count'] = $cursorAnyRuleCount;
                     $data['all_rule_count'] = $cursorAllRuleCount;
                 } else {
                     //Invalid rule given
                     $data['error'] = 'true';
                     $data['message'] = 'Error 004: ' . Config::get('constant.api_error.004');
                 }
             } else {
                 //Invalid rule given
                 $data['error'] = 'true';
                 $data['message'] = 'Error 004: ' . Config::get('constant.api_error.004');
             }
         } else {
             //Authentication failed
             $data['error'] = 'true';
             $data['message'] = $invalid_hash == true ? 'Error 012: ' . Config::get('constant.api_error.012') : 'Error 008: ' . Config::get('constant.api_error.008');
         }
     } else {
         //Invalid parameters
         $data['error'] = 'true';
         $data['message'] = 'Error 011: ' . Config::get('constant.api_error.011');
     }
     if (isset($data['error'])) {
         //log
         $logArray = array($client_id, $client_secret, $hash, $data['message'], date('Y-m-d H:i:s'));
         Log::info('Extract Rule Engine API Log', $logArray);
     }
     //set content-type : application-json and send response with the json encoded data.
     return response()->json($data);
 }
 /**
  * Respond with values corresponding to identifier and rule combination
  * POST /rule-engine
  *
  * @return Response
  */
 public function index()
 {
     //get mongo connection
     $mongoConnection = CommonController::getMongoConnection();
     //set log environment
     $this->setLogEnvironment();
     set_time_limit(0);
     ini_set('memory_limit', '1000M');
     define('API_ID', 1);
     $invalid_hash = false;
     $auth_failed = true;
     try {
         $identifier = strip_tags(trim(Input::get('identifier', '')));
         $rule = strip_tags(trim(Input::get('rule', '')));
         $hash = trim(Input::get('hash', ''));
         $client_id = strip_tags(trim(Input::get('client_id', '')));
         $client_secret = trim(Input::get('client_secret', ''));
         if ($identifier != '' && $client_id != '' && $rule != '' && $client_secret != '') {
             if (env('RULE_ENGINE_API_DEV_MODE') != true) {
                 //call oAuth server
                 $url = url('auth');
                 $post_param = array('api_id' => API_ID, 'client_id' => $client_id, 'client_secret' => $client_secret);
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $url);
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_param);
                 curl_setopt($ch, CURLOPT_HEADER, false);
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                 curl_setopt($ch, CURLOPT_NOBODY, false);
                 // remove body
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                 $res = curl_exec($ch);
                 curl_close($ch);
                 $auth_response = json_decode($res, true);
                 if (isset($auth_response['error']) && $auth_response['error'] == true) {
                     $data['error'] = 'true';
                     $data['message'] = $auth_response['message'];
                     return response()->json($data);
                 } else {
                     if ($auth_response['authentication'] && $auth_response['authentication'] == true) {
                         $auth_failed = false;
                         $secret_key = $auth_response['api_secret_key'];
                         $arrClientData['hits'] = isset($auth_response['hits']) ? $auth_response['hits'] : '';
                         $arrClientData['hits_count'] = isset($auth_response['hits_count']) ? $auth_response['hits_count'] : 0;
                         //user profile id
                         $user_profile = $auth_response['user_profile'];
                         //calculate hash
                         $calculated_hash = md5($rule . $identifier . $client_id . $client_secret . $secret_key);
                         $invalid_hash = $hash === $calculated_hash ? false : true;
                         //$invalid_hash = (1==1) ? false : true;
                     }
                 }
             } else {
                 $client_id = 1;
                 $invalid_hash = false;
                 $auth_failed = false;
                 $arrClientData['hits'] = '';
                 $user_profile = 3;
             }
             if ($invalid_hash == false && $auth_failed == false) {
                 if ($identifier != '') {
                     $arrIdentifier = explode(',', $identifier);
                     $identifierCount = 0;
                     if (is_numeric(trim($arrIdentifier[0]))) {
                         foreach ($arrIdentifier as $key => $value) {
                             if (strlen(trim($value)) == 10 && is_numeric(trim($value)) && $identifierCount <= Config::get('constant.max_identifier_allowed')) {
                                 $finalArrIdentifierInputPlain[] = trim($value);
                                 //$finalArrIdentifierInputQuoted[] = "'".trim($value)."'";
                                 $identifierCount++;
                             }
                         }
                     } else {
                         foreach ($arrIdentifier as $key => $value) {
                             if (!filter_var(trim($value), FILTER_VALIDATE_EMAIL) === false && $identifierCount <= Config::get('constant.max_identifier_allowed')) {
                                 $finalArrIdentifierInputPlain[] = trim($value);
                                 //$finalArrIdentifierInputQuoted[] = "'".trim($value)."'";
                                 $identifierCount++;
                             }
                         }
                     }
                     ###################################################################################
                     if (!empty($finalArrIdentifierInputPlain)) {
                         if ($rule != '') {
                             $arrRules = explode(',', $rule);
                             $ruleCount = 0;
                             foreach ($arrRules as $key => $value) {
                                 if ($ruleCount <= Config::get('constant.max_rule_allowed')) {
                                     $finalArrRules[] = trim($value);
                                 }
                                 $ruleCount++;
                             }
                             if (!empty($finalArrRules)) {
                                 $ruleStringInput = implode(',', $finalArrRules);
                             }
                             ###################################################################################
                             if (!empty($finalArrRules)) {
                                 try {
                                     //call API
                                     // $url = env('ANALYTICS_IN_API_HOST').'get_valid_rules.php';
                                     // //$parameters = 'rule='.$ruleStringInput.'&hash='.md5($ruleStringInput.env('IN_ANALYTICS_API_SECRET_KEY'));
                                     // $parameters = array('rule' => $ruleStringInput,'hash' => md5($ruleStringInput.env('IN_ANALYTICS_API_SECRET_KEY')));
                                     // $ch = curl_init();
                                     // curl_setopt($ch, CURLOPT_URL, $url);
                                     // curl_setopt($ch, CURLOPT_POST, 1);
                                     // curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
                                     // curl_setopt($ch, CURLOPT_HEADER, false);
                                     // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                                     // curl_setopt($ch, CURLOPT_NOBODY, false); // remove body
                                     // curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                                     // $res = curl_exec($ch);
                                     $res = $this->getValidRules($finalArrRules, $client_id, $user_profile);
                                     if ($res == '') {
                                         $data['error'] = 'true';
                                         $data['message'] = 'Error 013: ' . Config::get('constant.api_error.013');
                                         return response()->json($data);
                                     }
                                     $arrValidRules = $res;
                                     ######################################################################
                                     if (!empty($arrValidRules)) {
                                         $arrRuleSecret_RuleName = $this->getRuleSecret_RuleName($arrValidRules);
                                         $arrConditionRule = array('phoneNumber' => 1, '_id' => 0);
                                         foreach ($arrValidRules as $key => $rule) {
                                             $ruleCondition = array($rule['rule_secret'] => array('$cond' => array($this->getParsedArray(json_decode($rule['aggregate_rule'], true)), true, false)));
                                             $arrConditionRule = array_merge($arrConditionRule, $ruleCondition);
                                         }
                                         $database_name = $rule['database_name'];
                                         //check if the identifiers are present in database or not
                                         // select a collection (analogous to a relational database's table)
                                         $collection = $mongoConnection->selectCollection(env('MONGO_DATABASE'), $database_name);
                                         $arrCondition = array('$project' => $arrConditionRule);
                                         $mongoData = $collection->aggregate(array('$match' => array('phoneNumber' => array('$in' => $finalArrIdentifierInputPlain))), $arrCondition);
                                         //mongo result data
                                         $mongoData = $mongoData['result'];
                                         //if nothing found from mongo
                                         if (empty($mongoData)) {
                                             $data['error'] = 'true';
                                             $data['message'] = 'Error 014: ' . Config::get('constant.api_error.014');
                                             return response()->json($data);
                                         }
                                         //get result data in dezired format
                                         foreach ($mongoData as $key => $value) {
                                             $phoneNumber = $value['phoneNumber'];
                                             unset($value['phoneNumber']);
                                             foreach ($value as $rule_secret => $rule_value) {
                                                 if ($rule_value == true) {
                                                     $temp[$rule_secret]['rule_name'] = $arrRuleSecret_RuleName[$rule_secret];
                                                     $temp[$rule_secret]['value'] = 'true';
                                                 } else {
                                                     $temp[$rule_secret]['rule_name'] = $arrRuleSecret_RuleName[$rule_secret];
                                                     $temp[$rule_secret]['value'] = 'false';
                                                 }
                                             }
                                             $finalizedMongoData[$phoneNumber] = $temp;
                                             unset($temp);
                                         }
                                         //get NA identifiers
                                         foreach ($finalArrIdentifierInputPlain as $key => $value) {
                                             if (!array_key_exists($value, $finalizedMongoData)) {
                                                 $arrNAIdentifiers[] = $value;
                                             }
                                         }
                                         //add NA identifiers into final data
                                         if (isset($arrNAIdentifiers) && !empty($arrNAIdentifiers)) {
                                             foreach ($arrNAIdentifiers as $identifier) {
                                                 $temp[$identifier] = array();
                                                 foreach ($arrValidRules as $rule) {
                                                     $temp[$identifier][$rule['rule_secret']]['value'] = 'NA';
                                                     $temp[$identifier][$rule['rule_secret']]['rule_name'] = $rule['rule_name'];
                                                     $finalizedMongoData = array_merge($finalizedMongoData, $temp);
                                                 }
                                             }
                                         }
                                         $data = $finalizedMongoData;
                                         //increase user hit count
                                         if ($arrClientData['hits'] != '' || $arrClientData['hits'] != null) {
                                             $api_client = App\ApiClient::where('client_id', $client_id)->where('api_id', API_ID)->first();
                                             $api_client->hits_count = $arrClientData['hits_count'] + 1;
                                             $api_client->update();
                                         }
                                         if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
                                             $ip = $_SERVER['HTTP_CLIENT_IP'];
                                         } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                                             $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
                                         } else {
                                             $ip = $_SERVER['REMOTE_ADDR'];
                                         }
                                         foreach ($arrValidRules as $key => $value) {
                                             $param = array('rule_id' => $value['rule_secret'], 'client_id' => $client_id, 'response' => '', 'client_ip' => $ip, 'uid_count' => count($arrIdentifier), 'uid_type' => is_numeric(trim($arrIdentifier[0])) ? 'mobile' : 'email', 'api_id' => API_ID, 'added_on' => date('Y-m-d H:i:s'));
                                             //insert transaction data
                                             App\ApiTransaction::insert($param);
                                         }
                                     } else {
                                         //No valid email or rule found
                                         $data['error'] = 'true';
                                         $data['message'] = 'Error 002: ' . Config::get('constant.api_error.002');
                                     }
                                 } catch (PDOException $e) {
                                     //No valid email or rule found
                                     $data['error'] = 'true';
                                     $data['message'] = 'Error 005: ' . Config::get('constant.api_error.005');
                                 }
                             } else {
                                 $data['error'] = 'true';
                                 $data['message'] = 'Error 004: ' . Config::get('constant.api_error.004');
                             }
                         } else {
                             $data['error'] = 'true';
                             $data['message'] = 'Error 004: ' . Config::get('constant.api_error.004');
                         }
                     } else {
                         $data['error'] = 'true';
                         $data['message'] = 'Error 007: ' . Config::get('constant.api_error.007');
                     }
                 } else {
                     //Invalid identifier
                     $data['error'] = 'true';
                     $data['message'] = 'Error 007: ' . Config::get('constant.api_error.007');
                 }
             } else {
                 //Authentication failed
                 $data['error'] = 'true';
                 $data['message'] = $invalid_hash == true ? 'Error 012: ' . Config::get('constant.api_error.012') : 'Error 008: ' . Config::get('constant.api_error.008');
             }
         } else {
             //Invalid parameters
             $data['error'] = 'true';
             $data['message'] = 'Error 011: ' . Config::get('constant.api_error.011');
         }
     } catch (Exception $e) {
         //Something went wrong
         $data['error'] = 'true';
         $data['message'] = 'Error 010: ' . Config::get('constant.api_error.010');
     }
     if (isset($data['error'])) {
         //log
         $logArray = array($client_id, $client_secret, $hash, $data['message'], date('Y-m-d H:i:s'));
         Log::info('Rule Engine API Log', $logArray);
     }
     //set content-type : application-json and send response with the json encoded data.
     return response()->json($data);
 }