{"modulePath":"github.com/msoap/shell2http","version":"v1.18.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package main\n\nExecuting shell commands via simple http server. Settings through 2 command line arguments, path and shell command. By default bind to :8080.\n\nInstall/update:\n\n\tgo get -u github.com/msoap/shell2http\n\tln -s $GOPATH/bin/shell2http ~/bin/shell2http\n\nMacOS install:\n\n\tbrew tap msoap/tools\n\tbrew install shell2http\n\t# update:\n\tbrew upgrade shell2http\n\nUsage:\n\n\tshell2http [options] /path \"shell command\" /path2 \"shell command2\" ...\n\toptions:\n\t\t-host=\"host\"      : host for http server, default - all interfaces\n\t\t-port=NNNN        : port for http server, 0 - to receive a random port, default - 8080\n\t\t-form             : parse query into environment vars, handle uploaded files\n\t\t-form-check       : regexp for check form fields (pass only vars that match the regexp)\n\t\t-cgi              : run scripts in CGI-mode:\n\t\t                    - set environment variables with HTTP-request information\n\t\t                    - write POST|PUT|PATCH-data to script STDIN (if not set -form)\n\t\t                    - parse headers from script (eg: \"Location: URL\\n\\n\")\n\t\t-export-vars=var  : export environment vars (\"VAR1,VAR2,...\")\n\t\t-export-all-vars  : export all current environment vars\n\t\t-no-index         : don't generate index page\n\t\t-add-exit         : add /exit command\n\t\t-log=filename     : log filename, default - STDOUT\n\t\t-shell=\"shell\"    : shell for execute command, \"\" - without shell\n\t\t-cache=N          : caching command out for N seconds\n\t\t-one-thread       : run each shell command in one thread\n\t\t-show-errors      : show the standard output even if the command exits with a non-zero exit code\n\t\t-include-stderr   : include stderr to output (default is stdout only)\n\t\t-500              : return 500 error if shell exit code != 0\n\t\t-cert=cert.pem    : SSL certificate path (if specified -cert/-key options - run https server)\n\t\t-key=key.pem      : SSL private key path\n\t\t-basic-auth=\"\"\t  : setup HTTP Basic Authentication (\"user_name:password\"), can be used several times\n\t\t-timeout=N        : set timeout for execute shell command (in seconds)\n\t\t-no-log-timestamp : log output without timestamps\n\t\t-version\n\t\t-help\n\nIn the \"-form\" mode, variables are available for shell scripts:\n\n  - $v\\_NNN -- data from query parameter with name \"NNN\" (example: \\`[http://localhost:8080/path?NNN=123](http://localhost:8080/path?NNN=123)\\`)\n  - $filepath\\_ID -- uploaded file path, ID - id from \\`\\\u003cinput type=file name=ID\u003e\\`, temporary uploaded file will be automatically deleted\n  - $filename\\_ID -- uploaded file name from browser\n\nTo setup multiple auth users, you can specify the -basic-auth option multiple times. The credentials for basic authentication may also be provided via the SH\\_BASIC\\_AUTH environment variable. You can specify the preferred HTTP-method (via \"METHOD:\" prefix for path): shell2http GET:/date date\n\nExamples:\n\n\tshell2http /top \"top -l 1 | head -10\"\n\tshell2http /date date /ps \"ps aux\"\n\tshell2http -export-all-vars /env 'printenv | sort' /env/path 'echo $PATH' /env/gopath 'echo $GOPATH'\n\tshell2http -export-all-vars /shell_vars_json 'perl -MJSON -E \"say to_json(\\%ENV)\"'\n\tshell2http /cal_html 'echo \"\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eCalendar\u003c/h1\u003eDate: \u003cb\u003e$(date)\u003c/b\u003e\u003cbr\u003e\u003cpre\u003e$(cal $(date +%Y))\u003c/pre\u003e\u003c/body\u003e\u003c/html\u003e\"'\n\tshell2http -form /form 'echo $v_from, $v_to'\n\tshell2http -cgi /user_agent 'echo $HTTP_USER_AGENT'\n\tshell2http -cgi /set 'touch file; echo \"Location: /\\n\"'\n\tshell2http -cgi /404 'echo \"Status: 404\"; echo; echo \"404 page\"'\n\tshell2http -export-vars=GOPATH /get 'echo $GOPATH'\n\nMore complex examples:\n\nUpload file:\n\n\tshell2http -form \\\n\t\t/form 'echo \"\u003chtml\u003e\u003cbody\u003e\u003cform method=POST action=/file enctype=multipart/form-data\u003e\u003cinput type=file name=uplfile\u003e\u003cinput type=submit\u003e\u003c/form\u003e\"' \\\n\t\t/file 'cat $filepath_uplfile \u003e uploaded_file.dat; echo Ok'\n\nSimple http-proxy server (for logging all URLs)\n\n\t# setup proxy as \"http://localhost:8080/\"\n\tshell2http \\\n\t\t-log=/dev/null \\\n\t\t-cgi \\\n\t\t/ 'echo $REQUEST_URI 1\u003e\u00262; [ \"$REQUEST_METHOD\" == \"POST\" ] \u0026\u0026 post_param=\"-d@-\"; curl -sL $post_param \"$REQUEST_URI\" -A \"$HTTP_USER_AGENT\"'\n\nTest slow connection\n\n\t# http://localhost:8080/slow?duration=10\n\tshell2http -form /slow 'sleep ${v_duration:-1}; echo \"sleep ${v_duration:-1} seconds\"'\n\nProxy with cache in files (for debug with production API with rate limit)\n\n\t# get \"http://localhost:8080/get?url=http://api.url/\"\n\tshell2http \\\n\t\t-form \\\n\t\t/form 'echo \"\u003chtml\u003e\u003cform action=/get\u003eURL: \u003cinput name=url\u003e\u003cinput type=submit\u003e\"' \\\n\t\t/get 'MD5=$(printf \"%s\" $v_url | md5); cat cache_$MD5 || (curl -sL $v_url | tee cache_$MD5)'\n\nRemote sound volume control (Mac OS)\n\n\tshell2http \\\n\t\t/get  'osascript -e \"output volume of (get volume settings)\"' \\\n\t\t/up   'osascript -e \"set volume output volume (($(osascript -e \"output volume of (get volume settings)\")+10))\"' \\\n\t\t/down 'osascript -e \"set volume output volume (($(osascript -e \"output volume of (get volume settings)\")-10))\"'\n\nRemote control for Vox.app player (Mac OS)\n\n\tshell2http \\\n\t\t/play_pause 'osascript -e \"tell application \\\"Vox\\\" to playpause\" \u0026\u0026 echo ok' \\\n\t\t/get_info 'osascript -e \"tell application \\\"Vox\\\"\" -e \"\\\"Artist: \\\" \u0026 artist \u0026 \\\"\\n\\\" \u0026 \\\"Album: \\\" \u0026 album \u0026 \\\"\\n\\\" \u0026 \\\"Track: \\\" \u0026 track\" -e \"end tell\"'\n\nGet four random OS X wallpapers\n\n\tshell2http \\\n\t\t/img 'cat \"$(ls \"/Library/Desktop Pictures/\"*.jpg | ruby -e \"puts STDIN.readlines.shuffle[0]\")\"' \\\n\t\t/wallpapers 'echo \"\u003chtml\u003e\u003ch3\u003eOS X Wallpapers\u003c/h3\u003e\"; seq 4 | xargs -I@ echo \"\u003cimg src=/img?@ width=500\u003e\"'\n\nMore examples on [https://github.com/msoap/shell2http/wiki](https://github.com/msoap/shell2http/wiki)\n\n## Types\n\n```go\ntype Config struct {\n\t// contains filtered or unexported fields\n}\n```\nConfig - config struct\n\n","path":"github.com/msoap/shell2http","name":"main","synopsis":"Executing shell commands via simple http server.","isRedistributable":true}
