Yegor's blog

Small blog about system administration.

Fix DKIM issue in ISPConfig3

Download the patch, unzip and install
cd /tmp
wget blog.schaal-24.de/files/dkim-latest_ispconfig3.tar.gz
tar xfvz dkim-latest_ispconfig3.tar.gz
cd dkim_ispconfig3
alter the mysql-database
Login to mysql as the root-user:
mysql -u root -p
or use in phpMyAdmin the database an run the follwing sql-code.
Select the database of ISPConfig (see $conf['db_database'] in/usr/local/ispconfig/interface/lib/config.inc.php) and expand:
use dbispconfig;
ALTER TABLE `mail_domain` ADD `dkim_public` MEDIUMTEXT NOT NULL AFTER `domain`; ALTER TABLE `mail_domain` ADD `dkim_private` MEDIUMTEXT NOT NULL AFTER `domain`; ALTER TABLE `mail_domain` ADD `dkim` ENUM( 'n', 'y' ) NOT NULL AFTER `domain`;
Adjust the rights
chown -R ispconfig.ispconfig *
,
copy the new files,
cp -Rp interface /usr/local/ispconfig
cp -Rp server /usr/local/ispconfig
and activate the server-plugin
ln -s /usr/local/ispconfig/server/plugins-available/mail_plugin_dkim.inc.php /usr/local/ispconfig/server/plugins-enabled/mail_plugin_dkim.inc.php
customize amavis
If DKIM is not yet activated, a few parameters must be entered in amavisd. The corresponding config file is /etc/amavisd.conf (openSusSE) or/etc/amavis/conf.d/50-user (Debian).
Insert the following lines at the end:
#DKIM
$enable_dkim_verification = 1;
$enable_dkim_signing = 1; # load DKIM signing code,
@dkim_signature_options_bysender_maps = (
{ '.' => { ttl => 21*24*3600, c => 'relaxed/simple' } } );
adjust ISPConfig
Set the path for dkim-keys in Server Config / Mail .

Keys can now be created using the interface for mail domains and registered in DNS.

1 comment :

Post a Comment

Linux: How to change permissions for directories / files only



To recursively give directories read&execute privileges:

find /path/to/base/dir -type d -exec chmod 755 {} +

To recursively give files read privileges:

find /path/to/base/dir -type f -exec chmod 644 {} +

Or, if there are many objects to process:

chmod 755 $(find /path/to/base/dir -type d) chmod 644 $(find /path/to/base/dir -type f) 

Or, to reduce chmod spawning:

find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644

No comments :

Post a Comment

CentOS 6.4: Device eth0 does not seem to be present

After cloning a Centos machine from VMware template, I got following error message when networking service was restarted
device eth0 does not seem to be present
Initially, I thought the issue might be with the network adapter but was not sure exactly which network adapter settings should be kept..
On further investigation, I came with a solution with following solution.
Basically, the problem occurs due to old NIC record does not getting erased even though new NIC record is assigned.
1) Open following file which holds record of the NIC templates
vi /etc/udev/rules.d/70-persistent-net.rules
The above file should contain similar records as below:
# PCI device 0x15ad:0x07b0 (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", 
ATTR{address}=="00:50:56:a4:3c:58", 
ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x15ad:0x07b0 (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", 
ATTR{address}=="00:50:56:a4:35:b1", 
ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
2) Remove previous eth entries and change the last entry NAME to eth0
# PCI device 0x15ad:0x07b0 (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", 
ATTR{address}=="00:50:56:a4:35:b1", 
ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
3) Save the file.
4) Open following file and modify the mac address
/etc/sysconfig/network-scripts/ifcfg-eth0
5) Save the file.
6) Reload udev configuration for the changes we made to reflect
start_udev
7) Restart network service
service network restart
or
/etc/init.d/network restart
8) Check the available ip using ifconfig command and update /etc/resolv.conf file with correct nameservers.

That’s it !

2 comments :

Post a Comment

MDB to MySQL conversion in Linux.

Install package mdbtools that has mdb-schema and mdb-export,

The mdb-schema can be use to see schema.
The mdb-tables  can be used to see tables in it

/usr/bin/mdb-array
/usr/bin/mdb-export
/usr/bin/mdb-header
/usr/bin/mdb-hexdump
/usr/bin/mdb-parsecsv
/usr/bin/mdb-prop
/usr/bin/mdb-schema
/usr/bin/mdb-sql
/usr/bin/mdb-tables
/usr/bin/mdb-ver

To get the list of tables, you run the following command:


mdb-tables database.mdb

You can then get a CSV version for each table using:
mdb-export database.mdb table_name

You can also convert the mdb into a format required by MySQL. First you must get the put the table schema into the database using the following command:
mdb-schema database.mdb | mysql -u username -p database_name

You then import each table by running:
mdb-export -I database.mdb table_name | sed -e 's/)$/)\;/' | mysql -u username -p database_name


Script to convert .mdb file to MySQL:
===========================


$ cat ~/bin/mdb2mysql.sh
#!/bin/sh


if [ $# -ne 4 ]; then
echo "usage: $0 msaccess.mdb mysqldb mysqluser mysqlpass"
exit
fi

MDB_FILE=$1
MYSQL_DBNAME=$2
MYSQL_USER=$3
MYSQL_PASS=$4

MYSQL_IMPORT=/tmp/`basename $MDB_FILE .mdb`.sql

>$MYSQL_IMPORT

# create database
echo "DROP DATABASE IF EXISTS $MYSQL_DBNAME;" >> $MYSQL_IMPORT
echo "CREATE DATABASE $MYSQL_DBNAME; " >> $MYSQL_IMPORT
echo "USE $MYSQL_DBNAME; " >> $MYSQL_IMPORT

# import table structures with mysql data types
mdb-schema -S $MDB_FILE mysql >> $MYSQL_IMPORT

perl -p -i -e 's/-----*/--/g' $MYSQL_IMPORT
perl -p -i -e 's/DROP TABLE (.*)/DROP TABLE IF EXISTS $1/gi' $MYSQL_IMPORT

# Fix the Variables
#perl -p -i -e 's/Text/VARCHAR/g' $MYSQL_IMPORT
#perl -p -i -e 's/Long Integer/INT\(11\)/g' $MYSQL_IMPORT

# import data
for TABLE in `mdb-tables $MDB_FILE`
do
mdb-export -R';' -I $MDB_FILE  $TABLE >> $MYSQL_IMPORT

done

mysql -u$MYSQL_USER -p$MYSQL_PASS < $MYSQL_IMPORT

if [ $? -ne 0 ]; then
echo ""
echo "Fix the script at $MYSQL_IMPORT"
echo ""
echo "Run it using following command"
echo "mysql -u$MYSQL_USER -p$MYSQL_PASS < $MYSQL_IMPORT"
else
echo ""
echo "DONE. Script used is: $MYSQL_IMPORT"
echo ""
echo "Remove it if you no longer need it"
fi
$

Example:
=======


$ mdb2mysql.sh
usage: mdb2mysql.sh msaccess.mdb mysqldb mysqluser mysqlpass
$


$ mdb2mysql.sh PayRoll.mdb payroll root root

DONE. Script used is: /tmp/PayRoll.sql

Remove it if you no longer need it
$

ACCESS ISSUES:
============

MS Access allows +, - and % also in the column name. Such things can cause confusion.... the tool replaces + and - with just underscore...

If you had fields like Adj+ and Adj-, both will be named as Adj_ , this is a problem.

The mdb-schema will replace Discount% with Discount_ but INSERT INTO queries may still have DISCOUNT%.

Be careful.

No comments :

Post a Comment

How To Setup A PGP Key Server in Ubuntu



Just do the following:


Install the sks package

>sudo apt-get install sks



Build the key database

>sudo sks build


Set database permissions

>sudo chown -Rc debian-sks:debian-sks /var/lib/sks/DB


Set the server to start automatically at boot

set initstart=yes in /etc/default/sks


Start the service

>sudo /etc/init.d/sks start


That is it! Now your server is listening on port 11371 for key requests. You can now send and retrieve keys to and from the server using your favorite key manager!

If that is not good enough for you, then you can also add a web interface to handle your key searches and requests. To do that you will need to install Apache:


>sudo apt-get install apache2


Once installed create a directory called www in /var/lib/sks/. Download the index.html and keys.jpg file you will need here: (OpenSKS Web Interface)

Extract the contents to /var/lib/sks/www/. Edit index.html and change the three references to your.site.name (currently at lines 20, 36 & 62) to the url of your keyserver, for example keys.bauer-power.net. Now set the correct permissions on that directory:


>sudo chown -R debian-sks:debian-sks /var/lib/sks/www

Now if you browse to http://your.server.name:11371 you will see a nice, user-friendly web interface for doing public key exchanges!

2 comments :

Post a Comment

How to Backup your VPS files to DropBox

This simple script will backup any folders, any files or the whole VPS to your Dropbox account. However, the dropbox account has maximum 300MB cap per file upload through website.


#!/bin/bash
DROPBOX_USER="Your Dropbox username"
DROPBOX_PASS="Your Dropbox password"
DROPBOX_DIR="Directory in your dropbox account, e.g. /backups"
BACKUP_SRC="/home /var/www /var/git /etc /root"
BACKUP_DST="/tmp"
MYSQL_SERVER="127.0.0.1"
MYSQL_USER="root"
MYSQL_PASS="Your MySQL password"

#
# Stop editing here.
NOW=$(date +"%Y.%m.%d")
DESTFILE="$BACKUP_DST/$NOW.tgz"

#
# Upload a file to Dropbox.
# $1 = Source file
# $2 = Destination file.
function dropboxUpload
{
 #
 # Code based on DropBox Uploader 0.6 from http://www.andreafabrizi.it/?dropbox_uploader
 LOGIN_URL="https://www.dropbox.com/login"
 HOME_URL="https://www.dropbox.com/home"
 UPLOAD_URL="https://dl-web.dropbox.com/upload"
 COOKIE_FILE="/tmp/du_cookie_$RANDOM"
 RESPONSE_FILE="/tmp/du_resp_$RANDOM"

    UPLOAD_FILE=$1
    DEST_FOLDER=$2

 # Login
 echo -ne " > Logging in..."
 curl -s -i -c $COOKIE_FILE -o $RESPONSE_FILE --data "login_email=$DROPBOX_USER&login_password=$DROPBOX_PASS&t=$TOKEN" "$LOGIN_URL"
 grep "location: /home" $RESPONSE_FILE > /dev/null

 if [ $? -ne 0 ]; then
  echo -e " Failed!"
  rm -f "$COOKIE_FILE" "$RESPONSE_FILE"
  exit 1
 else
  echo -e " OK"
 fi

 # Load home page
 echo -ne " > Loading Home..."
 curl -s -i -b "$COOKIE_FILE" -o "$RESPONSE_FILE" "$HOME_URL"

 if [ $? -ne 0 ]; then
  echo -e " Failed!"
  rm -f "$COOKIE_FILE" "$RESPONSE_FILE"
  exit 1
 else
  echo -e " OK"
 fi

 # Get token
 TOKEN=$(cat "$RESPONSE_FILE" | tr -d '\n' | sed 's/.*<form action="https:\/\/dl-web.dropbox.com\/upload"[^>]*>\s*<input type="hidden" name="t" value="\([a-z 0-9]*\)".*/\1/')

 # Upload file
 echo -ne " > Uploading '$UPLOAD_FILE' to 'DROPBOX$DEST_FOLDER/'..."
    curl -s -i -b $COOKIE_FILE -o $RESPONSE_FILE -F "plain=yes" -F "dest=$DEST_FOLDER" -F "t=$TOKEN" -F "file=@$UPLOAD_FILE"  "$UPLOAD_URL"
    grep "HTTP/1.1 302 FOUND" "$RESPONSE_FILE" > /dev/null

    if [ $? -ne 0 ]; then
        echo -e " Failed!"
  rm -f "$COOKIE_FILE" "$RESPONSE_FILE"
        exit 1
    else
        echo -e " OK"
  rm -f "$COOKIE_FILE" "$RESPONSE_FILE"
    fi
}

# Backup files.
mysqldump -u $MYSQL_USER -h $MYSQL_SERVER -p$MYSQL_PASS --all-databases > "$NOW-Databases.sql"
tar cfz "$DESTFILE" $BACKUP_SRC "$NOW-Databases.sql"

dropboxUpload "$DESTFILE" "$DROPBOX_DIR"

rm -f "$NOW-Databases.sql" "$DESTFILE"
Save the script as “dropboxbackup.sh”, chmod +x it and run ./dropboxbackup.sh.
Add a Cron Job
crontab -e
# m h  dom mon dow   command
0 0 1 * *       /bin/bash /root/dropboxbackup.sh
To change the default editor to nano
yum install nano
nano ./bashrc
add this to the file
export EDITOR=nano
It will take effect next time you login.


No comments :

Post a Comment