getUserById($this->request->getSession()->getAttribute('user_id')); $modelCamera = new ModelCamera(); $camera = $modelCamera->getCamera($this->request->getParameter('id'),$this->request->getSession()->getAttribute('user_id')); $headScript = ''; $this->generateView(array('camera' => $camera, 'headScript' => $headScript, 'user'=> $user)); } public function swapState() { $whereController = "default"; $whereAction = null; if($this->request->existParameter('whereController')) $whereController = $this->request->getParameter('whereController'); if($this->request->existParameter('whereAction')) $whereAction = $this->request->getParameter('whereAction'); if($this->request->existParameter('swap')) { $command = null; $modelUser = new ModelUser(); $modelCamera = new ModelCamera(); $camera = $modelCamera->getCamera($this->request->getParameter('id'),$this->request->getSession()->getAttribute('user_id')); $login = $this->request->getSession()->getAttribute('login'); $password = $modelUser->getUserById($this->request->getSession()->getAttribute('user_id'))->getPassword(); $swap = $this->request->getParameter('swap'); if($swap == 'enable' && $camera->getEnabled() == false) $command = "enable"; else if($swap == 'disable' && $camera->getEnabled() == true) $command = 'disable'; if($command != null) $this->sendCommand($login,$password,$camera->getId(),$command); } $this->redirect($whereController,$whereAction); } public function delete() { $modelUser = new ModelUser(); $modelUser->deleteCam($this->request->getSession()->getAttribute('user_id'),$this->request->getParameter('id')); $this->redirect('default','settings'); } private function sendCommand($login,$password,$camera_id,$command) { $s = socket_create(AF_INET,SOCK_STREAM,0); if($s == false) throw new Exception("Creation de socket echoue"); $addr = gethostbyname(Configuration::get('host')); if($addr == Configuration::get('host')) { socket_close($s); throw new Exception("Recuperation IP impossible "); } $result = socket_connect($s,$addr,40550); if($result == false) { socket_close($s); throw new Exception("Connection socket échoue"); } $str = $login.":".$password.":".$command.":".$camera_id; //Command = enable|disable|disconnect $buf = $str."\0"; $size = socket_write($s,$buf,strlen($str)+1); if($size != strlen($buf)) { socket_close($s); throw new Exception("Ecriture dans la socket impossible"); } $data = ""; $ret = socket_recv($s, $data, 1, MSG_WAITALL); while($ret == 1 && $data != "\0") { $buf .= $data; $data = ""; $ret = socket_recv($s, $data, 1, MSG_WAITALL); } if($ret != 1 && strlen($buf) == 0) { socket_close($s); throw new Exception('Erreur rien à lire dans la socket'); } socket_close($s); } public function delayed() { $videos = array(); $records_path = "Content/records/".$this->request->getParameter("id"); if(file_exists($records_path)) { $files = scandir($records_path); if($files != false) { $i = 0; foreach($files as $file) { $path = $records_path."/".$file; if(is_file($path)) { $regex_results = array(); if(preg_match("/^([0-9]|[1-9][0-9]*)_([0-9]|[1-9][0-9]*)\.mp4$/",$file,$regex_results) == 1) { $videos[$i]["path"] = $path; $videos[$i]["begin"] = date('j/n/Y H:i:s',$regex_results[1]); $videos[$i]["end"] = date('j/n/Y H:i:s',$regex_results[2]); $i++; } } } $headScript = ''; $this->generateView(array('videos' => $videos, 'headScript' => $headScript)); } else throw new Exception("Fichier '".$records_path."' inconnue"); } else throw new Exception("Dossier '".$records_path."' inconnue"); } }