You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
			
		
		
		
		
			
		
			
				
					
					
						
							117 lines
						
					
					
						
							3.5 KiB
						
					
					
				
			
		
		
	
	
							117 lines
						
					
					
						
							3.5 KiB
						
					
					
				<?php
 | 
						|
/*****************************************************************************
 | 
						|
IP Reg, a PHP/MySQL IPAM tool
 | 
						|
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
 | 
						|
Copyright (C) 2011-2023 Thomas Hooge
 | 
						|
 | 
						|
SPDX-License-Identifier: GPL-3.0-or-later
 | 
						|
*****************************************************************************/
 | 
						|
 | 
						|
include("includes.php");
 | 
						|
include("header.php");
 | 
						|
 | 
						|
 | 
						|
// get string that was searched for ($search is already set in header.php)
 | 
						|
if (empty($search)) {
 | 
						|
    // parse nosearch box
 | 
						|
    $smarty->assign("nosearch", TRUE);
 | 
						|
    $smarty->display("search.tpl");
 | 
						|
    $smarty->display("footer.tpl");
 | 
						|
    exit;
 | 
						|
}
 | 
						|
 | 
						|
// hide nosearch box
 | 
						|
$smarty->assign("nosearch", FALSE);
 | 
						|
$smarty->assign("search", $search);
 | 
						|
 | 
						|
$needle = '%' . $search . '%';
 | 
						|
$resultcounter = 0;
 | 
						|
 | 
						|
// asset
 | 
						|
$sql = "SELECT a.asset_id AS id, a.asset_name AS name, 
 | 
						|
            CONCAT(LEFT(asset_info, 50), IF(CHAR_LENGTH(asset_info)>50,'...','')) AS description,
 | 
						|
            c.assetclass_name AS assetclass
 | 
						|
        FROM asset AS a LEFT JOIN assetclass AS c USING (assetclass_id)
 | 
						|
        WHERE a.asset_name LIKE :needle OR a.asset_hostname LIKE :needle
 | 
						|
		   OR a.asset_info LIKE :needle
 | 
						|
        ORDER BY a.asset_name";
 | 
						|
$sth = $dbh->prepare($sql);
 | 
						|
$sth->execute(['needle' => $needle]);
 | 
						|
 | 
						|
$assets = $sth->fetchAll();
 | 
						|
$resultcounter += count($assets);
 | 
						|
$smarty->assign("assets", $assets);
 | 
						|
 | 
						|
// location
 | 
						|
$sql = "SELECT location_id AS id, location_name AS name
 | 
						|
        FROM location
 | 
						|
        WHERE location_name LIKE :needle OR location_info LIKE :needle
 | 
						|
        ORDER BY location_name";
 | 
						|
$sth = $dbh->prepare($sql);
 | 
						|
$sth->execute(['needle' => $needle]);
 | 
						|
 | 
						|
$locations = $sth->fetchAll();
 | 
						|
$resultcounter += count($locations);
 | 
						|
$smarty->assign("locations", $locations);
 | 
						|
 | 
						|
// node
 | 
						|
$sql = "SELECT node_id AS id, node_ip AS ip,
 | 
						|
            CONCAT(LEFT(node_info, 30), IF(CHAR_LENGTH(node_info)>30,'...','')) AS info
 | 
						|
        FROM node
 | 
						|
	    WHERE node_ip LIKE :needle OR node_mac LIKE :needle
 | 
						|
           OR node_dns1 LIKE :needle OR node_dns2 LIKE :needle
 | 
						|
           OR node_info LIKE :needle
 | 
						|
        ORDER BY node_ip";
 | 
						|
$sth = $dbh->prepare($sql);
 | 
						|
$sth->execute(['needle' => $needle]);
 | 
						|
 | 
						|
$nodes = $sth->fetchAll();
 | 
						|
$resultcounter += count($nodes);
 | 
						|
$smarty->assign("nodes", $nodes);
 | 
						|
 | 
						|
// subnet
 | 
						|
$sql = "SELECT subnet_id AS id, subnet_address AS address
 | 
						|
        FROM subnet
 | 
						|
        WHERE subnet_address LIKE :needle OR subnet_info LIKE :needle
 | 
						|
        ORDER BY subnet_address";
 | 
						|
$sth = $dbh->prepare($sql);
 | 
						|
$sth->execute(['needle' => $needle]);
 | 
						|
 | 
						|
$subnets = $sth->fetchAll();
 | 
						|
$resultcounter += count($subnets);
 | 
						|
$smarty->assign("subnets", $subnets);
 | 
						|
 | 
						|
// vlan
 | 
						|
$sql = "SELECT vlan_id AS id, vlan_name AS name
 | 
						|
        FROM vlan
 | 
						|
        WHERE vlan_name LIKE :needle OR vlan_info LIKE :needle
 | 
						|
        ORDER BY vlan_name";
 | 
						|
$sth = $dbh->prepare($sql);
 | 
						|
$sth->execute(['needle' => $needle]);
 | 
						|
 | 
						|
$vlans = $sth->fetchAll();
 | 
						|
$resultcounter += count($vlans);
 | 
						|
$smarty->assign("vlans", $vlans);
 | 
						|
 | 
						|
// setup zone
 | 
						|
$sql = "SELECT zone_id AS id, zone_origin AS origin
 | 
						|
        FROM zone
 | 
						|
        WHERE zone_origin LIKE :needle OR zone_soa LIKE :needle
 | 
						|
           OR zone_hostmaster LIKE :needle OR zone_ns1 LIKE :needle
 | 
						|
           OR zone_ns2 LIKE :needle OR zone_ns3 LIKE :needle
 | 
						|
           OR zone_mx1 LIKE :needle OR zone_mx2 LIKE :needle
 | 
						|
           OR zone_info LIKE :needle
 | 
						|
        ORDER BY zone_origin";
 | 
						|
$sth = $dbh->prepare($sql);
 | 
						|
$sth->execute(['needle' => $needle]);
 | 
						|
 | 
						|
$zones = $sth->fetchAll();
 | 
						|
$resultcounter += count($zones);
 | 
						|
$smarty->assign("zones", $zones);
 | 
						|
 | 
						|
// grand totals
 | 
						|
$smarty->assign("resultcounter", $resultcounter);
 | 
						|
 | 
						|
$smarty->display("search.tpl");
 | 
						|
 | 
						|
$smarty->display("footer.tpl");
 | 
						|
 |