mirror of
https://github.com/dragonlock2/matthewtran.com.git
synced 2025-10-11 20:17:54 +00:00
add ipv4 update script
This commit is contained in:
parent
eb6f627962
commit
1192804767
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ __pycache__
|
|||||||
# website
|
# website
|
||||||
website/gitea
|
website/gitea
|
||||||
website/letsencrypt
|
website/letsencrypt
|
||||||
|
website/sendgrid.key
|
||||||
|
|
||||||
# monerod
|
# monerod
|
||||||
monerod/.bitmonero
|
monerod/.bitmonero
|
||||||
|
@ -24,11 +24,11 @@ Forward the following ports to the server.
|
|||||||
| terraria | 7777 |
|
| terraria | 7777 |
|
||||||
| wireguard | 51820 |
|
| wireguard | 51820 |
|
||||||
|
|
||||||
Run the following commands.
|
Run the following commands. For the IP update script, add a SendGrid API key to `website/sendgrid.key`.
|
||||||
|
|
||||||
```
|
```
|
||||||
docker compose build
|
docker compose build
|
||||||
docker compose up -d # auto restarts on reboot!
|
docker compose up -d # auto restarts on reboot!
|
||||||
```
|
```
|
||||||
|
|
||||||
Note for first start you'll need to configure Gitea.
|
Note for first start you'll need to configure Gitea. You may also need to `chown` and `chmod` the mounted folders for each container.
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
FROM ubuntu:22.04
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
# install dependencies
|
# install dependencies
|
||||||
|
ENV TZ=America/Los_Angeles
|
||||||
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
RUN apt-get update && apt-get upgrade
|
RUN apt-get update && apt-get upgrade
|
||||||
RUN apt-get install -y nginx certbot python3-certbot-nginx
|
RUN apt-get install -y nginx certbot python3-certbot-nginx python3-pip
|
||||||
|
RUN pip3 install sendgrid
|
||||||
|
|
||||||
RUN rm /etc/nginx/sites-enabled/default
|
RUN rm /etc/nginx/sites-enabled/default
|
||||||
|
|
||||||
@ -13,4 +17,5 @@ COPY html /var/www/matthewtran.com/html
|
|||||||
|
|
||||||
# start script
|
# start script
|
||||||
WORKDIR /root
|
WORKDIR /root
|
||||||
|
COPY sendgrid.ke[y] ip_update.py ./
|
||||||
COPY entry.sh ./
|
COPY entry.sh ./
|
||||||
|
@ -15,6 +15,7 @@ certbot --nginx \
|
|||||||
-d git.matthewtran.com
|
-d git.matthewtran.com
|
||||||
|
|
||||||
nginx -s reload
|
nginx -s reload
|
||||||
|
python3 ip_update.py &
|
||||||
|
|
||||||
# try renew once a day
|
# try renew once a day
|
||||||
while true
|
while true
|
||||||
|
33
website/ip_update.py
Normal file
33
website/ip_update.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import time
|
||||||
|
import urllib.request
|
||||||
|
from pathlib import Path
|
||||||
|
from sendgrid import SendGridAPIClient
|
||||||
|
from sendgrid.helpers.mail import Mail
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sg = SendGridAPIClient(Path('sendgrid.key').read_text())
|
||||||
|
|
||||||
|
old_ipv4, old_ipv6 = None, None
|
||||||
|
while True:
|
||||||
|
ipv4 = urllib.request.urlopen('https://v4.ident.me').read().decode('utf8')
|
||||||
|
ipv6 = None
|
||||||
|
# ipv6 = urllib.request.urlopen('https://v6.ident.me').read().decode('utf8')
|
||||||
|
|
||||||
|
if ipv4 != old_ipv4 or ipv6 != old_ipv6:
|
||||||
|
msg = Mail(
|
||||||
|
from_email='matthewlamtran@berkeley.edu',
|
||||||
|
to_emails='mtran319@gmail.com',
|
||||||
|
subject='pls update ip',
|
||||||
|
html_content=f'<p>ipv4: {ipv4}</p><p>ipv6: {ipv6}</p>'
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
print(f'IP changed to {ipv4} and {ipv6}')
|
||||||
|
resp = sg.send(msg)
|
||||||
|
except Exception as e:
|
||||||
|
print(e.message)
|
||||||
|
sg = SendGridAPIClient(Path('sendgrid.key').read_text())
|
||||||
|
|
||||||
|
old_ipv4, old_ipv6 = ipv4, ipv6
|
||||||
|
time.sleep(60 * 60) # 60 min
|
Loading…
x
Reference in New Issue
Block a user