File: link.send.php

package info (click to toggle)
glpi 0.68.2-1etch0.1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 7,464 kB
  • ctags: 9,655
  • sloc: php: 69,502; sql: 3,514; sh: 175; makefile: 61
file content (133 lines) | stat: -rw-r--r-- 4,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/*
 * @version $Id: link.send.php 3798 2006-08-22 15:12:55Z moyo $
 -------------------------------------------------------------------------
 GLPI - Gestionnaire Libre de Parc Informatique
 Copyright (C) 2003-2006 by the INDEPNET Development Team.

 http://indepnet.net/   http://glpi-project.org
 -------------------------------------------------------------------------

 LICENSE

 This file is part of GLPI.

 GLPI is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 GLPI is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with GLPI; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 --------------------------------------------------------------------------
 */

include ("_relpos.php");
$NEEDED_ITEMS=array("link","knowbase","computer","printer","networking","peripheral","monitor","software","infocom","phone","cartridge","consumable","contract","contact","enterprise");
include ($phproot . "/inc/includes.php");

checkRight("link","r");

if (isset($_GET["lID"])){
	$query="SELECT glpi_links.ID as ID, glpi_links.link as link,glpi_links.data as data from glpi_links WHERE glpi_links.ID='".$_GET["lID"]."'";

	$result=$db->query($query);
	if ($db->numrows($result)==1){
		$file=$db->result($result,0,"data");
		$link=$db->result($result,0,"link");

		$ci=new CommonItem;

		$ci->getFromDB($_GET["type"],$_GET["ID"]);

		// Manage Filename
		if (ereg("\[NAME\]",$link)){
			$link=ereg_replace("\[NAME\]",$ci->getName(),$link);
		}

		if (ereg("\[ID\]",$link)){
			$link=ereg_replace("\[ID\]",$_GET["ID"],$link);
		}


		// Manage File Content

		if (ereg("\[NAME\]",$file)){
			$file=ereg_replace("\[NAME\]",$ci->getName(),$file);
		}

		if (ereg("\[ID\]",$file)){
			$file=ereg_replace("\[ID\]",$_GET["ID"],$file);
		}

		if (ereg("\[SERIAL\]",$file)){
			if (isset($ci->obj->fields["serial"]))
				$file=ereg_replace("\[SERIAL\]",$ci->obj->fields["serial"],$file);
		}
		if (ereg("\[OTHERSERIAL\]",$file)){
			if (isset($ci->obj->fields["otherserial"]))
				$file=ereg_replace("\[OTHERSERIAL\]",$ci->obj->fields["otherserial"],$file);
		}


		if (ereg("\[LOCATIONID\]",$file)){
			if (isset($ci->obj->fields["location"]))
				$file=ereg_replace("\[LOCATIONID\]",$ci->obj->fields["location"],$file);
		}
		if (ereg("\[LOCATION\]",$file)){
			if (isset($ci->obj->fields["location"]))
				$file=ereg_replace("\[LOCATION\]",getDropdownName("glpi_dropdown_locations",$ci->obj->fields["location"]),$file);
		}
		if (ereg("\[NETWORK\]",$file)){
			if (isset($ci->obj->fields["network"]))
				$file=ereg_replace("\[NETWORK\]",getDropdownName("glpi_dropdown_network",$ci->obj->fields["network"]),$file);
		}
		if (ereg("\[DOMAIN\]",$file)){
			if (isset($ci->obj->fields["domain"]))
				$file=ereg_replace("\[DOMAIN\]",getDropdownName("glpi_dropdown_domain",$ci->obj->fields["domain"]),$file);
		}
		$ipmac=array();
		$i=0;
		if (ereg("\[IP\]",$file)||ereg("\[MAC\]",$file)){
			$query2 = "SELECT ifaddr,ifmac FROM glpi_networking_ports WHERE (on_device = ".$_GET["ID"]." AND device_type = ".$_GET["type"].") ORDER BY logical_number";
			$result2=$db->query($query2);
			if ($db->numrows($result2)>0){
				$data2=$db->fetch_array($result2);
				$ipmac[$i]['ifaddr']=$data2["ifaddr"];
				$ipmac[$i]['ifmac']=$data2["ifmac"];
			}
		}

		if (ereg("\[IP\]",$file)||ereg("\[MAC\]",$file)){

			if (count($ipmac)>0){
				foreach ($ipmac as $key => $val){
					$file=ereg_replace("\[IP\]",$val['ifaddr'],$file);
					$file=ereg_replace("\[MAC\]",$val['ifmac'],$file);
				}
			}
		}
		header("Content-disposition: filename=\"$link\"");
		$mime="application/scriptfile";

		header("Content-type: ".$mime);
		header('Pragma: no-cache');
		header('Expires: 0');

		// Pour que les \x00 ne devienne pas \0
		$mc=get_magic_quotes_runtime();
		if ($mc) @set_magic_quotes_runtime(0); 

		echo $file;

		if ($mc) @set_magic_quotes_runtime($mc); 

	}
}	
?>