Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / htdocs / mac / contract.php @ f3b307af

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