2011-10-24 22:36:08 +00:00
|
|
|
#lang racket/base
|
|
|
|
;; (Temporary) example client and server
|
|
|
|
|
|
|
|
(require racket/tcp)
|
|
|
|
(require racket/pretty)
|
|
|
|
(require racket/match)
|
2011-10-25 20:45:15 +00:00
|
|
|
(require racket/class)
|
|
|
|
(require racket/port)
|
2011-10-26 23:16:16 +00:00
|
|
|
(require racket/sandbox)
|
2011-10-24 22:36:08 +00:00
|
|
|
|
2011-10-27 18:15:44 +00:00
|
|
|
(require "ssh-service.rkt")
|
2011-10-24 22:36:08 +00:00
|
|
|
(require "standard-thread.rkt")
|
|
|
|
|
2011-10-27 18:15:44 +00:00
|
|
|
#;(define (t-client)
|
2011-10-24 22:36:08 +00:00
|
|
|
(let-values (((i o) (tcp-connect "localhost"
|
|
|
|
2323
|
|
|
|
;;22
|
|
|
|
)))
|
|
|
|
(let ((api (ssh-session 'client i o)))
|
|
|
|
(printf "Got API ~v\n" api)
|
|
|
|
(semaphore-wait (make-semaphore 0)))))
|
|
|
|
|
2011-10-27 18:15:44 +00:00
|
|
|
(define (repl-shell username in out)
|
|
|
|
(fprintf out "Hello, ~a.\n" username)
|
|
|
|
(parameterize ((current-input-port in)
|
|
|
|
(current-output-port out)
|
|
|
|
(current-error-port out)
|
|
|
|
(sandbox-input in)
|
|
|
|
(sandbox-output out)
|
|
|
|
(sandbox-error-output out)
|
|
|
|
(current-namespace (make-empty-namespace)))
|
|
|
|
(parameterize ((current-eval (make-evaluator 'racket/base)))
|
|
|
|
(read-eval-print-loop))
|
|
|
|
(fprintf out "\nGoodbye!\n")
|
|
|
|
(close-input-port in)
|
|
|
|
(close-output-port out)))
|
2011-10-24 22:36:08 +00:00
|
|
|
|
|
|
|
(define (t-server)
|
|
|
|
(define s (tcp-listen 2322 4 #t "localhost"))
|
|
|
|
(printf "Accepting...\n")
|
2011-10-27 18:15:44 +00:00
|
|
|
(tcp-pty-ssh-server s repl-shell))
|
2011-10-24 22:36:08 +00:00
|
|
|
|
|
|
|
(if (getenv "clientmode")
|
2011-10-27 18:15:44 +00:00
|
|
|
(void) #;(t-client)
|
2011-10-24 22:36:08 +00:00
|
|
|
(t-server))
|