Quantcast
Channel: Syed Jahanzaib – Personal Blog to Share Knowledge !
Viewing all 409 articles
Browse latest View live

Howto configure your Local SMS HTTP Gateway using KANNEL on Ubuntu

$
0
0

As per web defines: Kannel (http://www.kannel.org/) is one of the most popular open source WAP/SMS Gateway, because its very good performance to handle a huge SMS. Kannel supports many modem’s brand even generic modem, also support multi modems (modem bank).

x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x

After some testing, I have found Kannel one of the best , fastest SMS and WAP gateway among other open source sms gateways , capable of handling several hundreds of requests per second.

Following is a guide on how you can configure your own Local SMS HTTP gateway using KANNEL 

(The aim of configuring kannel on my Ubuntu box was that I required it to send sms via DMASOFTLAB RADIUS MANAGER which uses API to send sms via clickatell HTTP gateway for New Account / Expiry Warning / Password recovery via sms , verification code and many other cool functions. It comes with the clickatell HTTP gateway API which off course require you to buy sms bundle package and do require handsome amount of $$ if you have a huge number of users, Therefore to save $$ money , I  created my own gateway)

O/S = Ubuntu 10.4
Hardware = Teltonika ModemUSB/E12 UM1400

First install KANNEL using apt-get (the easiest one ;) )

apt-get install libxml2

apt-get install kannel

NOTE:
Kannel
works great with the Linux base distribution BUT there are some workarounds to make it run on Windows. Do some googling and you will find few links for it.

Now open the kannel config file by

nano /etc/kannel/kannel.conf

Remove all the lines and paste the following config

# Syed Jahanzaib
# http://aacable.wordpress.com
# aacable [at] hotmail.com

group = core
admin-port = 13000
smsbox-port = 13001
admin-password = zaibadmin
status-password = zaibstatus
log-file = "/var/log/kannel/bearerbox.log"
log-level = 0
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"

group = smsc
smsc = at
modemtype = teltonika
device = /dev/ttyACM0 # change this to match your port, it could ACM1 , if you dont set it correctly,  it will not work and you will get error in logs that unable to connect to device)
speed = 19200
my-number = 0333302100000 # (put your sim number, not necessary)

group = modems
id = teltonika
name = "Teltonika E12"
detect-string = "Undefined"
enable-mms = true
init-string = "AT+CNMI=2,2,0,1,1"
speed = 115200

group = smsbox
bearerbox-host = localhost
sendsms-port = 13013
global-sender = 13013
sendsms-chars = "0123456789 +-"
log-file = "/var/log/kannel/smsbox.log"
log-level = 0
access-log = "/var/log/kannel/access.log"

group = sendsms-user
username = kannel
password = kannel
concatenation = true
max-messages = 3

group = sms-service
keyword = default
get-url = "http://localhost/kannel/receivesms.php?sender=%p&text=%b"
accept-x-kannel-headers = true
max-messages = 3
concatenation = true
catch-all = true

Open two terminal windows and issue below commands in each terminal box in the following order.

1. Start the BearerBox

bearerbox -v 0 /etc/kannel/kannel.conf

You may see the following screenshot if your config is ok

Now leave it running.

2. Start the SMSBox (in second terminal window and leave it running as it will show you the debug logs)
smsbox -v 0 /etc/kannel/kannel.conf

You may see the following screenshot if your config is ok

[If you receive error that the address is already in use, first issue the command service kannel stop]

.

Now From your browse, type the following to make sure kannel is working fine :)

http://101.11.11.250:13000/status?password=zaibstatus
[change the ip and password to match your config]

and you may see the following screen , if your config is ok

.

.

Howto send SMS via http command

Open your browser and paste the following command.

http://101.11.11.250:13013/cgi-bin/sendsms?username=kannel&password=kannel&to=03333021909&text=ZAIB+KANNEL+WORK

Change the IP / ID + Password = and number to match your local configuration.

The result would be similar to the following . . .

.

Regard’s
Syed Jahanzaib


Filed under: Linux Related

DMASOFTLAB Radius Manager SMS Notification Configuration

$
0
0
~ Article by ~
Syed Jahanzaib

DMASOFTLAB Radius Manager have a very nice feature of SMS notification for New Account Activation Message, New Account Activation Verification Code / Password Recovery and many other cool functions that can be done using this feature, however activating it is a bit complex thing to do. As radius manager supplies clickatell HTTP gateway API with there default installation, and I really didn’t wanted to purchase the clickatell account because it would be expensive for any mid-large size network, even a small network wouldn’t want to pay extra amount. So I decided to create my own HTTP gateway which is connected with my GSM Modem. Following is the complete guide on how you can create your own SMS HTTP GATEWAY.

http://aacable.wordpress.com/2012/11/26/howto-configure-your-local-http-gateway-using-kannel-on-ubuntu/

Once you have a working HTTP gateway , you can move on to RM configuration section.

Howto configure API to make it work with your Local SMS HTTP gateway.

Login to your RM box using terminal.

Open the api.php file by

nano /var/www/radiusmanager/api/api.php
(Change the path if you have RM installed at some other folder)

Now remove all lines and replace them with the following.
(Change the $api_user to match your kannel config)

<?php
/*****************************************************************************
**        Name: api_sendsms
**
** Description: This function is used to send a SMS messages to a mobile phone.
**        You can call your SMS gateway to send a message to a mobile phone.
**        The function includes an example code of integrating the
**        clickatell.com HTTP -> SMS gateway.
**
** >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
**  Syed Jahanziab > I have changed it to use my local sms gateway running on KANNEL , Configured on same box where RM is installed and connected TELTONIKA GSM MODEM with it in VM.
** >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
**
**       Input: $mode - SMSMODE_ACCVERIFY: send verification code
**            SMSMODE_WELCOME: send account data
**            SMSMODE_PSWCODE: send new password activation code
**            SMSMODE_NEWPSW: send new password
**        $username - RADIUS user name
**        $password - RADIUS password
**        $firstname - first name of user
**        $lastname - last name of user
**        $address - postal address of user
**        $city - city of user
**        $zip - zip code of user
**        $country - country of user
**        $state - state of user
**        $phone - phone number of user
**        $mobile - mobile number of user
**        $email - email address of user
**        $srvid - associated service id
**        $verifycode - the verification code to send
**        $errmsg - pointer to error message returned by the gateway
**
**      Output: True if API succeeded or false
*****************************************************************************/
function api_sendsms($mode, $username, $password, $firstname, $lastname, $address, $city, $zip, $country, $state, $phone, $mobile, $email, $srvid, $verifycode, &$errmsg)
{
// enter your local sms http gateway credentials here

$api_user     = "kannel";
$api_password = "kannel";

switch ($mode)
{
case SMSMODE_ACCVERIFY:
$body = "Enter the following verification code in UCP: $verifycode";
break;

case SMSMODE_WELCOME:
$body = "Welcome new user! Your user name is $username, your password is $password";
break;

case SMSMODE_PSWCODE:
$body = "New password activation code: $verifycode";
break;

case SMSMODE_NEWPSW:
$body = "Your new password: $password";
break;
}

// return success (uncomment the following lines in testing environments only)

//  print $body;
//  return true;

// implement your own SMS gateway in the following block

$body = rawurlencode($body);
$ch = curl_init();
// change the IP and id password in the below line to match your local config. syed jahanzaib
curl_setopt($ch, CURLOPT_URL, "http://101.11.11.250:13013/cgi-bin/sendsms?user=$api_user&password=$api_password&api_id=$api_id&to=$mobile&text=$body");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
curl_close($ch);

// uncomment this to see the result from clickatell.com HTTP->SMS gateway

//  print $res;

if (substr($res, 0 , 4) ==  "ERR:")
{
$errmsg = $res;
return false;
}

// SMS sent successfully

return true;
}
?>

That’s It. Your RM is ready to send sms using your local SMS HTTP gateway.

.

Howto send Account Expiry Warning to User via email

Logon to RM Admin Panel,
Goto System/ System Settings

At the bottom of the page, You will see Notification’s section.
At the Expiry warning: Type the number of days you want RM to send account expiry warning before the account expires.
Also tick on all related options as showed in the image.
As showed in the image below . . .

.

Once the account reaches near its expiry, user will receive email like below . . .

Howto Recover User Password via FORGOT PASSWORD link at user.php (ver 4.x or above)

User can recover his forgotten password using Forgot my password at user.php

For Example

.

After submission the mobile number, user will receive A code on his mobile number (If he have defined valid number while registering the account. Then after entering the code in the below screen, he will receive new password.
As showed in the image below . . .

.

.

Regard’s
Syed Jahanzaib


Filed under: Linux Related

DMASOFTLAB Radius Manager: Install + Backup + Restore [Short Reference Guide]

$
0
0

Ubuntu

dmalogo

Following is a short reference guide for DMASOFTLAB Radius Manager

Part-  1)         Installation Of RM with some TIPS,
Part- 2)         Complete Backup for RM and RM DB,
Part- 3)         Restore RM Data to new Installation.

.

.

Part-1 # Installation of Radius Manager 4.x on Ubuntu 10.4

DMASOFTLAB Radius Manager 4.0 Short reference manual guide for UBUNTU 10.4

After you have installed Ubuntu, configure IP address and enable internet access on it.

Now open Terminal Window and issue the below command to install required Modules.

apt-get install mc wget rcconf make gcc mysql-server mysql-client libmysqlclient15-dev libperl-dev curl php5 php5-mysql php5-cli php5-curl php5-mcrypt php5-gd php5-snmp

wget http://www.dmasoftlab.com/cont/download/libltdl3_1.5.24-1ubuntu1_i386.deb

wget http://www.dmasoftlab.com/cont/download/libltdl3-dev_1.5.24-1ubuntu1_i386.deb


dpkg -i libltdl3_1.5.24-1ubuntu1_i386.deb


dpkg -i libltdl3-dev_1.5.24-1ubuntu1_i386.deb

IONCUBE Installation:

First Download ioncube library

wget http://www.dmasoftlab.com/cont/download/ioncube_loaders_lin_x86.tar.gz
Untar it in any temp folder for example /temp/ioncube

tar zxvf ioncube_loaders_lin_x86.tar.gz

Create new folder for ioncube in usr/local

mkdir /usr/local/ioncube

and copy the whole folder in /usr/local

Now Add the appropriate ionCube loader to your php.ini
For example
Add this line on top

zend_extension=/usr/local/ioncube/ioncube_loader_lin_5.3.so

in following files.
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

Installation procedure of FreeRadius
==============================

wget http://www.dmasoftlab.com/cont/download/freeradius-server-2.1.8-dmamod-3.tar.gz

tar zxvf freeradius-server-2.1.8-dmamod-3.tar.gz


cd freeradius-server-2.1.8-dmamod-3


./configure


make


make install


ldconfig

Now test RADIUS by issuing following command:

radiusd -X

You will see something like below . . .

radius-ready

Set the correct ownership on FreeRadius configuration files
================================================

chown www-data /usr/local/etc/raddb

chown www-data /usr/local/etc/raddb/clients.conf

TIP:

Review and edit (if required) the MySQL credentials in /usr/local/etc/raddb/sql.conf (Just in case you have mentioned different password/id for mysql)

.

Creating MySQL databases with MySQL command line tool
===============================================

mysql -u root -ppassword

CREATE DATABASE radius;
CREATE DATABASE conntrack;
CREATE USER ‘radius’@'localhost’ IDENTIFIED BY ‘yourpass’;
CREATE USER ‘conntrack’@'localhost’ IDENTIFIED BY ‘yourpass’;
GRANT ALL ON radius.* TO radius@localhost;
GRANT ALL ON conntrack.* TO conntrack@localhost;
exit

 Time to Install RADIUS MANAGER 4.0.4
=================================

Copy the radius manager radiusmanager-4.0.4.tgz (or your version) in any temp folder
now extract it using

tar zxvf radiusmanager-4.0.4.tgz

cd radiusmanager-4.0.4.tgz

chmod +x install.sh


Execute the installation Script . . .

./install.sh

Now the install script will ask few questions . . . Select answers as per your local design.
For example:
Select the Operating  System
2
(For Ubuntu)

Select Installation type:
1
(New Installation)

WWW root path:
Press Enter to select the Default , which is /var/www

Radius Database host:
Press Enter to select the Default , which is localhost

Radius Database username:
Press Enter to select the Default , which is radius

Radius Database password:
Press Enter to select the Default , which is radius123

CTS Database host:
Press Enter to select the Default , which is localhost

CTS database username:
Press Enter to select the Default , which is conntrack

CTS database password:
Press Enter to select the Default , which is conn123

Freeradius UNIX User:
Press Enter to select the Default , which is root

Httpd Unix User:
Press Enter to select the Default , which is www-data

Create rmpoller service:
Press Enter to select the Default , which is y (yes)

create rmconntrack service:
Press Enter to select the Default , which is y (yes)

Backup Radius database:
Press Enter to select the Default , which is y (yes)

Now it will ask if you want to start the installation
Press y and press ENTER to continue the installation.

and at the end you will INSTALLATION COMPLETE!
As showed in the image below . . .

radius-installation-complete

Now copy the two license files (that you receive from DMASOFTLAB) in /var/www/radiusmanager

lic.txt
mode.txt

Now access the admin panel from your browser

http://yourip/radiusmanager/admin.php

.

TIPS:

.

1# :

If you see the following error while accessing admin.php

Could not connect to localhost

Make sure your passwords for radius and conntrack hosts are set correctly in

/etc/radiusmanager.cfg
/var/www/radiusmanager/config/system_cfg.php

2# :

If you see blank page while accessing admin.php , following could be wrong.
a- Your license files are not valid or expired.
b- you have not installed ioncube library correctly.

To test if your license is valid, tail the /var/log/apache2/access.log and error.log , they will show you if your license have issues like expired or invalid dueto mac address restrictions.

To test IONCUBE LIBRARY , Open Terminal and Type
php-v

& you should see something similar to below . . . (Focus on Last line that says with the ioncube php loader . . .)

root@zaib-desktop:~# php -v
PHP 5.3.2-1ubuntu4.18 with Suhosin-Patch (cli) (built: Sep 12 2012 19:33:42)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd.

3# :

you are seeing ‘Incorrect user name and password error’ in mikrotik logs for the users created on RM, then make sure you have defined correct password in /etc/raddb/sql.conf (path for this file may be different like /usr/local/etc/raddb/sql.conf

.

Part-2 # Complete Backup

DMA provide its own backup script (bash script) Which creates full and differential backup. I have used it and it works really good. But since its copy righted , therefore I am not sharing it here. Just the traditional method I am posting here :) . To take full backup use the following.

Copy following Folders in any safe location:

boot
/etc
/home/root
/usr/local
/var/www
/var/lib/mysql
/var/spool/mail

Create mysql dump of database RADIUS: (which have RM User and other Data)

mysqldump -u radius -pradiuspass radius > /backup/db_full_type_current_date.sql
gzip -f /backup/db_full_type_current_date.sql

# To unzip the .gz file, use gzip -d filename.gz

.

Part-3 # Restore Backup

If somehow your server crashes, and you got to re-built it from scratch , you can restore the database using below procedure. (To simplify things, use the same OS)

1) Install OS (Same as previous one, in this example Ubuntu)
2) Install RM with the same same config you used for previous installation, e.g: radius db passwords and folders locations
3) Restore all the folders from the backup to there original locations.(backup that taken in part-2 backup part)
4) Now its time to restore mysql radius DB, use the below command to restore DB in mysql.

mysql -u root -prootpasswd radius < db_full_type_current_date.sql

Change the db_full_type_current_date.sql to match your mysql backup file.

Now restart your box once time.

If you receive ‘cannot connect to localhost’ check the passwords in

/etc/radiusmanager.cfg
/var/www/radiusmanager/config/system_cfg.ph

Also check the DB password in mysql , You can change the DB password via using this command

mysql -u root -prootpassword
use mysql;
UPDATE user SET Password=PASSWORD(“your_new_password”) WHERE User=’radius’;
UPDATE user SET Password=PASSWORD(“your_new_password”) WHERE User=’conntrack’;

Now restart your box or mysql service :)

To be continued . . .

Allah Hafiz

:)

Regard’s
Syed Jahanzaib
aacable [at] hotmail.com


Filed under: Linux Related, Radius Manager

Howto change MAC address of VM hosted in VM-Workstation

$
0
0

vmware

ethernet_mac_address

Manually Assigning a MAC Address For VM

To make sure that the same MAC address is assigned to a given virtual machine every time, even if the virtual machine is moved, you can assign the address manually instead of allowing VMware Workstation to assign it automatically. To assign the same, unique MAC address to any virtual machine manually, use a text editor to remove three lines from the configuration file and add two lines. The configuration file has a .vmx extension at the end of the file name.

To change MAC address of any virtual machine running under VM Workstation, Follow the below . . .

1- Make sure that the target VM is turned off.
2- Browse to folder where your VM is available. For example
F:\VM-WARE-IMAGES\UBUNTU

3- Now open VMX file in NOTEPAD , the name would be something like machine_name.VMX

4- Remove the three lines from the configuration file that begin with:
    ethernet0.generatedAddress
    ethernet0.addressType
    ethernet0.generatedAddressOffset
[Note: Change the ethernet0 to match your's]

Now Add a new static MAC address line to the configuration file with help of the following entries:

ethernet0.addressType = “static”
ethernet0.address = “00:11:22:33:44:55″

5- Now Save the configuration file. & Start the VM

Regard’s
Syed Jahanzaib


Filed under: General IT Related, Microsoft Related

Cisco 3750: Howto enable err-disabled ports

$
0
0

Personnel Reference Guide:

3750

To enable err-disabled ports on Cisco 3750 switch series. Follow the below . . .

First make telnet connection with the switch

telnet 10.0.0.1

(change the ip as required,)
Enter Password to continue.

To view Disabled Ports:

show interfaces status err-disabled

e.g:

NOC_SWITCH>show int status err-disabled

Port      Name               Status                    Reason               Err-disabled Vlans
Gi2/0/10                     err-disabled         link-flap

NOC_SWITCH>

To Enable Port:

enable
config t
int G2/0/10
no switchport port-security  (< You probably dont need this line, its just to disable pot security feature, I used it to perform various tests)
shut
no shut
exit

Change the interface name to match your. In above example I had two 3750-e models in stack mode. so its showing G2, you may get G1 if you have single switch.

TIP:
Link flap means that the specific port continuously goes up and down. The port is put into the errdisabled state if it flaps more than four-five times in few seconds. The common cause of link flap is a Layer 1 issue such as a bad cable, duplex mismatch.

Regard’s
Syed Jahanzaib


Filed under: Cisco Related

HyperV to VMware conversion

$
0
0

Howto convert Hyper-V hosts to Vmware ESXi

Task: We want to convert one of our host server running on Hyper-V (installed on Windows 2008 R2 CORE edition), you can use Vmware Vcenter Converter utility to perform this action.

First Download Vmware Vcenter convertetr 5.x from following location.
You must have vmware account to download the utlity, you can rgister it free.

http://downloads.vmware.com/d/details/converter5/dHclYnRqZEBiZEAldw==

After installation Done. Execute it. You may see following screen.
As showed in the image below . . .

1- vmconverter

.

Now click on CONVERT MACHINE
In Source Type , Select HYPER-V
In Server, type your Hyper-V IP
In User Name/Password , type your Administrator ID and password
and click NEXT to continue . . .
As showed in the image below . . .

2- convert-hyperv-machione

If you receive the following error
Unable to contact the specified host ‘x.x.x.x’ . The host might not be available on the network, there might be a network configuration problem, or the management services on this host are not responding
then disable the firewall on HYPERV Windows 2008 by using following command (at hyper v server command prompt)

netsh firewall set opmode disable

Now it will ask you for the agent deployment,
click YES to continue.
As showed in the image below . . .

3- agent

.

.

In next screen of  SOURCE SERVER , It will give you the list of machines hosted on source Hyper-V server.
Select your desired machine ,
and click NEXT to continue
As showed in the image below . . .

4- select source-vm-hyperv

.

.

In Next Screen of  DESTINATION SYSTEM , select the destination VMWARE ESXi Server
As showed in the image below . . .

5- select destination server.

.

In the next screen of  DESTINATION VIRTUAL MACHINE , Click NEXT to continue (Or you can change the machine name label here)
As showed in the image below . . .

6- select name.

.

In the next screen of  DESTINATION LOCATION , Select the datastore location (the drive where you want upload the vm)
As showed in the image below . . .

7- select datastore.
.

In the next screen , it will show you all the options before finally start converting, review all the options and modify if any required. then Click NEXT , and then FINISH to start converting the machine
As showed in the image below . . .

8- final

.

.

Finally it will start conversion of the hyper v machine into Vmware Esxi.
As showed in the image below . . .

9- status.

.

Regard’s
Syed Jahanzaib


Filed under: VMware ESXi Related

Vritualization: 3 in 1 > Using Mikrotik + Squid Proxy + Radius on single machine to save resources :)

$
0
0

"Virtualizing

.

Its a good idea to virtualize various servers so underutilized hardware can be used more efficiently, as now a days, getting good hardware is not a big deal. It can save considerable amount of power consumption , reduced heat factor , easy to mange multiple VM using various tools like Vcenter / VEEAM (my favorite), VM Explorer , live migrations from one Virtual Server to Another, Backup & Restore becomes very easy and the list goes on . . .

Recently I did an installation of a network where they were low in hardware resources but still they wanted to utilize the benefits of Mikrotik Router OS with external Squid proxy server and also the Radius Billing Server . So in total they required at least 3 physical machines, but I managed to install all of them on single server using Virtualization technology of VMWARE ESXi 5.x (64bit) and it worked so great :)
Here is how I did it.

Note: Because of some time shortage, I am just giving you an idea how it can be done, I am not writing in pin point details on how to connect every machine with Virtual/Physical switches. I will write about it soon.

Hardware Used for the Example:

64bit Server Class machine

Multiple SATA HDD’s (the more Faster drives (like 10-15krpm) you have, the better result you will be able to achieve. Preferably in RAID mode, either 10 or 0, depend on your management and goals, in this example I used 7200krpm SATA HDD, I dedicate each hdd for each OS, I tested it on IBM xseries with RAID0 and found RAID 0 much more faster with 15krpm but its not redundant, one drive fail and your whole RAID will go down, so if you want redundancy, go with at least RAID 5 or RAID 10 , Raid 1 is also good as it mirrors each drive, but requires additional drives and also for proxy, its useless to use mirroring as it would be requiring more read/write burden on controller, oh GOD, in which argument I got into :p)

16GB RAM (Mikrotik doesn’t requires much RAM in fact it officially supports maximum of 2G, but Radius and Squid do requires some good amount of RAM, I dedicated 8 GB to SQUID, 4GB to Radius, 2 GB to Mikrotik)

4 Network Adapters ( In this article, dueto time shortage, I have only mentioned howto add two network adapters for LAN and WAN link using virtual Switch tech)


Software Used:

1) Vmware ESXi 5.x  64bit as a Virtual Hyper-visor Server
Guest OS installed in it are as following
2) Mikrotik Router-OS 5.22
3) Ubuntu 10.4 for SQUID Proxy (2.7)
4) Ubuntu 10.4 for Radius Manager Billing System

First install Vmware ESXi. You can get its free edition from www.vmware.com  , just register and download the latest version , it would be in .iso format, Simply burn it to CD, and install it on your server , its very simple to install the ESXi, nothing more then just clicking NEXT NEXT :)

After ESXi installed, configure IP address on it, so you can manage it using its client called Vsphere client.

To shorten the story I am using only two interfaces for the mikrotik, LAN and WAN. in this example (shorten version) ESXi have two interfaces connected , one with the LAN user switch and other interface connected with the WAN (physically)

Creating Virtual Switch and bind Network Adapters with this switch.

Goto Configuration tab
From the list appear in Hardware section, click on Networking and click on ADD Networking
As showed in the image below , , ,

add-virtual-switch

2- add network wizard

3- add network wizard

4- add network wizard

5- add network wizard

Ok, our virtual switch is created.
Now its time to bind our WAN adapter in this switch. (So it can later be used for WAN for all hosts we will requiring for)

Click on the Properties
6- add network wizard

7- add network wizard

Done.

Creating Mikrotik in VM and assigning network adapters.

Now create new Virtual Machine for your Mikrotik.

Select necessary hardware that you required as required per user load. for example
Mikrotik = 1 CPU / 1 GB RAM / 10 GB HDD /

In Network Adapter Section, by default only one adapter is added, You have to add another adapter by selecting the number of adapters in drop down listing.
As showed in the image below . . .

8- adding lan wan in host

Once the configuration is completed. Simply install the Mikrotik in newly created hosts you just created in above steps.
After configuration is complete, review once again the host settings,
As showed in the image below . . .

9- Mikrotik Network Adapters
After the installation is done, Connect to mikrotik with WINBOX  and look for interfaces
As showed in the image below . . .

mikrotik-interface

.

I will write more on it later.

Regard’s
Syed Jahanzaib


Filed under: General IT Related, Mikrotik Related, VMware ESXi Related

Howto add FTP server in ESXi 5.x to support Fast Download/Upload of VM / Images

$
0
0

Yesterday I was trying to upload a 450GB VMDK file to ESXi host. (Actually it was VHD file and I converted it to VMDK using starwind converter), and it was uploading dead slow and showed countless hours to complete the upload.  After some googling I found that generally it takes too much time to Upload/Download any VM/ISO File FROM/TO ESXi host. I also tried VEEAM FASTSCP free tool but no avail. It still works very slow.

However if you add FTP service to your ESXi server, and use ftp client to upload/download files, then the upload/download will be much faster.  ProFTPD runs good in ESXi 5.x and offers high transfer rate over normal transfers.
As showed in the image below . . .

Upload to ESXi Host using Vsphere Client

9.8Mb

Upload to ESXi Host using FTP Client [After adding FTP service in ESXi]

27mb

.
.

To add FTP Service, use the following method.

First We have to Enable SSH in ESXi . Connect to your ESXi host,
Goto Configuration
Goto Security Profiles,
Click on Properties

enable-ssh

2- enable-ssh

.

3- enable-ssh

SSH service is now enabled on ESXi.

Now Connect to your ESXi host using any ssh client like putty.
Navigate to your datastore folder. For example the datastore on my ESXi host name is 1TB,

 cd /vmfs/volumes/1TB/
[Change the 1TB to match your datastore name]

Create any folder where your FTP Service files can be downloaded from the internet or any other source.
[make sure internet service is enabled so file can dierctly download to esxi host, if its not possible then download the package on your client PC, then upload it using Vsphere client and skip to esxcli software install section below . . . ]

mkdir ftp
cd ftp

Now download proftpd by using wget

wget  http://esxi-customizer.googlecode.com/files/ProFTPD-1.3.3-8-offline_bundle.zip

Now install it by using esxcli

esxcli software vib install –no-sig-check -d /vmfs/volumes/1TB/ftp/ProFTPD-1.3.3-8-offline_bundle.zip
[Change the 1TB to match your datastore name]

Later if you decide to remove proftp , simply issue following command

To uninstall the package run the following command

esxcli software vib remove -n ProFTPD

Now test it by using simple dos ftp command

ftp 10.0.0.1

ftp

Or using any ftp client like   CUTEFTP PRO

4-ftp-cute

Regard’s
Syed Jahanzaib


Filed under: VMware ESXi Related

Sending Payment Reminder / Service Status SMS to Users via GAMMU using CLI/GUI

$
0
0

mobile

Following is a short guide on how you can create your own SMS panel to send SMS to users about various Events using CLI or GUI method.

For example Payment Reminder, Service Down/Up Alert, and any other message you like to convey to all users.

If you have some prior experience with the Linux/SMS tools, I am sure you will ask why to do so much manual work if you already have open source free tools like smsplay, kannel and many others available , the answer is YES the pre made tools/applications have very nice GUI and and have other functions as well, you simply have to install it by single command and that’s it ready to use, but I always like to build my own solution rather then relying on the pre made applications, This way I can twist and modify the method as per my requirements. & yes its fun to play with the code and you feel much confident, happy and relaxed if you manage to create your own working solution that can fulfill your requirement.

Just FYI, DMASOFTLAB Radius Manager 4.1.x will have the function to send account expiry warning SMS before account expires.

.

Hardware Required:

# GSM Mobile / MODEM
(I used TELTONIKA GSM USB Device in this example, Picture is attached below . . .)
teltonika

Software Required:

# Ubuntu 10.x or any flavor of Linux you like to use.
# GAMMU or GNOKII (you can install gammu by apt-get install gammu )

(A very good guide for GAMMU installation & configuration is available here
http://techspalace.blogspot.com/2012/02/send-sms-using-gammu-command-line-tool.html
http://pierky.wordpress.com/2011/10/28/zabbix-send-sms-using-gammu-smsd/

 

Connect your GSM modem to your Linux Box via USB,
Make sure it is detected properly by Identifying it using DMESG command

dmesg | grep tty
(You may see following information if device is detected OK, As showed below)

1- detect modem

As you can see that the modem have been detected as USB ACM DEVICE ttyACM0

Now run gammu config by
gammu-config

It will ask you that gammu configuration file exists, click YES to continue
Now configuration box will open, Select the PORT and EDIT & type your port name that is detected in the dmesg command.
2- port.
3- portname
Click on OK , then SAVE and EXIT

Now identify it by using following command.

gammu –identify
(You may see following information if its connected OK , As showed below)

root@zaib-desktop:/sms# gammu –identify
Manufacturer         :   Teltonika
Model                      :   unknown (TM3 EDGE)
Firmware                :   05.41.02
IMEI                       :   3523870xxxxxxxx
SIM IMSI               :   410012xxxxxxx62

Test the configuration by sending SMS to your number using CLI method. Use the below command to send sms to your mobile.

echo “Zaib Test Message” | gammu sendsms TEXT 03333021909

If you don’t see any error message and receive the message to your number, then we are good to GO . . .

========================================================
TIP:

You can also use WAMMUwhich is a nice GUI frontend for GAMMU. Using it you can perform following functions easily.

Using wammu you can read/edit/delete/copy your contacts, to-do, calendar you can read/create/save/send and Backup your sms. Some type of phone supports file sending, display message including pictures and ringtones playback. Support for backup and import in various formats (vCard, vCalendar, iCalendar, gammu own backup,…) . Export messages to mail (IMAP4, maildir and mailbox storages are supported.
To install wammu, simply issue below command from GUI terminal.
apt-get install wammu
After installation completes, Goto Applications / Accessories / >Wammu
Run its configuration wizard to detect the modem and start using it :)

wammu-on-linux
========================================================

.

Download following sms-panel-zaib.rar file from following location , and extract all files in a new folder /sms

 

http://www.mediafire.com/?f77465ogydpe4fp

Following are the contents of /sms (after extracting)

root@zaib-desktop:~# ls /sms

start = > It executes all the scripts in order, First init , then startsms
data
     => Contains Users Mobile Numbers and Names, Sample Numbers are included. Modify it as per your requirements
path => Contains all the paths for the scripts/dir
init     
=> This script extracts mobile nos and data from various sources and create temporarily dunp files
message => Contains Message that will be sent to users, Modify it as per your requirements
mobile.no = > Automatically created via script which contain mobile nos. only
startsm => This script actually sends sms using gammu

=============================================

Now first edit data file which contains the mobile numbers.

nano /sms/data

Type your user mobile number in the following manner

# User’s Mobile Numbers and there Names
03333021909 # Syed Jahanzaib-Admin No.
03331234567 # A-420, Lake View Cottages :d
03211122334 # X-20, A One Villas Bungalows :p

Now SAVE and EXIT ( By pressing CTRL+O , then ENTER, then CTRL+X )

Edit the message file, it will contain the message that will be delivered to users.

nano /sms/message

Now type your required message. For example:

Dear User,
Due to some scheduled maintenance work, Internet service will not be available from 3:00pm till 5:00pm on 25th December, 2012. 

Thank you for your co-operation & Sorry for the inconvenience.

Regard’s
AA Networks (Pvt) Ltd. / zaib :)

Now SAVE and EXIT ( By pressing CTRL+O , then ENTER, then CTRL+X )

1-SEND SMS TO ALL USERS USING CLI

Now type /sms/start to execute the whole process.
It will first execute init script which will extract data from the paths / files,
Then it will start sendsms script which will actually send the sms to all the numbers fetched from init scripts (Users mobile numbers are mentioned in the data file)

2- SEND SMS TO ALL USERS USING  GUI  VIA WEBMIN

To use Customize GUI Panel, through which we can manage users mobile numbers list, and send sms to this list, You have to first install WEBMIN. which is a very nice multi purpose GUI tool to manage various Linux components


If you are using UBUNTU, you can install it via apt-get

First edit sources file, so that apt-get can fetch data from webmin directly.

nano /etc/apt/sources.list

Paste the following lines at end.

deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

Save & Exit.

Now execute following commands to install GPG key with which the repository is signed. Use the below command.

cd /root
wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc

Now you will be able to install with the commands :

apt-get update
apt-get install webmin

after successful install , you can access it using the URL  it showed you after successful message.Eample::
https://10.0.0.1:10000
[Use your root ID & Password to Login],

After successful login, you will see following screen . . .

webmin.

CREATE MENU’S & LINK THEM WITH THE COMMANDS in /SMS

Now goto OTHERS / CUSTOM COMMANDS
Click on Create A New File Editor
In Description, Type any EDIT USERS MOBILE NUMBER
in File to EDIT , tpye the mobile no file name  /sms/data
Click on SAVE
As showed in the image below . . .

6- Create File Editor.

Congrats, you have created a file editor which can edit the users mobile numbers,
After SAVING above file editor, you will be redirected back to main menu,
Now we will create a new file editor, which will actually send the message you type in the available box.

7- Create File Editor for message.

In Description, Type any Send SMS to ALL
In File to EDIT , tpye the message file name  /sms/message
In Command to run after saving, type /sms/start
Click on SAVE
As showed in the image below . . .

8- Create File Editor for message -2

.

.

Now you will have the menu  something like below.

9- Main menu.

Now Click on the Edit Users Mobile Nos. button
& add the required mobile numbers in following manner.

10- edit mobile numbersClick on SAVE to save the entries in /sms/data.

.

Now to send SMS to the list, Click on Send SMS to ALL
Type the message in the box, and click on SAVE, after saving, it will auto execute the /sms/start script which will start sending the message you just typed to the list. It may take long time to send SMS if you have large numbers of List. In my case, it took 3-4 Seconds per SMS.
As showed in the image below . . .

11- send sms

.

You can schedule various events alerts in CRON job by using pre defined message templates.

To be continued . . .

Regard’s
SYED JAHANZAIB


Filed under: Linux Related

Personnel notes on Password Protecting Apache folder/alias + Disable Apache Directory Browsing

$
0
0

password

Howto Disable DIRECTORY BROWSING in apache2

To Disable directory browsing in Apache (In Ubuntu its apache2), Remove the following directive from your required folder.

Indexes
For example,  you want to remove directory browsing for /var/www/backup folder.
Edit the below file /etc/apache2/sites-enabled/000-default by using following command

nano /etc/apache2/sites-enabled/000-default

The Default config is below.

Alias /backup /var/www/backup
<Directory /var/www/backup>
DirectoryIndex index.html
Options Includes Indexes FollowSymLinks MultiViews
</Directory>

Change it below

Alias /backup /var/www/backup
<Directory /var/www/backup>
#DirectoryIndex index.html
Options Includes FollowSymLinks MultiViews
</Directory>

Save & Exit , then Restart APACHE Service by
service apache2 restart
============================================================

Howto create Alias/Virtual Folder

To create Alias/VF, for example /var/www/backup
Edit the below file, and add the data as showed below

nano /etc/apache2/sites-enabled/000-default

Alias /backup /var/www/backup
<Directory /var/www/backup>
DirectoryIndex index.html # Change as per requirement
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride None
order allow,deny
allow from all
</Directory>

Save & Exit , then Restart APACHE Service by
service apache2 restart
============================================================

Howto Password Protect Apache Folder with .htaccess

If you want to password protect specific folder in Apache so un authorized users cannot access it, use the following method. There are other better methods available, You can follow them for best practices. I just did it this way.

First Create password file

htpasswd -c /etc/apache2/passwd zaibtest

(Replace zaibtest with your required username, It will ask you for password, enter password you like to set for user zaibtest. Also you can save this file anywhere you like)

Now protect your required folder, for example I want to protect /var/www/backup folder, then use the following directives in in /etc/apache2/sites-enabled/000-default

nano /etc/apache2/sites-enabled/000-default

Alias /backup /var/www/backup

<Directory /var/www/backup>
#DirectoryIndex user.php
AuthType Basic
AuthName “Please enter valid user password to access Zaib’s Data”
AuthUserFile /etc/apache2/passwd
Require valid-user
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride ALL
order allow,deny
allow from all
</Directory>

Save & Exit , then Restart APACHE Service by
service apache2 restart

Now try to access the folder, it will ask you the password.

asking-password

.
After providing valid id password, you can access your folder. (I use it to download backup data from remote location)

access-granted

UBUNTU:
apache2: Could not reliably determine the server’s fully qualified domain name,

 … waiting ..
apache2: Could not reliably determine the server’s fully qualified name

If you see above error whil restarting apach service, To fix that problem, you need to add and directive in the the httpd.conf file. Open the terminal and type,

nano /etc/apache2/httpd.conf

By default httpd.conf file will be blank. Now, simply add the following line to the file.

ServerName localhost

Save & EXIT.

Now restart the server.

service apache2 restart
This time, you will not see any error. :)

Regard’s
Syed Jahanzaib


Filed under: Linux Related

Howto configure GMAIL as SENDMAIL RELAY :D (Also can be used with RM to send Email Notifications)

$
0
0

gmail-logo

If you want to use GMAIL as your sendmail relay server, Use the below configuration.

{I required it to send DMASOFTLAB RADIUS MANAGER Email notifications to all users regarding there service status, account expiry, renewal , various alerts and other info. thats why I wrote this guide, it maybe useful for others too . . Syed Jahanzaib }

OS Used: Ubuntu 10.4

First install Sendmail and its utilities.

apt-get install sendmail mailutils

Now configure signed SSL certificates
mkdir /etc/mail/certs
chmod 700 /etc/mail/certs
cd /etc/mail/certs

openssl dsaparam 1024 -out dsa1024 -out dsa1024.pem
(It will ask you various questiosn , just enter them accordingly, like country code, for Pakistan its PK, and other information you have)

openssl req -x509 -nodes -days 3650 -newkey dsa:dsa1024.pem -out /etc/mail/certs/mycert.pem -keyout /etc/mail/certs/mykey.pem
(It will ask you various questiosn , just enter them accordingly, like country code, for Pakistan its PK, and other information you have)

openssl req -x509 -new -days 3650 -key /etc/mail/certs/mykey.pem -out /etc/mail/certs/mycert.pem

ln -s /etc/mail/certs/mycert.pem /etc/mail/certs/CAcert.pem
chmod 600 /etc/mail/certs/*
cd ..

Now configure gmail SMTP authentication information, This file may be blank, just paste the text showed in code box.
nano  /etc/mail/authinfo
AuthInfo:smtp.gmail.com "U:root" "I:USERNAME@gmail.com" "P:PASSWORD"
AuthInfo: "U:root" "I:USERNAME@gmail.com" "P:PASSWORD"

Save & Exit & issue below command

makemap hash -o /etc/mail/authinfo < /etc/mail/authinfo
Now Add the following configurations at the bottom of sendmail.mc file
nano /etc/mail/sendmail.mc
dnl #
dnl # SSL Settings
define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')
define(`confCACERT_PATH', `CERT_DIR')
define(`confCACERT', `CERT_DIR/CAcert.pem')
define(`confSERVER_CERT', `CERT_DIR/mycert.pem')
define(`confSERVER_KEY', `CERT_DIR/mykey.pem')
define(`confCLIENT_CERT', `CERT_DIR/mycert.pem')
define(`confCLIENT_KEY', `CERT_DIR/mykey.pem')
dnl #
dnl # GMAIL FORWARDING
define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')dnl

Now rebuild sendmail config and start the service :D

make -C /etc/mail

service sendmail restart

Test the setup ;)

Use the below command to test the local smtp .

- - - - -??

Regard's
Syed Jahanzaib


Filed under: Linux Related

2012 in review [My Blog Report by WP]

$
0
0

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

About 55,000 tourists visit Liechtenstein every year. This blog was viewed about 850,000 times in 2012. If it were Liechtenstein, it would take about 15 years for that many people to see it. Your blog had more visits than a small country in Europe!

Click here to see the complete report.


Filed under: General IT Related

DynamicDNS client for windows

$
0
0

A friend of mine asked me howto configure DDNS client in Windows, so he ca remotely access his PC from the remote location, In my previous article  at
http://aacable.wordpress.com/tag/aacable-dynamicdns/
I described howto howto configure DynamicDNS (changeip.com) on Mikrotik  for remote management,but in this following short guide I will tell you how you can configure dynamicdns on windows using the ddns client.

To configure dynamicdns client (changeip.com) on windows base OS, First create your account at changeip.com (its well described at http://aacable.wordpress.com/tag/aacable-dynamicdns/)

After your account is created, now  download and install dynamic dns client (known as homingbeacon) from following location

http://www.changeip.com/dns/homingbeacon/default.aspx

Installation is fairly simple. Just clicking few next next :)

After installation is done, execute “The HomingBeacon Console” from the windows start menu. After its open , click on ‘I already have changeip.com account‘  (If you don’t already have the account, you can create it from the web or clicking on ‘) am a new changeip.com customer’
As showed in the image below . . .

1- pic1
.

.
Now Enter your changeip.com account id with password that you already created earlier.
As showed in the image below . . .

2- enter id passwordClick on Save & Close.

.

.

It will update the public IP of your WAN to your account at changeip.com
As showed in the image below . . .

3- update

.

Verify it by going to your changeip.com account, and see if the ip is updated properly. Now its time to configure your DSL router to create port forwarding rule, so required connections can be made from remote location.
For example you want to host HTTP Server on your local PC and want to access it remotely, open your DSL Router Page, and

Login to your dsl modem control panel.
As showed in the image below . . .

4-add nat in dsl.

.

5-add-nat-rule

.

.

 

Regard’s
Syed Jahanzaib


Filed under: Microsoft Related

Windows 7 Annoying Bug: Explorer doesn’t refresh automatically when Create/delete/move any file/folder

$
0
0

Today I found an annoying Bug in Windows 7 (Win7 Professional x86).
When a user try to Create / Delete/ Move any file from the Desktop, it still shows at desktop and when the user press F5 , it instantly appears/disappears, seems like windows Explorer auto refresh not working properly.

This resolved the issue for me:

Go to
Tools / Folder Options / General Tab,
and at  the bottom, in the ‘Navigation Pane‘, make sure ‘Show all folders‘ and Automatically expand to current folder‘ are checked.
As showed in the image below . . .

show-files

.

show-files2.

.

Regard’s
~ SYED  JAHANZAIB ~


Filed under: Microsoft Related

Mikrotik: Netwatch Script to Detect Target Server Link & Act Accordingly

$
0
0

matrix

Someone requested me to create a script that can check Squid Proxy or Target Server Link state from Mikrotik, and if the Squid Proxy / Target Server is not responding, then it should Disable the redirect NAT rule so all load can be handle by Mikrotik.You can modify this script as per your requirements. you can modify it to check WAN link, and if the WAN link is down, it can trigger SMS Script / Sound Alaram, or shift to backup WAN link by enabling diabling ROUTE’s or it can also be used to detect any wan link failure detection and change the rules accordingly.
Possibilities are endless.
So here it is.

Adding Comments in Redirect Rule

First add comments in required NAT rule, i.e Rule that redirects port 80 traffic to squid. You can also disable/enable rules based on the numbers, BUT its not recommended BECAUSE if you add any new rule and move it somewhere, all your scripts will disable/enable wrong rules, that is why you have to use find command and get rules this way.

You can use GUI to add comment in the rule, I am showing you an example below . . .
/ip firewall nat
add action=dst-nat chain=dstnat comment=”Redirect to SQUID” disabled=no dst-port=80 protocol=tcp to-addresses=192.168.6.1 to-ports=8080

add action=masquerade chain=srcnat comment=”Default NAT Rule for Internet Access / zaib” disabled=no to-addresses=0.0.0.0

1- nat rule

Change the host ip address as your local requirements. Its jsut an example to show you.

.

.

Adding Scripts to Enable/Disable Rule

After adding comments in the dst-nt rule, you have to create two scripts that can enable and disable the dst-nat rule. We can name them UP and DOWN.
Copy paste the below scripts on Mikrotik Terminal. It will create two scripts in System/Scripts with the name of UP and DOWN.

/system script

add name=down policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=”:log info \”SQUID PROXY link Down. Disabling SQUID NAT Rule s\
    o all load should be handled by Mikrotik alone / zaib\”\r\
    \n/ip firewall nat disable [find comment=\"Redirect to SQUID\"];”

add name=up policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=\

    “:log info \”SQUID PROXY link is UP. Enabling SQUID NAT Rule / zaib\”\r\
    \n/ip firewall nat enable [find comment=\"Redirect to SQUID\"];”
2- Script-List

.

Adding NETWATCH to monitor Target Server [Squid] Link Detection

Use the below script to add netwatch entry for squid / target server link detection. It will also add the UP and DOWN script for the appropriate action. For example. When the target server link is down, it will execute script DOWN which will disable the NAT redirect rule , when the target server link is up and working, it will execute the UP script which will re-enable the redirect rule.

/tool netwatch
add comment=”Netwatch to Check SQUID Server Link state / zaib” disabled=no down-script=”/sys script run down” host=192.168.6.1 interval=5m timeout=1s \
    up-script=”/sys script run up”

3 - Squid Link Detection

(Replace the host ip to match your local target server ip)

.

.

Testing Scripts . . .   :) ~

Now test the scripts, Unplug the Target Server LAN link, and you will see something like below in the LOG.

4- link down

.

Now plugin the Target Server LAN link, and you will see something like below in the LOG.

5- link up

 

.

Regard’s

Syed Jahanzaib


Filed under: Mikrotik Related

Howto send email from command via Windows using GMAIL account

$
0
0

Send Email from Windows via command prompt using GMAIL Account  :) ~

If you want to send email from windows using command prompt using gmail account, first down mailsend utility from following URL and extract it to any folder you like.

http://www.muquit.com/muquit/software/mailsend/mailsend1.16.exe.zip

Now to send email using command via your GMAIL account, use the below syntax. Remember to change the email addressees and password to match your account details.

mailsend.exe -to aacable@hotmail.com -from your-gmail-id@gmail.com  -ssl -smtp smtp.gmail.com -port 465 -sub "Testing Email via Windows cmd using GMAIL test %time%" -M "This is body text of Testing Email via Windows cmd using GMAIL. %date% %time% sending / zaib." +cc +bc -q -auth-plain -user "your-gmail-id" -pass "yourpass"

To send email with attachment, use the following

mailsend.exe -to aacable@hotmail.com -from your-gmail-id@gmail.com  -ssl -smtp smtp.gmail.com -port 465 -sub "Testing Email via Windows cmd using GMAIL test %time%" -M "This is body text of Testing Email via Windows cmd using GMAIL. %date% %time% sending / zaib." +cc +bc -q -auth-plain -user "your-gmail-id" -pass "yourpass" -attach "c:\test.txt"

It’s very handy and useful in many conditions. For example I used it to send daily tape backup log OR daily backup file to my email in the morning by scheduling it.

 

.

For more info, please read this details guide at
http://www.codeproject.com/Tips/418420/Send-email-from-command-line-using-GMail-account

.

Regard’s
Syed Jahnazaib


Filed under: Microsoft Related

Personnel short notes for BLAT and Delete Files Older then X Days

$
0
0

To send email from windows command using your local company SMTP , use BLAT tool.

BLAT guide.
A wonderful guide is already available here.
http://cybergav.in/2010/10/28/how-to-send-emails-using-blat/

+++++++++++++++

First Download BLAT from following URL:
http://sourceforge.net/projects/blat/files/Blat%20Full%20Version/32%20bit%20versions/Blat%20v3.0.0/blat300_32.full.zip/download?use_mirror=autoselect

Unzip it to any folder you like.

+++++++++++++++

To install SMTP in BLAT use the below command . . .

blat -installSMTP 10.0.0.1  your-user-id@xyz.com.pk  5  25

+++++++++++++++
To send email using blat command, use the below command

blat -s “test mail” -i “test” -to  your-user-id@xyz.com.pk

+++++++++++++++
To send email with attachment of file using blat command, use the below command

blat -s “test mail” -i “Syed Jahanzaib / Admin” -to your-user-id@xyz.com.pk -body “Please see attached file” -attach c:\test.txt

+++++++++++++++

Email/Delete Files OLDER then X days Examples:

CORE EXAMPLE
forfiles -p “C:\test” -s -m *.* -d 0 -c “cmd /c c:\blat\blat.exe -to your-user-id@xyz.com.pk -i myname -s INFRA_LOGS -body INFRA_SERVERS_LOGS -attach @path”

Working EXAMPLE for file_server/ For TAPE BACKUP LOGS

forfiles -p “C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data” -s -m *.* -d 0 -c “cmd /c c:\blat\blat.exe -to your-user-id@xyz.com.pk -i myname -s INFRA_LOGS -body INFRA_SERVERS_LOGS -attach @path”

TO show (DELETE removed from syntax) FILES OLDER THEN X DAYS (in the below example its 30 days)

FORFILES /p c:\temp /d -30 /m * /c “cmd /c echo @file”

TO show (DELETE removed from syntax) FILES For TODAY

FORFILES /p c:\temp /d 0 /m * /c “cmd /c echo @file”

Windows 2003/7/2008 already have forfiles installed. but you can download it from here http://www.ipass.net/davesisk/forfiles.zip

.

Regard’s
Syed Jahanzaib


Filed under: Microsoft Related

iSCSI SAN/NAS SOLUTION FOR ESXi SERVER (Tutorial No 5)

Backup Files via CMD/Batch/ntbackup Scripts [Personnel Notes]

$
0
0

Salam to All,

Following are few backup batch files that I have used at my office to perform backup operation using scheduled backup tasks. I am posting them just for reference so they can be used as archiving or possibly useful for others too having same task.

+++++++++++++++++++++++++++++++++++++++

Few days back, a new oracle server was added in our IT dept. It is an oracle database server which serves many users request in our company. There was an annoying manual backup task that we have to perform on it on daily basis , the :@ task was to run 2 shortcut which creates backup dump files in E: drive, and then we have to manually rename the 2 dump files according to current date and then move them in other date-wise folder.
Quite annoying , isn’t it ? I mean still do we have to perform simple tasks like taking backup manually where every task is being done Automatically ?
Stupid enough ! :P

It was quite easy to do this task automatically in LINUX environment, but as currently i am working in MS (Microshit or Microsoft environment) I manage to done it with built-in DOS commands. Following is the complete dos batch file or call it the Backup script ;) , I just added in Schedule task, Now it runs daily and saves my time.

@echo off
Echo Oracle Backup Organizer Script.
Echo Developed by Syed Jahanzaib / aacable@hotmail.com
Echo Make sure you have the backkup folder where backup is copied on daily basis by other script.
Echo Setting current date
set dt=%date:~-4,4%%date:~-10,2%%date:~-7,2%

Echo Map File Server backup folder in local computer using admin account.
net use B: \\FILES_SERVER\D$\home\cic /USER:zaib-admin@localdomain admin-passwd

Echo Copying already created oracle Dump files (which you can create by using backup file scheduled to run daily)
Echo into remote file server with current date for backup - FILES_SERVER

copy e:\backup\Cic_final.Dmp B:\cic-backup.%dt%.dmp
copy e:\backup\nae_final.dmp B:\nae-backup.%dt%.dmp

Echo Renaming dump files to current date for the date wise backup
ren e:\backup\Cic_final.Dmp cic-backup.%dt%.dmp
ren e:\backup\nae_final.dmp nae-backup.%dt%.dmp

echo.
echo All Backup done. Allah Hafiz

NTBACKUP with EMAIL the LOGS and START/END Time Report

@echo off
rem #######################################################
rem Setting various Descriptions via environment variables
rem #######################################################

set dt=%date:~-4,4%%date:~-10,2%%date:~-7,2%
set logpath="C:\Documents and Settings\administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"
rem you must create .bks file using ntbackup GUI , os it knows which data to backup below
set backup-data=C:\backup\Users Autobackup of Users DATA.bks
set description=Users Autobackup
set jobname=Users Autobackup - DATA Backup TASK
set attachment=C:\backup\fileserver-ntbackup-%dt%.log
set mail-subject=Users Autobackup - DATA Backup TASKy
set mail-body=Users Autobackup - DATA Backup TASK
set mail-to="aacable@hotmail.com","email2@aacable.xyz"

rem set totaletime=%tot%

rem ######################################
rem Starting Backup in IBM LTO3 Tape Drive
rem ######################################

start /wait C:\WINDOWS\system32\ntbackup.exe backup "@%backup-data%" /n "%jobname%" /d "%description%" /j "%jobname%" /l:s /p "LTO Ultrium" /UM /v:no /r:yes /rs:no /hc:on /m normal

rem ### Copy current data last LOG to C:\backup
rem cd %logpath%
rem FOR /F %%i IN ('DIR /B /O:-D *.log') DO (
rem copy "%%i" %attachment%
rem cd c:\backup

forfiles -p %logpath% -s -m *.log -d 0 -c "cmd /c copy @file %attachment%"

rem #########################
rem STart END Time Algorithm
rem #########################

setlocal enableextensions enabledelayedexpansion
set starttime=%time%
ping -n 2 127.0.0.1 >nul: 2>nul:
set endtime=%time%
set total="echo Total   = %tot%"

set /a hrs=%endtime:~0,2%
set /a hrs=%hrs%-%starttime:~0,2%

set /a mins=%endtime:~3,2%
set /a mins=%mins%-%starttime:~3,2%

set /a secs=%endtime:~6,2%
set /a secs=%secs%-%starttime:~6,2%

if %secs% lss 0 (
set /a secs=!secs!+60
set /a mins=!mins!-1
)
if %mins% lss 0 (
set /a mins=!mins!+60
set /a hrs=!hrs!-1
)
if %hrs% lss 0 (
set /a hrs=!hrs!+24
)
set /a tot=%secs%+%mins%*60+%hrs%*3600

echo End     = %endtime%
echo Start   = %starttime%
echo Hours   = %hrs%
echo Minutes = %mins%
echo Seconds = %secs%
echo Total   = %tot%

rem ##########
rem Email LOGS
rem ##########

rem goto :blat)
rem :blat

c:\blat\blat.exe -to %mail-to% -i MY_SERVER_NAME -s "%mail-subject%" -body "%mail-body%|Backup Report:|Start   = %starttime%|End     = %endtime%|Hours   = %hrs%|Minutes = %mins%|Total   = %tot%||Automated Backup & Email Logs Script Created by  SYED_JAHANZAIB." -attach %attachment%
endlocal
rem ## THE END

To delete files olde then X days using FORFILES

forfiles /p “C:\test” /s /m *.* /c “cmd /c del @path” /d -15

Change /d -15 to match your requirements. you can change the del command to any other like to show the files, use echo. FORFILES is builtin command with Windwos 2003 /7. You can download it from
http://www.ipass.net/davesisk/forfiles.zip

Delete Files Over 15 Days Old using ROBOCOPY

set _robodel=%TEMP%\~robodel
MD %_robodel%
ROBOCOPY “C:\source_folder” %_robodel% /move /minage:15
del %_robodel% /q

Batch File to create SQL Backup

First create .sql file that can be called from batch file to create any specific DB backup.

for example c:\zaibdb.sql

BACKUP DATABASE [Promo] TO  DISK = N'D:\DataBaseBackup\zaibdb.Bak' WITH NOFORMAT, INIT,  NAME = N'Promo-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

now create a batch file which will call the above .sql file to start backup.

for example c:\start_backup.bat

@echo off
echo Creating FULL backup in D:\zaibdb.back
echo %Date% >> D:\DataBaseBackup\zaibdb.txt
sqlcmd -S .\SQLEXPRESS -i c:\zaibdb.sql > D:\DataBaseBackup\zaibdb.txt
echo.
echo Done
rem ping 127.0.0.1 -n 10 > null
echo . >> D:\DataBaseBackup\zaibdb.txt
echo This backup set was last created at %Date%  >> D:\DataBaseBackup\zaibdb.txt
echo.

Another Backup script that map remote  server folder locally
and then copy the required files and then delete the files older then 20 days

@echo off
rem Syed Jahanzaib / ??? (Pvt) Ltd. IS Dept.
rem This file will copy the today's SAP exports and cofiles only to files_server\export folder,
rem which is actually mapped locally as B: drive.
rem #
rem #
rem #
rem # Mapping files_server Folder via agpis Credentials
net use B: \\files_server\

rem # Copying Last Date Export files to \\file-server\B:\export folder
forfiles -p "J:\required_folder" -s -m *.* -d 0 -c "cmd /c copy @path B:\"

rem # Copying Last Date cofiles data to \\file-server\B:\cofiles folder
forfiles -p "J:\required_folder" -s -m *.* -d 0 -c "cmd /c copy @path B:\"

rem # Deleting export older then 20 Days . . .
forfiles -p "J:\required_folder" -s -m *.* -d -20 -c "cmd /c del @path"

rem # Deleting cofiles Logs older then 20 Days . . .
forfiles -p "J:\required_folder" -s -m *.* -d -20 -c "cmd /c del @path"

.

Daily Backup of Required Folder using ROBOCOPY

Robocopy method which will copy only new file by matching source and destination folder/file timstamps. Its much better as it displays results in command prompt with percentage and all the necessary info any admin want. :) its my favorite. You can downlod Robocopy by downloading Microsoft Resource Kit from following link.
http://www.microsoft.com/en-us/download/details.aspx?id=17657

@echo off
Robocopy /E /LOG+:h:\Softwares\Servers_Related\mail-backup-log.txt B:\archive\.  T:\backup\archive

Robocopy /E /LOG+:h:\Softwares\Servers_Related\mail-backup-log.txt T:\mailserver\c$\mt\.  T:\backup\mt

Robocopy /E /LOG+:h:\Softwares\Servers_Related\mail-backup-log.txt T:\mailserver\mail\.  T:\backup\mail

The above commands description is as follows.
/E  = Copy sub-directories, including Empty ones
/LOG+ = Output status to LOG file (append to existing log, so previous entries along with new one should be saved together, if you don’t use + , it will overwrite existing log-file, means delete old entries and overwrite new one)).

XCOPY Method

Following file will copy all the data from the source folder to target folder using windows builtin copy tool XCOPY.

@echo off

echo * * *  >> C:\backup-log.txt
echo Mail Backup Starts at %date% - %time%  >> C:\backup-log.txt

C:\windows\system32\xcopy.exe B:\source-folder\*.*  T:\targetfolder /S /D /C /Y

echo Mail Backup Ends at %date% - %time%  >> C:\backup-log.txt
echo * * * >> C:\backup-log.txt 

The above commands description is as follows.

/S = Copies directories and sub-directories except empty ones.
/D =  If no date is given, copies only those files whose  source time is newer than the destination time.
/C = Continues copying even if errors occur.
/Y  = Overwrite existing files if any without prompting, its necessary when you are running xcopy via batch / script file.

Regard’s
Syed Jahanzaib


Filed under: Microsoft Related

Active Directory DSQUERY & Miscellenous Commands with Syntax

$
0
0

Recently We were asked by the Auditors to provide some data of Active Directory for yearly Audit purpose. I already have few scripts that saved a lot of time. I also linked these scripts with the Linux base WEBMIN, so they can be called by nice GUI as showed in the example below.

Image

.

<How to link Linux base scritps with the webmin>

Following are scripts

Show All users in your domain

dsquery * dc=yourdomainname -filter “(&(objectCategory=Person)(objectClass=User))” -limit 0

Show All Users Created Since 1st January, 2012 till date

dsquery * dc=yourdomainname -filter “(&(objectCategory=Person)(objectClass=User)(whenCreated>=20120101000000.0Z))”

Show Users For Specific Period (Jan-2012 till Dec-2012)
e.g: Display Users Created from 1st January 2012 till 31st December 2012 (1 Year) Only.

dsquery * dc=yourdomainname -filter “(&(objectCategory=Person)(objectClass=User)(whenCreated>=20120101000000.0Z-)(whenCreated<=20121231000000.0Z-))”

> = greater then
< = less then
~ = approx
= equals

Miscellaneous commands . . .

Show All Users Info (Active/Non Active)
dsquery user -limit 0 | dsget user -dn -disabled

Show Inactive Users Only (Users that haven’t logged on since last 2 weeks)
dsquery user “dc=Your_Domain_Name” -inactive 2

Show DISABLED Users Only
dsquery user -disabled | dsget user -display -email -dept -title

Show ACTIVE Users Only
dsquery * -filter “(&(sAMAccountType=805306368)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))” -limit 0 | dsget user -display -email -dept -title

Show Users from Specific Group Only
dsquery group DC=yourdomainname -name “Type Group Name” | dsget group -members |sort |dsget user -display -email -dept -title

Show Only Specific User Details
Net user USERID /domain

Regard’s
Syed Jahanzaib


Filed under: Microsoft Related
Viewing all 409 articles
Browse latest View live