source: admin/WebConsole/clases/SockHidra.php @ 3fef8e1

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 3fef8e1 was 5eae07e, checked in by alonso <alonso@…>, 15 years ago

primeros archivos de administración

git-svn-id: https://opengnsys.es/svn/trunk@539 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 4.6 KB
Line 
1<?php
2
3include_once("EncripDescrip.php");
4
5/*================================================================================
6        Clase para conectarse con el servidor hidra y enviar comandos
7        Cualquier error producido en los procesos se puede recuperar con los m�odos
8================================================================================*/
9class SockHidra{
10        var $ultimoerror;                               // Ultimo error detectado
11        var $descripultimoerror;                // Descripción del ltimo error detectado
12        var $socket;                                    // Stream socket
13        var $servidor;                                  // El servidor hidra
14        var $puerto;                                            // El puerto odnde se conectar�
15        var $timeout;                                   // El tiempo de espera para la conexi�
16        var $encripdescrip;     // El encriptador
17        var $LONGITUD_TRAMA; // M�ima longitud de la trama
18       
19        //________________________________________________________________________________________
20        //
21        //  Constructor
22        // Par�etros:
23        //      - servidor: El nombre o la IP del servidor
24        //      - puerto: El puerto usado para las comunicaciones
25        //      - timeout: El tiempo de espera para la conexi�
26        //________________________________________________________________________________________
27        function SockHidra($servidor,$puerto,$timeout=30){
28                $this->servidor=$servidor;
29                if (!$this->_esIP($this->servidor))
30                        $this->servidor = gethostbyname ($servidor);
31                $this->puerto=$puerto;
32                $this->timeout=$timeout;
33                $this->LONGITUD_TRAMA=4048;
34
35                $this->encripdescrip=new EncripDescrip();
36        }
37        //________________________________________________________________________________________
38        //
39        // Averigua si el parametro pasado es una IP. devuelve true en caso afirmativo
40        //________________________________________________________________________________________
41        function _esIP(){
42                return(false);
43        }
44        //________________________________________________________________________________________
45        //
46        //      Conecta con el servidor
47        //      Devuelve:
48        //              - false: Si falla la conexi�
49        //              - true: En caso contrario
50        //________________________________________________________________________________________
51        function conectar(){
52                $this->socket = socket_create (AF_INET, SOCK_STREAM, 0);
53                if ($this->socket < 0) {
54                        $this->ultimoerror=socket_strerror($socket);
55                        $this->descripultimoerror="socket_create() fallo";
56                        return(false);
57                }
58                $result = socket_connect ($this->socket,$this->servidor,$this->puerto);
59                if ($result < 0) {
60                        $this->ultimoerror=socket_strerror($result);
61                        $this->descripultimoerror="socket_connect() fallo";
62                        return(false);
63                }
64                return(true);
65        }
66        //________________________________________________________________________________________
67        //
68        //      Cerrar la conexióncon el servidor
69        //      Devuelve:
70        //              - false: Si falla la conexi�
71        //              - true: En caso contrario
72        //________________________________________________________________________________________
73        function desconectar(){
74                socket_close ($this->socket);
75        }
76        //________________________________________________________________________________________
77        //
78        //              Devuelve el c�igo del ltimo error ocurrido durante el proceso anterior.
79        //________________________________________________________________________________________
80        function UltimoError(){
81                return($this->ultimoerror);
82        }
83        //________________________________________________________________________________________
84        //
85        //              Devuelve una cadena con el mensage del ltimo error ocurrido durante el proceso anterior.
86        //________________________________________________________________________________________
87        function DescripUltimoError(){
88                return($this->descripultimoerror);
89        }
90        //________________________________________________________________________________________
91        //
92        //      Envia una trama de comando al servidor
93        //      Par�etros:
94        //              - trama: Trama a enviar
95        //________________________________________________________________________________________
96        function envia_comando($parametros){
97                $trama="@JMMLCAMDJ".$parametros;
98                $resul=socket_write($this->socket, $this->encripdescrip->Encriptar($trama), strlen($trama));
99                if (!$resul) {
100                        $this->ultimoerror=socket_strerror($resul);
101                        $this->descripultimoerror="socket_write() fallo";
102                        return(false);
103                }
104                return(true);
105        }
106        //________________________________________________________________________________________
107        //
108        //      Recibe una trama del servidor
109        //      Par�etros:
110        //              - lon: Longitud de la trama
111        // Devuelve:
112        //              La trama recibida
113        //________________________________________________________________________________________
114        function recibe_respuesta(){
115                $trama = socket_read ($this->socket,$this->LONGITUD_TRAMA);
116                $cadenaret=$this->encripdescrip->Desencriptar($trama);
117                return($cadenaret);
118        }
119 }
120?>
Note: See TracBrowser for help on using the repository browser.