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

Alternative approach using sed and some for loop variables #12

Open
jessuppi opened this issue Aug 8, 2023 · 0 comments
Open

Alternative approach using sed and some for loop variables #12

jessuppi opened this issue Aug 8, 2023 · 0 comments

Comments

@jessuppi
Copy link

jessuppi commented Aug 8, 2023

Hello @ergin and thank you very much for your work on this script, I came across it a few times and finally implemented your research into my SlickStack script after several users asked for it.

This is not so much a feature request, but in case you wanted to share an alternative way to build cloudflare.conf using sed and an existing boilerplate, it seems to work okay...

Ref: https://github.com/littlebizzy/slickstack/blob/master/bash/ss-install-nginx-cloudflare-ips.txt

## ipv4 list ##
CLOUDFLARE_IPV4_LIST=$(for i in `curl -s -L https://www.cloudflare.com/ips-v4`; do
    echo "set_real_ip_from $i;" >> /tmp/ips-v4.txt;
done)

sed -i -e '/@CLOUDFLARE_IPV4_LIST/{r /tmp/ips-v4.txt' -e 'd' -e '}' "${TMP_CLOUDFLARE_CONF}"

## ipv6 list ##
CLOUDFLARE_IPV6_LIST=$(for i in `curl -s -L https://www.cloudflare.com/ips-v6`; do
    echo "set_real_ip_from $i;" >> /tmp/ips-v6.txt;
done)

sed -i -e '/@CLOUDFLARE_IPV6_LIST/{r /tmp/ips-v6.txt' -e 'd' -e '}' "${TMP_CLOUDFLARE_CONF}"

This is an example boilerplate:

https://github.com/littlebizzy/slickstack/blob/master/modules/nginx/includes/cloudflare-conf.txt

And the placeholders in the boilerplate @CLOUDFLARE_IPV4_LIST and @CLOUDFLARE_IPV6_LIST get replaced via sed using your nifty bash for loop and a few tmp files.

Anyway I had never used sed this way before so just wanted to share. Thanks!

P.S. we credited you in the script comments at the bottom

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

No branches or pull requests

1 participant