K, here's a version, which allows uploads directly to an existing Ahk.net account by using its webinterface and httpQuery.
; FSB für Autohotkey v0.1
; based on BoBo's FSB Script
; (deDE) http://de.autohotkey.com/forum/viewtopic.php?t=3537
; (enUS) http://www.autohotkey.com/forum/viewtopic.php?t=35580
; AutoHotkey.net won't work when no cookies are allowed - so we have to
; do some lil trick to get this working.
; PHP usually allows to receive cookie Informations being sent with the
; GET request. This is what we will do here...
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
MyAHKNetUserName := "My User at AutoHotkey.Net"
MyAHKNetPassword := "My Password at AutoHotkey.Net"
MyAHKNetUploadDir := "/screenshots/" ; Do not miss the leading and trailing slash
MyAHKNetPath := "https://ahknet.autohotkey.com/~" MyAHKNetUserName "/" SubStr(MyAHKNetUploadDir,2,-1)
imgType := "png"
If (!pToken := Gdip_Startup()) {
MsgBox, 48, gdiplus error!, % "Gdiplus failed to start. "
. "Please ensure you have gdiplus on your system"
ExitApp
}
OnExit, Exit
Return
AHKNET_Login:
; Neccessary settings to get the SESSION cookie sent via HttpHeaders
Tooltip("Get Cookie from AutoHotkey.net",2)
GoSub, EpicCycleOn
httpQueryOps := "storeHeader"
httpQueryDwFlags := (INTERNET_FLAG_NO_AUTO_REDIRECT:= 0x00200000)
; Send Request to get proper cookieData in Header
l := httpQuery(data:="","https://ahknet.autohotkey.com/xfm/?a=login")
VarSetCapacity(data,-1)
EpicCycle := 0
; Extract the SESSION Cookie
Loop,Parse,HttpQueryHeader,`n
if (RegExMatch(A_LoopField,"^Set-Cookie"))
Cookie := RegExReplace(A_LoopField,"Set-Cookie: |;.*")
; Login Procedure - so the server knows who we are
GoSub, EpicCycleOn
Tooltip("AutoHotkey.net Login",2)
httpQueryDwFlags := "" ; Not Neccessary anymore
PostData := "user=" uriEncode(MyAHKNetUserName) "&pass=" uriEncode(MyAHKNetPassword) "&cmd=Log+in"
l := httpQuery(data:="","https://ahknet.autohotkey.com/xfm/?a=login&" Cookie, PostData)
VarSetCapacity(data,-1)
EpicCycle := 0
; This was the magic request that logged us in.
; **************************************************************************************
; Some more testing will be neccessary here to get this properly working. Especially
; when Log in failed for some reasons.
; **************************************************************************************
; This is supposed to be the upload page.
GoSub, EpicCycleOn
Tooltip("Accessing AutoHotkey.net upload page",2)
l := httpQuery(data:="","https://ahknet.autohotkey.com/xfm/?a=create&d=&" Cookie)
VarSetCapacity(data,-1)
EpicCycle := 0
Return
AHKNET_Upload:
; Image 1
FileGetSize,size1,%FileName%
SplitPath,FileName,OFN1
FileRead,img1,%FileName%
VarSetCapacity(placeholder1,size1,32)
; Image 2
FileGetSize,size2,%FileNameThumb%
SplitPath,FileNameThumb,OFN2
FileRead,img2,%FileNameThumb%
VarSetCapacity(placeholder2,size2,32)
; Create Boundary
boundary := makeProperBoundary()
; Generate DummyPost
postPart_1 := "--" boundary "`n"
. "Content-Disposition: form-data; name=""upload_dir""`n"
. "`n"
. MyAHKNetUploadDir "`n"
. "--" boundary "`n"
. "Content-Disposition: form-data; name=""upload_1""; filename=""" ofn1 """`n"
. "Content-Type: " MimeType(img1) "`n"
. "Content-Transfer-Encoding: binary`n"
. "`n"
postPart_2 := "`n"
. "--" boundary "`n"
. "Content-Disposition: form-data; name=""upload_2""; filename=""" ofn2 """`n"
. "Content-Type: " MimeType(img2) "`n"
. "Content-Transfer-Encoding: binary`n"
. "`n"
postPart_3 := "`n"
. "--" boundary "`n"
. "Content-Disposition: form-data; name=""upload_3""; filename=""""`n"
. "Content-Type: application/octet-stream`n"
. "Content-Transfer-Encoding: binary`n"
. "`n"
. "`n"
. "--" boundary "`n"
. "Content-Disposition: form-data; name=""MAX_FILE_SIZE""`n"
. "`n"
. "8000000`n"
. "--" boundary "`n"
. "Content-Disposition: form-data; name=""cmd""`n"
. "`n"
. "Upload all`n"
. "--" boundary "--"
post := postPart_1 placeholder1 postPart_2 placeholder2 postPart_3
; Create Proper Headers
headers:="Content-type: multipart/form-data, boundary=" boundary "`nContent-Length: " strlen(post)
; Fix PostData - copy the binary imagedata into memory at posts position
; Image 1
DllCall("RtlMoveMemory"
,"uInt",(offset:=&post+strlen(postPart_1))
,"uInt",&img1,"uInt",size1)
; Image 2
DllCall("RtlMoveMemory"
,"uInt",(offset:=&post+strlen(postPart_1)+size1+strlen(postPart_2))
,"uInt",&img2,"uInt",size2)
; Send this stuff
; This is the place to show some nice uploading GFX or whatever
GoSub, EpicCycleOn
Tooltip("Upload pictures to AutoHotkey.net",2)
l := httpQuery(data:="","https://ahknet.autohotkey.com/xfm/?a=create&" Cookie, post, headers)
VarSetCapacity(data,-1)
EpicCycle := 0
If !(InStr(data,"success"))
MsgBox,16,Error,Errow at FileUpload
; This is the place to quit the nice uploading GFX
return
AHKNET_Logout:
GoSub, EpicCycleOn
httpQueryDwFlags := (INTERNET_FLAG_NO_AUTO_REDIRECT:= 0x00200000)
l := httpQuery(data:="","https://ahknet.autohotkey.com/xfm/?a=logout&" Cookie)
httpQueryDwFlags := Cookie := ""
EpicCycle := 0
Return
EpicCycleON:
EpicCycle := 1
SetTimer, EpicCycle, -1
Return
; EpicCycle - Stolen from Rhys
; http://www.autohotkey.com/forum/viewtopic.php?p=203787#203787
; Modified and adapted to be an indicator for current internet traffic
EpicCycle:
Width := 56, Height := 56
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
hBrush:=Gdip_BrushCreateSolid(0xEEff0000)
hPen:=Gdip_CreatePen(0xEEFFFFee0, 2)
fatPen:=Gdip_CreatePen(0xEE0000FF, 5)
eraserPen:=Gdip_CreatePen(0x00000000, 5)
CoordMode, Mouse, Screen
Loop,60
If (EpicCycle=0)
Break
else {
MouseGetPos,MX,MY
Gdip_SetCompositingMode(G, 1)
Gdip_Drawarc(G, FatPen, 2, 2, 50, 50, 270, A_Index*6)
Gdip_SetCompositingMode(G, 0)
Gdip_Drawarc(G, hPen, 2, 2, 50, 50, 270, A_Index*6)
UpdateLayeredWindow(hwnd1, hdc, MX-25, MY-25, Width, Height)
Sleep,10
}
Loop,30
If (EpicCycle=0)
Break
else {
MouseGetPos,MX,MY
Gdip_SetCompositingMode(G, 1)
Gdip_Drawarc(G, eraserPen, 2, 2, 50, 50, 270, A_Index*12)
UpdateLayeredWindow(hwnd1, hdc, MX-25, MY-25, Width, Height)
Sleep,10
}
Gdip_SetCompositingMode(G, 0)
Gui,Destroy
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
if (EpicCycle=1)
SetTimer, EpicCycle, -1
Return
Exit:
Gdip_Shutdown(pToken)
ExitApp
+PrintScreen:: ; press SHIFT+Druck
; Screenshoot in Originalgröße ertstellen.
FileName := SaveScreen(1.00,imgType,"Window") "." imgType
Sleep, 750
; Screenshot reduzieren auf 0,33 Prozent der Originalgröße zur Erstellung eines "Thumbnail".
FileNameThumb := SaveScreen(0.33,imgType,"Window") "." imgType
ClipBoard := "[url=" MyAHKNetPath "/" FileName "][img]" MyAHKNetPath "/" FileNameThumb "[/img][/url]"
Sleep, 750
GoSub, AHKNET_Login
GoSub, AHKNET_Upload
GoSub, AHKNET_Logout
Return
uriEncode(str)
{ ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release
b_Format := A_FormatInteger
data := ""
SetFormat,Integer,H
Loop,Parse,str
if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)<0x30) || (asc(A_LoopField)=0x3d))
data .= "%" . ((StrLen(c:=SubStr(ASC(A_LoopField),3))<2) ? "0" . c : c)
Else
data .= A_LoopField
SetFormat,Integer,%b_format%
return data
}
makeProperBoundary() {
; (w) derRaphael / zLib Style released
Loop,26
n .= chr(64+a_index)
n .= "0123456789"
Loop,% StrLen(A_Now) {
Random,rnd,1,% StrLen(n)
Random,UL,0,1
b .= RegExReplace(SubStr(n,rnd,1),".$","$" (round(UL)? "U":"L") "0")
}
Return b
}
MimeType(ByRef Binary) {
; (w) derRaphael / zLib Style released
MimeTypes:="424d image/bmp|4749463 image/gif|ffd8ffe image/jpeg|89504e4 image/png|4657530"
. " application/x-shockwave-flash|49492a0 image/tiff"
@:="0123456789abcdef"
Loop,8
hex .= substr(@,(*(a:=&Binary-1+a_index)>>4)+1,1) substr(@,((*a)&15)+1,1)
Loop,Parse,MimeTypes,|
if ((substr(hex,1,strlen(n:=RegExReplace(A_Loopfield,"\s.*"))))=n)
Mime := RegExReplace(A_LoopField,".*?\s")
Return (Mime!="") ? Mime : "application/octet-stream"
}
Tooltip(sTooltipTxt,Seconds=5) {
; (w) derRaphael / zLib Style released
if (Seconds+0=0)
Seconds = 5
StartTime := EndTime := A_Now
EnvAdd,EndTime,Seconds,Seconds
Loop,
if (EndTime=A_Now)
Break
else {
ToolTip, %sTooltipTxt%
sleep, 25
}
ToolTip
}
SaveScreen(Size,FileType,Type)
{
WinGetPos, X, Y, W, H, A
If (Type = "Window") {
pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)
FileName := "Window_" A_Now
} Else {
pBitmap := Gdip_BitmapFromScreen()
FileName := "Screen_" A_Now
}
Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
PBitmapResized := Gdip_CreateBitmap(Round(Width*Size), Round(Height*Size))
G := Gdip_GraphicsFromImage(pBitmapResized)
Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 0, 0, Round(Width*Size), Round(Height*Size), 0, 0, Width, Height)
Gdip_SaveBitmapToFile(PBitmapResized, A_ScriptDir "\" FileName "." FileType)
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapResized)
Gdip_DisposeImage(pBitmap)
Return (FileName)
}
#Include, httpQuery.ahk
#Include, Gdip.ahk
Yes! - It doesn't give you a warning when u entered a wrong password
Yes! - It doesn't give you a warning when u entered a wrong username
No! - It tells You when something with your upload went wrong (eg no success Message)
Comments, questions, wishes, or suggestions appreciated
Greets
dR