Viewing my local screen as snapshot via the web
I've been playing with two ways for any web-browser anywhere on the 'web to see what I've been up to on my local machines.
I have two solutions at present.
The LB route involves the following program which runs continuously, asleep most of the time, but at pre-defined intervals screengrabs its display; converts it to a jpg; then ftp's it to one of my externally hosted websites. There it is visible like this example below- but by not publicising the name of the file and by never putting up links to it the web-crawler robots won't find it, so there are no security problems.
PCT_DLL.dll is available on the web, as is ftp4w32.dll.
LB only
' LB side of LB-RB data-passing via 'C:/rb101/public/screen.jpg'.
' It puts in 'C:/public' a screengrab bmp, then converts it to a jpg and deletes bmp.
' The rest of the time this program sleeps, by using timer intervals.
' Close the mini-window at top LH screen when you want it to stop updating.
' The ftp part can be omitted if locally serving RunBASIC sites to the 'web.
' You need PCT_DLL.dll in the system dir or same dir as this prog is in.
' The prints to mainwin can be omitted if no debugging is needed.
'nomainwin
dim error$(2000)
error$( 0) ="No problem.."
error$(1003) ="user not connected to server"
error$(1004) ="cannot open file"
error$(1008) ="action not taken"
error$(1010) ="server cannot open file"
WindowWidth = 100
WindowHeight = 40
UpperLeftX = 1
UpperLeftY = 1
port = 21 'port to use
pasv = 1 'PASV mode? 1 is yes, 0 is no
ftphost$ = "atschool.eduweb.co.uk" 'ftp site address
login$ = "t*****n" 'ftp site username login
password$ = "t*********6" 'ftp site password
initpath$ = "" 'leave blank if you want the site's default
upload$ = "C:/rbp101/public/window.jpg" 'full path & file info for file to upload
remotefile$ = "screen.jpg" 'what you want it to be called on the ftp server
TRUE = 1
FALSE = 0
ftpsession = FALSE
open "LB" for graphics as #main
print #main, "trapclose [quit.main]"
hW =hwnd( #main)
'calldll #user32, "GetParent", hW as long, hP as long
timer 2000, [grabscreen]
wait
end
[grabscreen]
print "grabbing screen as bmp"
timer 0
'Save all screen to window.bmp
dest$ ="C:\rbp101\public\window.bmp"
hP =0 ' so will grab whole screen
open "PCT_DLL.dll" for dll as #conv
calldll #conv, "formtobmp", hP as ulong, dest$ as ptr, r as long
close #conv
print "done: waiting 2s"
timer 2000, [convert]
wait
[convert]
print "converting grab to jpg"
timer 0
'then convert it to window.jpg
source$ ="C:\rbp101\public\window.bmp": dest$ ="C:\rbp101\public\window.jpg"
open "PCT_DLL.dll" for dll as #conv
calldll #conv, "tojpeg", source$ as ptr, dest$ as ptr, r as long
close #conv
print "done: waiting 2s"
timer 2000, [delete]
wait
[delete]
print "deleting the bmp version"
timer 0
kill "C:\rbp101\public\window.bmp"
print "done"
print "uploading"
gosub [upload]
timer 600000, [grabscreen]
wait
[quit.main]
close #main
if ftpsession = TRUE then gosub [closeftp]
END
[upload]
parentftp =hW 'nd( #session)
open "ftp4w32.dll" for dll as #ftp
ftpsession = TRUE
calldll #ftp, "FtpInit", parentftp as long, res as long
print res; " "; error$( res)
calldll #ftp, "FtpSetSynchronousMode", void as long
calldll #ftp, "FtpSetDefaultPort", port as long, void as long
calldll #ftp, "FtpSetPassiveMode", pasv as long, void as long
t =time$( "seconds")
calldll #ftp, "FtpLogin", ftphost$ as struct, login$ as struct, password$ as struct, parentftp as long, 0 as long, res as long
calldll #ftp, "FtpCWD", initpath$ as struct, res as long
print res; " "; error$( res); " ";
calldll #ftp, "FtpSendFile", upload$ as struct, remotefile$ as struct, 0 as long, 0 as long, parentftp as long, 0 as long, res as long
print res; " "; error$( res);
gosub [closeftp]
print " Connected for "; time$( "seconds") -t; "s at time "; time$()
return
[closeftp]
calldll #ftp, "FtpCloseConnection", void as long
calldll #ftp, "FtpRelease", void as long
close #ftp
ftpsession = FALSE
print "ftp call over: delaying 600000ms ie 600s or 10 minutes."
return
RunBASIC method
The other RunBASIC method leaves out the ftp stage, but uses my local RunBASIC webserver, which picks up the locally saved image and presents it on a page with an auto-refresh.
html "<meta http-equiv=""Refresh"" content=""30"">"
html "<center>"
html "<b>Server Screen display</b>"
html "<p>"
html "<p>"
print "The page refreshes every 30 sec from server screen grabbed every 30 sec."
print "If nothing changes I'm probably working on laptop not server- or away!"
html "<img src=""/window.jpg"" width=""512"" height=""384""/>"
end
Meanwhile, LB is running this, to create updated images of the screen for RB to serve:-
' nomainwin
WindowWidth = 100
WindowHeight = 40
UpperLeftX = 1
UpperLeftY = 1
open "LB" for graphics as #main
print #main, "trapclose [quit.main]"
hW =hwnd( #main)
timer 2000, [grabscreen]
wait
end
[grabscreen]
print "grabbing screen as bmp"
timer 0
dest$ ="C:\rbp101\public\window.bmp"
hP =0
open "PCT_DLL.dll" for dll as #conv
calldll #conv, "formtobmp", hP as ulong, dest$ as ptr, r as long
close #conv
timer 2000, [convert]
wait
[convert]
timer 0
source$ ="C:\rbp101\public\window.bmp": dest$ ="C:\rbp101\public\window.jpg"
open "PCT_DLL.dll" for dll as #conv
calldll #conv, "tojpeg", source$ as ptr, dest$ as ptr, r as long
close #conv
timer 2000, [delete]
wait
[delete]
timer 0
kill "C:\rbp101\public\window.bmp"
gosub [upload]
timer 600000, [grabscreen]
wait
[quit.main]
close #main
END