Parsing a Config File in PHP

December 13th, 2007

This is a sample code to parse a config file in PHP

$mosConfig_CONFIG_IDE=Y
$mosConfig_HOST=localhost


while (!feof($fp)) {
$line = trim(fgets($fp));
if (ereg('\$mosConfig_', $line)) {
$line = ereg_replace ('\$mosConfig_',"",$line);
$pieces = explode("=", $line);
$option = trim($pieces[0]);
$value = trim($pieces[1]);
$value = ereg_replace ("^\'","",$value);
$value = ereg_replace ("\'\;$","",$value);
$config_values[$option] = $value;
}
}
fclose($fp);

Upgrading all CPAN Modules

November 27th, 2007

This command line interface will check and upgrade all CPAN library in your system.

perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'

Change Remote Desktop Default RDP Port

November 25th, 2007

To change the listening port on Microsoft Windows.

Run “regedit”

Change the port value under the following key.

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp\PortNumber

Setup SMTP Auth in sendmail

October 30th, 2007

This is a simple how-to to configure SMTP authenication in Sendmail.

1. install sendmail-cf rpm
#> yum install sendmail-cf

2. edit /etc/mail/sendmail.mc, verify it contains the following options

define(`SMART_HOST’, `cluster9out.us.messagelabs.com’)dnl
define(`confAUTH_OPTIONS’, `A’)dnl
TRUST_AUTH_MECH(`LOGIN PLAIN’)dnl
define(`confAUTH_MECHANISMS’, `LOGIN PLAIN’)dnl
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)dnl

3. execute this command
#> cd /etc/mail
#> make
#> service sendmail restart
#> /usr/sbin/saslauthd -a shadow

4. edit /etc/rc.d/rc.local, add the line below
/usr/sbin/saslauthd -a shadow

Remove “Editor” Field in Community Builder on the CB Profile Page

October 13th, 2007

Global Site Configuration -> Turn “Frontend User Params” to NO.

Joomla Query Optimization

October 1st, 2007

http://custompcsoftware.com/blog/2007/04/19/joomlas-non-optimized-search-in-contentsearchbotphp/

http://custompcsoftware.com/blog/2007/03/06/opensef-rc5-sp2-perfomance-improvement/

http://www.ircmaxell.com/articles/joomla/improving-joomlas-queries.html

Regular Expression to replace all characters except …

September 17th, 2007

link.replace(/[^0-9]/g,'')

Extracting the last part of the url

September 17th, 2007

link.substring(link.lastIndexOf('/')+1,link.lastIndexOf('.'))

Check Current Available Bandwidth

August 11th, 2007

Welcome to Bandwith Check Utility Home page.

Bandwidth Check is a small utility that helps an administrator measure the available bandwidth. In order to make use of this utility, you will need to turn on the chargen service, which is provided in many inetd implementations.

In order to make use of this utility, you will need to turn on chargen protocol.

To enable chargen on Linux:
create the following file /etc/xinetd.d/charge
service chargen
{
type = INTERNAL
id = chargen-stream
socket_type = stream
protocol = tcp
user = root
wait = no
disable = no
}
service xinetd restart

To Compile bwcheck
gcc -o bwcheck bwcheck.c

To execute
./bwcheck

./bwcheck 172.16.11.2
Throughput: 73390.74 kb

FINDMAC

August 11th, 2007

I have written a script to search for mac address on a cisco network – findmac 1.3b2

findmac is a utility written in Perl that helps administrators find out exactly which switch and which port a host is patched into. Only CISCO equipment with CDP enabled is currently supported. It is a very useful tool for administrators of large scale CISCO networks.

You can download it from here –
http://www.vicosys.com.hk/findmac/findmac.v13b2.tar.gz

# ./findmac.pl -h pigeon

Quote:
findmac 1.0 by Terence Chan (26 Feb 2003)pigeon Mac Address is 08:00:20:A9:C3:E0
08:00:20:A9:C3:E0 is found on 172.16.188.155 port FastEthernet0/1

# ./findmac.pl -m 00-00-0c-07-ac-10

Quote:
findmac 1.0 by Terence Chan (26 Feb 2003)This is a router.
00-00-0c-07-ac-10 is found on 172.16.2.1 port 3/1

#./findmac.pl -i -p -h pigeon

Quote:
findmac.pl 1.3b by Terence Chan (6 March 2003)pigeon MAC Address is 08:00:20:A9:C3:E0
12F17.HF.SWT-A (172.16.2.1) port 3/6 => (172.16.188.155)
sw-mcr-backbone-02 (172.16.188.155) port FastEthernet0/19 => (172.16.188.150)
sw-mcr-backbone-01 (172.16.188.150) port FastEthernet0/1 => 08:00:20:A9:C3:E0