TIPS How to use tonezone in dialplan

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,198
Reaction score
5,218
Sorry. I misread your earlier posts. You're actually running fwconsole reload as root which explains how things were being altered. Carry on.
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
Looks like you should go back to your known good backup Image
..and I am back.

Still trying to follow your suggestion with crontab, it seems the only way to benefit from privilege escalation.

I must be out of luck, because now I can't even add the command
Code:
/etc/asterisk/indications.conf IN_CLOSE_WRITE /bin/cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk
into crontab :(

$ crontab -e
crontab: installing new crontab
"/tmp/crontab.B1wE60":1: bad minute

I tried everything after googling the issue. I will continue another time.:hang:
 

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,633
Reaction score
841
crontab is really not the way to go , try ( as suggested I thought)

cat /var/lib/asterisk/scripts/indications.conf
cat /etc/asterisk/indications.conf
echo "/etc/asterisk/indications.conf IN_CLOSE_WRITE /usr/bin/cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk" >> /etc/incron.d/local #never do that more than once, EVER!!
# here is where the damage was done previously
fwconsole reload
# BUT !!!
cat /etc/asterisk/indications.conf
# lets be REALLY mean:-
rm -f /etc/asterisk/indications.conf # that should screw us, right? BUT OH !!!
diff /etc/asterisk/indications.conf /var/lib/asterisk/scripts/indications.conf
cat /etc/asterisk/indications.conf

p.s.

You have in your monika "RPI/BBB/RentPBX/DigitalOcean/OVH/VULTR", please don't tell us you were doing all this with you RPI hat (sic) on ;-) "
 
Last edited:

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
@dicko You made my day, thank you. It's a year since I started this thread.
:cheers2:

For readers on Centos, the command is:
Code:
echo "/etc/asterisk/indications.conf IN_CLOSE_WRITE /bin/cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk" >> /etc/incron.d/local

p.s. Changed my signature. Tinkering along whenever Ward comes with something.
The various RPI generations are out of order or serving video streams.
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
I guess its working a little different than I thought (on Centos?):
the incron.d job stops working.

With removing /etc/incron.d/local and reinstalling, I get this:

root@vultr:~ $ echo "/etc/asterisk/indications.conf IN_CLOSE_WRITE /bin/cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk">> /etc/incron.d/local

root@vultr:~ $ diff /etc/asterisk/indications.conf /var/lib/asterisk/scripts/indications.conf
8a9,10
> #include indications_custom.conf
>

root@vultr:~ $ rm -f /etc/asterisk/indications.conf # that should screw us, right? BUT OH !!!

root@vultr:~ $ diff /etc/asterisk/indications.conf /var/lib/asterisk/scripts/indications.conf

root@vultr:~ $ rm -f /etc/asterisk/indications.conf # that should screw us, right? BUT OH !!!

root@vultr:~ $ diff /etc/asterisk/indications.conf /var/lib/asterisk/scripts/indications.conf
diff: /etc/asterisk/indications.conf: No such file or directory

Log /var/log/cron
Mar 29 13:13:01 vultr /usr/bin/crontab[5328]: (asterisk) LIST (asterisk)
Mar 29 13:13:35 vultr incrond[2127]: system table local created, loading
Mar 29 13:14:01 vultr crond[2012]: (asterisk) RELOAD (/var/spool/cron/asterisk)

Mar 29 13:14:01 vultr CROND[5390]: (asterisk) CMD ([ -x /var/lib/asterisk/bin/schedtc.php ] && /var/lib/asterisk/bin/schedtc.php)
Mar 29 13:14:01 vultr CROND[5391]: (asterisk) CMD ([ -x /var/www/html/admin/modules/dashboard/scheduler.php ] && /var/www/html/admin/modules/dashboard/scheduler.php > /dev/null 2>&1)
Mar 29 13:14:01 vultr /usr/bin/crontab[5401]: (asterisk) LIST (asterisk)
Mar 29 13:14:01 vultr /usr/bin/crontab[5403]: (asterisk) LIST (asterisk)
Mar 29 13:14:01 vultr /usr/bin/crontab[5404]: (asterisk) REPLACE (asterisk)
Mar 29 13:14:01 vultr /usr/bin/crontab[5406]: (asterisk) LIST (asterisk)
Mar 29 13:14:01 vultr /usr/bin/crontab[5408]: (asterisk) LIST (asterisk)
Mar 29 13:14:01 vultr /usr/bin/crontab[5409]: (asterisk) REPLACE (asterisk)
Mar 29 13:14:01 vultr /usr/bin/crontab[5411]: (asterisk) LIST (asterisk)
Mar 29 13:14:34 vultr incrond[2127]: (system::local) CMD (/bin/cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5545]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5547]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5549]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5551]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5553]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5555]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5557]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5559]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5561]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5563]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5564]: (root) REPLACE (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5566]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5568]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5569]: (root) REPLACE (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5571]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5573]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5575]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5577]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5579]: (root) LIST (root)
Mar 29 13:14:55 vultr /usr/bin/crontab[5581]: (root) LIST (asterisk)
Mar 29 13:14:55 vultr /usr/bin/crontab[5583]: (root) LIST (asterisk)
Mar 29 13:15:01 vultr crond[2012]: (asterisk) RELOAD (/var/spool/cron/asterisk)
Mar 29 13:15:01 vultr CROND[5612]: (asterisk) CMD ([ -x /var/www/html/admin/modules/dashboard/scheduler.php ] && /var/www/html/admin/modules/dashboard/scheduler.php > /dev/null 2>&1)
Mar 29 13:15:01 vultr CROND[5613]: (asterisk) CMD (/usr/sbin/fwconsole userman --syncall -q)
Mar 29 13:15:01 vultr CROND[5614]: (asterisk) CMD ([ -x /var/lib/asterisk/bin/schedtc.php ] && /var/lib/asterisk/bin/schedtc.php)
Mar 29 13:15:01 vultr /usr/bin/crontab[5627]: (asterisk) LIST (asterisk)
Mar 29 13:15:01 vultr /usr/bin/crontab[5629]: (asterisk) LIST (asterisk)
Mar 29 13:15:01 vultr /usr/bin/crontab[5630]: (asterisk) REPLACE (asterisk)
Mar 29 13:15:01 vultr /usr/bin/crontab[5632]: (asterisk) LIST (asterisk)
Mar 29 13:15:01 vultr /usr/bin/crontab[5634]: (asterisk) LIST (asterisk)
Mar 29 13:15:01 vultr /usr/bin/crontab[5635]: (asterisk) REPLACE (asterisk)
Mar 29 13:15:01 vultr /usr/bin/crontab[5637]: (asterisk) LIST (asterisk)
 
Last edited:

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,633
Reaction score
841
Don't know what to say, my test machine

Linux freepbx.sangoma.local 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


A rethink

cat /etc/incron.d/bullshit
/etc/asterisk/indications.conf IN_CLOSE_WRITE /var/lib/asterisk/scripts/recoverindications.sh


cat /var/lib/asterisk/scripts/recoverindications.sh
#/bin/sh
sleep 10;
# for Netherlands
if [[ ! $(rasterisk -x 'indication show'|grep -o ^nl) ]];then /usr/bin/cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk;rasterisk -x 'core reload';fi

Double rethinking, maybe that belongs in plain old crontab

it puts the a into synchroncity
 
Last edited:

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,633
Reaction score
841
Final answer,

If there is no indications for Afrikanns (South Africa) and it is not your default language, and you want Germany and Taiwan as well as your default, then you got screwed by FreePBX , but if you have


crontab -l
* * * * * if [[ ! $(/usr/sbin/rasterisk -x 'indication show'|grep -o ^za) ]];then /usr/bin/cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk;/usr/sbin/rasterisk -x 'core reload';fi

it will only be for an average of 30 seconds after a fwconsole r
 
Last edited:

jerrm

Guru
Joined
Sep 23, 2015
Messages
838
Reaction score
405
I never could avoid race conditions with incron when altering the watched file. If anyone knows the correct recipe let me know. Also incron parsing seemed VERY picky about formatting for the command portion.

For an incron solution, simplify the incron command parsing by using a script as @dicko suggested above. The script can also log what's actually happening. I was going to offer up:

/etc/incron.d/local:
Code:
/etc/asterisk/indications.conf IN_CLOSE_WRITE /var/lib/asterisk/scripts/watch-indications.sh


/var/lib/asterisk/scripts/watch-indications.sh:
Code:
#!/bin/sh

#set these to appropriate paths for your system
alias diff=/usr/bin/diff
alias cp=/bin/cp
alias logger=/bin/logger

(
  diff -sq /var/lib/asterisk/scripts/indications.conf /etc/asterisk/indications.conf || {
    echo replacing target with backup
    cp /var/lib/asterisk/scripts/indications.conf /etc/asterisk
  }
) 2>&1 | logger -t watch-indications

make sure to chmod +x /var/lib/asterisk/scripts/watch-indications.sh
 

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,633
Reaction score
841
Good post @jerrm

Basically the trouble is that if you watch

/etc/asterisk/indications.conf

and then operate on that change, which itself changes the watched file, then iincron will of course call itself again, my grep -o watches for an unacceptable state and corrects it , which often works, but I found "not always" you might end up with many concurrent scripts running, cron although with a minimum granularity of 1 minute is my compromise, let fwconsole do it's stuff, decide that is not what you want , correct the situation, doing this every minute rather than creating a race is my suggested solution.

It should be noted that both cron and incron run scripts in /bin/sh so that is why full paths to binaries are less problematic
 
Last edited:

jerrm

Guru
Joined
Sep 23, 2015
Messages
838
Reaction score
405
@dicko:

The diff should prevent the race, but I like the cron solution too. One less process running on the system.

Either way, I hope the indications.conf is properly commented so the next guy who comes along (or the same guy 3 years from now) can figure out why the hell the file can't be changed.
 

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,633
Reaction score
841
I also tried the diff approach, that was also a ball of twine, I believe that the FreePBX and the custom incrons were the cause of race conditions , sometimes there where hundreds of processes running, I tried to sleep both before and after the cp but not so much I took the line of least resistance for now. Not that I even need it but it SHOULD be fixed by FreePBX IMHO, that's one for the OP though.

Regards
 

jerrm

Guru
Joined
Sep 23, 2015
Messages
838
Reaction score
405
Curious.. I do have something similar in place for another non-FreePBX problem without issue. My testing seemed good for a half dozen passes or so, but it doesn't really surprise me. INotify/incron functionality is one area where the Windows equivalents seem less glitchy, which is a rarity.
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
@dicko @jerrm thanks a lot for your contributions and amazing solutions.
I do not fully follow what you wrote in post #29-33, but if I understand correctly, you both indicated a proper working solution that avoids a loop/race condition.

I do have quite some questions to test my understanding (and due to a lack of knowledge):

1. @dicko #27: cron(tab) method
a. if /etc/asterisk/indications.conf does not contain tonecodes for za, then the script will copy /var/lib/asterisk/scripts/indications.conf, right?
b. /var/lib/asterisk/scripts/indications.conf should always have za tonezone, right?
c. The script assumes your default tonezone (in the FreePBX UI) is not za (South Africa), right?
d. This does not work for Germany as your default tonezone in /var/lib/asterisk/scripts/indications.conf, why?
e. This does not work for Taiwan as your default tonezone in /var/lib/asterisk/scripts/indications.conf, why?
f. The last action of the script is: rasterisk -x 'core reload', why? Would fwconsole restart (not fwconsole reload which alters indications.conf again) be an option?

2. @jerrm #28 incron method
a. Other scripts on my Centos use #!/bin/bash instead of #!/bin/sh and the script works with bash. Any reason you used sh?
b. Does your script run twice after every reload?
1st time: After a reload, when FreePBX copies the default system file to /etc/asterisk/indications.conf;
2nd time: After the script runs and copies /var/lib/asterisk/scripts/indications.conf to /etc/asterisk/indications.conf;​
c. I found a log in /var/log/messages. Very nice! Curious if there are more logs (Centos)?
Apr 1 16:34:43 vultr watch-indications: Files /var/lib/asterisk/scripts/indications.conf and /etc/asterisk/indications.conf differ
Apr 1 16:34:43 vultr watch-indications: replacing target with backup
Apr 1 16:34:43 vultr watch-indications: Files /var/lib/asterisk/scripts/indications.conf and /etc/asterisk/indications.conf are identical
Apr 1 16:35:06 vultr watch-indications: Files /var/lib/asterisk/scripts/indications.conf and /etc/asterisk/indications.conf differ
Apr 1 16:35:06 vultr watch-indications: replacing target with backup
Apr 1 16:35:06 vultr watch-indications: Files /var/lib/asterisk/scripts/indications.conf and /etc/asterisk/indications.conf are identical

3. As you indicated, this really should be fixed by FreePBX.
a. Do you agree with me that a simple fix would be to suggest to
#include indications_custom.conf to /etc/asterisk/indications.conf by default?
b. I am happy to follow-up with FreePBX people. Can you indicate where I can do this?
 

jerrm

Guru
Joined
Sep 23, 2015
Messages
838
Reaction score
405
2. @jerrm #28 incron method
a. Other scripts on my Centos use #!/bin/bash instead of #!/bin/sh and the script works with bash. Any reason you used sh?
b. Does your script run twice after every reload?
1st time: After a reload, when FreePBX copies the default system file to /etc/asterisk/indications.conf;
2nd time: After the script runs and copies /var/lib/asterisk/scripts/indications.conf to /etc/asterisk/indications.conf;​
c. I found a log in /var/log/messages. Very nice! Curious if there are more logs (Centos)?
a: No reason that matters. Bash is not always present on some systems I use. Use whatever shell/language you want.
b: Correct. Incron should trigger once after fwconsole is done, and again after the script itself copies the backup file over. The log reads as expected. The diff approach should avoid a race condition as the file will not be opened for write a second time after the copy, but note @dicko says he still had race conditions using a similar approach.
c: messages is the only place this would log on centos.

3. As you indicated, this really should be fixed by FreePBX.
a. Do you agree with me that a simple fix would be to suggest to
#include indications_custom.conf to /etc/asterisk/indications.conf by default?
b. I am happy to follow-up with FreePBX people. Can you indicate where I can do this?
a: Yes, adding a _custom include seems appropriate. Have to wonder if they had a reason not to already have one.
b: Officially report the issue at: https://wiki.freepbx.org/display/FOP/Bug+Reporting. Also worth opening a thread in the forums at https://community.freepbx.org/. If a few "me too" responses pop up it might help move things along.
 
Last edited:

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,633
Reaction score
841
@dicko @jerrm thanks a lot for your contributions and amazing solutions.
I do not fully follow what you wrote in post #29-33, but if I understand correctly, you both indicated a proper working solution that avoids a loop/race condition.

I do have quite some questions to test my understanding (and due to a lack of knowledge):

1. @dicko #27: cron(tab) method
a. if /etc/asterisk/indications.conf does not contain tonecodes for za, then the script will copy /var/lib/asterisk/scripts/indications.conf, right?
b. /var/lib/asterisk/scripts/indications.conf should always have za tonezone, right?
c. The script assumes your default tonezone (in the FreePBX UI) is not za (South Africa), right?
d. This does not work for Germany as your default tonezone in /var/lib/asterisk/scripts/indications.conf, why?
e. This does not work for Taiwan as your default tonezone in /var/lib/asterisk/scripts/indications.conf, why?
f. The last action of the script is: rasterisk -x 'core reload', why? Would fwconsole restart (not fwconsole reload which alters indications.conf again) be an option?u


Not quite, /var/lib/asterisk/scripts/indications.conf will have anything you put into it, my proposed method was to copy the one from the source code, i.e it would produce

/usr/sbin/rasterisk -x 'indication show'
Country Description
===========================
be Belgium
de Germany
pt Portugal
za South Africa
th Thailand
cz Czech Republic
dk Denmark
it Italy
at Austria
us United States / North America
au Australia
lt Lithuania
br Brazil
jp Japan
us-old United States Circa 1950/ North America
gr Greece
no Norway
pl Poland
nl Netherlands
ph Philippines
sg Singapore
se Sweden
ee Estonia
hu Hungary
ve Venezuela / South America
mx Mexico
ru Russian Federation / ex Soviet Union
my Malaysia
nz New Zealand
uk United Kingdom
tw Taiwan
cn China
fi Finland
cl Chile
il Israel
in India
ch Switzerland
fr France
es Spain
bg Bulgaria


Under these circumstances then ^de and ^tw WOULD show true. the Only reason ^za would be there and ^de not would be if FreePBX had mangled the file and your default language was za, I chose za as a 'least likely' case but in retrospect ( and thats appropriate :) ) ^us-old is probably a better choice unless your grandad is still deploying sip stacks on Westinghouse 500 sets with Asterisk
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
This was fixed and published in module: core 14.0.18.4
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
I just installed pbxinaflash LEAN on CentOS 6 and was hoping I could now use the new tonezone solution.

Unfortunately, one year later and we are not in core 14 yet.

I tried the instructions provided by Andrew Nagy here, but it looks like pbxinaflash does not allow me to get the edge core v14.0.18.4

Anyone knows if there is a way to get it or just get the fix?
 

Members online

Forum statistics

Threads
25,803
Messages
167,722
Members
19,232
Latest member
voiplads
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top