webssh2_client 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,345 @@
1
+ # WebSSH2 Client
2
+
3
+ WebSSH2 Client is a web-based SSH client that allows users to connect to SSH servers directly from their web browsers. It's built using modern web technologies and provides a seamless, secure SSH experience.
4
+
5
+ # EXPERIMENTAL
6
+ The current status of this is experimental and this first version is a refactor of webssh2 v0.2.x to be compatible with a refactor of the same version of webssh2 as a stand-alone server-side component for BIG-IP running Node.js v6.9.1.
7
+
8
+ The intention is to harmonize the latest release of webssh2 splitting out the client and server as seperate repos (webssh2-client and webssh2-server) but joining them both together as modules in a parent webssh2 in an attempt to provide backwards compatibility.
9
+
10
+ The main idea for bifurcating the client/server is to make it easier to customize the client to work in other frameworks and use-cases.
11
+
12
+ ## Features
13
+
14
+ - Web-based SSH terminal emulation
15
+ - Secure authentication
16
+ - Customizable terminal options
17
+ - Session logging
18
+ - Responsive design
19
+ - Support for reconnection and reauthentication
20
+
21
+ ## Technology Stack
22
+
23
+ - Node.js (v18+)
24
+ - Socket.IO for real-time communication
25
+ - Xterm.js for terminal emulation
26
+ - Webpack for bundling
27
+ - ES6+ JavaScript
28
+
29
+ ## Installation
30
+
31
+ 1. Clone the repository:
32
+ ```
33
+ git clone https://github.com/billchurch/webssh2-client.git
34
+ cd webssh2-client
35
+ ```
36
+
37
+ 2. Install dependencies:
38
+ ```
39
+ npm install
40
+ ```
41
+
42
+ 3. Build the client:
43
+ ```
44
+ npm run build
45
+ ```
46
+
47
+ ## WebSSH2 Configuration
48
+
49
+ The WebSSH2 client can be customized using the `window.webssh2Config` object. This object is typically injected by the WebSSH2 server, but it can also be manually set or modified by users for customization purposes.
50
+
51
+ ### Basic Usage
52
+
53
+ In the client HTML file, you'll find this script tag:
54
+
55
+ ```html
56
+ <script>
57
+ window.webssh2Config = null;
58
+ </script>
59
+ ```
60
+
61
+ The WebSSH2 server replaces this null value with a configuration object. However, you can also set this manually to override server-provided settings or to configure the client when using it standalone.
62
+
63
+ ### Configuration Options
64
+
65
+ Here's a comprehensive list of parameters that can be injected using `window.webssh2Config`:
66
+
67
+ ```javascript
68
+ window.webssh2Config = {
69
+ socket: {
70
+ url: null, // WebSocket URL. If null, it will be automatically determined
71
+ path: '/ssh/socket.io', // Socket.IO path
72
+ },
73
+ ssh: {
74
+ host: null, // SSH server hostname (required for autoConnect)
75
+ port: 22, // SSH server port
76
+ username: null, // SSH username (required for autoConnect)
77
+ password: null, // SSH password (required for autoConnect)
78
+ sshTerm: 'xterm-color', // Terminal type
79
+ readyTimeout: 20000, // SSH connection timeout (ms)
80
+ },
81
+ terminal: {
82
+ cursorBlink: true, // Whether the cursor should blink
83
+ scrollback: 10000, // Number of rows to keep in scrollback
84
+ tabStopWidth: 8, // Tab width
85
+ bellStyle: 'sound', // Terminal bell style ('sound' or 'none')
86
+ fontSize: 14, // Font size in pixels
87
+ fontFamily: 'courier-new, courier, monospace', // Font family
88
+ letterSpacing: 0, // Letter spacing
89
+ lineHeight: 1, // Line height
90
+ },
91
+ header: {
92
+ text: null, // Custom header text
93
+ background: 'green', // Header background color
94
+ },
95
+ autoConnect: false, // Whether to connect automatically
96
+ logLevel: 'info', // Logging level ('debug', 'info', 'warn', 'error')
97
+ };
98
+ ```
99
+
100
+ ### Auto-Connect Functionality
101
+
102
+ The `autoConnect` option is used to create pre-configured connections:
103
+
104
+ - When set to `true`, the client will attempt to connect immediately using the provided SSH configuration, bypassing the login form.
105
+ - For `autoConnect` to work, you must provide at least the `host` in the SSH configuration.
106
+ - Username and password are optional for `autoConnect`. If not provided, the server may use other methods (like basic auth or session data) to authenticate the connection.
107
+ - If the host is missing when `autoConnect` is `true`, the login form will be shown instead.
108
+
109
+ Example usage:
110
+
111
+ ```javascript
112
+ window.webssh2Config = {
113
+ ssh: {
114
+ host: 'example.com',
115
+ port: 22,
116
+ username: 'user', // Optional
117
+ password: 'password' // Optional
118
+ },
119
+ autoConnect: true
120
+ };
121
+ ```
122
+
123
+ This configuration will attempt to connect to `example.com` as soon as the page loads, using any provided credentials or relying on server-side authentication methods.
124
+
125
+ ### Security Considerations
126
+
127
+ - The `autoConnect` feature only requires the host to be specified. Authentication is handled by the server, which may use various methods including basic auth or session data.
128
+ - If you do include username and password in the client-side configuration, be cautious as this may pose security risks, especially in production environments.
129
+ - For production use, consider using secure server-side authentication methods rather than including credentials in the client-side configuration.
130
+ - When `autoConnect` is not used, ensure that your server is configured to securely prompt for or handle credentials as needed.
131
+
132
+ ### Customization Examples
133
+
134
+ 1. Changing terminal appearance:
135
+ ```javascript
136
+ window.webssh2Config = {
137
+ terminal: {
138
+ fontSize: 16,
139
+ fontFamily: 'Fira Code, monospace',
140
+ cursorBlink: false
141
+ }
142
+ };
143
+ ```
144
+
145
+ 2. Setting a custom header:
146
+ ```javascript
147
+ window.webssh2Config = {
148
+ header: {
149
+ text: 'My Custom SSH Client',
150
+ background: '#007acc'
151
+ }
152
+ };
153
+ ```
154
+
155
+ 3. Configuring for a specific SSH server with auto-connect:
156
+ ```javascript
157
+ window.webssh2Config = {
158
+ ssh: {
159
+ host: 'myserver.example.com',
160
+ port: 2222
161
+ },
162
+ autoConnect: true
163
+ };
164
+ ```
165
+
166
+ By leveraging these configuration options, you can customize the WebSSH2 client to suit your specific needs or integrate it seamlessly into your existing systems. Remember that the server handles authentication, providing flexibility in how credentials are managed and secured.
167
+
168
+ ## Usage
169
+
170
+ ### Development
171
+
172
+ To start the development server:
173
+
174
+ ```
175
+ npm start
176
+ ```
177
+
178
+ This will run the application using `node index.js`.
179
+
180
+ To build the development version:
181
+
182
+ ```
183
+ npm run builddev
184
+ ```
185
+
186
+ This will use Webpack to build the development version of the application.
187
+
188
+ To watch for changes and rebuild automatically:
189
+
190
+ ```
191
+ npm run watch
192
+ ```
193
+
194
+ This will start the server and watch for file changes, rebuilding as necessary.
195
+
196
+ ### Production Build
197
+
198
+ To create a production build:
199
+
200
+ ```
201
+ npm run build
202
+ ```
203
+
204
+ This will generate optimized files for production using Webpack.
205
+
206
+ ### Analyze Bundle
207
+
208
+ To analyze the bundle size:
209
+
210
+ ```
211
+ npm run analyze
212
+ ```
213
+
214
+ This will generate a JSON report of the bundle and analyze its size.
215
+
216
+ ### Publishing
217
+
218
+ Before publishing, the package will automatically run the build script:
219
+
220
+ ```
221
+ npm publish
222
+ ```
223
+
224
+ This ensures that the latest production build is included in the published package.
225
+
226
+ ## Scripts
227
+
228
+ - `start`: Runs the application using Node.js
229
+ - `build`: Creates a production build using Webpack
230
+ - `builddev`: Creates a development build using Webpack
231
+ - `analyze`: Analyzes the bundle size
232
+ - `watch`: Runs the application and watches for changes, rebuilding as necessary
233
+ - `watch:build`: Watches for changes and rebuilds using Webpack (development config)
234
+ - `prepublishOnly`: Runs before publishing to ensure the latest build is included
235
+
236
+ ## URL Parameters
237
+
238
+ The WebSSH2 client supports various URL parameters to customize the SSH connection and terminal behavior. These parameters can be added to the URL when accessing the client.
239
+
240
+ ### SSH Connection Parameters
241
+
242
+ - `host`: The hostname or IP address of the SSH server to connect to.
243
+ - Example: `?host=192.168.1.1`
244
+
245
+ - `port`: The port number of the SSH server (default is 22).
246
+ - Example: `?port=2222`
247
+
248
+ - `username`: The username to use for SSH authentication.
249
+ - Example: `?username=admin`
250
+
251
+ - `password`: The password to use for SSH authentication (not recommended for production use).
252
+ - Example: `?password=secretpassword`
253
+
254
+ ### Terminal Configuration
255
+
256
+ - `sshTerm`: The terminal type to request (default is "xterm-color").
257
+ - Example: `?sshTerm=xterm-256color`
258
+
259
+ - `readyTimeout`: The timeout (in milliseconds) for the SSH handshake (default is 20000).
260
+ - Example: `?readyTimeout=30000`
261
+
262
+ - `cursorBlink`: Whether the cursor should blink (true/false).
263
+ - Example: `?cursorBlink=true`
264
+
265
+ - `scrollback`: The number of lines to keep in the scrollback buffer (default is 10000).
266
+ - Example: `?scrollback=5000`
267
+
268
+ - `tabStopWidth`: The width of tab stops (default is 8).
269
+ - Example: `?tabStopWidth=4`
270
+
271
+ - `bellStyle`: The style of the terminal bell ("sound" or "none", default is "sound").
272
+ - Example: `?bellStyle=none`
273
+
274
+ ### Display Options
275
+
276
+ - `fontSize`: The font size for the terminal (in pixels).
277
+ - Example: `?fontSize=14`
278
+
279
+ - `fontFamily`: The font family to use for the terminal.
280
+ - Example: `?fontFamily=Consolas,Monaco,Lucida%20Console,Liberation%20Mono,DejaVu%20Sans%20Mono,Bitstream%20Vera%20Sans%20Mono,Courier%20New,monospace`
281
+
282
+ - `letterSpacing`: The letter spacing for the terminal font.
283
+ - Example: `?letterSpacing=1`
284
+
285
+ - `lineHeight`: The line height for the terminal.
286
+ - Example: `?lineHeight=1.2`
287
+
288
+ ### UI Customization
289
+
290
+ - `header`: Custom text to display in the header.
291
+ - Example: `?header=My%20SSH%20Session`
292
+
293
+ - `headerBackground`: Background color for the header.
294
+ - Example: `?headerBackground=red`
295
+
296
+ ### Debugging
297
+
298
+ - `logLevel`: Sets the logging level for debugging purposes.
299
+ - Example: `?logLevel=debug`
300
+
301
+ ### Usage Example
302
+
303
+ A full URL with multiple parameters might look like this:
304
+
305
+ ```
306
+ http://localhost:2222/ssh/host/192.168.1.100?port=2222&header=Production%20Server&headerBackground=red&fontSize=14&bellStyle=none
307
+ ```
308
+
309
+ This URL would connect to a SSH server at 192.168.1.100 on port 2222, with a red header displaying "Production Server", using a 14px font size and disabling the audible bell.
310
+
311
+ Note: Be cautious about including sensitive information like passwords in URL parameters, especially in production environments.
312
+
313
+ ## Debugging
314
+
315
+ This project uses the `debug` module for logging. To enable debugging in the browser:
316
+
317
+ 1. Open the browser's console.
318
+ 2. Enter: `localStorage.debug = 'webssh2-client*'`
319
+ 3. Refresh the page.
320
+
321
+ To disable debugging, enter: `localStorage.debug = ''`
322
+
323
+ ## Contributing
324
+
325
+ Contributions are welcome! Please feel free to submit a Pull Request.
326
+
327
+ 1. Fork the repository
328
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
329
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
330
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
331
+ 5. Open a Pull Request
332
+
333
+ ## Style Guide
334
+
335
+ This project follows the Airbnb JavaScript Style Guide. Please ensure your contributions adhere to this style.
336
+
337
+ ## License
338
+
339
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
340
+
341
+ ## Acknowledgments
342
+
343
+ - [Xterm.js](https://xtermjs.org/) for providing the terminal emulator
344
+ - [Socket.IO](https://socket.io/) for real-time, bidirectional communication
345
+ - [Webpack](https://webpack.js.org/) for module bundling
@@ -0,0 +1,8 @@
1
+ // webssh2-client
2
+ // /client/index.js
3
+ const path = require('path');
4
+
5
+ module.exports = {
6
+ getPublicPath: () => path.join(__dirname, 'public'),
7
+ version: require('../package.json').version
8
+ };
@@ -0,0 +1,53 @@
1
+ <!-- Version Version 0.2.14 - 2024-07-19T13:56:58.848Z - 8055264 -->
2
+ <!-- webssh2-client -->
3
+ <!-- /client/src/client.htm -->
4
+ <!DOCTYPE html>
5
+ <html>
6
+ <head>
7
+ <title>WebSSH2</title>
8
+ <link rel="icon" type="image/x-icon" href="favicon.ico">
9
+ <script>
10
+ window.webssh2Config = null;
11
+ </script>
12
+ <script defer src="webssh2.bundle.js"></script><link href="webssh2.css" rel="stylesheet"></head>
13
+ <body>
14
+ <div id="loginModal" class="modal">
15
+ <div class="modal-content">
16
+ <h2>WebSSH2 Login</h2>
17
+ <form id="loginForm" class="pure-form pure-form-stacked">
18
+ <fieldset>
19
+ <input type="text" id="hostInput" placeholder="Hostname" required>
20
+ <input type="text" id="portInput" placeholder="Port" required>
21
+ <input type="text" id="usernameInput" placeholder="Username" required autocomplete="username">
22
+ <input type="password" id="passwordInput" placeholder="Password" required autocomplete="current-password">
23
+ <button type="submit" class="pure-button pure-button-primary">Connect</button>
24
+ </fieldset>
25
+ </form>
26
+ </div>
27
+ </div>
28
+ <div id="errorModal" class="modal">
29
+ <div class="modal-content error-modal">
30
+ <span class="close">&times;</span>
31
+ <h2>Error</h2>
32
+ <p id="errorMessage"></p>
33
+ </div>
34
+ </div>
35
+ <div class="box">
36
+ <div id="header"></div>
37
+ <div id="terminalContainer" class="terminal"></div>
38
+ <div id="bottomdiv">
39
+ <div class="dropup" id="menu">
40
+ <i class="fas fa-bars fa-fw"></i> Menu
41
+ <div id="dropupContent" class="dropup-content">
42
+ <button id="logBtn" class="menu-button"><i class="fas fa-clipboard fa-fw"></i> Start Log</button>
43
+ <button id="downloadLogBtn" class="menu-button"><i class="fas fa-download fa-fw"></i> Download Log</button>
44
+ <button id="credentialsBtn" class="menu-button"><i class="fas fa-key fa-fw"></i> Credentials</button>
45
+ <button id="reauthBtn" class="menu-button"><i class="fas fa-key fa-fw"></i> Switch User</button>
46
+ </div>
47
+ </div>
48
+ <div id="footer"></div>
49
+ <div id="status"></div>
50
+ </div>
51
+ </div>
52
+ </body>
53
+ </html>
Binary file