⬆️ ⬇️

Auto provisioning for MicroSIP softphone

My acquaintance with MicroSIP began several years ago. It is the simplicity and undemanding of resources against the background of competitors that forced to pay attention to it. And now, when all the functionality necessary for work appeared in it, I decided to implement it for work within the company.



Auto provisioning or configuration auto distribution mechanism is used in most hardware phones. There is no such mechanism in MicroSIP, but there is a simple configuration file with which we will actually work. And having a portable version of the program will play into our hands when deciding whether to distribute the distribution and updates.



JScript was used to develop the configuration distribution script and updates. The essence of the process is as follows: when a user logs in, a script is launched that pulls out the current version of the distribution and settings and applies them to the logged-in user on the local machine. When applying the settings, only the settings specified in the configuration file on the server are changed, the rest of the user settings remain unchanged.



Create a shared folder on the Windows server with read access for all domain users and place 2 files in it: microsip_autoconf.js and MicroSIP.ini . The js file contains the script itself, in which (when you save the structure described in this article), you need to change the value of the srvConfPath variable to the path to the configuration storage and distribution folder. Next, through group policies, we create a task to execute this script when a user logs on to the system. In the ini file we place the configuration common to all.

')

Contents of the microsip_autoconf.js file
// ============================================================================ //   - MicroSIP // ============================================================================ var WSN = WScript.CreateObject("WScript.Network"); var FSO = WScript.CreateObject("Scripting.FileSystemObject"); var WSS = WScript.CreateObject('WScript.Shell'); var confFileName = 'MicroSIP.ini'; var confFolderName = 'MicroSIP'; var distFolderName = 'Dist'; var usersFolderName = 'Users'; var srvConfPath = '\\\\<server_name>\\microsip$'; var userName = WSN.UserName; var srvDistPath = srvConfPath + '\\' + distFolderName; var usrConfPath = WSS.ExpandEnvironmentStrings('%APPDATA%') + '\\' + confFolderName; var genConfFileOnSrv = srvConfPath + '\\' + confFileName; var usrConfFileOnSrv = srvConfPath + '\\' + usersFolderName + '\\' + userName + '.ini'; var usrConfFileOnLoc = usrConfPath + '\\' + confFileName; var genSrvINI = {}; var usrSrvINI = {}; var usrLocINI = {}; //         if ( !(FSO.FileExists(usrConfFileOnSrv) && FSO.GetFile(usrConfFileOnSrv).Size > 0) ) { //     ,  WScript.Quit(); } //        if (FSO.FolderExists(srvDistPath)) { //    MicroSIP (/ ) var cmdLine = 'tasklist /fi "IMAGENAME eq microsip.exe" /fi "USERNAME eq ' + userName + '" /FO CSV /NH'; var wasRunning = /microsip.exe/.test(WSS.Exec(cmdLine).StdOut.ReadAll()); //   MicroSIP ( )    WSS.run("taskkill.exe /T /F /IM MicroSIP.exe", 0, true); FSO.CopyFolder(srvDistPath, usrConfPath); //      strDesktop = WSS.SpecialFolders("Desktop"); oMyShortcut = WSS.CreateShortcut(strDesktop + "\\MicroSIP.lnk"); oMyShortcut.WindowStyle = 4; oMyShortcut.IconLocation = usrConfPath + '\\microsip.exe, 0'; oMyShortcut.TargetPath = usrConfPath + '\\microsip.exe'; oMyShortcut.WorkingDirectory = usrConfPath; oMyShortcut.Save(); } //       ReadINIFile(genSrvINI, genConfFileOnSrv); //       ReadINIFile(usrSrvINI, usrConfFileOnSrv); //        ReadINIFile(usrLocINI, usrConfFileOnLoc); //        //         //         MergeINIObj(usrLocINI,genSrvINI); MergeINIObj(usrLocINI,usrSrvINI); //    SaveINIFile(usrLocINI,usrConfPath,usrConfFileOnLoc); //   MicroSIP if (wasRunning) { WSS.run(usrConfPath + "\\microsip.exe", 1, false); } //      ini    function ReadINIFile(INIObj, filename) { if ((FSO.FileExists(filename)) && (FSO.GetFile(filename).Size > 0)) { var fileh = FSO.OpenTextFile(filename, 1); while (!fileh.AtEndOfStream) { var line = fileh.ReadLine(); if (/^\[(\w+)\]/.test(line)){ var section = RegExp.$1.toLowerCase(); INIObj[section] = {}; } if (/^([^;#][^=]*?)\s*=\s*([^\r\n]*?)\s*$/.test(line)){ var param = RegExp.$1.toLowerCase(); var value = RegExp.$2; INIObj[section][param] = value; } } fileh.Close(); } } //    INI  ini- function SaveINIFile(INIObj, confPath, filename){ function WriteArray(arr){ for (var i in arr){ var value = arr[i]; if (typeof(value)=='object') { if (value) { file.Write('[' + i + ']\r\n'); WriteArray(value); } }else{ if (value) { file.Write(i + '=' + value + '\r\n'); } } } } if (!FSO.FolderExists(confPath)){ FSO.CreateFolder(confPath); } var file = FSO.OpenTextFile(filename, 2, true); WriteArray(INIObj); file.Close(); } //   INI    () INI  function MergeINIObj(firstINIObj, secondINIObj){ for (var section in secondINIObj){ if (!firstINIObj[section]) { firstINIObj[section] = {}; } for (var param in secondINIObj[section]){ if (!firstINIObj[section][param] || firstINIObj[section][param] != secondINIObj[section][param]){ firstINIObj[section][param] = secondINIObj[section][param]; } } } } 


Contents of MicroSIP.ini
 [Settings] disableLocalAccount=1 EnableLog=0 updatesInterval=never CheckUpdatesTime=1466489328 denyIncoming= usersDirectory=http://phonebook.local SingleMode=1 LocalDTMF=1 autoanswer=button denyIncoming=button micAmplification=1 swLevelAdjustment=1 audioCodecs=PCMA/8000/1 PCMU/8000/1 accountId=1 [Account1] Server=voip.local Domain=voip.local Proxy= PublicAddr= ListenPort= SRTP= Transport=udp Publish=0 STUN= ICE=0 allowRewrite=1 voicemailNumber= disableSessionTimer=0 


Next we need to create 2 more directories: Dist - to store the current distribution of the program and Users - for the personal configuration files of users. In Dist, unpack the portable version of MicroSIP and add a language file (if necessary). For Users, we set permissions for reading to all domain users and disable permissions inheritance. We will issue permissions separately for each configuration file in this directory only to the user whose settings are contained in this file.



Now we can create configuration files for users in the Users directory of the sAMAccountName.ini format . The priority of this file is higher, which allows redefining the global settings specified in MicroSIP.ini and, if necessary, making the settings personalized for each user.



Contents of sAMAccountName.ini
 [Account1] label=number AuthID=number Username=number DisplayName=sAMAccountName Password=password 


Actually, that's all. Now, when logging in, the employees whose configuration files are located in the Users directory will copy the distribution kit from Dist to the profile folder, create a configuration file and create a shortcut to launch MicroSIP.lnk on the desktop. In such a simple way we managed to solve the tasks of distributing and managing soft phones on workstations.

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



All Articles