Changes of Revision 60
[-] | Changed | _service:set_version:inventory-system.spec |
1
2 %define pkgname inventory-system 3 Name: inventory-system 4 Release: 0 5 -Version: 0.0.rev1694 6 +Version: 0.0.rev1753 7 Url: http://www.linux-administrator.com/ 8 License: GPLv2 9 Group: System 10 |
||
[+] | Changed | _service:recompress:tar_scm:inventory-system-0.0.rev1753.tar.bz2/client/inventory-system.sh ^ |
@@ -1,8 +1,8 @@ #!/bin/bash # Inventory System # Author: Carsten Schoene -# $LastChangedDate: 2012-08-12 12:42:39 +0200 (Sun, 12 Aug 2012) $ -# $Rev: 1694 $ +# $LastChangedDate: 2012-09-09 18:53:04 +0200 (Sun, 09 Sep 2012) $ +# $Rev: 1753 $ # # Default options (can be changed by inventory-system.conf) DEBUG="yes" @@ -39,6 +39,8 @@ modprobe ipmitool getopt +readlink +fdisk " # clean old logfile @@ -82,9 +84,10 @@ # script usage function usage { - echo "Usage: $0 [--help|--uuid|--systemtype|--serial|--cpu|--mem|--product|--arch|--os|--kernel|--mgmtmac|--mgmtip]" + echo "Usage: $0 [--help|--uuid|--disk|--systemtype|--serial|--cpu|--mem|--product|--arch|--os|--kernel|--mgmtmac|--mgmtip]" echo -e "\t--help\t\tShows this help" echo -e "\t--uuid\t\tUUID of this system" + echo -e "\t--disk\t\tRoot disk size of this system" echo -e "\t--systemtype\tSystem image type" echo -e "\t--serial\tSystem serial number (Service Tag)" echo -e "\t--cpu\t\tCPU type" @@ -99,7 +102,7 @@ } RUN_FUNCTIONS="" -args=`${GETOPT} -a -o h -l help,uuid,systemtype,serial,cpu,mem,product,arch,os,kernel,mgmtmac,mgmtip -- "$@"` +args=`${GETOPT} -a -o h -l help,uuid,disk,systemtype,serial,cpu,mem,product,arch,os,kernel,mgmtmac,mgmtip -- "$@"` if [ $? != 0 ] ; then usage fi @@ -114,6 +117,10 @@ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_uuid" shift ;; + -d|--disk) + RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_disk_size_root" + shift + ;; -t|--systemtype) RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_type" shift @@ -177,6 +184,28 @@ echo ${UUID} } +# get the disk size of boot device +function get_system_disk_size_bootdev { + ROOTDEV=`${READLINK} -f /dev/root` + # HP + HP_ROOTDISK=`echo ${ROOTDEV} | ${GREP} "/dev/cciss" | ${SED} -r 's@(/dev/cciss/c[0-9]d[0-9]).*@\1@'` + if [ -z "${HP_ROOTDISK}" ] ; then + # Software Raid + MD_ROOTDISK=`echo ${ROOTDEV} | ${GREP} "/dev/md" | ${SED} -r 's@(/dev/md[0-9]).*@\1@'` + RD=${MD_ROOTDISK} + elif [ -z "${MD_ROOTDISK}" ] ; then + # normale block devices + BL_ROOTDISK=`echo ${ROOTDEV} | ${SED} -r 's@(/dev/x?[hsv]d[a-z]).*@\1@'` + RD=${BL_ROOTDISK} + else + RD=${HP_ROOTDISK} + fi + SIZE=`LANG=C ${FDISK} -l ${RD} | ${GREP} "^Disk /" | ${AWK} '{print $(NF-1)/1024 }'` + debug "SYSTEM-ROOT-DEV: ${RD}" + debug "SYSTEM-ROOTDEV-SIZE: ${SIZE}" + echo ${SIZE} +} + # read serialnumber / service tag with dmidecode function get_system_serial { SYSSERIAL=`${DMIDECODE} -s system-serial-number` @@ -449,6 +478,7 @@ request="" for VAR in get_system_uuid \ get_system_serial \ + get_system_disk_size_bootdev \ get_system_cpu \ get_system_memory \ get_system_manufacturer \ | ||
[+] | Added | _service:recompress:tar_scm:inventory-system-0.0.rev1753.tar.bz2/server/inet4.class.php ^ |
@@ -0,0 +1,163 @@ +<?php +// $LastChangedDate: 2012-08-12 17:00:15 +0200 (Sun, 12 Aug 2012) $ +// $Rev: 1696 $ + +class IPv4 +{ + private $ip_long; + public $ip; + public $cidr; + + function __construct($ip,$cidr) + { + $this->ip = $ip; + $this->ip_long = ip2long($ip); + $this->cidr = $cidr; + } + + function __toString(){ + $methods = get_class_methods($this); + + foreach($methods as $meth){ + if(substr($meth, 0, 2) != '__' && $meth != 'mask2cidr' && $meth != 'cidr2mask'){ + $r[] = $this->$meth(); + } + } + + return json_encode($r); + } + + static function mask2cidr($mask) + { + $mask = ip2long($mask); + $base = ((1<<32)-1); + return 32-log(($mask ^ $base)+1,2); + } + + static function cidr2mask($cidr) + { + $mask = ip2long('255.255.255.255'); + $base = ((1<<$cidr)-1); + return 32-log(($mask ^ $base)+1,2); + } + + function address(){ + return $this->ip; + } + + function cidr() { + return $this->cidr; + } + + function netmask() + { + $netmask = ((1<<32) -1) << (32-$this->cidr); + return long2ip($netmask); + } + + function network() + { + $network = $this->ip_long & (ip2long($this->netmask())); + return long2ip($network); + } + + function broadcast() + { + $broadcast = ip2long($this->network()) | (~(ip2long($this->netmask()))); + return long2ip($broadcast); + } + + function wildcard() + { + $inverse = ~(((1<<32) -1) << (32-$this->cidr)); + return long2ip($inverse); + } + + function availablehosts() + { + $hosts = (ip2long($this->broadcast()) - ip2long($this->network())) -1; + return $hosts; + } + + function availablenetworks() + { + return pow(2, 24)/($this->availablehosts()+2); + } + + function isipin($ip) + { + $lnet=ip2long($this->network()); + $lip=ip2long($ip); + $binnet=str_pad( decbin($lnet),32,"0","STR_PAD_LEFT" ); + $firstpart=substr($binnet,0,$this->mask2cidr($this->netmask())); + $binip=str_pad( decbin($lip),32,"0","STR_PAD_LEFT" ); + $firstip=substr($binip,0,$this->mask2cidr($this->netmask())); + return(strcmp($firstpart,$firstip)==0); + } + + function increment($start,$end) + { + $start_arr = explode('.',$start); + $end_arr = explode('.',$end); + + while($start_arr <= $end_arr) + { + $start_arr[3]++; + if($start_arr[3] == 256) + { + $start_arr[3] = 0; + $start_arr[2]++; + if($start_arr[2] == 256) + { + $start_arr[2] = 0; + $start_arr[1]++; + if($start_arr[1] == 256) + { + $start_arr[1] = 0; + $start_arr[0]++; + } else { + return implode('.',$start_arr); + } + } else { + return implode('.',$start_arr); + } + } else { + return implode('.',$start_arr); + } + } + } + + function is_ip4($ip) + { + if ( preg_match('/^([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])$/',$ip)) + { + return true; + } else { + return false; + } + } + + function is_net4($net) + { + if ( preg_match('/^([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])\/[0-9]{1,2}$/', $net )) + { + return true; + } else { + return false; + } + } + + function reverse_ip4($ip) + { + if ( is_ip( $ip ) ) + { + $iparr = explode(".", $ip); + $rip = $iparr[3] . "." . $iparr[2] . "." . $iparr[1] . "." . $iparr[0]; + return $rip; + } else { + return false; + } + } + +} +?> | ||
[+] | Added | _service:recompress:tar_scm:inventory-system-0.0.rev1753.tar.bz2/server/inv-dhcp4.class.php ^ |
@@ -0,0 +1,40 @@ +<?php +// $LastChangedDate: 2012-08-12 20:31:53 +0200 (Sun, 12 Aug 2012) $ +// $Rev: 1697 $ + +class inv_dhcp4 { + function mac_is_valid($mac) + { + $mac = strtolower(trim($mac)); + if ( preg_match('/[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}/', $mac) ) + { + return true; + } else { + return false; + } + } + + function mac_is_blacklisted($mac) + { + global $config; + $mac = strtolower(trim($mac)); + if ( $mac == "none" ) + { + return false; + } + elseif ( $this->mac_is_valid($mac) ) + { + if ( array_search($mac, $config["isdf"]["dhcp"]["macblacklist"]) === false ) + { + return false; + } else { + return true; + } + } else { + return false; + } + } + +} + +?> |