FreeSwitch ESL: NodeJS/JS/Freeswitch Syntax Confliction - node.js

I'm building a Twillio-like Dialer API using Modesl in Node.JS to send commands and parameters to Freeswitch Console.
Edit: I've narrowed down the issue to a syntax issue, where the javascript I'm using to input my variables are conflicting with FreeSwitchs syntax.
uuid_send_dtmf needs to have a ' in front of it, whereas uuid is a NodeJS parameter that needs to be passed after one space, as is dmtf, and the api_on_answer requires a ' for closing after my parameters are passed.
Syntax has always been my weak point, any help would be greatly appreciated.
,api_on_answer='uuid_send_dtmf ' + uuid + ' ' + dmtf +' ' }
conn.api('originate {
origination_uuid=' + uuid
+ ',origination_caller_id_number=' + cid
+ ',api_on_answer=uuid_send_dtmf ' + uuid
+ ' ' + dmtf +' }
sofia/external/' + pnumber + '#provider', function(res) {
Currently the command is giving a very vague error of little help:
2019-03-17 08:53:22.755065 [DEBUG] switch_ivr_originate.c:2204 Parsing global variables
2019-03-17 08:53:22.755065 [ERR] switch_ivr_originate.c:2209 Parse Error!
2019-03-17 08:53:22.755065 [DEBUG] switch_ivr_originate.c:3941 Originate Resulted in Error Cause: 27 [DESTINATION_OUT_OF_ORDER]
What is the correct way to do what I need?

Fixed using '\' to input ' inline.
var onanswer = '\'' + uuid + ' ' + dmtf;

try this,
conn.api(`originate {origination_uuid=${uuid},origination_caller_id_number=${cid},api_on_answer='${uuid_send_dtmf} ${uuid} ${dtmf}'}sofia/external/${pnumber}#${provider}`, function(res) {
template literals or strings, enclosed by back-ticks, this would provide you the required format, cheers :)

Related

How to use Jest useFakeTimers with RXJS?

My application is primarily using React Redux. We have a few places that use RXJS to simplify things. I just started using jest.useFakeTimers.
I realized that given code like this from(anAsyncMethod).pipe(timeout(FETCH_TOKEN_TIMEOUT)) will trigger a timeout error the second jest.runAllTimers(); fires in my afterEach.
The relevant stack is here:
stack: 'Error: \n' +
' at _super (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js:6:26)\n' +
' at new TimeoutErrorImpl (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/operators/timeout.js:21:9)\n' +
' at timeoutErrorFactory (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/operators/timeout.js:66:11)\n' +
' at AsyncAction.eval (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/operators/timeout.js:44:84)\n' +
' at AsyncAction.eval (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/util/caughtSchedule.js:7:21)\n' +
' at AsyncAction._execute (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/scheduler/AsyncAction.js:65:18)\n' +
' at AsyncAction.execute (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/scheduler/AsyncAction.js:53:26)\n' +
' at AsyncScheduler.flush (webpack-internal:///../../node_modules/rxjs/dist/esm5/internal/scheduler/AsyncScheduler.js:26:33)\n' +
' at callTimer (/Users/dstein/Repositories/uxp-plugin/node_modules/#sinonjs/fake-timers/src/fake-timers-src.js:729:24)\n' +
' at Object.next (/Users/dstein/Repositories/uxp-plugin/node_modules/#sinonjs/fake-timers/src/fake-timers-src.js:1409:17)\n' +
' at Object.runAll (/Users/dstein/Repositories/uxp-plugin/node_modules/#sinonjs/fake-timers/src/fake-timers-src.js:1468:23)\n' +
' at FakeTimers.runAllTimers (/Users/dstein/Repositories/uxp-plugin/node_modules/#jest/fake-timers/build/modernFakeTimers.js:75:19)\
Is there any way to work around this issue?
well looks like anAsyncMethod takes longer than FETCH_TOKEN_TIMEOUT therefore the error is thrown, this is expected.
when you subscribe to your observable you should check for errors:
from(anAsyncMethod).pipe(timeout(FETCH_TOKEN_TIMEOUT)).subscribe(
res => console.log('ok'),
err => console.error('timeout')
);
or you can catch the error
from(anAsyncMethod).pipe(
timeout(FETCH_TOKEN_TIMEOUT),
catchError(error => of(`Request timed out after: ${FETCH_TOKEN_TIMEOUT}`))
);

How to overcome the error of 'exception of type IndexError'?

I have to get an specific output for a specific input as shown below:
code: soMe SuPPLies liKE Ice-cREAm aRe iMPORtant oNly tO THeir cReaTORS. tO DestroY thEm iS pOInTLess.
says: destroy their ice-cream supplies
I wrote a program below:
line = input("code: ")
words = line.split()
human = words[11] + ' ' + words[8] + ' ' + words[3] + ' ' + words[1]
print('says:',human.lower())
While I am getting the desired output, the compiler is giving me an error - 'Your submission raised an exception of type IndexError. This occurred on line 3 of your submission.'
Please help me.

Want to run several db.query() method in parallel without getting any error

I am using Node JS . I am a beginner. I use OrientJS to connect orientdb from Node JS. I want to run several db.query() method in parallel. This queries are formed by reading a large text file using line-by-line module.
For example,
var queryForGeoUpdate = 'update (' +
'\nselect from (' +
"\n select expand(outE('GeoAgentSummary')) " +
'\n from Agent ' +
'\n where name = "' + name + '" and number = \'' + number + "' and type = '" + type + "'" +
"\n) where in.name = '" + Geo + "'" +
'\n) increment _' + FiscalYear + ' = ' + TMSSalesAllocatedBookingsNet + 'f, _' +
FiscalPeriodID + ' = ' + TMSSalesAllocatedBookingsNet +
'f, _' + FiscalQuarterID + ' = ' + TMSSalesAllocatedBookingsNet + 'f'
// console.log(queryForGeoUpdate)
db.query(queryForGeoUpdate) // query and db call for Country ends here
like db.query(queryForGeoUpdate) there are seven queries like db.query(queryForRegionUpdate) and so on...
if I run it asynchronously "process out of memory occurrs". If I run it synchronously it takes too much time. How can I solve it within very less time..
Any help is appreciated..
I am not familiar with the DB you are using. If you are sure the DB works "correctly" and the calls you make are correct (e.g. if there isn't a way to make you queries much smaller) you could try running with:
node --max_old_space_size="memmory in MB, try something large like 8192" app.js
It seems rather strange that a DB query would run out of memory thought... I always assumed queries are, generally speaking,a lot more CPU intensive and require relatively little memory.
For these sort of large queries you might also try spawning separate processes:
https://nodejs.org/api/child_process.html

PKCS11 Python FindObjects in available slots

I wrote a script in python that gets info from a Cryptoki library. From there I can make (only)LowLevel API calls such as:
C_getInfo
C_GetSlotList
C_SlotInfo
C_OpenSession
C_GetTokenInfo
C_Logout
C_CloseSession
C_Initialize
Here's a few examples on their implementation
a.C_Initialize()
print("C_GetInfo:", hex(a.C_GetInfo(info)))
print("Library manufacturerID:", info.GetManufacturerID())
del info
print("C_GetSlotList(NULL): " + hex(a.C_GetSlotList(0, slotList)))
print("\tAvailable Slots: " + str(len(slotList)))
for x in range(len(slotList)):
print("\tC_SlotInfo(): " + hex(a.C_GetSlotInfo(slotList[x], slotInfo)))
print("\t\tSlot N." + str(x) + ": ID=" + str(slotList[x]) + ", name='" + slotInfo.GetSlotDescription() + "'")
print("\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], CKF_SERIAL_SESSION | CKF_RW_SESSION, session)))
print("\t\tSession:" + str(session))
#print("\tMechList:" + hex(a.C_GetMechanismList(0, slotList[x])))
print("\tC_GetTokenInfo(): " + hex(a.C_GetTokenInfo(slotList[x], tokenInfo)))
print("\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID())
print("\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel())
print("\tC_Login(): " + hex(a.C_Login(session, CKU_USER, pin)))
print("\t\tSessionInfo: state=" + hex(sessionInfo.state) + ", flags=" + hex(sessionInfo.flags))
QUESTION
I can't seem to figure out what api call is needed to find objects in the slot list.. i have something like print("Finding objects: " + hex(a.C_FindObjects(slotList[x], CKA_CLASS, CKO_CERTIFICATE)))
I'm not sure what arguments to pass or if it's structured the right way.
Im using this documentation LowLevel API pkcs11
Ultimately I'm trying to extract the specific omnikey smart card token.. use its private key and cert to sign and verify data..
SearchResult = PyKCS11.LowLevel.ckobjlist(10)
SearchTemplate = PyKCS11.LowLevel.ckattrlist(0)
print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session,SearchTemplate))
print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult))
print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session))
First you have to make a result variable and use it to search the object list. I passed 10 in, as I knew there were only a handful of objects and tokens within the list. You can construct a template variable that searches each object for specific attributes, such if it is Private, Modifiable, Key Type, Encrypt, etc. Then you have to make (a.C_FindObjectsInit(session,SearchTemplate)) call to initialize the search in the session by template specifications. Working with the LowLevel API can be confusing, there is virtually no documentation. Hope this helps.

AWS4 Signing request signature does not match…even though it seems to

I appear to have correctly followed the procedure for generating a canonical string and string to sign for the AWS4 SDK. However I receive the error The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
The only clue I have is that when I'm not using the Moment.js utc() call, it accepts the signature as a match but (as expected) treats the signature as expired, so I suspect the UTC vs. local time is related to the issue.
Here is the code where I generate the timestamps.
var now = moment().utc();
var date_stamp = now.format('YYYYMMDD');
var amzn_date = now.format('YYYY-MM-DDTHH:mm:ssZ');
var string_to_sign_date = now.format('YYYYMMDDTHHmmssZ');
string_to_sign_date = string_to_sign_date.replace('+00:00', 'Z');
amzn_date = string_to_sign_date.replace('+00:00', 'Z');
Here is where I create the string_to_sign:
var string_to_sign = connectMeRequest.algorithm + '\n' + string_to_sign_date + '\n' + credential_scope + '\n' + cryptoJS.SHA256(canonical_request);
Here is my (console logged) vs. Amazon's signature. I didn't replace the newlines in their JSON res in case that is the issue.
My output for canonical string:
POST
/prod/makeEchoCallHandler
content-type:application/x-www-form-urlencoded
host:408wm9ltub.execute-api.us-west-2.amazonaws.com
x-amz-date:20160116T191451Z
x-amz-target:aws4_request
content-type;host;x-amz-date;x-amz-target
03a2c439264740e4883441d0049beaf9da4dc865ddd7169dbe9e747f28da6185
Their output:
POST\n/prod/makeEchoCallHandler\n\ncontent-type:application/x-www-form-urlencoded\nhost:408wm9ltub.execute-api.us-west-2.amazonaws.com\nx-amz-date:20160116T191451Z\nx-amz-target:aws4_request\n\ncontent-type;host;x-amz-date;x-amz-target\n03a2c439264740e4883441d0049beaf9da4dc865ddd7169dbe9e747f28da6185
My output for string to sign:
AWS4-HMAC-SHA256
20160116T191451Z
20160116/us-west-2/execute-api/aws4_request
ab63b72a190addcde39771097bbbc2e28c0d00c458fda9136d2d630e227e9074
Their output:
AWS4-HMAC-SHA256\n20160116T191451Z\n20160116/us-west-2/execute-api/aws4_request\nab63b72a190addcde39771097bbbc2e28c0d00c458fda9136d2d630e227e9074
The '\n' is officially part of the string to sign. You need to add it in explicitly. A good example is found here. The important part is:
StringToSign =
Algorithm + '\n' +
RequestDate + '\n' +
CredentialScope + '\n' +
HashedCanonicalRequest
Add those in and give it another try!
EDIT: As noted in the comments, this looks to be an error in the date formatting between the canonical string and the string to sign.

Resources