1 | <? |
---|
2 | // ************************************************************************************************************************************************* |
---|
3 | // Aplicación WEB: ogAdmWebCon |
---|
4 | // Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla |
---|
5 | // Fecha Creación: Año 2009-2010 |
---|
6 | // Fecha Última modificación: Agosto-2010 |
---|
7 | // Nombre del fichero: incorporaordenadores.php |
---|
8 | // Descripción : |
---|
9 | // Da de alta en la base de datos nuevos ordenadores desde un fichero de configuración dhcp |
---|
10 | // ************************************************************************************************************************************************* |
---|
11 | include_once("../includes/ctrlacc.php"); |
---|
12 | include_once("../clases/AdoPhp.php"); |
---|
13 | include_once("../includes/CreaComando.php"); |
---|
14 | include_once("../idiomas/php/".$idioma."/incorporaordenadores_".$idioma.".php"); |
---|
15 | //________________________________________________________________________________________________________ |
---|
16 | $cmd=CreaComando($cadenaconexion); |
---|
17 | if (!$cmd) |
---|
18 | Header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D. |
---|
19 | //___________________________________________________________________________________________________ |
---|
20 | $swf=0; |
---|
21 | $idaula=0; |
---|
22 | $nombreaula=""; |
---|
23 | $contenido=""; |
---|
24 | |
---|
25 | if (isset($_GET["idaula"])) $idaula=$_GET["idaula"]; |
---|
26 | if (isset($_GET["nombreaula"])) $nombreaula=$_GET["nombreaula"]; |
---|
27 | |
---|
28 | if (isset($_POST["swf"])) $swf=$_POST["swf"]; // Recoge parametros |
---|
29 | if (isset($_POST["contenido"])) $contenido=$_POST["contenido"]; |
---|
30 | if (isset($_POST["idaula"])) $idaula=$_POST["idaula"]; |
---|
31 | if (isset($_POST["nombreaula"])) $nombreaula=$_POST["nombreaula"]; |
---|
32 | |
---|
33 | $resul=0; |
---|
34 | $ordDup=""; |
---|
35 | |
---|
36 | if(!empty($contenido)){ // Se ha introducido contenido en lugar de fichero |
---|
37 | $resul=procesaLineas($cmd,$idaula,$contenido); |
---|
38 | } |
---|
39 | //___________________________________________________________________________________________________ |
---|
40 | ?> |
---|
41 | <HTML> |
---|
42 | <TITLE>Administración web de aulas</TITLE> |
---|
43 | <HEAD> |
---|
44 | <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
45 | <LINK rel="stylesheet" type="text/css" href="../estilos.css"> |
---|
46 | </HEAD> |
---|
47 | <BODY> |
---|
48 | <FORM action="incorporaordenadores.php" method="post" name="fdatos"> |
---|
49 | <INPUT type=hidden name=swf value=1> |
---|
50 | <INPUT type=hidden name=idaula value=<?echo $idaula?>> |
---|
51 | <INPUT type=hidden name=nombreaula value=<?echo $nombreaula?>> |
---|
52 | <BR> |
---|
53 | <P align=center class=cabeceras><?echo $TbMsg[0]?><BR> |
---|
54 | <SPAN align=center class=subcabeceras><IMG src="../images/iconos/aula.gif"> <?echo $TbMsg[1].":".$nombreaula ?></SPAN></P> |
---|
55 | <!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> |
---|
56 | <table align=center class=tabla_datos border="0" cellpadding="0" cellspacing="1"> |
---|
57 | <!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> |
---|
58 | <tr> |
---|
59 | <th> <? echo $TbMsg[2]?> </th> |
---|
60 | <td><textarea class="cajatexto" name="contenido" cols="70" rows="18"></textarea></td></tr> |
---|
61 | <!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> |
---|
62 | </TABLE> |
---|
63 | </FORM> |
---|
64 | <TABLE align=center> |
---|
65 | <TR> |
---|
66 | <TD><IMG src="../images/boton_cancelar.gif" style="cursor:hand" onclick=""></TD> |
---|
67 | <TD width=20></TD> |
---|
68 | <TD><IMG src="../images/boton_confirmar.gif" style="cursor:hand" onclick="javascript:document.fdatos.submit();"></TD> |
---|
69 | </TR> |
---|
70 | </TABLE> |
---|
71 | <? |
---|
72 | //________________________________________________________________________________________________________ |
---|
73 | // Mensaje con el resultado del proceso |
---|
74 | echo '<SCRIPT LANGUAGE="javascript">'; |
---|
75 | if (!empty($resul)) |
---|
76 | echo " alert('".$TbMsg[$resul]."');"; |
---|
77 | if (!empty($ordDup)) |
---|
78 | echo " alert('".$TbMsg[5]."\\n".$ordDup."');"; |
---|
79 | echo '</SCRIPT>'; |
---|
80 | //________________________________________________________________________________________________________ |
---|
81 | ?> |
---|
82 | </BODY> |
---|
83 | </HTML> |
---|
84 | <? |
---|
85 | // ************************************************************************************************************************************************* |
---|
86 | function procesaLineas($cmd,$idaula,$buffer) |
---|
87 | { |
---|
88 | $nombre=""; |
---|
89 | $MAC=""; |
---|
90 | $IP=""; |
---|
91 | $sw=false; |
---|
92 | $posa=-1; |
---|
93 | |
---|
94 | while($posa<strlen($buffer)){ |
---|
95 | if ('host'==substr($buffer,$posa,4)){ |
---|
96 | $posa=$posa+4; |
---|
97 | $posb=$posa; |
---|
98 | while( substr($buffer,$posb,1)!="{") $posb++; |
---|
99 | $nombre=substr($buffer,$posa,$posb-$posa); |
---|
100 | } |
---|
101 | if ('hardware ethernet'==substr($buffer,$posa,17)){ |
---|
102 | $posa=$posa+17; |
---|
103 | $posb=$posa; |
---|
104 | while( substr($buffer,$posb,1)!=";") $posb++; |
---|
105 | $MAC=substr($buffer,$posa,$posb-$posa); |
---|
106 | } |
---|
107 | |
---|
108 | if ('fixed-address'==substr($buffer,$posa,13)){ |
---|
109 | $posa=$posa+13; |
---|
110 | $posb=$posa; |
---|
111 | while( substr($buffer,$posb,1)!=";") $posb++; |
---|
112 | $IP=substr($buffer,$posa,$posb-$posa); |
---|
113 | } |
---|
114 | if(!empty($nombre) && !empty($MAC) && !empty($IP)){ |
---|
115 | if(!Inserta($cmd,$idaula,$nombre,$MAC,$IP)) return(4); |
---|
116 | $sw=true; |
---|
117 | $nombre=""; |
---|
118 | $MAC=""; |
---|
119 | $IP=""; |
---|
120 | $resul=true; |
---|
121 | } |
---|
122 | $posa++; |
---|
123 | } |
---|
124 | if($sw) |
---|
125 | return(3); |
---|
126 | else |
---|
127 | return(4); |
---|
128 | |
---|
129 | } |
---|
130 | //________________________________________________________________________________________________________ |
---|
131 | function Inserta($cmd,$idaula,$nombre,$lamac,$laip) |
---|
132 | { |
---|
133 | global $ordDup; |
---|
134 | |
---|
135 | $grupoid=0; |
---|
136 | $nombreordenador=trim($nombre); |
---|
137 | $ip=trim($laip); |
---|
138 | $auxmac=trim($lamac); |
---|
139 | $mac=""; |
---|
140 | for($i=0;$i<strlen($auxmac);$i++) |
---|
141 | if(substr($auxmac,$i,1)!=":") |
---|
142 | $mac.=substr($auxmac,$i,1); |
---|
143 | |
---|
144 | if(existeOrdenador($cmd,$nombreordenador,$mac,$ip)){ |
---|
145 | $ordDup.="Nombre=".$nombre.",Mac=".$mac.",Dirección ip=".$ip." \\n"; |
---|
146 | return(true); |
---|
147 | } |
---|
148 | $idperfilhard=0; |
---|
149 | $idrepositorio=0; |
---|
150 | $idconfiguracion=0; |
---|
151 | $cmd->CreaParametro("@grupoid",$grupoid,1); |
---|
152 | $cmd->CreaParametro("@idaula",$idaula,1); |
---|
153 | $cmd->CreaParametro("@nombreordenador",$nombreordenador,0); |
---|
154 | $cmd->CreaParametro("@ip",$ip,0); |
---|
155 | $cmd->CreaParametro("@mac",$mac,0); |
---|
156 | $cmd->CreaParametro("@idperfilhard",$idperfilhard,1); |
---|
157 | $cmd->CreaParametro("@idrepositorio",$idrepositorio,1); |
---|
158 | $cmd->CreaParametro("@idconfiguracion",$idconfiguracion,1); |
---|
159 | |
---|
160 | $cmd->texto="INSERT INTO ordenadores(nombreordenador,ip,mac,idperfilhard,idrepositorio,idaula,grupoid) VALUES (@nombreordenador,@ip,@mac,@idperfilhard,@idrepositorio,@idaula,@grupoid)"; |
---|
161 | $resul=$cmd->Ejecutar(); |
---|
162 | return($resul); |
---|
163 | } |
---|
164 | //________________________________________________________________________________________________________ |
---|
165 | // Recupera los datos de un ordenador |
---|
166 | // Parametros: |
---|
167 | // - cmd: Una comando ya operativo (con conexión abierta) |
---|
168 | // - ip: Dirección IP |
---|
169 | //________________________________________________________________________________________________________ |
---|
170 | function existeOrdenador($cmd,$nombre,$MAC,$IP){ |
---|
171 | $rs=new Recordset; |
---|
172 | $cmd->texto="SELECT * FROM ordenadores WHERE nombreordenador='".$nombre."' OR mac='".$MAC."' OR ip='".$IP."'"; |
---|
173 | $rs->Comando=&$cmd; |
---|
174 | if (!$rs->Abrir()) return(false); // Error al abrir recordset |
---|
175 | $rs->Primero(); |
---|
176 | if (!$rs->EOF){ |
---|
177 | $rs->Cerrar(); |
---|
178 | return(true); |
---|
179 | } |
---|
180 | else |
---|
181 | return(false); |
---|
182 | } |
---|
183 | ?> |
---|