@@ -301,100 +301,3 @@ For security reasons, only the following commands are allowed in the REST API:
3013015 . ** Production Use** : This server is designed for development/testing. Use with caution in production environments
3023026 . ** Network Access** : Consider implementing authentication and HTTPS for production use
3033037 . ** Session Isolation** : Each web terminal session is isolated and cleaned up properly
304-
305- ## Configuration
306-
307- ### Environment Variables
308-
309- - ` PORT ` - Server port (default: 8080)
310-
311- ## Examples
312-
313- ### Python Integration
314-
315- ``` python
316- import requests
317-
318- def execute_command (command , json_response = False ):
319- url = " http://localhost:8080/execute"
320- headers = {" Accept" : " application/json" } if json_response else {}
321- response = requests.post(url, data = command, headers = headers)
322-
323- if json_response:
324- return response.json()
325- else :
326- return response.text
327-
328- # Example usage - raw output
329- output = execute_command(" ls -la" )
330- print (output)
331-
332- # Example usage - JSON response
333- result = execute_command(" pwd" , json_response = True )
334- print (f " Success: { result[' success' ]} " )
335- print (f " Output: { result[' output' ]} " )
336- print (f " Command: { result[' command' ]} " )
337- ```
338-
339- ### JavaScript/Node.js Integration
340-
341- ``` javascript
342- async function executeCommand (command , jsonResponse = false ) {
343- const headers = jsonResponse ? { ' Accept' : ' application/json' } : {};
344-
345- const response = await fetch (' http://localhost:8080/execute' , {
346- method: ' POST' ,
347- headers,
348- body: command
349- });
350-
351- if (jsonResponse) {
352- return await response .json ();
353- } else {
354- return await response .text ();
355- }
356- }
357-
358- // Example usage - raw output
359- executeCommand (' pwd' )
360- .then (output => console .log (output));
361-
362- // Example usage - JSON response
363- executeCommand (' ls -la' , true )
364- .then (result => {
365- console .log (' Success:' , result .success );
366- console .log (' Output:' , result .output );
367- console .log (' Command:' , result .command );
368- });
369- ```
370-
371- ### Shell Script Integration
372-
373- ``` bash
374- #! /bin/bash
375-
376- # Function to execute command via HTTP (raw output)
377- execute_via_http () {
378- local command=" $1 "
379- curl -s -X POST http://localhost:8080/execute -d " $command "
380- }
381-
382- # Function to execute command via HTTP (JSON response)
383- execute_via_http_json () {
384- local command=" $1 "
385- curl -s -X POST http://localhost:8080/execute \
386- -H " Accept: application/json" \
387- -d " $command " | jq -r ' .output'
388- }
389-
390- # Example usage - raw output
391- echo " Current directory:"
392- execute_via_http " pwd"
393-
394- echo " Files in current directory:"
395- execute_via_http " ls -la"
396-
397- # Example usage - JSON response
398- echo " System info:"
399- execute_via_http_json " uname -a"
400- ```
0 commit comments