/[smeserver]/rpms/smeserver-manager/sme10/smeserver-manager-0.1.4-add-in-letsencrypt-scripts-and-getmyip.patch
ViewVC logotype

Annotation of /rpms/smeserver-manager/sme10/smeserver-manager-0.1.4-add-in-letsencrypt-scripts-and-getmyip.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Mon Dec 9 16:45:58 2024 UTC (2 months, 1 week ago) by brianr
Branch: MAIN
CVS Tags: smeserver-manager-0_1_4-36_el7_sme, HEAD
* Mon Dec 09 2024 Brian Read <brianr@koozali.org> 0.1.4-36.sme
- Add in letsencrypt scripts and getmyip [SME: ]

1 brianr 1.1 diff -urN smeserver-manager-0.1.4.old/root/etc/e-smith/events/actions/letsencrypt-kill-dehydrated-timer smeserver-manager-0.1.4/root/etc/e-smith/events/actions/letsencrypt-kill-dehydrated-timer
2     --- smeserver-manager-0.1.4.old/root/etc/e-smith/events/actions/letsencrypt-kill-dehydrated-timer 1970-01-01 01:00:00.000000000 +0100
3     +++ smeserver-manager-0.1.4/root/etc/e-smith/events/actions/letsencrypt-kill-dehydrated-timer 2024-11-22 11:28:49.316853979 +0000
4     @@ -0,0 +1,2 @@
5     +#! /bin/sh
6     +systemctl is-active --quiet dehydrated.timer && systemctl stop dehydrated.timer
7     diff -urN smeserver-manager-0.1.4.old/root/etc/e-smith/events/actions/letsencrypt-setdomains smeserver-manager-0.1.4/root/etc/e-smith/events/actions/letsencrypt-setdomains
8     --- smeserver-manager-0.1.4.old/root/etc/e-smith/events/actions/letsencrypt-setdomains 1970-01-01 01:00:00.000000000 +0100
9     +++ smeserver-manager-0.1.4/root/etc/e-smith/events/actions/letsencrypt-setdomains 2024-12-01 14:47:00.000000000 +0000
10     @@ -0,0 +1,159 @@
11     +#!/bin/bash
12     +
13     +#----------------------------------------------------------------------
14     +# copyright (C) 2022 Koozali SME Server
15     +#
16     +# This program is free software; you can redistribute it and/or modify
17     +# it under the terms of the GNU General Public License as published by
18     +# the Free Software Foundation; either version 2 of the License, or
19     +# (at your option) any later version.
20     +#
21     +# This program is distributed in the hope that it will be useful,
22     +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23     +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24     +# GNU General Public License for more details.
25     +#
26     +# You should have received a copy of the GNU General Public License
27     +# along with this program; if not, write to the Free Software
28     +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29     +#
30     +#----------------------------------------------------------------------
31     +
32     +event=$1
33     +fqdn=$2
34     +todo=$3
35     +domainlist=""
36     +
37     +case $todo in
38     + disabled|enabled)
39     + #
40     + ;;
41     + *)
42     + todo="all"
43     + ;;
44     +esac
45     +
46     +if [[ ! -z "$fqdn" ]]
47     + then
48     + # if fqdn not empty just use this one
49     + domainlist="$fqdn"
50     +elif [[ ! -z "$event" ]] && [[ "$event" == *"domain"* ]]
51     + then
52     + # else if event *domains* => all domains
53     + domainlist=$(perl -Mesmith::DomainsDB -e 'my $domains = esmith::DomainsDB->open; my @DOM = $domains->get_all_by_prop(type=>"domain"); print( join(" " , map { $_->key } @DOM)) ')
54     +elif [[ ! -z "$event" ]] && [[ "$event" == *"host"* ]]
55     + then
56     + # else if event *hosts* => all hosts
57     + domainlist=$(perl -Mesmith::HostsDB -e 'my $domains = esmith::HostsDB->open; my @DOM = $domains->get_all_by_prop(type=>"host"); print( join(" " , map { $_->key } @DOM)) ')
58     +else
59     + # else all domain and hosts
60     + domains=$(perl -Mesmith::DomainsDB -e 'my $domains = esmith::DomainsDB->open; my @DOM = $domains->get_all_by_prop(type=>"domain"); print( join(" " , map { $_->key } @DOM)) ')
61     + hosts=$(perl -Mesmith::HostsDB -e 'my $domains = esmith::HostsDB->open; my @DOM = $domains->get_all_by_prop(type=>"host"); print( join(" " , map { $_->key } @DOM)) ')
62     + domainlist="$domains $hosts"
63     +fi
64     +domainlist=$(echo $domainlist |sort|uniq)
65     +
66     +#list from pihole install script; only ipv4 ones
67     +#here we select our
68     +dns=$(/sbin/e-smith/db configuration getprop letesencrypt dnscheck||echo "https://cloudflare-dns.com/dns-query,8.8.8.8,8.8.4.4,1.1.1.1,1.0.0.1,208.67.222.222,208.67.220.220,4.2.2.1,4.2.2.2,8.20.247.20,84.200.69.80,84.200.70.40,9.9.9.10,149.112.112.10")
69     +# from https://stackoverflow.com/questions/10586153/how-to-split-a-string-into-an-array-in-bash
70     +IFS=', ' read -r -a DNS <<< "$dns"
71     +RANDOM=$$$(date +%s)
72     +x=1
73     +#TODO: if only one element skip the random selection
74     +while [ $x -le 5 ]; do
75     +mydns=${DNS[ $RANDOM % ${#DNS[@]} ]}
76     +if [[ $mydns == http* ]] ; then
77     + curl -s $mydns >/dev/null
78     + if [[ "$?" == "0" ]]; then
79     + break
80     + fi
81     +else
82     + nc -z -w2 $mydns 53
83     + if [[ "$?" == "0" ]]; then
84     + break
85     + fi
86     +fi
87     +x=$(( $x + 1 ))
88     +#in case of failure defaulting on a dns over https after 5
89     +mydns="https://cloudflare-dns.com/dns-query"
90     +done
91     +echo "External DNS Server : $mydns"
92     +
93     +MYFORCEDIP=$(/sbin/e-smith/db configuration getprop letesencrypt ExternalIP)
94     +# check if gateway or server only
95     +MYMODE=$(/sbin/e-smith/db configuration get SystemMode)
96     +# check our external ip if gateway, internal else
97     +LOCALIP=$(/sbin/e-smith/db configuration get InternalIP)
98     +MYIP=$LOCALIP
99     +# check the ip suggested by external world that point to us.
100     +MYEXTIP=$(/usr/sbin/e-smith/getmyip)
101     +
102     +if [ -z "$MYFORCEDIP" ]; then
103     + # we do not expect that a server-only has an ip routable on internet as firewall is not designed for that
104     + # but in case, we handle the situation as for ExternalIP in servergateway mode, please write ad hoc rules for masq if you do so...
105     + if [[ "$MYMODE" == "servergateway" ]] ; then
106     + MYIP=$(/sbin/e-smith/db configuration get ExternalIP);
107     + fi
108     + if [[ "$MYIP" != "$MYEXTIP" ]] ; then
109     + echo "External Interface IP: $MYIP"
110     + echo "Detected Wan IP : $MYEXTIP"
111     + echo "You seem to be behind a firewall, using the external IP obtained with our test $MYEXTIP"
112     + MYIP=$MYEXTIP
113     + fi
114     +else
115     + MYIP=$MYFORCEDIP
116     +fi
117     +
118     +echo "============================================================================================="
119     +OUTPUT="Domain\tStatus\tMYIP\tA\tLE_status\tLE_previous"
120     +# TODO all : check disabled and enabled ; active : check enabled and undef only
121     +
122     +for DOMAIN in $domainlist
123     + do
124     + # is it a host, a domain or should we ignore it
125     + TYPE=$(/sbin/e-smith/db domains gettype $DOMAIN || /sbin/e-smith/db hosts gettype $DOMAIN )
126     + if [[ "$TYPE" == "domain" ]] ; then
127     + TYPE="domains"
128     + elif [[ "$TYPE" == "host" ]] ; then
129     + TYPE="hosts"
130     + else
131     + echo "$DOMAIN is not in domains and not in hosts ($TYPE)"
132     + continue
133     + fi
134     + # do we have a priority ?
135     + currentstate=$(/sbin/e-smith/db $TYPE getprop $DOMAIN letsencryptSSLcert || echo "disabled")
136     + if [ "$currentstate" != "$todo" -a "$todo" != "all" ] ; then
137     + #echo "$DOMAIN skipping, only checking $todo $TYPE"
138     + continue
139     + fi
140     + # https://stackoverflow.com/questions/15268987/bash-based-regex-domain-name-validation
141     + if ( ! echo $DOMAIN| grep -P -q '(?=^.{4,253}$)(^(?:[a-zA-Z0-9](?:(?:[a-zA-Z0-9\-]){0,61}[a-zA-Z0-9])?\.)+([a-zA-Z]{2,}|xn--[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])$)' -Z ) ; then
142     + if [[ "$currentstate" == "disabled" ]]; then continue; fi
143     + echo "$DOMAIN is not a RFC compliant domain, disabling"
144     + /sbin/e-smith/db $TYPE setprop $DOMAIN letsencryptSSLcert disabled
145     + /sbin/e-smith/db $TYPE delprop $DOMAIN letsencryptMYIP
146     + continue
147     + fi
148     + THISDOMIP=$(/usr/bin/q A @$mydns $DOMAIN -f json |jq -r 'first(.Answers[].A | select( . != null )) // null' 2>/dev/null || /usr/bin/q A @$LOCALIP $DOMAIN -f json |jq -r 'first(.Answers[].A | select( . != null )) // null' 2>/dev/null )
149     + previous=$(/sbin/e-smith/db $TYPE getprop $DOMAIN letsencryptSSLcert||echo 'undefined');
150     + # if it does not resolve, next
151     + if [[ "$THISDOMIP" == "" ]]
152     + then
153     + OUTPUT="$OUTPUT\n$DOMAIN\tNOK\t$MYIP\tnoip\tdisabled\t$previous"
154     + /sbin/e-smith/db $TYPE setprop $DOMAIN letsencryptSSLcert disabled
155     + /sbin/e-smith/db $TYPE delprop $DOMAIN letsencryptMYIP
156     + continue;
157     + fi
158     + if [[ "$MYIP" == "$THISDOMIP" ]]
159     + then
160     + OUTPUT="$OUTPUT\n$DOMAIN\tOK\t$MYIP\t$THISDOMIP\tenabled\t$previous"
161     + /sbin/e-smith/db $TYPE setprop $DOMAIN letsencryptSSLcert enabled letsencryptMYIP $THISDOMIP
162     + else
163     + OUTPUT="$OUTPUT\n$DOMAIN\tNOK\t$MYIP\t$THISDOMIP\tdisabled\t$previous"
164     + /sbin/e-smith/db $TYPE setprop $DOMAIN letsencryptSSLcert disabled letsencryptMYIP $THISDOMIP
165     + fi
166     + sleep 1
167     +done
168     +printf "%b" $OUTPUT |column -t -s $'\t'
169     +
170     diff -urN smeserver-manager-0.1.4.old/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/sme_core.css/90contribs smeserver-manager-0.1.4/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/sme_core.css/90contribs
171     --- smeserver-manager-0.1.4.old/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/sme_core.css/90contribs 2020-11-19 07:53:26.000000000 +0000
172     +++ smeserver-manager-0.1.4/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/sme_core.css/90contribs 2024-11-26 16:25:00.000000000 +0000
173     @@ -67,5 +67,21 @@
174     color: #8ebe43;
175     background-color: #8ebe43;
176     }
177     +
178     +/* flag container no flag */
179     +#flag-container span {
180     + font-size: 24px;
181     +}
182     +
183     +.fallback-box {
184     + display: inline-block; /* Make it inline-block to fit around the content */
185     + border: 2px solid gray; /* Change the border color as desired */
186     + padding: 10px; /* Add some padding */
187     + border-radius: 10px; /* Round the corners of the box */
188     + font-size: 60px; /* Adjust size if needed */
189     + margin-top: 10px; /* Add some margin */
190     + text-align: center; /* Center text inside the box */
191     +}
192     +
193     HERE
194     }
195     diff -urN smeserver-manager-0.1.4.old/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/styles.css/50body smeserver-manager-0.1.4/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/styles.css/50body
196     --- smeserver-manager-0.1.4.old/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/styles.css/50body 2024-12-09 10:51:08.462623478 +0000
197     +++ smeserver-manager-0.1.4/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/css/styles.css/50body 2024-11-26 16:25:00.000000000 +0000
198     @@ -234,7 +234,7 @@
199     width: 100%;
200     }
201     #h2e11 {
202     - width: 70%;
203     + width: 50%;
204     float: left;
205     }
206     #h2e12 {
207     @@ -257,9 +257,9 @@
208     width: 70%;
209     }
210    
211     -#h2e22,#h2e23 {
212     +#h2e22,#h2e23,#h2e12 {
213     float: left;
214     - width: 10%;
215     + width: 14em;
216     text-align: center;
217     }
218    
219     @@ -273,6 +273,7 @@
220     left: 2px;
221     }
222    
223     +
224     /*end*/
225     EOF
226     }
227     diff -urN smeserver-manager-0.1.4.old/root/usr/sbin/e-smith/getmyip smeserver-manager-0.1.4/root/usr/sbin/e-smith/getmyip
228     --- smeserver-manager-0.1.4.old/root/usr/sbin/e-smith/getmyip 1970-01-01 01:00:00.000000000 +0100
229     +++ smeserver-manager-0.1.4/root/usr/sbin/e-smith/getmyip 2024-11-27 15:53:00.000000000 +0000
230     @@ -0,0 +1,54 @@
231     +#!/bin/bash
232     +
233     +# List of services to query for the public IP
234     +services=(
235     + "ifconfig.me"
236     + "ipinfo.io/ip"
237     + "icanhazip.com"
238     + "api.ipify.org"
239     + "ident.me"
240     + "ip.tyk.nu"
241     + "checkip.amazonaws.com"
242     + "ipecho.net/plain"
243     + "myip.dnsomatic.com"
244     + "ip.seeip.org"
245     + "ipapi.co/ip"
246     + "wtfismyip.com/text"
247     + "openident.net/ip"
248     + "ifconfig.co/ip"
249     +)
250     +
251     +# Function to shuffle the array of services
252     +shuffle_services() {
253     + local i
254     + for ((i=${#services[@]} - 1; i > 0; i--)); do
255     + local j=$((RANDOM % (i + 1)))
256     + local temp="${services[i]}"
257     + services[i]="${services[j]}"
258     + services[j]="$temp"
259     + done
260     +}
261     +
262     +# Function to fetch the public IP address
263     +get_public_ip() {
264     + shuffle_services
265     + for service in "${services[@]}"; do
266     + public_ip=$(curl -s --max-time 5 "$service")
267     +
268     + # Check if the curl request was successful and there's a valid IP address
269     + if [[ $? -eq 0 && $public_ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
270     + logger -t public_ip_script "Service used: $service, IP found: $public_ip"
271     + echo "$public_ip"
272     + return
273     + fi
274     + done
275     +
276     + # If none of the services returned a valid IP, output an error message
277     + echo "Failed to retrieve public IP using all services." >&2
278     + logger -t public_ip_script "Error: Failed to retrieve public IP using all services."
279     + exit 1
280     +}
281     +
282     +# Execute the function
283     +get_public_ip
284     +
285     diff -urN smeserver-manager-0.1.4.old/root/usr/share/smanager/themes/default/public/css/letsencrypt.css smeserver-manager-0.1.4/root/usr/share/smanager/themes/default/public/css/letsencrypt.css
286     --- smeserver-manager-0.1.4.old/root/usr/share/smanager/themes/default/public/css/letsencrypt.css 2024-12-09 10:51:12.148733531 +0000
287     +++ smeserver-manager-0.1.4/root/usr/share/smanager/themes/default/public/css/letsencrypt.css 2024-12-09 15:13:38.416498067 +0000
288     @@ -53,3 +53,38 @@
289     .read1 {}
290     .text2 {}
291     .back3 {}
292     + .inline-buttons {
293     + display: flex; /* Use flexbox to arrange items horizontally */
294     + gap: 10px; /* Optional: Add space between buttons */
295     + }
296     +
297     + .inline-buttons .link {
298     + /* Additional styling can be added here if needed */
299     + }
300     +
301     +
302     + .inline-buttons .link {
303     + display: inline-block; /* Keep links as inline-block for button shape */
304     + padding: 7px 14px; /* Adjusted padding to approximate 70% of the original */
305     + margin: 0; /* Remove margin */
306     + background-color: #efefef; /* Light gray background color */
307     + color: black; /* Text color */
308     + text-decoration: none; /* Remove underline */
309     + border: 2px solid #bbb; /* Thin, light gray border */
310     + border-radius: 3px; /* Slightly rounded corners */
311     + font-size: 11.2px; /* Adjusted font size to approximate 70% of the original */
312     + text-align: center; /* Center the text */
313     + cursor: pointer; /* Pointer cursor on hover */ }
314     +
315     + /* Hover and active effects for better interaction */
316     + .inline-buttons .link:hover {
317     + background-color: #d9d9d9; /* Darker shade on hover */
318     + }
319     +
320     + .inline-buttons .link:active {
321     + background-color: #c0c0c0; /* Even darker shade on click */
322     + }
323     +
324     + span .label {
325     + padding-top:13em;
326     + }

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed