-
Notifications
You must be signed in to change notification settings - Fork 11
/
intheshell.go
234 lines (203 loc) · 5.11 KB
/
intheshell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package main
import (
"os"
"os/exec"
"os/signal"
"strconv"
"strings"
"syscall"
"time"
)
// Constants
const (
OneMSec = 1000 * 1000 // One milliseond
OneSec = 1000 * 1000 * 100 // One second
TextSpeed = 50 // Text showing speed
)
var abortOp bool
// Return Ghost and his height
func getGhost() string {
ghost := ps1str() + " \n" +
ps1str() + Bold(" ___\n") +
ps1str() + Bold(" _/ @@\\\n") +
ps1str() + Bold(" ( \\ 0/__\n") +
ps1str() + Bold(" \\ \\__)\n") +
ps1str() + Bold(" / \\\n") +
ps1str() + Bold(" / \\\n") +
ps1str() + Bold(" ^^^^^^^^^\n") +
ps1str()
return ghost
}
// Show text from black to white
func textShowSlow(inString string) {
for i := 232; i <= 255; i++ {
if abortOp {
break
}
os.Stdout.Write([]byte("\033[38;5;" + strconv.Itoa(i) + "m" + Bold(inString) + "\033[0m\r"))
time.Sleep(OneMSec * TextSpeed)
os.Stdout.Sync()
}
}
// Show text from white to black
func textHideSlow(inString string) {
for i := 255; i >= 232; i-- {
if abortOp {
break
}
os.Stdout.Write([]byte("\033[38;5;" + strconv.Itoa(i) + "m" + Bold(inString) + "\033[0m\r"))
time.Sleep(OneMSec * TextSpeed)
os.Stdout.Sync()
}
}
// Clearing screen
func clearScreen() {
os.Stdout.Write([]byte("\033[H\033[2J"))
os.Stdout.Sync()
}
// Bold text
func Bold(inString string) string {
return "\033[1m" + inString + "\033[0m"
}
// Creating PS1
func ps1str() string {
return "ghost@shell:~$ "
}
// Show creds on exit
func showCreds() {
os.Stdout.Write([]byte("\n\n"))
os.Stdout.Write([]byte(centrifyText("Created")))
os.Stdout.Write([]byte("\n"))
os.Stdout.Write([]byte(centrifyText(" by")))
os.Stdout.Write([]byte("\n\n"))
os.Stdout.Write([]byte(Bold(centrifyText("Andrey Esin"))))
os.Stdout.Write([]byte("\n\n"))
os.Stdout.Write([]byte(centrifyText("[ https://hubzil.la/profile/andrey ] [ t.me/la_stik ] [ [email protected] ]")))
os.Stdout.Write([]byte("\n\n"))
os.Stdout.Write([]byte(Bold(centrifyText("Sources"))))
os.Stdout.Write([]byte("\n"))
os.Stdout.Write([]byte(centrifyText("[ github.com/esin/intheshell ]")))
os.Stdout.Write([]byte("\n"))
os.Stdout.Sync()
time.Sleep(time.Second * 3)
}
// Get terminal count
func getTTYSize() (int, int) {
cmd := exec.Command("stty", "size")
cmd.Stdin = os.Stdin
out, err := cmd.Output()
//println(string(out))
if err != nil {
//log.Fatal(err)
appExit()
}
outStr := strings.Replace(string(out), "\n", "", -1)
cols, err := strconv.Atoi(strings.Split(outStr, " ")[1])
if err != nil {
//log.Fatal(err)
appExit()
}
rows, err := strconv.Atoi(strings.Split(outStr, " ")[0])
if err != nil {
//log.Fatal(err)
appExit()
}
return cols, rows
}
// Return string, which can be showed in horizontal center of terminal
func centrifyText(inText string) string {
cols, _ := getTTYSize()
resultString := ""
spacesCount := (cols / 2) - (len(inText) / 2)
for i := 0; i < spacesCount; i++ {
resultString = resultString + " "
}
resultString = resultString + inText
return resultString
}
// Right exiting from application
func appExit() {
abortOp = true
clearScreen()
showCreds()
os.Stdout.Write([]byte("\033[?25h"))
os.Exit(0)
}
func centerVertical() string {
_, rows := getTTYSize()
resultString := "\n"
for i := 0; i < rows/2; i++ {
resultString += "\n"
}
return resultString
}
func main() {
// Catch ctrl-c
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-c
appExit()
}()
// 2 minutes enough to see the "movie"
go func() {
time.Sleep(time.Second * 120)
appExit()
}()
abortOp = false
// Don't allow using scp, ssh with params and similar
args := os.Args
if len(args) > 1 {
os.Stdout.Write([]byte("Hey, just try:" + Bold(" ssh [email protected]")))
os.Stdout.Write([]byte("\n"))
os.Stdout.Write([]byte("\033[?25h"))
os.Exit(0)
}
clearScreen()
// Hide cursor
os.Stdout.Write([]byte("\033[?25l"))
//1 scene
//Andrey Esin
os.Stdout.Write([]byte(centerVertical()))
textShowSlow(centrifyText("Andrey Esin"))
time.Sleep(OneSec * 5)
textHideSlow(centrifyText("Andrey Esin"))
time.Sleep(OneSec * 1)
clearScreen()
// 2 scene
// PRESENTS
os.Stdout.Write([]byte(centerVertical()))
textShowSlow(centrifyText("PRESENTS"))
time.Sleep(OneSec * 5)
textHideSlow(centrifyText("PRESENTS"))
time.Sleep(OneSec * 1)
clearScreen()
// 3 scene
// GHOST IN THE SHELL (bash)
os.Stdout.Write([]byte(centerVertical()))
textShowSlow(centrifyText("GHOST IN THE SHELL (bash)"))
time.Sleep(OneSec * 5)
textHideSlow(centrifyText("GHOST IN THE SHELL (bash)"))
time.Sleep(OneSec * 1)
clearScreen()
cols, _ := getTTYSize()
ghost := getGhost()
spaces := " "
for i := 0; i < cols-15-len(ps1str()); i++ {
clearScreen()
spaces += " "
result := strings.Replace(ghost, ps1str(), ps1str()+spaces, -1)
//println(result)
os.Stdout.Write([]byte(result))
time.Sleep(OneMSec * 50)
os.Stdout.Sync()
}
clearScreen()
//GHOST IN THE SHELL (bash)
os.Stdout.Write([]byte(centerVertical()))
textShowSlow(centrifyText("THE END"))
time.Sleep(OneSec * 5)
textHideSlow(centrifyText("THE END"))
time.Sleep(OneSec * 1)
appExit()
}