ryxeo-glpi-git / htdocs / mac / contract.php @ 7c12ea40
Historique | Voir | Annoter | Télécharger (4,34 ko)
1 | 1c14bcc4 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | gestion des contrats - affichage et rappel
|
||
4 | e213dd82 | root | http://www.abuledu.net/mac/contract.php/view=toto/mac=08:D8:34:B8:90:CD
|
5 | f3b307af | root |
|
6 | Code retour:
|
||
7 | timestampfincontrat:CODE:nom du contrat:texte informatif:hashcode pour mise a jour(tabuledu):
|
||
8 | 1c14bcc4 | Eric Seigne | */
|
9 | |||
10 | 7c12ea40 | root | $conf_wpkg_remote_server_propagate_auth = "http://wpkg.abuledu.net/tabuledu/newauth2/"; |
11 | |||
12 | 1c14bcc4 | Eric Seigne | $g_http_request = $_SERVER['REQUEST_URI']; |
13 | e213dd82 | root | preg_match("/.*mac=(.*)/",$_SERVER['REQUEST_URI'],$regs); |
14 | $mac = addslashes(strtoupper($regs[1])); |
||
15 | |||
16 | preg_match("/.*view=(.*)\/mac=/",$_SERVER['REQUEST_URI'],$regs); |
||
17 | $view = addslashes($regs[1]); |
||
18 | |||
19 | f3b307af | root | $hash = hash("md5", time() + "abuledu.net"); |
20 | |||
21 | e213dd82 | root | //print "on a $mac et $view";
|
22 | |||
23 | f3b307af | root | function insert_hash_allow_upgrade() { |
24 | 7c12ea40 | root | global $hash, $DB, $conf_wpkg_remote_server_propagate_auth; |
25 | f3b307af | root | $version = "0.0"; |
26 | $ip = $_SERVER['REMOTE_ADDR']; |
||
27 | //Insere le hash dans la table
|
||
28 | $query = "INSERT INTO glpi_plugin_anet_upgrade_hash VALUES('',NOW(),'$ip','$hash','$version')"; |
||
29 | $result = $DB->query($query); |
||
30 | 7c12ea40 | root | |
31 | //Et ensuite une petite requete distante :)
|
||
32 | $code = urlencode("$ip:$hash"); |
||
33 | readfile($conf_wpkg_remote_server_propagate_auth . $code); |
||
34 | f3b307af | root | } |
35 | |||
36 | 1c14bcc4 | Eric Seigne | //Ou du POST
|
37 | if(trim($mac) == "") { |
||
38 | $mac = addslashes(strtoupper($_POST['mac'])); |
||
39 | e213dd82 | root | } |
40 | 1c14bcc4 | Eric Seigne | |
41 | $_SERVER['REQUEST_URI'] = ""; |
||
42 | $_SERVER['HTTP_REFERER'] = ""; |
||
43 | define('GLPI_ROOT', '..'); |
||
44 | include (GLPI_ROOT . "/inc/includes.php"); |
||
45 | |||
46 | //On recupere l'id du serveur dont la macaddr correspond
|
||
47 | e213dd82 | root | $query = "SELECT FK_computers AS ID FROM glpi_computer_device WHERE specificity ='" . $mac . "'"; |
48 | 1c14bcc4 | Eric Seigne | $result = $DB->query($query); |
49 | $data = $DB->fetch_assoc($result); |
||
50 | //print_r($data);
|
||
51 | |||
52 | if($data['ID']) { |
||
53 | $serverid=$data['ID']; |
||
54 | e213dd82 | root | |
55 | //Quand on a le serverID il faut trouver l'entite dans laquelle il se trouve
|
||
56 | $queryEntity = "SELECT FK_entities AS EntityID FROM glpi_computers WHERE ID='$serverid'"; |
||
57 | $resultEntity = $DB->query($queryEntity); |
||
58 | $dataEntity = $DB->fetch_assoc($resultEntity); |
||
59 | $entityID = $dataEntity['EntityID']; |
||
60 | |||
61 | 1c14bcc4 | Eric Seigne | //Et ensuite on cherche dans les contrats ce qui correspond
|
62 | // -> contrat non supprime
|
||
63 | // -> contrat correspondant a ce serveur
|
||
64 | // -> contrat de type 1 ()
|
||
65 | e213dd82 | root | $query2 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_contracts as c WHERE |
66 | 1c14bcc4 | Eric Seigne | c.deleted='0' AND
|
67 | e213dd82 | root | c.FK_entities='$entityID'";
|
68 | |||
69 | 1c14bcc4 | Eric Seigne | //print $query2;
|
70 | $result2 = $DB->query($query2); |
||
71 | $data2 = $DB->fetch_assoc($result2); |
||
72 | |||
73 | //print_r($data2);
|
||
74 | //print mktime() . " -- ";
|
||
75 | $endc = $data2['endcontract']; |
||
76 | if($endc > mktime()) { |
||
77 | e213dd82 | root | if($view == "web") { |
78 | header('Location: http://www.abuledu.net/mac/view/direct.php'); |
||
79 | exit;
|
||
80 | } |
||
81 | else {
|
||
82 | f3b307af | root | insert_hash_allow_upgrade(); |
83 | print $endc . ":" . "DIRECT:" . $data2['name'] . ":none:$hash"; |
||
84 | e213dd82 | root | } |
85 | 1c14bcc4 | Eric Seigne | } |
86 | //Reconduction automatique ...
|
||
87 | else if($endc < mktime() && $data2['recursive']=='1') { |
||
88 | e213dd82 | root | if($view == "web") { |
89 | header('Location: http://www.abuledu.net/mac/view/direct.php'); |
||
90 | exit;
|
||
91 | } |
||
92 | else {
|
||
93 | f3b307af | root | print mktime(0,0,0, date("m",$endc)+$data2['periodicity'], date("d",$endc), date("Y",$endc)) . ":" . "DIRECT:" . $data2['name'] . ":" . "Renouvellement automatique:$hash"; |
94 | e213dd82 | root | } |
95 | 1c14bcc4 | Eric Seigne | } |
96 | else {
|
||
97 | //Le serveur a ete installe par un partenaire qui a un contrat global mais pas encore d'avenant pour ce serveur
|
||
98 | //1 on cherche le partenaire qui a installe ce serveur
|
||
99 | $query3 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_plugin_anet_epacks,glpi_contracts as c WHERE FK_serveur='" . $serverid . "' AND c.FK_entities=FK_clientderyxeo"; |
||
100 | //print $query3;
|
||
101 | $result3 = $DB->query($query3); |
||
102 | $data3 = $DB->fetch_assoc($result3); |
||
103 | /*
|
||
104 | print "<pre>";
|
||
105 | print_r($data3);
|
||
106 | print "</pre>";
|
||
107 | */
|
||
108 | $endc = $data3['endcontract']; |
||
109 | if($endc > mktime()) { |
||
110 | e213dd82 | root | if($view == "web") { |
111 | header('Location: http://www.abuledu.net/mac/view/partner.php'); |
||
112 | exit;
|
||
113 | } |
||
114 | else {
|
||
115 | f3b307af | root | insert_hash_allow_upgrade(); |
116 | print $endc . ":PARTNER" . ":" . $data3['name'] . ":" . "Avenant pour ce serveur manquant:$hash"; |
||
117 | e213dd82 | root | } |
118 | 1c14bcc4 | Eric Seigne | } |
119 | else{
|
||
120 | //Le serveur existe dans notre base mais c'est tout
|
||
121 | e213dd82 | root | if($view == "web") { |
122 | header('Location: http://www.abuledu.net/mac/view/waiting.php'); |
||
123 | exit;
|
||
124 | } |
||
125 | else {
|
||
126 | f3b307af | root | print "000:WAITING:000:none:$hash"; |
127 | e213dd82 | root | } |
128 | 1c14bcc4 | Eric Seigne | } |
129 | } |
||
130 | } |
||
131 | else {
|
||
132 | e213dd82 | root | if($view == "web") { |
133 | header('Location: http://www.abuledu.net/mac/view/forbidden.php'); |
||
134 | exit;
|
||
135 | } |
||
136 | else {
|
||
137 | f3b307af | root | print "000:FORBIDDEN:000:NOT:$hash"; |
138 | e213dd82 | root | } |
139 | 1c14bcc4 | Eric Seigne | } |
140 | |||
141 | ?> |