Пример #1
0
 /**
  * @return string|\yii\web\Response
  */
 public function actionAdd()
 {
     $this->getView()->addBread('Add');
     $api = new Api();
     $api->userID = \Yii::$app->user->id;
     $api->timeCreated = time();
     if ($this->isPost() && $api->load($this->post())) {
         if ($api->save()) {
             return $this->redirect(['/api']);
         }
     }
     return $this->render('add', ['api' => $api]);
 }
Пример #2
0
 /**
  * Tracker update application
  *
  * 1. Check input
  * 2. Check auth
  * 3. Set current absence 
  * @return Response
  */
 function updateversion()
 {
     $attributes = Input::only('application');
     //1. Check input
     if (!$attributes['application']) {
         return Response::json('101', 200);
     }
     if (!isset($attributes['application']['api']['client']) || !isset($attributes['application']['api']['secret']) || !isset($attributes['application']['api']['tr_ver']) || !isset($attributes['application']['api']['station_id']) || !isset($attributes['application']['api']['email']) || !isset($attributes['application']['api']['password'])) {
         return Response::json('102', 200);
     }
     //2. Check auth
     $client = \App\Models\Api::client($attributes['application']['api']['client'])->secret($attributes['application']['api']['secret'])->workstationaddress($attributes['application']['api']['station_id'])->with(['branch'])->first();
     if (!$client) {
         $filename = storage_path() . '/logs/appid.log';
         $fh = fopen($filename, 'a+');
         $template = date('Y-m-d H:i:s : Login : '******'application']['api']) . "\n";
         fwrite($fh, $template);
         fclose($fh);
         return Response::json('402', 200);
     }
     //3. Set current absence
     if ((double) $attributes['application']['api']['tr_ver'] < (double) Config::get('current.absence.version')) {
         return Response::json('sukses|' . Config::get('current.absence.url1') . '|' . Config::get('current.absence.url2'), 200);
     }
     return Response::json('200', 200);
 }
Пример #3
0
 /**
  *
  */
 public function actionUpdate()
 {
     $aApi = Api::find()->all();
     foreach ($aApi as $mApi) {
         UpdaterAccountApi::update($mApi);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $apis = ['MailChimp', 'GetResponse', 'iContact', 'Infusionsoft', 'Madmimi', 'AWeber', 'Constant Contact'];
     foreach ($apis as $ap) {
         $api = Api::where('name', '=', $ap)->first();
         if (!$api) {
             Api::create(['name' => $ap]);
         }
     }
 }
 /**
  *
  */
 public function actionUpdate()
 {
     $aApi = Api::find()->all();
     foreach ($aApi as $mApi) {
         if ($mApi->characters) {
             foreach ($mApi->characters as $mCharacter) {
                 UpdaterCharacterMarketOrder::update($mApi->keyID, $mApi->vCode, $mCharacter->characterID);
             }
         }
     }
 }
Пример #6
0
 public function actionIndex()
 {
     $condition = [];
     $condition['status'] = 1;
     $query = Api::find()->where($condition);
     $query->orderBy('created_at DESC');
     $models = $query->all();
     $output = [];
     foreach ($models as $model) {
         $item = ['id' => $model->id, 'api_name' => $model->api_name, 'api_url' => $model->api_url, 'api_type' => $model->type, 'created_at' => $model->created_at ? date("Y-m-d H:i:s", $model->created_at) : ''];
         $output[] = $item;
     }
     return $this->render('index', ['list' => $output]);
 }
Пример #7
0
 /**
  * Tracker admin login
  *
  * 1. Check input
  * 2. Check auth
  * 3. Check tracker version
  * 4. Parsing data variable
  * 5. Check work auth
  * @return Response
  */
 function absence()
 {
     $attributes = Input::only('application');
     //1. Check input
     if (!$attributes['application']) {
         return Response::json('101', 200);
     }
     if (!isset($attributes['application']['api']['client']) || !isset($attributes['application']['api']['secret']) || !isset($attributes['application']['api']['tr_ver']) || !isset($attributes['application']['api']['station_id']) || !isset($attributes['application']['api']['email']) || !isset($attributes['application']['api']['password'])) {
         return Response::json('102', 200);
     }
     //2. Check auth
     $client = \App\Models\Api::client($attributes['application']['api']['client'])->secret($attributes['application']['api']['secret'])->workstationaddress($attributes['application']['api']['station_id'])->with(['branch'])->first();
     if (!$client) {
         $filename = storage_path() . '/logs/appid.log';
         $fh = fopen($filename, 'a+');
         $template = date('Y-m-d H:i:s : Login : '******'application']['api']) . "\n";
         fwrite($fh, $template);
         fclose($fh);
         return Response::json('402', 200);
     }
     //3. Check tracker version
     if (strtolower($attributes['application']['api']['tr_ver']) != $client['tr_version']) {
         $result->tr_version = strtolower($attributes['application']['api']['tr_ver']);
         if (!$result->save()) {
             return Response::json('301', 200);
         }
     }
     //4. Parsing data variable
     $organisationid = $content->data->branch->organisation_id;
     $email = $attributes['application']['api']['email'];
     $password = $attributes['application']['api']['password'];
     $check = Auth::attempt(['email' => $email, 'password' => $password]);
     //5. Check work auth
     if ($check) {
         $employee = \App\Models\Employee::id(Auth::user()['id'])->first();
         if (!$employee) {
             return Response::json('403', 200);
         }
         $workauth = \App\Models\WorkAuthentication::menuid(102)->workid($employee['work_id'])->organisationid($organisationid)->orderby('tmp_auth_group_id', 'asc')->first();
         if (!$workauth) {
             return Response::json('403', 200);
         } else {
             return Response::json('Sukses', 200);
         }
     } else {
         return Response::json('404', 200);
     }
     return Response::json('404', 200);
 }
Пример #8
0
 /** 
  * observe Api event saving
  * 1. unique workstation address
  * 2. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function saving($model)
 {
     $errors = new MessageBag();
     if (is_null($model->id)) {
         $id = 0;
     } else {
         $id = $model->id;
     }
     //1. unique workstation address
     $other_api = Api::address($model->workstation_address)->notid($id)->first();
     if ($other_api) {
         $errors->add('Api', 'Workstation ID sudah terdaftar');
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
Пример #9
0
 /**
  * Tracker check time
  *
  * 1. Check input
  * 2. Check auth
  * 3. Return current time
  * @return Response
  */
 function absencetime()
 {
     //1. Check input
     $attributes = Input::only('application');
     if (!$attributes['application']) {
         return Response::json('101', 200);
     }
     if (!isset($attributes['application']['api']['client']) || !isset($attributes['application']['api']['secret']) || !isset($attributes['application']['api']['tr_ver']) || !isset($attributes['application']['api']['station_id'])) {
         return Response::json('102', 200);
     }
     //2. Check auth
     $client = \App\Models\Api::client($attributes['application']['api']['client'])->secret($attributes['application']['api']['secret'])->workstationaddress($attributes['application']['api']['station_id'])->with(['branch'])->first();
     if (!$client) {
         $filename = storage_path() . '/logs/appid.log';
         $fh = fopen($filename, 'a+');
         $template = date('Y-m-d H:i:s : Test : ') . json_encode($attributes['application']['api']) . "\n";
         fwrite($fh, $template);
         fclose($fh);
         return Response::json('401', 200);
     }
     //3. Return current time
     $date = Carbon::now();
     return Response::json('sukses|' . $date->format('Y/m/d H:i:s'), 200);
 }
Пример #10
0
 public static function findByKey($key)
 {
     $user_id = Api::where('api_key', $key)->value('user_id');
     if ($user_id === null) {
         return;
     }
     return static::find($user_id);
 }
Пример #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getApi()
 {
     return $this->hasOne(Api::className(), ['id' => 'apiID']);
 }
Пример #12
0
 /**
  * Store logs
  *
  * 1. Check input
  * 2. Check auth
  * 3. Check tracker version
  * 4. Check data log
  * 5. Simpan data log
  * @return Response
  */
 public function store()
 {
     dd(Response::json('101', 200));
     $attributes = Input::only('application', 'log');
     //1. Check input
     if (!$attributes['application']) {
         return Response::json('101', 200);
     }
     if (!isset($attributes['application']['api']['client']) || !isset($attributes['application']['api']['secret']) || !isset($attributes['application']['api']['station_id'])) {
         return Response::json('102', 200);
     }
     //2. Check auth
     $results = \App\Models\Api::client($attributes['application']['api']['client'])->secret($attributes['application']['api']['secret'])->workstationaddress($attributes['application']['api']['station_id'])->with(['branch'])->first();
     if (!$results) {
         $filename = storage_path() . '/logs/appid.log';
         $fh = fopen($filename, 'a+');
         $template = date('Y-m-d H:i:s : Log : ') . json_encode($attributes['application']['api']) . "\n";
         fwrite($fh, $template);
         fclose($fh);
         return Response::json('402', 200);
     }
     //3. Check tracker version
     if (isset($attributes['application']['api']['tr_ver']) && strtolower($attributes['application']['api']['tr_ver']) != $result['tr_version']) {
         $result->tr_version = strtolower($attributes['application']['api']['tr_ver']);
         if (!$result->save()) {
             return Response::json('301', 200);
         }
     }
     $organisationid = $result->branch->organisation_id;
     //4. Check data log
     if (!$attributes['log']) {
         return Response::json('103', 200);
     }
     //5. Simpan data log
     DB::beginTransaction();
     if (isset($attributes['log'])) {
         $attributes['log'] = (array) $attributes['log'];
         foreach ($attributes['log'] as $key => $value) {
             $log['name'] = strtolower($value[1]);
             $log['on'] = date("Y-m-d H:i:s", strtotime($value[2]));
             $log['pc'] = $value[3];
             $person = \App\Models\Person::username($value[0])->first();
             //5a. check is log belongs to existed user
             if (!$person) {
                 //5b. store log to error if not
                 $log['email'] = $value[0];
                 $log['message'] = 'User tidak terdaftar';
                 $log['organisation_id'] = $organisationid;
                 $log['ip'] = $_SERVER['REMOTE_ADDR'];
                 $saved_error_log = new \App\Models\ErrorLog();
                 $saved_error_log->fill($log);
                 $saved_error_log->save();
             } else {
                 //5b. store log to log if yes
                 $log['person_id'] = $person['id'];
                 $saved_log = new \App\Models\Log();
                 $saved_log->fill($log);
                 if (!$saved_log->save()) {
                     $log['email'] = $value[0];
                     $log['message'] = json_encode($saved_log->getError());
                     $log['ip'] = $_SERVER['REMOTE_ADDR'];
                     $saved_error_log = new \App\Models\ErrorLog();
                     $saved_error_log->fill($log);
                     $saved_error_log->save();
                 }
             }
         }
     }
     DB::commit();
     return Response::json('Sukses', 200);
 }
Пример #13
0
 /**
  * boot
  * observing model
  *
  */
 public static function boot()
 {
     parent::boot();
     Api::observe(new ApiObserver());
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $UserObj = \Auth::user();
     $snip_data = Snips::join('snip_layouts', 'snip_layouts.snip_id', '=', 'snips.id')->where('snips.id', $id)->get()->toArray();
     $users = array();
     $users[''] = 'Select Profile';
     $users[\Auth::user()->id] = \Auth::user()->name;
     if (isset($snip_data[0])) {
         $snip_data = $snip_data[0];
     }
     $profile_arr = Profile::select('id', 'parent_id', 'child_name', 'child_pic')->where('id', $snip_data['user_id'])->get()->toArray();
     $child_profile = array('name' => '', 'url' => '', 'image' => "");
     foreach ($profile_arr as $key => $val) {
         $child_profile = array('name' => $val['child_name'], 'image' => "/images/profiles/" . $val['child_pic']);
     }
     $users_arr = Profile::select('id', 'parent_id', 'child_name')->where('parent_id', $UserObj->id)->get();
     foreach ($users_arr as $key => $val) {
         $users[$val->id] = $val->child_name;
     }
     $users['addprofile'] = 'Add Profile';
     $domains = array();
     $domains_arr = Domains::select('id', 'name')->get();
     foreach ($domains_arr as $key => $val) {
         $domains[$val->id] = $val->name;
     }
     $email_services = array();
     $email_services_arr = Api::select('id', 'name')->get();
     foreach ($email_services_arr as $key => $val) {
         $email_services[$val->id] = $val->name;
     }
     $feed_type = array('Page_url' => 'PAGE URL', 'RSS_feed' => 'RSS FEED URL', 'Trap.it feed' => 'Trap.it RSS FEED');
     $themes = array('Social' => 'Social', 'Candy' => 'Candy', 'Big-Candy' => 'Big Candy', 'Bean' => 'Bean', 'Full-Width' => 'Full Width');
     $position = array('Top_Left' => 'Top Left', 'Top_Right' => 'Top Right', 'Bottom_Left' => 'Bottom Left', 'Bottom_Right' => 'Bottom Right');
     $position_theme = 'bottom-left-div';
     if (isset($snip_data['position']) && $snip_data['position'] == 'Top_Left') {
         $position_theme = 'top-left-div';
     } elseif (isset($snip_data['position']) && $snip_data['position'] == 'Top_Right') {
         $position_theme = 'top-right-div';
     } elseif (isset($snip_data['position']) && $snip_data['position'] == 'Bottom_Left') {
         $position_theme = 'bottom-left-div';
     } elseif (isset($snip_data['position']) && $snip_data['position'] == 'Bottom_Right') {
         $position_theme = 'bottom-right-div';
     }
     $timestamp = time();
     $hash = md5('unique_salt' . $timestamp);
     $user_type = $UserObj->type;
     return view('link.edit')->with(compact('users', 'feed_type', 'themes', 'timestamp', 'hash', 'position', 'snip_data', 'domains', 'email_services', 'child_profile', 'position_theme', 'user_type'));
 }
 public function subscribe(Request $request)
 {
     $data = $request->all();
     $rules = ['growpage' => 'required|exists:relink_snips,id'];
     $this->validate($request, $rules);
     $growPage_item = ReLinkSnips::find($data['growpage']);
     $api = Api::find($growPage_item['api']);
     $service = UserService::where(['user_id' => $growPage_item['user_id'], 'api_id' => $growPage_item['api']])->first();
     $name = str_replace(' ', '', strtolower($api->name));
     $this->{$name}($service, $data['email']);
 }