1<?php
2
3/**
4 *	Script to replace fields in IP address list
5 ***********************************************/
6
7/* functions */
8require_once( dirname(__FILE__) . '/../../../functions/functions.php' );
9
10# initialize user object
11$Database 	= new Database_PDO;
12$User 		= new User ($Database);
13$Admin	 	= new Admin ($Database);
14$Result 	= new Result ();
15
16# verify that user is logged in
17$User->check_user_session();
18# check maintaneance mode
19$User->check_maintaneance_mode ();
20
21# validate csrf cookie
22$User->Crypto->csrf_cookie ("validate", "replace_fields", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
23
24# strip tags - XSS
25$_POST = $User->strip_input_tags ($_POST);
26
27//verify post
28if(empty($_POST['search'])) { $Result->show("danger", _('Please enter something in search field').'!', true); }
29//if device verify that it exists
30if($_POST['field'] == "switch") {
31	if(!$device1 = $Admin->fetch_object("devices", "hostname", $_POST['search']))	{ $Result->show("danger  alert-absolute", _('Switch').' "<i>'. $_POST['search']  .'</i>" '._('does not exist, first create switch under admin menu').'!', true); }
32	if(!$device2 = $Admin->fetch_object("devices", "hostname", $_POST['replace']))	{ $Result->show("danger  alert-absolute", _('Switch').' "<i>'. $_POST['search']  .'</i>" '._('does not exist, first create switch under admin menu').'!', true); }
33
34	//replace posts
35	$_POST['search']  = $device1->id;
36	$_POST['replace'] = $device2->id;
37}
38
39# update
40$Admin->replace_fields ($_POST['field'], $_POST['search'], $_POST['replace']);