function message() { $BS = new Button("Nachricht", "comment_alt2_stroke", "iconicL"); $BS->style("float:left;"); $read = false; $message = $this->messageParser(); #$this->A("NuntiusMessage"); if ($this->A("NuntiusRead") > "0") { $read = true; $BS = new Button("Nachricht", "check", "iconicL"); $BS->style("float:left;color:darkgreen;"); $ex = explode("\n", $message); $message = "<span style=\"color:grey;\">" . $ex[0]; if (isset($ex[1])) { $message .= " …"; } $message .= "</span>"; } $from = ""; $ex = explode(":", $this->A("NuntiusSender")); if ($ex[0] == "Device") { $D = new Device($ex[1]); $from = $D->A("DeviceName"); } if ($ex[0] == "FritzBox") { $from = $this->A("NuntiusSender"); } if ($ex[0] == "Mobile") { $from = $this->A("NuntiusSender"); } return "\n\t\t\t<div id=\"Nuntius" . $this->getID() . "\" style=\"cursor:pointer;" . ($read ? "" : "background-color:#efefef;") . "min-height:40px;margin-bottom:10px;margin-top:10px;\" onclick=\"" . OnEvent::rme($this, "read", "", "function(t){ \$j('#Nuntius" . $this->getID() . "').replaceWith(t.responseText); fheOverview.loadContent('mNuntiusGUI::getOverviewContent'); }") . "\">\n\t\t\t\t{$BS}\n\t\t\t\t<div style=\"margin-left:40px;\" class=\"\">\n\t\t\t\t\t<p><small style=\"float:right;color:grey;\">Von {$from}, " . Util::CLDateTimeParser($this->A("NuntiusTime")) . "</small>" . nl2br($message) . "</p>\n\t\t\t\t</div>\n\t\t\t</div>"; }
/** * Determine if the device is Windows Phone. * * @param Device $device * @param UserAgent $userAgent * @return bool */ private static function checkWindowsPhone(Device $device, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'Windows Phone') !== false) { $device->setName($device::WINDOWS_PHONE); return true; } return false; }
/** * Determine if the device is Iphone. * * @return bool */ public function checkIphone() { if (stripos($this->userAgent->getUserAgentString(), 'iphone;') !== false) { $this->device->setName(Device::IPHONE); return true; } return false; }
/** * Get all devices */ public function fetchAll() { $devices = json_decode($this->dataProvider->get('devices')->getBody()->__toString()); foreach ($devices->devices as $deviceData) { $device = new Device($deviceData, $this->dataProvider); $this->devices[$device->getId()] = $device; } }
public function delete($id) { $data = array(); $device = new Device($id); $device->delete(); redirect("/", "refresh"); }
/** * Base test */ public function testBase() { $timestamp = time(); $tokenLength = 32; $deviceToken = str_repeat('14', 32); $data = pack('NnH*', $timestamp, $tokenLength, $deviceToken); $device = new Device($data); $this->assertEquals($timestamp, $device->getTimestamp()); $this->assertEquals($tokenLength, $device->getTokenLength()); $this->assertEquals($deviceToken, $device->getDeviceToken()); }
function get_config($id = '') { // MUST HAVE<input type='hidden' name='id' value=".$id."></input> // the name of the property must follow the conventions plugin_<Classname>_<propertyName> // have the form post and make sure the submit button is named widget_update // make sure there is also a hidden value giving the name of this Class file // Get defaults $subquery = "select device_id, enabled FROM plugin_SNMPPoller_devices"; $result2 = mysql_query($subquery); if (!$result2) { return "<b>Oops something went wrong, unable to read plugin_SNMPPoller_devices SQL table </b>"; } $devices = array(); while ($obj = mysql_fetch_object($result2)) { $devices[$obj->device_id] = $obj->enabled; } // Now we have the defaults in $devices; $content .= "<h1>Please select the Devices you would like to Monitor with the SNMP poller</h1>"; $content .= "<form id='configForm' method='post' name='edit_devices'>\r\n\t\t\t<input type='hidden' name='class' value='SNMPPoller'></input>\r\n\t\t\t<input type='hidden' name='id' value=" . $id . "></input> "; $select_all = "<input name='all' type='checkbox' value='Select All' onclick=\"checkAll(document.edit_devices['devices[]'],this)\""; #$content .= "<table border=1><tr><th>$select_all</th><th>Device</th><th>Device Type</th><th>Location</th></tr>"; $form = new Form("auto", 4); $keyHandlers = array(); $keyData = array(); $keyTitle = array(); foreach (Device::get_devices() as $id => $name) { if (array_key_exists($id, $devices) && $devices[$id] == 1) { $checked = "checked='yes'"; } else { $checked = ""; } $deviceInfo = new Device($id); array_push($keyData, "<input type=checkbox name=devices[] value='{$id}' {$checked} >"); array_push($keyData, $name); array_push($keyData, $deviceInfo->get_type_name()); array_push($keyData, $deviceInfo->get_location_name()); #$content .= "<tr><td><input type=checkbox name=devices[] value='$id' $checked ></td>"; #$content .= "<td>$name</td><td>". $deviceInfo->get_type_name() ."</td>"; #$content .= "<td>". $deviceInfo->get_location_name() ."</td></tr>"; } #$content .= "</table> <br>"; //get all the device and display them all in the 3 sections "Device Name", "Device Type", "Location". $heading = array($select_all, "Device Name", "Device Type", "Location "); $form->setSortable(true); // or false for not sortable $form->setHeadings($heading); $form->setEventHandler($handler); $form->setData($keyData); $form->setTableWidth("auto"); $content .= $form->showForm(); $content .= "<div style='clear:both;'></div><input type='submit' class='submitBut' name='plugin_update' value='Update configuration'/>\r\n\t\t\t</form> "; return "{$content}"; }
function device_controller() { global $session, $route, $mysqli, $user, $redis; $result = false; require_once "Modules/device/device_model.php"; $device = new Device($mysqli, $redis); if ($route->format == 'html') { if ($route->action == "view" && $session['write']) { $devices_templates = $device->get_templates(); $result = view("Modules/device/Views/device_view.php", array('devices_templates' => $devices_templates)); } if ($route->action == 'api') { $result = view("Modules/device/Views/device_api.php", array()); } } if ($route->format == 'json') { if ($route->action == 'list') { if ($session['userid'] > 0 && $session['write']) { $result = $device->get_list($session['userid']); } } elseif ($route->action == "create") { if ($session['userid'] > 0 && $session['write']) { $result = $device->create($session['userid']); } } elseif ($route->action == "listtemplates") { if ($session['userid'] > 0 && $session['write']) { $result = $device->get_templates(); } } else { $deviceid = (int) get('id'); if ($device->exist($deviceid)) { $deviceget = $device->get($deviceid); if (isset($session['write']) && $session['write'] && $session['userid'] > 0 && $deviceget['userid'] == $session['userid']) { if ($route->action == "get") { $result = $deviceget; } if ($route->action == "delete") { $result = $device->delete($deviceid); } if ($route->action == 'set') { $result = $device->set_fields($deviceid, get('fields')); } if ($route->action == 'inittemplate') { $result = $device->init_template($deviceid); } } } else { $result = array('success' => false, 'message' => 'Device does not exist'); } } } return array('content' => $result); }
public function testRegisterDeviceExisted() { Device::create($this->_params); $response = $this->_getResponse(); $this->assertTrue($this->client->getResponse()->isOk()); $this->assertEquals(json_encode(array("code" => ApiResponse::EXISTED_DEVICE, "data" => ApiResponse::getErrorContent(ApiResponse::EXISTED_DEVICE))), $response->getContent()); }
private function getDevice() { /*require_once(app_path().'/includes/ip.codehelper.io.php'); require_once(app_path().'/includes/php_fast_cache.php'); $_ip = new ip_codehelper(); $campusid = 0; $real_client_ip_address = $_ip->getRealIP(); $visitor_location = $_ip->getLocation($real_client_ip_address); $guest_ip = $visitor_location['IP']; $guest_country = $visitor_location['CountryName'];*/ $guest_ip = '0.0.0.0'; //get the ip address of the remote machine if (Session::has('my_ip')) { $guest_ip = Session::get('my_ip'); } else { $guest_ip = str_random(60); Session::put('my_ip', $guest_ip); } //check if the ip adress is in the devices table $device = Device::where('ip', '=', $guest_ip); if ($device->count()) { //redirect to the previous page $device = $device->first(); $campusid = $device->branch_id; return $campusid; } else { //redirect to country selection page and save it on selection return 0; } }
public function message_push_notification() { $input = $this->_getInput(); $device_token = "150F5252DBAF4FFA2F6FE07D84A14B0EA840C7C1FE595536B2787C724AF7EE4A"; $result = Device::message_push_notification(strtolower($device_token)); return Response::json($result); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $key = Input::get('key'); $deliverydate = Input::get('date'); $dev = \Device::where('key', '=', $key)->first(); $model = $this->model; $merchants = $model->where('group_id', '=', 4)->get(); //print_r($merchants); //die(); for ($n = 0; $n < count($merchants); $n++) { $or = new \stdClass(); foreach ($merchants[$n] as $k => $v) { $nk = $this->underscoreToCamelCase($k); $or->{$nk} = is_null($v) ? '' : $v; } $or->extId = $or->id; unset($or->id); //$or->boxList = $this->boxList('delivery_id',$or->deliveryId,$key); //$or->boxObjects = $this->boxList('delivery_id',$or->deliveryId, $key , true); $merchants[$n] = $or; } $actor = $key; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'logged out')); return $merchants; // }
public function getAll() { if (!isset($this->Elements) || $this->countElements() < 0) { return Device::getEmptyInstance(); } return $this->Elements; }
public function getOutput() { global $gvPath; $ip = $_SERVER['REMOTE_ADDR']; //Check whether the address is registered $device = Device::fromDatabaseByIpAddress($ip); if (!$device) { $page = new WebPageOutput(); $page->setHtmlPageTitle('Dispositivo non riconosciuto'); $page->addHtmlHeader('<meta http-equiv="refresh" content="5">'); $page->setHtmlBodyContent($this->getPageContentForUnknown($ip)); return $page; } if ((int) $device->getDeskNumber() === 0) { // DisplayMain $td_code = $device->getTdCode(); if ($td_code) { $td_code = "?td_code=" . urlencode($td_code); } else { $td_code = ''; } $redirect = new RedirectOutput("{$gvPath}/device/main{$td_code}"); return $redirect; } $num = $device->getDeskNumber(); $redirect = new RedirectOutput("{$gvPath}/device/desk?desk_number={$num}"); return $redirect; }
public function selectCampus($id) { $campusid = $id; $ipadress = $this->getIPAdress(); /*store the institutions id alongside the specific ip adress in the devices table * and redirect user to the specific homepage */ $exists = Device::where('ip', '=', $ipadress); if ($exists->count()) { $device = $exists->first(); $device->branch_id = $campusid; if ($device->save()) { if (Auth::user()) { return Redirect::route('member-home'); } else { return Redirect::route('home'); } } } else { $devicecreate = Device::create(array('ip' => $ipadress, 'branch_id' => $campusid)); if ($devicecreate) { if (Auth::user()) { return Redirect::route('member-home'); } else { return Redirect::route('home'); } } } return Redirect::route('selectcampus-get')->withInput()->with('global', 'Sorry!! Campus details were not loaded, please retry.'); }
function check_device_key($devicekey) { global $mysqli, $redis; include "Modules/device/device_model.php"; $device = new Device($mysqli, $redis); $session = $device->devicekey_session($devicekey); if (empty($session)) { header($_SERVER["SERVER_PROTOCOL"] . " 401 Unauthorized"); header('WWW-Authenticate: Bearer realm="Device KEY", error="invalid_devicekey", error_description="Invalid device key"'); print "Invalid device key"; $log = new EmonLogger(__FILE__); $log->error("Invalid device key '" . $devicekey . "'"); exit; } return $session; }
private function getTableBody() { global $gvPath; $devices = Device::fromDatabaseCompleteList(); if (count($devices) === 0) { return '<tr><td colspan="4" class="noEntry">Nessun dispositivo</td></tr>'; } $ret = ""; foreach ($devices as $device) { if ($device->getDeskNumber()) { $roleMsg = "Display spotello " . $device->getDeskNumber(); $tdText = ' '; } else { $roleMsg = "Display di sala"; if ($device->getTdCode()) { $tdText = $device->getTdCode(); } else { $tdText = 'Tutte'; } } $ret .= <<<EOS <tr> <td>{$device->getIpAddress()}</td> <td>{$roleMsg}</td> <td>{$tdText}</td> <td><a href="{$gvPath}/application/adminDeviceEdit?dev_id={$device->getId()}" class="tdEditLink">Modifica</a> <a class="ajaxRemove" href="{$gvPath}/ajax/removeRecord?dev_id={$device->getId()}">Rimuovi</a></td> </tr> EOS; } return $ret; }
public static function checkSessionId($input) { $device = Device::where('device_id', $input['device_id'])->where('session_id', $input['session_id'])->where('user_id', $input['user_id'])->first(); if (!empty($device)) { return $input['session_id']; } return false; }
private function getDevice() { $header = Request::header('Authorization'); preg_match('#^Bearer\\s+(.*?)$#', $header, $matches); $authToken = $matches[1]; $device = Device::where('auth_token', $authToken)->first(); return $device; }
private function getUserTokens($userId) { $tokens = array(); Device::where('user_id', $userId)->get()->each(function ($device) use(&$tokens) { $this->info("Tokens {$device->auth_token}"); $tokens[] = $device->auth_token; }); return $tokens; }
/** * Creates an object with the unique device ID $uid. This object can * then be added to the IP connection. * * @param string $uid */ public function __construct($uid, $ipcon) { parent::__construct($uid, $ipcon); $this->apiVersion = array(2, 0, 0); $this->responseExpected[self::FUNCTION_SET_VOLTAGE] = self::RESPONSE_EXPECTED_FALSE; $this->responseExpected[self::FUNCTION_GET_VOLTAGE] = self::RESPONSE_EXPECTED_ALWAYS_TRUE; $this->responseExpected[self::FUNCTION_SET_MODE] = self::RESPONSE_EXPECTED_FALSE; $this->responseExpected[self::FUNCTION_GET_MODE] = self::RESPONSE_EXPECTED_ALWAYS_TRUE; $this->responseExpected[self::FUNCTION_GET_IDENTITY] = self::RESPONSE_EXPECTED_ALWAYS_TRUE; }
public function transLoggerWithId($Module, $Description, $id) { if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'; } $deviceModel = new Device(); try { $dev = $deviceModel->getDeviceIdByUserId($id); } catch (Exception $ex) { $dev = 1; } $ip = filter_var($ip, FILTER_VALIDATE_IP); $ip = $ip === false ? '0.0.0.0' : $ip; DB::table('tbl_translog')->insert(array('trans_user_id' => $id, 'trans_deviceid' => $dev, 'trans_module' => $Module, 'trans_description' => $Description, 'trans_ip' => $ip)); }
public function execute() { global $gvPath; // Trim data $this->desk_number = trim($this->desk_number); $this->desk_ip_address = trim($this->desk_ip_address); // Data validation if ($this->desk_number === '' && $this->desk_ip_address === '') { $this->message = "Errore: tutti i campi sono obbligatori."; return true; } // desk_number should contain... numbers if (preg_match('/^[1-9][0-9]*$/', $this->desk_number) !== 1) { $this->message = "Errore: il numero dello sportello non è valido."; return true; } // Check ip_address if (!filter_var($this->desk_ip_address, FILTER_VALIDATE_IP)) { $this->message = "Errore: l'indirizzo IP non è valido."; return true; } $desk = Desk::fromDatabaseByNumber($this->desk_number); if ($desk && ($this->desk_id === 0 || $this->desk_id !== (int) $desk->getId())) { $this->message = "Errore: il numero sportello non è disponibile."; return true; } unset($desk); // Check ip is not taken $desk = Desk::fromDatabaseByIpAddress($this->desk_ip_address); $device = Device::fromDatabaseByIpAddress($this->desk_ip_address); if ($device || $desk && ($this->desk_id === 0 || $this->desk_id !== (int) $desk->getId())) { $this->message = "Errore: l'indirizzo IP è gia stato assegnato."; return true; } unset($desk); if ($this->desk_id === 0) { $desk = Desk::newRecord(); } else { $desk = Desk::fromDatabaseById($this->desk_id); } if ($desk->isOpen()) { $this->message = "Errore: il desk è aperto. Chiudere la sessione prima di continuare."; return true; } $desk->setNumber($this->desk_number); $desk->setIpAddress($this->desk_ip_address); if ($desk->save()) { gfSetDelayedMsg('Operazione effettuata correttamente', 'Ok'); $redirect = new RedirectOutput("{$gvPath}/application/adminDeskList"); return $redirect; } else { $this->message = "Impossibile salvare le modifiche. Ritentare in seguito."; return true; } }
public function getOwnerToken() { $token = null; if (isset($this->user_id) && (int) $this->user_id > 0) { $device = Device::whereIn('user_id', $this->user_id)->get()->first(); if ($device) { $token = $device->auth_token; } } return $token; }
public function show($deviceId) { $device = Device::with(array('users' => function ($query) { $query->where('device_user.user_id', '=', Auth::user()->id); }, 'heartbeats' => function ($query) { }))->where('id', '=', $deviceId)->whereNull('deleted_at')->first(); if (is_null($device)) { return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_NOTFOUND, array()); } return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_SUCCESS, $device); }
public function removeDevice() { $dev_id = $_GET['dev_id']; $device = Device::fromDatabaseById($dev_id); if ($device) { if ($device->delete()) { return 'true'; } } return 'false'; }
/** * Creates an object with the unique device ID $uid. This object can * then be added to the IP connection. * * @param string $uid */ public function __construct($uid, $ipcon) { parent::__construct($uid, $ipcon); $this->apiVersion = array(2, 0, 0); $this->responseExpected[self::FUNCTION_BEEP] = self::RESPONSE_EXPECTED_FALSE; $this->responseExpected[self::FUNCTION_MORSE_CODE] = self::RESPONSE_EXPECTED_FALSE; $this->responseExpected[self::CALLBACK_BEEP_FINISHED] = self::RESPONSE_EXPECTED_ALWAYS_FALSE; $this->responseExpected[self::CALLBACK_MORSE_CODE_FINISHED] = self::RESPONSE_EXPECTED_ALWAYS_FALSE; $this->responseExpected[self::FUNCTION_GET_IDENTITY] = self::RESPONSE_EXPECTED_ALWAYS_TRUE; $this->callbackWrappers[self::CALLBACK_BEEP_FINISHED] = 'callbackWrapperBeepFinished'; $this->callbackWrappers[self::CALLBACK_MORSE_CODE_FINISHED] = 'callbackWrapperMorseCodeFinished'; }
/** * Creates an object with the unique device ID $uid. This object can * then be added to the IP connection. * * @param string $uid */ public function __construct($uid, $ipcon) { parent::__construct($uid, $ipcon); $this->apiVersion = array(2, 0, 0); $this->responseExpected[self::FUNCTION_SET_STATE] = self::RESPONSE_EXPECTED_FALSE; $this->responseExpected[self::FUNCTION_GET_STATE] = self::RESPONSE_EXPECTED_ALWAYS_TRUE; $this->responseExpected[self::FUNCTION_SET_MONOFLOP] = self::RESPONSE_EXPECTED_FALSE; $this->responseExpected[self::FUNCTION_GET_MONOFLOP] = self::RESPONSE_EXPECTED_ALWAYS_TRUE; $this->responseExpected[self::CALLBACK_MONOFLOP_DONE] = self::RESPONSE_EXPECTED_ALWAYS_FALSE; $this->responseExpected[self::FUNCTION_SET_SELECTED_STATE] = self::RESPONSE_EXPECTED_FALSE; $this->responseExpected[self::FUNCTION_GET_IDENTITY] = self::RESPONSE_EXPECTED_ALWAYS_TRUE; $this->callbackWrappers[self::CALLBACK_MONOFLOP_DONE] = 'callbackWrapperMonoflopDone'; }
public function loginSocial() { $input = Input::all(); $user = User::where('facebook_id', $input['facebook_id'])->where('google_id', $input['google_id'])->first(); if (!$user) { $sessionId = generateRandomString(); $userId = User::create(['username' => $input['username'], 'facebook_id' => $input['facebook_id'], 'google_id' => $input['google_id'], 'status' => INACTIVE])->id; Device::create(['user_id' => $userId, 'session_id' => $sessionId, 'device_id' => $input['device_id']]); } else { $userId = $user->id; $sessionId = Common::getSessionId($input, $userId); } return Common::returnData(200, SUCCESS, $userId, $sessionId); }
public function beat() { $data = Input::all(); // return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_SUCCESS, $data['data']); if (is_null($data)) { return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_ERROR, array('item' => 'data')); } if (is_null($data['phone_imei'])) { return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_ERROR, array('item' => 'phone_imei')); } $heartbeat = new Heartbeat($data); $heartbeat->save(); $device = Device::with(array('users' => function ($query) { $query->where('device_user.user_id', '=', Auth::user()->id); }, 'heartbeats' => function ($query) { }))->where('hardware_id', '=', $data['phone_imei'])->whereNull('deleted_at')->get(); if (is_null($device)) { $device = new Device(array('name' => $data['phone_imei'], 'hardware_id' => $data['phone_imei'])); $device->save(); } $device->heartbeats()->attach($heartbeat); return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_SUCCESS, $device); }