Syed Jahanzaib – Personal Blog to Share Knowledge !

September 29, 2015

Sending SMS in URDU/ARABIC or other language via KANNEL

Filed under: Linux Related — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 10:41 AM

u[OS = Ubuntu]

It is very easy to send SMS in URDU or ARABIC fonts using KANNEL as your gateway using &charset=UTF-8&coding=1  (in some cases its &charset=UTF-8&coding=2) code.

Just add the following in your /etc/kannel.conf file under SMSC section

 alt-charset= "UTF-8" 

 

 

Save & restart kannel service

service kannel stop
killall -9 bearerbox
service kannel start

 

EXAMPLES:


 

To send SMS in URDU via browser / URL via KANNEL

http://KANNEBOXIP/cgi-bin/sendsms?username=kannel&password=KANNELPASSWORD&to=03333021909&charset=UTF-8&coding=1&text=سلام+علیکم+آپ+KANNEL+میں+بہت+آسانی+سے+اردو+فونٹس+میں+ایس+ایم+ایس+بھیج+سکتے+ہیں.+مثال+اکاؤنٹ+ختم+ہونے+کی+معلومات،+مرحبا+پیغامات+وغیرہ+وغیرہ+شکریہ+سید+جہانزیب

Result Example:

urdu

You can get the urdu/arabic font by translating it via translate.google.com and copy paste the translated text.


 

To send SMS in URDU using Local FILE via KANNEL

Use any UTF converter tool /notepad /word etc, OR if you dont have one,  do it online via Converter TEXT to encoded

Paste your URDU text and hit Enter it will give you UTF8 encoded data,As showed here

utf8

Copy that data and paste it in any local file, example /temp/urdu.txt

Now use the below command from the Linux terminal to send this file contents via kannel in URDU ; )


curl "http://KANNELBOXIP:13013/cgi-bin/sendsms?username=kannel&password=KANNELPASS&to=03333021909&charset=UTF-8&coding=1" -G --data-urlencode text@/temp/urdu.txt

Result Example:file


 

Note: If you still receive SMS with ??? signs , then try with

http://KANNEBOXIP/cgi-bin/sendsms?username=kannel&password=KANNELPASSWORD&to=03333021909&charset=UTF-8&coding=2&text=سلام+علیکم+آپ+KANNEL+میں+بہت+آسانی+سے+اردو+فونٹس+میں+ایس+ایم+ایس+بھیج+سکتے+ہیں.+مثال+اکاؤنٹ+ختم+ہونے+کی+معلومات،+مرحبا+پیغامات+وغیرہ+وغیرہ+شکریہ+سید+جہانزیب

جزاک اللہ

سید جہانزیب

September 26, 2015

Using SMS CLI option in playSMS to enhance security for SMS base renewal

Filed under: Linux Related, Mikrotik Related — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 11:17 AM

cli

Another approach here …

https://aacable.wordpress.com/2018/07/17/freeradius-with-mikrotik-part-17-retrieve-user-password-via-sms/

 

TASK:

Operator requirement was to have a facility via which he can renew user account by simply sending sms to the radius system with user account name + admin password and above all only his mobile number should be authorized for this action. So basically two levels of securities are  required. One is admin password, second is sender CLI , something like mac address, and this is really strong because spoofing mobile numbers is not easily possible.

This method was also required because sometimes admin is out of station and opening billing page in mobile is not an easy task dueto to complex billing pages, navigation lot of pages in order to simple renew user account, and it requires good internet connectivity as well too. What if internet facility is not available in remote part, then SMS comes really handy to perform few or basic level of task.

This post is one of my ‘Sharing Ideas’  series which are practically implementable very easily and i have done it at few networks too. I know there are always many ways to achieve the same task. I just picked the easiest one. This code can be trimmed as it contains junks as it was made quickly in the lab. You can achieve the same task with some PHP code decently but that’s not my area

 


 

 

SOLUTION: A simple Script !

The following bash script will do the following.

  1. Upon receiving of SMS , it will first verify the SENDER SMS , if not found in /temp/adminmobile.txt , then it will return error and exit, otherwise continue to next step
  2. It will check for the Valid admin password , if not matched with /temp/password.txt, then it will return error and exit, otherwise continue to next step
  3. It will then check for valid user in radius mysql users table, if not found then it will exit, otherwise continue to next step
  4. If all conditions matches, it will simply renew the account by adding 31 days to the account and add entries in SYSLOG events, and it will also add full invoice in the ADMIN account. It will also return the FULL reply with the actions taken to the sender.

TIP: As you can see I have used simple text file to store the admin mobile number and simple password, but its recommended to use mysql table to store the said info for better reasons.


 

 

playSMS Section:

  • Login to PlaySMS
  • Goto Features / Manage Command / Add Sms Command
  • Create Command as showed in the image.

playsms-renewal commandPay attention to the SMSSENDER. by default playsms will add comma in between commandparm and smssender, so we will use SED to separate them : ).
SAVE the Command.

Now moving to script section


 

SCRIPT SECTION

Create script with any name (as mentioned in the playSMS section) and paste the date.
Just make sure you change user info like mysql id / password / text file names and location for admin mobile and admin password.

  • mkdir /temp
  • touch /temp/adminmobile.txt
  • touch /temp/password.txt

[Now add the password and mobile number of Admin. mobile number must be in following format  923333021909]

Now create the script in /var/lib/playsms/sms_commands/1

  • touch /var/lib/playsms/sms_commands/1/adrenew.sh
  • chmod +x /var/lib/playsms/sms_commands/1/adrenew.sh
  • nano touch /var/lib/playsms/sms_commands/1/adrenew.sh

[paste the following data and modify it as required]


# Script to renew account via sms with password and admin mobile CLI security
# Designed by Syed Jahanzaib for Test Purposes for a network
# 25th September, 2015
# aacable at hotmail dot com
# https://aacable.wordpress.com
# Script Starts Now

#!/bin/bash
SQLUSER="root"
SQLPASS="YOUR_SQL_PASSWORD"
echo $1 | sed 's/[+]/ /g' > /tmp/adminrenew

# Password file for storing Admin Password, better to use mysql query to fetch the password
PASS=`cat /tmp/adminrenew | awk {' print $1 '}`
USR=`cat /tmp/adminrenew | awk {' print $2 '}`

# File to store Admin Mobiel Number to match with the sender number
SENDER=`cat /tmp/adminrenew | awk {' print $3 '}`
NEXTEXPIRYADD=$(date +"%Y-%m-%d" -d "+31 days")

# LOOK FOR AUTHORIZED MOBILE NUMBER AND MATCH IT WITH LOCAL FILE
ADMINMOBILE=`cat /temp/adminmobile.txt`
if [ "$SENDER"  != "$ADMINMOBILE" ]; then
echo -e "ERROR: You number is not authorized to send SMS to this sytem! Jz"
exit 0
fi

# LOOK FOR VALID PASSWORD IN LOCALFILE
PASSVALID=`cat /temp/password.txt`
if [ "$PASS"  != "$PASSVALID" ]; then
echo -e "ERROR: Incorrect Admin Password!"
exit 0
fi

#LOOK FOR VALID USER IN RADIUS
USRVALID=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvid FROM radius.rm_users WHERE rm_users.username = '$USR';"`
if [ "$USRVALID" == "" ]; then
echo -e "ERROR: USER NOT FOUND!"
exit 0
fi

######################
# ACCOUNT EXPIRY CHECK
######################

TODAY=$(date +"%Y-%m-%d")
TODAYDIGIT=`echo $TODAY  | sed -e 's/-//g'`
MONTH=$(date +"-%m")
CMONTH=`echo $MONTH  | sed -e 's/-//g'`
MONTHYEAR=$(date +"%B-%Y")
ALPHAMONTHYEAR=`echo $MONTHYEAR #| sed -e 's/-//g'`
SRVEXPIRYFULL=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$USR';" |awk 'FNR == 2'`
SRVEXPIRYFULLD=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$USR';" |awk '{print $1}' | sed 's/expiration//'`
SRVEXPIRY=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$USR';" |awk 'FNR == 2' | sed -e 's/-//g' | sed 's/00:.*//'`
LOGOFFDATE=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT lastlogoff FROM radius.rm_users WHERE username = '$USR';"  |awk 'FNR == 2 {print $1,$2}'`
SRVID=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvid FROM radius.rm_users WHERE rm_users.username = '$USR';" |awk 'FNR == 2 {print $1}'`
SRVPRICE=`mysql -u$SQLUSER -p$SQLPASS -e "use radius;  SELECT unitprice FROM radius.rm_services WHERE rm_services.srvid = $SRVID;" |awk 'FNR == 2 {print $1}' | cut -f1 -d"."`

#LOOK FOR USER ACTUAL SERVICE NAME
PKGNAME=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvname FROM radius.rm_services WHERE rm_services.srvid = '$SRVID';" |awk 'FNR == 2'`

# Look for Pakacge Quota trafficunitcomb
#PKGQUOTA=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT trafficunitcomb FROM rm_services WHERE srvid= '$SRVID';" |awk 'FNR == 2'`
#PKGQUOTAB=$(($PKGQUOTA / 1024))

########### ACCOUNT STATUS EXPIRED TODAY ACTION ############
if [ $SRVEXPIRY -eq $TODAYDIGIT ]
then
echo "Account Status: EXPIRED TODAY! Last LOGOUT date: $LOGOFFDATE"
NEXTEXPIRYADD=$(date +"%Y-%m-%d" -d "+31 days")

# PRINT FETCHED VALUES , JUST FOR INFO / ZAIB
echo User Account  = $USR
echo User Package = $PKGNAME
echo Service Price at Billing = $SRVPRICE PKR
echo -e "Next Expiry =  $NEXTEXPIRYADD"

# ADD 30 DAYS VALUE TO EXPIRED USER ACCOUNT
mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET expiration = '$NEXTEXPIRYADD' WHERE username = '$USR';"

# ADD SYSLOG ENTRY
mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_syslog (datetime, ip, name, eventid, data1) VALUES (NOW(), '$SENDER', 'galaxy', 'Account Renewed', '$USR', '$USR renewd - $PKGNAME');"

# Add rough DATA in INVOICE for billing purpose
mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_invoices (managername, username, date, bytesdl, bytesul, bytescomb, downlimit, uplimit, comblimit, time, uptimelimit, days, expiration, capdl, capul, captotal, captime, capdate, service, comment, transid, amount, invnum, address, city, zip, country, state, fullname, taxid, paymentopt, paymode, invtype, paid, price, tax, remark, balance, gwtransid, phone, mobile, vatpercent ) VALUES ('admin-$SENDER', '$USR', NOW(), '0', '0', '0', '0', '0', '0', '0', '0', '31', '$NEXTEXPIRYADD', '0', '0', '0', '0', '1', '$PKGNAME', '', '$TODAY', '1', '$TODAY', '', '', '', '', '', 'admin SMS renewed ', '', DATE_ADD(CURDATE(), INTERVAL '14' DAY), '0', '0', '$TODAY', '$SRVPRICE', '0.000000', '', '0.00', '', '', '03333021909', '0.00' );"

########### ACCOUNT STATUS EXPIRED IN PAST ACTION ############

elif [ $SRVEXPIRY -lt $TODAYDIGIT ]
then
echo "Account Status: EXPIRED on $SRVEXPIRYFULL! Last LOGOUT date: $LOGOFFDATE"
NEXTEXPIRYADD=$(date +"%Y-%m-%d" -d "+31 days")

# PRINT FETCHED VALUES , JUST FOR INFO / ZAIB
echo User Account  = $USR
echo User Package = $PKGNAME PKR
echo Service Price at Billing = $SRVPRICE PKR
echo -e "Next Expiry =  $NEXTEXPIRYADD"

# ADD 30 DAYS VALUE TO EXPIRED USER ACCOUNT
mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET expiration = '$NEXTEXPIRYADD' WHERE username = '$USR';"

# ADD SYSLOG ENTRY
mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_syslog (datetime, ip, name, eventid, data1) VALUES (NOW(), '$SENDER', 'galaxy', '$USR', '$USR renewd - $PKGNAME');"

# Add rough DATA in INVOICE for billing purpose
mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_invoices (managername, username, date, bytesdl, bytesul, bytescomb, downlimit, uplimit, comblimit, time, uptimelimit, days, expiration, capdl, capul, captotal, captime, capdate, service, comment, transid, amount, invnum, address, city, zip, country, state, fullname, taxid, paymentopt, paymode, invtype, paid, price, tax, remark, balance, gwtransid, phone, mobile, vatpercent ) VALUES ('admin-$SENDER', '$USR', NOW(), '0', '0', '0', '0', '0', '0', '0', '0', '31', '$NEXTEXPIRYADD', '0', '0', '0', '0', '1', '$PKGNAME', '', '$TODAY', '1', '$TODAY', '', '', '', '', '', 'admin SMS renewed ', '', DATE_ADD(CURDATE(), INTERVAL '14' DAY), '0', '0', '$TODAY', '$SRVPRICE', '0.000000', '', '0.00', '', '', '03333021909', '0.00' );"

# Update QUOTA for the USER
#mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET comblimit = '$PKGQUOTAB' WHERE username = '$USR';"

else
########### ACCOUNT STATUS OK! ACTION ############

echo -e "User Billing Info:"
echo "Account STATUS= OK!"

NEXTEXPIRYADD=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; select DATE_ADD(expiration, INTERVAL 31 DAY) as x from rm_users where username= '$USR';" |awk 'FNR == 2'`

# PRINT FETCHED VALUES , JUST FOR INFO / ZAIB
echo User Account  = $USR
echo User Package = $PKGNAME PKR
echo Service Price at Billing = $SRVPRICE PKR
echo -e "Next Expiry =  $NEXTEXPIRYADD"

NEXTEXPIRYADD=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; select DATE_ADD(expiration, INTERVAL 31 DAY) as x from rm_users where username= '$USR';" |awk 'FNR == 2'`

# ADD 30 DAYS VALUE TO EXPIRED USER ACCOUNT
mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET expiration = '$NEXTEXPIRYADD' WHERE username = '$USR';"

# ADD COMMENTS
mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET comment = 'Last renewed by SMS $SENDER'  WHERE username = '$USR';"

# ADD SYSLOG ENTRY
mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_syslog (datetime, ip, name, eventid, data1) VALUES (NOW(), '$SENDER', 'galaxy', 'Account Renewed', '$USR renewd - $PKGNAME');"

# Add rough DATA in INVOICE for billing purpose
mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_invoices (managername, username, date, bytesdl, bytesul, bytescomb, downlimit, uplimit, comblimit, time, uptimelimit, days, expiration, capdl, capul, captotal, captime, capdate, service, comment, transid, amount, invnum, address, city, zip, country, state, fullname, taxid, paymentopt, paymode, invtype, paid, price, tax, remark, balance, gwtransid, phone, mobile, vatpercent ) VALUES ('admin-$SENDER', '$USR', NOW(), '0', '0', '0', '0', '0', '0', '0', '0', '31', '$NEXTEXPIRYADD', '0', '0', '0', '0', '1', '$PKGNAME', '', '$TODAY', '1', '$TODAY', '', '', '', '', '', 'admin SMS renewed ', '', DATE_ADD(CURDATE(), INTERVAL '14' DAY), '0', '0', '$TODAY', '$SRVPRICE', '0.000000', '', '0.00', '', '', '03333021909', '0.00' );"

fi

# Script ENDs here
# Thankoooo . zaib


 

TEST AND RESULTS

Now send sms in following format to the radius/playSMS attached system.

adrenew YOURPASS USERNAME

and you will receive reply accordingly as showed in the image below …

2015-09-26 05.16.45


 

:)~~

Regard’s
Syed Jahanzaib

September 22, 2015

Mikrotik User Manager False Active Session Removal Scripts

Filed under: Mikrotik Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 2:21 PM

duplicate

Mikrotik ‘User Manager‘ is a free and builtin package of mikrotik which provides basic level of radius / billing capabilities. Its good for smaller networks but form its introduction till the latest version, it always contains few bugs that can be sometimes annoying for the admin and surely not suitable for large production environment like ISP’s. One little example is FALSE active sessions in userman where user actually not active any more in the Mikrotik connected session but the userman shows it active thus preventing user from re-connecting.

This usually happens when users lost connectivity [specially wifi users] or disconnected from the mikrotik but userman still keep it in its active session therefore the user gets denied when he try to re-connect. so when the admin manually remove its Active session from the userman web interface, user then able to connect.

This is no mean a solution, but you can say as a workaround only a script was posted in mikrotik forums, therefore re-posting with some mods it so that it may help others as well. Just for reference purposes.

Schedule it to run according to your router load. on the load of around 150+ users with low end router, I schedule it to run after every 5 minutes as this script does take some times to calculate each user so take a note of it. adjust value accordingly.

 


# Script Source : Mikrotik Forums
# This script remove false active sessions in User Manager v5 or above
# I only tested it with ver 6.32.1 and it worked very well in a active network. [Jahanzaib]

# Script Starts Here.
# Setting Timeout in Seconds
# Timeout in Seconds, when session update is older -> session closed
:local Timeout 60

#------------------------------------------
:local LastSessionUpdate;
:local SessionTimeout;
:foreach i in=[/tool user-manager session find where active=yes] do={

# When was the last Update of the session-informations
:set LastSessionUpdate [/tool user-manager session get $i till-time]

# SessionTimeout is a value that tells me how many seconds ago the last update of this session was
:set SessionTimeout ([system clock get time] - [:pick $LastSessionUpdate ([:find $LastSessionUpdate " "]+1) [:len $LastSessionUpdate]]-[/system clock get gmt-offset])

# if last update is more then Timeout seconds ago then close session and log it
:if ($SessionTimeout > $Timeout) do={
/tool user-manager session remove  numbers=$i
:log warning (" Removed false active session by Zaib - Username is  " . [/tool user-manager session get $i user]);
}
}

userman_+false

September 17, 2015

Monitoring multiple WAN links in PCC using BLACK-HOLE route approach !

Filed under: Mikrotik Related — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 12:18 PM

bh

Scenario:

Dual pppoe-client wan links are configured in mikrotik with PCC load balancing.

Task:

To monitor both (ow more) wan links via some fixed routes and email in case any goes down or take other action as required.

Solution:

You must be aware that to achieve any task, there are multiple ways to do so, Select whatever is best and whatever works for you (offcourse without affecting any other functionality). I tried various solutions to monitor pppoe-wan clients, but most of them didn’t worked as I wanted. So I used blackhole route approach and it worked 100%.

Example:

[This example is just for demonstration purpose only. In the real production environment you MUST use multiple host monitoring , because it is very possible that if you monitor single host, and for some reason ISP blocks it, or the owner of the host close it for maintenance then what happens? YES you will get false alarm even if the internet is working fine. To avoid such false alarms ,You must use multiple host to monitor each wan link I wrote multiple wan monitor script in some previous post, search it.)

For WAN-1 link we will monitor 4.2.2.1  [DNS Server]
For WAN-2 link we will monitor 208.67.222.123 [Open DNS server IP]

 

/ip route
add comment="WAN-1  /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=1 dst-address=4.2.2.1/32 gateway=pppoe-out1 scope=30 target-scope=10

add comment="WAN-2  /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=1 dst-address=208.67.222.123/32 gateway=pppoe-out2 scope=30 target-scope=10

PROBLEM:

The problem is that as soon as one WAN (pppoe-out1 disconnects for any reason like line dead etc, the PING will then look in main table and whatever route it found (example pppoe-out2) it will pass the traffic from that available wan link, and this is BAD for our monitoring script because we wanted to FORCE specific route to always pass via specific link only.

For this reason we will duplicate above routes, BUT this time we will use type ‘blackhole‘ and create higher distance value so that when default route FOR SPECIFIC MONITORED HOST goes down, then next route with higher distance value will be enabled automatically and will send packets to black-hole resulting in timeout which we will be using in net watch monitoring scripts.

 

add comment="WAN-1  blackhole /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=2 dst-address=4.2.2.1/32 type=blackhole

add comment="WAN-2  blackhole /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=2 dst-address=208.67.222.123/32 type=blackhole

So as soon as WAN1 goes down, the ping to 4.2.2.1 will go to BLACKHOLE / timeout dueto above rules. same for wan2.

 


Example script to monitor wan link and email or take other action

Complete script to monitor wan1 is as follows. Just for reference purposes.


# Syed Jahanzaib / aacable @ hotmail.com
# https://aacable.wordpress.com
# WAN Monitor script (for single host) and email if down/up
# Kindly configure tools/Email first to send email alert
# Modified on : 26-NOV-2015 added KANNEL sms support, on request of mr anotnino ITALY

:local i 0;
:local F 0;
:local date;
:local time;
:set date [/system clock get date];
:set time [/system clock get time];

:global DSL1netstatus;
:global DSL1netLastChange;

:local adminmail1 "YOUR MAIL ADDRESS"
:local gmailid "YOURGMAILID@gmail.com"
:local gmailpass "YOURGMAILPASS"

# If you have KANNEL , you can modify below

:local KANNEHOST "192.168.100.1"
:local KANNELID "kannel"
:local KANNELPASS "kannel"
:local cell1 "03333021909"

# Donot use spaces in following, instead use plus sign to accomodate space
:local COMPANY "MY_ISP_ZAIB"
:local UPSMS "$COMPANY+INFO:+WAN-1+is+UP+now+at+$date+$time"
:local DOWNSMS "$COMPANY+ALERT:+WAN-1+is+DOWN+now+at+$date+$time"


# Check WAN1 GATEWAY to be monitored (Currently we are monitoring internet host)
:global wan1host1 4.2.2.1

# Gmail SMTP Address
:global gmailsmtp
:set gmailsmtp [:resolve "smtp.gmail.com"];

# Ping Internet Host 10 times,
:for i from=1 to=10 do={
if ([/ping $wan1host1 count=1]=0) do={:set F ($F + 1)}
:delay 1;
};

# If no response (10 out of 10 Ping fails for each item, Times out, then LOG down status and take action
:if (($F=10)) do={
:if (($DSL1netstatus="UP")) do={
:set DSL1netstatus "DOWN";

# Also add status in global variables to be used as tracking
:set date [/system clock get date];
:set time [/system clock get time];
:set DSL1netLastChange ($time . " " . $date);


##################################################
####### FOR DOWN STATUS, CHANGE THE RULES ########
##################################################
# If the link is down, then LOG info and warning in Mikrotik LOG window [Zaib]
:log error "WAN1 Gateway Not Responding. Please Check DSL1 Connectivity..."


# "Emailing the DOWN status. . . "
/tool e-mail send to="$adminmail1" password=$gmailpass subject="$[/system clock get date] $[/system clock get time] -- ALERT: PTCL DSL-1 is DOWN" from=$gmailid server=$gmailsmtp tls=yes body="$[/system clock get date] $[/system clock get time] : ALERT: PTCL DSL-1 is DOWN"

# IF USB MODEM IS CONNECTED WITH LOCAL RB THEN USE FOLLOWING
#/tool sms send port=usb3 phone-number=$cell4  message="INFO: xxxxx Network DSL-1 is DOWN ... / by Jz."  channel=0

# IF YOU HAVE SMS GATEWAY LIKE KANNEL USE FOLLOWING
# Send DOWN SMS
#/tool fetch url="http://$KANNELHOST:13013/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$cell1&text=$DOWNSMS"


##################################################
####### FOR UP STATUS, CHANGE THE RULES ########
##################################################
# If ping is ok 5/5 reply received, then LOG UP and take action as required

} else={:set DSL1netstatus "DOWN";}
} else={
:if (($DSL1netstatus="DOWN")) do={
:set DSL1netstatus "UP";
# If link is UP, then LOG info and warning in Mikrotik LOG window [Zaib]
log warning "WAN1 Gateway RESTORED ..."

# "Emailing the UP  status. . . "
/tool e-mail send to="$adminmail1" password=$gmailpass subject="$[/system clock get date] $[/system clock get time] -- INFO: PTCL DSL-1 is UP Now." from=$gmailid server=$gmailsmtp tls=yes body="$[/system clock get date] $[/system clock get time] : ALERT: PTCL DSL-1 is UP Now."

# IF USB MODEM IS CONNECTED WITH LOCAL RB THEN USE FOLLOWING
#/tool sms send port=usb3 phone-number=$cell4  message="INFO: xxxxx Network DSL-1 is UP ... / by Jz."  channel=0

# IF YOU HAVE SMS GAETWAY LIKE KANNEL USE FOLLOWING
# Send UP SMS
#/tool fetch url="http://$KANNELHOST:13013/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$cell1&text=$UPSMS"


:set date [/system clock get date];
:set time [/system clock get time];
:set DSL1netLastChange ($time . " " . $date);

} else={:set DSL1netstatus "UP";}
}

 

EMAIL ALERT

 

alerts

SMS ALERT

sms_alert

LOG

WAN_DOWN_ALERTS_LOGS

 

You can perform other customized actions on DOWN or UP  too 🙂

 

Regard’s
SYED JAHANZAIB

September 15, 2015

Event ID 7000 The Diagnostic Service Host service failed to start !

Filed under: Microsoft Related — Tags: , , , — Syed Jahanzaib / Pinochio~:) @ 11:22 AM

7000 diagnostic service host error

The Diagnostic Service Host service failed to start due to the following error:
A privilege that the service requires to function properly does not exist in the service account configuration. You may use the Services Microsoft Management Console (MMC) snap-in (services.msc) and the Local Security Settings MMC snap-in (secpol.msc) to view the service configuration and the account configuration.

Today at my company, every domain user was receiving above error in  there Event logs / SYSTEM section.

To sort this issue i did following

  1. Login to Domain Controller PC
  2. Open Group policy editor (or run gpedit.msc from RUN) and edit default domain policy (or any other custom policy you may have other then default)
  3. Goto Computer or USER  Configuration -> Policies -> Windows Settings -> Security Settings -> Local Policies -> User Rights Assignment -> Profile system performance

There you may see only ADMINISTRATOR user added by default, now add following users

LOCAL SERVICE
NT Service\WdiServiceHost

Now open CMD and issue following command to force GPUDPATE.

gpupdate /force


 

 

At client end, clear the logs, and reboot system. After rebooting check Event Viewer and you wont see the error again. [I waited about 15 minutes before rebooting client]

 

Regard’s
Syed Jahanzaib

September 7, 2015

Resolving “Trust Relation between this workstation and the PDC”


Just adding this post as reference on howto solve TRUST RELATIONSHIP ERROR which may appear when you try to login to your workstation/server using domain account.

trust-error

In this post I have used NETDOM / Windows network wizard & Powershell methods. All worked fine for different OS

 


Method # 1 / NETDOM command

[Tested on various OS including Windows 2008/2016]

Login on the effected computer using any of below method

  • Using the local admin account
  • OR if you dont have the local admin account, then simply unplug the wire/wireless and then login with your domain ID and it will login using cached credentials, but this ID must have Admin privileges on local computer)

Open COMMAND prompt &  Issue following command

netdom resetpwd /s:domainserver /ud:domain\admin /pd:YOURPASSWORD

Example if you have following setup

  • AD Server Name : DC01
  • Domain Name : mydomain.local
  • User Name : DOMAIN_ADMIN_ID

Complete CMD example …

netdom resetpwd /s:dc01 /ud:mydomain.local\domain_admin_id /pd:YOURPASSWORD

Once you see successfull message , logoff or restart the machine, and then login with domain user account & hopefully it will login insha Allah.


Method # 2 / Powershell (version 3 required)

To reestablish trust you can also use powershell command. (You must have at least PS ver3. windows 2008/7 have ver 2 by default, so you may want to upgrade it from MS site here )

PS command:

Test-ComputerSecureChannel -repair -Credential (Get-Credential)]

It will ask you to enter account credentials, , simply enter domain\ID and password of domain Admin account, and enter.

After then simply log off and login with your domain id (or better to restart the system) and it will work Insha Allah.


Method # 3 (For Windows XP/7/10 Only which have network wizard option)

I accidentally deleted some COMPUTER accounts under Active Directory Users > Computers section, This resulted in Trust relationship error on various workstations,

At client side, unplug Wire, (& disable WiFi) , this will allow you to logon to workstation using your domain account,(Make sure your domain user have local admin rights,) then simply run the network wizard ,

Then reboot & will be restored just like in previous working condition.

if you use the network wizard, you dont have to join – re-join the domain, it will simply add the computer entry in AD.

If your domain account don’t have ADMIN privileges, then you have to login with system local admin account. If you even dont have local admin account then reset it from any password crack utility.

if nothing works, then you have to unjoin this workstation from the domain, and re join it. If you use same user id on rejoining then you will see the same user profile as before.

 


Upgrade Powershell in 2008

To upgrade powershell ver 2.0  to new version in windows 2008 R2 , do following

Afterwards It may ask you for a restart … Do so so changes can take effect.


Regard’s

Syed Jahanzaib

%d bloggers like this: