Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Variable replace possibility #17

Merged
merged 1 commit into from
Feb 15, 2023

Conversation

git001
Copy link
Contributor

@git001 git001 commented May 4, 2022

Solve #7

@richcorbs
Copy link

This looks sooooo useful to me. Any update?

@git001
Copy link
Contributor Author

git001 commented Dec 12, 2022

Well I have add this feature to my fork https://github.com/git001/caddy-exec as I don't know if the PR will be merged.

@richcorbs
Copy link

Thanks @git001! I'm new to caddy and go. I have go built with the abiosoft version of caddy-exec. How can I build it with your version?

@yroc92
Copy link

yroc92 commented Dec 12, 2022

@richcorbs should be xcaddy --with github.com/git001/caddy-exec

@git001
Copy link
Contributor Author

git001 commented Dec 13, 2022

@richcorbs as @yroc92 written can you create your own caddy version with xcaddy you can add with --with ... any further module you want from the https://caddyserver.com/download list.

@richcorbs
Copy link

Thank you both for the help.

What's the syntax? This is what I'm trying:

http://localhost {
         route /check {
                 exec /check /bin/ls /var/www/{query domain} {
                         foreground true
                         status 404 on error
                 }
         }
}

When I curl that route with ?domain=abc.com I get this error and the placeholders aren't interpolated properly:

2022/12/13 04:55:28.937	ERROR	http.handlers.exec.exit		{"command": ["exec", "/bin/ls", "/var/www/{query", "domain}"], "duration": 0.000353293, "error": "exec: \"exec\": executable file not found in $PATH"}

@git001
Copy link
Contributor Author

git001 commented Dec 13, 2022

Please try to use "/var/www/{query domain}" it's just the same as every other placeholder usage.
https://caddyserver.com/docs/conventions#placeholders

@richcorbs
Copy link

richcorbs commented Dec 13, 2022

Progress! I tried using query.domain instead of query domain and it seems to have parsed the command properly! Thanks for that! The output on the server is now:

2022/12/13 10:54:04.997	ERROR	http.handlers.exec.exit		{"command": ["exec", "/bin/ls", "/var/www/abc.com"], "duration": 0.000318644, "error": "exec: \"exec\": executable file not found in $PATH"}

I'm still getting "error": "exec: \"exec\": executable file not found in $PATH". Does this imply that there is something wrong with my go environment?

Where does "exec" come from in the command array? It wasn't there in the output when I tried using the abiososft version?

@git001
Copy link
Contributor Author

git001 commented Dec 13, 2022

well exec is wrong here. just use /bin/ls.

@richcorbs
Copy link

richcorbs commented Dec 13, 2022 via email

@richcorbs
Copy link

Is it possible that caddy-exec is adding in "exec" somehow?

Do you have a working configuration you could share with me?

@richcorbs
Copy link

I had an idea. Is this only supported in the .json config file and not in a Caddyfile?

@richcorbs
Copy link

I got around the exec issue in the OS by linking exec to /bin/sh and it works. Kind of.

Whatever querystring is passed the first time is what it remembers for every execution after that. I was hoping it might be dynamic on every request.

@git001
Copy link
Contributor Author

git001 commented Dec 15, 2022

I had an idea. Is this only supported in the .json config file and not in a Caddyfile?

Yes I have tested it only with json version.

@Omicron7
Copy link

@abiosoft Any chance of getting this merged? It would be extremely helpful to be able to replace {placeholders} in the exec command/args.

Omicron7 referenced this pull request in git001/caddy-exec Feb 15, 2023
@abiosoft abiosoft merged commit ce4098e into abiosoft:master Feb 15, 2023
@abiosoft
Copy link
Owner

@abiosoft Any chance of getting this merged? It would be extremely helpful to be able to replace {placeholders} in the exec command/args.

Done ✅

@Omicron7
Copy link

@abiosoft Thanks

@ltd
Copy link

ltd commented Apr 26, 2023

I'm still seeing that placeholders are not dynamic, is this working for others?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants