AutoIT Siemens CMP Generator
Jump to navigation
Jump to search
AU3 script to generate files for Siemens
This source code will compile to make a little GUI for generating the .cmp files used in Siemens phone system, taking initial generic textual templates for modification.
; RMDC Siemens CMP generator
; release history, ISO versioning
; V20111118 first version
; V20111122 fixed bugs auto extn prefix
; V20120119 fixed 'Add More' box going to wrong place, altered name check to allow numberic and underscroes
#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <Process.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
Local $wtit = "SIEMENS CMP File Generator V20120119"
If WinExists($wtit) Then Exit ; It's already running
AutoItWinSetTitle($wtit)
;Load template
Func loadtemp($t)
;template in
$fin = @ScriptDir & "\" & $t
Global $tt = FileRead($fin)
;check read ok
If $tt = -1 Then
MsgBox(0, "Error", "Erro reading" & $fin & " . Please check file exists and you have read access")
Return -1
EndIf
EndFunc
; Start building up the GUI
GuiCreate($wtit, 450, 300)
GuiSetIcon(@SystemDir & "\shell32.dll", 310)
;little help system
$helpmenu = GUICtrlCreateMenu("Help")
$infoitem = GUICtrlCreateMenuItem("Help", $helpmenu)
$aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)
$useitem = GUICtrlCreateMenuItem("HowToUse", $helpmenu)
; COMBO
;;$pref=GUICtrlCreateCombo("252", 10, 10, 50, 30) ; create first item
;;GUICtrlSetData(-1, "232|229") ; add other item snd set a new default
;;GuiCtrlCreateLabel("Prefix", 10, 30, 51, 20)
;GUICtrlCreateEdit ( "text", left, top [, width [, height [, style [, exStyle]]]] )
;GUICtrlCreateButton ( "text", left, top [, width [, height [, style [, exStyle]]]] )
;GUICtrlCreateLabel ( "text", left, top [, width [, height [, style [, exStyle]]]] )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;OUTPUT GUI GENERATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$outp=GuiCtrlCreateInput("", 10, 240, 350, 20)
$outpl=GuiCtrlCreateLabel("Output location", 10, 260, 200, 20)
GUICtrlSetState($outp, $GUI_HIDE)
GUICtrlSetState($outpl, $GUI_HIDE)
;write out generated CMP txt file
Func output($msg,$s,$txt)
$date = @MON & "-" & @MDAY & "-" & @YEAR
$c = $s & $date & ".txt"
$cmpout = (@TempDir & "\" & $c)
;add file header
$t="FILE VERSION:11.00.01:MP2"&@CRLF&$txt
;open File
$op = FileOpen($cmpout,2)
;write out cmp file
$wr = FileWrite ($op, $t )
;check write ok
If $wr = -1 Then
MsgBox(0, "Error", "Erro writing" & $cmpout & " . Please check write access.")
Return -1
EndIf
FileClose($wr)
GUICtrlSetData ($outp, $cmpout)
GUICtrlSetData ($outpl,$msg)
GUICtrlSetState($outp, $GUI_SHOW)
GUICtrlSetState($outpl, $GUI_SHOW)
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;USER CMP GUI GENERATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;INPUT for user create
GuiCtrlCreateLabel("User Creator", 10, 1,65,16,$SS_SUNKEN)
;Extension #
$extn=GuiCtrlCreateInput("", 10, 20, 50, 20)
GuiCtrlCreateLabel("Extension", 11, 40, 50, 20)
;First Name
$first=GuiCtrlCreateInput("", 70, 20, 80, 20)
GuiCtrlCreateLabel("First Name", 71, 40, 80, 20)
;Surname
$surn=GuiCtrlCreateInput("", 160, 20, 80, 20)
GuiCtrlCreateLabel("Surname", 161, 40, 80, 20)
;GGenerate button
$genuser = GuiCtrlCreateButton("Generate User CMP", 310, 20, 120, 20)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;PICKUP GROUP GUI GENERATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;INPUT for pickup group create
$addp=""
Global $a[20]
$j=0
$leftmin=10
$leftmax=200
$topmin=120
$topmax=210
$left=$leftmin
$top=$topmin
$pnum = GuiCtrlCreateInput("", $left, $top-23, 30, 20)
GuiCtrlCreateLabel("Pickup Group Creator", $left, $top-43,110,16,$SS_SUNKEN)
GuiCtrlCreateLabel("Group", $left+35, $top-21,70,20)
GuiCtrlCreateLabel("Extensions", $left+170, $top-21,70,20)
$addp = GuiCtrlCreateButton("Add More", $leftmax+40, $top, 60, 20)
Func pickup($n)
If $top > $topmax Then
Return
EndIf
;MsgBox(0, "Extension", $t)
For $i = 1 to $n
If $left > $leftmax Then $left=$leftmin
$a[$j] = GuiCtrlCreateInput("", $left, $top, 40, 20)
$left+=45
$j+=1
Next
GUICtrlSetPos($addp,$leftmax+40,$top)
$top+=30
EndFunc
;Create 5 group boxes to start with
pickup(5)
$gengroup = GuiCtrlCreateButton("Generate Pickup CMP", 310, 100, 120, 20)
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; USER TEMPLATE MOD
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func modtemplateuser()
If loadtemp("UOL.txt") = -1 Then Return
$extnn=StringStripWS(GUICtrlRead($extn,1),7)
$surnn=StringStripWS(GUICtrlRead($surn,1),7)
$firstt=StringStripWS(GUICtrlRead($first,1),7)
If chknum($extnn,4,4,"Extension") = -1 Then Return
If getprefix($extnn) = -1 Then Return
If StringLen($surnn) < 2 OR StringLen($firstt) < 2 Then
MsgBox(0, "Names", "First/Surname: Please enter at least 2 letters for first and surname.")
Return
EndIf
;string over 20 chars or contains anything other than alphanum or _ then abort
$n=$surnn&$firstt
If StringLen($n) > 20 OR StringRegExp($n,'[^A-Za-z0-9_]+') Then
MsgBox(0, "Names", "First/Surname: Please enter combined max of 20 letters for first and surname."&@CR&"Names can only contain letters,numbers and underscores.")
Return
EndIf
;reverse extn to generate password
$l = StringLen($extnn)
$rextnn=""
For $i = 1 to $l
$l = StringRight($extnn, $i)
$n = StringTrimRight($l, $i-1)
$rextnn= $rextnn & $n
Next
$pwdd=$extnn & $rextnn
;search and replace in template
$tt = StringReplace($tt, "#extn#", $extnn)
$tt = StringReplace($tt, "#pref#", $preff)
$tt = StringReplace($tt, "#first#", $firstt)
$tt = StringReplace($tt, "#surn#", $surnn)
$tt = StringReplace($tt, "#pwd#", $pwdd)
$s=$extnn &"_"& $preff &"_"& $surnn &"_"& $firstt &"_"
If output("User Group Template Path",$s,$tt) = -1 Then Return
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PICKUP GROUP TEMPLATE MOD
;;;;;;;;;;;;;;;;;;;;;;;;;;
Func modtemplategroup()
If loadtemp("PICKUP.txt") = -1 Then Return
;check pickup group number
$pnumm=StringStripWS(GUICtrlRead($pnum,1),7)
If chknum($pnumm,2,3,"Pickup Goup") = -1 Then Return
;setup template
$ttout=""
;loop though array of inputs validate extensions then get prefixes, then generate template - if box empty then skip
For $i=0 To UBound($a)-1
;reset template for each run
$ttt=$tt
If GUICtrlRead($a[$i],1) = "" Then ContinueLoop
;check valid extension numbers
$extnn=StringStripWS(GUICtrlRead($a[$i],1),7)
If chknum($extnn,4,4,"Extension, box "&$i+1) = -1 Then Return
;get numFile:Siemens CMP Generator.pngber prefixes
If getprefix($extnn) = -1 Then Return
;alter template
$ttt = StringReplace($ttt, "#extn#", $extnn)
$ttt = StringReplace($ttt, "#pref#", $preff)
$ttt = StringReplace($ttt, "#pnum#", $pnumm)
;concat template
$ttout=$ttout &@CRLF& $ttt
Next
;catch no numbers being put in
If $ttout = "" Then Return -1
$s=$pnumm &"_"
If output("Pickup Group Template Path",$s,$ttout) = -1 Then Return
EndFunc
Func chknum($v,$min,$max,$txt)
;input: characters and number of digits wanted,$txt it relates to
;read values entered and strip WS, then check data formatting
$l=StringLen($v)
If $l > $max OR $l < $min OR NOT StringIsDigit($v) Then
;If $l > $max OR $l < $min Then
MsgBox(0, $txt&"Number", "Error with "&$txt&" Number: Please enter a number with a minimum of "&$min&" digits and a maxium of "&$max&" digits.")
Return -1
EndIf
EndFunc
Func getprefix($e)
Global $preff
Switch StringLeft($e,1)
Case 1
$preff = 223
Case 2 To 5
$preff = 252
Case 7
$preff = 229
EndSwitch
EndFunc
; GUI MESSAGE LOOP
GuiSetState()
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $useitem
MsgBox(64, "Use", "[Top Menu] Operation & Maintanence > Recovery"&@CR&@CR&"[LHS] Import and Export > Import >"&@CR&@CR&"Browse to new script file, "&@TempDir&"\xxxxx.cmp"&@CR&@CR&"Next, Change type to 'Openscape Voice'"&@CR&@CR&"Click on target node button and select UOL production"&@CR&@CR&"Save, Import")
Case $msg = $aboutitem
MsgBox(64, "About", "Written for the University of Leicester "&@CR&@CR&"by richud.com 2011-2012"&@CR&@CR&"http://www.richud.com/wiki/AutoIT_Siemens_CMP_Generator"&@CR&@CR&"Bug / feature requests to: rfm6@le.ac.uk")
Case $msg = $infoitem
MsgBox(32, "Info", "Create CMP file for SIEMENS phone system"&@CR&@CR&"Enter details and press Generate CMP."&@CR&@CR&"Extension must be only 4 numbers."&@CR&@CR&"Combined total for surname and firstname is 20 letters.")
Case $msg = $genuser
modtemplateuser()
Case $msg = $addp
pickup(5)
Case $msg = $gengroup
modtemplategroup()
EndSelect
WEnd