Archive for the ‘Web’ Category
Code completion of Portlet API in JSP pages
Friday, April 4th, 2008Including the tag <portlet:defineObjects/> in JSP pages is enough to access portlets specific elements, RenderRequest and RenderResponse. But sometimes, IDE like Eclipse would not offer code completion/assistance by just including that tag.
Including this, instead of the tag:
<%@ page import=”javax.portlet.RenderRequest” %>
<%@ page import=”javax.portlet.RenderResponse” %>
<%@ page import=”javax.portlet.PortletConfig” %>
<%
RenderRequest renderRequest = (RenderRequest)request.getAttribute(”javax.portlet.request”);
RenderResponse renderResponse = (RenderResponse)request.getAttribute(”javax.portlet.response”);
PortletConfig portletConfig = (PortletConfig)request.getAttribute(”javax.portlet.config”);
%>
Including this , Eclipse would offer code completion for you presentation pages.(eg. JSP )
Never forget to include portlet.jar on the build path.

traversing child input items using JQuery
Friday, April 4th, 2008The script.
function getItems() {
childs = $(’#ad’).children();
for(i = 0; i < childs.length; i++) {
// get the value
id = $(childs[i]).attr(”id”);
val = $(childs[i]).val();
$(’#log’).append(id + “=>” + val + “<br/>”);
}
}
<div id=”ad”>
<input type=’text’ id=’text1′ /> <br/>
<input type=’text’ id=’text2′ /> <br/>
<input type=’text’ id=’text3′ /> <br/>
</div>
<div id=”log”>
</div>
<input type=’button’ value=’get’ onclick=’javascript:getItems()’/>

Twitter with Twhirl
Friday, February 1st, 2008Twit Twitter
Wednesday, January 30th, 2008SharedReader and ReadBurner
Sunday, January 27th, 2008checking http proxy server
Saturday, November 17th, 2007There are 3 basic proxy type servers ( Actually I lied, theres more than three) :
1. Anonymous
These HTTP proxy servers does not send a HTTP_X_FORWARDED_FOR, HTTP_FORWARDED, and HTTP_CLIENT_IP variable for a host( the page you are requesting or the host of a website). Those variables are holds the IP address of the requesting side. (But this can be altered, like sending a wrong HTTP request). Your IP Address cannot be logged, but the host will now that a proxy server were used in the connection, by the HTTP_VIA variable.
2. High Anonymous
These kind of HTTP proxy servers does not send a HTTP_X_FORWARDED_FOR, HTTP_FORWARDED, HTTP_CLIENT_IP, HTTP_VIA, HTTP_XROXY_CONNECTION, HTTP_PROXY_CONNECTION. Without these variables, the host can’t determine if youre using a proxy server, and you IP will never be logged.
3. Transparent
Client’s IP address is easily seen by the host, by looking at the HTTP_X_FORWARDED_FOR variable.
This is a fast and dirty code. I assume you have some very basic knowledge using curl in Php.
// file: testsite.php
// A simple if else in checking server variables.
if ( isset($_SERVER[’HTTP_X_FORWARDED_FOR’]) || isset($_SERVER[’HTTP_FORWARDED’]) || isset($_SERVER[’HTTP_CLIENT_IP’]) )
{
if ( isset($_SERVER[’HTTP_VIA’]) )
{
echo “Transparent Proxy Type [PT1]
“;
}
}
if (!isset($_SERVER[’HTTP_X_FORWARDED_FOR’]) && !isset($_SERVER[’HTTP_FORWARDED’]) && !isset($_SERVER[’HTTP_CLIENT_IP’]) )
{
if ( isset($_SERVER[’HTTP_VIA’]) )
{
echo “Anonymous Proxy Type [PT2]
“;
}
}
if (!isset($_SERVER[’HTTP_X_FORWARDED_FOR’]) && !isset($_SERVER[’HTTP_FORWARDED’]) && !isset( $_SERVER[’HTTP_CLIENT_IP’]) )
{
if ( !isset($_SERVER[’HTTP_VIA’]) && !isset($_SERVER[’HTTP_PROXY_CONNECTION ‘]) )
{
echo “High Anonymous Proxy Type[PT3](if your using a proxy)
“;
}
}
// file: index.php
// $proxy = the proxy server, in the form of ip:port
// $test_url = the test site you want to access
// $timeout = number of seconds to wait for the server before considering it a bad request
function check_proxy($proxy, $test_url, $timeout)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $test_url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); /* We what the content of the test site*/
curl_setopt($ch, CURLOPT_HEADER, 1); /* Include the HTTP Header in the content */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); /*We dont want to be follow when we see a Location header when the server sends a response*/
}
if ($transfer = curl_exec($ch))
{
if (!isset($transfer))
{
echo “TimeOut or BAD PROXY
“;
}
else
{
if ( strpos($html_body, “[PT1]”) )
{
echo “Transparent
“;
}
else if ( strpos($html_body, “[PT2]”) )
{
echo “Anonymous
“;
}
else
{
echo “High Anonymous
“;
}
}
}
else
{
echo “TimeOut or BAD PROXY
“;
}
curl_close($ch);
echo ““;
}
checkProxy(”"your proxy server:port”, “testsite.php”, 10);
How it works:
The the index.php script will fetch the content of testsite.php , using a proxy server. If the proxy server is present, testsite.php script will be executed , check the server variables and output one of these [PT1], [PT2], or [PT3] in its content. Basically, $transfer is the html content generated by the testsite.php. This is a stupid trick since we will use a strpos in checking the proxy types.
Checking a thousand proxy in the php script would take you some time. A C program using libcurl, and pthreads would do the job, if you want a batch checking proxy servers. The code tag of this theme sucks.