This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathgfx.js
executable file
·149 lines (132 loc) · 6.28 KB
/
gfx.js
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
var CLI = require('clui'),
clc = require('cli-color'),
os = require('os'),
_ = require('lodash'),
utils = require('./utils.js');
var Line = CLI.Line,
LineBuffer = CLI.LineBuffer,
Gauge = CLI.Gauge,
Sparkline = CLI.Sparkline,
drawTimeout,
inSeries = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
outSeries = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
error = clc.red.bold;
module.exports = {
draw: function(inbound,outbound,old,msg,tType) {
var typeMsg;
switch(tType){
case 'simpleproxy':
typeMsg = '\nConnected for internal websites:\n\n'
+ 'This tunnel allows live, screenshots, or selenium tests to '
+ 'be run through your local network. For sites hosted on your '
+ 'computer, use the domain "local" as opposed to "localhost":\n\n'
+ ' e.g. http://local';
break;
case 'webserver':
typeMsg = '\nConnected for local HTML files:\n\n'
+ 'This tunnel allows access to files in a specified directory '
+ 'and its subdirectory. By default, the server listens on the '
+ 'first open port from 8080-8089, but you may specify a custom '
+ 'port with the "--port" flag. To access the statically hosted '
+ 'directory, use "local". To specify a locally hosted static '
+ 'webpage for screenshots or otherwise, use local and the '
+ 'filename of the webpage:\n\n'
+ ' e.g. http://local\n\t'
+ ' http://local/FILENAME';
break;
case 'tunnel':
typeMsg = '\nConnected for proxy server:\n\n'
+ 'This mode allows you to run live tests and snapshot tests '
+ ' through a proxy, specified by IP and port. For locally hosted '
+ ' sites, use the domain "local" as opposed to '
+ ' "localhost":\n\n\te.g. http://local';
break;
case 'local':
typeMsg = `
Tunnel running locally.
`;
break;
default:
typeMsg = 'How did you get here...';
}
console.log('\u001b[2J'); // character code to clear the terminal screen
console.log('\u001b[100;0H');
var blankLine = new Line().fill().output();
if((!_.isNull(old))&&(!_.isUndefined(old))){
var oldLine = new Line()
.padding(2)
.column(old.msg,200,[clc.bold.red])
.fill()
.output();
}
blankLine.output();
if((!_.isNull(msg))&&!_.isUndefined(msg)){
var msgLine = new Line()
.padding(2)
.column(msg,200,[clc.bold.red])
.fill()
.output();
}
blankLine.output();
var connection = new Line()
.padding (2)
.column(typeMsg)
.fill()
.output();
blankLine.output();
inSeries.push(inbound);
inSeries.shift();
var inLine = new Line()
.padding(2)
.column('Inbound Requests/Sec ', 20, [clc.cyan])
.column(Sparkline(inSeries, ' reqs/sec'), 80)
.fill()
.output();
outSeries.push(outbound);
outSeries.shift();
var outLine = new Line()
.padding(2)
.column('Outbound Packets/Sec ', 20, [clc.cyan])
.column(Sparkline(outSeries, ' packets/sec'), 80)
.fill()
.output();
blankLine.output();
var quitLine = new Line()
.padding(2)
.column('(to quit cbt_tunnels, press ctrl+c)',100,[clc.cyan])
.fill()
.output();
blankLine.output();
},
warn: function(message){
global.logger.error(error(message));
},
help: function(){
global.logger.info(
clc.bold("cbt_tunnels.js has three run modes:\n\n")
+ clc.underline("Internal Websites:\n")
+ "This directs requests from CBT browsers to your computer to test sites behind your firewall that would otherwise be inaccessible.\n"
+ "Basic usage:\n 'cbt_tunnels --username USERNAME --authkey AUTHKEY'\n\n"
+ clc.underline("Local HTML Files:\n")
+ "This allows you to test static sites that are on your computer but not currently hosted on a server.\n"
+ "Basic usage:\n 'cbt_tunnels --username USERNAME --authkey AUTHKEY --dir PATHTODIRECTORY (optional: --port OPENPORT)'\n\n"
+ clc.underline("Proxy Server:\n")
+ "This tunnel directs the connection through a proxy of your choice."
+ "Basic usage:\n 'cbt_tunnels --username USERNAME --authkey AUTHKEY --proxyIp PROXYIP --proxyPort PROXYPORT'\n\n"
+ clc.underline("Further flags:\n")
+ " '--kill KILLFILENAME' | Appending this flag allows you specify the\n"
+ " | name of a 'kill file' that if placed in\n"
+ " | the current directory will cause the\n"
+ " | program to gracefully shutdown.\n"
+ clc.underline("_ |\n")
+ " '--ready READYFILENAME'| Specifiying this flag creates an\n"
+ " | empty file at the path specified\n"
+ " | when the cbt_tunnels is fully connected.\n"
+ clc.underline("_ |\n")
+ " '--verbose' | Specifiying this flag enables verbose\n"
+ " | mode; you'll see most of the\n"
+ " | traffic handling.\n"
+ clc.underline("_ |\n")
+ "\nFor instructions on scripting, please see: https://github.com/crossbrowsertesting/cbt-tunnel-nodejs\n");
}
}