Thursday, July 21, 2011

SVN path based authorization with LDAP authuntication

We can use LDAP for authentication and "AuthzSVNAccessFile" directive with config file for authorizing.

Configuration as follows

#----------------Apache Config ------------------------#

< Location /repo >
DAV svn
SVNPath /path/to/repo/
SVNListParentPath On
SVNAutoversioning On
SVNReposName "User Repo"
SVNPathAuthz off
AuthBasicProvider ldap
AuthBasicAuthoritative on
AuthzLDAPAuthoritative off
AuthType Basic
AuthName "User Login"
AuthLDAPBindDN ""
AuthLDAPBindPassword password
AuthzSVNAccessFile /etc/apache2/svnaccess.conf
Satisfy All
Require valid-user

< /Location >

#--------------------svnaccess.conf file -----------------------

admin = user1, user2

* = rw

* = r

Tuesday, July 19, 2011

How to backup Cisco configurations without a TFTP

"expect" is a nice linux program that can be used to automate interactive applications. There fore you can used it to execute cisco commands through a linux machine.
Best way to backup the cisco config is using "show run" command but the problem was how to save running config into a separate machine. You can use "expect" program to do that.

First you need to install "expect" program. In ubuntu/debian its easy

apt-get install expect

Then change the "router" and "pass" variables of the following script and execute on a crontab.


# ------------------- config --------------------- #
set router
set pass password
set timeout 1000
set filesave [exec date +%m-%d-%Y]

#------------------------------------------------- #

spawn telnet $router
expect "Password:"
send "$pass\n"
expect ">"
send "en\n"
expect "Password:"
send "$pass\n"

log_file $router--$filesave.cfg
send "term len 0\n"
send "show running-config\n"
expect "end\r"
send "\n"
send "exit\n"

This will save the file in IP--date.cfg format

Monday, July 18, 2011

Python script for Birthday Paradox

Probablity of two people have same birthday is .5 .
More information checkout


# Function to calculate the birthday paradox

def calParadox(in_noOfdates,in_noOfBdaysPerYear):
avg =float(1)
avgnext =float(0)
count =1
curNoOfdates =noOfdates=in_noOfdates
avgList = []

# probablity of two people having same birthday should be equel to .5 for more information
# check wikipedia about birthday problem

while avg >float(.5):
curNoOfdates =curNoOfdates-noOfBdaysPerYear
avg =avg * curNoOfdates/noOfdates
count +=1

if (avgList[-2] -.5) < (.5-avg):
count -=1

return count

# Call the function with parameters of no of birthdays and days per year :)
paradoxVal =calParadox(365,1)
print "Birthday paradox is %d" % paradoxVal