1<?php
2
3/**
4 * Script to print mail notification form
5 ********************************************/
6
7# include required scripts
8require_once( dirname(__FILE__) . '/../../../functions/functions.php' );
9
10# initialize required objects
11$Database 	= new Database_PDO;
12$Result		= new Result;
13$User		= new User ($Database);
14$Subnets	= new Subnets ($Database);
15$Tools	    = new Tools ($Database);
16$Addresses	= new Addresses ($Database);
17
18
19# verify that user is logged in
20$User->check_user_session();
21
22# id must be numeric
23is_numeric($_POST['id']) || strlen($_POST['id'])==0 ?:	$Result->show("danger", _("Invalid ID"), true);
24
25$csrf = $User->Crypto->csrf_cookie ("create", "mail_notify");
26
27# get IP address id
28$id = $_POST['id'];
29
30# fetch address, subnet, vlan and nameservers
31$address = (array) $Addresses->fetch_address (null, $id);
32$subnet  = (array) $Subnets->fetch_subnet (null, $address['subnetId']);
33$vlan    = (array) $Tools->fetch_object ("vlans", "vlanId", $subnet['vlanId']);
34$nameservers    = (array) $Tools->fetch_object("nameservers", "id", $subnet['nameserverId']);
35
36# get all custom fields
37$custom_fields = $Tools->fetch_custom_fields ('ipaddresses');
38
39# get subnet calculation
40$subnet_calculation = $Tools->calculate_ip_calc_results ($subnet['ip']."/".$subnet['mask']);
41
42
43# checks
44sizeof($address)>0 ?:	$Result->show("danger", _("Invalid ID"), true);
45sizeof($subnet)>0 ?:	$Result->show("danger", _("Invalid subnet"), true);
46
47
48# set title
49$title = _('IP address details').' :: ' . $address['ip'];
50
51
52# address
53										$content[] = "&bull; "._('IP address').": \t\t $address[ip]/$subnet[mask]";
54# description
55empty($address['description']) ? : 		$content[] = "&bull; "._('Description').":\t\t $address[description]";
56# hostname
57empty($address['hostname']) ? : 		$content[] = "&bull; "._('Hostname').": \t\t $address[hostname]";
58# subnet desc
59$s_descrip = empty($subnet['description']) ? "" : 	 " (" . $subnet['description']. ")";
60# subnet
61						$content[] = "&bull; "._('Subnet').": \t\t $subnet[ip]/$subnet[mask] $s_descrip";
62						$content[] = "&bull; "._('Netmask').": \t\t ".$subnet_calculation['Subnet netmask'];
63# gateway
64$gateway = $Subnets->find_gateway($subnet['id']);
65if($gateway !==false)
66 						$content[] = "&bull; "._('Gateway').": \t\t". $Subnets->transform_to_dotted($gateway->ip_addr);
67
68
69# VLAN
70empty($subnet['vlanId']) ? : 			$content[] = "&bull; "._('VLAN ID').": \t\t $vlan[number] ($vlan[name])";
71
72# Nameserver sets
73if ( !empty( $subnet['nameserverId'] ) ) {
74	$nslist = str_replace(";", ", ", $nameservers['namesrv1']);
75
76						$content[] = "&bull; "._('Nameservers').": \t $nslist (${nameservers['name']})";
77}
78
79# Switch
80if(!empty($address['switch'])) {
81	# get device by id
82	$device = (array) $Tools->fetch_object("devices", "id", $address['switch']);
83	!sizeof($device)>1 ? : 				$content[] = "&bull; "._('Device').": \t\t\t $device[hostname]";
84}
85# port
86empty($address['port']) ? : 			$content[] = "&bull; "._('Port').": \t\t $address[port]";
87# mac
88empty($address['mac']) ? : 			$content[] = "&bull; "._('Mac address').": \t\t $address[mac]";
89# owner
90empty($address['owner']) ? : 			$content[] = "&bull; "._('Owners').": \t\t $address[owner]";
91
92# custom
93if(sizeof($custom_fields) > 0) {
94	foreach($custom_fields as $custom_field) {
95		if(!empty($address[$custom_field['name']])) {
96						$content[] =  "&bull; ". _($custom_field['name']).":\t".$address[$custom_field['name']];
97		}
98	}
99}
100?>
101
102
103
104<!-- header -->
105<div class="pHeader"><?php print _('Send email notification'); ?></div>
106
107<!-- content -->
108<div class="pContent mailIPAddress">
109
110	<!-- sendmail form -->
111	<form name="mailNotify" id="mailNotify">
112	<table id="mailNotify" class="table table-noborder table-condensed">
113
114	<!-- recipient -->
115	<tr>
116		<th><?php print _('Recipients'); ?></th>
117		<td>
118			<input type="text" class='form-control input-sm pull-left' name="recipients" style="width:400px;margin-right:5px;">
119			<i class="fa fa-info input-append" rel="tooltip" data-placement="bottom" title="<?php print _('Separate multiple recepients with ,'); ?>"></i>
120		</td>
121	</tr>
122
123	<!-- title -->
124	<tr>
125		<th><?php print _('Title'); ?></t>
126		<td>
127			<input type="text" class='form-control input-sm' name="subject" style="width:400px;" value="<?php print $title; ?>">
128		</td>
129	</tr>
130
131	<!-- content -->
132	<tr>
133		<th><?php print _('Content'); ?></th>
134		<td style="padding-right:20px;">
135			<textarea name="content" class='form-control input-sm' rows="10" style="width:100%;"><?php print implode("\n", $content); ?></textarea>
136		</td>
137	</tr>
138
139	</table>
140	<input type="hidden" name='csrf_cookie' value='<?php print $csrf; ?>'>
141	</form>
142</div>
143
144<!-- footer -->
145<div class="pFooter">
146	<div class="btn-group">
147		<button class="btn btn-sm btn-default hidePopups"><?php print _('Cancel'); ?></button>
148		<button class="btn btn-sm btn-default btn-success" id="mailIPAddressSubmit"><i class="fa fa-envelope-o"></i> <?php print _('Send Mail'); ?></button>
149	</div>
150
151	<!-- holder for result -->
152	<div class="sendmail_check"></div>
153</div>
154