예제 #1
0
 public function activate()
 {
     /*$ac = new anyC();
     		$ac->setCollectionOf("FhemPreset");
     		$ac->addJoinV3("FhemServer","FhemPresetServerID","=","FhemServerID");
     		$ac->addAssocV3("FhemPresetID", "=", $PresetID);
     		$S = $ac->getNextEntry();*/
     $S = new FhemServer($this->A("FhemPresetServerID"));
     switch ($S->A("FhemServerType")) {
         case "0":
             try {
                 $T = new Telnet($S->A("FhemServerIP"), $S->A("FhemServerPort"));
             } catch (NoServerConnectionException $e) {
                 die("error:'The connection to the server with IP-address " . $S->A("FhemServerIP") . " could not be established!'");
             }
             $c = "set " . $this->A("FhemPresetName") . " on";
             $T->fireAndForget($c);
             $T->disconnect();
             break;
         case "1":
             $ac = new anyC();
             $ac->setCollectionOf("FhemEvent");
             $ac->addAssocV3("FhemEventPresetID", "=", $this->ID);
             $ac->lCV3();
             while ($E = $ac->getNextEntry()) {
                 $S->setDevice($E->A("FhemEventFhemID"), $E->A("FhemEventAction"));
             }
             break;
     }
 }
예제 #2
0
 public function getTelnet()
 {
     if (!$this->_telnet instanceof Telnet) {
         $this->_telnet = Telnet::create($this);
     }
     return $this->_telnet;
 }
예제 #3
0
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" /> 
  <?php 
error_reporting(E_ERROR);
include "Telnet.php";
?>
</head>

<body>

<?php 
$requestMsg = $_POST['request'];
$responseMsg = 'Welcome';
try {
    $telnet = new Telnet('192.168.0.12', 4444);
    $telnet->setPrompt("\n");
    if (!isset($requestMsg)) {
        $requestMsg = "getStatus";
    }
    $responseMsg = $telnet->exec($requestMsg);
} catch (Exception $e) {
    $responseMsg = 'Exception: ' . $e->getMessage();
}
$responseMsg = str_replace("\r\n", '', $responseMsg);
?>

  <form action="" method="POST">
  <?php 
if ($responseMsg == "stopped") {
    ?>
예제 #4
0
 public function resetServers()
 {
     $S = new mFhemServerGUI();
     $t = new HTMLTable(2, "Telnet-Commands");
     while ($s = $S->getNextEntry()) {
         $T = new Telnet($s->getA()->FhemServerIP, $s->getA()->FhemServerPort);
         $T->fireAndForget("rereadcfg");
         $t->addRow(array($s->getA()->FhemServerIP, "rereadcfg"));
     }
     echo $t;
 }
예제 #5
0
 /**
  * notice,记录到日志,同时打印到telnet客户端(如果有telnet链接的话)
  * @param string $msg
  * @param bool $display
  */
 protected static function notice($msg, $display = false)
 {
     ServerLog::add("Server notice:" . $msg);
     Telnet::sendToAllClient($msg . "\n");
     if ($display) {
         if (self::$serverStatus == self::STATUS_STARTING) {
             echo $msg . "\n";
         }
     }
 }
예제 #6
0
 protected function _fixIt(Telnet $telnet)
 {
     switch ($this->_state) {
         case self::STATE_START:
             $this->_print('Changing folder...');
             $telnet->sendString('cd ' . self::FOLDER);
             $this->_state = self::STATE_IN_FOLDER;
             break;
         case self::STATE_IN_FOLDER:
             $telnet->sendString('pwd');
             $this->_state = self::STATE_FOLDER_CHECK;
             break;
         case self::STATE_FOLDER_CHECK:
             if (self::FOLDER != $this->_result) {
                 $msg = 'Couldn\'t change folder to ' . self::FOLDER;
                 $this->_print(CRLF . $msg, true);
                 $telnet->sendString('exit');
                 return;
             }
             $this->_print(' Ok', true);
             $this->_print('Checking ip_conntrack_max value...');
             $telnet->sendString('cat ip_conntrack_max');
             $this->_state = self::STATE_GET_VALUE;
             break;
         case self::STATE_GET_VALUE:
             $this->_print(' Ok', true);
             $msg = 'Current ip_conntrack_max value: ' . $this->_result;
             $this->_print($msg, true);
             /* Если желаемое значение уже установлено, */
             if ($this->_result == $this->_ip_conntrack_max) {
                 /* Выводим сообщение */
                 $msg = 'The desired value is already set.';
                 $this->_print($msg, true);
                 /* И успешно завершаем работу */
                 $telnet->sendString('exit');
                 $this->_state = self::STATE_FINISH;
                 return;
             }
             $this->_print('Fixing ip_conntrack_max value...');
             $cmd = 'echo ' . $this->_ip_conntrack_max . ' > ip_conntrack_max';
             $telnet->sendString($cmd);
             $this->_state = self::STATE_VALUE_SET;
             break;
         case self::STATE_VALUE_SET:
             $telnet->sendString('cat ip_conntrack_max');
             $this->_state = self::STATE_VALUE_IS_SET;
             break;
         case self::STATE_VALUE_IS_SET:
             if ($this->_result != $this->_ip_conntrack_max) {
                 $msg = 'Couldn\'t change value ' . $this->_result . ' to ' . $this->_ip_conntrack_max;
                 $this->_print(CRLF . $msg, true);
                 $telnet->sendString('exit');
                 return;
             }
             $this->_print(' Ok', true);
             $msg = 'Current ip_conntrack_max value: ' . $this->_ip_conntrack_max;
             $this->_print($msg, true);
             $telnet->sendString('exit');
             $this->_state = self::STATE_FINISH;
             break;
     }
 }
예제 #7
0
 /**
  * 关闭telnet链接
  */
 public static function close()
 {
     foreach (self::$connections as $con) {
         fclose($con);
     }
     self::$connections = array();
     self::$event->delAll(self::$bindSocket);
     @fclose(self::$bindSocket);
 }
예제 #8
0
 if ($DEBUG) {
     echo "<p>addData()";
 }
 $c = $_GET['channel'];
 $t = $_GET['temp'];
 $h = $_GET['humidity'];
 addData($c, $t, $h);
 $t10 = $t / 10;
 $thnames = array(1 => "THAussen", 2 => "THSchlaf", 3 => "THAndreas", 4 => "THBad");
 $thName = $thnames[$c];
 if ($useTelnet) {
     if ($DEBUG) {
         print "<br>### using telnet ###<br>";
     }
     //send data to fhem
     $telnet = new Telnet('192.168.0.40', 7072);
     $result = $telnet->connect();
     if ($DEBUG) {
         print "<br>telnet connect: " . $result . "<br>";
     }
     //lueften_ja berechnen und setzen
     if ($result) {
         $telnet->exec('setreading ' . $thName . ' T ' . $t10 . "\r\n", $result);
         // NOTE: $result may contain newlines
         if ($DEBUG) {
             print $result;
         }
         $telnet->exec('setreading ' . $thName . ' H ' . $h . "\r\n", $result);
         if ($DEBUG) {
             print '<br>setreading: ' . $result . '<br';
         }
예제 #9
0
 public function getListXML()
 {
     $T = new Telnet($this->A("FhemServerIP"), $this->A("FhemServerPort"));
     $T->setPrompt("</FHZINFO>");
     return $T->fireAndGet("xmllist") . "</FHZINFO>";
 }
예제 #10
0
 function ItemModelId($path)
 {
     /* find pol, sol and the type of item */
     list($pol_id, $sol_id, $rest) = sscanf($path, "/opt/xplico/pol_%d/sol_%d/%s");
     $type = strtok($rest, '/');
     /* set sol id and pol id to avoid error permision in the controller */
     $this->Session->write('pol', $pol_id);
     $this->Session->write('sol', $sol_id);
     /* controller and id */
     $control = null;
     $id = null;
     switch ($type) {
         case 'http':
             /* load model */
             $Feed = new Feed_xml();
             /* find id */
             $control = 'Feed_xml';
             $conditions = array('Feed_xml.rs_body' => $path);
             $param = array('recursive' => 0, 'fields' => array('Feed_xml.id'), 'conditions' => $conditions);
             $id = $Feed->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $Web = new Web();
                 /* find id */
                 $control = 'Web';
                 $conditions = array("or" => array('Web.rq_header' => $path, 'Web.rs_header' => $path, 'Web.rq_body' => $path, 'Web.rs_body' => $path));
                 $param = array('recursive' => 0, 'fields' => array('Web.id'), 'conditions' => $conditions);
                 $id = $Web->find('first', $param);
             }
             break;
         case 'fbwchat':
             /* load model */
             $Fbc = new Fbchat();
             /* find id */
             $control = 'Fbchat';
             $conditions = array('Fbchat.chat' => $path);
             $param = array('recursive' => 0, 'fields' => array('Fbchat.id'), 'conditions' => $conditions);
             $id = $Fbc->find('first', $param);
             break;
         case 'ftp':
             /* load model */
             $Ftp = new Ftp_file();
             /* find id */
             $control = 'Ftp_file';
             $conditions = array('Ftp_file.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Ftp_file.id'), 'conditions' => $conditions);
             $id = $Ftp->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $Ftp = new Ftp();
                 /* find id */
                 $control = 'Ftp';
                 $conditions = array('Ftp.cmd_path' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Ftp.id'), 'conditions' => $conditions);
                 $id = $Ftp->find('first', $param);
             }
             break;
         case 'ipp':
         case 'pjl':
             /* load model */
             $Pjl = new Pjl();
             /* find id */
             $control = 'Pjl';
             $conditions = array("or" => array('Pjl.pcl_path' => $path, 'Pjl.pdf_path' => $path));
             $param = array('recursive' => 0, 'fields' => array('Pjl.id'), 'conditions' => $conditions);
             $id = $Pjl->find('first', $param);
             break;
         case 'mail':
             /* load model */
             $Mail = new Email();
             /* find id */
             $control = 'Email';
             $conditions = array('Email.mime_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Email.id'), 'conditions' => $conditions);
             $id = $Mail->find('first', $param);
             break;
         case 'mms':
             /* load model */
             $Mms = new Mmscontent();
             /* find id */
             $control = 'Mmscontent';
             $conditions = array('Mmscontent.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Mmscontent.id'), 'conditions' => $conditions);
             $id = $Mms->find('first', $param);
             break;
         case 'nntp':
             /* load model */
             $Nntp = new Nntp_article();
             /* find id */
             $control = 'Nntp_article';
             $conditions = array('Nntp_article.mime_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Nntp_article.id'), 'conditions' => $conditions);
             $id = $Nntp->find('first', $param);
             break;
         case 'telnet':
             /* load model */
             $Teln = new Telnet();
             /* find id */
             $control = 'Telnet';
             $conditions = array('Telnet.cmd' => $path);
             $param = array('recursive' => 0, 'fields' => array('Telnet.id'), 'conditions' => $conditions);
             $id = $Teln->find('first', $param);
             break;
         case 'tftp':
             /* load model */
             $Tftp = new Tftp_file();
             $control = 'Tftp_file';
             $conditions = array('Tftp_file.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Tftp_file.id'), 'conditions' => $conditions);
             $id = $Tftp->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $Tftp = new Tftp();
                 /* find id */
                 $control = 'Tftp';
                 $conditions = array('Tftp.cmd_path' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Tftp.id'), 'conditions' => $conditions);
                 $id = $Tftp->find('first', $param);
             }
             break;
         case 'sip':
             /* load model */
             $mdl = new Sip();
             $control = 'sips';
             $conditions = array('Sip.commands' => $path);
             $param = array('recursive' => 0, 'fields' => array('Sip.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             if ($id == null) {
                 $conditions = array('Sip.ucaller' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Sip.id'), 'conditions' => $conditions);
                 $id = $mdl->find('first', $param);
                 if ($id == null) {
                     $conditions = array('Sip.ucalled' => $path);
                     $param = array('recursive' => 0, 'fields' => array('Sip.id'), 'conditions' => $conditions);
                     $id = $mdl->find('first', $param);
                 }
             }
             break;
         case 'webmail':
             /* load model */
             $mdl = new Webmail();
             $control = 'webmails';
             $conditions = array('Webmail.mime_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Webmail.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'httpfile':
             /* load model */
             $mdl = new Httpfile();
             $control = 'httpfile';
             $conditions = array('Httpfile.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Httpfile.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'grbudp':
             /* load model */
             $mdl = new Unknow();
             $control = 'unknows';
             $conditions = array('Unknow.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'grbtcp':
             /* load model */
             $mdl = new Unknow();
             $control = 'unknows';
             $conditions = array('Unknow.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'rtp':
             /* load model */
             $mdl = new Rtp();
             $control = 'rtps';
             $conditions = array('Rtp.ucaller' => $path);
             $param = array('recursive' => 0, 'fields' => array('Rtp.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             if ($id == null) {
                 $conditions = array('Rtp.ucalled' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Rtp.id'), 'conditions' => $conditions);
                 $id = $mdl->find('first', $param);
             }
             break;
         case 'irc':
             /* load model */
             $mdl = new Irc();
             $control = 'ircs';
             $conditions = array('Irc.cmd_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Irc.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $mdl = new Irc_channel();
                 $control = 'ircs';
                 $conditions = array('Irc_channel.channel_path' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Irc_channel.id'), 'conditions' => $conditions);
                 $id = $mdl->find('first', $param);
             }
             break;
         case 'paltalk_exp':
             /* load model */
             $mdl = new Paltalk_exp();
             $control = 'paltalk_exps';
             $conditions = array('Paltalk_exp.channel_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Paltalk_exp.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'paltalk':
             /* load model */
             $mdl = new Paltalk_room();
             $control = 'paltalk_rooms';
             $conditions = array('Paltalk_room.room_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Paltalk_room.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'msn':
             /* load model */
             $mdl = new Msn_chat();
             $control = 'msn_chats';
             $conditions = array('Msn_chat.chat_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Msn_chat.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
     }
     if ($id != null) {
         return array('model' => $control, 'id' => $id[$control]['id']);
     }
     return null;
 }