| 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 | ## ADV: modificacion para asignar a los ordenadores, cuando se crean desde "incorpoar ordenadores" el repositorio "default" | 
|---|
| 150 | $idrepositorio=1; | 
|---|
| 151 | $idconfiguracion=0; | 
|---|
| 152 | $cmd->CreaParametro("@grupoid",$grupoid,1); | 
|---|
| 153 | $cmd->CreaParametro("@idaula",$idaula,1); | 
|---|
| 154 | $cmd->CreaParametro("@nombreordenador",$nombreordenador,0); | 
|---|
| 155 | $cmd->CreaParametro("@ip",$ip,0); | 
|---|
| 156 | $cmd->CreaParametro("@mac",$mac,0); | 
|---|
| 157 | $cmd->CreaParametro("@idperfilhard",$idperfilhard,1); | 
|---|
| 158 | $cmd->CreaParametro("@idrepositorio",$idrepositorio,1); | 
|---|
| 159 | $cmd->CreaParametro("@idconfiguracion",$idconfiguracion,1); | 
|---|
| 160 |  | 
|---|
| 161 | $cmd->texto="INSERT INTO ordenadores(nombreordenador,ip,mac,idperfilhard,idrepositorio,idaula,grupoid) VALUES (@nombreordenador,@ip,@mac,@idperfilhard,@idrepositorio,@idaula,@grupoid)"; | 
|---|
| 162 | $resul=$cmd->Ejecutar(); | 
|---|
| 163 | return($resul); | 
|---|
| 164 | } | 
|---|
| 165 | //________________________________________________________________________________________________________ | 
|---|
| 166 | //      Recupera los datos de un ordenador | 
|---|
| 167 | //              Parametros: | 
|---|
| 168 | //              - cmd: Una comando ya operativo (con conexión abierta) | 
|---|
| 169 | //              - ip: Dirección IP | 
|---|
| 170 | //________________________________________________________________________________________________________ | 
|---|
| 171 | function existeOrdenador($cmd,$nombre,$MAC,$IP){ | 
|---|
| 172 | $rs=new Recordset; | 
|---|
| 173 | $cmd->texto="SELECT * FROM ordenadores WHERE nombreordenador='".$nombre."' OR mac='".$MAC."' OR ip='".$IP."'"; | 
|---|
| 174 | $rs->Comando=&$cmd; | 
|---|
| 175 | if (!$rs->Abrir()) return(false); // Error al abrir recordset | 
|---|
| 176 | $rs->Primero(); | 
|---|
| 177 | if (!$rs->EOF){ | 
|---|
| 178 | $rs->Cerrar(); | 
|---|
| 179 | return(true); | 
|---|
| 180 | } | 
|---|
| 181 | else | 
|---|
| 182 | return(false); | 
|---|
| 183 | } | 
|---|
| 184 | ?> | 
|---|