Monday, May 20, 2019

HTTP to HTTPs Redirect Loop

We are implementing the WordPress site where I am trying to redirect the site from HTTP to HTTPs. Everything is set but still site is not able to redirect to HTTPs then below setting in Wordpress helped me to redirect.

Edit wp-config.php

if
(($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] ==
'https') OR ($_SERVER['HTTP_X_FORWARDED_PROTO'] ==
'https'))
{$_SERVER['HTTPS']='on';}

Wednesday, June 11, 2014

Checking Passwordless Login Enabled or Not

If you want to check if passwordless login enabled or not on the given host then below is the command which can be used to check for the same.

ssh -o StrictHostKeyChecking=no -o NumberOfPasswordPrompts=0 host0103 "echo hello"

We can run this in for loop for the number of hosts and it will either print error if password less login is not allowed or print the word "hello" if it is enabled. 

Friday, March 21, 2014

Extract and Repack Debian Package

I just needed to repack a Debian package to solve this problem below are the steps. 
$ mkdir -p extract/DEBIAN
$ dpkg-deb -x package.deb extract/
$ dpkg-deb -e package.deb extract/DEBIAN
[...do something, e.g. edit the control file...]
$ mkdir build
$ dpkg-deb -b extract/ build/
  • -x extracts the package contents
  • -e extracts the control files
  • -b builds the new package
Done.

Monday, December 30, 2013

Recover Deleted File


grep -a -B 25 -A 100 'some string in file' /dev/sda1 > results.txt


grep searches through a file and prints out all the lines that match some pattern. Here, the pattern is some string that is known to be in the deleted file. The more specific this string can be, the better. The file being searched by grep (/dev/sda1) is the partition of the hard drive the deleted file used to reside in. The -a flag tells grep to treat the hard drive partition, which is actually a binary file, as text. Since recovering the entire file would be nice instead of just the lines that are already known, context control is used. The flags -B 25 -A 100 tell grep to print out 25 lines before a match and 100 lines after a match. Be conservative with estimates on these numbers to ensure the entire file is included (when in doubt, guess bigger numbers). Excess data is easy to trim out of results, but if you find yourself with a truncated or incomplete file, you need to do this all over again. Finally, the > results.txt instructs the computer to store the output of grep in a file called results.txt. [Ref]

Thursday, October 17, 2013

Convert Dmesg timestamp to Human readable format.

I am using ubuntu 12.04 where util-linux package is update and you have the option of converting dmesg timestamp to human readable format just by passing option "-T". But for those who are using the dmesg which doesn't support "-T" option can use below simple program to convert it into human readable format.

Program_file: dmesg_realtime.sh
Parameters: dmesg_timestamp

#cat dmesg_realtime.sh
#!/bin/bash
ut=`cut -d' ' -f1 < /proc/uptime`
ts=`date +%s`
realtime_date=`date -d"70-1-1 + $ts sec - $ut sec + $1 sec" +"%F %T"`
echo $realtime_date

#./dmesg_realtime.sh 8642755.690405
2013-08-16 08:48:09


Tuesday, September 24, 2013

Top 10 MySQL Mistakes Made By PHP Developers

I just came across the Blog written by "Craig Buckler" Director of OptimalWorks which will be useful for the PHP Developers.

Monday, August 12, 2013

Postfix as a spam trap server

Reference here

If you want to build a Spam trap with Postfix this can be done very very easy. You don't even have to configure Postfix to act as a Spam trap.
Postfix ships with a neat tool called smtp-sink which does the trick.
smtp-sink is mainly intended to act as a testing tool for SMTP clients which need a Server to play with. So you can configure it to log the whole conversation or even dump each received mail to a file. The latter is needed for a spamtrap.

There is no configuration file to configure smtp-sink. Everything is done via command-line options.
smtp-sink -c -d "%Y%m%d%H/%M." -f . -u postfix -R /tmp/ -B "550 5.3.0 The recipient does not like your mail. Don't try again." -h spamtrap.example.com 25 1024
Let's have a closer look to each parameter.
  • -u postfix
    Runs the program under the user "postfix"
  • -R /tmp/
    Sets the output directory to /tmp/. In this directory the mails will be stored. If you have a high spam volume (hundreds of Spam per minute) it is recommended to write the mails to a ramdisk
  • -d "%Y%m%d%H/%M."
    Writes the mail to a directory of the format "YearMonthDayHour" and in this directory the files are name "Month.RandomID". Note that the dates are in UTC
  • -c
    Write statistics about connection counts and message counts to stdout while running
  • -f .
    Reject the mail after END-OF-DATA. But the mail will be saved. Cool, isn't it?!
  • -B "550 5.3.0 The recipient does not like your mail. Don't try again"
    This is the rejection message after END-OF-DATA.
  • -h spamtrap.example.com
    Announce the hostname spamtrap.example.com
  • 25
    The port to listen on. Can be prepended with an IP or host if you want to bind on a special interface.
  • 1024
    The backlog count of connections that can wait in the TCP/IP stack before they get a free slot for sending mail.
You can find more information in the man page of smtp-sink, but these are the important ones to run a catch-all spamtrap.
In this configuration the program accepts any mail with any size from any sender to any recipient with IPv4 and IPv6. The only restrictions are that there are only 256 simultaneous connections possible with 1024 queued connections and the program is flagged experimental.
So do not use smtp-sink in a production environment.

The next step of a Spamtrap is to read the saved files, parse and interpret them and then do whatever is needed. For example block further connections from that IP via a firewall, feed it to a blacklist, scan for viruses or create checksums from these mails.

The -B option is only valid in newer versions of Postfix. In 2.7.1 it is missing. In 2.8.2 it is present. Somewhere in-between it was introduced.