Invoke shell from MySQL trigger

No I am not insane, and after a long days search over the wide Internet, even google admitted defeat, there seemed to be no way to do this. Finally I had already dropped the idea or even let off the thing altogether. But recently for another project I needed to check in for an entirely different requirement and stumbled on the fact. And yes I checked it, voila the shell invoke from mysql trigger is possible.
Continue reading “Invoke shell from MySQL trigger”

String encryption with password

While searching for some thing, I found a string encryption code sample for Visual Basic, and I just wanted the same in php, and did a port. Just like what F. Balena has done over there, this function is also used for both, encrypt as well as decrypt.


<?php
function stringEncrypt($str$pass){
    
$strlen strlen($str);
    
$passIndex 0;
    
$passLen strlen($pass);
    
// null passwords wont encode
    
if(strlen($pass) == 0
        return 
$str;
    for (
$i 0$i $strlen$i++){
        
// get the next char in the password
        
$passChr ord($pass[($i $passLen)]);
        
// encrypt one character in the string
        
$str[$i] = chr(ord($str[$i]) ^ $passChr);
        
// modify the character in the password (avoid overflow)
        
$pass[($i $passLen)] = chr(($passChr 17) & 255);
    }
 return 
$str;    
}

function getIpBehindProxy

We were worried, about all the comments on kerala online, being marked as spam by the akismet plugin. When on detailed examination, we found that the basic problem was that wordpress was logging only the immediate downsteam ip as the remote address, well ours was a bit confusing setup, but to handle the traffic we needed it that way.

A search for wordpress behind reverse proxy, landed me to the wordpress support page. In fact the 5th entry on that page is done by Gopka, who is the lead on this project from Saturn.

We started to correct the remote address by overriding the global variable making slight changes to the wp-config, such that we will not accidentally overwrite the changes while upgrading wordpress. Well the code


if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        
$list explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
        
$_SERVER['REMOTE_ADDR'] = $list[0];
  }


when added to the wp-config, it started to log the first IP, and that would be mostly private IPs if the request was from organisations where internet was shared through proxies or using NAT. The case was same at our office, so we had to find the first public ip from the list of IPs and the code for function getIpBehindProxy was the out come.
Continue reading “function getIpBehindProxy”

Web Spider using php cli

Purely on academic basis, I had once helped to cook up a web spider, which is used to build site maps. The spider was written in php and uses a couple of reg-exp matches, and finally writes the full sitemap from the start url. The system is assembled using two classes, WebPage and WebSpider. Then to make it similar to linux utilities in the command line environment, some functions were scooped in.
Continue reading “Web Spider using php cli”

PHP Opcode Caches, switching between

Opcode Cache

A PHP accelerator is an extension designed to boost the performance of software applications written using the PHP programming language. Most PHP accelerators work by caching the compiled bytecode of PHP scripts to avoid the overhead of parsing and compiling source code on each request (some or all of which may never even be executed). For best performance, caching is to shared memory with direct execution from the shared memory and the minimum of memory copying at runtime. A PHP accelerator typically reduces server load and increases the speed of PHP code anywhere from 2-10 times, depending on factors such as the inherent execution time of the PHP application and the percentage of source code actually executed on a given request. While a code optimizer may even slow down overall performance when used in isolation, it can provide an additional performance boost when coupled with a code cache as the optimization effort is performed just once.
Continue reading “PHP Opcode Caches, switching between”

JavaScript Aggregate; WordPress plugin

Collects all different linked javascripts and replaces with a combined single script, optionally compressed. Based on code originally written by David Holmes, Martin Kliehm, Gaetano Giunta. Uses the PHP adaptation of JSMin, published by Douglas Crockford as jsmin.c, also based on its Java translation by John Reilly.

After reading about Website Performance Tweaks, and a lot of other blogs and slides, I thought about how to cook up a javascript aggregate plugin for wordpress. The out come is wp-jsmin. Though this is in its infancy, it is being used in this blog, to combine all linked javascript to a single link, thereby reducing server requests. This code is still in the testing stage, and may break if the used scripts do not pass lint checks. I am planning to shift all the options to a options page in the wordpress admin page.

Those who are daring enough could download and try. Please put a comment here if you are using this on your wordpress. And for others who would like professional help, I would be most pleased to extend my services through RentACoder. Or for a whole dedicated wordpress team to design, build and maintain sites like Kerala News, Cirrus Travles or Rajeev Gandhi Center for Biotechnology, send an inquiry to Saturn.

Download

Tunning (tuning) WordPress

Tweaking the wordpress 404 template such that error pages for images and other linked items do not go the full blown 404 error page.

Today on the server logs I found about 2900 404 errors triggered from a single IP, the logs are similar as


[IP REMOVED] keralaonline.com - [27/Apr/2009:11:38:34 +0530] "GET /wp-content/uploads/2009/04/photo993.jpg HTTP/1.0" 404 18013 "https://keralaonline.com/wp-content/uploads/2009/04/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
[IP REMOVED] keralaonline.com - [27/Apr/2009:11:38:38 +0530] "GET /wp-content/uploads/2009/04/photo997.jpg HTTP/1.0" 404 18013 "https://keralaonline.com/wp-content/uploads/2009/04/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
[IP REMOVED] keralaonline.com - [27/Apr/2009:11:38:39 +0530] "GET /wp-content/uploads/2009/04/photo999.jpg HTTP/1.0" 404 18013 "https://keralaonline.com/wp-content/uploads/2009/04/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"

one can see that the request is scripted and at a random interval, seems to be a script kiddie trying to leech images, but I got worried that even for this wordpress would go and output my pretty 404 page, which was as you could see is a whopping 17Kb, and takes about half a second to build. So just gave a twist and modified the top area of my 404 template Continue reading “Tunning (tuning) WordPress”

function is_ipaddress

Well this may not be new to you all, but still, when I was on the lookout how I could validate an ip address, all the regular expression techniques either failed on valid addresses or bloated too much. The out come was wrote a piece of code which may help others if this is correct, in its way. Not sure, since most of the addresses which I tested against the other validation methods, and failed or non valid ones which passed were blocked here.
Still I am not the ultimate, if you have better suggestions than the code given here, please do so. Continue reading “function is_ipaddress”

FLV Streaming with PHP

For pseudostreaming I did see some of the projects and suggestions which used a serverside scripting language, to achieve the same as the plugins or modules for the web server software does. Ports in perl, php and python as well as shell was also found, but all were bloated, that they were not transparent. So I thought I would give a try.

Pseudostreaming is a protocol that can be installed on regular HTTP servers such as Apache, Tomcat, IIS or lighthttpd. It uses a server side script for Flash-to-server communication. The player sends a HTTP request to the server with a start time parameter in the request URL’s query string and the server script responds with the video stream so that its start position corresponds to the requested parameter. This start time parameter is usually named simply start. This same technique is used by the ultra-popular YouTube service which uses lighthttpd servers.
Continue reading “FLV Streaming with PHP”