/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }