Pages

Sunday, August 8, 2010

How to install ns-allinone-2.34 in Lucid Lynx

I am listing down the steps to install ns-allione-2.34 in lucid lynx


1. Download ns-allinone-2.34.tar from here.


2. Place it in somewhere, e.g. /home/simulator, then extract it.
$ cd //simulator
$ tar -xvf ns-allinone-2.34.tar



3. Download & install some packages from repository
$ apt-get install build-essential autoconf automake libxmu-dev


4. Install the ns2
$ cd ns-allinone-2.34


5. You might face problem with the installation of otcl-1.13, the problem can be due to the gcc-4.4.1 / g++-4.4.1 compilers. But please try this :
apt-get install g++-4.3
CC=gcc-4.3 CXX=g++-4.3 ./install

try to edit the Makefile.in too
From :
CC= @CC@
to :
CC= gcc-4.3


6. Edit some paths in .bashrc file
$ gedit ~/.bashrc

Put these lines on that file. Off course, you might change /home/simulator for it depends on where you extract ns-allinone-2.34.tar.


# LD_LIBRARY_PATH
OTCL_LIB=/home/simulator/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/simulator/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/home/simulator/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/home/simulator/ns-allinone-2.34/bin:/home/simulator/ns-allinone-2.34/tcl8.4.18/unix:/home/simulator/ns-allinone-2.34/tk8.4.18/unix
NS=/home/simulator/ns-allinone-2.34/ns-2.34/
NAM=/home/simulator/ns-allinone-2.34/nam-1.13/
export PATH=$PATH:$XGRAPH:$NS:$NAM


7. Validate it

$ cd ns-2.34
$ ./validate

(Optionally) You can create a symlink, so that ns can be called from everywhere

$ sudo ln -s /home/simulator/ns-allinone-2.34/ns-2.34/ns /usr/bin/ns

8. Try to run it.
$ ns



external link:http://www.linuxquestions.org/questions/linux-networking-3/ns-installation-wont-let-me-do-it-on-ubuntu-9-10-a-766193/
And here after you can develop and simulate codes using ns :D

Wednesday, April 7, 2010

Mapbender Installation Instructions fo Ubuntu 9.10(Karmic Koala)




Mapbender (2.6+) is shipped with an install script, located at
/mapbender_2.6/resources/db/install_2.6.sh 
(currently for unix-like and windows OS). You will be asked to input several bits of information, after that the installation will proceed automatically. Some of the things mentioned on this page, still apply. Especially all the prerequisites need to be fulfilled, the webserver configuration is not done automatically [Apache configuration, php configuration]. Installation of gettext. And also a final customization of the mapbender.conf has to be done.


Contents

Prerequisites: To be able to install and operate your own copy of Mapbender you need:
  • Webserver (sudo apt-get install apache2)
  • an installation of PHP (sudo apt-get install php5 ; sudo apt-get install php5-pgsql)
    • php-mbstring
    • php-gettext
    • php-gd2
    • php5-imagick
  • Database :Postgresql (sudo apt-get install postgresql-client-8.4 ; sudo apt-get install postgresql-server-dev-8.4)
  • Installation of gettext (sudo apt-get install gettext)

Directories

  • conf - directory for configuration files.
  • http - directory for the application.
  • license - licensing information files
  • log - logfiles will be saved here.
  • resource/db - directory for the SQL-Dump to build up the Mapbender database or update the database.
  • resources/locales - directory contains translation files for different languages (Mapbender.po files, they are basically object files).

Run the install-Script

Database required by Mapbender needs administrative privileges. There is an install-script that creates the database and creates tables and content
  • install_2.6.sh.
./mapbender/resources/db/install_2.6.sh



Apache virtual directory

After installation create a virtual directory. Edit  /etc/apache2/sites-available/default:


Alias /mapbender /var/www/apache2-default/mapbender_2.4.3/http/

       
          Options MultiViews
          DirectoryIndex index.php
          Order allow,deny
          Allow from all
       


You must reload (or stop and restart) the Apache program after making changes to the configuration file to make them take effect.


sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart


If you want to enable directory browsing, e.g. for debugging purposes add Indexes to the Options line. 



Make sure you have loaded the required modules (for example, Ubuntu and Apache2)
a2enmod deflate
a2enmod headers
a2enmod setenvif (for BrowserMatch)

PHP Configuration

You might have to make some adjustments to the file php.ini. Changes in the php.ini also become operative only after restarting the Apache web server !


sudo /etc/init.d/apache2 restart


1. During the test and installation phase of Mapbender it can be helpful log php-errors. Configure the file php.ini as follows:


error_reporting  =  E_ALL & ~E_NOTICE
log_errors = On
error_log = "/var/log/php.log"
 
2. Check the following details in php.ini allow_url_fopen parameter:
extension_dir = (path to extensions-directory)
allow_url_fopen = On
 
3. Mapbender manages access authorization in SESSIONS. Check the following details:
session.save_handler = files
session.save_path = (Path to SESSIONS-Directory). (Check authorisation!)

4. Further details of session management should be customized according to server load (see 'garbage collection' in php.ini)

5. With regard to other modules the extension gd2 should be included in the installation and configuration process.
extension=gd.so              (Linux)



# sudo apt-get install lbgd2-dev 

6. For some Mapbender modules access to a PostgreSQL database is required. If these modules should be used, you have to check the availability of the required extension in the php.ini file:
 
extension=pgsql.so           (Linux)


7. short_open_tag
short_open_tag = OFF


8. Mapbender requires simplexml and dom for XML parsing. If not installed, this will lead to some hard-to-find bugs, because PHP fails to throw exceptions! These modules should be already installed if you are using a Linux distribution, but if you compile PHP yourself you need to include these as well

Mapbender Database

Mapbender offers an install-script (install.sh) that sets up the database for you. The following descriptions shows what is happening.
Mapbender offers an update script (update.sh) that keeps your database upoto-date

PostgreSql Database

The user under which you load the database must have Postgres superuser rights during inserting the psql_*.sql files below so it can temporarily disable constraint triggers during insert.

You have to decide to either use UTF-8 or ISO-8859-1 character encoding.
  • database with UTF-8 encoding
createdb -E UTF8 mapbender
  • database with ISO-8859-1 encoding
createdb -E Latin1 mapbender
First load the empty Mapbender table definiton (schema)
psql -f pgsql_schema.sql 
Then load the data in mapbender/resources/db/postgresql/ - be sure to use the dump with the correct enconding!
  • UTF-8
psql -f pgsql_data.sql  (in subfolder utf8/)
  • ISO-8859-1
psql -f pgsql_data.sql  (in subfolder iso/)
At the end set the constraints and sequences. Here you have to check which PostgreSQL version you are using:
  • pgsql_serial_set_sequences.sql (for 8.x)
psql -f pgsql_serial_set_sequences.sql  
You can install PostGIS as follows (as User postgres (su postgres)):
  • createlang plpgsql (already installed in Mapbender >= 2.5)
  • psql -f lwpostgis.sql -d (change into the PostGIS directory!)
  • psql -f spatial_ref_sys.sql -d (change into the PostGIS directory!)


How to load the sqls in PostgreSQL: You find the SQL: /mapbender/resources/db/postgresql/
Notice: There is a difference between the ISO-8859-1 or UTF-8 data-files. Make sure you choose the right folder (iso or utf8)
psql -f pgsql_schema.sql mapbender
psql -f pgsql_data.sql mapbender
psql -f pgsql_serial_set_sequences.sql mapbender
Check the PostgreSQL log file for any errors during insert.
If you want to update from Mapbender Version 2.2.2 to Mapbender Version 2.2.3 load the sqls in the folder update
  • one column var_name in table gui_element_vars has changed
  • new table mb_user_wmc
  • update of the mapbender guis (admin1, admin2_de, admin2_en, gui and gui1. Notice, that gui_de und gui1_de are not longer part of the standard guis. We want to solve the multilanguage problem with element vars in the following versions)



Mapbender Configuration File mapbender.conf

You find the Mapbender Configuration File in the directory "conf". Here you find the file mapbender.conf-dist. Rename the file to mapbender.conf.
Choose the database you want to use (from Mapbender 2.7 on only PostgreSQL is supported):
define("SYS_DBTYPE", "pgsql"); 
If you use PostgreSQL type your database information here (here is an example):
else {
   define("DBSERVER", "localhost");
   define("PORT", "5432");
   define("DB", "mapbender");
   define("OWNER", "mb");
   define("PW", "mb");
}


perpared statements (PHP > 5.1.x, PostgreSQL > 7.4) define("PREPAREDSTATEMENTS",true);
encoding - default characterset UTF-8 / ISO-8859-1
define("CHARSET","UTF-8");




Define a directory for temporary files, this directory must have write access
define("TMPDIR", "../tmp");
URL for login (test this link to know if your mapbender software is running )
define("LOGIN", "http://localhost/mapbender/frames/login.php");
 define("MAXLOGIN", 3);
 $login = LOGIN;


URL to owsproxy (no terminating slash)
define("OWSPROXY", "http://localhost/owsproxy");


type of server-connection curl, socket, http
#define("CONNECTION", "curl");
 define("CONNECTION", "http");
 #define("CONNECTION", "socket");
define("CONNECTION_PROXY", "");
 define("CONNECTION_PORT", "");
 define("CONNECTION_USER", "");
 define("CONNECTION_PASSWORD", "");


security: path to modules
define("CHECK", false);


mail settings for internal mapbender mails Mapbender can communicate with its users by email. For example, when a user lost his/her password, Mapbender can send an email to this person with a new password.


define("USE_PHP_MAILING", "false");
define("MAILHOST", "");
define("MAILUSERNAME", "");
define("MAILPASSWORD", "");
define("MAILADMIN", "");
define("MAILADMINNAME", "");
$mailHost = MAILHOST;
$mailUsername =  MAILUSERNAME;
$mailPassword =  MAILPASSWORD;


Mapbender error logging
  • Set Mapbender error logging (see possible options below)
define("LOG_LEVEL", "error"); //"off","error","warning","notice" or "all"
define("LOG_JS", "on"); // "on", "alert", "console" or "off"
Internationalisation
define("USE_I18N", true);
  • Define default language
define("LANGUAGE", "de");   // "en", "de", "bg", "gr", "nl", "it", es" 
  • you can change the translations in the Mapbender.po (mapbender/resources/locale/de_DE/Mapbender.po files if you prefer a different translation.
    • You can edit the Mapbender.po files with an editor
    • or with poedit
    • after changing Mapbender.po you have to compile the Mapbender.mo files again, see gettext (make sure that gettext is installed).
Example - How to compile the Mapbender.mo files
msgfmt resources/locale/de_DE/LC_MESSAGES/Mapbender.po -o resources/locale/de_DE/LC_MESSAGES/Mapbender.mo


Change the Permission of log Folder

  • Linux : change the permission of log folder to 777 so that php script can write logs in it.
chmod -R 777 log


Check the Setup

You can check your setup with the script mapbender_setup.php. The script mapbender_setup.php moved to the directory:
/mapbender/tools/mapbender_setup.php
To access the script you have to move it temporary to /mapbender/http/tools/mapbender_setup.php. 

Please notice that for security reasons the directory tools should not be available for external users, as e.g. the mapbender_setup.php displays internal information about your system (PHP version, databasename, database user...). You can protect the directory by htaccess or just remove the tools-directory again after testing.
Run the mapbender_setup.php:
http://localhost/mapbender/tools/mapbender_setup.php
The mapbender_setup.php checks wether all configurations of the mapbender.conf are right and checks some system settings.



After the installation - first Login
After the installtion you can login with the user account root and the inital password root. Make sure to change this password asap in order to secure your Mapbender installation. Go to admin2_en Create and edit user to change the password.
You should not delete the user root. To administrate your applications you should create a new user f.e. admin which you use instead if user root.



If you feel any installation instruction that is causing trouble to you, then feel free to comment on this post. I will surely try to answer them when I get some time :)

Saturday, March 13, 2010

iptables

#icmp-type 0 echo-reply
#icmp-type 8 echo-request

#incoming ping packets
SERVER_IP="192.168.154.7"
iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -d $SERVER_IP -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type 0 -s $SERVER_IP -d 0/0 -m state --state ESTABLISHED,RELATED -j ACCEPT


#outgoing ping packets
SERVER_IP="192.168.154.4"
iptables -A OUTPUT -p icmp --icmp-type 8 -s $SERVER_IP -d 0/0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -s 0/0 -d $SERVER_IP -m state --state ESTABLISHED,RELATED -j ACCEPT


#disable outgoing ICMP request
HOST_TO_BLOCK="192.168.154.4"
iptables -A OUTPUT -p icmp --icmp-type 8 -s 0/0 -d $HOST_TO_BLOCK -j DROP

#disable incoming ICMP request
HOST_TO_BLOCK="192.168.154.7"
iptables -A OUTPUT -p icmp --icmp-type 8 -s$HOST_TO_BLOCK  -d 0/0 -j DROP


SQL HARDENING

#start installation by creating a unique, regular group and user account on the operating system, which will be dedicated to the MySQL database:

groupadd mysql
useradd mysql -c "MySQL Server" -d /dev/null -g mysql -s /sbin/nologin


#compiling and installing MySQL in the /usr/local/mysql directory:

./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --with-mysqld-ldflags=-all-static
make
su
make install
strip /usr/local/mysql/libexec/mysqld
scripts/mysql_install_db
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql

#--with-mysqld-ldflags=-all-static parameter causes the MySQL server to be linked statically which wil simplify the process of chrooting the server

#for installing the software in the /usr/local/mysql directory, run the MySQL daemon with the privileges of the mysql account, and create the mysql.sock socket in the /tmp directory.


#size of the database =medium

cp support-files/my-medium.cnf /etc/my.cnf
chown root:sys /etc/my.cnf
chmod 644 /etc/my.cnf


#start the MySQL server 

/usr/local/mysql/bin/mysqld_safe &


#establishing a connection with the database

/usr/local/mysql/bin/mysql -u root mysql

#Once the connection is successfully established, we can shutdown the database

/usr/local/mysql/bin/mysqladmin -u root shutdown


#securing MySQL is to prepare the chrooted environment, in which the MySQL server will run 


#preparing the chrooted environment

mkdir -p /chroot/mysql/dev
mkdir -p /chroot/mysql/etc
mkdir -p /chroot/mysql/tmp
mkdir -p /chroot/mysql/var/tmp
mkdir -p /chroot/mysql/usr/local/mysql/libexec
mkdir -p /chroot/mysql/usr/local/mysql/share/mysql/english


#access rights to the above directories 

chown -R root:sys /chroot/mysql
chmod -R 755 /chroot/mysql
chmod 1777 /chroot/mysql/tmp


#Next, the following files have to be copied into the new directory structure:

cp /usr/local/mysql/libexec/mysqld /chroot/mysql/usr/local/mysql/libexec/
cp /usr/local/mysql/share/mysql/english/errmsg.sys /chroot/mysql/usr/local/mysql/share/mysql/english/
cp /etc/hosts /chroot/mysql/etc/
cp /etc/host.conf /chroot/mysql/etc/
cp /etc/resolv.conf /chroot/mysql/etc/
cp /etc/group /chroot/mysql/etc/
cp /etc/master.passwd /chroot/mysql/etc/passwords
cp /etc/my.cnf /chroot/mysql/etc/


#From the files: /chroot/mysql/etc/passwords and /chroot/mysql/etc/group we must remove all the lines except the mysql account and group
#Next, we have to build the password database as follows 

cd /chroot/mysql/etc
pwd_mkdb -d /chroot/mysql/etc passwords
rm -rf /chroot/mysql/etc/master.passwd


#creating a special device file /dev/null:

ls -al /dev/null

mknod /chroot/mysql/dev/null c 2 2
chown root:sys /chroot/mysql/dev/null
chmod 666 /chroot/mysql/dev/null


We must also copy the mysql database, which contains grant tables created during MySQL installation:

cp -R /usr/local/mysql/var/ /chroot/mysql/usr/local/mysql/var
chown -R mysql:mysql /chroot/mysql/usr/local/mysql/var



#test if it runs correctly by executing the following command

chrootuid /chroot/mysql mysql /usr/local/mysql/libexec/mysqld &


#/chroot/mysql/etc/my.cnf for MySQL server and /etc/my.cnf for MySQL tools (mysqladmin, mysql, mysqldump)

#To disable listening on the 3306/tcp port, the following parameter should be added to the [mysqld] section of /chroot/mysql/etc/my.cnf:

skip-networking


#disable the use of
LOAD DATA LOCAL INFILE command 

#For SQL Injection vulnerabilities in PHP applications, the following parameter should be added in the [mysqld] section in /chroot/mysql/etc/my.cnf:

set-variable=local-infile=0

#in the [client] section of /etc/my.cnf

socket = /chroot/mysql/tmp/mysql.sock


#changing the database administrator's password

chrootuid /chroot/mysql mysql /usr/local/mysql/libexec/mysqld &

#and change the administrator's password as follows:

/usr/local/mysql/bin/mysql -u root
mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');


#Remove default users/db ,sample database (test) and all accounts except the local root account

mysql> drop database test;
mysql> use mysql;
mysql> delete from db;
mysql> delete from user where not (host="localhost" and user="root");
mysql> flush privileges;


#change the default name of administrator's account (root), to a different one.so it will be difficult to perform brute-force and dictionary attacks on the administrator's password.

mysql> update user set user="mydbadmin" where user="root";
mysql> flush privileges;


#remove the content of the MySQL history file (~/.mysql_history)

cat /dev/null > ~/.mysql_history


#create all databases and accounts which will be used by specific PHP applications.
#should be emphasized that these accounts should have access rights only to the databases which are used by the PHP applications
#should not have any access rights to the
mysql database administrative privileges (FILE, GRANT, ALTER, SHOW DATABASE, RELOAD, SHUTDOWN, PROCESS, SUPER)