I have a client who is using and old (outdated and unsupported) php/perl CMS as an intranet site. In implementing a DRP (Disaster Recovery Plan) they switched all the server references in the code and on the server from the server IP address to a DNS name. This was done using a search and replace :-(
This effectively broke the intranet site. They were able to get most of it back up and running with the exception of logins and how sessions were managed. For some reason, once this CMS saw a domain name instead of an IP address, it changed the path in the cookie to something like this:
mywebserver/http://mywebserver/somesite
from what worked before which was:
mywebserver/somesite
We searched through config files and didn't find anything conclusive to begin with. Then we found some code where cookies were being created and modified it so that after the cookie string was created we did some string manipulation on it like this:
$setcookie =~ s/http:\/\/mywebserver//m
This resets the setcookie var by searching through the setcookie var (it's a multiple line string so we needed to use /m) for the string 'http://mywebserver', replacing it with nothing.
It turned out that the CMS was creating more than one cookie, so we found this bit of code in two more files, added our hack there, and sessions worked again!
I have to confess, I was surprised that this little hack worked.
Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts
Wednesday, November 11, 2009
Tuesday, September 11, 2007
Oracle & perl
Continuing to work with SqlPlus and Oracle 10g. Today I resolved two issues I had with an sql query.
With the first problem, I was passing two parameters into the .sql file and when the sql was executed in the file, along with the selected information, it would output 'old ... my sql here with the params not replaced' and then 'new... my sql here with the params replaced'. Thanks for that, but I know which params I'm replace, I don't need more notification of it. It turns out getting rid of this notification is fairly easy. At the top of the script, just put 'set verify off' and no more 'old...new' junk.
In the second problem (same script) I was doing some division and there were instances where my divisor could be (and was) 0. Sql doesn't like to divide by 0 at all (like pretty much every other language I've worked with). There is a neat little fix to get around this as well. My divisor looked like 'select count(a.blah) from ....' and if you add 'select decode(count(a.blah),0,1,count(a.blah)) from ...' it will substitute a 1 if the selected count is a 0. It worked super.
Messing around with Perl some more, I discovered some good functions. @myArray = split(/~/,$var); will take make an array of strings, seperating them by every '~' found in the string. Working with arrays, push(@myArray, someValue) pushes a new value onto 'myArray'. Pretty basic stuff, I know. I like to celebrate small victories (and remember them for next time).
Can you believe it, I hit a dog riding my bike on the way home from work today. A big doberman. He ran right infront of me. I slammed on my brakes and my rear end came up. I didn't hit him hard - but enough to put my handle bars out of alignment with my front tire a bit. I fixed that at the first red light I stopped at. I also just about hit a snake warming himself on the pavement.
With the first problem, I was passing two parameters into the .sql file and when the sql was executed in the file, along with the selected information, it would output 'old ... my sql here with the params not replaced' and then 'new... my sql here with the params replaced'. Thanks for that, but I know which params I'm replace, I don't need more notification of it. It turns out getting rid of this notification is fairly easy. At the top of the script, just put 'set verify off' and no more 'old...new' junk.
In the second problem (same script) I was doing some division and there were instances where my divisor could be (and was) 0. Sql doesn't like to divide by 0 at all (like pretty much every other language I've worked with). There is a neat little fix to get around this as well. My divisor looked like 'select count(a.blah) from ....' and if you add 'select decode(count(a.blah),0,1,count(a.blah)) from ...' it will substitute a 1 if the selected count is a 0. It worked super.
Messing around with Perl some more, I discovered some good functions. @myArray = split(/~/,$var); will take make an array of strings, seperating them by every '~' found in the string. Working with arrays, push(@myArray, someValue) pushes a new value onto 'myArray'. Pretty basic stuff, I know. I like to celebrate small victories (and remember them for next time).
Can you believe it, I hit a dog riding my bike on the way home from work today. A big doberman. He ran right infront of me. I slammed on my brakes and my rear end came up. I didn't hit him hard - but enough to put my handle bars out of alignment with my front tire a bit. I fixed that at the first red light I stopped at. I also just about hit a snake warming himself on the pavement.
Wednesday, September 5, 2007
Got Something done today!
...or at least, it felt like it. After doing housekeeping with our production application yesterday at work, today was a 'sit down and code' day. Boy did it feel good. I had told myself that I had to get this charting solution finished today or it would turn into a waste of time. It turns out that FusionCharts are super easy to implement, and boy, do they look sharp.
In my 'solution', I'm using Nagios to provide the data, with its 'service-perfdata' process. That file gets big quickly. I just enabled it in the Nagios configuration on Friday last week, and I already had 12 Megs of data. Going through the Nagios documentation and forums, there doesn't appear to be any mechanism to 'roll' this file or archive it or buffer it.... It had me stumped for a while. Then I realized I could just do a simple 'tail -1000 service-perfdata.out > service-perfdata.out' in a shell script with a cron job, and presto - a simple fix.
So, mental note to self.... whenever you're coding a shell script (or any kind of script) that gets run by cron, make all the file paths in the script(s) absolute. I keep on running into this problem. Cron is ignorant about everybody's profile and position.
I just started coding with Perl this summer on this project, and I really like it. Working with arrays is tricky and not very intuitive. Otherwise, though, Perl is fantastic for whipping up something quick. Today I found out that you can use && and || in conditional 'if' statements. That was good. Also, something I've noticed in the past and ran into again today - the 'chop' and 'chomp' functions in perl don't seem to work like the documentation says they should. I ended up having to something like this to get rid of spaces '$var =~ s| ||g' - basically using sed (or the like) to get rid of spaces I didn't want. Perl's localtime() function to convert unix to to something readable worked slick for me today. Another thing I ran into not too long ago - the proper way to concatenate strings in Perl is with '.'
Rode my bike into work today. Just had the pedal axle fixed, and wow, what a difference. The aphids are all over the place right now. After a ride they are just plastered all over me. It's hard to not breathe them in while one rides.
In my 'solution', I'm using Nagios to provide the data, with its 'service-perfdata' process. That file gets big quickly. I just enabled it in the Nagios configuration on Friday last week, and I already had 12 Megs of data. Going through the Nagios documentation and forums, there doesn't appear to be any mechanism to 'roll' this file or archive it or buffer it.... It had me stumped for a while. Then I realized I could just do a simple 'tail -1000 service-perfdata.out > service-perfdata.out' in a shell script with a cron job, and presto - a simple fix.
So, mental note to self.... whenever you're coding a shell script (or any kind of script) that gets run by cron, make all the file paths in the script(s) absolute. I keep on running into this problem. Cron is ignorant about everybody's profile and position.
I just started coding with Perl this summer on this project, and I really like it. Working with arrays is tricky and not very intuitive. Otherwise, though, Perl is fantastic for whipping up something quick. Today I found out that you can use && and || in conditional 'if' statements. That was good. Also, something I've noticed in the past and ran into again today - the 'chop' and 'chomp' functions in perl don't seem to work like the documentation says they should. I ended up having to something like this to get rid of spaces '$var =~ s| ||g' - basically using sed (or the like) to get rid of spaces I didn't want. Perl's localtime() function to convert unix to to something readable worked slick for me today. Another thing I ran into not too long ago - the proper way to concatenate strings in Perl is with '.'
Rode my bike into work today. Just had the pedal axle fixed, and wow, what a difference. The aphids are all over the place right now. After a ride they are just plastered all over me. It's hard to not breathe them in while one rides.
Subscribe to:
Posts (Atom)