Click here to Skip to main content
15,890,438 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: The Whole Codebase I inherited [again] Pin
Keith Barrow21-Jun-11 9:06
professionalKeith Barrow21-Jun-11 9:06 
GeneralRe: The Whole Codebase I inherited [again] Pin
AspDotNetDev21-Jun-11 10:15
protectorAspDotNetDev21-Jun-11 10:15 
GeneralRe: The Whole Codebase I inherited [again] Pin
JV999921-Jun-11 20:31
professionalJV999921-Jun-11 20:31 
GeneralRe: The Whole Codebase I inherited [again] Pin
Keith Barrow21-Jun-11 21:24
professionalKeith Barrow21-Jun-11 21:24 
GeneralRe: The Whole Codebase I inherited [again] Pin
JV999921-Jun-11 22:07
professionalJV999921-Jun-11 22:07 
GeneralRe: The Whole Codebase I inherited [again] Pin
Keith Barrow22-Jun-11 8:07
professionalKeith Barrow22-Jun-11 8:07 
GeneralRe: The Whole Codebase I inherited [again] Pin
CDP180222-Jun-11 2:12
CDP180222-Jun-11 2:12 
General(Long) For your enjoyment, legacy PHP web site hell [modified] PinPopular
DoctorOwl20-Jun-11 16:17
DoctorOwl20-Jun-11 16:17 
I submitted this to The Daily WTF and they didn't use it, so here we go.

(PS: I saw it's now in TDWTF Forums. Zecc, I signed up for the forums over a week ago now but it requires admin approval before you can post. Admin appears to be away because I never got approved. I also submitted again to ask them to approve my account so I could use the forums and I got no response. It's not that I just "couldn't be bothered", the whole thing has left me slightly miffed.)

--

A company I work with is replacing a mainframe application with a trendy new version, but it's not complete yet. The old software still published customer data to a website once an hour, and this responsibility had to be handed off to the new system, but "in the old format", until a proper project could be contracted out to make a new website.

It sounded like a nightmare. There was only a production system to work with, all the data had to be extracted in a few CSV formats (incremental and full updates) and transferred over FTP. I was told there was no access to the source code, nobody knew how it worked aside from it being in production for nearly a decade, and the only way to test it would be to click a button that could start a manual import process, quickly check a few screens, and revert the data again with a forced export from the legacy system before anyone could notice anything wrong.

I took it on, for fun.

I started by spending days creating a CSV extract from data in the new system based on the column names that had been provided from the legacy system. Then I compared the data to a previous CSV and found that the old system ignored/munged a whole bunch of those columns and that I had to start from scratch and build a new "purposefully broken extract", just in case the parser on the web-site end (a complete black box at the time) would choke on logically valid data. The one good thing was that the website was supposed to email us with a detailed explanation or where and why any data import failed.

And finally, late one night, we tested it by FTP'd the new data over and clicking the manual import button. And nothing happened. Not even the email.

"It's a disaster!" The format of my data export was assumed incorrect and so bad that the web site couldn't even parse it, so it was thrown back at me. I went over it column by column and could not find any problems. I explained as such, and another developer sent off a complaint to the web hosting company asking if they had messed something up (Why them? "Because it used to work!")

Which is right about the time I noticed the FTP account I had been provided (once switched to PASV mode) had entire access to the web site, which turned out to be a bunch of HTML and PHP scripts, with an ancient MySQL database (username, password, and location) embedded inside. I copied everything to my local machine, cloned the database, and tweaked the script so I could run it locally; but it spewed out a bunch of errors about truncated strings. I determined these were because I was using a way-too-new (anything in the past 5 years) version of MySQL, and had to trawl the internet looking for a binary of the ancient version I wanted to use instead.

And the import worked. When run manually. No problems. The button to do it via the web, was another matter. After looking into it, it had been so many years since the website had been written (let alone maintained), that various PHP APIs had been disabled/deprecated as security risks, and this had likely been upgraded at one stage on the web host. The automatic import processes were ticking along, but the back-end administration buttons which did all kinds of cross-posting would not.

It sounds easy describing that here, but when I first downloaded the site, it took a lot of digging to get there, because the structure was like this:

public_html/form_01.php
public_html/form_01o.php
public_html/form_02.php
public_html/form_02o.php
public_html/publicform.php
public_html/mainform.php
public_html/usermain.php

public_html/admin/form_01.php
public_html/admin/form_01o.php
public_html/admin/form_02.php
public_html/admin/form_02o.php
public_html/admin/publicform.php
public_html/admin/mainform.php
public_html/admin/usermain.php

public_html/www/form_01.php
public_html/www/form_01.bak
public_html/www/form_01o.php
public_html/www/form_02.php
public_html/www/form_02o.php
public_html/www/publicform.php
public_html/www/mainform.php
public_html/www/usermain.php

public_html/www/admin/form_01.php
public_html/www/admin/form_01o.php
public_html/www/admin/form_02.php
public_html/www/admin/form_02o.php
public_html/www/admin/publicform.php
public_html/www/admin/mainform.php
public_html/www/admin/usermain.php


That's right! Your favourite PHP spaghetti! I also later found even more .php files (some active include files with a single/multiple versions, and some more lots of copies) hidden in other subdirectories OUTSIDE the public_html folder.

I could also see that the PHP code was just concatenating a massive INSERT string from all the fields in the CSV without manipulating or sanitising it. Beautiful. But I decided not to touch that, and just change the code on the manual import button to get it working, and it "worked great". Except none of the financial figures showed up properly; some looked like they'd been divided by 100 and had extra numbers tacked onto the end. I pointed this out to the only other person who knew anything about the web site and they told me not to worry as "even the old system does that" and it had always been like this!

I pulled out the PHP code again and had a look, and not being fluent in the language, I had to run to IRC to ask what was happening. Do you see it?

<?=printf("%.2f", $myrow1->x_value);?>


That's right. It was printing dollar amounts, followed by the length of the string. EVERYWHERE.

I bit the bullet and removed the equals sign, tested it, and put the changes out in production myself, and it all worked fine.

Maybe the real WTF is if I was given the proper security in the beginning, I could have saved a few days and pumped the data right into the database instead of going through the PHP side, and also done my own testing in a web browser instead of comparing line-by-line data exports from the old and new systems.

I'm considering rewriting the user-oriented part of the site in ASP .Net as a fun learning project for myself (and getting paid just a little for it once it's done, of course). After all, the standards can't be that high when this was all accepted in the first place...

modified on Thursday, June 23, 2011 9:41 PM

QuestionWhat do you think of my small game made in Windows API RAW? Pin
andyharglesis17-Jun-11 20:36
andyharglesis17-Jun-11 20:36 
AnswerRe: What do you think of my small game made in Windows API RAW? PinPopular
walterhevedeich17-Jun-11 21:38
professionalwalterhevedeich17-Jun-11 21:38 
GeneralRe: What do you think of my small game made in Windows API RAW? Pin
OriginalGriff17-Jun-11 22:33
mveOriginalGriff17-Jun-11 22:33 
AnswerRe: What do you think of my small game made in Windows API RAW? Pin
AspDotNetDev17-Jun-11 22:38
protectorAspDotNetDev17-Jun-11 22:38 
AnswerRe: What do you think of my small game made in Windows API RAW? Pin
H A Tanner18-Jun-11 9:50
H A Tanner18-Jun-11 9:50 
AnswerRe: What do you think of my small game made in Windows API RAW? PinPopular
RobCroll19-Jun-11 21:29
RobCroll19-Jun-11 21:29 
GeneralRe: What do you think of my small game made in Windows API RAW? Pin
Firo Atrum Ventus19-Jun-11 22:07
Firo Atrum Ventus19-Jun-11 22:07 
AnswerRe: What do you think of my small game made in Windows API RAW? Pin
Ravi Sant19-Jun-11 22:26
Ravi Sant19-Jun-11 22:26 
AnswerRe: What do you think of my small game made in Windows API RAW? Pin
0bx20-Jun-11 0:11
0bx20-Jun-11 0:11 
AnswerRe: What do you think of my small game made in Windows API RAW? Pin
Pete O'Hanlon20-Jun-11 0:53
mvePete O'Hanlon20-Jun-11 0:53 
QuestionRe: What do you think of my small game made in Windows API RAW? Pin
Dimitrios Kalemis22-Jun-11 3:10
Dimitrios Kalemis22-Jun-11 3:10 
AnswerRe: What do you think of my small game made in Windows API RAW? Pin
Mark Bunds4-Aug-11 10:46
Mark Bunds4-Aug-11 10:46 
GeneralNot a big one but... Pin
venomation16-Jun-11 9:32
venomation16-Jun-11 9:32 
GeneralRe: Not a big one but... Pin
andyharglesis17-Jun-11 21:01
andyharglesis17-Jun-11 21:01 
GeneralRe: Not a big one but... PinPopular
soap brain17-Jun-11 23:10
soap brain17-Jun-11 23:10 
GeneralRe: Not a big one but... PinPopular
Firo Atrum Ventus19-Jun-11 15:22
Firo Atrum Ventus19-Jun-11 15:22 
JokeRe: Not a big one but... Pin
Ra-one19-Jun-11 20:04
Ra-one19-Jun-11 20:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.