# $Id: Portfile,v 1.13 2006/07/23 00:28:25 markd Exp $

PortSystem	1.0

name				nedi
version				1.0.w-rc1
revision			1
categories			net
maintainers			markd@opendarwin.org
platforms			darwin

description			Network Discovery Suite

long_description	        A low noise network discovery, management, and inventory \
				system for Cisco networks with a user friendly web interface.

homepage			http://nedi.sourceforge.net
master_sites		        sourceforge:nedi

distname                        ${name}-${version}
extract.suffix			.tgz

checksums			md5 4465eab09f07f22ca714f06815209c1d

depends_lib			port:perl5.8 \
				port:mysql5 \
				port:p5-net-snmp \
				port:p5-net-telnet \
				port:p5-net-telnet-cisco \
				port:p5-algorithm-diff \
				port:p5-dbi \
				port:p5-dbd-mysql

worksrcdir		${name}-${version}

pre-fetch {
        ui_msg "\n #### It is recommended that you pre-install ####\n"
        ui_msg "\n #### port mysql5 with the +server variant.  ####\n"
        ui_msg "\n #### 'port install mysql5 +server'          ####\n"
}

use_configure			no
build {}

extract {}
patch {}

destroot {
	set nedidir ${prefix}/share/

	xinstall -d ${worksrcpath}
	xinstall -d ${destroot}${prefix}/share
	system "cd ${destroot}${prefix}/share  && gzip -dc ${distpath}/${distname}.tgz | \
		/usr/bin/gnutar --no-same-owner -xf -"

# Keep nedi.conf from prying eyes because it has passwords!
	system "chmod 600 ${destroot}${prefix}/share/${name}/nedi.conf"
}

post-destroot {
# Fix paths
       eval reinplace "s|/usr/bin/perl|${prefix}/bin/perl|g" \
                [glob ${destroot}${prefix}/share/${name}/*.pl] \
		[glob ${destroot}${prefix}/share/${name}/inc/*.pl] \
                [glob ${destroot}${prefix}/share/${name}/html/inc/*.pl]

	reinplace "s|netstat|/usr/sbin/netstat|g" \
                ${destroot}${prefix}/share/${name}/inc/libmisc.pl

        reinplace "s|/etc/nedi.conf|${prefix}/share/nedi/nedi.conf|g" \
                ${destroot}${prefix}/share/${name}/html/inc/libmisc.php

# Keep these empty directories
        destroot.keepdirs \
                ${destroot}${prefix}/share/${name}/db/cfg \
		${destroot}${prefix}/share/${name}/html/log
}


post-activate {

ui_msg "\n#### To complete the NeDi OS X installation ####

1) Setup MySQL (for new installs)
-----------------------------------------------
-Configure MySQL:
        sudo -u mysql ${prefix}/lib/mysql5/bin/mysql_install_db

-Start MySQL and set it to run at system boot:
	sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.mysql5.plist

   NOTE: MySQL must have been installed with the +server variant in order to
      use launchctl to run MySQL at system boot.

-Set the root MySQL password:
   Follow the instructions that were given after you executed 'mysql_install_db' above.


2) Install PHP5 with SNMP support and Apache 2
------------------------------------------------
	sudo port install php5 +apache2 +mysql5 +snmp

	sudo ${prefix}/apache2/bin/apxs -a -e -n \"php5\" libphp5.so


3) Turn on Apache 2
------------------------------------------------
   Turn off Apple's Apache 1.3 (Personal Web Sharing in System Preferences).  Then execute
   these commands:

	cd ${prefix}/apache2/conf
	sudo cp httpd.conf.sample httpd.conf

   Edit the user/group variables in the Apache 2 httpd.conf to be your selected NeDi user/group.

   Start Apache 2 and set it to run at system boot:
	sudo launchctl load -w /Library/LaunchdDaemons/org.darwinports.apache2.plist


4) Configure NeDi, initialize database, and Login to NeDi
-----------------------------------------------
-Set NeDi owner: sudo chown -R <nedi-user>:<nedi-group> ${prefix}/share/${name}/
-Apache symlink: ln -s ${prefix}/share/${name}/html/  ${prefix}/apache2/htdocs/nedi
-Edit nedi.conf Backend/Authen/Device Access sections: sudo pico ${prefix}/share/${name}/nedi.conf
	Leave nedi.conf permissions at 600 to protect your network passwords!
backend		MSQ
dbpass		<nedidb-password>
authuser	mysql

comm <my-commnity-string> (community string of your Cisco devices)
<usr> <pass> <enablepass> (user/pass of your Cisco devices)

-Initialize the NeDi database:
	cd ${prefix}/share/${name}
	sudo ./nedi.pl -i
	When prompted for \"MySQL admin user:\" and enter 'root' and then MySQL root password.

-Set Nedi MySQL user to use old style passwords
	mysql -u root -p
	mysql> SET PASSWORD FOR nedi@localhost = OLD_PASSWORD('<nedidb-pwd>');

-Verify the NeDi DB:
        mysql -u root -p
        mysql> use nedi;
        mysql> show tables;
        mysql> exit;

-Login to the NeDi web interface: http://localhost/nedi/index.php
	Initial user/pass is 'admin'/'admin'


5) Discover Your Network with NeDi
-----------------------------------------------
-Edit the seedlist file: pico ${prefix}/share/${name}/seedlist
-Edit nedi.conf Device Acc. variables: sudo pico ${prefix}/share/${name}/nedi.conf

comm <my-community-string>
<usr>  <pass>  <enablepass>

-Make any other desired changes in nedi.conf
-Start NeDi data collection:
	cd ${prefix}/share/${name}/nedi.pl
	sudo -u <nedi-user> nedi.pl -c -d (debug)
-Put a command in the crontab to discover your network at regular intervals.
 	For example, to run NeDi every day at 11:00 and 3:00:
1 11,15 * * * cd ${prefix}/share/${name} ; ./nedi.pl -c >> /dev/null 2>&1
\n"
}
