Thursday, September 20, 2012

Saving a root owned file as normal user

This happens lot of times. I login as a normal user and start to edit root owned file in vim / vi text editor. However, I'm not able to save changes due to permission issue (all config files are owned by root). So to save file, i can do :w !sudo tee % 
Where,
:w - Write a file.
!sudo - Call shell sudo command.
tee - The output of write (vim :w) command redirected using tee. The % is nothing but current file name i.e. /etc/apache2/conf.d/mediawiki.conf. In other words tee command is run as root and it takes standard input and write it to a file represented by %. However, this will prompt to reload file again (hit L to load changes in vim itself):

Top Reasons of SPAM Mails

Why Is My Emails Getting As Spam? Qusetion asked by everyone if your mails are marked spam to your friends mailbox
 
Don't worry just follow the below steps.

First we need to check Email Headers.
1. Return Path
2. To
3. From
4. We should not use CAPS because not only being unprofessional, but it
also triggers spam filters. To land in the Spam folder consistently,
please do not USE ALL CAPS IN THE SUBJECT LINE AND THE BODY FROM TO and
Excessive punctuation (e.g. -/, ;^%#$@+ * "').

E.g. as follows.

1. Email "From : ADMIN ENROLL " getting
spam in gmail.com sometimes and if we not change it will increasing
count.

2. Email "From: noreply@exmaple.com" it
getting in mailbox, check the CAPS deference.

http://php.net/manual/en/function.mail.php
http://www.niso.org/khelp/kmlm/user_help/html/examine_mail_headers.html

Please check this too. It can be understand better. :)
http://www.infusionblog.com/email-marketing/7-ways-for-your-email-to-land-in-the-spam-folder/

Check SPF for Domain.:
http://www.microsoft.com/mscorp/safety/content/technologies/senderid/wizard/

What is SPF records and How to setup?
http://www.kazeli.com/help/index.cfm?pageloc=quest&questid=435&catid=337,338

To diagnose the mail. Why its going in Spam.
Check tool:
http://mxtoolbox.com/
Here you can check following points
1. Mxlookup : For your domain and ip
2. Blacklist : For your IP
3. Diagnostics : SMTP Diagnostics, check your mail server
4. Analyze Headers : Check your mail headers.
5. SPF Records : Check your Sender Policy Framework
7. DNS Lookup : Check your Domain lookup.

If you check above all things your mail will not go in Spam.!

Friday, June 8, 2012

Transparent SQUID 2.6 Configuration on Centos

SQUID 2.6 (Transparent PROXY SERVER)

Main benefit of setting transparent proxy is you do not have to setup up individual browsers to work with proxies.

Server: bhagwat-desktop (192.168.1.5 Local Network IP)
Client: Linux & Windows XP//Vista/7
Default Port NO: 8080


Please change this Setting for automatic forwarding

vi /etc/sysctl.conf
net.ipv4.ip_forward=0    >>    net.ipv4.ip_forward=1

Installation Of Required Packages:

Install the squid package with yum

yum install squid

Configure SQUID config file:

NOTE: Modify squid.conf file (Before Modifying any Files take one backup copy)

vi /etc/squid/squid.conf


#Recommended minimum configuration:
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 9100
acl Safe_ports port 80        # http
acl Safe_ports port 21        # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 70        # gopher
acl Safe_ports port 210        # wais
acl Safe_ports port 1025-65535    # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl Safe_ports port 9100    #  Network Printer
acl CONNECT method CONNECT
acl freesites url_regex "/etc/squid/freesites"
http_access allow freesites
acl blockfiles urlpath_regex "/etc/squid/blocks.files.acl"
http_access deny blockfiles
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl our_networks src 192.168.1.0/24
http_access allow our_networks
http_access allow localhost
http_access deny all
icp_access allow all
http_port 192.168.1.5:8080 transparent
hierarchy_stoplist cgi-bin ?
access_log /var/log/squid/access.log squid
ftp_passive on
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern .        0    20%    4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
visible_hostname my_squid_bhagwat
coredump_dir /var/spool/squid

Now start Squid server & also add in start up
/etc/init.d/squid start

chkconfig squid on

Now run this command to redirect all traffic on squid

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

/etc/init.d/iptables save
/etc/init.d/iptables start

Check it with this command
iptables -t nat -L


You do not have to setup up individual browsers to work with proxies.


Problems and Solution with FTP

Add following line in /etc/rc.local

/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp

save with :wq

then run 

/etc/rc.local

& it's done

Starting httpd: (98) Address already in use: make_sock: could not bind to address 0.0.0.0:443

Starting httpd: (98)Address already in use: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down
Unable to open logs!

Solution
netstat -ptnl | grep 443
tcp        0      0 :::443                      :::*                        LISTEN      953/sshd

Kill the process (kill -9 process_id)

check error log
tail -f /var/lof/httpd/error.log

Wednesday, May 23, 2012

Install phpMyAdmin on CentOS 5 - With Yum Installation

Install MySQL

yum install mysql-server mysql mysql-devel
chkconfig mysqld on
service mysqld start
 Set Password for MYSQL
mysql -u root -p
enter password

Install PHP & HTTPD

yum install php php-mysql
yum Install httpd

Download the rpmforge package from Centos website
after installing rpmforge run following command
yum install phpmyadmin

vi /etc/httpd/conf.d/phpmyadmin.conf
the format should be like below (allow from all)
<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
  Deny from all
  Allow from all
</Directory>


Go to phpmyadmin direcotry (in my case it /usr/share/phpmyadmin)
cp config.sample.inc.php config.inc.php
vi config.inc.php

Edit th config.inc.php file, find the line that contacin "blowfish_secret", and modify like below
$cfg['blowfish_secret'] = 'TypeAnything_for_secure';

(Type any secure password instead of TypeAnything_for_secure)

service httpd restart


Open browser & type http://ipaddress_of_machine/phpmyadmin
login with root
password of mysql (which you set earlier)

Tuesday, May 22, 2012

Install DBD::Oracle in Ubuntu

ERROR

root@bhagwat-desktop: perl Makefile.PL
Using DBI 1.620 (for perl 5.012004 on i686-linux-gnu-thread-multi-64int) installed in /usr/local/lib/perl/5.12.4/auto/DBI/

Configuring DBD::Oracle for perl 5.012004 on linux (i686-linux-gnu-thread-multi-64int)

Remember to actually *READ* the README file! Especially if you have any problems.

Trying to find an ORACLE_HOME
Your LD_LIBRARY_PATH env var is set to ''

      The ORACLE_HOME environment variable is not set and I couldn't guess it.
      It must be set to hold the path to an Oracle installation directory
      on this machine (or a machine with a compatible architecture).
      See the appropriate README file for your OS for more information.
      ABORTED!

Solution


Oracle Instant Client

Download the instant client packages you’ll need. I chose to download the RPMs and convert them to .deb files using alien Oracle also provides .zip files if you don’t want to do it the alien way.
convert rpm into deb package through aliean (apt-get install alien)
aliean oracle-instantclient11.2-basic-xx.x.x.x.x-x.i386.rpm
Above command convert rpm to deb package
install the deb package 
dpkg -i  xxxxx*.deb
 Then type this command at terminal
export ORACLE_HOME=/usr/lib/oracle/11.2/client/
echo $ORACLE_HOME 
create permanent entry with 
vi /etc/profile
ORACLE_HOME=/usr/lib/oracle/11.2/client/
export ORACLE_HOME

 

 Install DBD::Oracle with following command

cpan DBD::Oracle
or 
go to downloaded directory of DBD::Oracle package & run 
perl Makefile.PL
make
make install

Wednesday, May 9, 2012

Install OCI8 in Centos/RedHat

Install OCI8 in Centos

Download OCI8 package from here
http://pecl.php.net/package/oci8
tar -xzvf oci-<VERSION>.tgz
cd oci-<VERSION>
phpize

1) Configure the PECL package as a shared object using the instant client and specifying where the Oracle client libraries are. Then build and install it.

./configure –with-oci8=instantclient,/usr/lib/oracle/<VERSION>/client/lib
make
make install

2) Add the library shared object for PHP

echo extension=oci8.so > /etc/php.d/oci8.ini

3) Start Apache

‘service httpd start’ _or_ ‘/etc/init.d/httpd restart’

4) Create a PHP info page and checked to see if the Oracle (oci8) driver is listed:

echo <? phpinfo(); ?> > /var/www/html/phpinfo.php