[40] | 1 | <? |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | function connectDB($hostDB, $userDB, $passwordDB) { |
---|
| 5 | |
---|
| 6 | $link = mysql_connect("$hostDB", "$userDB", "$passwordDB") |
---|
| 7 | or die("Impossible de se connecter : " . mysql_error()); |
---|
| 8 | |
---|
| 9 | //mysql_close($link); |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | /************************************************************************************ |
---|
| 17 | * |
---|
| 18 | * |
---|
| 19 | * Create Table USER |
---|
| 20 | * Create Table SERVICE |
---|
| 21 | * Create Table POWER |
---|
| 22 | * Create Table SERVICEUSER |
---|
| 23 | * Create Table CMDUSER |
---|
| 24 | * Create Table CMDSERVICE |
---|
| 25 | * Create Table SWITCH |
---|
| 26 | * Create Table CMDSWITCH |
---|
| 27 | * Create Table SERVICESWITCH |
---|
| 28 | * CREATE Table DEVICE |
---|
| 29 | * |
---|
| 30 | *TODO: METTRE LES PRIMARY KEY |
---|
| 31 | *************************************************************************************/ |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | function createDatabase($hostDB, $nameDB, $userCreateDB, $passwdCreateDB, $userDB, $passwdDB, $adminApp, $passwdAdminApp) |
---|
| 35 | { |
---|
| 36 | |
---|
| 37 | //connect DB |
---|
| 38 | $buffer = ""; |
---|
| 39 | $link = @mysql_connect($hostDB, $userCreateDB, $passwdCreateDB); |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | if (mysql_error()) { |
---|
| 43 | |
---|
| 44 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 45 | |
---|
| 46 | return $buffer; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | //Create DB |
---|
| 52 | $sql = "CREATE DATABASE IF NOT EXISTS $nameDB"; |
---|
| 53 | if (@mysql_query($sql, $link)) { |
---|
| 54 | $buffer = 1 ; |
---|
| 55 | } else { |
---|
| 56 | $buffer = "Create database: [FAILED] :" . mysql_error() ; |
---|
| 57 | return $buffer ; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | //echo "step create user<br>"; |
---|
| 62 | //Création de l'utilisateur pour l'accÚs à la base. |
---|
| 63 | $sql = "GRANT ALL PRIVILEGES ON $nameDB.* TO $userDB@localhost IDENTIFIED BY '$passwdDB' "; |
---|
| 64 | if (@mysql_query($sql, $link)) { |
---|
| 65 | $buffer = 1; |
---|
| 66 | } else { |
---|
| 67 | $buffer = "Create ACCESS DATABASE FROM $userDB [FAILED] :" . mysql_error() ; |
---|
| 68 | return $buffer ; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | mysql_close(); |
---|
| 72 | |
---|
| 73 | $link = @mysql_connect($hostDB, $userDB, $passwdDB); |
---|
| 74 | if (!$link) { |
---|
| 75 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
| 76 | return $buffer; |
---|
| 77 | }else{ |
---|
| 78 | |
---|
| 79 | $db_selected = @mysql_select_db($nameDB, $link); |
---|
| 80 | if (!$db_selected) { |
---|
| 81 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | //Create Table USER |
---|
| 88 | $sql = "CREATE TABLE IF NOT EXISTS USER ( |
---|
| 89 | idUser VARCHAR(50) NOT NULL, |
---|
| 90 | passwdUser VARCHAR(100) NOT NULL, |
---|
| 91 | PRIMARY KEY (idUser) );"; |
---|
| 92 | |
---|
| 93 | @mysql_query($sql,$link); |
---|
| 94 | if (mysql_error()){ |
---|
| 95 | $buffer = "Create Table USER: [FAILED] : " . mysql_error(); |
---|
| 96 | return $buffer ; |
---|
| 97 | }else{ |
---|
| 98 | $buffer = 1; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | //Create Table SERVICE |
---|
| 102 | $sql = "CREATE TABLE IF NOT EXISTS SERVICE ( |
---|
| 103 | idService VARCHAR(50) NOT NULL, |
---|
| 104 | PRIMARY KEY (idService) );"; |
---|
| 105 | @mysql_query($sql,$link); |
---|
| 106 | if (mysql_error()){ |
---|
| 107 | $buffer = "Create Table SERVICE: [FAILED] : " . mysql_error(); |
---|
| 108 | }else{ |
---|
| 109 | $buffer = 1; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | //Create Table SERVICEUSER |
---|
| 114 | $sql = "CREATE TABLE IF NOT EXISTS SERVICEUSER ( |
---|
| 115 | idUser VARCHAR(50) NOT NULL, |
---|
| 116 | idService VARCHAR(50) NOT NULL, |
---|
| 117 | PRIMARY KEY (idUser, idService) );"; |
---|
| 118 | |
---|
| 119 | @mysql_query($sql,$link); |
---|
| 120 | if (mysql_error()){ |
---|
| 121 | $buffer = "CREATE TABLE SERVICEUSER: [FAILED] : " . mysql_error(); |
---|
| 122 | return $buffer ; |
---|
| 123 | }else{ |
---|
| 124 | $buffer = 1; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | // Create Table POWER |
---|
| 130 | /*$sql = "CREATE TABLE IF NOT EXISTS Power ( |
---|
| 131 | idPower VARCHAR(50) NOT NULL, |
---|
| 132 | descPower VARCHAR(50) NOT NULL;)";*/ |
---|
| 133 | $sql = "CREATE TABLE IF NOT EXISTS POWER ( |
---|
| 134 | idPower VARCHAR(50) NOT NULL, |
---|
| 135 | descPower VARCHAR(200), |
---|
| 136 | PRIMARY KEY (idPower) );"; |
---|
| 137 | |
---|
| 138 | @mysql_query($sql,$link); |
---|
| 139 | if (mysql_error()){ |
---|
| 140 | $buffer = "Create Table POWER: [FAILED] : " . mysql_error(); |
---|
| 141 | return $buffer ; |
---|
| 142 | }else{ |
---|
| 143 | $buffer = 1; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | //Create Table CMDUSER |
---|
| 147 | $sql = "CREATE TABLE IF NOT EXISTS CMDUSER ( |
---|
| 148 | idPower VARCHAR(50) NOT NULL, |
---|
| 149 | idUser VARCHAR(50) NOT NULL, |
---|
| 150 | PRIMARY KEY (idPower, idUser));"; |
---|
| 151 | @mysql_query($sql,$link); |
---|
| 152 | if (mysql_error()){ |
---|
| 153 | $buffer = "Create Table CMDUSER: [FAILED] : " . mysql_error(); |
---|
| 154 | }else{ |
---|
| 155 | $buffer = 1; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | //Create Table CMDSERVICE |
---|
| 159 | $sql = "CREATE TABLE IF NOT EXISTS CMDSERVICE ( |
---|
| 160 | idPower VARCHAR(50) NOT NULL, |
---|
| 161 | idService VARCHAR(50) NOT NULL, |
---|
| 162 | PRIMARY KEY (idPower, idService))"; |
---|
| 163 | @mysql_query($sql,$link); |
---|
| 164 | if (mysql_error()){ |
---|
| 165 | $buffer = "Create Table CMDSERVICE: [FAILED] : " . mysql_error(); |
---|
| 166 | return $buffer ; |
---|
| 167 | }else{ |
---|
| 168 | $buffer = 1; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | //Create Table SWITCH |
---|
| 172 | $sql = "CREATE TABLE IF NOT EXISTS SWITCH ( |
---|
| 173 | idSwitch VARCHAR(50) NOT NULL, |
---|
| 174 | location VARCHAR(200), |
---|
| 175 | level INT(2), |
---|
| 176 | portignore VARCHAR(50) , |
---|
| 177 | PRIMARY KEY (idSwitch) |
---|
| 178 | );"; |
---|
| 179 | @mysql_query($sql,$link); |
---|
| 180 | if (mysql_error()){ |
---|
| 181 | $buffer = "Create Table SWITCH: [FAILED] : " . mysql_error(); |
---|
| 182 | return $buffer ; |
---|
| 183 | }else{ |
---|
| 184 | $buffer = 1; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | //Create Table CMDSWITCH |
---|
| 188 | $sql = "CREATE TABLE IF NOT EXISTS CMDSWITCH ( |
---|
| 189 | idPower VARCHAR(50) NOT NULL, |
---|
| 190 | idSwitch VARCHAR(50) NOT NULL, |
---|
| 191 | idUser VARCHAR(50) NOT NULL, |
---|
| 192 | PRIMARY KEY (idPower, idSwitch, idUser) |
---|
| 193 | );"; |
---|
| 194 | @mysql_query($sql,$link); |
---|
| 195 | if (mysql_error()){ |
---|
| 196 | $buffer = "Create Table CMDSWITCH: [FAILED] : " . mysql_error(); |
---|
| 197 | return $buffer; |
---|
| 198 | }else{ |
---|
| 199 | $buffer = 1; |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | //Create Table SERVICESWITCH |
---|
| 203 | $sql = "CREATE TABLE IF NOT EXISTS SERVICESWITCH ( |
---|
| 204 | idService VARCHAR(50) NOT NULL, |
---|
| 205 | idSwitch VARCHAR(50) NOT NULL, |
---|
| 206 | PRIMARY KEY (idService, idSwitch) |
---|
| 207 | );"; |
---|
| 208 | @mysql_query($sql,$link); |
---|
| 209 | if (mysql_error()){ |
---|
| 210 | $buffer = "CREATE TABLE SERVICESWITCH: [FAILED] : " . mysql_error(); |
---|
| 211 | return $buffer ; |
---|
| 212 | }else{ |
---|
| 213 | $buffer = 1; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | //CREATE Table RESEAU |
---|
| 218 | $sql = "CREATE TABLE IF NOT EXISTS NETWORK ( |
---|
| 219 | idNetwork VARCHAR(50) NOT NULL, |
---|
| 220 | nameNetwork VARCHAR(50) NOT NULL, |
---|
| 221 | interface VARCHAR(8) NOT NULL, |
---|
| 222 | mainRouter VARCHAR(50) NOT NULL, |
---|
| 223 | PRIMARY KEY (idNetwork) |
---|
| 224 | );"; |
---|
| 225 | @mysql_query($sql,$link); |
---|
| 226 | if (mysql_error()){ |
---|
| 227 | $buffer = "CREATE TABLE NETWORK: [FAILED] : " . mysql_error(); |
---|
| 228 | return $buffer ; |
---|
| 229 | }else{ |
---|
| 230 | $buffer = 1; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | //CREATE Table DEVICE |
---|
| 234 | $sql = "CREATE TABLE IF NOT EXISTS DEVICE ( |
---|
| 235 | mac VARCHAR(20) NOT NULL, |
---|
| 236 | hostname VARCHAR(50) NOT NULL, |
---|
| 237 | ip VARCHAR(50) NOT NULL, |
---|
| 238 | type VARCHAR(20), |
---|
| 239 | PRIMARY KEY (hostname) |
---|
| 240 | );"; |
---|
| 241 | @mysql_query($sql,$link); |
---|
| 242 | if (mysql_error()){ |
---|
| 243 | $buffer = "CREATE TABLE DEVICE: [FAILED] : " . mysql_error(); |
---|
| 244 | return $buffer ; |
---|
| 245 | }else{ |
---|
| 246 | $buffer = 1; |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | //init table POWER |
---|
| 250 | |
---|
| 251 | $power = array("addUser", |
---|
| 252 | "delUser", |
---|
| 253 | "updateUser", |
---|
| 254 | "addService", |
---|
| 255 | "delService", |
---|
| 256 | "updateService", |
---|
| 257 | "addServiceUser", |
---|
| 258 | "delServiceUser", |
---|
| 259 | "addSwitch", |
---|
| 260 | "delSwitch", |
---|
| 261 | "updateSwitch", |
---|
| 262 | "addServiceSwitch", |
---|
| 263 | "delServiceSwitch", |
---|
| 264 | "addRight", |
---|
| 265 | "delRight", |
---|
| 266 | "addNetwork", |
---|
| 267 | "delNetwork", |
---|
| 268 | "addDevice", |
---|
| 269 | "delDevice", |
---|
| 270 | "disablePort", |
---|
| 271 | "enablePort", |
---|
| 272 | "genFileKlaskConf", |
---|
| 273 | "klaskupdatesw", |
---|
| 274 | "klaskupdatedb", |
---|
| 275 | "klaskexportdb", |
---|
| 276 | "klaskgenmap", |
---|
| 277 | "klasksearch" ); |
---|
| 278 | |
---|
| 279 | foreach( $power as $idPower) { |
---|
| 280 | $sql = "INSERT INTO POWER VALUE('$idPower', '') "; |
---|
| 281 | @mysql_query($sql,$link); |
---|
| 282 | if (mysql_error()){ |
---|
| 283 | $buffer = "INSERT POWER $idPower IN TABLE SERVICESWITCH: [FAILED] : " . mysql_error(); |
---|
| 284 | return $buffer; |
---|
| 285 | }else{ |
---|
| 286 | $buffer = 1; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | //init table user, insert adminApp account |
---|
| 292 | $passwdAdminApp= md5($passwdAdminApp); |
---|
| 293 | $sql= "INSERT INTO USER VALUE('$adminApp', '$passwdAdminApp');"; |
---|
| 294 | @mysql_query($sql,$link); |
---|
| 295 | if (mysql_error()){ |
---|
| 296 | $buffer .= "INSERT USER ADMIN $adminApp IN TABLE USER: [FAILED] : " . mysql_error(); |
---|
| 297 | return $buffer; |
---|
| 298 | }else{ |
---|
| 299 | $buffer = 1; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | //init table CMSUSER for adminApp account |
---|
| 303 | foreach( $power as $idPower) { |
---|
| 304 | $sql = "INSERT INTO CMDUSER VALUE('$idPower', '$adminApp') "; |
---|
| 305 | @mysql_query($sql,$link); |
---|
| 306 | if (mysql_error()){ |
---|
| 307 | $buffer .= "INSERT CMDUSER $idPower FOR USER $adminApp: [FAILED] : " . mysql_error(); |
---|
| 308 | return $buffer; |
---|
| 309 | }else{ |
---|
| 310 | $buffer = 1; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | return $buffer; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | function createFileConfig($hostDB, $nameDB, $userDB, $passwdDB, $adminApp) { |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | |
---|
| 323 | //Create file config.php |
---|
| 324 | $fileConfig="./conf/config.php"; |
---|
| 325 | |
---|
| 326 | $content = "<?\n"; |
---|
| 327 | $content .= "\$GLOBALS['hostDB']=\"$hostDB\";\n"; |
---|
| 328 | $content .= "\$GLOBALS['nameDB']=\"$nameDB\";\n"; |
---|
| 329 | $content .= "\$GLOBALS['userDB']=\"$userDB\";\n"; |
---|
| 330 | $content .= "\$GLOBALS['passwdDB']=\"$passwdDB\";\n"; |
---|
| 331 | $content .= "\$GLOBALS['auth']=\"classic\";\n"; |
---|
| 332 | $content .= "\$GLOBALS['adminApp']=\"$adminApp\";\n"; |
---|
| 333 | $content .= "?>"; |
---|
| 334 | |
---|
| 335 | if (!$handle=fopen($fileConfig, "w+")) { |
---|
| 336 | $buffer = "Open file $fileConfig: [FAILED]"; |
---|
| 337 | return $buffer; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | if (!fwrite($handle, $content)) { |
---|
| 341 | $buffer = "Write in file $fileConfig: [FAILED]"; |
---|
| 342 | return $buffer; |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | return 1; |
---|
| 346 | |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | |
---|
| 350 | function displaySaisieDB() |
---|
| 351 | { |
---|
| 352 | |
---|
| 353 | $buffer = "<h1>Installation Etape 1</h1>"; |
---|
| 354 | $buffer .= "<FORM METHOD=\"POST\" ACTION=\"install.php?section=saisieDB\">"; |
---|
| 355 | $buffer .= "<TABLE>"; |
---|
| 356 | $buffer .= "<TR><TD>ParamÚtres pour la création de la base de données</TD></TR>"; |
---|
| 357 | $buffer .= "<TR><TD>Nom de la machine : </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textHostDB\"></INPUT></TD></TR>"; |
---|
| 358 | $buffer .= "<TR><TD>Nom de la base de données: </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textNameDB\"></INPUT></TD></TR>"; |
---|
| 359 | $buffer .= "<TR><TD>Utilisateur (autorisé à créer une base de données, exemple root): </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textUserCreateDB\"></INPUT></TD></TR>"; |
---|
| 360 | |
---|
| 361 | $buffer .= "<TR><TD>Mot de passe de l'utilisateur (autorisé à créer une base de donnée): </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textPasswdCreateDB\"</INPUT></TD></TR>"; |
---|
| 362 | |
---|
| 363 | $buffer .= "<TR><TD>Utilisateur (pour l'accÚs de l'application à la base): </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textUserDB\"></INPUT></TD></TR>"; |
---|
| 364 | |
---|
| 365 | $buffer .= "<TR><TD>Mot de passe de l'utilisateur (pour l'accÚs à la base): </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textPasswdDB\"></INPUT></TD></TR>"; |
---|
| 366 | |
---|
| 367 | $buffer .= "<TR><TD>Compte administrateur de l'application: </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textAdminApp\"></INPUT></TD></TR>"; |
---|
| 368 | |
---|
| 369 | $buffer .= "<TR><TD>Mot de passe du compte administrateur de l'application: </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textPasswdAdminApp\"></INPUT></TD></TR>"; |
---|
| 370 | |
---|
| 371 | $buffer .= "<TR><TD><INPUT TYPE=\"SUBMIT\" VALUE=\"VALIDER\"></INPUT></TD></TR>"; |
---|
| 372 | $buffer .= "</TABLE></FORM>"; |
---|
| 373 | |
---|
| 374 | return $buffer; |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | |
---|
| 380 | |
---|
| 381 | function displayChooseAuth() { |
---|
| 382 | |
---|
| 383 | $buffer = "<h1>Installation Etape 2: Choix d'authentification</h1>"; |
---|
| 384 | $buffer .= "<FORM METHOD=\"POST\" ACTION=\"./install.php?section=auth\">"; |
---|
| 385 | $buffer .= "<TABLE>"; |
---|
| 386 | $buffer .= "<TR><TD>Quel mode d'authentification souhaitez-vous ?</TD></TR>"; |
---|
| 387 | $buffer .= "<TR><TD><INPUT TYPE=\"RADIO\" NAME=\"radioAuth\" VALUE=\"classic\" checked>Classique</INPUT></TD>"; |
---|
| 388 | $buffer .= "<TD><INPUT TYPE=\"RADIO\" NAME=\"radioAuth\" VALUE=\"ldap\">LDAP</TD></TR>"; |
---|
| 389 | $buffer .= "<TR><TD><INPUT TYPE=\"SUBMIT\" VALUE=\"VALIDER\"></INPUT></TD></TR>"; |
---|
| 390 | $buffer .= "</TABLE></FORM>"; |
---|
| 391 | |
---|
| 392 | |
---|
| 393 | return $buffer ; |
---|
| 394 | |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | |
---|
| 398 | function displaySaisieLDAP() { |
---|
| 399 | |
---|
| 400 | $buffer = "<h1>Installation Etape 3: ParamÚtres LDAP</h1>"; |
---|
| 401 | $buffer .= "<FORM METHOD=\"POST\" ACTION=\"./install.php?section=createFileAuth\">"; |
---|
| 402 | $buffer .= "<TABLE>"; |
---|
| 403 | $buffer .= "<TR><TD>Nom du serveur LDAP</TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textHostLdap\"></INPUT></TD></TR>"; |
---|
| 404 | $buffer .= "<TR><TD>Bind des Utilisateurs (exemple: ou=people, dc=ens, dc=fr) </TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textBindUser\"></INPUT></TD></TR>"; |
---|
| 405 | $buffer .= "<TR><TD>Champs du service d'affectation de l'utilisateur</TD><TD><INPUT TYPE=\"TEXT\" NAME=\"textService\"></TD></TR>"; |
---|
| 406 | $buffer .="<TR><TD><INPUT TYPE=\"SUBMIT\" VALUE=\"VALIDER\"></INPUT></TD></TR>"; |
---|
| 407 | $buffer .= "</TABLE></FORM>"; |
---|
| 408 | |
---|
| 409 | return $buffer ; |
---|
| 410 | |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | function createFileLDAP($hostLDAP, $bindUser, $bindService) { |
---|
| 419 | |
---|
| 420 | //Create file auth_ldap.php |
---|
| 421 | $fileAuthLDAP="./ldap/auth_ldap.php"; |
---|
| 422 | |
---|
| 423 | $content = "<?\n"; |
---|
| 424 | $content .= "\$GLOBALS['hostLDAP']=\"$hostLDAP\";\n"; |
---|
| 425 | $content .= "\$GLOBALS['dnUser']=\"$bindUser\";\n"; |
---|
| 426 | $content .= "\$GLOBALS['dnService']=\"$bindService\";\n"; |
---|
| 427 | $content .= "?>"; |
---|
| 428 | |
---|
| 429 | if (!$handle=fopen($fileAuthLDAP, "w+")) { |
---|
| 430 | $buffer = "Open file $fileAuthLDAP: [FAILED]"; |
---|
| 431 | return $buffer; |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | if (!fwrite($handle, $content)) { |
---|
| 435 | $buffer = "Write in file $fileAuthLDAP: [FAILED]"; |
---|
| 436 | return $buffer; |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | //READ config.php |
---|
| 440 | $fileConfig="./conf/config.php"; |
---|
| 441 | $contentToWrite= ""; |
---|
| 442 | $handle = @fopen($fileConfig, "r"); |
---|
| 443 | if ($handle) { |
---|
| 444 | while (!feof($handle)) { |
---|
| 445 | $contentFile = fgets($handle, 4096); |
---|
| 446 | |
---|
| 447 | |
---|
| 448 | if ( !( ereg ("\?>", $contentFile) ) && (!ereg("GLOBALS\['auth'\]", $contentFile) ) ) { |
---|
| 449 | $contentToWrite .= $contentFile; |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | fclose($handle); |
---|
| 454 | |
---|
| 455 | $contentToWrite .= "\$GLOBALS['auth']=\"ldap\";\n"; |
---|
| 456 | $contentToWrite .= "?>\n"; |
---|
| 457 | |
---|
| 458 | //REWRITE config.php |
---|
| 459 | if (!$handle=fopen($fileConfig, "w+")) { |
---|
| 460 | $buffer = "Open file $fileConfig: [FAILED]"; |
---|
| 461 | return $buffer; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | if (!fwrite($handle, $contentToWrite)) { |
---|
| 465 | $buffer = "Write in file $fileConfig: [FAILED]"; |
---|
| 466 | return $buffer; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | |
---|
| 470 | return 1; |
---|
| 471 | |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | |
---|
| 475 | |
---|
| 476 | |
---|
| 477 | ?> |
---|