This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from gluesys/dohyunkim
Dohyunkim
- Loading branch information
Showing
19 changed files
with
1,256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sshell2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
## Functional Specification | ||
|
||
| Category | Name | Function | | ||
|-----------|-------|-----------| | ||
|Sign in SSHELL | Sign in| Login with id and password| | ||
| | Sign up | Sign up with id and password | | ||
|Connect To PC | Load session | Load saved session| | ||
| | Save session | Save session information | | ||
| | Delete session | Delete selected session | | ||
| | Connect ssh | Connect to remote PC | | ||
| Use terminal | Terminal shell | Use CLI | | ||
| | Customize | customize font, background color | | ||
| Customize themes | Customize preview | Show preview based on present font, </br>background color | | ||
| | Save customization | Save present font, background color | | ||
<br/> | ||
|
||
## REST API | ||
``` | ||
{ | ||
signin : | ||
- id, | ||
password | ||
signup : [ | ||
id, | ||
password | ||
], | ||
session :{ | ||
load : [ | ||
sessionID | ||
], | ||
save : [ | ||
IP | ||
], | ||
delete : [ | ||
sessionID | ||
] | ||
}, | ||
open : [ | ||
IP : | ||
], | ||
customize : { | ||
preview : [ | ||
font, | ||
fontColor, | ||
fontSize, | ||
backgroundColor | ||
], | ||
save : [ | ||
font, | ||
fontColor, | ||
fontSize, | ||
backgroundColor | ||
] | ||
}, | ||
} | ||
``` | ||
|
||
| URI | Input | Function | | ||
|-------|-------|----------| | ||
|signin|{ id: "",<br/> password: "" }| login| | ||
|signup|{ id: "",<br/> password: "" }| signup| | ||
|session/load | { sessionID: "" } | load session | | ||
|session/save | { IP: "" } | save session | | ||
|session/delete | { sessionID: "" } | delete session | | ||
|open | { ip: "" } | connect | | ||
|customize | | customize| | ||
|customize/preview | { font: "", <br/>fontcolor: "", <br/>fontsize: "",<br/>backgroundColor: ""} | preview customization| | ||
|customize/save | { font: "", <br/>fontcolor: "", <br/>fontsize: "",<br/>backgroundColor: ""} | save customization | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package Handler; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Terminal; | ||
use Terminal::Ascii2Html; | ||
use JSON (); | ||
|
||
sub new { | ||
my $class = shift; | ||
|
||
my $self = {@_}; | ||
bless $self, $class; | ||
|
||
$self->{ascii2html} = Terminal::Ascii2Html->new; | ||
|
||
return $self; | ||
} | ||
|
||
sub run { | ||
my $handler = shift; | ||
|
||
my $cmd = $handler->{cmd}; | ||
|
||
return sub { | ||
my $self = shift; | ||
|
||
my $terminal = Terminal->new( | ||
cmd => $cmd, | ||
on_row_changed => sub { | ||
my ($terminal, $row, $text) = @_; | ||
|
||
$text = $handler->{ascii2html}->htmlify($text); | ||
|
||
my $message = JSON->new->encode( | ||
{type => 'row', row => $row, text => $text}); | ||
$self->send($message); | ||
}, | ||
on_cursor_move => sub { | ||
my ($terminal, $x, $y) = @_; | ||
|
||
my $message = | ||
JSON->new->encode({type => 'cursor', x => $x, y => $y}); | ||
$self->send($message); | ||
}, | ||
on_finished => sub { | ||
my $terminal = shift; | ||
|
||
$self->close; | ||
} | ||
); | ||
|
||
$self->on( | ||
message => sub { | ||
my ($self, $message) = @_; | ||
|
||
my $json = JSON->new; | ||
|
||
eval { $message = $json->decode($message); }; | ||
return if !$message || $@; | ||
|
||
my $type = $message->{type}; | ||
if ($type eq 'key') { | ||
my $buffer; | ||
|
||
my $code = $message->{code}; | ||
|
||
$terminal->key($code); | ||
} | ||
elsif ($type eq 'action') { | ||
$terminal->move($message->{action}); | ||
} | ||
else { | ||
warn "Unknown type '$type'"; | ||
} | ||
} | ||
); | ||
|
||
$self->on( | ||
disconnect => sub { | ||
} | ||
); | ||
|
||
$terminal->start; | ||
}; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package Sshell; | ||
use Mojo::Base 'Mojolicious', -signatures; | ||
|
||
# This method will run once at server start | ||
sub startup ($self) { | ||
|
||
# Load configuration from config file | ||
my $config = $self->plugin('NotYAMLConfig'); | ||
|
||
# Configure the application | ||
$self->secrets($config->{secrets}); | ||
|
||
# Router | ||
my $r = $self->routes; | ||
|
||
# Normal route to controller | ||
$r->get('/')->to('example#index'); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package Sshell::Controller::Example; | ||
use Mojo::Base 'Mojolicious::Controller', -signatures; | ||
|
||
use Terminal; | ||
use Terminal::Ascii2Html; | ||
use JSON (); | ||
|
||
|
||
# This action will render a template | ||
sub index ($self) { | ||
|
||
$self->{ascii2html} = Terminal::Ascii2Html->new; | ||
|
||
my $log = $self->app->log; | ||
|
||
|
||
my $cmd = "/usr/bin/zsh"; | ||
my $terminal = Terminal->new( | ||
cmd => $cmd, | ||
on_row_changed => sub { | ||
my ($terminal, $row, $text) = @_; | ||
|
||
$text = $self->{ascii2html}->htmlify($text); | ||
|
||
my $message = JSON->new->encode( | ||
{type => 'row', row => $row, text => $text}); | ||
$self->send($message); | ||
}, | ||
on_cursor_move => sub { | ||
my ($terminal, $x, $y) = @_; | ||
|
||
my $message = | ||
JSON->new->encode({type => 'cursor', x => $x, y => $y}); | ||
$self->send($message); | ||
}, | ||
on_finished => sub { | ||
my $terminal = shift; | ||
|
||
$self->close; | ||
} | ||
); | ||
$self->on( | ||
message => sub { | ||
my ($self, $message) = @_; | ||
|
||
my $json = JSON->new; | ||
|
||
eval { $message = $json->decode($message); }; | ||
return if !$message || $@; | ||
|
||
my $type = $message->{type}; | ||
if ($type eq 'key') { | ||
my $buffer; | ||
|
||
my $code = $message->{code}; | ||
|
||
$terminal->key($code); | ||
} | ||
elsif ($type eq 'action') { | ||
$terminal->move($message->{action}); | ||
} | ||
else { | ||
warn "Unknown type '$type'"; | ||
} | ||
} | ||
); | ||
|
||
$self->on( | ||
disconnect => sub { | ||
} | ||
); | ||
|
||
$terminal->start; | ||
|
||
|
||
|
||
# Render template "example/welcome.html.ep" with message | ||
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!'); | ||
} | ||
|
||
|
||
1; |
Oops, something went wrong.