Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / htdocs / mac / contract.php @ 7c12ea40

Historique | Voir | Annoter | Télécharger (4,34 ko)

1
<?php
2
/*
3
  gestion des contrats - affichage et rappel
4
  http://www.abuledu.net/mac/contract.php/view=toto/mac=08:D8:34:B8:90:CD
5
  
6
  Code retour:
7
  timestampfincontrat:CODE:nom du contrat:texte informatif:hashcode pour mise a jour(tabuledu):
8
*/
9

    
10
$conf_wpkg_remote_server_propagate_auth = "http://wpkg.abuledu.net/tabuledu/newauth2/";
11

    
12
$g_http_request = $_SERVER['REQUEST_URI'];
13
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
$hash = hash("md5", time() + "abuledu.net");
20

    
21
//print "on a $mac et $view";
22

    
23
function insert_hash_allow_upgrade() {
24
  global $hash, $DB, $conf_wpkg_remote_server_propagate_auth;
25
  $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

    
31
  //Et ensuite une petite requete distante :)
32
  $code = urlencode("$ip:$hash");
33
  readfile($conf_wpkg_remote_server_propagate_auth . $code);
34
}
35

    
36
//Ou du POST
37
if(trim($mac) == "") {
38
  $mac = addslashes(strtoupper($_POST['mac']));
39
}
40

    
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
$query = "SELECT FK_computers AS ID FROM glpi_computer_device WHERE specificity ='" . $mac . "'";
48
$result = $DB->query($query);
49
$data = $DB->fetch_assoc($result);
50
//print_r($data);
51

    
52
if($data['ID']) {
53
  $serverid=$data['ID'];
54
  
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
  //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
  $query2 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_contracts as c WHERE 
66
  c.deleted='0' AND
67
  c.FK_entities='$entityID'";
68

    
69
  //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
    if($view == "web") {
78
      header('Location: http://www.abuledu.net/mac/view/direct.php');
79
      exit;
80
    }
81
    else {
82
      insert_hash_allow_upgrade();
83
      print $endc . ":" . "DIRECT:" . $data2['name'] . ":none:$hash";
84
    }
85
  }
86
  //Reconduction automatique ...
87
  else if($endc < mktime() && $data2['recursive']=='1') {
88
    if($view == "web") {
89
      header('Location: http://www.abuledu.net/mac/view/direct.php');
90
      exit;
91
    }
92
    else {
93
      print mktime(0,0,0, date("m",$endc)+$data2['periodicity'], date("d",$endc), date("Y",$endc)) . ":" . "DIRECT:" . $data2['name'] . ":" . "Renouvellement automatique:$hash";
94
    }
95
  }
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
      if($view == "web") {
111
        header('Location: http://www.abuledu.net/mac/view/partner.php');
112
        exit;
113
      }
114
      else {
115
        insert_hash_allow_upgrade();
116
        print $endc . ":PARTNER" . ":" . $data3['name'] . ":" . "Avenant pour ce serveur manquant:$hash";
117
      }
118
    }
119
    else{
120
      //Le serveur existe dans notre base mais c'est tout
121
      if($view == "web") {
122
        header('Location: http://www.abuledu.net/mac/view/waiting.php');
123
        exit;
124
      }
125
      else {
126
        print "000:WAITING:000:none:$hash";
127
      }
128
    }
129
  }
130
 }
131
 else {
132
   if($view == "web") {
133
     header('Location: http://www.abuledu.net/mac/view/forbidden.php');
134
     exit;
135
   }
136
   else {
137
     print "000:FORBIDDEN:000:NOT:$hash";
138
   }
139
 }
140

    
141
?>
Redmine Appliance - Powered by TurnKey Linux