ryxeo-glpi-git / htdocs / epack / register-tabuledu.php @ 7c12ea40
Historique | Voir | Annoter | Télécharger (26,6 ko)
1 | e213dd82 | root | <?php
|
---|---|---|---|
2 | //AJAX CODE
|
||
3 | |||
4 | $commande = ""; |
||
5 | $message = ""; |
||
6 | $debug = ""; |
||
7 | $log_debug = 1; //flag pour savoir s'il faut ecrire les debug logs dans le fichier de logs |
||
8 | $log_file = "/tmp/debug.log"; |
||
9 | $send_mail = 0; //flag pour savoir s'il faut envoyer un mail (en bref a toute insertion ou update de base) |
||
10 | |||
11 | 7c12ea40 | root | function get_ip() { |
12 | //Just get the headers if we can or else use the SERVER global
|
||
13 | if ( function_exists( 'apache_request_headers' ) ) { |
||
14 | $headers = apache_request_headers();
|
||
15 | } else {
|
||
16 | $headers = $_SERVER; |
||
17 | } |
||
18 | |||
19 | //Get the forwarded IP if it exists
|
||
20 | if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) { |
||
21 | $the_ip = $headers['X-Forwarded-For']; |
||
22 | } elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) |
||
23 | ) { |
||
24 | $the_ip = $headers['HTTP_X_FORWARDED_FOR']; |
||
25 | } else {
|
||
26 | $the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ); |
||
27 | } |
||
28 | return $the_ip; |
||
29 | } |
||
30 | |||
31 | e213dd82 | root | function make_pdf($pass,$code,$datapost) { |
32 | global $message; |
||
33 | global $login_email; |
||
34 | require_once('lib/odf.php'); |
||
35 | 3a4c0c8e | root | $odf = new odf("abuledu-base_genere_automatiquement_enregistrement_epack_tabuledu.odp"); |
36 | e213dd82 | root | |
37 | //1ere page
|
||
38 | setlocale(LC_TIME, "fr_FR.UTF-8"); |
||
39 | // $odf->setVars('date', strftime("%A %e %B %Y"));
|
||
40 | $odf->setVars('date_installation', $datapost['IDATE']); |
||
41 | $odf->setVars('date', date("d/m/Y")); |
||
42 | |||
43 | //Le epack
|
||
44 | $odf->setVars('epack_pass', $pass); |
||
45 | $odf->setVars('epack_code', $code); |
||
46 | |||
47 | //L'école
|
||
48 | $odf->setVars('ecole_nom', $datapost['INAME'], true, 'UTF-8'); |
||
49 | $odf->setVars('ecole_adresse', $datapost['IADDRESS0'], true, 'UTF-8'); |
||
50 | $odf->setVars('ecole_cp', $datapost['IPOSTALCODE'], true, 'UTF-8'); |
||
51 | $odf->setVars('ecole_ville', $datapost['ICITY'], true, 'UTF-8'); |
||
52 | $odf->setVars('ecole_pays', $datapost['ICOUNTRY'], true, 'UTF-8'); |
||
53 | $odf->setVars('ecole_tel', $datapost['ITEL'], true, 'UTF-8'); |
||
54 | $odf->setVars('ecole_email', $datapost['IEMAIL'], true, 'UTF-8'); |
||
55 | |||
56 | //Le tabuledu
|
||
57 | $odf->setVars('srv_serial', $datapost['ISERIAL'], true, 'UTF-8'); |
||
58 | $odf->setVars('srv_cpu', $datapost['CPU'], true, 'UTF-8'); |
||
59 | $odf->setVars('srv_ram', $datapost['RAM'], true, 'UTF-8'); |
||
60 | $odf->setVars('srv_hdd0', $datapost['HDD0'], true, 'UTF-8'); |
||
61 | $odf->setVars('srv_eth0', $datapost['MAC0'], true, 'UTF-8'); |
||
62 | $odf->setVars('srv_eth1', $datapost['MAC1'], true, 'UTF-8'); |
||
63 | |||
64 | //L'admin local
|
||
65 | $odf->setVars('adm_prenom', $datapost['ADM_FIRSTNAME'], true, 'UTF-8'); |
||
66 | $odf->setVars('adm_nom', $datapost['ADM_LASTNAME'], true, 'UTF-8'); |
||
67 | $odf->setVars('adm_email', $datapost['ADM_EMAIL'], true, 'UTF-8'); |
||
68 | |||
69 | //La personne ressource
|
||
70 | $odf->setVars('pr_prenom', $datapost['PR_FIRSTNAME'], true, 'UTF-8'); |
||
71 | $odf->setVars('pr_nom', $datapost['PR_LASTNAME'], true, 'UTF-8'); |
||
72 | $odf->setVars('pr_email', $datapost['PR_EMAIL'], true, 'UTF-8'); |
||
73 | |||
74 | //L'anim TICE
|
||
75 | $odf->setVars('atice_prenom', $datapost['ATICE_FIRSTNAME'], true, 'UTF-8'); |
||
76 | $odf->setVars('atice_nom', $datapost['ATICE_LASTNAME'], true, 'UTF-8'); |
||
77 | $odf->setVars('atice_email', $datapost['ATICE_EMAIL'], true, 'UTF-8'); |
||
78 | |||
79 | //Le revendeur
|
||
80 | $odf->setVars('rvd_code', $datapost['RCODE'], true, 'UTF-8'); |
||
81 | $odf->setVars('rvd_nom', $datapost['RNAME'], true, 'UTF-8'); |
||
82 | $odf->setVars('rvd_tel', $datapost['RTEL'], true, 'UTF-8'); |
||
83 | $odf->setVars('rvd_email', $datapost['REMAIL'], true, 'UTF-8'); |
||
84 | $odf->setVars('rvd_adresse', $datapost['RADDRESS'], true, 'UTF-8'); |
||
85 | $odf->setVars('rvd_cp', $datapost['RCP'], true, 'UTF-8'); |
||
86 | $odf->setVars('rvd_ville', $datapost['RVILLE'], true, 'UTF-8'); |
||
87 | |||
88 | //On créé un fichier local pour archive ...
|
||
89 | $fichier="archives/" . date("Y-m-d") . "-epack-register-" . $code . ".odp"; |
||
90 | $fichier_pdf="archives/" . date("Y-m-d") . "-epack-register-" . $code . ".pdf"; |
||
91 | |||
92 | $odf->saveToDisk($fichier); |
||
93 | $t = exec("unoconv --server localhost --port 2002 -f pdf " . $fichier); |
||
94 | |||
95 | //Ensuite il faut l'envoyer par email ...
|
||
96 | $txtmail = "Bonjour, |
||
97 | 3a4c0c8e | root | vous venez d'enregistrer un ePack d'installation AbulÉdu version TAbulÉdu et nous vous en remercions.
|
98 | e213dd82 | root |
|
99 | Vous trouverez ci-joint le document récapitulatif de votre enregistrement.
|
||
100 |
|
||
101 | --
|
||
102 | RyXéo SARL
|
||
103 | contact@ryxeo.com
|
||
104 | Tel: 05 35 54 01 18";
|
||
105 | $crlf = "\n"; |
||
106 | $hdrs = array( |
||
107 | 'From' => 'contact@ryxeo.com', |
||
108 | 3a4c0c8e | root | 'Subject' => mb_encode_mimeheader("[TAbulEdu] Fiche d'installation " . $datapost['INAME']), |
109 | e213dd82 | root | 'BCC' => 'contact@ryxeo.com, supportteam@ryxeo.com' |
110 | ); |
||
111 | $mime = new Mail_mime($crlf); |
||
112 | $mime->setTXTBody($txtmail); |
||
113 | $mime->addAttachment($fichier_pdf, mime_content_type($fichier_pdf)); |
||
114 | $mime->addAttachment($fichier, mime_content_type($fichier)); |
||
115 | $body = $mime->get(array('text_charset' => 'utf-8')); |
||
116 | $hdrs = $mime->headers($hdrs); |
||
117 | $mail =& Mail::factory('mail'); |
||
118 | |||
119 | if(trim($datapost['REMAIL']) == "") { |
||
120 | if(trim($login_email) != "") { |
||
121 | $mail->send($login_email, $hdrs, $body); |
||
122 | } |
||
123 | else {
|
||
124 | //On cherche le mail associe a ce pack ?
|
||
125 | $mail->send("contact@ryxeo.com", $hdrs, $body); |
||
126 | } |
||
127 | } |
||
128 | else {
|
||
129 | $mail->send($datapost['REMAIL'], $hdrs, $body); |
||
130 | } |
||
131 | } |
||
132 | |||
133 | function send_mail_installation($pass,$code,$datapost) { |
||
134 | 7c12ea40 | root | global $DB; |
135 | |||
136 | $ip = get_ip();
|
||
137 | $install_societe = ""; |
||
138 | $client_final = ""; |
||
139 | |||
140 | $query1 = "SELECT * FROM glpi_plugin_anet_epacks LEFT JOIN glpi_entities AS g ON FK_clientderyxeo=g.ID WHERE code='$code' AND password='$pass'"; |
||
141 | $result = $DB->query($query1); |
||
142 | if($DB->numrows($result)>0) { |
||
143 | $data=$DB->fetch_assoc($result); |
||
144 | $install_societe = $data['name']; |
||
145 | } |
||
146 | e213dd82 | root | |
147 | 7c12ea40 | root | $query2 = "SELECT * FROM glpi_plugin_anet_epacks LEFT JOIN glpi_entities AS g ON FK_client=g.ID WHERE code='$code' AND password='$pass'"; |
148 | $result = $DB->query($query2); |
||
149 | if($DB->numrows($result)>0) { |
||
150 | $data=$DB->fetch_assoc($result); |
||
151 | $client_final = $data['name']; |
||
152 | } |
||
153 | |||
154 | $mail_content = "Bonjour, |
||
155 | e213dd82 | root |
|
156 | 3a4c0c8e | root | une nouvelle tabuledu vient d'être installée
|
157 | e213dd82 | root |
|
158 | Référence du ePack AbulÉdu:
|
||
159 | - $pass
|
||
160 | - $code
|
||
161 |
|
||
162 | Installateur:
|
||
163 | 7c12ea40 | root | - Société: $install_societe
|
164 |
|
||
165 | Client final:
|
||
166 | - $client_final
|
||
167 |
|
||
168 | Adresse IP utilisée lors de l'installation: $ip
|
||
169 | e213dd82 | root |
|
170 | --
|
||
171 | abuledu.net est un service de RyXéo SARL, société éditrice d'AbulÉdu
|
||
172 | 7c12ea40 | root | script register-tabuledu.php sur www.abuledu.net
|
173 | e213dd82 | root |
|
174 | ";
|
||
175 | |||
176 | if(stripos($code, "-TESTS-")) { |
||
177 | 7c12ea40 | root | ryxeo_mail("anet@ryxeo.com",$mail_content,"contact@ryxeo.com","[epack de test] Nouvelle tabuledu dans la base abuledu.net - " . $code); |
178 | e213dd82 | root | } |
179 | else {
|
||
180 | 7c12ea40 | root | ryxeo_mail("anet@ryxeo.com",$mail_content,"contact@ryxeo.com","Nouvelle tabuledu dans la base abuledu.net - $client_final ($install_societe)" ); |
181 | e213dd82 | root | } |
182 | } |
||
183 | |||
184 | //Verifie si les donnees qu'on a en entree sont correctes sinon on saute ... direction webadmin/installation
|
||
185 | function verification_data() { |
||
186 | global $datapost; |
||
187 | global $message; |
||
188 | $error = ""; |
||
189 | if(trim(strtolower($datapost['MAC0'])) == "") // || trim(strtolower($datapost['MAC1'])) == "" ) |
||
190 | $error .= "<li>Il manque une carte réseau dans ce tabuledu !</li>"; |
||
191 | if(trim($datapost['INAME']) == "") |
||
192 | $error .= "<li>Erreur sur le nom de l'installation</li>"; |
||
193 | if(trim($datapost['IADDRESS0']) == "") |
||
194 | $error .= "<li>Adresse de l'installation incorrecte</li>"; |
||
195 | if(trim($datapost['IPOSTALCODE']) == "") |
||
196 | $error .= "<li>Code postal incorrect</li>"; |
||
197 | if(trim($datapost['ICITY']) == "") |
||
198 | $error .= "<li>Nom de ville incorrect</li>"; |
||
199 | if(trim($datapost['ICOUNTRY']) == "") |
||
200 | $error .= "<li>Nom du pays incorrect</li>"; |
||
201 | if(trim($datapost['ITEL']) == "") |
||
202 | $error .= "<li>Numéro de téléphone incorect</li>"; |
||
203 | if(trim($datapost['ADM_LASTNAME']) == "") |
||
204 | $error .= "<li>Nom du contact administratif incomplet</li>"; |
||
205 | if(trim($datapost['ADM_FIRSTNAME'])== "") |
||
206 | $error .= "<li>Prénom du contact administratif incomplet</li>"; |
||
207 | if(strpos($datapost['IEMAIL'],"@") == FALSE) |
||
208 | $error .= "<li>Adresse email de l'école incorrecte</li>"; |
||
209 | if(strpos($datapost['ADM_EMAIL'],"@") == FALSE) |
||
210 | $error .= "<li>Adresse email du responsable administratif incorrecte</li>"; |
||
211 | |||
212 | if($error != "") { |
||
213 | $message .= "<ul>"; |
||
214 | $message .= $error; |
||
215 | $message .= "</ul>"; |
||
216 | return false; |
||
217 | } |
||
218 | else
|
||
219 | return true; |
||
220 | |||
221 | } |
||
222 | |||
223 | //création des fichiers de conf sur ce nouve<au tabuledu
|
||
224 | //ou restauration des fichiers de conf (si réinstallation)
|
||
225 | function make_conffiles($login,$pass,$code) { |
||
226 | global $commande; |
||
227 | $codecrypt = md5($pass); |
||
228 | |||
229 | //Si c'est un tabuledu de tests on ne cree surtout pas le fichier gdipc pour eviter que apt essaye
|
||
230 | //de passer en mode authentifie, on demandera donc le login/pass rvd a chaque upgrade
|
||
231 | if(stripos($code, "-TESTS-")) { |
||
232 | $commande .= ""; |
||
233 | } |
||
234 | else {
|
||
235 | $commande .= " echo \"" . $login . ";dip.abuledu.net;http://dip.abuledu.net/gnudip/cgi-bin/gdipupdt.cgi;" . $codecrypt . ";/home/abecmd/.GnuDIP2.cache." . $login . ".dip.abuledu.net;0;2073600\" > ~abecmd/.GnuDIP2 |
||
236 | chmod 600 ~abecmd/.GnuDIP2
|
||
237 | chown abecmd:admin ~abecmd/.GnuDIP2
|
||
238 | su - abecmd gdipc\n";
|
||
239 | } |
||
240 | |||
241 | $commande .= " mkdir ~abecmd/.ssh || true |
||
242 | echo \"ssh-dss AAAAB3NzaC1kc3MAAACBAPM3DKuDXuSsQgPeBNO/jBEAd28smHqYVAODRwshfI04/rFvwh/A+7UZ2H/QnZOn6XLS/3R4yPp/QdGKEJ0BCHDd2fLIuS6ZLDHoHdQRBFzEAXP1SE1Yyp9c1pKnWeke6oK6196yKpE2aWBRv9kma+KoPhz7mpt6KHISow+yYV/PAAAAFQDFCotxKtxherzuwzVbeXmiOGQ3EwAAAIEAq+KXzJUt13h5QvM7u0O3mbDGD6YY9avMYqFk8StJ4DoFpSfeiwvNynoDsAE2qLTje7hbs+UO4Ns1lCLhh4R4T9wdLodTRVfizvqjZhmhOGfTHUjX9qi+dTs7c0mtqZz89ZZSqJsnMb9I1Ifj0H++MOswa7qp1cFxzUYtlew128QAAACAXve21Gn+gD7GXhvLIMq7bq6/ECjcjoBQcpLF72Z3tAsd0i0Scv1eydsUiee47pr3o4fJToQAr3iFQX6zWnDaw4htg3cZAMzfuvXxuWBcDoQ2qjYAk1A/FoJM7z5pPZXnWQZ+Vq+HfsW8W7EHztVgoZ/Xj/10webHjcL8CzFGWU4= remoteabecmd@Timide
|
||
243 | ssh-dss AAAAB3NzaC1kc3MAAACBAIyAzv1X8Hy8r8QiJAmhlDs9INd0jCpYNk5OxBDYA1/qdmKVqVMwKACvZg8xigRBg4e5PMsgpGQf9OxHTlhIiqAjwxmi7tHAy1t1fHuqDCZmqpQG5banOPvr4R5w4q47jKAJNqRsofgZACQKo8KkSHxY5VWZNx5bOfZYdEcWcNqpAAAAFQCXElvdvY+/aILI5a1z4fKRybA7GQAAAIB+5v/foiMKyZ+JEocToPIj2fP4mH7o8xnA1T8HKUGOiutxT/TWT4OnUMmquA/XVdzOyJ/tEeznfUDvlJZzKtFoW75ftQ8Or0AJj68jGQQ3wxQW5TXKuOCoo4vdf0ZQ+ASbzY1ECdxiQEB5kWusWbpes/eyTzDzjpUjMfR2JS5+rAAAAIAksQfdasobfpGuqLIvHBpgSFyas9J6EguBQVauNyLy7IE/WmAN1zgbYvBVU7KY3WUr5pgum9GcExCfnGH/qW7zR7M5zbZdOwq2W4AphXibkf+YbB2q1BouigbUzCiA54wa6XArtHsx0PpzyToHjAplnI4O5DhJ1SQNHClLbfA9Gw== erics@hurlevent
|
||
244 | \" > ~abecmd/.ssh/authorized_keys
|
||
245 | chmod 700 ~abecmd/.ssh -R
|
||
246 | chown abecmd:admin ~abecmd/.ssh -R
|
||
247 | adduser abecmd admin || true
|
||
248 | cd ~abecmd
|
||
249 | wget apt.ryxeo.com/ryxeo/bashrc -O .bashrc
|
||
250 | chown abecmd .bashrc
|
||
251 | ";
|
||
252 | |||
253 | //Et maintenant on sauvegarde qqpart le code/pass du pack
|
||
254 | $commande .= " |
||
255 | echo \"" . $code . ":" . $pass . "\" > /etc/abuledu/epack |
||
256 | chown aesd:www-data /etc/abuledu/epack || true
|
||
257 | chmod 640 /etc/abuledu/epack || true
|
||
258 | sed -i -e \"/.*EPACK.*/D\" /etc/abuledu/rvd || true
|
||
259 | echo RVD_EPACK_CODE=\\\"$code\\\" >> /etc/abuledu/rvd
|
||
260 | ";
|
||
261 | |||
262 | //L'identification du revendeur ... a améliorer
|
||
263 | $commande .= make_rvd_conffile();
|
||
264 | |||
265 | //Il faudrait egalement faire la base pour OCS-NG et les remontees automatiques ... on utilisera le code du epack
|
||
266 | } |
||
267 | |||
268 | function make_rvd_conffile() { |
||
269 | global $DB; |
||
270 | //Securisation de l'identification du revendeur ... a améliorer
|
||
271 | $commande .= " |
||
272 | chown aesd /etc/abuledu/rvd
|
||
273 | chmod 400 /etc/abuledu/rvd
|
||
274 | ";
|
||
275 | |||
276 | } |
||
277 | |||
278 | function add_user_and_update_link($usermail,$identity,$userlastname,$userfirstname,$tag="") { |
||
279 | global $DB; |
||
280 | global $debug; |
||
281 | global $message; |
||
282 | global $send_mail; |
||
283 | |||
284 | if(trim($usermail) == "") { |
||
285 | $message .= "<li><font color=\"red\">ERROR ($tag)</font> compte utilisateur sans adresse email ! $userlastname :: $userfirstname</li>\n"; |
||
286 | return;
|
||
287 | } |
||
288 | |||
289 | $query = "SELECT * from glpi_users WHERE email='$usermail'"; |
||
290 | $result = $DB->query($query); |
||
291 | $debug .= "<p>nb ; " . $DB->numrows($result) . " req : $query</p>"; |
||
292 | if($DB->numrows($result)>0) { |
||
293 | $data = $DB->fetch_assoc($result); |
||
294 | $iduser = $data['ID']; |
||
295 | //existe dejà on fait juste le lien s'il n'existe pas déjà
|
||
296 | $query2 = "SELECT * FROM glpi_users_profiles WHERE FK_users='$iduser' AND FK_entities='$identity'"; |
||
297 | //$debug .= "$query2";
|
||
298 | $result2 = $DB->query($query2); |
||
299 | if($DB->numrows($result2)<=0) { |
||
300 | //pour eviter qu'un utilisateur se retrouve dans l'entite racine ...
|
||
301 | if(trim($identity) != 0) { |
||
302 | $query3 = "INSERT INTO glpi_users_profiles(FK_users,FK_entities,FK_profiles,recursive,dynamic) VALUES('$iduser','$identity',1,0,1)"; |
||
303 | $result3 = $DB->query($query3); |
||
304 | $send_mail = 1; |
||
305 | if($result3) |
||
306 | $message .= "<li>Attribution des droits de l'utilisateur $usermail sur le tabuledu: <font color=\"green\">OK</font></li>\n"; |
||
307 | else {
|
||
308 | $message .= "<li>Attribution des droits de l'utilisateur $usermail sur le tabuledu: <font color=\"red\">ERROR</font></li>\n"; |
||
309 | } |
||
310 | } |
||
311 | else {
|
||
312 | $message .= "<li>Tentative de lien avec l'entité racine($identity) refusée pour $usermail: <font color=\"red\">ERROR</font></li>\n"; |
||
313 | //$message .= "<li>$query2</li>\n";
|
||
314 | } |
||
315 | } |
||
316 | //Sinon c'est que tout est déjà fait !
|
||
317 | } |
||
318 | //Sinon c'est que l'utilisateur n'existe pas encore dans la base
|
||
319 | else {
|
||
320 | //Insérer l'utilisateur ... et appel sur la même fonction qui cette fois ci fera le reste :)
|
||
321 | $query2 = "INSERT INTO glpi_users(name,email,realname,firstname,FK_profiles,FK_entities,auth_method) VALUES( |
||
322 | '$usermail',
|
||
323 | '$usermail',
|
||
324 | '$userlastname',
|
||
325 | '$userfirstname',
|
||
326 | '0',
|
||
327 | '$identity',
|
||
328 | '1'
|
||
329 | )";
|
||
330 | $result2 = $DB->query($query2); |
||
331 | $send_mail = 1; |
||
332 | if($result2) { |
||
333 | $message .= "<li>Création du compte utilisateur $usermail : <font color=\"green\">OK</font></li>\n"; |
||
334 | add_user_and_update_link($usermail,$identity,$userlastname,$userrfirstname,$tag); |
||
335 | } |
||
336 | else {
|
||
337 | $message .= "<li>Création du compte utilisateur $usermail : <font color=\"red\">ERROR</font></li>\n"; |
||
338 | } |
||
339 | } |
||
340 | } |
||
341 | |||
342 | //Vite une session
|
||
343 | session_start(); |
||
344 | 7c12ea40 | root | if(isset($_GET['reset']) && trim($_GET['reset']) != "") { |
345 | e213dd82 | root | // Finalement, on détruit la session.
|
346 | session_destroy(); |
||
347 | header('Location: http://abuledu.net/epack/register/'); |
||
348 | } |
||
349 | //print_r($_SESSION);
|
||
350 | //recupration des variables de l'url
|
||
351 | $g_http_request = $_SERVER['REQUEST_URI']; |
||
352 | |||
353 | 7c12ea40 | root | if(isset($_SESSION['epack_session']) && $_SESSION['epack_session'] > 1) { |
354 | e213dd82 | root | $pass = strtoupper($_SESSION['epack_pass']); |
355 | $code = strtoupper($_SESSION['epack_code']); |
||
356 | if(isset($_POST['login_email'])) { |
||
357 | $login_email = $_POST['login_email']; |
||
358 | $login_pass = $_POST['login_pass']; |
||
359 | } |
||
360 | if(isset($_SESSION['login_email'])) { |
||
361 | $login_email = $_SESSION['login_email']; |
||
362 | $login_pass = $_SESSION['login_pass']; |
||
363 | } |
||
364 | } |
||
365 | else {
|
||
366 | $debug .= "Pas de session\n"; |
||
367 | //Si on est sur un formulaire POST (on casse la limite de la taille de la requete GET)
|
||
368 | if(isset($_POST["pass"])) { |
||
369 | $debug .= "Passage en POST\n"; |
||
370 | |||
371 | $pass = $_POST["pass"]; |
||
372 | $code = strtoupper($_POST["code"]); |
||
373 | $datapost = array(); |
||
374 | |||
375 | $debug .= "<p>Req::" . $_SERVER['REQUEST_URI'] . "</p>\n"; |
||
376 | |||
377 | foreach($_POST as $key=>$value) { |
||
378 | $datapost[$key]=$value; |
||
379 | $debug .= "<p>" . $key . " -> " . $value . "</p>\n"; |
||
380 | } |
||
381 | } |
||
382 | else {
|
||
383 | 7c12ea40 | root | ereg(".*pass=(.*).code=(.*)",$_SERVER['REQUEST_URI'],$regs); |
384 | e213dd82 | root | $pass = addslashes($regs[1]); |
385 | |||
386 | 7c12ea40 | root | //si code=rvd11-01-5799-acip-282/data=none
|
387 | |||
388 | $tabcode = explode("/",$regs[2]); |
||
389 | if(is_array($tabcode)) { |
||
390 | //print_r($tabcode);
|
||
391 | $code = $tabcode[0]; |
||
392 | } |
||
393 | else {
|
||
394 | $code = strtoupper(addslashes($regs[2])); |
||
395 | } |
||
396 | |||
397 | if(count($regs) > 3) { |
||
398 | $keyvalue_list=explode("&",base64_decode($regs[3])); |
||
399 | $datapost = array(); |
||
400 | |||
401 | $debug .= "<p>Req::" . $_SERVER['REQUEST_URI'] . "</p>\n"; |
||
402 | foreach($keyvalue_list as $key=>$value) { |
||
403 | // Explode each individual key/value into an array
|
||
404 | $keyvalue=explode("=",$value); |
||
405 | // Make sure we have a "key=value" array
|
||
406 | if(count($keyvalue)==2) { |
||
407 | $datapost[$keyvalue[0]]=$keyvalue[1]; |
||
408 | $debug .= "<p>" . $keyvalue[0] . " -> " . $keyvalue[1] . "</p>\n"; |
||
409 | } |
||
410 | else {
|
||
411 | $debug .= "<p>XXX:" . $value . "</p>\n"; |
||
412 | } |
||
413 | e213dd82 | root | } |
414 | } |
||
415 | 7c12ea40 | root | else {
|
416 | $debug .= "<p>Pas de regs3 ...</p>\n"; |
||
417 | } |
||
418 | e213dd82 | root | } |
419 | |||
420 | //Ou du POST
|
||
421 | if(trim($pass) == "" || trim($code) == "") { |
||
422 | $pass = addslashes($_POST['pass']); |
||
423 | $code = addslashes(strtoupper($_POST['code'])); |
||
424 | } |
||
425 | } |
||
426 | |||
427 | $_SERVER['REQUEST_URI'] = ""; |
||
428 | $_SERVER['HTTP_REFERER'] = ""; |
||
429 | |||
430 | define('GLPI_ROOT', '..'); |
||
431 | include (GLPI_ROOT . "/inc/includes.php"); |
||
432 | |||
433 | include ("ryxeo.php"); |
||
434 | include('Mail.php'); |
||
435 | include('Mail/mime.php'); |
||
436 | |||
437 | //Si epack ryxeo de tests
|
||
438 | if(stripos($code, "RYXEO-TESTS-")) { |
||
439 | if(is_array($datapost)) { |
||
440 | $k = array_keys($datapost); |
||
441 | for($i = 0; $i < count($k); $i++) { |
||
442 | $key = $k[$i]; |
||
443 | $debug .= $key . "=" . $datapost[$key] . "\n"; |
||
444 | } |
||
445 | } |
||
446 | } |
||
447 | if(isset($datapost["MINIWEBADMIN"]) && stripos($code, "-TESTS-")) { |
||
448 | $message .= "<p><h2>Vous pouvez maintenant passer à l'étape suivante: <a href=\"/maj/\">la 1ere mise à jour de votre tabuledu.</a></h2></p>\n"; |
||
449 | //le flag qui indique a miniwebadmin que le epack est enregistre
|
||
450 | $commande .= "\n touch /tmp/epack.ok \n"; |
||
451 | } |
||
452 | /*
|
||
453 | if(trim($debug) != "" ) {
|
||
454 | $message .= "<pre>
|
||
455 | $debug
|
||
456 | </pre>";
|
||
457 | }
|
||
458 | */
|
||
459 | |||
460 | $debug .= "<p>Du cote abuledu.net ... $g_http_request</p>\n7"; |
||
461 | |||
462 | |||
463 | //On ne fait pas tout le bazaaar, on teste / valide la procedure uniquement
|
||
464 | 7c12ea40 | root | /*
|
465 | e213dd82 | root | if(stripos($code, "-TESTS-")) {
|
466 | 7c12ea40 | root | make_pdf($pass,$code,$datapost);
|
467 | send_mail_installation($pass,$code,$datapost);
|
||
468 | }
|
||
469 | */
|
||
470 | e213dd82 | root | //print_r($_SERVER);
|
471 | //On ne fait pas tout le bazaaar, on teste / valide la procedure uniquement
|
||
472 | if(stripos($code, "-TESTS-")) { |
||
473 | 7c12ea40 | root | //$object = array();
|
474 | print "<p>L'enregistrement de votre tabuledu avec un ePack AbulÉdu Serveur partenaire n'est pas possible ... </p>\n"; |
||
475 | print "<p>Veuillez demander un ePack de tests tabuledu à RyXéo</p>\n"; |
||
476 | //$object['message'] .= $message;
|
||
477 | //$object['command'] = $commande;
|
||
478 | e213dd82 | root | return;
|
479 | } |
||
480 | |||
481 | //print "<pre>";
|
||
482 | //print_r($datapost);
|
||
483 | //$message .= implode("::",$datapost);
|
||
484 | //print "</pre>";
|
||
485 | //reset ...
|
||
486 | //print_r($_SESSION);
|
||
487 | //unset($_SESSION['epack_session']);
|
||
488 | if(trim($pass) != "" && trim($code) != "") { |
||
489 | $query = "SELECT * FROM glpi_plugin_anet_epacks |
||
490 | LEFT JOIN glpi_entities AS g ON FK_client=g.ID
|
||
491 | WHERE code='$code' AND password='$pass'";
|
||
492 | $result = $DB->query($query); |
||
493 | $debug .= "$query"; |
||
494 | $mac0 = trim(strtolower($datapost['MAC0'])); |
||
495 | $mac1 = trim(strtolower($datapost['MAC1'])); |
||
496 | //$data=$DB->fetch_assoc($result);
|
||
497 | //$nbresultat = $DB->numrows($result);
|
||
498 | //print_r($data);
|
||
499 | //exit;
|
||
500 | if($DB->numrows($result)>0) { |
||
501 | $data=$DB->fetch_assoc($result); |
||
502 | |||
503 | 7c12ea40 | root | if($data['FK_serveur'] > 0) { |
504 | $query2 = "SELECT * FROM glpi_entities_data WHERE FK_entities='" . $data['FK_client'] . "'"; |
||
505 | $result2 = $DB->query($query2); |
||
506 | $data2=$DB->fetch_assoc($result2); |
||
507 | e213dd82 | root | |
508 | 7c12ea40 | root | $message .= "<p>Merci, ePack correctement activé.</p>\n"; |
509 | $message .= "<h4>Rappel des informations concernant ce client: </h4>"; |
||
510 | $message .= "<ul> |
||
511 | <li>Nom: " . $data['name'] . "</li> |
||
512 | <li>Adresse: " . $data2['address'] . " " . $data2['postcode'] . " " . $data2['town'] . "</li> |
||
513 | </ul>\n";
|
||
514 | $message .= "<p>Merci d'avoir enregistré cette tabuledu. Pour toute demande de modification, veuillez utiliser votre compte abuledu.net ou prendre <a href=\"mailto:contact@ryxeo.com\">contact avec RyXéo</a></p>"; |
||
515 | send_mail_installation($pass,$code,$datapost); |
||
516 | |||
517 | e213dd82 | root | } |
518 | //pack deja utilise ? si oui c'est qu'il a bien été activé
|
||
519 | else if($data['FK_activation'] > 0) { |
||
520 | $notes = "Données collectées lors de l'enregistrement du tabuledu le " . date("Y-m-d") . "\n\n"; |
||
521 | foreach ($datapost as $key => $value) { |
||
522 | $notes .= "$key = $value\n"; |
||
523 | } |
||
524 | //On créé l'entité de l'école dans l'entité du client qui est elle même dans l'entité du revendeur
|
||
525 | $query1 = "SELECT * FROM glpi_entities WHERE name='" . addslashes($datapost['INAME']) . "' AND parentID='" . $data['FK_client'] . "'"; |
||
526 | $result1 = $DB->query($query1); |
||
527 | if($DB->numrows($result1) > 0) { |
||
528 | //L'entité existe déjà ...
|
||
529 | $data1 = $DB->fetch_assoc($result1); |
||
530 | $identityenduser = $data1['ID']; |
||
531 | } |
||
532 | else {
|
||
533 | 7c12ea40 | root | //L'entité n'existe pas, on l'ajoute : là c'est un peu nul on utilise le code epack a defaut de connaitre le nom de l'école (formulaire léger sur tabuledu)
|
534 | e213dd82 | root | $query1 = "INSERT INTO glpi_entities VALUES('','" . addslashes($datapost['INAME']) . "'," . $data['FK_client'] . ",'" . $data['completename'] . " > " . addslashes($datapost['INAME']) . "','',5)"; |
535 | $result1 = $DB->query($query1); |
||
536 | $send_mail = 1; |
||
537 | } |
||
538 | $query1 = "SELECT * from glpi_entities WHERE name='" . addslashes($datapost['INAME']) . "' AND parentID='" . $data['FK_client'] . "';"; |
||
539 | $result1 = $DB->query($query1); |
||
540 | $data1 = $DB->fetch_assoc($result1); |
||
541 | //Creation ok
|
||
542 | $identityenduser = $data1['ID']; |
||
543 | if($DB->numrows($result1) > 0) { |
||
544 | $query1 = "INSERT INTO glpi_entities_data VALUES('',$identityenduser,'" . |
||
545 | addslashes($datapost['IADDRESS0'] . " " . $datapost['IADDRESS1'] ) . "','" . |
||
546 | addslashes($datapost['IPOSTALCODE']) . "','" . |
||
547 | addslashes($datapost['ICITY']) . "','" . |
||
548 | "','" .
|
||
549 | addslashes($datapost['ICOUNTRY']) . "','" . |
||
550 | "','" .
|
||
551 | addslashes($datapost['ITEL']) . "','" . |
||
552 | "','" .
|
||
553 | addslashes($datapost['IEMAIL']) . "','" . |
||
554 | "','" .
|
||
555 | "','" .
|
||
556 | "');";
|
||
557 | $result1 = $DB->query($query1); |
||
558 | //print $query1;
|
||
559 | //print_r($data1);
|
||
560 | $message .= "<ul>\n"; |
||
561 | if($result1) |
||
562 | $message .= "<li>Création de l'école: <font color=\"green\">OK</font></li>\n"; |
||
563 | else {
|
||
564 | $message .= "<li>Création de l'école: <font color=\"red\">ERROR</font></li>\n"; |
||
565 | } |
||
566 | |||
567 | } |
||
568 | |||
569 | //Il faut inserer le tabuledu dans le compte du client final et faire le toutim
|
||
570 | $query2 = "INSERT INTO glpi_computers(FK_entities,name,date_mod,os_license_number,comments,notes,state) |
||
571 | VALUES(
|
||
572 | '" . $identityenduser . "', |
||
573 | '" . addslashes($datapost['INAME']) . "', |
||
574 | NOW(),
|
||
575 | '" . $mac0 . ".dip.abuledu.net', |
||
576 | '" . addslashes($datapost['ICOMMENT']) . "', |
||
577 | '" . addslashes($notes) . "', |
||
578 | '1'
|
||
579 | )";
|
||
580 | $result2 = $DB->query($query2); |
||
581 | $send_mail = 1; |
||
582 | |||
583 | $query2 = "SELECT * from glpi_computers WHERE name='" . addslashes($datapost['INAME']) . "' AND os_license_number='" . $mac0 . ".dip.abuledu.net';"; |
||
584 | // print "select $query2";
|
||
585 | $result2 = $DB->query($query2); |
||
586 | $data2 = $DB->fetch_assoc($result2); |
||
587 | // print_r($data2);
|
||
588 | //Creation ok
|
||
589 | $idserver = $data2['ID']; |
||
590 | if($DB->numrows($result2) > 0) { |
||
591 | 7c12ea40 | root | $message .= "<li>Ajout de cette tabuledu sur AbulÉdu.net: <font color=\"green\">OK</font></li>\n"; |
592 | e213dd82 | root | |
593 | //On attribue le pack au tabuledu
|
||
594 | $nbu = $data['nbused'] + 1; |
||
595 | $query3 = "UPDATE glpi_plugin_anet_epacks SET FK_serveur='" . $idserver . "', FK_enduser='" . $identityenduser . "', nbused='$nbu' WHERE code='$code' AND password='$pass'"; |
||
596 | $result3 = $DB->query($query3); |
||
597 | |||
598 | |||
599 | $query3 = "INSERT INTO glpi_computer_device(specificity,device_type,FK_device,FK_computers) |
||
600 | VALUES('" . $datapost['CPU'] . "','2','2','$idserver'), |
||
601 | ('" . $datapost['RAM'] . "','3','2','$idserver'), |
||
602 | ('" . $datapost['HDD0'] . "','4','4','$idserver'),"; |
||
603 | if(trim($datapost['HDD1'])) |
||
604 | $query3 .= "('" . $datapost['HDD1'] . "','4','4','$idserver'),"; |
||
605 | $query3 .= "('" . $datapost['MAC0'] . "','5','2','$idserver'), |
||
606 | ('" . $datapost['MAC1'] . "','5','2','$idserver');"; |
||
607 | $result3 = $DB->query($query3); |
||
608 | $send_mail = 1; |
||
609 | if($result3) |
||
610 | $message .= "<li>Ajout des pièces détachées du tabuledu: <font color=\"green\">OK</font></li>\n"; |
||
611 | else
|
||
612 | $message .= "<li>Ajout des pièces détachées du tabuledu: <font color=\"red\">ERROR</font></li>\n"; |
||
613 | //Insertion des pièces détachées ok
|
||
614 | |||
615 | //Ajout des contacts liés à ce tabuledu ?
|
||
616 | add_user_and_update_link($datapost['IEMAIL'], $identityenduser,$datapost['INAME'],$datapost['ICITY'],"Installation"); |
||
617 | add_user_and_update_link($datapost['ADM_EMAIL'], $identityenduser,$datapost['ADM_LASTNAME'],$datapost['ADM_FIRSTNAME'],"Directrice ou directeur"); |
||
618 | add_user_and_update_link($datapost['PR_EMAIL'], $identityenduser,$datapost['PR_LASTNAME'],$datapost['PR_FIRSTNAME'],"Autre contact"); |
||
619 | add_user_and_update_link($datapost['ATICE_EMAIL'], $identityenduser,$datapost['ATICE_LASTNAME'],$datapost['ATICE_FIRSTNAME'],"Animateur TICE"); |
||
620 | |||
621 | //Création des fichiers de conf pour se rattacher a la maintenance (?) ... mais si pas de maintenance ?
|
||
622 | //On gerera ça sur les paiements des contrats associés
|
||
623 | make_conffiles($datapost['MAC0'],$pass,$code); |
||
624 | |||
625 | //Mail d'information a ryxeo + pdf au rvendeur
|
||
626 | 7c12ea40 | root | //make_pdf($pass,$code,$datapost);
|
627 | e213dd82 | root | send_mail_installation($pass,$code,$datapost); |
628 | |||
629 | if(isset($datapost["MINIWEBADMIN"])) { |
||
630 | $message .= "</ul>\n<p>Vous pouvez maintenant passer à l'étape suivante: <a href=\"/maj/\">la 1ere mise à jour de votre tabuledu.</a></p>\n"; |
||
631 | //le flag qui indique a miniwebadmin que le epack est enregistre
|
||
632 | $commande .= "\n touch /tmp/epack.ok \n"; |
||
633 | } |
||
634 | else {
|
||
635 | $message .= "<li><font color=\"green\">Bravo</font> votre tabuledu est maintenant bien enregistré sur abuledu.net. Vous pouvez passer à l'étape de création automatique du <a href=\"recette.php\">cahier de recettes</a></li>\n"; |
||
636 | $message .= "</ul>\n"; |
||
637 | } |
||
638 | } |
||
639 | else
|
||
640 | $message .= "<li>Ajout du tabuledu sur anet: <font color=\"red\">ERROR</font></li>\n"; |
||
641 | } |
||
642 | else if ($data['activation_date'] == "0000-00-00") { |
||
643 | 7c12ea40 | root | $message .= "FORBIDDEN:<p><font color=\"red\">Erreur, ce packs n'a pas été activé !!! Vous devez activer votre ePack tout de suite à l'adresse suivante, <a href=\"http://www.abuledu.net/epack/new\" target=\"_blank\">abuledu.net/epack/new</a> comme indiqué sur la fiche ePack.</font></p>\n"; |
644 | e213dd82 | root | } |
645 | else {
|
||
646 | 7c12ea40 | root | $message .= "FORBIDDEN:<p><font color=\"red\">Erreur, ce pack a déjà été utilisé ou n'a pas encore été activé !!!</font></p>\n"; |
647 | e213dd82 | root | } |
648 | } |
||
649 | else {
|
||
650 | 7c12ea40 | root | $message .= "FORBIDDEN:<p><font color=\"red\">Erreur de code ($code) ou de mot de passe ($pass) epack !!!</font></p>\n"; |
651 | e213dd82 | root | } |
652 | } |
||
653 | else {
|
||
654 | 7c12ea40 | root | $message .= "FORBIDDEN:<p><font color=\"red\">Erreur: code ou mot de passe epack invalide ($code / $pass).</font></p>\n"; |
655 | e213dd82 | root | } |
656 | |||
657 | $object = array(); |
||
658 | if(trim($message) == "") |
||
659 | $message .= "<p><font color=\"red\">Erreur non prévue, merci de contacter RyXéo sans tarder...</font></p>"; |
||
660 | $object['message'] = "<h1>Enregistrement de votre tabuledu avec un ePack</h1>\n"; |
||
661 | $object['message'] .= $message; |
||
662 | |||
663 | 7c12ea40 | root | //print json_encode($object);
|
664 | print $message; |
||
665 | e213dd82 | root | |
666 | if($log_debug != "") { |
||
667 | 7c12ea40 | root | if($fp = fopen($log_file,"a")) { |
668 | e213dd82 | root | fwrite($fp, $debug); |
669 | 7c12ea40 | root | fwrite($fp, "**********************************"); |
670 | fwrite($fp, $message); |
||
671 | fwrite($fp, "**********************************"); |
||
672 | e213dd82 | root | fclose($fp); |
673 | } |
||
674 | } |
||
675 | |||
676 | 7c12ea40 | root | $ip = get_ip();
|
677 | |||
678 | $txtmail = "Bonjour, |
||
679 | une erreur d'enregistrement ePack ou autre pour TabulEdu vient de se produire
|
||
680 |
|
||
681 | $message
|
||
682 |
|
||
683 | Adresse IP utilisée lors de l'installation: $ip
|
||
684 |
|
||
685 | --
|
||
686 | RyXéo SARL
|
||
687 | contact@ryxeo.com
|
||
688 | Tel: 05 35 54 01 18";
|
||
689 | $crlf = "\n"; |
||
690 | $hdrs = array( |
||
691 | 'From' => 'contact@ryxeo.com', |
||
692 | 'Subject' => mb_encode_mimeheader("[TAbulEdu] Fiche d'erreur " . $datapost['INAME']), |
||
693 | 'BCC' => 'contact@ryxeo.com' |
||
694 | ); |
||
695 | $mime = new Mail_mime($crlf); |
||
696 | $mime->setTXTBody($txtmail); |
||
697 | $mime->addAttachment($fichier_pdf, mime_content_type($fichier_pdf)); |
||
698 | $mime->addAttachment($fichier, mime_content_type($fichier)); |
||
699 | $body = $mime->get(array('text_charset' => 'utf-8')); |
||
700 | $hdrs = $mime->headers($hdrs); |
||
701 | $mail =& Mail::factory('mail'); |
||
702 | |||
703 | $mail->send("contact@ryxeo.com", $hdrs, $body); |
||
704 | |||
705 | |||
706 | e213dd82 | root | //print_r($_SERVER);
|
707 | ?> |