Tag Archive for web

Get the IP exposed to the internet

wget -q -O - <a href="http://www.whatismyip.org

" >http://www.whatismyip.org
source

List apache server clients IPs by occurence (with country and provider info)

#!/usr/bin/perl -w
use strict;
#
# List apache server clients IPs by occurence (with country and provider info)
# perl administration web log apache
#
my %ips;
my $logfile = '/var/log/apache2/access.log';
open my $fh, '<', $logfile
or die "cannot open file $logfile: $!
";
#
# hash ip occurences
while (<$fh>) {
$ips{$1}++ if (/^(d+.d+.d+.d+)/);
}
#
# sort ip by occurence and print
# get whois data, parse and print
foreach my $ip (sort { $ips{$b} <=> $ips{$a} } keys %ips) {
print $ips{$ip} . "	" . $ip;
my $result = qx{ whois -B -h whois.ripe.net $ip };
my ($country, $descr) = ('', '');
if ($result =~ /country:s+(w+)/) {
$country = $1;
}
if ($result =~ /descr:s+(.+?)
/) {
$descr = $1 ;
}
print "	" . lc($country);
print "  " . lc($descr) . "
";
}
#
# command line alternative (without dns info):
# awk '{print $1}' /var/log/apache2/access.log | sort | uniq -c

source

Download linked JPEGs from a Web page, on the command line

lwp-request -o links <a href="http://flickr.com/" >http://flickr.com/</a> | grep jpg | perl -pe "chomp; s/.*?(S+jpg)/$1 /;" | xargs wget

#or

lwp-request -o links <a href="http://flickr.com" >http://flickr.com</a> | grep jpg | perl -pe "chomp; s/IMGs*(.*jpg)/$1 /;" | xargs wget

#The following will download the numbered images site.com/gallery/01.jpg through site.com/gallery/16.jpg

perl -e "$i=0;while($i<16){open(WGET,qq/|xargs wget/);printf WGET qq{http://site.com/gallery/%02d.jpg},++$i}"

source

Read local file with XmlHttpRequest

/* Read a file  using xmlhttprequest

If the HTML file with your javascript app has been saved to disk,
this is an easy way to read in a data file.  Writing out is
more complicated and requires either an ActiveX object (IE)
or XPCOM (Mozilla).

fname - relative path to the file
callback - function to call with file text
*/
function readFileHttp(fname, callback) {
xmlhttp = getXmlHttp();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
callback(xmlhttp.responseText);
}
}
xmlhttp.open("GET", fname, true);
xmlhttp.send(null);
}

/*
Return a cross-browser xmlhttp request object
*/
function getXmlHttp() {
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp == null) {
alert("Your browser does not support XMLHTTP.");
}
return xmlhttp;
}

source

css run-time expression

<!--[if lte IE 6]>
<style type="text/css" media="screen">
.wrap,
.searchpanel,
.messages,
.constrain,
.footer div {
width: expression(document.body.clientWidth > 1000 ? "1000px" : document.body.clientWidth < 912 ? "765px" : "98%" );
}
</style>
<![endif]-->

source

Automated UI test with Selenium-RC, WWW::Selenium and Test::More

use WWW::Selenium;
use Test::More tests => 2;  #update to reflect the number of tests to be run

my $sel = WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*iexplore",  # *iehta has more cross-domain privileges than *iexplore
browser_url => "http://mysite.com",
);
$sel->start();
$sel->open("http://mysite.com/testpopup.html");
diag("Check whether the popup is hidden.");
my $canSeePopup = $sel->is_visible("modalWindow");
ok ($canSeePopup == 0, "Popup is not visible.");
diag("Check whether the magic is hidden.");
ok(
$sel->is_visible("modalWindowMagicLayer") == 0,
"CSS magic is hidden... for now."
);
$sel->stop();;

source

Deny Access to .svn Files From Web

RewriteEngine On
RedirectMatch 404 /.svn(/|$)

source

Send emails from the web

<?php
$email = "test@test.de";

/* Absender */
$absender = "Testuser <".$email.">";
/* Rueckantwort */
$reply = $email;
/* Betreff */
$subject = "Kontaktformular";

/* Nachricht */
$message = '
<html>
<head>
<title>BlaBla</title>
</head>
<body bgcolor="#ff4500" link="#FFD700" vlink="#FFD700" alink="#ff7813">
<table width="500" border="0" cellspacing="5" cellpadding="5">
<tr>
<td>
<p>Inhalt der Email</p>
</td>
</tr>
</table>
</body>
</html>
';
/* Baut Header der Mail zusammen */
$headers .= "From: $absender";
$headers .= "Reply-To:$reply";
$headers .= "X-Mailer: PHP/".phpversion()."";
$headers .= "X-Sender-IP: $REMOTE_ADDR";
$headers .= "Content-type: text/html";

/* Verschicken der Mail */
if(mail($email, $subject, $message, $headers)) echo "<tr><td><p>Ihre Nachricht wurde erfolgreich verschickt.</p></td></tr>";
?>

source

submit a POST query with parameters

#! /usr/bin/perl -w
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
#The Perl Black Book, Holzner, p. 1247

=item how to call submit_query():
#Method 1.
my %example = (test1 => 'noah', test2 => 'sussman');
submit_query("http://suburbanangst.com/reg.php", %example);

#Method 2.
submit_query("http://suburbanangst.com/reg.php?test1=foo&test2=bar;");
=cut

sub submit_query {
my ($file, %query) = @_;
my $user_agent = LWP::UserAgent->new;
$user_agent->agent("MSIE/5.5 " . $user_agent->agent);
my $request = POST
#'http://suburbanangst.com/reg.php',
$file,
[%query];
my $response = $user_agent->request($request);
print $response->as_string;
}

source

Aggregate RSS feeds

#! /usr/bin/perl -w
BEGIN {
unshift(@INC, "/home/suburban/public_html/yubaba");
#   Add the directory where this file is to the beginning of @INC
}

use strict;
use CGI qw(:standard);
use RSS2html;
use NoFace;    #old script to scrape weather.com.  broken.

#yubaba.pl is the RSS feed script it should be run by a cron job every half-hour or so.
#sussman may 03

#****************************************************************
# REMEMBER TO REMOVE SLASHDOT FROM rssList.txt BEFORE TESTING!  *
#****************************************************************

#MAIN

my $rss_feeds = "/home/suburban/public_html/yubaba/rssList.txt";  #List of RSS uris, one per line
my $non_rss = "/home/suburban/public_html/yubaba/nonRss.txt";
my $parser = new rss2html;
my $grab = new NoFace;

my $display = new CGI;

#my %syndicate = $grab -> get_facts ($non_rss);
#wtr_high, wtr_low, wtr_cloud_condition, wtr_tomorrow_temp, wtr_tomorrow_cloud

#print $display->header;
#print start_html(-title=>'suburbanangst.com: news',
#		 -head=>Link({-rel=>"stylesheet",
#		 -href=>"http://suburbanangst.com/style.css"})
#		);
print start_html(-title=>'suburbanangst.com: news',
-head=>
Link(
{
-rel=>"stylesheet",
-href=>"http://suburbanangst.com/style.css"
}
),
-script=>
{
type=>"text/javascript",
code=>'setTimeout("window.location.reload(true)", 900*1000); // refresh time in ms'
}
);

print <<HTML;
<table width="100%">
<tr>
<td style="text-align: center;"><a href="bookmarks.html">Bookmarks</a> ||
<a href="http://onemorebug.com">OneMoreBug.com</a> ||
<a href="http://tommyz.net">TommyZ.net</a> ||
<a href="http://OneMoreBug.com/">Web Design Seminar</a>  ||  <a href="/PL/">Perl Scripts</a>
</td>
</tr>
<tr>
<td style="text-align: center;"><a href="help/">Resources</a> ||
<a href="game/">GURPS Teleria</a>
</td>
</tr>
<tr>
<td style="text-align: center;">
<h3>Welcome to Suburban Angst!</h3>
</td>
</tr>
HTML

print "<tr><td style="text-align: center;">";

print "</td></tr><tr><td style="text-align: center;"><a href="http://www.srh.noaa.gov/data/forecasts/NYZ072.php?warncounty=NYC061&city=New+York">Weather</a>  ||  <a href="http://nyt.com">New York Times</a> || <a href="http://google.com">Google</a>  ||  <a href="http://h2odev.law.harvard.edu/ezuckerman/">Google Map</a>";

print "<p></p><!-- <p style="text-align: center;">Last updated ";
print scalar localtime();
print " PST<p/> gotta fix this! -->";

#THE KKK TOOK MY WEATHER CHANNEL AWAY
#print "<p>$syndicate{'wtr_cloud_condition'}, <b>$syndicate{'wtr_high'}</b>,  High/Low: <b>$syndicate{'wtr_low'}.</b>  Precip: <b>$syndicate{'wtr_precip'}.</b>  <i>Tomorrow:</i> $syndicate{'wtr_tomorrow_cloud'}, $syndicate{'wtr_tomorrow_temp'}, precip: $syndicate{'wtr_tomorrow_precip'}.</p>";

print "<a href="http://dailyrotten.com">Daily Rotten</a>  || <a href="http://consumptionjunction.com/content/browse.asp?type=8">Consumption Junction Daily</a> || <a href="http://freshnews.org">FreshNews</a></p>";

print "</td></tr></table>
";

print <<HTML;
<table cellspacing="10" width="60%%" align="center">

HTML

render($rss_feeds);

print <<HTML;
</table>
HTML

print $display->end_html;

#****************************************************************
# SUBROUTINES                                                   *
#****************************************************************

sub render {
$ARGV[0] = shift;            #argument is my RSS feeds
my $counter = 0;             #counts the number of boxes
my $other_counter = 0;       #counts the number of boxes in a column
my $number_of_entries = 0;  #must be an even number.  half the entries go in one column, half in the other.  overflow entries span the whole screen.
#****************
#Assumes we are reading a file with one URL on each line
#****************
while (<>) {
chomp(my $url = $_);

if ($url ne "") {
if ($counter == 0) { print "<tr><!--1a-->";
}

if ($other_counter == 0) {
print '<td class="blogborder"><!--2a-->';
}

$parser -> rss_get ($url);

if ($other_counter >= ($number_of_entries / 2) -1) {
print "<!--2b--></td>";
$other_counter = 0;
}
else {
++$other_counter;
}

if ($counter >= ($number_of_entries) -1 ) {
print "</tr><!--1b-->";
$counter = 0;
}
else {
++$counter;
}
}
}
}

source