{"id":15113696,"url":"https://github.com/max1220/cgi_command","last_synced_at":"2026-01-20T02:21:40.193Z","repository":{"id":256318567,"uuid":"854902217","full_name":"max1220/cgi_command","owner":"max1220","description":"CGI script and JS library for arbitrary command execution. Supports streaming responses using Server Sent Events.","archived":false,"fork":false,"pushed_at":"2024-09-10T02:13:38.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T15:26:29.336Z","etag":null,"topics":["bash","cgi-script","javascript-library"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/max1220.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-10T00:45:56.000Z","updated_at":"2024-09-10T02:26:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8a220da-47d1-4615-80c4-aea8c26cd537","html_url":"https://github.com/max1220/cgi_command","commit_stats":null,"previous_names":["max1220/cgi_command"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max1220%2Fcgi_command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max1220%2Fcgi_command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max1220%2Fcgi_command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max1220%2Fcgi_command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/max1220","download_url":"https://codeload.github.com/max1220/cgi_command/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378140,"owners_count":20929297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","cgi-script","javascript-library"],"created_at":"2024-09-26T01:22:21.353Z","updated_at":"2026-01-20T02:21:40.167Z","avatar_url":"https://github.com/max1220.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cgi_command\n\nThis library and CGI script is designed to execute arbitrary commands via CGI.\n\nIt is designed to provide simple shell script-like administration/automation\nfunctionality for the browser with a dead-simple bash CGI-based backend.\n\nThe JavaScript part of this library makes common operations\n(such as getting a complete response from a command, streaming a response,\nuploading/downloading files from the server, etc.)\neasy, and the CGI script serves as the backend for this.\n\nThe CGI script is designed to be as flexible as possible,\nand can set any response headers, including content-type, allows setting\nenvironment variables and changing directories before executing,\nsupports various encodings(such as an unmodified, event stream, base64),\nand allows all HTTP methods(parameters are always URL-encoded).\n\n\n\n# cgi-bin/cgi_command.sh\n\nThis is the server-side CGI script that runs the command and encodes the output.\n\n\n## !!! WARNING !!!\n\nWarning: Leaving this CGI script runnable unprotected is obviously very dangerous!\n\nIt should almost always be protected by some sort of authentication.\nGiving access to this script should be treated the same as giving access to\na shell belonging to the user that runs the CGI script.\n\n\n## Requirements\n\nThis CGI script just requires basic shell tools(bash, coreutils), and a\nCGI capable webserver.\n\nFor testing, it is convenient to use the BusyBox httpd server.\nAn example configuration `busybox_httpd.conf` file is provided.\n\nYou can start a test instance like this(from this directory):\n\n```\nbusybox httpd -v -f -p 127.0.0.1:8080 -c busybox_httpd.conf\n```\n\nYou should change the default username/password(`user`/`password`) in `busybox_httpd.conf`.\n\n\n## nginx\n\nIf you want to use nginx to host this script, you can use fcgiwrapd to listen\nfor fcgi requests on a unix socket, and have that run the CGI script.\nThis makes it easy to export the shell as another user as well\n(www-data probably has shell access disabled). Make sure fcgiwrapd has multiple\nprocesses preforked.\n\nYou need to make sure to disable buffering as well, or you can't properly\nstream the responses using the server-sent events/EventSource mechanism.\n\nSee the included `nginx.conf` for an example.\n\n\n## QUERY_STRING parameters\n\nSupported parameters in the QUERY_STRING. Some options can be specified multiple times.\n\n * `cmd` - command to run(required, can be specified multiple times to supply arguments)\n * `encoding` - One of \"eventstream_bytes\", \"eventstream_lines\", \"base64\" or \"none\"(required)\n * `header` - A header to include(complete \"Header: value\" line, can be specified multiple times)\n * `env` - Export an environment variable(in exports \"ENV_VAR=value\" format)\n * `cwd` - Change working directory before running command\n * `content_type` - If set, respond with the specified Content-Type. Defaults to text/plain\n * `merge_stderr` - If set to true, stderr is merged with stdout\n\n\n\n# CgiCommand.js\n\nThis JavaScript library contains the base functionality for generating URLs and\nexecuting requests to the CGI script.\n\n\n## `CgiCommand` Constructor\n\nThe constructor arguments are put into the properties, and never used directly.\n\n```\nCgiCommand(command, base_url=CGI_BACKEND, encoding=\"none\", headers=[], env=[], content_type=\"text/plain\", merge_stderr=true)\n```\n\n\n## Properties\n\n * command\n * base_url\n * encoding\n * headers\n * env\n * merge_stderr\n * content_type\n\n\n## Methods\n\nAll methods make use of properties, not constructor arguments directly.\n\n * get_url()\n   - Return the URL base on the current properties\n * xhr_sync(method=\"GET\", body)\n   - Perform a synchronous XHR, and return the request\n * xhr(method=\"GET\", body, resp_cb, progress_cb)\n   - Perform an asynchronous XHR, and register the callback(returns the request immediately)\n * stream(open_cb, data_cb, ret_cb)\n   - Start streaming events using the Server-Sent Events/EventSource() mechanism.\n\n\n\n# ShellUtils.js\n\nThis JavaScript library contains shell related utillity functions.\n\nThese basic utillity functions use synchronous XHRs and are intended to provide\nsimple shell script-like administration/automation functionality for the browser.\n\n\n## escape_shell(str) \n\nescape shell special characters in str.\n\n\n## `ShellUtils` Constructor\n\nYou need to provide the URL to the `cgi_command.sh` script as the only parameter.\n\n```\nShellUtils(base_url)\n```\n\n\n## Properties\n\nThe only property of a ShellUtils instance is `base_url`, which is used for\ncreating the requests.\n\n\n## Methods\n\nAll methods use synchronous XHRs.\n\n * run(cmd, body)\n   - Runs the command(array of strings), optionally with body sent to stdin\n * run_script(script_str)\n   - Runs the script_str by providing it on stdin to bash.\n * upload_to_path(data, path)\n   - Upload the specified data(string) to path\n * get_file_url(path, content_type=\"application/octet-stream\")\n   - Get a URL to this file on the server(`cat $path` with content_type)\n * get_env()\n   - Get the parsed environment the CGI script runs with(`printenv`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmax1220%2Fcgi_command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmax1220%2Fcgi_command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmax1220%2Fcgi_command/lists"}