예제 #1
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;
     }
 }