[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 4 /** 5 6 * Gestion des cles pour clients Windows (permet d'ajouter une cle dans la base) 7 * @Version $Id: ajout_cle.php 2949 2008-05-04 18:45:49Z plouf $ 8 9 */ 10 11 include "entete.inc.php"; 12 include "ldap.inc.php"; 13 include "ihm.inc.php"; 14 require "include.inc.php"; 15 16 require_once ("lang.inc.php"); 17 bindtextdomain('se3-registre', "/var/www/se3/locale"); 18 textdomain('se3-registre'); 19 20 echo "<h1>Importation des clés</h1>"; 21 22 // connexion(); 23 24 if (ldap_get_right("computers_is_admin", $login) != "Y") 25 die(gettext("Vous n'avez pas les droits suffisants pour accéder à cette fonction") . "</BODY></HTML>"); 26 27 // Aide 28 $_SESSION["pageaide"] = "Gestion_des_clients_windows#Description_du_processus_de_configuration_du_registre_Windows"; 29 30 $act = $_POST['action']; 31 switch ($act) { 32 default: 33 break; 34 35 case "file": 36 if (isset($_POST['upload'])) { // si formulaire soumis 37 if (file_exists("/tmp/import.reg")) 38 unlink("/tmp/import.reg"); 39 $content_dir = '/tmp/'; // dossier ou sera deplace le fichier 40 $tmp_file = $_FILES['fichier']['tmp_name']; 41 42 if (!is_uploaded_file($tmp_file)) { 43 exit(gettext("Le fichier est introuvable")); 44 } 45 // on copie le fichier dans le dossier de destination 46 $name_file = $_FILES['fichier']['name']; 47 48 if (!move_uploaded_file($tmp_file, $content_dir . $name_file)) { 49 exit(gettext("Impossible de copier le fichier dans") . " $content_dir"); 50 } 51 $fichier_reg = $content_dir . $name_file; 52 echo gettext("Le fichier") . " $name_file " . gettext("a bien été uploadé"); 53 print_nice(read_reg_file($content_dir . $name_file)); 54 55 } 56 57 break; 58 59 case "valid": 60 echo "a faire"; 61 break; 62 } 63 64 function print_nice($elem,$max_level=10,$print_nice_stack=array()){ 65 if(is_array($elem) || is_object($elem)){ 66 if(in_array(&$elem,$print_nice_stack,true)){ 67 echo "<font color=red>RECURSION</font>"; 68 return; 69 } 70 $print_nice_stack[]=&$elem; 71 if($max_level<1){ 72 echo "<font color=red>nivel maximo alcanzado</font>"; 73 return; 74 } 75 $max_level--; 76 echo "<table border=1 cellspacing=0 cellpadding=3 width=100%>"; 77 if(is_array($elem)){ 78 echo '<tr><td colspan=2 style="background-color:#333333;"><strong><font color=white>CLE</font></strong></td></tr>'; 79 }else{ 80 echo '<tr><td colspan=2 style="background-color:#333333;"><strong>'; 81 echo '<font color=white>OBJECT Type: '.get_class($elem).'</font></strong></td></tr>'; 82 } 83 $color=0; 84 foreach($elem as $k => $v){ 85 if($max_level%2){ 86 $rgb=($color++%2)?"#888888":"#BBBBBB"; 87 }else{ 88 $rgb=($color++%2)?"#8888BB":"#BBBBFF"; 89 } 90 echo '<tr><td valign="top" style="width:40px;background-color:'.$rgb.';">'; 91 echo '<strong>'.$k."</strong></td><td>"; 92 print_nice($v,$max_level,$print_nice_stack); 93 echo "</td></tr>"; 94 } 95 echo "</table>"; 96 return; 97 } 98 if($elem === null){ 99 echo "<font color=green>NULL</font>"; 100 }elseif($elem === 0){ 101 echo "0"; 102 }elseif($elem === true){ 103 echo "<font color=green>TRUE</font>"; 104 }elseif($elem === false){ 105 echo "<font color=green>FALSE</font>"; 106 }elseif($elem === ""){ 107 echo "<font color=green>EMPTY STRING</font>"; 108 }else{ 109 echo str_replace("\n","<br>\n",$elem); 110 } 111 } 112 113 114 function read_reg_file($regfile) 115 { 116 117 $handle = fopen ($regfile,"r"); 118 //echo "handle: " . $file . "<br>"; 119 $row = 1; 120 unset($n); 121 $os = "TOUS"; 122 $description = ""; 123 $categorie = "appli"; 124 $souscategorie = ""; 125 126 while ((($data = fgets($handle, 1024)) !== FALSE) ) { 127 128 $num = count($data); 129 //echo "$num fields in line $row: $data <br>\n"; 130 131 $reg_section = preg_replace("/\r/i", "", $data); 132 133 if (preg_match("/^;categorie=(.+)$/", $reg_section, $res)) { 134 $categorie = $res[1]; 135 } else if (preg_match("/^;souscategorie=(.+)$/", $reg_section, $res)) { 136 $souscategorie = $res[1]; 137 } else if (preg_match("/^;description=(.+)$/", $reg_section, $res)) { 138 $description = $res[1]; 139 } else if (preg_match("/^;os=(.+)$/", $reg_section, $res)) { 140 $os = $res[1]; 141 } else if (preg_match("/^\[([^;\r\n]+)\]$/", $reg_section, $res)) { 142 $path = $res[1]; 143 unset($binary); 144 } else if (preg_match("/^(.+)=(?:(dword|he[^:]+|dword):|)(.+)$/", $reg_section, $res)) { 145 if (preg_match("/^(.+)\\\\$/", $res[3], $valeur)) { 146 $binary = $valeur[1]; 147 } else { 148 $binary = preg_replace("/^\"(.+)\"$/", "\\1", $res[3]); 149 } 150 $n++; 151 $cle[$n]['path']=$path; 152 $cle[$n]['key'] = preg_replace("/^\"(.+)\"$/", "\\1", $res[1]); 153 $cle[$n]['valeur'] = $binary; 154 $cle[$n]['categorie'] = $categorie; 155 $cle[$n]['souscategorie'] = $souscategorie; 156 $cle[$n]['os'] = $os; 157 $cle[$n]['description'] = $description; 158 if ($res[2] == "dword") { 159 $cle[$n]['type'] = "REG_DWORD"; 160 } else if ($res[2] == "hex") { 161 $cle[$n]['type'] = "REG_BINARY"; 162 } else if ($res[2] == "hex(2)") { 163 $cle[$n]['type'] = "REG_EXPAND_SZ"; 164 $cle[$n]['valeur'] = hexToStr($binary); 165 } else if ($res[2] == "hex(7)") { 166 $cle[$n]['type'] = "REG_MULTI_SZ"; 167 $cle[$n]['valeur'] = hexToStr($binary); 168 } else { 169 $cle[$n]['type'] = "REG_SZ"; 170 } 171 } else if (preg_match("/^\s+([A-Fa-f0-9,]+)(\\\\|)$/", $reg_section, $res)) { 172 if ($res[2]) { 173 $binary .= $res[1]; 174 } else if ($cle[$n]['type'] == "REG_BINARY") { 175 $cle[$n]['valeur'] = $binary.$res[1]; 176 } else { 177 $cle[$n]['valeur'] = hexToStr($binary.$res[1]); 178 } 179 } 180 $row++; 181 } //end while 182 fclose($handle); 183 return($cle); 184 } 185 186 function hexToStr($hexlist) 187 { 188 $string=''; 189 foreach (preg_split("/,/", $hexlist) as $key=>$value) 190 { 191 // retour a la ligne 192 if ($value == "00") { $value = "0a"; } 193 $string .= chr(hexdec($value)); 194 } 195 return $string; 196 } 197 198 199 retour(); 200 201 include("pdp.inc.php"); 202 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |