Comments (5)
@zicjin of course,
you can add any http header to output of your shell script including CORS.
for example:
shell2http -cgi /cors 'echo "Access-Control-Allow-Origin: *\n"; echo date:; date'
request/response:
$ curl -i http://localhost:8080/cors
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Server: shell2http dev
X-Shell2http-Exit-Code: 0
Date: Sun, 14 Jul 2024 12:21:57 GMT
Content-Length: 36
Content-Type: text/plain; charset=utf-8
date:
Sun Jul 14 15:21:57 EEST 2024
from shell2http.
@msoap Thank you for your patience.
How can I get cgi to incorporate the output of shell commands instead of simply 'date'.
I would like to make this /ping api support cors:
shell2http -form /ping 'ping -c 3 -w 2 $v_ip'
shell2http -cgi -form /ping 'echo "Access-Control-Allow-Origin: *\n"; echo date:; ping -n 3 -w 2 $v_ip'
But the above modification is not working.
from shell2http.
could you please show how it not working?
for me working that command:
$ shell2http -cgi -form /ping 'echo "Access-Control-Allow-Origin: *\n"; ping -c 2 $v_ip'
2024/07/14 17:46:39 register: /ping (echo "Access-Control-Allow-Origin: *\n"; ping -c 2 $v_ip)
2024/07/14 17:46:39 register: / (index page)
2024/07/14 17:46:39 listen http://localhost:8080/
2024/07/14 17:47:02 localhost:8080 [::1]:54818 "GET /ping?ip=127.0.0.1" 200 310 "curl/8.6.0" 1.014s
2024/07/14 17:48:03 localhost:8080 [::1]:54827 "GET /ping?ip=127.0.0.1" 200 310 "curl/8.6.0" 1.011s
$ curl -i 'http://localhost:8080/ping?ip=127.0.0.1'
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Server: shell2http dev
X-Shell2http-Exit-Code: 0
Date: Sun, 14 Jul 2024 14:48:03 GMT
Content-Length: 310
Content-Type: text/plain; charset=utf-8
PING 127.0.0.1 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.066 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.204 ms
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.066/0.135/0.204/0.069 ms
from shell2http.
@msoap Use your script to launch shell2http. Create a cross-domain request using fetch() on any web page will still be blocked.
shell2http -cgi -form /ping 'echo "Access-Control-Allow-Origin: *\n"; ping -c 2 $v_ip'
You can see there is no "Access-Control-Allow-Origin: *" in the response header.
but if the request is created with an empty web page or curl, "Access-Control-Allow-Origin: *" will appear in the response header.
from shell2http.
@zicjin shell2http can return any kind of http-headers, it's no different from any other server, this means there is cors support. But support of CORS also depends on the page(host) from which the request originates. Please use advice from chatgpt:
![image](https://private-user-images.githubusercontent.com/844117/348631687-b6c72a25-9db8-4ea3-bd0c-143c8d7cbb39.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMzODI3ODQsIm5iZiI6MTcyMzM4MjQ4NCwicGF0aCI6Ii84NDQxMTcvMzQ4NjMxNjg3LWI2YzcyYTI1LTlkYjgtNGVhMy1iZDBjLTE0M2M4ZDdjYmIzOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxMVQxMzIxMjRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xOTAyNTdhZjA5OTRlYzc3NjMzNTc2OGJhZTliZDQ4MTU2YTE5NGY2ZjVjNWRlZGNmNmI4NWNiNzVjYjQwNzY5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9._1QEBLxVzQBVu6hmEFP92Vy1rVNJ_t3gA58KP1clrkg)
from shell2http.
Related Issues (20)
- Passing Spaces in `$v_params` to Command HOT 3
- "No such file or directory" err HOT 3
- How can get request body from command? (question) HOT 2
- Parsing of ASCII encoding not working for all characters HOT 1
- Create new shell2http binaries to solve CVE-2016-2183 HOT 3
- support async call on windows HOT 2
- Support parameter transfer command HOT 2
- What are these logs? HOT 1
- I would like to prohibit executing some commands when using shell2http HOT 1
- Regarding Required Installation and Operation Storage Space HOT 1
- Ability to define multiple endpoints in dockerfile HOT 1
- Support configuration file method HOT 5
- Using a POST request to write JSON to script stdin HOT 1
- Create routes to shell mappings using JSON HOT 1
- Documentation for docker should include details about using --init HOT 2
- Streaming endpoints HOT 2
- logging to file does not include stderr from shell commands HOT 2
- may support read cig/shell script from file HOT 1
- Latest docker images (latest, 1.16.0, 1.15.0) don't work on arm64 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shell2http.