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