Progress 4gl Secure Socket Authentication - sockets

Currently attempting to perform a socket connection to a host that has authentication setup using the username:password#domain syntax. The following curl request works fine when run via command line:
/opt/pware/bin/curl -s -v -S -k -X POST -d #/test/worldpay.xml https://username:password#secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp
The problem lies when attempting to post the same worldpay.xml payload file using progress secure socket. My socket connects using the following:
DEFINE VARIABLE vhSocket AS HANDLE NO-UNDO.
CREATE SOCKET vhSocket.
vhSocket:CONNECT('-H test.worldpay.com -S 443 -ssl -nohostverify') NO-ERROR.
IF vhSocket:CONNECTED() EQ FALSE THEN
DO:
Message "COULD NOT CONNECT".
vhSocket:DISCONNECT().
DELETE OBJECT vhSocket NO-ERROR.
RETURN.
END.
ELSE
Message "CONNECTED!".
I am setting up my header as follows once the socket connection is opened:
ASSIGN
vRequest = 'POST ' +
username + ":" + password + "#" + "/jsp/merchant/xml/paymentService.jsp" +
' HTTPS/1.1' + chr(13) + chr(10) +
'Connect: close' + chr(13) + chr(10) +
'Host: ' + "secure-test.worldpay.com" + chr(13) + chr(10) +
'Content-Length: ' + string(LENGTH(postdata,"raw")) + chr(13) + chr(10) +
'Content-Type: text/xml' + chr(13) + chr(10) +
chr(13) + chr(10) +
postData +
chr(13) + chr(10).
set-byte-order(vData) = BIG-ENDIAN.
set-size(vData) = LENGTH(vRequest,"raw").
put-string(vData,1,LENGTH(vRequest,"raw")) = vRequest.
vReturnCode = vhSocket:WRITE(vData, 1, LENGTH(vRequest,"raw")).
Any help on figuring out how the header should be structured or how to perform basic authentication over Secure Sockets in Progress would be greatly appreciated. Thanks guys!

For http(s) basic authentication, you don't POST the username as part of the URL.
See https://en.wikipedia.org/wiki/Basic_access_authentication#Client_side
This is what we use in our http client, you'll have to change the call to AddHttpHeader to code that send that header line to the server socket.
/*------------------------------------------------------------------------------
Purpose: Adds a basic authorization header to the request
Notes:
#param pcUserName The UserName to use for basic authorization
#param pcPassword The password to use for basic authorization
------------------------------------------------------------------------------*/
METHOD PUBLIC VOID SetBasicAuthorization (pcUserName AS CHARACTER,
pcPassword AS CHARACTER):
DEFINE VARIABLE cBase64 AS LONGCHAR NO-UNDO.
DEFINE VARIABLE mAuthorization AS MEMPTR NO-UNDO .
ASSIGN cBase64 = SUBSTITUTE ("&1:&2":U, pcUserName, pcPassword) .
SET-SIZE (mAuthorization) = LENGTH (cBase64) .
PUT-STRING (mAuthorization, 1, LENGTH (cBase64)) = cBase64 .
ASSIGN cBase64 = BASE64-ENCODE (mAuthorization) .
AddHttpHeader (SUBSTITUTE ("Authorization Basic &1":U, cBase64)) .
FINALLY:
SET-SIZE (mAuthorization) = 0 .
END FINALLY.
END METHOD .
So in your case, try this:
ASSIGN
vRequest = 'POST ' + "/jsp/merchant/xml/paymentService.jsp" +
' HTTPS/1.1' + chr(13) + chr(10) +
'Connect: close' + chr(13) + chr(10) +
'Host: ' + "secure-test.worldpay.com" + chr(13) + chr(10) +
'Content-Length: ' + string(LENGTH(postdata,"raw")) + chr(13) + chr(10) +
'Content-Type: text/xml' + chr(13) + chr(10) +
'Authorization: Basic ' + cBase64 + chr(13) + chr(10) +
chr(13) + chr(10) +
postData +
chr(13) + chr(10).

Related

Can an sdp error cause stream corruption?

I am trying to get a RTP (over udp) live stream (h264) from my Raspberry Pi using GStreamer (rpicamsrc). The video is being capture and forwarded to the browser using the Kurento Media Server, i.e. RPi -> KMS -> Browser.
The stream comes through with about 4s delay (which is not ideal but okay) however what is displayed seems to be corrupted and I am not sure why.
Corrupted Stream Display:
Some colleagues have suggested problems with interlacing/ p-frames (?) but I don't have any clue about this or what I should be looking for.
Mangled SDP from receiver
String rtpSdpOffer =
"v=0\r\n"
+ "o=- 0 0 IN IP4 " + senderIp + "\r\n"
+ "s=Kurento Tutorial - RTP Player\r\n"
+ "c=IN IP4 " + senderIp + "\r\n"
+ "t=0 0\r\n";
if (useAudio) {
rtpSdpOffer +=
"m=audio " + senderRtpPortA + " RTP/AVPF 96\r\n"
+ "a=rtpmap:96 opus/48000/2\r\n"
+ "a=sendonly\r\n"
+ sdpComediaAttr
+ "a=ssrc:" + senderSsrcA + " cname:" + senderCname + "\r\n";
}
rtpSdpOffer +=
"m=video " + senderRtpPortV + " " + senderProtocol + " 103\r\n"
+ sdpCryptoAttr
+ "a=rtpmap:103 " + senderCodecV + "/90000\r\n"
+ "a=rtcp-fb:103 goog-remb\r\n"
+ "a=sendonly\r\n"
+ sdpComediaAttr
+ "a=ssrc:" + senderSsrcV + " cname:" + senderCname + "\r\n"
+ "";
Gstreamer script to begin stream
PEER_A={KMS_AUDIO_PORT} PEER_V={KMS_VIDEO_PORT} PEER_IP={KMS_PUBLIC_IP} \
SELF_PATH="{PATH_TO_VIDEO_FILE}" \
SELF_A=5006 SELF_ASSRC=445566 \
SELF_V=5004 SELF_VSSRC=112233 \
bash -c 'gst-launch-1.0 -e \
rtpbin name=r sdes="application/x-rtp-source-sdes,cname=(string)\"user\#example.com\"" \
rpicamsrc ! video/x-raw,width=200,height=150,framerate=25/1 ! decodebin name=d \
d. ! x264enc tune=zerolatency \
! rtph264pay ! "application/x-rtp,payload=(int)103,clock-rate=(int)90000,ssrc=(uint)$SELF_VSSRC" \
! r.send_rtp_sink_1 \
r.send_rtp_src_1 ! udpsink host=$PEER_IP port=$PEER_V bind-port=$SELF_V \
r.send_rtcp_src_1 ! udpsink host=$PEER_IP port=$((PEER_V+1)) bind-port=$((SELF_V+1)) sync=false async=false \
udpsrc port=$((SELF_V+1)) ! tee name=t \
t. ! queue ! r.recv_rtcp_sink_1 \
t. ! queue ! fakesink dump=true async=false'
Any help is greatly appreciated
SDP can cause corruption. If the codec data you would transmit in there does not match the stream. But it looks like you don't transmit codec data via SDP - but probably in-band.
The artifact in the image looks like a rowbyte/stride problem. Maybe caused by your video dimensions. It is recommend to use resolutions multiple of 16. However it should still work. It could be that the decoder/renderer does something weird. I would try to receive the stream and save to file watch it in a regular video player and check whether it displays better and what video dimensions are being reported.

In a QLikView script generate code dependent of parameters in function call

I have a script in QLikView to extract and check my data. It has to perform a data extraction for 12 separate times. I made a function that works properly but some things are hardcoded and I want to call the same function 12 times with different parameters. The question that I have is about code generation dependent of the parameters in the function.
A part of my code is :
SUB SplitsenOpMiddel(middel, eersteVraag, laatsteVraag)
Temp_Middel_$(middel):
LOAD
Veldzoeknaam AS ZoekNaam,
VeldP_id AS $(middel)_VeldP_id,
Middel AS $(middel)_Middel,
MATEnr AS $(middel)_MATE,
IF(Vraagnr=1, VeldWaarde) AS $(middel)_Vraag001,
IF(Vraagnr=2, VeldWaarde) AS $(middel)_Vraag002,
IF(Vraagnr=3, VeldWaarde) AS $(middel)_Vraag003,
IF(Vraagnr=4, VeldWaarde) AS $(middel)_Vraag004,
IF(Vraagnr=5, VeldWaarde) AS $(middel)_Vraag005,
IF(Vraagnr=6, VeldWaarde) AS $(middel)_Vraag006,
IF(Vraagnr=1, VeldTypeGrp) AS $(middel)_Vraag001Type,
IF(Vraagnr=2, VeldTypeGrp) AS $(middel)_Vraag002Type,
IF(Vraagnr=3, VeldTypeGrp) AS $(middel)_Vraag003Type,
IF(Vraagnr=4, VeldTypeGrp) AS $(middel)_Vraag004Type,
IF(Vraagnr=5, VeldTypeGrp) AS $(middel)_Vraag005Type,
IF(Vraagnr=6, VeldTypeGrp) AS $(middel)_Vraag006Type
RESIDENT Data2
WHERE Vraagsort = '$(middel)';
In this case, the function call is :
CALL SplitsenOpMiddel('A', 1, 6)
So far, the numbers 1 to 6 are hardcoded but what I want is generate this code dependent of the second and third parameter.
My second function call will be :
CALL SplitsenOpMiddel('B', 7, 10)
And automatically the code needs to be :
Temp_Middel_$(middel):
LOAD
Veldzoeknaam AS ZoekNaam,
VeldP_id AS $(middel)_VeldP_id,
Middel AS $(middel)_Middel,
MATEnr AS $(middel)_MATE,
IF(Vraagnr=7, VeldWaarde) AS $(middel)_Vraag007,
IF(Vraagnr=8, VeldWaarde) AS $(middel)_Vraag008,
IF(Vraagnr=9, VeldWaarde) AS $(middel)_Vraag009,
IF(Vraagnr=10, VeldWaarde) AS $(middel)_Vraag010,
IF(Vraagnr=7, VeldTypeGrp) AS $(middel)_Vraag007Type,
IF(Vraagnr=8, VeldTypeGrp) AS $(middel)_Vraag008Type,
IF(Vraagnr=9, VeldTypeGrp) AS $(middel)_Vraag009Type,
IF(Vraagnr=10, VeldTypeGrp) AS $(middel)_Vraag0010Type
RESIDENT Data2
WHERE Vraagsort = '$(middel)';
Is there a way in QlikView to perform this?
Another part of my code where I need the same type of code generation is :
Check_Middel_$(middel):
NOCONCATENATE LOAD
ZoekNaam,
$(middel)_VeldP_id,
$(middel)_Middel,
$(middel)_MATE,
IF(ISNULL($(middel)_Vraag001),
IF(ISNULL($(middel)_Vraag002) AND
ISNULL($(middel)_Vraag003) AND
ISNULL($(middel)_Vraag004) AND
ISNULL($(middel)_Vraag005) AND
ISNULL($(middel)_Vraag006), 'G', 'F'))
AS $(middel)_Leeg_Check,
IF($(middel)_Vraag001 = 0,
IF($(middel)_Vraag002 = 0 AND
$(middel)_Vraag003 = 0 AND
$(middel)_Vraag004 = 0 AND
$(middel)_Vraag005 = 0 AND
$(middel)_Vraag006 = 0, 'G', 'F'))
AS $(middel)_0_Check,
IF(($(middel)_Vraag001 <> 0 AND NOT ISNULL($(middel)_Vraag001)),
IF(ISNULL($(middel)_Vraag002) OR
ISNULL($(middel)_Vraag003) OR
ISNULL($(middel)_Vraag004) OR
ISNULL($(middel)_Vraag005) OR
ISNULL($(middel)_Vraag006), 'F',
IF(($(middel)_Vraag002 = 0) AND ($(middel)_Vraag003 = 0) AND ($(middel)_Vraag004 = 0) AND ($(middel)_Vraag005 = 0) AND ($(middel)_Vraag006 = 0), 'M', 'G')))
AS $(middel)_Vol_Check,
$(middel)_Vraag001,
$(middel)_Vraag002,
$(middel)_Vraag003,
$(middel)_Vraag004,
$(middel)_Vraag005,
$(middel)_Vraag006
RESIDENT Middel_$(middel);
DROP TABLE Middel_$(middel);
You need to "build" the script on the fly. The code below shows how this can be achieved for the first function SplitsenOpMiddel can look. Calling this function like this call SplitsenOpMiddel('A', 1, 6) will generate the table with the required fields.
You can have a look at the sample qvw here. Tried to cover both cases but might not work as you expected but will give you an idea.
sub SplitsenOpMiddel(middel, eersteVraag, laatsteVraag)
let Temp_Middel = 'Temp_Middel_' & '$(middel)' & ':' & chr(13) & 'Load' & chr(13);
for b = $(eersteVraag) to $(laatsteVraag)
let Temp_Middel = '$(Temp_Middel)' & 'IF(Vraagnr=' & $(b) & ', VeldWaarde) AS' & ' $(middel)' & '_Vraag00' & $(b) & ',' & chr(13) &
'IF(Vraagnr=' & $(b) & ', VeldTypeGrp) AS' & ' $(middel)' & '_Vraag00' & $(b) & 'Type,' & chr(13);
next
let Temp_Middel = '$(Temp_Middel)' & 'Veldzoeknaam AS ZoekNaam,' & chr(13) &
'VeldP_id AS ' & '$(middel)' & '_VeldP_id,' & chr(13) &
'Middel AS ' & '$(middel)'& '_Middel,' & chr(13) &
'MATEnr AS ' & '$(middel)' & '_MATE ' & chr(13) &
'Resident Data2' & chr(13) &
'WHERE Vraagsort =' & chr(39) & '$(middel)' & chr(39) & ';';
$(Temp_Middel);
end sub
If your question is if it could work, I would answer yes. Variables in QlikView are handled as text to be replaced when invoked, so I see to reason why it shouldn't work.

Status check of service is failing

I am working on Windows 2008 Server R2. I found this VBScript that should be checking the whether a service is either started or stopped.
Here is the script:
'Declare Variables
Dim objWMIService, objProcess, colProcess, Status, strComputer, strService
'Assign Arguments
strComputer = WScript.Arguments(0)
strService = WScript.Arguments(1)
Status = False
'Check For Arguments - Quit If None Found
If Len(strService) < 1 Then
Wscript.echo "No Arguments Entered - Exiting Script"
WScript.Quit
End If
'Setup WMI Objects
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("SELECT DisplayName, Status, State FROM Win32_Service WHERE DisplayName = '" & strService & "'")
'Check For Running Service
For Each objProcess In colProcess
If InStr(objProcess.DisplayName, strService) > 0 And objProcess.State = "Running" Then
Status = True
End If
Next
If Status = True Then
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Running"
Else
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Not Running"
End If
Via the command line I call the script like this
CSCRIPT ServiceCheckScript.vbs LOCALHOST "Print Spooler"
Response from the command line is
...\ServiceCheckScript.vbs(20, 1) (null): 0x80041017
I see that the 0x80041017 error refers to result of a query returning a null value, but I am not sure as to why that may be.
A few issues with the above code:
Verify you got results from your WMI query so you don't attempt to use a null. Wrap the use of the results in if colProcess.count > 0 then.
Remove the extra .quit by enclosing your code in the parameters verification. Its cheaper/cleaner to do this with an argument count than a string function wscript.arguments.count = 2 since you were only checking to ensure they were not empty. If you need a more sophisticated validation, then more logic would be required.
There isn't any reason to use instr(objProcess.Displayname, strService) because your WMI query already specified that the results are equal to the service display name in this, where DisplayName = strService.
It's simpler/clearer to perform the conditional inspection of service status all inside the loop.
Here is my example.
'Declare Variables
Dim objWMIService, objProcess, colProcess, Status, strComputer, strService
'Verify arguments were passed
if WScript.Arguments.Count = 2 then
'Assign Arguments
strComputer = WScript.Arguments(0)
strService = WScript.Arguments(1)
'Setup WMI Objects
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("SELECT DisplayName, Status, State FROM " & _
"Win32_Service WHERE DisplayName = '" & strService & "'")
'Ensure there were results returned
if colProcess.count > 0 then
'Check For Running Service
For Each objProcess In colProcess
If objProcess.State = "Running" Then
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Running"
else
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Not Running"
End If
Next
else
WScript.Echo "Service: " & UCase(strComputer) & " " & strService & " Does not exist"
end if
end if
edit: Just adding that I validated the above code in both Win 8.1 and Server 2012R2, using both valid and invalid service names. However, I would add more error checking, like verifying the computer parameter is valid to ensure your WMI query doesn't fail unnecessarily/inexplicably.

How to run program with variable command line arguments?

I have the following script:
For $alpha = 1 to 10
For $beta = 1 to 10
Run('"C:\Users\MyProg.exe ' & alpha/10 & ' ' & beta/10 & ' 200 2 0.5'
;some other actions follow
Next
Next
I have checked many times that the string is well-formed, thus I have no idea why the script wouldn't run the program. Could you help me please?
Just replace the ending ' with "') and use proper variable names including the $... like $alpha instead of just alpha. Your syntax check in SciTE should have told you.
For $alpha = 1 to 10
For $beta = 1 to 10
Run('"C:\Users\MyProg.exe ' & $alpha/10 & ' ' & $beta/10 & ' 200 2 0.5"')
;some other actions follow
Next
Next

Scala Process for Linux is stuck

I'm trying to use Scala Process in order to concate two files and send the result to a new file.
The code works fine, but when i remove the permissions to the folder, it seems to be stuck.
Here is the code:
val copyCommand = Seq("bash", "-c", "cat \"" + headerPath + "\" \"" + FilePath + "\"")
Process(copyCommand).#>>(new File(FileWithHeader)).!
Maybe something like this can help (without invoking bash)?
import sys.process._
(Seq("cat", "file-1.txt", "file-2.txt") #>> new java.io.File("files-1n2.txt")).!
I preformed the concatination in the same comend without creating new file and it's work fine:
val copyCommand = Seq("bash", "-c", "cat \"" + headerPath + "\" \"" + FilePath + "\">FileWithHeader")
Process(copyCommand).#!