127.0.0.1 localhost.localdomain localhost 10.10.8.226 jbrgseveren01.steepler.local jbrgseveren01
[openfire] secret = XXXX deny=0.0.0.0/0.0.0.0 permit=10.10.8.226/255.255.255.0 read = all write = all
Server Name: AsteriskGSeveren01 ServerAddress: 10.10.8.98 Port: 5038 Username: openfire Password: XXXX
#!/usr/bin/perl # users.pl v1.1 # # Script to generate asterisk 'users.conf' file from Active Directory (LADP) on users which contains 'phone' attribute # # Using: # 1. Print users to STDOUT: # users.pl # # 2. Print users to file: # users.pl users_custom.conf use strict; use warnings; use Net::LDAP; use Lingua::Translit; ###################### ### BEGIN SETTINGS ### ###################### my $debug = 0; my $warning = 0; # name of Domain my $AD="steepler.local"; # Domain name in format AD # for example mydomain.ru my $ADDC="DC=steepler,DC=local"; # user in Active directory # example: "CN=asterisk,CN=Users,$ADDC" my $ADUserBind="cn=openfire, cn=users, dc=steepler, dc=local"; my $ADpass="XXXXXXX"; # base search tree # example "OU=Users,$ADDC" my $ADUsersSearchBase="$ADDC"; # Field in active directory where telephone number, display name, phone stored # "telephonenumber", "displayname", "mail" my $ADfieldTelephone="telephonenumber"; my $ADfieldFullName="displayname"; my $ADfieldMail="mail"; my $ADfieldUser="samaccountname"; my $ADfieldGroup="memberOf"; my $ADSearchGroup="CN=IM,CN=Users,DC=steepler,DC=local"; # You need to create a dialplan in your asterisk server; my $dialplan="office"; # default settings my $user_static = "context = $dialplan call-limit = 100 type = friend registersip = no host = dynamic callgroup = 1 threewaycalling = no hasdirectory = no callwaiting = no hasmanager = no hasagent = no hassip = yes hasiax = yes nat=yes qualify=yes dtmfmode = rfc2833 insecure = no pickupgroup = 1 autoprov = no label = macaddress = linenumber = 1 LINEKEYS = 1 callcounter = yes disallow = all allow = ulaw,alaw,iLBC,h263,h263p "; ####################### ### END OF SETTINGS ### ####################### my $ldap; # get array DNS names of AD controllers my $dig = "dig -t srv _ldap._tcp.$AD" . '| grep -v "^;\|^$" | grep SRV | awk "{print \$8}"'; my @adControllers = `$dig`; # try connect to AD controllers foreach my $controller (@adControllers){ $controller =~ s/\n//; #INITIALIZING $ldap = Net::LDAP->new ( $controller ) or next; print STDERR "Connected to AD controller: $controller\n" if $debug > 0; last; } die "$@" unless $ldap; my $mesg = $ldap->bind ( dn=>$ADUserBind, password =>$ADpass); #PROCESSING - Displaying SEARCH Results # Accessing the data as if in a structure # ie Using the "as_struct" method my $ldapUsers = LDAPsearch ( $ADUsersSearchBase, "$ADfieldGroup=$ADSearchGroup", [ $ADfieldFullName, $ADfieldTelephone, $ADfieldMail, $ADfieldUser ] )->as_struct; # translit RUS module. # GOST 7.79 RUS, reversible, GOST 7.79:2000 (table B), Cyrillic to Latin, Russian my $tr = new Lingua::Translit("GOST 7.79 RUS"); my %hashPhones = (); my $phones = \%hashPhones; my @out; while ( my ($distinguishedName, $attrs) = each(%$ldapUsers) ) { # if not exist phone or name - skipping my $attrPhone = $attrs->{ "$ADfieldTelephone" } || next; my $attrUser = $attrs->{ "$ADfieldUser" } || next; my $attrName = $attrs->{ "$ADfieldFullName" } || next; my $encName = $tr->translit("@$attrName"); my $attrMail = $attrs->{ "$ADfieldMail" } || [""]; # check for duplicates phone number if ( $phones -> {"@$attrPhone"} ){ my $currUser = "@$attrName"; my $existUser = $phones -> {"@$attrPhone"}; print STDERR "@$attrPhone alredy exist! Exist:'$existUser' Current:'$currUser'... skipping - '[@$attrPhone] $currUser'\n" if $warning; next; } else { $phones -> {"@$attrPhone"} = "@$attrName"; } # password for SID = (telephonenumber without first digit) + 1 # example: phone=6232 pass=233 #$phsecret =sprintf("%03d",( substr("@$attrVal",1,100)+1)); my $phsecret = "@$attrPhone"; my $lcuser = "@$attrUser"; $lcuser = lc($lcuser); push (@out, "@$attrPhone " . "$lcuser " . "$encName\n" ); } # End of that DN # print to file if (@ARGV){ open FILE, "> $ARGV[0]" or die "Error create file '$ARGV[0]': $!"; print STDOUT "Printing to file '$ARGV[0]'"; print FILE @out; close FILE; print STDOUT " ...done!\n"; } # print to STDOUT else{ print @out; } exit 0; #OPERATION - Generating a SEARCH #$base, $searchString, $attrsArray sub LDAPsearch { my ($base, $searchString, $attrs) = @_; my $ret = $ldap->search ( base => $base, scope => "sub", filter => $searchString, attrs => $attrs ); LDAPerror("LDAPsearch", $ret) && die if( $ret->code ); return $ret; } sub LDAPerror { my ($from, $mesg) = @_; my $err = "[$from] - error" ."\nCode: " . $mesg->code ."\nError: " . $mesg->error . " (" . $mesg->error_name . ")" ."\nDescripton: " . $mesg->error_desc . ". " . $mesg->error_text; print STDERR $err if $warning; }
#!/bin/bash TIMESTAMP=`/bin/date +%d%m%y%k%M%S` BACKUPDIR=/opt/openfire/bin/phone-mappings/backup BINDIR=/opt/openfire/bin WORKDIR=$BINDIR/phone-mappings SCRIPTNAMEDEVICE=$WORKDIR/phone-bindings-from-AD-device.sql SCRIPTNAMEUSER=$WORKDIR/phone-bindings-from-AD-user.sql SCRIPT=$WORKDIR/$SCRIPTNAME PERLSCRIPT=$BINDIR/users-from-AD.pl DEVICETPLHEAD=$WORKDIR/phoneDevice.tplhead DEVICEINJ=$WORKDIR/phoneDevice.inj DEVICETPLFOOT=$WORKDIR/phoneDevice.tplfoot USERTPLHEAD=$WORKDIR/phoneUser.tplhead USERINJ=$WORKDIR/phoneUser.inj USERTPLFOOT=$WORKDIR/phoneUser.tplfoot #backuping tables mysqldump -uXXXXXXX -pXXXXXXX openfire phoneDevice > $BACKUPDIR/phoneDevice-$TIMESTAMP.sql mysqldump -uXXXXXXX -XXXXXXX openfire phoneUser > $BACKUPDIR/phoneUser-$TIMESTAMP.sql # Clearing injections cat /dev/null > $DEVICEINJ cat /dev/null > $USERINJ # finding current Asterisk server ID in openfire DB serverID=`mysql -Bse "SELECT serverID FROM openfire.phoneServer;" -uXXXX -pXXXX` # resetting counters counter=0 counter2=0 #executing perl script to retrieve current phone numbers from AD for i in `$PERLSCRIPT`; do counter=`expr $counter + 1` binder[$counter]=$i done maxcount=$counter counter=1 while [ "$counter" -lt "$maxcount" ] do # deviding array into two with extensions and jids counter2=`expr $counter2 + 1` extension=${binder[$counter]} counter=`expr $counter + 1` username=${binder[$counter]} counter=`expr $counter + 1` callerID=${binder[$counter]} counter=`expr $counter + 1` callerID=$callerID\ ${binder[$counter]} counter=`expr $counter + 1` deviceID=$counter2 userID=$counter2 # Creating phoneDevice injection echo INSERT INTO \`phoneDevice\` VALUES\($deviceID,\'SIP/$extension\',\'$extension\',\'$callerID\',1,$userID,$serverID\)\; >> $DEVICEINJ # Creating phoneUser injection echo INSERT INTO \`phoneUser\` VALUES\($userID,\'$username\'\)\; >> $USERINJ done # Compile complete injections cat $DEVICETPLHEAD > $SCRIPTNAMEDEVICE cat $DEVICEINJ >> $SCRIPTNAMEDEVICE cat $DEVICETPLFOOT >> $SCRIPTNAMEDEVICE # Compile complete injections cat $USERTPLHEAD > $SCRIPTNAMEUSER cat $USERINJ >> $SCRIPTNAMEUSER cat $USERTPLFOOT >> $SCRIPTNAMEUSER # Injecting into tables cat $SCRIPTNAMEDEVICE | mysql -uXXXXXXX -pXXXXXXX cat $SCRIPTNAMEUSER | mysql -uXXXXXXX –pXXXXXXX
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; USE openfire; DROP TABLE IF EXISTS `phoneUser`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE phoneUser ( userID bigint not null, username varchar(255) not null unique, primary key (userID) ); SET character_set_client = @saved_cs_client; LOCK TABLES `phoneUser` WRITE; /*!40000 ALTER TABLE `phoneUser` DISABLE KEYS */;
/*!40000 ALTER TABLE `phoneUser` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; USE openfire; DROP TABLE IF EXISTS `phoneDevice`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE `phoneDevice` ( `deviceID` bigint(20) NOT NULL, `device` varchar(255) NOT NULL, `extension` varchar(255) NOT NULL, `callerId` varchar(255) default NULL, `isPrimary` int(11) NOT NULL, `userID` bigint(20) default NULL, `serverID` bigint(20) NOT NULL, PRIMARY KEY (`deviceID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; SET character_set_client = @saved_cs_client; LOCK TABLES `phoneDevice` WRITE; /*!40000 ALTER TABLE `phoneDevice` DISABLE KEYS */;
/*!40000 ALTER TABLE `phoneDevice` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
#!/bin/bash WORKDIR=/opt/openfire/bin/phone-mappings SCRIPTNAME=phone-mappings-script.sh SCRIPT=$WORKDIR/$SCRIPTNAME SERVER=jbrgseveren01.steepler.local #asterisk USER@HOST:/PathToFile ASTERISK=root@10.10.8.98 #asterisk /PathToFile RPATH=/etc/asterisk/scripts counter=0 counter2=0 #clearing script file cat /dev/null > $SCRIPT #perform MYSQL request for mappings for i in `mysql -Bse "SELECT extension,username FROM openfire.phoneDevice JOIN openfire.phoneUser ON openfire.phoneUser.UserID=openfire.phoneDevice.UserID;" -uXXXX -pXXXX`; do counter=`expr $counter + 1` mapper[$counter]=$i done maxcount=$counter counter=1 while [ "$counter" -lt "$maxcount" ] do # deviding array into two with extensions and jids counter2=`expr $counter2 + 1` extension[$counter2]=${mapper[$counter]} counter=`expr $counter + 1` jid[$counter2]=${mapper[$counter]} counter=`expr $counter + 1` # forming asterisk script outstringdel="asterisk -rvx \"database del AMPUSER "${extension[$counter2]}"/jid\"" outstringadd="asterisk -rvx \"database put AMPUSER "${extension[$counter2]}"/jid "${jid[$counter2]}"@"$SERVER"\"" echo $outstringdel >> $SCRIPT echo $outstringadd >> $SCRIPT done # moving scrip to asterisk host chmod 755 $SCRIPT scp $SCRIPT $ASTERISK:$RPATH # run script ssh $ASTERISK $RPATH/$SCRIPTNAME
[from-internal-noxfer-custom] ; Missed calls Jabber notification exten => h,1,Macro(XMPPSend,) exten => h,n,Macro(hangupcall) [macro-XMPPSend] ; Missed calls Jabber notification exten => s,1,GotoIf($["foo${DB(AMPUSER/${THISDIAL:4}/jid)}" = "foo"]?5:2) exten => s,n,Set(JID=${DB(AMPUSER/${THISDIAL:4}/jid)}) exten => s,n,Jabbersend(asterisk-jabber,${JID},${STRFTIME(${EPOCH},,%d/%m/%Y-%H:%M:%S)} - ${THISDIAL:4} ${CALLERID(name)}, ${CALLERID(num)}) exten => s,n,MacroExit() exten => s,n,Noop(No Jabber ID provided for target extension - ${THISDIAL:4}) exten => s,n,MacroExit()
[general] debug=no ;;Turn on debugging by default. ;autoprune=yes ;;Auto remove users from buddy list. ;autoregister=yes ;;Auto register users from buddy list. [asterisk-jabber] ;;label type=component ;;Client or Component connection serverhost=jbrgseveren01.steepler.local ;;Route to server username=asterisk ;;Username with optional roster. secret=XXXX ;;Password port=5275 ;;Port to use defaults to 5222
Source: https://habr.com/ru/post/137124/
All Articles