Create your blog and photo album with postbit
Create your blog and photo album

Create new post


Upload a picture:
Tags (keywords separated by comma)

Save Cancel
webtools:   Followers: 10 ; Following: 2

Explore webtools's photo albums:
Photos from posts (2)
Photos from posts (2)

How to run a simple local web server

Sometimes I just need a simple and fast webserver to test my sites, html pages and CGI scripts but I don't want to install a full webserver like Apache or Nginx.
The fastest way to run a local web server is typing this in the command line:
python -m SimpleHTTPServer
This will display "Serving HTTP on port 8000 ..." and you'll be able to see the current directory and files when accessing your own computer:
You can run multiple web servers at once, but each must be in a distinct port or you'll get the error "Address already in use". Just put the desired port number after the python command (e.g.: how to run python webserver in port 8001):
python -m SimpleHTTPServer 8001

How to run a web server that runs CGI
If you want to run a webserver that also runs CGI, then run:
python -m CGIHTTPServer
The CGI scripts should be in the "cgi-bin" folder. So you need to run the python command in a directory before "cgi-bin" dir.
I am using cygwin command line under Windows 7 and I got an error when running "python -m CGIHTTPServer": - - [30/Aug/2014 19:51:59] "GET /cgi-bin/ HTTP/1.1" 200 -
  Exception happened during processing of request from ('', 51562)
  Traceback (most recent call last):  File "/usr/lib/python2.7/", line 247, in run_cgi    os.setuid(nobody)
  OverflowError: user id is greater than maximum - - [30/Aug/2014 19:51:59] CGI script exit status 0x7f00
It is very easy to correct this error. Just change the error line (line 247 in the script
Change from this: 
to this:
Then the python web server will be able to run cgi scripts. Even Perl scripts will run under this command line web server.

How to run a web server that runs PHP

You can even run php scripts using this python server, but you'll need to add the following lines at the beginning of the php file the follwing 2 lines (followed by a third empty line). Example of php file that will run under "python -m CGIHTTPServer":

Content-type: text/html

1+2 = <?php echo 1+2?>

But the php script must be inside "cgi-bin" directory and must have executable permission (chmod a+x *php). I usually create a symbolic link so I don't need to move php files inside "cgi-bin" directory:
ln -s . cgi-bin



Post by webtools (2014-08-30 20:03)

Post your comment:

Name: Email: Site:

Install nano editor in EC2 server

If you create an EC2 instance in Amazon cloud using 32 bit linux, the old version of nano is installed (2.0.9).

To install the new version, you need to download and compile:


make install

Then you can remove the old version:
rm /bin/nano

The new current version of GNU nano editor will be installed in this path:

It's better to use the new version of the editor because you can use new features and run nano as defined in this alias:
alias p='nano -T 2 -w -c -u'

I have this line above in my .bashrc (bash configuration file), because:

 -u: enable Undo (alt-u) and rEdo (alt-e)
 -w: disable wraping long lines
 -c: show cursor position
 -T 2: Intend tab as 2 spaces

Post by webtools (2014-08-29 13:45)

Post your comment:

Name: Email: Site:

GeoIP - locating IP country and city

GeoIP2 Precision give more city results that were not available in free version.

For example, the GeoIP2 Precision says that IP "" is from the city Ipero, region Sao Paulo, Brazil, ISP and Organization "virtua" (domain, postal code 18560, coordinates (-23.35, -47.6833).
You can test individual IP's using the geoip demo page:

And the free version only finds the country (Brazil).

Free GeoIP database download:
GeoLite2 City (GeoLite2-City.mmdb and .csv)
GeoLite2 Country (GeoLite2-Country.mmdb and .csv)

Sample content of GeoLite2-City-Blocks.csv (first line is header with file format / file structure and following lines are sample data). Size of complete file is 182 Mb:
Sample content of GeoLite2-City-Locations.csv (first line is header / file structure). Size of complete file is 6.4 Mb:
Other GeoIP database (samples):
Available sample files to download:
The full GeoIP Organization (ISP list) costs $25:
The full GeoIP2 City database costs $370:
I downloaded the binary files (free version):
GeoIP.dat (719 kb, contains only country code data) and GeoLiteCity.dat (18 MB, contains country, region and city information)
Note that some IPs can not be found, not even in the Geo IP Precision database.
Example: "The IP address you provided ( cannot be found in our database." (error from maxmind demo site)

How to install Geo::IP (installing and using perl Geo::IP CPAN module):

1) Download Geo IP databases:

 Download page 'GeoLite Country' with updated version of GeoIP.dat.gz:
 gunzip GeoIP.dat.gz; gunzip GeoLiteCity.dat.gz;
 mkdir /usr/local/share/GeoIP
 ln -s GeoIP.dat /usr/local/share/GeoIP/GeoIP.dat
GEOIP TEST SCRIPT (returns country code, 2 letters):
/usr/local/bin/geoip-lookup (IP number)
2) Download and install C API (CAPI):
 make install
3) install Geo::IP perl module from CPAN:
# Not needed: Geo::IP::PurePerl
# If you ge the error "The GeoIP CAPI is not installed you should do that", then install manually. Type in CPAN prompt:
look Geo::IP
cd (path to Geo::IP downloaded source)
perl Makefile.PL LIBS='-L/usr/local/lib' INC='-I/usr/local/include';
make test
make install
If you get the error:  "fatal error: GeoIP.h: No such file or directory", then you need to install the Geo IP C API (CAPI) in step 2 above, because it contains the required libs to compile Geo::IP.

Post by webtools (2014-08-29 12:22)

Post your comment:

Name: Email: Site:

Custom access_log format and awstats

When using Apache web server, I like to have a customized access log format because I have many distinct domains in a single IP using virtualhosts configuration. It's a variation from the NSCA extended common log format with virtual host.

In my virtualhosts.conf, I usually redefine access_log file format to include more useful information. This is what I write in the beginning of the virtual hosts conf file:

LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcombined
CustomLog logs/access_log vcombined
Then inside the tags <VirtualHost *:80> ... </VirtualHost>, this custom log format can be included like this:
CustomLog logs/ vcombined
So it will use the "vcombined" format specified in the beginning of the file above.
Example of the resulting log file (real sample from one of my logs): - - [27/Aug/2014:18:03:23 -0300] "GET / HTTP/1.1" 200 14281 "" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 OPR/23.0.1522.77"
Description of the custom log format using this example:
%V = (host name)
%h = (user's IP number)
%l = - (remote logname from identd)
%u = - (remote user from auth)
%t = [27/Aug/2014:18:03:23 -0300] (date, time and gmt)
\"%r\" = "GET / HTTP/1.1" (Method URL with GET or POST command)
%>s = 200 (status result, 200 OK in this case, could be 404, 500, 301, etc.)
%b = 14281 (size of the answer, number of bytes)
\"%{Referer}i\" = "" (Referer page)
\"%{User-Agent}i\" = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 OPR/23.0.1522.77" (user agent browser)

Web Analytics:
How to run AwStats to process web log files

When I need to process the access log with an anlyser tool (e.g. AWStats), then I need to change the log format in the default configuration file:
AwStats configuration file path: ./awstats-7.4/wwwroot/cgi-bin/
The log file format I need to configure to match my Apache log and use awstats is this:
LogFormat = "%host %host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
Then run awstats with command:
perl -config=my-domain
Warning: If you get the error "Never updated (See 'Build/Update' on awstats_setup.html page)", then check if you put only the name of your configuration file in the "-config=my-domain" (correct). Do NOT run with parameter "" (wrong). This will correct the problem of having zero in all values (awstats all zero, showing only 0, empty stats).
The results stats can be seen using a local web server:
(start this webserver in wwwroot directory, that is cgi-bin previous directory)
Then see the webstats results in your browser:

For some reason the images (icons) were broken and to correct I had to change in the conf file:
DirIcons="/awstatsicons" changed to DirIcons="/icon"

To see geo stats you need to instsall Geo::IPfree perl module and uncomment this line in the conf file:
(see more about GeoIP)

Then you need to run again (rebuild) the stats. Just remove the file "cgi-bin/" (change the date and filename to your file) and rerun awstats again (-update parameter):

perl -config=my-domain -update

AwStats hints:

* If you have multiple log files (a log file split in many parts) you can run awstats with parameter "-LogFile=x" to override the access log path defined in configuration file.
perl -config=my-domain -LogFile=/var/log/httpd/my-domain.access_log

* If you need to consider 301 redirect as a valid requests, change conf file to include "301" (warning: if the redirect is to a page in your own domain, then 1 access will count as 2 pages viewed):

# ValidHTTPCodes="200 304"
ValidHTTPCodes="200 304 301"


Post by webtools (2014-08-27 18:09)

Post your comment:

Name: Email: Site:

Bootstrap Framework

What is Bootstrap?

Bootstrap is a ".css" file plus an optional ".js" file that improves the layout of your html page.

Bootstrap download and bootstrap documentation:

This blog (Postbit) is created with Bootstrap layout.

Files included in

bootstrap/css/bootstrap-responsive.min.css (minified css)
bootstrap/css/bootstrap.min.css (minified css)
bootstrap/js/bootstrap.min.js (minified javascript)

Bootstrap secrets:

There is an optional file in bootstrap (docs.css) that is not part of bootstrap's distribution and contains some precious design gems.

1) The faded out <hr>:

Syntax: <hr class="soften">

This thin hr line is similar to the one found in the Safari default error page, that is ErrorPageDividerLine.png, done without CSS, it's an image line as a png file (686 x 1 pixels):



CSS code to create this <hr> line (faded horizontal rule):

/* Faded out hr */
hr.soften {
  height: 1px;
  background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,.1), rgba(0,0,0,0));
  background-image:    -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,.1), rgba(0,0,0,0));
  background-image:     -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,.1), rgba(0,0,0,0));
  background-image:      -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,.1), rgba(0,0,0,0));
  border: 0;
2) Footer css class

<footer class="footer">
  <div class="container">
    <p>Footer info, copyright, nav links, etc..</p>
Result - footer with separator line, light gray background and gray text:


Bootstrap's docs.css can be downloaded from Twitter Bootstrap git repository:

If you upgrade from Bootstrap 2 to Bootstrap 3, some changes need to be made:

Bootstrap 2 syntax: <input type=text class="input-xlarge">

Bootstrap 3 syntax: <input type=text class="input-lg"> (large height beautiful input button)

Post by webtools (2012-11-01 11:38)

From: Jared
Thankyou - very helpful 2013-08-06 22:15

Post your comment:

Name: Email: Site:

E-commerce features

Features of an e-commerce website:

E-Commerce Administration features:

Back End Features (ecommerce management / admin features):


  • Add new product
  • List price (product price)
  • Discount price
  • Cost price manager (only admin user can view Cost price)
  • Price can be defined by "each" (unit price) or by "weight"
  • Edit product
  • List products
  • Delete products
  • Upload product images and thumbs
  • Product variation (one product can have options like color, size, model with distinct prices)
  • Can create thumbnails automatically from big image files
  • Define max. units in cart for each product
  • Define product keywords to search
  • Search products by id, description, name or category
  • Stock manager (products may or may not have stock control)
  • Define starting date when product will be available in the site (optional)
  • Define last date when product will be removed from site (optional)
  • Manage product listing priority
  • Define if "product is hot deal" (Featured Product)


  • Add new category (Category name, text, listing priority, image upload)
  • List categories
  • Edit categories
  • Create/manage sub-categories
  • Category names in multiple languages
  • Delete categories
  • Assign products to categories


  • Add new customer
  • Customer Shipping information database
  • Customer Billing information database
  • List customers
  • Edit customers
  • Delete customers
  • Search customers by name or id


  • View orders from each customer
  • Search orders
  • Order status (New Orders, Processing Orders, Shipped Orders, Received Orders, Canceled Orders)
  • Send email using backend tool to inform user about order status
  • Print Slip: Create print version of order detail to print and include with product shipping
  • Admin can view selected shipping method
  • Admin can download orders to view using Excel


  • Accept multiple credit cards (Visa, Mastercard, American Express, other cards)
  • Verify valid credit cards online with Cybersource
  • PAYPAL integration


  • Full level administration (with login and password)
  • Second level administration (with login and password), but only with some selected backend options available.
  • Enable HTTPS/SSL (secure server) to do transactions with sensitive data (user information and credit card information)


  • List orders
  • Delete/reject orders
  • Reject partial order (select valid products to accept in each order)
  • View credit card information
  • Manage order status (New, processing, sent, received, canceled)


  • Calculate FEDEX price based on weight, shipping zip code and destination zip code
  • Calculate UPS price based on weight, shipping zip code and destination zip code
  • Calculate USPS price based on weight, shipping zip code and destination zip code
  • Calculate DHL price based on weight, shipping zip code and destination zip code
  • Offer multiple shipping options (1 day, 2 day, 3 days or ground)
  • Calculate best shipping price based on comparision between shipping carriers


  • Fully Customizable Layout of shopping cart and product pages


  • Site content manager to create dynamic pages (e.g.: Contact form, company info, about, privacy policy, history and more)


  • View store front in multiple languages
  • Lock/Unlock store
  • Setup e-mails (admin can receive e-mails with orders)
  • Edit e-mail content (order confirm message to admin and customer)
  • Setup Available Shipping Methods (create, list, edit, delete shipping methods)
  • Setup Payment Methods
  • Language setup
  • Weight Unit setup (Grams, Pounds, Ounces)
  • Backup full store database tool (download and upload)


  • Number of sessions
  • Number of orders
  • Number of shipped orders
  • Number of products
  • Number of customers
  • Number of suppliers

E-commerce Front End Features (user view):

  • Manage stores in multiple languages (English, Spanish, Portuguese and more)
  • Search products by name, description or id
  • List products by category
  • Add/Update/Delete products from shopping cart
  • Stores user info (login, password, shipping and billing info)
  • User can create login and password.
  • Forget password option will send password to user's email
  • User can supply shipping and billing information
  • User can select shipping options (1 day, 2 days, ground...)
  • User can enter Coupon/Promotion Code

See also: Layout ideas for e-commerce websites

Post by webtools (2012-10-30 23:48)

Post your comment:

Name: Email: Site:

Javascript Minifier

How can I minify JavaScript code?

It is important to minify JavaScript code to make it shorter (in number of bytes) so it will improve page load times.
This online tool can be used to paste the original JavaScript code and create the minified version:

The conversion is done by the server using the JavaScript::Minifier Perl tool.

But if you really want to compile and optimize Javascript code, you can use Google Closure Compiler, directly from this page:

Post by webtools (2011-09-22 17:20)

Post your comment:

Name: Email: Site:

Beautify JavaScript Code (Javascript Unminifier)

How can I unminify JavaScript Code?

To "decrypt" minified JavaScript you need to use an online JavaScript beautifier. It is very useful when you have a javascript code that was minified or obfuscated and you need to make it readable again:

Just copy and paste your "ugly" (unformatted or unidented) javascript code into the form and it will re-ident.
It will reformat the js code, including missing "enters" (new lines) and indentation spaces. It will display the total number of bytes and number of lines after beautify.

Based in the Perl code of JavaScript::Beautifier - Beautify Javascript (beautifier for javascript).

Post by webtools (2011-09-20 17:45)

From: Minify Code
Just more suggestion tools to beautify JavaScript CSS and HTML These are fast and easy to use! 2014-05-02 02:52

From: м
не работает ссылка, зато нашел здесь 2012-12-18 08:45

Post your comment:

Name: Email: Site:

Base64 encoder/decoder

How to encode to Base 64 or decode from Base 64 characters?

If you need to encode to or decode from Base64 you can use an online Base64 converter tool:

You just need to paste the text or the Base 64 code in the form and it will do online instant conversion.

Base64 is mainly used to encode email attachments, URL, and multi-part files.
It is also possible to download the decoded result as an attachment binary file using this online Base64 conversion tool.

This is the Perl code used by this online decoder function to encode to (and decode from) Base64:

package Template;
sub Encode_Base64 { # Upper Case to not conflict with MIME::Base64

# Hello World = SGVsbG8gV29ybGQ=

# my $encoded = Encode_Base64 Template($content);
# my $encoded = Encode_Base64 Template($content, "\n");

my $self = shift;

my $encoded = "";
my $end_of_line = $_[1];
$end_of_line = "\n" unless defined $end_of_line;
pos($_[0]) = 0; # ensure start at the beginning

my $i=0;
my $l=length($_[0]);
for ($i=0;$i<$l;$i+=45) {
my $a = substr($_[0],$i,45);
$encoded .= substr(pack('u', $a), 1);

$encoded =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs

# fix padding at the end
my $padding = (3 - length($_[0]) % 3) % 3;

$encoded =~ s/.{$padding}$/'=' x $padding/e if $padding;

# break encoded string into lines of no more than 76 characters each (word wrap)
if (length $end_of_line) {
$encoded =~ s/(.{1,76})/$1$end_of_line/g;

return $encoded;

sub Decode_Base64 {

my $self = shift;

my $str = shift;
my $decoded = "";

$str =~ tr|A-Za-z0-9+=/||cd; # remove non-base64 chars
if (length($str) % 4) {
print STDERR "Base64 decoder requires string length to be a multiple of 4\n";
$str =~ s/=+$//; # remove padding
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format
while ($str =~ /(.{1,60})/gs) {
my $len = chr(32 + length($1)*3/4); # compute length byte
$decoded .= unpack("u", $len . $1 ); # uudecode

return $decoded;


Post by webtools (2011-09-20 17:26)

From: rick
Would love an offline version of this decoder its the only one i have found works 100% 2011-12-09 10:55

Post your comment:

Name: Email: Site:

Environment variables

How to view environment variables?

To list all environment variables (ENV) in your browser, use this online tool to dynamically display the environment vars:

This tool can be used to:

  • List all environment variables received from the browser plus variables generated by the server.

  • Display JavaScript variables already existent in the DOM (Document Object Model) of the generated html page.

  • Upload files with a form and see exact results of how the script in the server side will get and parse the submitted results

  • List cookies in the web page

  • Post a form using GET or POST method and select optional enctype="multipart/form-data" and fill some input form fields to see the raw posted information from the browser to the server.

See also PHP environment variables (and how to list environment variables), including Apache variables and system configuration.

Sample result of the server environment variables generated with this online tool:

Environment variables and other system information
LOCALTIME = Tue Sep 20 16:28:15 2011
OSNAME ( $^O ) = linux

(DOCUMENT_ROOT) = [/virtual/]
(HTTP_ACCEPT) = [text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]
(HTTP_ACCEPT_CHARSET) = [ISO-8859-1,utf-8;q=0.7,*;q=0.3]
(HTTP_ACCEPT_ENCODING) = [gzip,deflate,sdch]
(HTTP_ACCEPT_LANGUAGE) = [en-US,en;q=0.8]
(HTTP_CONNECTION) = [keep-alive]
(HTTP_COOKIE) = [__utma=65499964.634924034.1308594646.1316467809.1316545000.31; __utmb=65499964.12.10.1316545000; __utmc=65499964; __utmz=65499964.1308594646.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)]
(HTTP_HOST) = []
(HTTP_USER_AGENT) = [Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1]
(PATH) = [/sbin:/usr/sbin:/bin:/usr/bin]
(REDIRECT_URL) = [/ambiente]
(REMOTE_PORT) = [62365]
(REQUEST_URI) = [/ambiente]
(SCRIPT_FILENAME) = [/virtual/]
(SCRIPT_NAME) = [/cgi-bin/]
(SERVER_ADMIN) = [root@localhost]
(SERVER_PORT) = [80]
(SERVER_SIGNATURE) = [Apache/2.2.20 (Amazon) Server at Port 80
(SERVER_SOFTWARE) = [Apache/2.2.20 (Amazon)]

Post by webtools (2011-09-20 16:28)

Post your comment:

Name: Email: Site:

  Page 1 of 2 NEXT PAGE >>

| Explore users | New posts | Create your blog | Create your photo album |
| About Postbit | Our blog | Terms of use | Contact Postbit |

Copyright © 2018 -