HowTo: Fortune & Cowsay

Administration, Funstuff, Info.Tech, Learn New Things, Linux System Administration Comments Off on HowTo: Fortune & Cowsay

fortune_cowsay

While working, I envy the terminal of my workmate, Roland Heymanns, showing a cow with quotes. So I install my own too.

OS: Kali Linux (Debian)

How to install:

root@mojo:~# apt-get install -y fortune cowsay

Then add the commands to your PATH

root@mojo:~# cd ~
root@mojo:~# nano .profile

or

root@mojo:~# cd ~
root@mojo:~# nano .bash_profile

Add the following to the end of the file (be sure its the right path for fortune and cowsay):

PATH=$PATH:/usr/games
export PATH

Save and exit. Next edit your .bashrc

root@mojo:~# cd ~
root@mojo:~# nano .bashrc

Add the the following lines to the end of the file…

fortune | cowsay -d

or if you don’t want to set the PATH, simply edit your .bashrc and at the end of the file, add this line:

/usr/games/fortune | /usr/games/cowsay -d

That’s it… log off and log in again. Open your terminal, you’ll have your cow greetings.

In case you get an error like you cant locate fortune or fortune-mod or cowsay (most likely you will encounter this if you install your OS offline), update your source.list.

root@mojo: ~# nano /etc/apt/source.list

then replace the source with the following:

## Regular repositories
deb http://http.kali.org/kali kali main non-free contrib
deb http://security.kali.org/kali-security kali/updates main contrib non-free
## Source repositories
deb-src http://http.kali.org/kali kali main non-free contrib
deb-src http://security.kali.org/kali-security kali/updates main contrib non-free

then do the update and upgrade…

apt-get clean
apt-get update
apt-get upgrade

I think that would solve the problem…

Code Igniter: Cannot get POST values

Administration, Code Igniter, Info.Tech, PHP, Web Development Comments Off on Code Igniter: Cannot get POST values

I encountered this issue in Code Igniter that I cannot get the POST values. Some says its the .htaccess issue. I used same .htaccess with all my application and works fine. I was working on my new environment, Kali Linux, and realised that its the mod_rewrite module wasn’t loaded and partly affects the .htaccess.

# cd /etc/apache2/mods-enabled/
# locate mod_rewrite
/usr/lib/apache2/modules/mod_rewrite.so
# touch rewrite.load
# nano rewrite.load

At the file:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

Save the changes and restart apache.

Hope this will help you… Pee coding!

Allow postfix to send email with different sender from SMTP account

Administration, Info.Tech, Linux System Administration, PHP, Web Development Comments Off on Allow postfix to send email with different sender from SMTP account

Allow postfix  to send email with different sender from SMTP account…

Error:

postfix/smtpd[27402]: NOQUEUE: reject: RCPT from unknown[125.123.123.100]: 553 5.7.1 <user@xxx.co.nz>: Sender address rejected: not owned by user user@xxx.co.nz; from=<xxx@xxx.co.nz> to=<xxx@gmail.com> proto=ESMTP helo=<localhost>

Edit postfix configuration:

[root@mail ~]# nano /etc/postfix/main.cf

Change from:

smtpd_sender_restrictions = permit_mynetworks, reject_sender_login_mismatch, permit_sasl_authenticated

To:

smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated

Then restart postfix…

[root@mail ~]# postfix stop
postfix/postfix-script: stopping the Postfix mail system
postfix/postfix-script: waiting for the Postfix mail system to terminate
[root@mail ~]# postfix start
postfix/postfix-script: starting the Postfix mail system
[root@mail ~]#

That’s it.. You can now change your from or reply-to in your PHPMailer. 🙂

Hope this helps…

HowTo: iRedMail 0.8.6

Administration, Info.Tech, Linux System Administration Comments Off on HowTo: iRedMail 0.8.6

This guide will cover the following:

  • Install iRedMail
  • Disable Greylisting
  • Enable Catch-All
  • Email Forwarder

Reference: HowToForge: iRedMail: Build A Full-Featured Mail Server On CentOS 6 With Postfix, Dovecot, PostgreSQL

First of all, its better your server is a clean install.

Download iRedmail at http://www.iredmail.org/download.html

tar -xvjf iRedMail-0.8.6.tar.bz2

cd iRedMail-0.8.6

bash iRedMail.sh

Just follow the wizard installation and after installation, do the following commands: (just some few fixes)

ln -s /etc/amavisd/amavisd.conf /etc/amavisd.conf

amavisd showkeys

Add the DKIM keys to your DNS and configure SPF too then you may test by casting the commands below;

Refer to:

  1. http://code.google.com/p/iredmail/wiki/DNS_SPF
  2. http://code.google.com/p/iredmail/wiki/DNS_DKIM
amavisd testkeys

After reboot, we will now disable greylisting.

nano /etc/policyd/cluebringer.conf

Change from:

# Access Control module
[AccessControl]
enable=1

# Greylisting module
[Greylisting]
enable=1

# CheckHelo module
[CheckHelo]
enable=1

# CheckSPF module
[CheckSPF]
enable=1

# Quotas module
[Quotas]
enable=1

to:

# Access Control module
[AccessControl]
enable=1

# Greylisting module
[Greylisting]
enable=0

# CheckHelo module
[CheckHelo]
enable=1

# CheckSPF module
[CheckSPF]
enable=1

# Quotas module
[Quotas]
enable=1

Then reboot your server. (Don’t know how to restart the policyd) hehehe..

Next is enable the Catch-All;

nano /etc/postfix/mysql/domain_alias_catchall_maps.cf

Change from:

query       = SELECT alias.goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain='%d' AND alias.address=CONCAT('%u', '@', alias_domain.target_domain) AND alias_domain.target_domain=domain.domain AND alias.active=1 AND alias_domain.active=1 AND domain.backupmx=0

to:

query       = SELECT alias.goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain='%d' AND (alias.address=CONCAT('%u', '@', alias_domain.target_domain) OR alias.address=CONCAT('@', alias_domain.target_domain)) AND alias_domain.target_domain=domain.domain AND alias.active=1 AND alias_domain.active=1 AND domain.backupmx=0

Save then restart postfix;

postfix stop

postfix start

Now catch-all is now enable in postfix. Next thing is add which domain to catch-all and where to go. Login to MySQL as root, use vmail database and add to the following rows to alias table.

INSERT INTO alias (address, goto, domain) VALUES ('@sample.co.nz', 'user@sample.co.nz', 'sample.co.nz');

INSERT INTO alias (address, goto, domain) VALUES ('@test.sample.co.nz', 'user@sample.co.nz', 'test.sample.co.nz');

Aside from catch all, you can setup the email forwarder too;

INSERT INTO alias (address, goto, domain) VALUES ('info@sample.co.nz', 'user@sample.co.nz', 'sample.co.nz');

All done.. its self explanatory… Hehehe…

Hope this helps.

 

Some Reference:

Git: Can’t push problem

Administration, Info.Tech, Linux System Administration Comments Off on Git: Can’t push problem

My workmate, Sid Bachtiar, was working on our git repo server and we’re having issue on pushing the files. It keep us telling nothing to push.

Solution:

[root@git helpdesk]# find /home/git/repotest.git -type d -exec chmod 775 {} +

or if still doesnt work…

[root@git helpdesk]# chmod 775 -R /home/git/repotest.git

 

So that git can write files… Done!

Installing subversion in CentOS

Administration, Info.Tech, Linux System Administration 1 Comment »

THIS IS A REPOST FROM electrictoolbox.com


Subversion (SVN) is a version control system. This post looks at how to install subversion on CentOS (the process is similar for other Linux distros) and the setting up a repository.

To install subversion on CentOS you need to have the RMForge custom repository enabled, and then issue the following command:

yum -y install subversion

This will check for any dependencies and then prompt you to install those and subversion itself. Type in “y” and <enter> to install these.

Unfortunately it doesn’t set up anything else after installing the necessary files, so you need to add a subversion user and set up the repositories etc yourself. If we decide to call the subversion user “svn” then you add them like so:

useradd svn
passwd svn

And then change to the subversion user like so:

su svn

Change to the svn user’s directory and then create a “repositories” directory like so:

cd
mkdir repositories

And now create your project’s repository. For example, if we had a project called “myproject” you would do this:

cd repositories
svnadmin create myproject

There will now be a “myproject” directory containing the following:

-rw-rw-r-- 1 svn svn  229 Nov 21 16:58 README.txt
drwxrwxr-x 2 svn svn 1024 Nov 21 16:58 conf
drwxrwsr-x 6 svn svn 1024 Nov 21 16:58 db
-r--r--r-- 1 svn svn    2 Nov 21 16:58 format
drwxrwxr-x 2 svn svn 1024 Nov 21 16:58 hooks
drwxrwxr-x 2 svn svn 1024 Nov 21 16:58 locks

You need to edit “myproject/conf/svnserve.conf” and uncomment the following lines:

auth-access = write
password-db = passwd

and edit the password file “myproject/conf/passwd” adding a new user and password. Note that the password is stored in plain text. In the following example we have a user called “john” whose password is “foobar123”:

[users]
john = foobar123

And finally, as the svn user, start the subversion daemon like so:

svnserve -d -r /home/svn/repositories

You can now connect to the subversion repository at e.g. svn://svn@hostname/myproject

You can add additional repositories under this user using the “svnadmin create” command and then access them at svn://[userame]@[hostname]/[project name]

You can use tortoiseSVN as client.

Centos 6.2: PHP, MySQL and Nginx

Administration, Info.Tech, Linux System Administration, Operating Systems, PHP, Web Development 1 Comment »

I’ve been curious about the word nginx. A lot of posting about nginx. So I do a little research and found out its a HTTP server. So I tried my own research and experiment which all sample configuration can be found at nginx.org. For my experiment, I used Centos 6.2, PHP, MySQL and the Nginx. Here’s you will do it to setup Web Server using Nginx;

Download first the EPEL for Centos 6 (http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/repoview/epel-release.html or epel-release-6-7.noarch.rpm (820)) — purpose for this is so you can install the per-requesites of Nginx like spawn-fcgi.

[root@server ~]# wget http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/epel-release-6-7.noarch.rpm

[root@server ~]# rpm -ivh epel-release-6-7.noarch.rpm

[root@server nginx]# yum repolist
Loaded plugins: fastestmirror, protectbase, security
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * epel: ftp.cuhk.edu.hk
 * extras: centos.ipserverone.com
 * updates: centos.ipserverone.com
0 packages excluded due to repository protections
repo id                                                        repo name                                                                                              status
base                                                           CentOS-6 - Base                                                                                        6,294
epel                                                           Extra Packages for Enterprise Linux 6 - x86_64                                                         7,561
extras                                                         CentOS-6 - Extras                                                                                          6
nginx                                                          nginx repo                                                                                                23
updates                                                        CentOS-6 - Updates                                                                                     1,147
repolist: 15,031

Then install nginx.

[root@server ~]# yum -y install nginx

Install PHP, MySQL and other packages.

[root@server ~]# yum -y install php-pear-Net-Socket php-pear php-common php-gd php-devel php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql

Install spawn-fgi

[root@server ~]# yum -y install spawn-fcgi

Download and setup the spawn-fcgi to init.d (spawn-fcgi init.d script (797))

[root@server ~]# wget http://bash.cyberciti.biz/dl/419.sh.zip
[root@server ~]# unzip 419.sh.zip
[root@server ~]# mv 419.sh /etc/init.d/php_cgi
[root@server ~]# chmod +x /etc/init.d/php_cgi

Start PHP app server and check if running

[root@server ~]# /etc/init.d/php_cgi start
[root@server ~]# netstat -tulpn | grep :9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      1843/php-cgi

Configure nginx.conf for PHP based webserver for WordPress, Drupal & Joomla (Download: nginx.conf (798)).

[root@server nginx]# cat nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    server {
        listen 80 default_server;
        server_name .nginx.ph;
        access_log /var/log/nginx/nginx.ph_access_log;
        error_log /var/log/nginx/nginx.ph_error_log;

        index index.html index.php index.htm;

        root /home/camilord/public_html;

        location / {
           # if you're just using wordpress and don't want extra rewrites
           # then replace the word @rewrites with /index.php
           try_files $uri $uri/ @rewrites;
        }

        location @rewrites {
           # Can put some of your own rewrite rules in here
           # for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
           # If nothing matches we'll just send it to /index.php
           rewrite ^ /index.php last;
        }

        # This block will catch static file requests, such as images, css, js
        # The ?: prefix is a 'non-capturing' mark, meaning we do not require
        # the pattern to be captured into $1 which should help improve performance
        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
                # Some basic cache-control for static files to be sent to the browser
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        # remove the robots line if you want to use wordpress' virtual robots.txt
        location = /robots.txt  { access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }

        # this prevents hidden files (beginning with a period) from being served
        location ~ /\.          { access_log off; log_not_found off; deny all; }

        location ~ \.php {
                fastcgi_param  QUERY_STRING       $query_string;
                fastcgi_param  REQUEST_METHOD     $request_method;
                fastcgi_param  CONTENT_TYPE       $content_type;
                fastcgi_param  CONTENT_LENGTH     $content_length;

                fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
                fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param  REQUEST_URI        $request_uri;
                fastcgi_param  DOCUMENT_URI       $document_uri;
                fastcgi_param  DOCUMENT_ROOT      $document_root;
                fastcgi_param  SERVER_PROTOCOL    $server_protocol;

                fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
                fastcgi_param  SERVER_SOFTWARE    nginx;

                fastcgi_param  REMOTE_ADDR        $remote_addr;
                fastcgi_param  REMOTE_PORT        $remote_port;
                fastcgi_param  SERVER_ADDR        $server_addr;
                fastcgi_param  SERVER_PORT        $server_port;
                fastcgi_param  SERVER_NAME        $server_name;

                fastcgi_pass 127.0.0.1:9000;
        }

       #location ~ \.php$
       #{
       #    root           html;
       #    fastcgi_pass   127.0.0.1:9000;
       #    fastcgi_index  index.php;
       #    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
       #    include        fastcgi_params;
       #}
    }
}

Restart Nginx

[root@server ~]# service nginx restart

I think that’s it.. it should be working because its working on my CentOS linux box. 🙂

Reference:

  1. http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/
  2. http://www.cyberciti.biz/faq/rhel-fedora-centos-linux-enable-epel-repo/
  3. http://www.thegeekstuff.com/2012/06/enable-epel-repository/
  4. http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/repoview/epel-release.html
  5. http://wiki.nginx.org/ServerBlockExample
  6. http://kbeezie.com/view/nginx-configuration-examples/

 

Manage Apache Download Speed and Traffic Limits

Administration, Linux System Administration, Operating Systems 1 Comment »

I’ve been experimenting on how I can limit the download speed via Apache configuration. This method is good for file-sharing website and for hosting servers. In my case, I am using Centos 5.5 and Apache 2.2.3 + mod_cband 0.9.7.5.

So, here’s what you will do… Assume you already installed the Apache.

  1. Install Apache Development libraries by casting “yum -y install apache-devel”
  2. Download “mod_cband” from http://dembol.org/blog/mod_cband/ or direct download link at http://dembol.org/downloads/cband/mod-cband-0.9.7.5.tgz

Follow steps (must be root mode)…

cd ~
wget http://dembol.org/downloads/cband/mod-cband-0.9.7.5.tgz
tar xzvf mod-cband-0.9.7.5.tgz
cd mod-cband-0.9.7.5
./configure
make
make install

To check if successfully installed, type just like below and must have same result:

[root@localhost ~]# cat /etc/httpd/conf/httpd.conf | grep mod_cband.so
LoadModule cband_module       /usr/lib/httpd/modules/mod_cband.so

Then add the code below at httpd.conf then save and restart apache.

CBandScoreFlushPeriod 1
CBandRandomPulse On

Next is add a “scoreboard”

mkdir /var/www/scoreboard
chown apache:apache /var/www/scoreboard/

Final steps is create an vhost entry at /etc/httpd/conf.d just like this (in my case, I created cband.com as my vhost);

[root@localhost conf.d]# cat cband.com.conf
<VirtualHost *:80>
    ServerAdmin webmaster@cband.com
    DocumentRoot /home/cband.com/public_html
    ServerName cband.com
    CBandSpeed 1024 10 30
    CBandRemoteSpeed 50kb/s 3 3
    CBandLimit 500M
    CBandExceededSpeed 128 5 15
    CBandScoreboard /var/www/scoreboard
    CBandPeriod 4W
    CBandExceededURL http://cband.com/exceeded.html

    <Location /cband-status>
      SetHandler cband-status
    </Location>
    <Location /cband-status-me>
      SetHandler cband-status-me
    </Location>

    ErrorLog logs/cband.com-error_log
    CustomLog logs/cband.com-access_log common
</VirtualHost>

[root@localhost conf.d]#

After you created the vhost file, restart your apache.

You can check the status of certain vhost by accessing the URL: http://cband.com/cband-status

or another status URL: http://cband.com/cband-status-me

Further Explanation:

  1. CBandSpeed 1024 10 30 — Overall apache performance. Max bandwidth speed is 1024bits per secs. 10 requests per secs. 30 max connections
  2. CBandRemoteSpeed 50kb/s 3 3 — Individual apache performance. Max bandwidth speed is 50kb/s, max 3 requests/s and max 3 connections
  3. CBandLimit 500M — 500MB max bandwidth limit
  4. CBandExceededSpeed 128 5 15 — Bandwidth speed limit at 128kbps, 5 request/s and max of 15 connections
  5. CBandScoreboard /var/www/scoreboard — scoreboard location
  6. CBandPeriod 4W – time to refresh
  7. CBandExceededURL http://cband.com/exceeded.html — if bandwidth exceeded, redirect to the specified URL.
You can use the following units in the mod_cband directives:

Transfer speeds:

    kbps: 1024 bits per second
    Mbps: 1024*1024 bits per second
    Gbps: 1024*1024*1024 bits per second
    The default is kbps.

Transfer quotas:

    K: 1000 bytes
    M: 1000*1000 bytes
    G: 1000*1000*1000 bytes
    Ki: 1024 bytes
    Mi: 1024*1024 bytes
    Gi: 1024*1024*1024 bytes
    The default is K.

Time periods:

    S: seconds
    M: minutes
    H: hours
    D: days
    W: weeks
    The default is S.

Reference:

Download mod_cband file:

PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/mcrypt.so’ – libmcrypt.so.4: cannot open shared object file: No such file or directory in Unknown on line 0

Administration, Info.Tech, Linux System Administration, PHP Comments Off on PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/mcrypt.so’ – libmcrypt.so.4: cannot open shared object file: No such file or directory in Unknown on line 0

I created some script in php, encrypting and decrypting my emails. but when I ran the script, got some issues. When I traced it, the php-mcrypt library is missing. I am using CentOS 6.2 at 64bit architecture. Some says I will move the libmcrypt.so.4 and  libmcrypt.so.4.4.8 from /usr/lib to usr/lib64 and /usr/lib/php/mcrypt.so to /usr/lib64/php/mcrypt.so but when I check the file, its not there. The files aren’t there at the installed directory. to check this issues, cast php -v;

[root@mail lib64]# php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mcrypt.so' - libmcrypt.so.4: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.3.3 (cli) (built: Feb  2 2012 23:47:49)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.0.10, Copyright (c) 2002-2011, by ionCube Ltd.

If there’s PHP Warning, then that means there are missing files… if more warnings, probably there’s a problem during installation of your php. But in this guide, I will only discuss how to fix the php-mcrypt issues.

First download the lacking files, which are;

  1. libmcrypt-2.5.8-4.el5.centos.x86_64.rpm
  2. php-mcrypt-5.3.3-1.el6.x86_64.rpm

You can download those files at rpmfind.net or rpm.pbone.net. Then extract the files inside the rpm pack by using the command rpm2cpio.

[root@mail ~]# rpm2cpio libmcrypt-2.5.8-4.el5.centos.x86_64.rpm | cpio -idmv
[root@mail ~]# rpm2cpio php-mcrypt-5.3.3-1.el6.x86_64.rpm | cpio -idmv

Then move the files that you just extracted to /usr/lib64 and after moving the files, restart httpd and cast again the php -v.

[root@mail ~]# php -v
PHP 5.3.3 (cli) (built: Feb  2 2012 23:47:49)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.0.10, Copyright (c) 2002-2011, by ionCube Ltd.
[root@mail ~]#

This is the output you should get, no PHP Warnings and php-mcrypt should be working fine. That’s it! Happy solving!

Securing Web Folders

Administration, Info.Tech, Linux System Administration Comments Off on Securing Web Folders

Create or Add this to .htaccess

AuthType Basic
AuthName "Members Only"
AuthUserFile /home/user/public_html/secretfolder/.htpasswd
<limit GET PUT POST>
         require valid-user
</limit>

then execute the htpasswd command;

htpasswd -c /home/user/public_html/secretfolder/.htpasswd admin

That’s it.. if you visit http://servername.com/~user/secretfolder/ — it will prompt a username and password. So you have to enter admin as username and the password you entered.

Enjoy~!

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in