Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Setup screen command, and base client routes.

  • Loading branch information...
commit 7755245212bfa952db92062bd9d502b59828d6ff 1 parent a4ee623
@jwinnenb authored
View
19 DESIGN.org
@@ -0,0 +1,19 @@
+
+Knucklehead depends on HTTP for most of its control structure, reducing its commands to nothing more than GET queries.
+
+* Client Server
+
+/screen-png
+/keyboard
+/mouse
+/upload
+/download
+/checksum
+/command
+
+* Master Server
+
+/login
+/verify
+/users
+/computers
View
21 src/kh/client/core.clj
@@ -1,4 +1,19 @@
-(ns kh.client.core)
+(ns kh.client.core
+ (:use [compojure core route]
+ [kh.client screen]
+ ring.adapter.jetty))
-(defn launch-client [& args]
- (println "launch-server stub"))
+(defroutes client-core
+ (GET "/screen" [cookie scale] (screen-png scale))
+ (GET "/keyboard" [] nil)
+ (GET "/mouse" [] nil)
+ (GET "/upload" [] nil)
+ (GET "/download" [] nil)
+ (GET "/checksum" [] nil)
+ (GET "/command" [] nil))
+
+(defn launch-client [client-port client-ssl-cert client-ssl-pass]
+ (.start
+ (Thread.
+ (fn []
+ (run-jetty #'client-core {:ssl true :ssl-port client-port :keystore client-ssl-cert :key-password client-ssl-pass})))))
View
26 src/kh/client/screen.clj
@@ -0,0 +1,26 @@
+(ns kh.client.screen
+ (:import
+ [java.awt.image BufferedImage]
+ [java.awt Dimension Image Rectangle Robot Toolkit]
+ [java.io ByteArrayInputStream ByteArrayOutputStream]
+ [javax.imageio ImageIO]))
+
+(defn capture-screen [base-scale]
+ (let [scale (or scale 1)
+ base-image (.createScreenCapture (Robot.) (Rectangle. (.getScreenSize (. java.awt.Toolkit getDefaultToolkit))))
+ image (BufferedImage. (* (.getWidth base-image) scale) (* (.getHeight base-image) scale) BufferedImage/TYPE_INT_RGB)
+ gr (.createGraphics image)]
+ (.drawImage gr base-image (* (.getWidth base-image) scale) (* (.getHeight base-image) scale) nil)
+ (.dispose gr)
+ image))
+
+(defn capture-screen-png [scale]
+ (let [image (capture-screen scale)
+ out (ByteArrayOutputStream.)]
+ (ImageIO/write image "png" out)
+ (ByteArrayInputStream. (.toByteArray out))))
+
+(defn screen-png [cookie scale]
+ {:headers {"Content-type" "image/png"}
+ :status 200
+ :body (capture-screen-png scale)})
View
5 src/sql/kh.sql
@@ -0,0 +1,5 @@
+create table khuser (
+ khuname varchar (32) primary key,
+ khpass varchar (40),
+ khcookie varchar (40)
+);
Please sign in to comment.
Something went wrong with that request. Please try again.