Retrieve JSON from flash program in IE embed with Autoit - json
I am trying to retrieve a JSON that is sent from the flash program each time I load it.
Using Charles I am able to get the JSON data - application/json; charset=utf8 POST method - from the website however I would like Autoit to capture the JSON data and paste it into a text file on my desktop.
Basically, whenever I press a button on the flash program, I would like Autoit to parse the JSON data.
Another way is making a proxy in pure Autoit
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=proxy.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
TCPStartup()
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIEdit.au3>
#Include <Array.au3>
#Include <File.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode" , 1)
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",3)
Opt("TrayOnEventMode",1)
Global $ini = #ScriptDir & "\config.ini"
Global $mainarray[30][10]
Global $proxysocket , $proxysocketssl
Global $GUISHOW = 1
$mainarray[0][0] = "Hostport"
$mainarray[0][1] = "Clientsocket"
$mainarray[0][2] = "Hostsocket"
$mainarray[0][3] = "Request"
$mainarray[0][4] = "Hostname"
$mainarray[0][5] = "Timerhandle connection"
$mainarray[0][6] = "Blocked"
$mainarray[0][7] = "State"
$mainarray[0][8] = "connection type"
$mainarray[0][9] = "req count"
Global $gui = GUICreate("ProxyServer v0.2",700,700)
$DEBUG=GUICtrlCreateEdit("" , 5 , 30 , 500 ,670,BitOr($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
GUICtrlSetLimit(-1 , 2000000000000000)
Global $button_debug_clear = GUICtrlCreateButton("Clear",5,5,90,20)
GUICtrlSetOnEvent($button_debug_clear,"_debug_clear")
GUICtrlCreateLabel("Listening IP:",515,40,70,20)
GUICtrlCreateLabel("Port HTTP:",515,60,70,20)
GUICtrlCreateLabel("Port HTTPS:",515,80,70,20)
Global $input_proxyip = GUICtrlCreateInput("",590, 40,100,20)
Global $input_proxyport = GUICtrlCreateInput("",590,60,60,20)
Global $input_proxyportssl = GUICtrlCreateInput("",590,80,60,20)
Global $button_proxy_save = GUICtrlCreateButton("Save and Restart",515,140,180,20)
GUICtrlSetOnEvent($button_proxy_save,"_mainsocket_save")
Global $checkbox_debug = GUICtrlCreateCheckbox("Debugmode", 515 , 240, 120, 20)
Global $checkbox_debug_save = GUICtrlCreateCheckbox("Save Debug to file", 515 , 260, 120, 20)
Global $checkbox_debug_content = GUICtrlCreateCheckbox("Show traffic content", 515 , 280, 120, 20)
Global $button_debug_content = GUICtrlCreateButton("Binary to String",515,320,120,19)
GUICtrlSetOnEvent($button_debug_content,"_debug_binary")
Global $button_debug_array = GUICtrlCreateButton("show mainarray",515,340,120,19)
GUICtrlSetOnEvent(-1,"_show_array")
Global $tray_showgui = TrayCreateItem("Show gui")
TrayItemSetOnEvent($tray_showgui,"_gui_show")
GUISetOnEvent($GUI_EVENT_CLOSE,"_quit")
GUISetState(#SW_SHOW,$gui)
_mainsocket_create()
While 1
$newclientsock = TCPAccept($proxysocket)
If $newclientsock <> -1 Then
_save("] new HTTP clientconnection :" &_SocketToIP($newclientsock) &#CRLF)
_clientconnection_to_mainarray($newclientsock,80,"HTTP")
EndIf
$newclientsockssl = TCPAccept($proxysocketssl)
If $newclientsockssl <> -1 Then
_save("] new HTTPS clientconnection :" &_SocketToIP($newclientsockssl) &#CRLF)
_clientconnection_to_mainarray($newclientsockssl,443,"HTTPS","start")
EndIf
;--Recieving Req from Client
For $i = 1 To UBound($mainarray) -1
If $mainarray[$i][1] <> "" Then
$request = TCPRecv($mainarray[$i][1],100000)
If #error Then
_save("] Client " & $i & " closed connection after " & Floor(TimerDiff($mainarray[$i][5])) & " ms" & #CRLF)
_mainarray_deleteclient($i)
EndIf
If $request <> "" Then
_save("] Client " & $i & " requested" & #CRLF & #CRLF & $request & #CRLF)
$mainarray[$i][9] += 1
$mainarray[$i][3] = $request
If GUICtrlRead($checkbox_debug_content) = 1 Then _save($request & #CRLF)
EndIf
EndIf
Next
;--connecting and sending Req to Host
For $i = 1 To UBound($mainarray) -1
If $mainarray[$i][3] <> "" Then
If $mainarray[$i][2] = "" Then
$forward = _Get_Address($mainarray[$i][3])
_save("]" & $i &" Got Host Address : " & $forward & #CRLF)
$mainarray[$i][6] = 0
$mainarray[$i][4] = $forward
If $forward = "0" Then
_Send_Response($mainarray[$i][1],400)
_save("]" & $i &" Host is 0 , Error 400" & #CRLF)
Else
$serverip = TCPNameToIP($forward)
$serversock = TCPConnect($serverip,$mainarray[$i][0])
If $serversock <> -1 Then
_save("]" & $i &" Connected to Host: " & $forward & #CRLF)
$mainarray[$i][2] = $serversock
Else
_save("]" & $i &" Not Connected to Host: " & $forward & #CRLF)
_Send_Response($mainarray[$i][1],400)
_mainarray_deleteclient($i)
EndIf
EndIf
Else
$forward = _Get_Address($mainarray[$i][3])
If $forward <> $mainarray[$i][4] Then
_save("]" & $i &" Host Address changed from: " & $mainarray[$i][4] & " to: " & $forward & #CRLF)
$mainarray[$i][4] = $forward
TCPCloseSocket($mainarray[$i][2])
$mainarray[$i][2] = ""
EndIf
EndIf
If $mainarray[$i][2] <> "" Then
$prevlen = StringLen($mainarray[$i][3])
$mainarray[$i][3] = _request_modify($mainarray[$i][3],$mainarray[$i][4])
If $mainarray[$i][7] = "" Then
;$mainarray[$i][3] = _request_modify($mainarray[$i][3],$mainarray[$i][4])
TCPSend($mainarray[$i][2] , $mainarray[$i][3])
If Not #error Then
_save("]" & $i &" Sending HTTP to Host " & $mainarray[$i][4] & " successfull prevlen:" & $prevlen & " now:" & StringLen($mainarray[$i][3]) & #CRLF)
$mainarray[$i][3] = ""
Else
_save("]" & $i &" Error Sending HTTP to Host " & #CRLF)
EndIf
EndIf
EndIf
EndIf
Next
;--Waiting for Response from Host and Sending to client
For $i = 1 To UBound($mainarray) -1
If $mainarray[$i][2] <> "" Then
$serverresponse = TCPRecv($mainarray[$i][2],400000,1)
If #error Then
_mainarray_hostkillclient($i)
EndIf
If $serverresponse <> Binary("") Then
If $mainarray[$i][6] = 0 Then
_save("]" & $i &" Got Host response" & #CRLF)
If $mainarray[$i][1] <> "" And $mainarray[$i][7] = "" Then
TCPSend($mainarray[$i][1],$serverresponse)
If Not #error Then
_save("]" & $i &" Sent data to Client " & #CRLF)
If GUICtrlRead($checkbox_debug_content) = 1 Then _save(BinaryToString($serverresponse) & #CRLF)
EndIf
EndIf
ElseIf $mainarray[$i][6] = 1 Then
TCPSend($mainarray[$i][1],"HTTP/1.1 " & "403")
_mainarray_hostkillclient($i)
EndIf
EndIf
EndIf
Next
;---only for HTTPS
For $i = 1 To UBound($mainarray) -1
If $mainarray[$i][1] <> "" And $mainarray[$i][3] <> "" And $mainarray[$i][8] = "HTTPS" And $mainarray[$i][7] = "start" Then
_Send_Response($mainarray[$i][1],200) ;,$data="")
$mainarray[$i][3] = ""
$mainarray[$i][7] = ""
EndIf
Next
WEnd
Func _show_array()
_ArrayDisplay($mainarray)
EndFunc
Func _mainsocket_save()
IniWrite($ini,"SYSTEM","PROXYPORT",GUICtrlRead($input_proxyport))
IniWrite($ini,"SYSTEM","PROXYIP",GUICtrlRead($input_proxyip))
IniWrite($ini,"SYSTEM","PROXYPORTSSL",GUICtrlRead($input_proxyportssl))
_mainsocket_create()
EndFunc
Func _mainsocket_create()
TCPShutdown()
TCPStartup()
$IP = IniRead($ini,"SYSTEM","PROXYIP","127.0.0.1")
$PORT = IniRead($ini,"SYSTEM","PROXYPORT","8080")
$PORTSSL = IniRead($ini,"SYSTEM","PROXYPORTSSL","8043")
GUICtrlSetData($input_proxyip, $IP)
GUICtrlSetData($input_proxyport,$PORT)
GUICtrlSetData($input_proxyportssl,$PORTSSL)
$proxysocket = TCPListen($IP,$PORT)
If #error Then
_GUICtrlEdit_AppendText($DEBUG , "] Error HTTP Proxy couldn't bind socket on IP :" & $IP & " Port :" & $PORT & #CRLF)
Else
_GUICtrlEdit_AppendText($DEBUG , "] HTTP Proxy listening on IP :" & $IP & " Port :" & $PORT & #CRLF)
EndIf
$proxysocketssl = TCPListen($IP,$PORTSSL)
If #error Then
_GUICtrlEdit_AppendText($DEBUG , "] Error HTTPS Proxy couldn't bind socket on IP :" & $IP & " Port :" & $PORTSSL & #CRLF)
Else
_GUICtrlEdit_AppendText($DEBUG , "] HTTPS Proxy listening on IP :" & $IP & " Port :" & $PORTSSL & #CRLF)
EndIf
EndFunc
Func _Get_Address($text)
If IsBinary($text) Then
$text = BinaryToString($text)
EndIf
$serversock=StringSplit($text , #CRLF,1)
For $i=1 To $serversock[0]
If StringLeft($serversock[$i],6)="Host: " Then
Return StringTrimLeft($serversock[$i],6)
EndIf
Next
Return 0
EndFunc
Func _clientconnection_to_mainarray($sock,$port = 80,$type = "HTTP",$state = "")
For $i = 1 To UBound($mainarray) -1
If $mainarray[$i][1] = "" And $mainarray[$i][2] = "" Then
$mainarray[$i][1] = $sock
$mainarray[$i][0] = $port
$mainarray[$i][5] = TimerInit()
$mainarray[$i][7] = $state
$mainarray[$i][8] = $type
_save("] Added new client to mainarray , pos: " & $i & #CRLF)
If $i + 5 > UBound($mainarray) Then ReDim $mainarray[UBound($mainarray)+5][10]
Return
EndIf
Next
EndFunc
Func _mainarray_deleteclient($line)
TCPCloseSocket($mainarray[$line][1])
$mainarray[$line][0] = ""
$mainarray[$line][1] = ""
$mainarray[$line][3] = ""
$mainarray[$line][4] = ""
$mainarray[$line][5] = ""
$mainarray[$line][6] = ""
$mainarray[$line][7] = ""
$mainarray[$line][8] = ""
$mainarray[$line][9] = ""
If $mainarray[$line][2]<> "" Then
TCPCloseSocket($mainarray[$line][2])
$mainarray[$line][2] = ""
EndIf
EndFunc
Func _mainarray_hostkillclient($line)
_save("]" & $line &" Connection Closed by Host after " & Floor(TimerDiff($mainarray[$line][5])) & " ms" & #CRLF)
$mainarray[$line][2] = ""
$mainarray[$line][4] = ""
$mainarray[$line][5] = ""
If $mainarray[$line][1]<> "" Then
TCPCloseSocket($mainarray[$line][1])
_mainarray_deleteclient($line)
EndIf
EndFunc
Func _Send_Response($browsersock,$code,$data="")
If $data="" Then
$data=#CRLF & #CRLF
Else
$data=#CRLF & $data & #CRLF & #CRLF
EndIf
TCPSend($browsersock , "HTTP/1.0 " & $code & " Message" & $data)
EndFunc
Func _quit()
TCPShutdown()
Exit
EndFunc
Func _gui_show()
If $GUISHOW = 0 Then
Local $pw = InputBox("Enter Password","Enter Password","","*",150,130)
If Not #error Then
If $pw = "1234" Then
GUISetState(#SW_SHOW)
$GUISHOW = 1
Return
EndIf
EndIf
ElseIf $GUISHOW = 1 Then
GUISetState(#SW_HIDE)
$GUISHOW = 0
Return
EndIf
EndFunc
Func _save($text)
If GUICtrlRead($checkbox_debug_save) = 1 Then
$file = FileOpen(#ScriptDir & "\log\" & #Year & #MON & #MDAY & "-log.txt",9)
FileWrite ($file,$text)
FileClose($file)
Endif
If GUICtrlRead($checkbox_debug) = 1 Then _GUICtrlEdit_AppendText($DEBUG , $text)
Endfunc
Func _SocketToIP($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not #error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
If Not #error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
Return $aRet
EndFunc ;==>SocketToIP
Func _debug_binary()
Local $aSel = _GUICtrlEdit_GetSel($DEBUG)
Local $text = StringMid(GUICtrlRead($DEBUG),$aSel[0]+1,$aSel[1]-$aSel[0])
If $text <> "" Then
Else
$text = InputBox("Binary to String","Enter Binary Data")
EndIf
If StringLower(StringLeft($text,2)) <> "0x" Then $text = "0x" & $text
$tempfile = FileOpen(#ScriptDir & "\temp.txt",2)
FileWrite($tempfile,BinaryToString($text))
FileClose($tempfile)
ShellExecute(#ScriptDir & "\temp.txt")
EndFunc
Func _debug_clear()
GUICtrlSetData($DEBUG,"")
EndFunc
Func _request_modify($req,$host)
Local $encoding = "Accept-Encoding: identity" ;deflate, gzip, compress,
Local $reqsplit
Local $modified_method = 0 , $modified_connection = 0 , $modified_encoding = 0
If $req <> "" And Not IsBinary($req) Then
$reqsplit = StringSplit($req,#CRLF,1)
If IsArray($reqsplit) Then
For $i = 1 to $reqsplit[0] - 1
_save("] modifying :" & $i & " " & $reqsplit[$i])
If StringLeft($reqsplit[$i],3) = "GET" Or StringLeft($reqsplit[$i],4) = "POST" Or StringLeft($reqsplit[$i],7) = "CONNECT" And $modified_method = 0 Then
$reqsplit[$i] = StringReplace($reqsplit[$i],$host,"")
$reqsplit[$i] = StringReplace($reqsplit[$i],"http://","")
$reqsplit[$i] = StringReplace($reqsplit[$i],":443","")
$modified_method = 1
EndIf
If StringInStr(Stringlower($reqsplit[$i]),"proxy-connection: keep-alive") And $modified_connection = 0 Then
$reqsplit[$i] = "Connection: keep-alive"
$modified_connection = 1
EndIf
If StringInStr(Stringlower($reqsplit[$i]),"accept-encoding") And $modified_encoding = 0 Then
$reqsplit[$i] = $encoding
$modified_encoding = 1
EndIf
_save(" -> to :" & $reqsplit[$i] & #CRLF)
Next
$req = _ArrayToString($reqsplit, #CRLF , 1 , Ubound($reqsplit)-1)
EndIf
If GUICtrlRead($checkbox_debug_content) = 1 Then
_save("] Request modified to:" & #CRLF)
_save($req &#CRLF)
EndIf
EndIf
Return $req
EndFunc
What you need is a WinPcap Autoit3 UDF
Look at the Example(3): Saving http traffic to a pcap file for 10s...
Related
How to create a Function to check the supplied URL against a Whitelist of approved URLs Or Domains before redirecting
I am new in the Classic ASP, and I want to ask if there's anyone who has experienced and knew of how to create a validation Function in Classic ASP to check the supplied URL against a Whitelist of approved URLs or Domains before redirecting. Below is the sample codes If not GetNameChk then chk = AssignCustAddr(id) If UCase(Left(chk,5)) = "ERROR" then ReportAnWarning chk, RelConn End if gostring = "proposer.asp" Else gostring = "CustGet.asp?AddrId=" & encrypt1(trim(request.form("AddrId" & id))) & "&CustId=" & encrypt1(trim(request.form("CustId" & id))) & "&id=" & encrypt1(id) & "&SurName" & id & "=" gostring = gostring & encrypt1(Replace(trim(request.form("SurName" & id))," ","+")) gostring = gostring & "&GivenName" & id & "=" gostring = gostring & encrypt1(Replace(trim(request.form("GivenName" & id))," ","+")) gostring = gostring & "&NRIC" & id & "=" gostring = gostring & encrypt1(Replace(trim(request.form("nric" & id))," ","+")) End If response.redirect gostring The gostring URL or Domain is need to Validate and Whitelist. Is there anyone knew about this? Thank you in advance! I have tried a sort of validation but it's only sanitized(removing the untrusted characters) the value of the URL or Domain please see below Function CRLF(strChar) If strChar ="" Or IsNull(strChar) Then CRLF ="":Exit Function Dim strBadChar, arrBadChar, tempChar, I strBadChar = "--,+,\,\r,*,%,^,#,!,#,$,(,),[,],{,},;,<,>,~,`,\n," & Chr(34) & "," & Chr(0) & "" arrBadChar = Split(strBadChar, ",") tempChar = strChar For I = 0 To UBound(arrBadChar) tempChar = Replace(tempChar, arrBadChar(I), "") Next tempChar = Replace(tempChar, "##", "#") CRLF = tempChar End Function So, what I am expecting is to check the supplied URL/Domain (gostring) and compare against a whitelist of approved URLs or Domains before redirecting.
How to query a user name by a email address in Jira Rest API
I want to create issues in Jira based on Outlook emails received using VBA. However, when setting the assignee/reporter via the REST API it appears that users can only be specified by name. When trying to specify a user by email address I get this error: assignee: expected Object containing a 'name' property Here is the Json code that is not working: JSON(0) = "{" JSON(1) = " ""fields"": {" JSON(2) = " ""project"": {" JSON(3) = " ""id"": 23354" JSON(4) = " }," JSON(5) = " ""summary"": ""#customSubject""," JSON(6) = " ""description"": ""#customBody""," JSON(7) = " ""issuetype"": {" JSON(8) = " ""name"": ""#issueName""" JSON(9) = " }," JSON(10) = " ""assignee"": {" JSON(11) = " ""emailAddress"": ""#assignEmail""" JSON(12) = " }," JSON(13) = " ""labels"": [" JSON(14) = " ""#jiraLabel""" JSON(15) = " ]" JSON(16) = " }" JSON(17) = "}" JSON = getJSON(CustomReplace(OutlookMail.Subject), CustomReplace(OutlookMail.Body), "Ticket", CustomReplace(OutlookMail.SenderName), "") Do you have any idea how can I make this work with email address instead of name? This is working: JSON(0) = "{" JSON(1) = " ""fields"": {" JSON(2) = " ""project"": {" JSON(3) = " ""id"": 23354" JSON(4) = " }," JSON(5) = " ""summary"": ""#customSubject""," JSON(6) = " ""description"": ""#customBody""," JSON(7) = " ""issuetype"": {" JSON(8) = " ""name"": ""#issueName""" JSON(9) = " }," JSON(10) = " ""assignee"": {" JSON(11) = " ""name"": ""#assignAlias""" JSON(12) = " }," JSON(13) = " ""labels"": [" JSON(14) = " ""#jiraLabel""" JSON(15) = " ]" JSON(16) = " }" JSON(17) = "}" JSON = getJSON(CustomReplace(OutlookMail.Subject), CustomReplace(OutlookMail.Body), "Ticket", "myusername", "")
The ability to use usernames / email addresses for assignees / reporters for issues was deprecated years and years ago and replaced with using accountIDs. If you don't know a person's accountID, you have to search for it based on their username / email address.
autoit modi.document error Variable must be of type "Object"
#include <Constants.au3> #include <ScreenCapture.au3> #Include <Misc.au3> #include <Array.au3> #include <GDIPlus.au3> $image = #MyDocumentsDir & "\aaa_teste.jpg" ConsoleWrite(OCR($image)) Func OCR($Image) Local $miDoc, $Doc Local $str Local $oWord Local $sArray[500] Local $as_Text = "" $miDoc = ObjCreate("MODI.Document") ConsoleWrite("ObjCreate - The error value is: " & #error & #CRLF) $miDoc.Create(#TempDir & '\OCR_ImageResize.jpg') ConsoleWrite("Create - The error value is: " & #error & #CRLF) $miDoc.Ocr(9, False, False) ConsoleWrite("Ocr - The error value is: " & #error & #CRLF) If $Error = False Then $i = 0 For $oWord in $miDoc.Images(0).Layout.Words $str = $str & $oWord.text & #CrLf ConsoleWrite($oWord.text & #CRLF) $sArray [$i] = $oWord.text $i += 1 Next $as_Text = _ArrayToString($sArray," ",0) $as_Text = StringReplace($as_Text, " ", "", 0) ElseIf $Error = True Then $Error = False EndIf $miDoc.Close(False) Return $as_Text EndFunc I`m trying read a text from a screencapture The error is: "C:\Users\jose.barbosaneto\Desktop\TESTE.au3" (23) : ==> Variable must be of type "Object".: $miDoc.Create(#TempDir & '\OCR_ImageResize.jpg') $miDoc^ ERROR Please help me
The only downside of MODI library is that it relies 100 % on MS Office. So if you don't have the proper version installed it will not find the needed COM object. Check the Office version you have installed and see if MODI is in there. Go in Uninstall Programs and click on Change/Repair on the MS Office version you have. From there you can check if MODI documents are installed. Edit: Install MDI to TIFF Files Converter and SharePoint Designer from this link: https://support.microsoft.com/en-us/kb/982760 After installing them go to > Uninstall a Program>MS Office SharePoint Designer 2007> Right click on it and select Change>select Add or Remove Features. From there in the menu you will find the option Office Tools. Expand it. Then click on the small arrows on MODI(Microsoft Office Document Imaging) and select "Run all from my Computer". And you are ready to go! Edit2: Here is a tested and working example. #include <GUIConstants.au3> #include <Array.au3> Dim $miDoc, $Doc Dim $str Dim $oWord Dim $sArray[500] Const $miLANG_CZECH = 5 Const $miLANG_DANISH = 6 Const $miLANG_DUTCH = 19 Const $miLANG_ENGLISH = 9 Const $miLANG_FINNISH = 11 Const $miLANG_FRENCH = 12 Const $miLANG_GERMAN = 7 Const $miLANG_GREEK = 8 Const $miLANG_HUNGARIAN = 14 Const $miLANG_ITALIAN = 16 Const $miLANG_JAPANESE = 17 Const $miLANG_KOREAN = 18 Const $miLANG_NORWEGIAN = 20 Const $miLANG_POLISH = 21 Const $miLANG_PORTUGUESE = 22 Const $miLANG_RUSSIAN = 25 Const $miLANG_SPANISH = 10 Const $miLANG_SWEDISH = 29 Const $miLANG_TURKISH = 31 Const $miLANG_SYSDEFAULT = 2048 Const $miLANG_CHINESE_SIMPLIFIED = 2052 Const $miLANG_CHINESE_TRADITIONAL = 1028 Local $ImagePath = #DesktopDir & "\Untitled.png" ; you can choose .tif format if you also want ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $miDoc = ObjCreate("MODI.Document") $miDocView = ObjCreate("MiDocViewer.MiDocView") $Viewer = GUICreate("Embedded MODI Viewer", 640, 580, (#DesktopWidth - 640) / 2, (#DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) ;Creates an ActiveX Control in the GUI. $GUIActiveX = GUICtrlCreateObj($miDocView, -1, -1, 640, 580) GUICtrlSetResizing($Viewer, $GUI_DOCKAUTO) $miDoc.Create($ImagePath) $miDoc.Ocr($miLANG_ENGLISH, True, False) ; Show GUI GUISetState() $miDocView.Document = $miDoc $miDocView.SetScale(0.75, 0.75) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd $i = 0 For $oWord In $miDoc.Images(0).Layout.Words $str = $str & $oWord.text & #CRLF ConsoleWrite($oWord.text & #CRLF) $sArray[$i] = $oWord.text $i += 1 Next _ArrayDisplay($sArray, "OCR Result") ;MsgBox(0,"",$miDocView.FileName) ;------------------------------ This is a COM Error handler -------------------------------- Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "COM Error Test", "We intercepted a COM Error !" & #CRLF & #CRLF & _ "err.description is: " & #TAB & $oMyError.description & #CRLF & _ "err.windescription:" & #TAB & $oMyError.windescription & #CRLF & _ "err.number is: " & #TAB & $HexNumber & #CRLF & _ "err.lastdllerror is: " & #TAB & $oMyError.lastdllerror & #CRLF & _ "err.scriptline is: " & #TAB & $oMyError.scriptline & #CRLF & _ "err.source is: " & #TAB & $oMyError.source & #CRLF & _ "err.helpfile is: " & #TAB & $oMyError.helpfile & #CRLF & _ "err.helpcontext is: " & #TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns EndFunc ;==>MyErrFunc
Disconnecting the BE database to do compact
I'm sure I'm just being blind here. I need to compact my BE data file, but the code fails because the initial file copy to backup the data file gives a permission denied. I've seen several examples of compacting the MS Access Backend, but they all prediate their code with the statament 'Make sure all connections are disconnected". In my case both files are local. There are no other users. All forms have been closed. The user is not a DBadmin type so a single button on the front end app to compact both would be ideal. Here is the compact code... Err_Pos = 1 If IsFormLoaded(frm_nm) Then DoCmd.Close acForm, frm_nm End If Fl_BE_Cnt_Str = Cnnt_str BE_Full_Nm_Str = Split(Split(Fl_BE_Cnt_Str, "Database=")(1), ";")(0) s_Pos = InStrRev(Fl_BE_Cnt_Str, "\") BE_DB_Name_Str = Right(Fl_BE_Cnt_Str, Len(Fl_BE_Cnt_Str) - s_Pos) s_Pos = InStrRev(BE_Full_Nm_Str, "\") BE_Path_Str = Left(BE_Full_Nm_Str, s_Pos) Tmp_BE_Hold_FNM_Str = BE_Path_Str & "Tmp_BE.accdb" Err_Pos = 5 're-map current table links to empty DB with same table Structure For Each T_Def In CurrentDb.TableDefs If InStr(T_Def.Name, "MSys") = 0 Then T_Def.Connect = ";Database=" & BE_Path_Str & "MPD_BEStruct.accdb" T_Def.RefreshLink End If Next T_Def Err_Pos = 10 'Backup s_Pos = InStrRev(BE_DB_Name_Str, ".") BkUp_FNMN_Str = Left(BE_DB_Name_Str, s_Pos) & ".BAK" Err_Pos = 15 ' remove possible left over backup Kill BE_Path_Str & BkUp_FNMN_Str On Error GoTo Err_BE_Compact Err_Pos = 20 FileCopy BE_Full_Nm_Str, BE_Path_Str & BkUp_FNMN_Str 'Compact DBEngine.CompactDatabase BE_Full_Nm_Str, Tmp_BE_Hold_FNM_Str Err_Pos = 25 'Delete Uncompacted Version Kill BE_Full_Nm_Str Err_Pos = 30 'Rename Compacted Version Name Tmp_BE_Hold_FNM_Str As BE_Full_Nm_Str Err_Pos = 35 'reconnect to the new compacted Back End For Each T_Def In CurrentDb.TableDefs If InStr(T_Def.Name, "MSys") = 0 Then T_Def.Connect = ";Database=" & BE_Path_Str & BE_DB_Name_Str T_Def.RefreshLink End If Next T_Def ' let backup stay around if compact has corrupted DB 'Kill BE_Path_Str & "MPD_BEStruct.accdb" Err_Pos = 40 SendKeys "%(FMC)" ' Exit_BE_Compact: Exit Function Err_BE_Compact: e_Cnt = e_Cnt + 1 If e_Cnt < 1000 Then Select Case Err.Number Case 3204 If Err_Pos = 5 Then Kill BE_Path_Str & "MPD_BEStruct.accdb" End If Resume Case Else Dim Why_Str As String Select Case Err_Pos Case 5 Why_Str = "record Source Disconnect Error" Case 10 Why_Str = "record Source Disconnect Error" Case 15 Why_Str = "Previous Backup won't delete" Case 20 Why_Str = "Tmp Back up of BackEnd datafile failed" Case 25 Why_Str = "Compac of BackEnd failed" Case 30 Why_Str = "Rename of compacted BackEnd failed" Case 35 Why_Str = "Reconnect to BackEnd failed" End Select If ErrChoice = vbYesNoCancel Then ErrMsg = Err.Description & ": " & Str(Err.Number) & vbNewLine & Why_Str & vbNewLine & "Press 'Yes' to resume next;" & vbCrLf & _ "'No' to Exit Procedure." & vbCrLf & "or 'Cancel' to break into code" Else ErrMsg = Err.Description & ": " & Str(Err.Number) & vbNewLine & Why_Str & vbNewLine & "Press 'Yes' to resume next;" & vbCrLf & _ "'No' to Exit Procedure." End If End Select Else Why_Str = "Too Many Errors" ErrMsg = Err.Description & ": " & Str(Err.Number) & vbNewLine & Why_Str & vbNewLine & _ "Press 'OK' to Exit Procedure." ErrAns = MsgBox(ErrMsg, _ vbCritical + vbQuestion + vbOKOnly, "Function: BE_Compact") Resume Exit_BE_Compact End If ErrAns = MsgBox(ErrMsg, _ vbCritical + vbQuestion + ErrChoice, "Function: BE_Compact") If ErrAns = vbYes Then Resume Next ElseIf ErrAns = vbCancel Then On Error GoTo 0 Resume Else Resume Exit_BE_Compact End If
You've got a couple splits to get the path. I would doublecheck that the path is correct as I've copied many Access databases programmatically with FileCopy.
Convert CSV to LDIF for import into ldap?
I have a MSSQL database with 13k users in a table with headers like username, password, fname, lname, etc. I would love to be able to turn this data into a proper ldap server. Currently I've done the following: Create a job on the mssql server to export that table hourly in a csv. The query pulls username, password, fname, lastname,and memberid. ftp this data hourly to my linux ldap server. Can someone recommend a method on how to turn this csv into ldif so I can run ldapmodify and put in all these entries into my ldap server? I'm assuming I can write a parser, but would love to know if there's already a product that can do csv to ldif conversion in this manner and if this plan makes any sense or if there's a better way to do this? Thanks.
Just in case someone is still looking for something like that, I made an autoit script to convert a given CSV file into LDIF: ;########################################################################################### ;##### Load requirements #include <File.au3> ;########################################################################################### ;#### Start the app LDIF_Converter() ;########################################################################################### ;#### App function Func LDIF_Converter() TrayTip("CSV2LDIF Converter","Konvertierung gestartet...",2000,1) Local $file = "import_ADS.ldif", $contacts = 0, $sFilePath = "3CXImport.csv" ; Remote old file FileDelete($file); ; Write Header FileWrite($file,"#Base structure for each person"); Filewrite($file,#crlf) FileWrite($file,"dn: ou=Telefonbuch,dc=example,dc=com"); Filewrite($file,#crlf) FileWrite($file,"ou: Telefonbuch"); Filewrite($file,#crlf) FileWrite($file,"objectClass: organizationalUnit"); Filewrite($file,#crlf) FileWrite($file,"objectClass: top"); Filewrite($file,#crlf) Filewrite($file,#crlf) ; Read out CSV File _FileReadToArray($sFilePath, $contacts, $FRTA_NOCOUNT, ";") ; Write to File for each contact For $i = 0 To UBound ($contacts) - 1 ; Clear contact cache $cache = "" ; Write object ID & comman attributes $cache = $cache & "dn: uid="&$i+1&",ou=Telefonbuch,dc=example,dc=com" & #CRLF $cache = $cache & "objectClass: inetOrgPerson" & #CRLF $cache = $cache & "objectClass: organizationalPerson" & #CRLF $cache = $cache & "objectClass: person" & #CRLF $cache = $cache & "objectClass: top" & #CRLF ; Check if company or person and set the corresponding CN if $contacts[$i][1] == "" Then $cn = $contacts[$i][0] Else $cn = $contacts[$i][1] & " " & $contacts[$i][2] EndIf ; Write common name $cache = $cache & "cn: "&$cn & #CRLF if $contacts[$i][1] == "" Then $sn = $contacts[$i][0] Else $sn = $contacts[$i][1] & " " & $contacts[$i][2] EndIf ; Write lastname/company $cache = $cache & "sn: "&$sn & #CRLF ; Write mobile number $mobile = StringRegExpReplace($contacts[$i][5],'[a-zA-Z;\\/:.,*?\"<>|& ]',"") if $mobile <> "" And $mobile <> " " Then $cache = $cache & "mobile: "& $mobile & #CRLF EndIf ; Write organisation if $contacts[$i][0] <> "" Then $cache = $cache & "o: "&$contacts[$i][0] & #CRLF EndIf ; Write telephone number $phone = StringRegExpReplace($contacts[$i][3],'[a-zA-Z;\\/:.,*?\"<>|& ]',"") if $phone <> "" And $phone <> " " Then $cache = $cache & "telephoneNumber: "& $phone & #CRLF EndIf ; Write fax number $fax = StringRegExpReplace($contacts[$i][4],'[a-zA-Z;\\/:.,*?\"<>|& ]',"") if $fax <> "" And $fax <> " " Then $cache = $cache & "facsimileTelephoneNumber: "& $fax & #CRLF EndIf ; Write email if $contacts[$i][6] <> "" Then $cache = $cache & "mail: "&$contacts[$i][6] & #CRLF EndIf ; Seperator for contacts $cache = $cache & #CRLF ; Write all in one file access FileWrite($file,$cache) Next TrayTip("CSV2LDIF Converter","Konvertiertierung abgeschlossen ",2000) sleep(2000) EndFunc
A simple Google search revealed several CSV to LDIF converters. For example scv2ldif2.pl. It is in Perl, but you can find at least several Windows implementation of Perl (for example Strawberry Perl.