

How to enable the country related chart types in "Graph Alert Data":
--------------------------------------------------------------------


BASE does not come with all the data necessary to display
countries versus number of alerts.  Additional software has to
be installed:


I. Basic support for the mapping of IP addresses to countries:

The BASE package does not include the necessary data.  Any user
must install additional software for this.  Currently there are
two different and alternative possibilities implemented in BASE:


1. Perl module "Geo::IPfree":

BASE does not use the whole module.  But it relies on the
human readable form of the database, that can be produced by the
perl script ipct2txt.pl, which is provided by this perl module:

http://search.cpan.org/CPAN/authors/id/G/GM/GMPASSOS/Geo-IPfree-0.2.tar.gz

The database can be generated as follows:

	cd /usr/lib/perl5/site_perl/5.8.8/Geo/
	perl ipct2txt.pl ./ipscountry.dat /var/www/html/base/ips-ascii.txt
	chown apache.apache /var/www/html/base/ips-ascii.txt
	ls -al /var/www/html/base/ips-ascii.txt
	-rw-r--r-- 1 apache apache 961593 2008-02-27 20:18 /var/www/html/base/ips-ascii.txt

# if you use SELINUX:

	chcon -t httpd_sys_content_t /var/www/html/base/ips-ascii.txt
	ls -alZ /var/www/html/base/ips-ascii.txt
	-rw-r--r--  apache apache user_u:object_r:httpd_sys_content_t /var/www/html/base/ips-ascii.txt

	
Now BASE must be told where to find this database.  This must be
done in base_conf.php:

	$Geo_IPfree_file_ascii = "/var/www/html/base/ips-ascii.txt";




2. Perl module "IP::Country":

Instead of reading ips-ascii.txt BASE can be configured to 
call an external executable during runtime: ip2cc.
This script is provided by the IP::Country module.

http://search.cpan.org/dist/IP-Country/

(requires Geography::Countries as well)

BASE calls ip2cc during runtime, or more precisely, makes
the web server call it. 

For this to work BASE must be told where to find ip2cc
in base_conf.php:

	$IP2CC = "/usr/bin/ip2cc";

or wherever ip2cc is installed ("which ip2cc" tells you the path).



II. World map chart types:

The different countries can be displayed in a world map, that is
included in the BASE distribution.  Unfortunately, there is no
way to tell the PEAR::Image_Graph-0.7.2 library where the world map
and the coordinates file are located.  Their location is rather
hard coded in the library: $PEAR_path/Image/Graph/Images/Maps/


1. Installing:

Therefore the files "world_map6.txt" and "world_map6.png" 
must be installed in the PEAR directory under 
Image/Graph/Images/Maps/

For example:

	pear config-show | grep "PEAR directory"
	PEAR directory     php_dir    /usr/share/pear

Therefore both of these files must be installed under

	/usr/share/pear/Image/Graph/Images/Maps/

This location is hard coded in PEAR::Image_Graph-0.7.2.  It cannot
be configured otherwise by BASE.


2. Licensing and references:

The world map (world_map6.png) has been released as "public domain".  Cf.

http://commons.wikimedia.org/wiki/Image:BlankMap-World6.svg
http://upload.wikimedia.org/wikipedia/commons/0/03/BlankMap-World6.svg
http://upload.wikimedia.org/wikipedia/commons/c/c3/BlankMap-World.png


The coordinates file (world_map6.txt) has been generated by the BASE 
project team and shares the BASE license.  The raw data for it came 
from different sources, but predominantly from the "CIA World Factbook":

https://www.cia.gov/library/publications/the-world-factbook/



III. Troubleshooting:

1. The markers (labels, that point to a country) are messy
and look a bit chaotic:

As of version PEAR::Image_Graph-0.7.2 there are no real solutions
for this.  If it is too annoying, switch them off by commenting
out the following line in base_graph_display.php around line 446:

$Marker->setSecondaryMarker(Image_Graph::factory('Image_Graph_Marker_Pointing_Radial', array(40, &$ValueMarker)));


2. The world map looks too small.

Indeed, the initial size is just 600x300 pixel.  This has been done
deliberately, because right at the beginning you may want to
change some settings in the web form  (for example "Minimum Threshold 
Value").  And for this you need a good overview. But you can increase
it to a size of 1800x913 pixel by clicking at the image once or
twice (depending on your browser habits).  However the web form is then
not visible any more and can only be reaccessed by the "back"-button
or the web browser.

Note: The original size of 1800x913 is a hard coded value.  It cannot
be changed without regenerating the coordinates file world_map6.txt.
Which must be done from external data and requires several steps of
processing.



3. Why is there no legend to the world map?

Good question.  I don't know.  The usual way to add a legend
to a graph doesn't seem to work as of version 0.7.2 of PEAR::Image_Graph:

Even the workaround available on the PEAR::Image_Graph web site ("BUGS") does
NOT help here with maps.

PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 35 bytes) in /usr/share/pear/Image/Canvas.php on line 451, referer: https://localhost/base/base_graph_main.php



4. "You must have at least 3 points in your array...":

In the web server logs can be found the following messages:

PHP Warning:  imagefilledpolygon() [<a href='function.imagefilledpolygon'>function.imagefilledpolygon</a>]: You must have at least 3 points in your array in /usr/share/pear/Image/Canvas/GD.php on line 1004, referer: https://localhost/base/base_graph_main.php

or

PHP Warning:  imagepolygon() [<a href='function.imagepolygon'>function.imagepolygon</a>]: You must have at least 3 points in your array in /usr/share/pear/Image/Canvas/GD.php on line 1023, referer: https://localhost/base/base_graph_main.php


You can either ignore this warning or increase "Minimum Threshold Value"
in the web form.



5. "Undefined offset...":

In the web server logs there can be found the following message:

PHP Notice:  Undefined offset:  2 in /usr/share/pear/Image/Graph/Plotarea/Map.php on line 108, referer: https://localhost/base/base_graph_main.php


This message can safely be ignored.  Your logging level is too high, anyway.
In /etc/php.ini there should be something like:

	error_reporting = E_ALL & ~E_NOTICE



6. "Undefined index...":

In the web server logs there can be found the following message:

PHP Notice:  Undefined index:  Network in /usr/share/pear/Image/Graph/Plotarea/Map.php on line 191, referer: https://localhost/base/base_graph_main.php


This message can be ignored.  And the logging level is too high 
(too sensitive), anyway:

In /etc/php.ini there should be something like:

	error_reporting = E_ALL & ~E_NOTICE




7. A particular font could not be found.

Make sure, the line starting with "Verdana" in fontmap.txt
contains the path to a readable font file. If you do not have
this particular font, map it to something different, e.g.:

Verdana,/usr/share/ghostscript/fonts/default/TrueType/timr____.ttf

The file fontmap.txt can be found in the PEAR directory
under Image/Canvas/Fonts/, e.g.:

/usr/share/pear/Image/Canvas/Fonts/fontmap.txt

One possibility on fedora 9 could be, for example:

rpm -Uvh dejavu-lgc-fonts-2.24-3.fc9.noarch.rpm

vim /usr/share/pear/Image/Canvas/Fonts/fontmap.txt

Verdana,/usr/share/fonts/dejavu/DejaVuLGCSans.ttf
Verdana Bold,/usr/share/fonts/dejavu/DejaVuLGCSans-Bold.ttf
Verdana Bold Italic,/usr/share/fonts/dejavu/DejaVuLGCSans-BoldOblique.ttf
Verdana Italic,/usr/share/fonts/dejavu/DejaVuSans-Oblique.ttf



BTW: A different font name can be chosen in base_graph_display.php.



8. The font sizes are strange/wrong in safe_mode

In safe_mode BASE falls back to a default font and thus cannot
adjust any font sizes.  This is a known issue, for which 
no proper workaround is known for the time being.

According to the docs this should be solvable by adding
the different font directories to

	include_path
and
	safe_mode_include_dir

in /etc/php.ini.

But this does not seem to work... Maybe changing the ownership
of all of the font files to apache.apache helps.  But currently
BASE falls back to the default font in safe_mode in any case.
It does not pay respect to this workaround.



