Asterisk AST_SORCERY function

 AST_SORCERY gets a field from a sorcery object. Sorcery is always created for PJSIP aors, endpoints and identifies in asterisk. It allows you to access information from dialplan in runtime.

Syntax:

AST_SORCERY(module_name,object_type,object_id,field_name[,retrieval_method[,retrieval_details]])

PJSIP config example:

[mytrunk]
type=aor
contact=sip:sip.example.com:5060

[mytrunk]
type=endpoint
context=from-external
disallow=all
allow=ulaw,alaw,g722
outbound_auth=mytrunk
aors=mytrunk

[mytrunk]
type=identify
endpoint=mytrunk
match=sip.example.com


Usage example:

> dialplan eval function AST_SORCERY(res_pjsip,identify,mytrunk,match)

Return Value: Success (0)

Result: sip.example.com

> dialplan eval function AST_SORCERY(res_pjsip,endpoint,mytrunk,allow)

Return Value: Success (0)

Result: (ulaw|alaw|g722)


Enjoy!

OpenWRT/LEDE Project and Cisco VPN client in 4 easy steps

1. Install OpenWRT/LEDE project on your router and add vpnc, vpnc-scripts and luci-proto-vpnc using System | Software menu item




In my particular case I have setup router using WAN port attached to the modem and the client devices on LAN ports!

2. Add new interface myVPN using Network | Interfaces and change protocol to VPNC. Now you can setup VPN Server IP address, user name and password, group name and password. Important! In my case output interface is wan, because WAN port connected to outgoing modem!



and add myVPN interface to the lan firewall section of interface settings!



3. Switch now to the Network | Firewall and navigate to Custom Rules
You have to add forwarding rules for new myVPN interface



iptables -A forwarding_rule -o vpn-myVPN -j ACCEPT
iptables -A forwarding_rule -i vpn-myVPN -j ACCEPT
iptables -t nat -A postrouting_rule -o vpn-myVPN -j MASQUERADE

4. Add static routing to the subnetworks behind VPN connection as last step under Network | Static routes



Enjoy!

HOWTO: measure bandwith on AsteriskNOW (SHMZ, CentOS, Fedora)

iptraf allows to measure the throughput on network interface and watch individual connections.You can install iptraf with following command

# yum -y install iptraf

after start it displays as summary traffic as also detailed information about connections for NIC.

# iptraf



Other blogs recommend to install nload or iftop utilities, sadly both are not available in repository and you have to build from sources.

Enjoy!

Asterisk: HOWTO forward DNIS to remote party

Dialed Number Identification Service (DNIS) is a service that lets determine which telephone number was dialed by a customer.

Usually dialed number is known for subscriber, because each DID corresponds unique extension.
It is not a case for transfered calls, because information about DID will be lost. To inform far side about original dialed number the SIP protocol provides the Diversion header.
To set the Diversion field you have to set rdnis variable in dialplan. E.g.


;catch all extension
exten=>_.,n,Set(CALLERID(rdnis)=${EXTEN})

;in the macro
exten=>s,n,Set(CALLERID(rdnis)=${MACRO_EXTEN})

; or hardcoded
exten=>_.,n,Set(CALLERID(rdnis)=123456789)

Enjoy!

Book "LINQ in Action" by Fabrice Marguerie

LINQ, Language INtegrated Query, is a new extension to the Visual Basic and C# programming languages designed to simplify data queries and database interaction. It addreses O/R mapping issues by making query operations like SQL statements part of the programming language. It also offers built-in support for querying in-memory collections like arrays or lists, XML, DataSets, and relational databases. LINQ in Action is a fast-paced, comprehensive tutorial for professional developers. This book explores what can be done with LINQ, shows how it works in an application, and addresses the emerging best practices. It presents the general purpose query facilities offered by LINQ in the upcoming C# 3.0 and VB.NET 9.0 languages. A running example introduces basic LINQ concepts. You'll then learn to query unstructured data using LINQ to XML and relational data with LINQ to SQL. Finally, you'll see how to extend LINQ for custom applications. LINQ in Action will guide you along as you explore this new world of lambda expressions, query operators, and expression trees. As well, you'll explore the new features of C# 3.0, VB.NET 9.0. The book is very practical, anchoring each new idea with running code. Whether you want to use LINQ to query objects, XML documents, or relational databases, you will find all the information you need to get started But LINQ in Action does not stop at the basic code. This book also shows you how LINQ can be used for advanced processing of data, including coverage of LINQ's extensibility, which allows querying more data sources than those supported by default. All code samples are built on a concrete business case. The running example, LinqBooks, is a personal book cataloging system that shows you how to create LINQ applications with Visual Studio 2008 and above.

SoftwareDistribution folder is huge on small drive

Windows cleans SoftwareDistribution directory automatically after updates are installed.
The directory was 1GB big after updates on 20GB partition and the reason was \softwaredistribution\datastore\datastore.edb file.
Forums says just delete the whole folder. Don't do it!
datastore.edb is Extensible Storage Engine (ESE) database and you can shrink it.
Launch cmd.exe as as administrator and execute

net stop wuauserv
esentutl /d %windir%\softwaredistribution\datastore\datastore.edb
net start wuauserv

After defragmentation the file was reduced upto 10MB. Wow! I got free space on the disk.
Enjoy!

Certificate Credentials - Generate Proxy Class

Below you will find my workaround for proxy class generation if remote web service is old-fashioned and protected with certificate credentials.
Often is enough svcutil.exe to generate proxy class. But not in my case because web service was ancient and does not provide MEX, WS or netTcp binding. Please advise whether is possible to use svcutil for archaic service like https://remote.com/service?wsdl
Another way to create proxy class is wsdl.exe utility, but wsdl.exe does not support certificates at all.

Solution: I have installed locally http NGINX revers proxy with following config

    server {
        listen       8080;
        server_name  localhost;

        location / {
     #repace urls in response     
     sub_filter 'https://remote.com:8080/' 'http://$host:8080/';
     sub_filter_types *; # enable all type
     sub_filter_once off;
            proxy_pass https://remote.com:8080/;
            proxy_ssl_certificate  cert.pem;
            proxy_ssl_certificate_key cert.pem;
        }
    }

to convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM file execute
openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

start Nginx and execute wsdl.exe command
wsdl.exe http://localhost:8080/service?wsdl

Enjoy!


How to REALLY destroy stored data

I have written already about SDelete and bootable DiskWipe, but what if you have to rely on the result?
In that case you have only once option - physical destruction!

First you have to disassemble your hard drive disk and extract each single platter.

As next step use blow torch (blowlamp) till surface of disk will be red, look at the photo.

After that all your data are really demolished.


CAUTION! That is truly very dangerous! Fire hazard! 

bulk convert to u-law or a-law audio format


The telephone system requires often audio prompts in u-law or a-law format.
To convert all your wav files you can execute following command in the directory with wav files,
it will convert file and save it with the same file name and new extension

# for a in *.wav; do sox "$a" -t raw -r 8000 -c 1 -e u-law ${a/.wav/.ulaw} ; done

or 

# for a in *.wav; do sox "$a" -t raw -r 8000 -c 1 -e a-law ${a/.wav/.alaw} ; done

Enjoy!

Connecting to Ubuntu using UltraVNC


first enable Desktop Sharing on Ubuntu 16.04 host

and protect it with password.


Ubuntu is running Vino VNC Server and UltraVNC does not support Vino encryption. You have to execute without restart and sudo(!) the followinf command

$ gsettings set org.gnome.Vino require-encryption false

Enjoy!

PS: I did not test the settings with TightVNC or RealVNC, but expecting also  to be working solution

Aspose.Cells change style of cell

It was possible in previous versions of Aspose Cells to apply changes directly to cell.
Starting from version 7.0 you have to call first GetStyle() method and then call SetStyle(s) method.

You can use simple extension method to mimic old behavior.


public static class AsposeCellsExt
    {
        public static void ChangeStyle(this Cell cell, Action<Style> applyChangesTo)
        {
            Style s = cell.GetStyle();
            applyChangesTo(s);
            cell.SetStyle(s);
        }
    }

and now to fill A1 cell with green background you can execute just single line

cells[0, 0].ChangeStyle(s => { s.ForegroundColor = GREEN; s.Pattern = Aspose.Cells.BackgroundType.Solid; });


Enjoy!

[SOLVED]: mysqldump: Got error: 1045: Access denied for user 'ODBC'@'localhost'

I would like to execute mysqldump using .mylogin.cnf file and --login-path option to make it more secure as it can be with plain text password. It appears the error
mysqldump: Got error: 1045: Access denied for user 'ODBC'@'localhost' (using password: NO) when trying connect.
It was really strange because I have never created any ODBC user.


The solution: you have to export MYSQL_TEST_LOGIN_FILE variable and point to correct CNF file, e.g.
SET MYSQL_TEST_LOGIN_FILE=C:\secret\.mylogin.cnf
 - or -
export MYSQL_TEST_LOGIN_FILE=/var/mysql/.mylogin.cnf

Don't forget to restrict access permission to the file!

Enjoy!

OTRS: add new statistics takes too long

Does it take an enternity to create new statistics in OTRS?
Check an option CustomerIDAsMultiSelect in SysConfig and set it to No,
You can't select mutiple customers anymore, try to revert the option back and edit existing report.

Enjoy!

[SOLVED] ERROR 1290 (HY000) The MySQL server is running with the --secure-file-priv


if appears the error
ERROR 1290 (HY000) The MySQL server is running with the --secure-file-priv

you have to check
1.  execute show variables and find secure_file_priv variable value (e.g. c:/uploads/)
2. use full path in SELECT .. INTO OUTFILE  or LOAD DATA statements (e.g. 'c:/uploads/some_file.cvs')
3. grant file priviledge to the user (e.g. GRANT FILE ON *.* TO 'someuser'@'localhost';)


You can always change the path in my.ini file, search for secure_file_priv 


Enjoy!

[SOLVED] crond[PID]: (root) FAILED to authorize user with PAM (Permission denied)


I have disabled root login in /etc/security/access.conf and it appears  the error message in /var/cron/log

crond[PID]: (root) FAILED to authorize user with PAM (Permission denied)

The fixed access.conf file looks like

#Allow root only from localhost and cron daemon
+ : root  : 127.0.0.1 ::1
+ : root : cron crond :0 tty1 tty2 tty3 tty4 tty5 tty6
- : root  : ALL


Enjoy!

ARDUINO: control your gate, pump just with single power button

It is often necessary to control remotely two-state devices like entrance gate, water pump, RF switch or IR switch. My idea was to keep just single on/off button and keep smallest possible leakage current.
You can see my idea on schematic below.

Windows Server - make network private

You can mark your network location on windows host as private just in three steps

1. Launch PowerShell as administrator
2. Get list of network interfaces (NICs) with command
Get-NetConnectionProfile

3. Change network category for selected network interface
Set-NetConnectionProfile -InterfaceIndex 15 -NetworkCategory Private


Enjoy!

Arduino - Easter Egg Dyeing

You know that modern eastern egg dyes requires about 5 minutes to make super bright eggs. It also takes about 5 minutes and 10 lines of code to create the countdown timer with left minute display on arduino.
The schematic diagram is more than simple. Just connect 5 or more green LEDs on ports 0-7 and one red LED on port 8.

Here is photo of my assembled board.

Is it possible to make the code shorter?!
/*
  Arduino - count down timer
*/

int MAX_LEDS = 5; // max_leds = maximun minutes
int counter = 60 * MAX_LEDS; 
bool flip_flop = LOW;

void setup() {
  
   DDRB = DDRC = DDRD = 255; // set all ports to output
   PORTD = (((unsigned int)1 << MAX_LEDS) - 1); // ON first N LEDs

   while(counter--){
    delay(1000);  // wait for a second
    flip_flop = flip_flop == LOW ? HIGH : LOW;
    digitalWrite((int)(counter/60), flip_flop); // blink current minute LED
   }

   while(true){
    delay(1000);  // wait for a second
    flip_flop = flip_flop == LOW ? HIGH : LOW;
    digitalWrite(8, flip_flop); // blink red light
   }
}

void loop() {

}

and video

Enjoy!

[SOLVED]: rhythmbox does not play mp3 file

Yes, it should play and you have already double checked  that gstreamer was installed with all possible plugins. Also was installed apt://ubuntu-restricted-extras on Ubuntu or ugly on fedora

# yum install gstreamer gstreamer-ffmpeg gstreamer-plugins-bad gstreamer-plugins-bad-free gstreamer-plugins-bad-free-extras gstreamer-plugins bad-nonfree gstreamer-plugins-base gstreamer-plugins-good gstreamer-plugins-ugly install faad2 faac libdca wget compat-libstdc++-33 compat-libstdc++-296  xine-lib-extras-freeworld
just execute following command, which helped me a lot

# cd ~/Music
# find . -exec touch '{}' \;


Enjoy with mp3 on rhythmbox!

Asterisk AST_SORCERY function

 AST_SORCERY gets a field from a sorcery object. Sorcery is always created for PJSIP aors, endpoints and identifies in asterisk. It allows y...