Asterisk - macro GotoIf or operator - syntax

Asterisk 16.13.0
Want to switch action between (primo, secondo, terzo and bo) based on the caller number.
[macro-gigi]
exten => s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,GotoIf($["${CALLERID(num)}"="207"]?primo)
exten => s,n,GotoIf($["${CALLERID(num)}"="205"|"206"]?secondo:terzo)
exten => s,n(bo),NoOp(caller not managed: ${CALLERID(num)} - ${EXTEN} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit
exten => s,n(primo),NoOp(primo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit
exten => s,n(secondo),NoOp(secondo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit
exten => s,n(terzo),NoOp(terzo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,GotoIf($["${CALLERID(num)}"="203"|"204"]?:bo)
exten => s,n,NoOp(terzo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit
If the caller is 207 it run primo and this is fine.
If the caller is 203 or 204 it run secondo and this is wrong.
If the caller is 206 or 205 it run secondo and this is fine.
If the caller is someone else it run secondo and this is wrong.
I don't get if it is wrong the use of OR opeator ="205"|"206" or the gotoif sequences.
-- Executing [s#macro-gigi:1] NoOp("SIP/206-00000042", "macro-gigi: 206 - SIP/206-00000042") in new stack
-- Executing [s#macro-gigi:2] GotoIf("SIP/206-00000042", "0?primo") in new stack
-- Executing [s#macro-gigi:3] GotoIf("SIP/206-00000042", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s#macro-gigi:8] NoOp("SIP/206-00000042", "secondo: 206 - SIP/206-00000042") in new stack
-- Executing [s#macro-gigi:9] MacroExit("SIP/206-00000042", "") in new stack
-- Executing [s#macro-gigi:1] NoOp("SIP/203-00000044", "macro-gigi: 203 - SIP/203-00000044") in new stack
-- Executing [s#macro-gigi:2] GotoIf("SIP/203-00000044", "0?primo") in new stack
-- Executing [s#macro-gigi:3] GotoIf("SIP/203-00000044", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s#macro-gigi:8] NoOp("SIP/203-00000044", "secondo: 203 - SIP/203-00000044") in new stack
-- Executing [s#macro-gigi:9] MacroExit("SIP/203-00000044", "") in new stack
-- Executing [s#macro-gigi:1] NoOp("SIP/204-00000045", "macro-gigi: 204 - SIP/204-00000045") in new stack
-- Executing [s#macro-gigi:2] GotoIf("SIP/204-00000045", "0?primo") in new stack
-- Executing [s#macro-gigi:3] GotoIf("SIP/204-00000045", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s#macro-gigi:8] NoOp("SIP/204-00000045", "secondo: 204 - SIP/204-00000045") in new stack
-- Executing [s#macro-gigi:9] MacroExit("SIP/204-00000045", "") in new stack
-- Executing [s#macro-gigi:1] NoOp("SIP/205-00000043", "macro-gigi: 205 - SIP/205-00000043") in new stack
-- Executing [s#macro-gigi:2] GotoIf("SIP/205-00000043", "0?primo") in new stack
-- Executing [s#macro-gigi:3] GotoIf("SIP/205-00000043", "1?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s#macro-gigi:8] NoOp("SIP/205-00000043", "secondo: 205 - SIP/205-00000043") in new stack
-- Executing [s#macro-gigi:9] MacroExit("SIP/205-00000043", "") in new stack
-- Executing [s#macro-gigi:1] NoOp("PJSIP/102-00000050", "macro-gigi: 102 - PJSIP/102-00000050") in new stack
-- Executing [s#macro-gigi:2] GotoIf("PJSIP/102-00000050", "0?primo") in new stack
-- Executing [s#macro-gigi:3] GotoIf("PJSIP/102-00000050", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s#macro-gigi:8] NoOp("PJSIP/102-00000050", "secondo: 102 - PJSIP/102-00000050") in new stack
-- Executing [s#macro-gigi:9] MacroExit("PJSIP/102-00000050", "") in new stack
EDIT:
With this change it works everything but it isn't DRY:
exten => s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,GotoIf($["${CALLERID(num)}"="205"]?secondo)
exten => s,n,GotoIf($["${CALLERID(num)}"="206"]?secondo)
exten => s,n,GotoIf($["${CALLERID(num)}"="207"]?primo)
exten => s,n,GotoIf($["${CALLERID(num)}"="203"]?terzo)
exten => s,n,GotoIf($["${CALLERID(num)}"="204"]]?terzo:bo)

205|206 result will be 1
exten => s,n,GotoIf($[ $[ "${CALLERID(num)}"="205"] | $["${CALLERID(num)}"="206"] ]?secondo)
https://www.voip-info.org/asterisk-expressions/
But that is NOT asterisk-way. Asterisk way is like this:
exten => s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CHANNEL})
exten => s/_20[56],n,Goto(secondo);actually really asterisk way is do what needed on this patern
exten => s/207,1,NoOp(primo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
same => n,Nopo(other dialplan for 207)
same => n,MacroExit
exten => s/_20[34],1,Goto(terzo)
exten => s/_2XX,1,Goto(bo);other
https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching
If you need macro-like behavior, use gosub/return. Macro is depricated.

Related

wkhtmltopdf, 0.12.6, Warning: Blocked access to file

When upgrade wkhtmltopdf to 0.12.6, it came to such messages and the image did not show in the target pdf:
Warning: Blocked access to file /path/to/bpa_product_layering.png
BTW, the same source html file works well with 0.12.5
This is caused by the change of default behavior in version 0.12.6 of wkhtmltopdf. wkhtmltopdf disables local file access by default now. It could be solved by adding the command line parameter
--enable-local-file-access
or the combination
--disable-local-file-access --allow <path>
For those that are using laravel-snappy, add the 'enable-local-file-access' option in the config\snappy.php:
'pdf' => [
'enabled' => true,
'binary' => env('WKHTML_PDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
'timeout' => false,
'options' => [
'enable-local-file-access' => true,
'orientation' => 'landscape',
'encoding' => 'UTF-8'
],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => env('WKHTML_IMG_BINARY', '/usr/local/bin/wkhtmltoimage'),
'timeout' => false,
'options' => [
'enable-local-file-access' => true,
'orientation' => 'landscape',
'encoding' => 'UTF-8'
],
'env' => [],
],
wkhtmltopdf disables local file access by default in the 0.12.6 version
Just bumping this thread with a correction in case you're still getting the same error in spite of using:
--enable-local-file-access
For some reason, this cmd line argument does not work when being specified after input/output files, you have to write this argument right after wkhtmltopdf.exe.
So
wkhtmltopdf.exe --enable-local-file-access input.html output.pdf
instead of other variants.
in my case, I put "enable-local-file-access": "", in options, it worked.
In Windows with Python, I came across a similar error as well when running code:
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries)
Error:
Warning: Blocked access to file C:/XXXXXX/background.A.jpg
Error: Failed to load about:blank, with network status code 301 and
http status code 0 - Protocol "about" is unknown
What I did to resolve this:
Add variable options
kitoptions = {
"enable-local-file-access": None
}
Add options to call
FROM
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries)
TO
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries, options=kitoptions)
Full Source:
import imgkit
#library path to kit
path_wkthmltopdf = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'
wkhtmltoimage_binaries = imgkit.config(wkhtmltoimage=path_wkthmltopdf)
#OPTIONS
kitoptions = {
"enable-local-file-access": None
}
html_file_directory = r'C:\XXXX\template'
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries, options=kitoptions)
if result:
print("successful")
else:
print("failed")
For the C API, contrary to what the documentation says, it's not load.blockLocalFileAccess but loadPage.blockLocalFileAccess that you must set to "false":
wkhtmltoimage_set_global_setting(settings, "loadPage.blockLocalFileAccess", "false");
Hopefully, the documentation will be updated soon; see issue #4763.
I confirm that the problem comes from the wkhtmltopdf version. For those on Symfony (3.4), just add an option in config.yml:
knp_snappy:
pdf:
options:
enable-local-file-access: true
I know am a bit late in party but just wanted to write clear example with c# here so one can understand clearly.
ProcessStartInfo proc = new ProcessStartInfo();
proc = new ProcessStartInfo();
proc.RedirectStandardError = true;
proc.UseShellExecute = false;
proc.WorkingDirectory = #"" + Config.WkhtmltopdfPath;
proc.FileName = #"" + Config.WkhtmltopdfPath + #"\wkhtmltopdf.exe";
proc.Arguments = #" --enable-local-file-access -T 0 -B 0 --page-width 210mm --page-height 450mm " + fileName + ".html " + fileName + ".pdf";
Process inkscape = Process.Start(proc);

Oracle Datapump: Invalid operation at line 6224

I've a Oracle dump file that I'm trying to import to AWS RDS Oracle 12.1.0.2.v17
database.
The dump file looks like this:
$ strings EXPDP.dmp | head -n 6
_|lM
"PACOPROD"."SYS_EXPORT_SCHEMA_01"
IBMPC/WIN_NT64-9.1.0
unicode
AL32UTF8
12.01.00.00.00
The commands I'm running is:
DECLARE
hdnl NUMBER;
BEGIN
hdnl := DBMS_DATAPUMP.OPEN( operation => 'IMPORT', job_mode => 'SCHEMA', job_name=>null, version=>'COMPATIBLE');
DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => 'EXPDP.dmp', directory => 'DATA_PUMP_DIR', filetype => dbms_datapump.ku$_file_type_dump_file);
DBMS_DATAPUMP.METADATA_FILTER(hdnl,'SCHEMA_EXPR','IN (''PACOPROD'')');
DBMS_DATAPUMP.START_JOB(hdnl);
END;
/
The response is:
Error report -
ORA-39002: invalid operation
ORA-06512: at "SYS.DBMS_DATAPUMP", line 6224
ORA-06512: at line 7
The closes similar issue I've found is this, even though it's not exactly the same error message and in my case both source and target db is running 12.1.
I think the issue is one of the following:
A) The DMP file is corrupt.
B) I'm doing something wrong.
I've no clue how to get further though. Where shall I dig or what should I try to go forward?
Try to add a log file to the operation. It some times contain more information:
DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => 'EXPDP.log', directory => 'DATA_PUMP_DIR', filetype => dbms_datapump.KU$_FILE_TYPE_LOG_FILE);

FTP a file from a Server's Subfolder using PL/SQL

I'm trying to get a file from a Windows Server to our Oracle Application Server directory named EXT_TAB_DATA.
I have followed the sample of a similar SO post (PL/SQL FTP API binary vs ascii mode), using Tim Hall's FTP Package.
Code Block
set serveroutput on
DECLARE
l_conn UTL_TCP.connection;
BEGIN
L_CONN := FTP.login (p_host => 'sample.corp.server' -- this is a sample, not the real IP address
p_user => 'corporate/user1', -- this is a sample, not the real User
p_port => '21',
p_pass => 'pwd');
ftp.binary(p_conn => l_conn);
ftp.get (p_conn => l_conn,
p_from_file => '101_Test.csv',
p_to_dir => 'EXT_TAB_DATA',
p_to_file => '101_Test_Trans.csv');
ftp.logout(l_conn);
END;
/
However, the file i'm trying to transfer is located in a subfolder named "Payroll_Folder" in "sample.corp.server.
Seems FTP.login only checks the main directory of the host, and not inside subfolders.
How can I get the the file '101_Test.csv' from the Server/Directory "sample.corp.server/Payroll_Folder"?
Change
p_from_file => '101_Test.csv'
to
p_from_file => 'Payroll_Folder/101_Test.csv'

Sagepay Simulator Vendor Error

I'm trying to perform transaction using Sagepay Server API. I've properly setup by simulator vendor account and also added the IP address. Still im getting the following error
Sage Pay returned an MALFORMED status. The POST was Malformed because "Simulator cannot find your vendor name. Ensure you have have supplied a Vendor field with your Vendor name assigned to it."
Here is my POST request data
[VPSProtocol] => 2.23
[TxType] => PAYMENT
[Currency] => GBP
[Vendor] => curiouslabx
[NotificationUrl] => http://localhost:8080/numberplate/sagepay_notification
[Description] => Purchase of number plate AU59STG
[AllowGiftAid] => 0
[ApplyAVSCV2] => 0
[Apply3DSecure] => 0
[Profile] => NORMAL
[AccountType] => E
[Amount] => 700.00
[success_url] => http://localhost:8080/numberplate/payment/payment_status/success/
[failure_url] => http://localhost:8080/numberplate/payment/payment_status/failure/
[BillingFirstnames] => test
[BillingSurname] => test
[BillingAddress1] => test
[BillingAddress2] => test
[BillingCity] => testtest
[BillingPostCode] => test
[BillingCountry] => test
[BillingState] => test
[BillingPhone] => test
[DeliveryFirstnames] => test
[DeliverySurname] => test
[DeliveryAddress1] => test
[DeliveryAddress2] => test
[DeliveryCity] => testtest
[DeliveryPostCode] => test
[DeliveryCountry] => test
[DeliveryState] => test
[DeliveryPhone] => test
[VendorTxCode] => 14-04-30-20-10-53-572086512
I'm using sagepay server library for codeigniter https://github.com/ollierattue/codeigniter-sagepay-server/
If you are using the Simulator, things are in a bad way anyway. It does not support protocol 3.00 - your will need to integrate at this level, or your integration will cease to function on 31/7/15

meaning of failure_reset_period option in win32-service gem for Ruby

Creating new service with win32-service, what's the meaning of the failure_reset_period ?
I'll appreciate some words on other options too (failure_reboot_message, failure_command, failure_actions, failure_delay) and examples.
Thank you in advance.
an example of use:
Service.new(
:service_name => SERVICE_NAME,
:display_name => SERVICE_DISPLAYNAME,
:start_type => Service::AUTO_START,
:error_control => Service::ERROR_NORMAL,
:service_type => Service::WIN32_OWN_PROCESS,
:description => 'This service does blah blah..',
:binary_path_name => path,
:failure_reset_period => 86400, # period (in seconds) with no failures after which the failure count should be reset to 0
:failure_actions => [ Service::ACTION_RESTART ], # action to take
:failure_delay => 60000 # delay before action in milliseconds
)
failure_reset_period resets to 0 the failure count on the service after specified time, what is useful since you can configure different actions for the first, second and other failures of the service.
meaning of those options is described here, for failure_reset_period:
the number of days that must pass before the service fail count is
reset
What if I need to set second and third failure options having different failure_delay?

Resources