From e22ab295443b7077166d117ec9fc538643ea1682 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 6 Dec 2015 17:05:19 +0100 Subject: [PATCH] Fix Issue #180 --- .../executeappswitchcommandajax.class.php | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100755 shc/data/commands/all/interface/executeappswitchcommandajax.class.php diff --git a/shc/data/commands/all/interface/executeappswitchcommandajax.class.php b/shc/data/commands/all/interface/executeappswitchcommandajax.class.php new file mode 100755 index 0000000..f7f80ba --- /dev/null +++ b/shc/data/commands/all/interface/executeappswitchcommandajax.class.php @@ -0,0 +1,181 @@ +disableAutoHtmlEndocde(); + + //Objekt und Befehl holen + $switchableId = RWF::getRequest()->getParam('sid', Request::GET, DataTypeUtil::INTEGER); + $switchable = SwitchableEditor::getInstance()->getElementById($switchableId); + $command = RWF::getRequest()->getParam('command', Request::GET, DataTypeUtil::INTEGER); + + //Benutzeranmeldung + $rwfUser = UserEditor::getInstance()->getGuest(); + if(RWF::getRequest()->issetParam('user', Request::GET) && RWF::getRequest()->issetParam('password', Request::GET)) { + + $userName = RWF::getRequest()->getParam('user', Request::GET, DataTypeUtil::PLAIN); + $password = RWF::getRequest()->getParam('password', Request::GET, DataTypeUtil::PLAIN); + + $user = UserEditor::getInstance()->getUserByName($userName); + if($user != null && $user->checkPasswordHash($password)) { + + $rwfUser = $user; + } + } + + //pruefen ob das schaltbare Element existiert + if(!$switchable instanceof Switchable) { + + $this->data = array( + 'success' => false, + 'message' => RWF::getLanguage()->get('index.room.error.id') + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } + + //pruefen ob deaktiviert + if(!$switchable->isEnabled()) { + + $this->data = array( + 'success' => false, + 'message' => RWF::getLanguage()->get('index.room.error.disabled') + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } + + //Berechtigungen Pruefen + if(!$switchable->isUserEntitled($rwfUser)) { + + $this->data = array( + 'success' => false, + 'message' => RWF::getLanguage()->get('index.room.error.premission') + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } + + try{ + + //je nach befehl schalten + if($command == 0) { + + $switchable->switchOff(); + } elseif($command == 1) { + + $switchable->switchOn(); + } elseif($command == 2) { + + $switchable->toggle(); + } else { + + //Fehler ungueltiger Befehl + $this->data = array( + 'success' => false, + 'message' => RWF::getLanguage()->get('index.room.error.command') + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } + } catch(\SoapFault $e) { + + //Fehler ungueltiger Befehl + $this->data = array( + 'success' => false, + 'message' => 'Fritz!Box Error: '. $e->getMessage() + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } + + //Befele Senden (nur Wake On lan sendet die Pakete direkt + if(!$switchable instanceof WakeOnLan && !$switchable instanceof AvmSocket && !$switchable instanceof FritzBox) { + + try { + + CommandSheduler::getInstance()->sendCommands(); + } catch (\Exception $e) { + + if ($e->getCode() == 1510) { + + //GPIO Schaltserver nicht errreicht + $this->data = array( + 'success' => false, + 'message' => RWF::getLanguage()->get('index.room.error.1510') + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } elseif ($e->getCode() == 1511) { + + //Schaltserver unterstuetzt kein GPIO schalten + $this->data = array( + 'success' => false, + 'message' => RWF::getLanguage()->get('index.room.error.1511') + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } elseif ($e->getCode() == 1512) { + + //kein Schaltserver erreichbar + $this->data = array( + 'success' => false, + 'message' => RWF::getLanguage()->get('index.room.error.1512') + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } + } + } + + //aktuellen Status speicherb + SwitchableEditor::getInstance()->updateState(); + + //schalten erfolgreich + $this->data = array( + 'success' => true + ); + RWF::getLanguage()->enableAutoHtmlEndocde(); + return; + } + +} \ No newline at end of file