Archive

Archive for the ‘Code’ Category

Execute MySQL Script from Java

January 20th, 2005 Tony 6 comments

Ant is a great tool for deployment but I found that it simply wasn’t powerful enough to handle all my needs. So I’ve been developing some deployment tools to make it easier for me to deploy new code releases. One necessity was to be able to execute a MySQL script from Java. The following function will do the job. One note, this function requires that the location of the MySQL executable is in your machine’s path variable.


public static String executeScript (String dbname, String dbuser,
String dbpassword, String scriptpath, boolean verbose) {
String output = null;
try {
String[] cmd = new String[]{"mysql",
dbname,
"--user=" + dbuser,
"--password=" + dbpassword,
"-e",
"\"source " + scriptpath + "\""

};
System.err.println(cmd[0] + " " + cmd[1] + " " +
cmd[2] + " " + cmd[3] + " " +
cmd[4] + " " + cmd[5]);
Process proc = Runtime.getRuntime().exec(cmd);
if (verbose) {
InputStream inputstream = proc.getInputStream();
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

// read the output
String line;
while ((line = bufferedreader.readLine()) != null) {
System.out.println(line);
}

// check for failure
try {
if (proc.waitFor() != 0) {
System.err.println("exit value = " +
proc.exitValue());
}
}
catch (InterruptedException e) {
System.err.println(e);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return output;
}

Categories: Code Tags:

Change the Appearance of a Gallery Website Photo Album

January 4th, 2005 Tony No comments

If you want to change the appearance of a Gallery website photo album, navigate to the directory gallery/html_wrap (assuming gallery/ is the root folder of your Gallery installation). This folder contains header and footer files for all pages in Gallery.

Once you’ve found this folder its pretty easy to guess which files control the header and footer of particular pages. For instance:

gallery.header.default = HTML header for the main index page
album.header.default = HTML header for all albums
photo.footer.default = HTML footer for individual photo pages

For safety I create a backup of the file before changing it:

cp gallery.header.default gallery.header.default.BAK

Categories: Code Tags:

phpBB Exploit – howdark Exploit

December 11th, 2004 Tony 8 comments

There is a serious exploit in phpBB that requires immediate patch.

Patch

If you maintain a site running phpBB forums load this patch immediately. Apparently the exploit allows the hacker to gain root access to mySql. Many sites have been hacked including phpBB’s own support forum. Ouch.

I haven’t been able to find much info on how the exploit works. The code change in this patch seems trivial and I still don’t understand how it fixes the problem with the forums. If anyone has more insight I would love to hear.

Supposedly this is only a temporary patch and we need to stay tuned for a permanant fix.

Full discussion on the security flaw including input from ‘jessbunny’, the user that reported the problem and then proceded to use the exploit against phpBB.com

Categories: Code Tags:

need help with a regular expression? regex coach

October 18th, 2004 Tony No comments

regular expressions can get complex and difficult to visualize. don’t pull your hair out. Regex Coach is an amazing application that can break down a complex regular expression in the simplest of terms and do it in real time!

Categories: Code Tags:

Upgrading Apache with CPanel – PHP loses with cURL Setting

October 12th, 2004 Tony 4 comments

If CPanel WHM warns you that you need to upgrade Apache and you click the link ‘Click here to upgrade’ be forewarned that it recompiles PHP and does not remember any options you had previously chosen. So if you are currently using cURL and perform an Apache upgrade via CPanel you will find that PHP is no longer configured ‘–with-curl’.

Instead scroll down the left side to the ‘Software’ section and click ‘Update Apache’. On the following screen make sure the boxes for cURL, cURL SSL, and mcrypt are checked. I’ve found that leaving any of these unclicked results in PHP not compiling with cURL.

Categories: Code Tags: