Giter Club home page Giter Club logo

caddy-cgi's People

Contributors

aksdb avatar jung-kurt avatar lukehsiao avatar mfashby avatar ueffel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

caddy-cgi's Issues

error when using both cgi and static files

Hello there!

I am attempting to build a docker image with caddy and your cgi extension. I have the cgi stuff working and I have the static html stuff working but I cannot get them to work together.

I am not sure if its something i'm doing within my caddyfile thats wrong, or if its some compatibility issue so I was hoping you would be able to suggest a fix:

my docker image uses /app as the working directory. And I copy two folders to it: ./cgi and ./public
Public has a static index.html and cgi has the script that I want to execute behind an and /api path.

To accomplish this I configure the caddy file like this:

{
    http_port 9054
    order cgi last
}

localhost:9054

cgi /cgi/* /app{path}
cgi /api/v1* /app/cgi/script.sh
root /* /app/public
file_server

This doesn't work. It only serves the static index file.

However if I comment out the root and file_server dirctive then cgi endpoints work as expected, but not the index.html.

How can I change my caddy file so that the cgi script works AND also serves static html content?

Thanks!

Issue with empty POST_DATA with Content-Type "application/x-www-form-urlencoded"

Hi,

I have a cgi call with method POST and content-type application/x-www-form-urlencoded.
The payload is two variables: sessionid and command.
sessionid is a uuid and command is %2Fusr%2Flibexec%2Fopkg-call%20list-available

I wrote a bash script to display everything and the HTTP_CONTENT_LENGTH variable has value 96 (which is correct) but the POST_DATA variable is not set.

Take from your documentation I built the following command:

wget -O - -q --post-data="sessionid=999999f9999998877665544332211007&command=%2Fusr%2Flibexec%2Fopkg-call%20list-available" http://192.168.1.2:8080/show/weekly?mode=summary

Inside my script I put printf "POST_DATA [%s]\n" $POST_DATA but it's always empty.

When putting inspect in the Placeholders I can not see http.request.body...

Could you help me to get the form data in my bash script?
This is the missing part to make OpenWrt LuCI work with Caddy 🙏

Caddy built from official website and here is the info:

caddy --version
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

SCRIPT_NAME is not stripped from PATH_INFO when a placeholder is used

When a SCRIPT_NAME environment variable containing a Caddy placeholder (e.g. regex) is defined inside the cgi directive, PATH_INFO is not stripped. For example:

I have a perl script, called as https://example.com/admin.pl/1234

I set SCRIPT_NAME to any placeholder, e.g.:

@perlFile path_regexp perlScript ^(/.*\.pl)

PATH_INFO is passed automatically, and it contains: /admin.pl/1234

According to RFC 3875, PATH_INFO should contain the path section after SCRIPT_NAME, up to the query string. Since it's optional, if a URL ends in SCRIPT_NAME, PATH_INFO may also remain empty.

I suspect that internally, the actual placeholder text is used, instead of the placeholder value.

Would it be possible to use the placeholder value instead?

I use Caddy v2.5.2, and Caddy-CGI v2, according to Caddy's download page.

Inspect returns:

CGI for Caddy inspection page

Executable .................... /usr/local/cgi-bin/admin.pl
Root .......................... /
Dir ........................... /usr/local/cgi-bin
Environment
  PATH_INFO ................... /admin.pl/1234
  REMOTE_USER ................. 
  SCRIPT_EXEC ................. /usr/local/cgi-bin/admin.pl 
  SCRIPT_FILENAME ............. /usr/local/cgi-bin/admin.pl
  SCRIPT_NAME ................. /admin.pl
  SERVER_PORT ................. 
Inherited environment
Placeholders
  {path} ...................... /admin.pl/1234
  {root} ...................... /
  {http.request.host} ......... example.com
  {http.request.method} ....... GET
  {http.request.uri.path} ..... /admin.pl/1234

404 in combination with file_server

When I'm using cgi together with file_server, i'm getting a 404 on cgi calls.

Im using the following Caddyfile

{
    order cgi last
    http_port 8081
}

localhost:8082 {
    root  *  D:\Mobile

   file_server browse

    cgi cgi-bin/cgiip.exe D:\Mobile\cgi-bin\cgiip.exe {
        script_name cgi-bin/cgiip.exe/
    }
}

Without the file_server section, cgi seems to be working fine. But no static content is delivered. :( My website is not working :(
With the file file_server section included, i'm getting a 404 on all cgi calls. The file_server tries to deliver the cgi-call as a file. My website is also not working :(

My website contains static content and in addition cgi calls to a third party software.

Any help appreciated. Is it a bug, or am I using it in a wrong way?

module declares its path as: github.com/jung-kurt/caddy-cgi

trying to compile caddy
xcaddy build --with github.com/aksdb/caddy-cgi

I got an error:
2023/10/16 13:01:46 [INFO] exec (timeout=0s): /usr/bin/go get -d -v github.com/aksdb/caddy-cgi github.com/caddyserver/caddy/v2
go: downloading github.com/aksdb/caddy-cgi v1.11.4
go: github.com/aksdb/caddy-cgi upgrade => v1.11.4
go get: github.com/aksdb/[email protected]: parsing go.mod:
module declares its path as: github.com/jung-kurt/caddy-cgi
but was required as: github.com/aksdb/caddy-cgi
2023/10/16 13:01:49 [FATAL] exit status 1

Please add short installation howto to README

Zoneminder issue when caddy runs as root

This plug-in seems to work fine when caddy is running as the www user.
But when caddy runs as root, the streams cut in and out.

I want to run caddy as root in order to bind port 80

{"level":"info","ts":1691180819.7048585,"msg":"cgi: bogus
header line: HTTP/1.0 200 OK"}
{"level":"info","ts":1691180821.219545,"msg":"cgi: copy e
rror: write tcp 192.168.1.156:8000->192.168.1.188:56076:
write: broken pipe"}

This is the error that keeps happening.

CGI error: fork/exec (File not found on Windows)

But i’m running on an error while runnning on windows.
It does not matter in which format I enter the exe/script.

C:\Windows\system32\hostname.exe does exist

Caddy version: v2.7.6

caddy run --config Caddyfile
2024/02/07 09:59:31.872 INFO    using provided configuration    {"config_file": "Caddyfile", "config_adapter": ""}
2024/02/07 09:59:31.876 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2024/02/07 09:59:31.876 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc000130d00"}
2024/02/07 09:59:31.876 INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2024/02/07 09:59:31.876 INFO    autosaved config (load with --resume flag)      {"file": "C:\\Users\\...\\AppData\\Roaming\\Caddy\\autosave.json"}
2024/02/07 09:59:31.877 INFO    serving initial configuration
2024/02/07 09:59:31.879 WARN    tls     storage cleaning happened too recently; skipping for now        {"storage": "FileStorage:C:\\Users\\...\\AppData\\Roaming\\Caddy", "instance": "0689bf7e-c42b-4533-9c97-07daf87cc2c0", "try_again": "2024/02/08 09:59:31.879", "try_again_in": 86400}
2024/02/07 09:59:31.879 INFO    tls     finished cleaning storage units
2024/02/07 09:59:33.781 INFO    CGI error: fork/exec .\hostname.exeC:\Windows\system32\hostname.exe: Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.

Caddyfile

{
	order cgi before respond
}

:2015

cgi /update hostname.exe {
	#script_name /script.cgi
}

Edit:
Outlput with "inspect"

CGI for Caddy inspection page

Executable .................... hostname.exe
Root .......................... /
Dir ........................... 
Environment
  PATH_INFO ................... /update
  REMOTE_USER ................. 
  SCRIPT_EXEC ................. hostname.exe 
  SCRIPT_FILENAME ............. hostname.exe
  SCRIPT_NAME ................. 
Inherited environment
Placeholders
  {path} ...................... /update
  {root} ...................... /
  {http.request.host} ......... localhost
  {http.request.method} ....... GET
  {http.request.uri.path} ..... /update

Error when builing module

Hello, when I try to build the module with xcaddy, I get an error :/

uzanto@veil:/etc/nginx/sites-enabled$ xcaddy build --with github.com/aksdb/caddy-cgi
2021/08/17 12:01:21 [INFO] Temporary folder: /tmp/buildenv_2021-08-17-1201.682109676
2021/08/17 12:01:21 [INFO] Writing main module: /tmp/buildenv_2021-08-17-1201.682109676/main.go
2021/08/17 12:01:21 [INFO] Initializing Go module
2021/08/17 12:01:21 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init caddy 
go: creating new go.mod: module caddy
go: to add module requirements and sums:
	go mod tidy
2021/08/17 12:01:21 [INFO] Pinning versions
2021/08/17 12:01:21 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2 
go get: added github.com/beorn7/perks v1.0.1
go get: added github.com/caddyserver/caddy/v2 v2.4.3
go get: added github.com/caddyserver/certmagic v0.14.0
go get: added github.com/cespare/xxhash/v2 v2.1.1
go get: added github.com/golang/protobuf v1.5.2
go get: added github.com/google/uuid v1.2.0
go get: added github.com/klauspost/cpuid/v2 v2.0.6
go get: added github.com/libdns/libdns v0.2.1
go get: added github.com/matttproud/golang_protobuf_extensions v1.0.1
go get: added github.com/mholt/acmez v0.1.3
go get: added github.com/miekg/dns v1.1.42
go get: added github.com/prometheus/client_golang v1.10.1-0.20210603120351-253906201bda
go get: added github.com/prometheus/client_model v0.2.0
go get: added github.com/prometheus/common v0.26.0
go get: added github.com/prometheus/procfs v0.6.0
go get: added go.uber.org/atomic v1.7.0
go get: added go.uber.org/multierr v1.6.0
go get: added go.uber.org/zap v1.17.0
go get: added golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
go get: added golang.org/x/net v0.0.0-20210525063256-abc453219eb5
go get: added golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40
go get: added golang.org/x/term v0.0.0-20210503060354-a79de5458b56
go get: added golang.org/x/text v0.3.6
go get: added google.golang.org/protobuf v1.26.0
2021/08/17 12:01:22 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/aksdb/caddy-cgi 
go: downloading github.com/aksdb/caddy-cgi v1.11.4
go get: github.com/aksdb/[email protected]: parsing go.mod:
	module declares its path as: github.com/jung-kurt/caddy-cgi
	        but was required as: github.com/aksdb/caddy-cgi
2021/08/17 12:01:23 [FATAL] exit status 1

Upstream possible?

Is there a way to get this upstreamed into Caddy so that we don't have to make a custom build to use it?

Module does not build anymore

Seems to be this issue - probably caused by bumping dependencies?

$ xcaddy build --with github.com/aksdb/caddy-cgi/v2 |& gh gist create
✓ Created gist
https://gist.github.com/werdnum/513d0b8a72a38b65437a62f142012e48

In particular:

2023/11/23 14:42:38 [INFO] exec (timeout=0s): /usr/local/bin/go build -o /Users/andrew/caddy -ldflags -w -s -trimpath
# github.com/caddyserver/caddy/v2/modules/caddyhttp
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:462:9: cannot use func(eh parser.ExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *common.Error) {…} (value of type func(eh parser.ExprHelper, target *expr.Expr, args []*expr.Expr) (*expr.Expr, *common.Error)) as parser.MacroExpander value in return statement
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:479:13: eh.GlobalCall undefined (type parser.ExprHelper has no field or method GlobalCall)
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:479:37: eh.Ident undefined (type parser.ExprHelper has no field or method Ident)
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:479:66: cannot use matchArgs (variable of type []*expr.Expr) as []ast.Expr value in argument to eh.NewList
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:488:9: cannot use func(eh parser.ExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *common.Error) {…} (value of type func(eh parser.ExprHelper, target *expr.Expr, args []*expr.Expr) (*expr.Expr, *common.Error)) as parser.MacroExpander value in return statement
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:495:14: eh.GlobalCall undefined (type parser.ExprHelper has no field or method GlobalCall)
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:495:38: eh.Ident undefined (type parser.ExprHelper has no field or method Ident)
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:509:9: cannot use func(eh parser.ExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *common.Error) {…} (value of type func(eh parser.ExprHelper, target *expr.Expr, args []*expr.Expr) (*expr.Expr, *common.Error)) as parser.MacroExpander value in return statement
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:545:14: eh.GlobalCall undefined (type parser.ExprHelper has no field or method GlobalCall)
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:545:38: eh.Ident undefined (type parser.ExprHelper has no field or method Ident)
../go/pkg/mod/github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/celmatcher.go:545:38: too many errors
2023/11/23 14:43:48 [INFO] Cleaning up temporary folder: /Users/andrew/buildenv_2023-11-23-1439.1035174675

Q about uid/gid permissions

Is it correct that this Caddy plugin runs the CGI process it launches as root?
Is there a way to avoid this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.