
trainer
Members-
Posts
12 -
Joined
-
Last visited
trainer's Achievements

Seeker (1/7)
0
Reputation
-
UDF to support SFTP protocol using PSFTP
trainer replied to Lupo73's topic in AutoIt Example Scripts
Hi Lupo.. maybe you should add the red marked code below to your functions, because if someone (like me) has installed putty and uses a standard session, connecting to any server will fail, because the standard session is being loaded by default and the desired StdOut "psftp>" never appears. This is the solution to the problem kazki has described in his post. Cheers trainer Func _SFTP_Open($sPath = 'psftp.exe') Local $hSession = Run($sPath & " -load null", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) [...] Func _SFTP_Connect($hSession, $sServerName, $sUsername = "", $sPassword = "", $iServerPort = 0) If ProcessExists($hSession) = 0 Then Return SetError(1, 0, 0) EndIf If $iServerPort = 0 Then $iServerPort = "" EndIf Local $sLine, $sStringSplit StdinWrite($hSession, 'open ' & $sServerName & ' ' & $iServerPort & @CRLF) $wait_for_key_saving = 0 $save_key_if_not_saved = True While 1 ;If after 5 seconds no psftp>-prompt appears, putty is probably waiting for the answer whether the (new) ssh-key should be saved in the registry (this appears every time, if the key is not being saved) --> answer the question with 'y' (once). $wait_for_key_saving += 1 If $wait_for_key_saving >= 500 And $save_key_if_not_saved Then StdinWrite($hSession, 'y' & @CRLF) $save_key_if_not_saved = False EndIf $sLine = StdoutRead($hSession) [...] -
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
The fate of the coders. I guess I spent thousands of hours searching after forgotten semicolons in my php scripts... trainer -
No ideas at all? trainer
-
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
Hi taurus, I'd like to help you - if i could. But I don't succeed in decrypting either. This is strange, because like "SkinnyWhiteGuy" wrote (): ; ------------------------------------------------------- ; Function: rc4 ; Purpose: An encryption/decryption RC4 implementation in AutoIt ; Syntax: rc4($key, $value) ; Where: $key = encrypt/decrypt key ; $value = value to be encrypted/decrypted ; On success returns encrypted/decrypted version of $value ; Author: SkinnyWhiteGuy on the AutoIt forums at www.autoitscript.com/forum ; Notes: The same function encrypts and decrypts $value. ; ------------------------------------------------------- And in php it works exactly this way ... Does anyone know the solution? trainer -
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
Hi JohnOne, no problem - but I am sure that it is the way I explained... Take a look at the first few lines: http://php.net/manual/en/language.variables.scope.php trainer -
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
Hi taurus, if you don't want to disable the warnings, you have to take care that every variable being used is being declared before the first usage, like $string = ""; or $my_array = array(); In this case you have to do this inside of the function (because of the local "area of valitity" - or whatever this is called in English ): function hex_str($hex){ $string = ""; for ($i=0; $i < strlen($hex)-1; $i+=2) $string .= chr(hexdec($hex[$i].$hex[$i+1])); return $string; } trainer -
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
Hi taurus, this is a warning and not an error. It depends on your php settings whether it is shown or not. It occurs because $string hasn't been defined yet. You can safely turn it off by adding the following to the top of the script: // PHP-Parser-Debugging-Level ini_set ('display_errors', TRUE); // On, Off ini_set ('error_reporting',E_ALL ^ E_NOTICE); // Debug-Level The "^ E_NOTICE" means: show the errors but not the warnings trainer -
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
Hello taurus, I should definitely read the whole topic before posting ... Anyway - good luck with your project. And here's a little improvement/correction to the posted Autoit-rc4-function: Return StringTrimLeft(StringLower($output),2) (otherwise the return result would be 0xE97A0F259C instead of e97a0f259c) Cheers trainer -
Hi there, maybe someone can help me with this: how do I upload a file via WinHTTP to a .htaccess-protected php-script via SSL? Is this possible? What I already have is: - Posting SSL encrypted ASCII data to a .htaccess protected script (Script 1) - Sending (NOT SSL encrypted) files to a NOT .htaccess protected script (Script 2) Any Ideas? Thanks for helping, trainer Script 1: $http = ObjCreate("WinHttp.WinHttpRequest.5.1") $http.Open("POST", "https://www.domain.de/test.php", false) $http.SetRequestHeader ("Content-Type", "application/x-www-form-urlencoded") $http.SetCredentials("user", "passwort", 0) $http.Send("content=123") ConsoleWrite($http.ResponseText & @CR) Script2: #include-once #include "Array.au3" #include "WinHTTP.au3" Dim $file[1][2] = [["file_upload","export.zip"]] $test = post_multipart("http://www.domain.de/test.php", "", 0, $file) ConsoleWrite($test[0] & @CR) ConsoleWrite($test[1] & @CR) ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Global $MIMETypes[1][2] = [["zip", "application/zip"]] _ArraySort($MIMETypes, 0, 0, 0, 2) ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func post_multipart($host, $selector, $fields, $files) Local $Return = encode_multipart_formdata($fields, $files) Local $content_type = 'Content-Type: ' & $Return[0] & @CRLF $body = $Return[1] Local $URL = _WinHttpCrackUrl($host) Local $hSession = _WinHttpOpen() Local $hConnection = _WinHTTPConnect($hSession,$URL[2],$URL[3]) Local $hRequest = _WinHttpOpenRequest($hConnection,"POST",$URL[6]&$URL[7],"HTTP/1.1","http://"&$URL[2]) _WinHttpSendRequest($hRequest,$content_type,$WINHTTP_NO_REQUEST_DATA,StringLen($Return[1])) _WinHTTPWriteDataBin($hRequest,StringToBinary($Return[1])) _WinHttpReceiveResponse($hRequest) Local $Return[2] If _WinHttpQueryDataAvailable($hRequest) Then Local $temp While 1 $temp = _WinHttpReadData($hRequest) If $temp = "" Then ExitLoop $Return[1] &=$temp WEnd $temp ="" EndIf $Return[0] = _WinHttpQueryHeaders($hRequest) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnection) _WinHttpCloseHandle($hSession) Return $Return EndFunc ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func _WinHttpWriteDataBin($hRequest, $binary) Local $lpBinary Local $iNumberOfBytesToWrite If IsDllStruct($binary) Then $lpBinary = DllStructGetPtr($binary) $iNumberOfBytesToWrite = DllStructGetSize($binary) Else $iNumberOfBytesToWrite = BinaryLen($binary) Local $sBinary = DllStructCreate("byte[" & $iNumberOfBytesToWrite & "]") DllStructSetData($sBinary, 1, $binary) $lpBinary = DllStructGetPtr($sBinary) EndIf Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpWriteData", _ "hwnd", $hRequest, _ "ptr", $lpBinary, _ "dword", $iNumberOfBytesToWrite, _ "dword*", 0) If @error Or Not $a_iCall[0] Then Return SetError(1, 0, 0) EndIf Return SetError(0, $a_iCall[4], 1) EndFunc ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func encode_multipart_formdata($fields, $files) Local Const $BOUNDARY = getBoundary() $L = "" For $i = 0 To UBound($fields) - 1 $L &= ('--' & $BOUNDARY) & @CRLF $L &= ('Content-Disposition: form-data; name="' & $fields[$i][0] & '"') & @CRLF $L &= @CRLF $L &= $fields[$i][1] & @CRLF Next For $i = 0 To UBound($files) - 1 $L &= ('--' & $BOUNDARY) & @CRLF $L &= ('Content-Disposition: form-data; name="' & $files[$i][0] & '"; filename="' & $files[$i][1] & '"') & @CRLF $content_type = get_content_type($files[$i][1]) $L &= ('Content-Type: ' & $content_type) & @CRLF $L &= @CRLF $L &= FileRead($files[$i][1]) & @CRLF Next $L &= ('--' & $BOUNDARY & '--') & @CRLF $L &= @CRLF $content_type = 'multipart/form-data; boundary="' & $BOUNDARY & '"' Local $Return[2] = [$content_type, $L] Return $Return EndFunc ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func get_content_type($path) Local $szExt = StringLower(StringRegExpReplace( $path ,".*(?:\.([^.\\/]*))?\Z","$1")) If $szExt = "" Then Return 'application/octet-stream' Local $mimeid = _ArrayBinarySearch2D($MIMETypes, $szExt) If $mimeid = -1 Then Return SetError(1, 0, 'application/octet-stream') Return $MIMETypes[$mimeid][1] EndFunc ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func _ArrayBinarySearch2D(Const ByRef $avArray, $vValue, $iStart = 0, $Column = 0, $iEnd = 0) If Not IsArray($avArray) Then Return SetError(1, 0, -1) Local $iUBound = UBound($avArray) - 1 ; Bounds checking If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound If $iStart < 0 Then $iStart = 0 If $iStart > $iEnd Then Return SetError(4, 0, -1) Local $iMid = Int(($iEnd + $iStart) / 2) If $avArray[$iStart][$Column] > $vValue Or $avArray[$iEnd][$Column] < $vValue Then Return SetError(2, 0, -1) ; Search While $iStart <= $iMid And $vValue <> $avArray[$iMid][$Column] If $vValue < $avArray[$iMid][$Column] Then $iEnd = $iMid - 1 Else $iStart = $iMid + 1 EndIf $iMid = Int(($iEnd + $iStart) / 2) WEnd ; Entry not found If $iStart > $iEnd Then Return SetError(3, 0, -1) Return $iMid EndFunc ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func getBoundary() return Stringleft(_TimeGetStamp()*random(10,256,1), 16) EndFunc ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func _TimeGetStamp() Local $av_Time $av_Time = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0) If @error Then SetError(99) Return False EndIf Return $av_Time[0] EndFunc ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
Hi, ok - after reading again: this ist NOT what you asked for . But maybe someone can take advantage of it. trainer -
Convert _StringEncrypt to PHP
trainer replied to taurus905's topic in AutoIt General Help and Support
Hi, maybe this could help: Autoit-Code: $enc_key = "streng_geheim" $string = "Hello" MsgBox(0,"",rc4($enc_key, $string)) ;--------------------------------------------- Func rc4($key, $value) Local $S[256], $i, $j, $c, $t, $x, $y, $output Local $keyLength = BinaryLen($key), $valLength = BinaryLen($value) For $i = 0 To 255 $S[$i] = $i Next For $i = 0 To 255 $j = Mod($j + $S[$i] + Dec(StringTrimLeft(BinaryMid($key, Mod($i, $keyLength)+1, 1),2)),256) $t = $S[$i] $S[$i] = $S[$j] $S[$j] = $t Next For $i = 1 To $valLength $x = Mod($x+1,256) $y = Mod($S[$x]+$y,256) $t = $S[$x] $S[$x] = $S[$y] $S[$y] = $t $j = Mod($S[$x]+$S[$y],256) $c = BitXOR(Dec(StringTrimLeft(BinaryMid($value, $i, 1),2)), $S[$j]) $output = Binary($output) & Binary('0x' & Hex($c,2)) Next Return $output EndFunc Result: e97a0f259c PHP-Code $enc_key = "streng_geheim"; $string = "e97a0f259c"; $string = hex_str($string); $string = rc4Decrypt($enc_key, $string); echo $string; #--------------------------------------------------------------- function str_hex($string){ for ($i=0; $i < strlen($string); $i++) $hex .= sprintf("%02x",ord($string[$i])); return $hex; } #--------------------------------------------------------------- function hex_str($hex){ for ($i=0; $i < strlen($hex)-1; $i+=2) $string .= chr(hexdec($hex[$i].$hex[$i+1])); return $string; } #--------------------------------------------------------------- function rc4Encrypt($key, $pt) { $s = array(); for ($i=0; $i<256; $i++) { $s[$i] = $i; } $j = 0; $x; for ($i=0; $i<256; $i++) { $j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256; $x = $s[$i]; $s[$i] = $s[$j]; $s[$j] = $x; } $i = 0; $j = 0; $ct = ''; $y; for ($y=0; $y<strlen($pt); $y++) { $i = ($i + 1) % 256; $j = ($j + $s[$i]) % 256; $x = $s[$i]; $s[$i] = $s[$j]; $s[$j] = $x; $ct .= $pt[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]); } return $ct; } #--------------------------------------------------------------- function rc4Decrypt($key, $ct){ return rc4Encrypt($key, $ct); } Result: Hello -
Hi there, maybe someone can help? I'm trying to convert a string into the UTF16 format. In php I can use a function like this: function Str2Utf16($string) { $string = iconv("ISO-8859-1", "UTF-16", $string); return substr($string, 2, strlen($string)-2); In VBA there seems to be no need to convert the string - but AutoIt (even though I'm using v. 3.3.0.0) seems to handle the string as UTF8, just like php. Why do I need this? I'm trying to send a http-Request to the AVM Fritzbox 7270 in order to log in to the webinterface. Therefore I need to construct a string in the UTF-16-LE format (without BOM and final zero-bytes). Details: http://www.avm.de/de/Extern/Technical_Note_Session_ID.pdf I already tried something like this: (found within another post in this forum: http://www.autoitscript.com/forum/index.php?showtopic=92061&st=0&p=662436&hl=utf16&fromsearch=1&), but this doesen't work for me >_< ; string conversion: UTF-8 --> UTF-16 Func _Utf8ToUtf16($Utf8String) Local $struct = _WinAPI_MultiByteToWideChar($Utf8String, 65001) Return($struct) EndFunc Thanx for any replies an help trainer