📜 ⬆️ ⬇️

Call from terminal

I decided to publish a short note how to use the basic knowledge of programming to realize the possibility of calls from the terminal server.
Who needs it: first of all it will be interesting to those people (or organizations) who have a terminal server (EG windows 2003) there is some CRM program in it that stores contact information for customers. And employees use software IP phones.

What we have is the local network, the terminal server itself [we have Windows 2003 Standart], the IP telephony server [Asterisk], the client machines [Windows XP] with the installed IP software [X-lite].
The general idea: on the terminal server [hereinafter TS] there should be a certain program [client part. Further [KCh], which determines from which IP-address Vasily Pupkin came in [I ask all VP not to be offended :)]. A certain server program hangs on Vasily's computer and listens to the port [further midrange]. The question arises - why is the server on the server CC, and on the client machine MF? The thing is that on the server the program will not listen to the ports, but will “connect” to the client machine and send the number to which you need to call.

To solve this problem, I used AutoIt3 and a small GETTSCIP program, by running it through the console we get our IP in the terminal [just what we need]
')
1. We write midrange [will stand on the client machine]. As we said earlier, the program is listening to the port [in this example, 65532]. If data arrives, it searches for a window with a specific header [X-lite. For other IP phones, you can use Autoit Window Info, which comes standard with AutoIt], activates the IP phone, sends the received digits to the IP phone, and presses Enter. Sample script:

Local $szServerPC = @ComputerName
Local $szIPADDRESS = TCPNameToIP($szServerPC)
$socket = UDPBind($szIPADDRESS, 65532)
If @error <> 0 Then Exit
While 1
$data = UDPRecv($socket, 50)
If $data <> "" Then
WinActivate("XLite")
Send($data & "{enter}")
EndIf
sleep(100)
WEnd
Func OnAutoItExit()
UDPCloseSocket($socket)
UDPShutdown()
EndFunc


2. We write KCH [will stand on a terminal server]. So, the QC as a parameter, we specify the phone number. This will allow us to insert, for example, a button for a call to 1C [for example, in our CRM]. Further, the CC determines the IP address from which the client entered the terminal. And by UDP sends him a phone number. Accordingly, the employee at this moment triggered MF and a call occurs. Sample script [pre-copy the GETTSCIP program named getmyip.exe into the system directory]:

if($CmdLine[0]==1) then
Local $foo = Run(@ComSpec & " /c getmyip", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
Local $ip
While 1
$line = StdoutRead($foo)
If @error Then ExitLoop
if $line<>'' then
$ip=$line
EndIf
Wend
$ip=StringReplace($ip,"WTSClientAddress: ","");
$socket = UDPOpen($ip, 65532)
If @error <> 0 Then Exit
$status = UDPSend($socket, $CmdLine[1])
If $status = 0 then
MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
Exit
EndIf
EndIf
Func OnAutoItExit()
UDPCloseSocket($socket)
UDPShutdown()
EndFunc


That's all. Now you can put a button on the vehicle in 1C or another program with the execution of the 2nd part of the program, the phone number is specified as a parameter.
Client, server for Xlite and getmyip can be downloaded in the archive here .

Source: https://habr.com/ru/post/76355/


All Articles