Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
hotchilipowder committed May 15, 2024
2 parents a313b03 + 0aafde8 commit 23adf23
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
16 changes: 13 additions & 3 deletions docs/docs/git.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ Common git skill

关于git学习的资料,可以查看 \ `git教程 <https://www.liaoxuefeng.com/wiki/896043488029600>`_\

Set git proxy
-------------


.. code-block:: bash
git config --global http.proxy xxx
git config --global https.proxy xxx
Change history user.name and user.email
Expand Down Expand Up @@ -177,12 +187,12 @@ Github Save username and password
---------------------------------


由于经常有开项目的习惯,存在多个账号,所以建议先设置local的 \ :code:`user.username`\ \ :code:`user.email`\ ,并且进一步设置, 当前的项目的存储方式,这样可以少输入密码
由于经常有开项目的习惯,存在多个账号,所以建议先设置local的 \ :code:`user.name`\ \ :code:`user.email`\ ,并且进一步设置, 当前的项目的存储方式,这样可以少输入密码


.. code-block:: bash
git config --local user.username "hotchilipowder"
git config --local user.name "hotchilipowder"
git config --local user.email "[email protected]"
git config --local credential.helper cache
Expand All @@ -193,7 +203,7 @@ Github Save username and password
.. code-block:: bash
[user]
username = hotchilipowder
name = hotchilipowder
email = [email protected]
[credential]
helper = cache
Expand Down
6 changes: 5 additions & 1 deletion docs/docs/homelab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,15 @@ Nodejs Install

just download from \ `https://nodejs.org/en/download <https://nodejs.org/en/download>`_

根据 \ `Build takes so long <https://github.com/orgs/nodejs/discussions/43451>`_ , 可以发现,还是要使用多核编译,但是仍然非常慢!



.. code-block:: bash
:linenos:
./configure --prefix=~/.local
make && make install
make -j 4 && make install
MISC
Expand Down
57 changes: 46 additions & 11 deletions scripts/dnspod_ddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
parser.add_argument('--domain', '-d', default=DOMAIN, help='Domain')
parser.add_argument('--sub_domain', '-s', default='xxx', help='Subdomain, default: xxx')
parser.add_argument('--record_type', '-t', default='AAAA', help='Record Type, e.g., AAAA(default), A')
parser.add_argument('--local_ip_type', '-lt', default=None, help='Use local IPV4 or IPV6, default: None')
args = parser.parse_args()

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,6 +47,22 @@ def get_public_ipv4():
return content


def get_local_ipv4():
cmdline = "ip a | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | grep -v '172*'| head -n 1"
res = subprocess.run(cmdline, shell=True, capture_output=True)
ip = res.stdout.decode('utf8').strip()
logger.warning(ip)
return ip


def get_local_ipv6():
cmdline = 'ip a | grep inet6 | grep -v "::1" | grep -Eo "([a-f0-9:]+:+)+[a-f0-9]+" | head -n 1'
res = subprocess.run(cmdline, shell=True, capture_output=True)
ip = res.stdout.decode('utf8').strip()
logger.warning(ip)
return ip


class DNSPod(object):
"""DNSPod ddns application."""

Expand All @@ -65,13 +82,18 @@ def run(self, params=None):
if params is None:
params = self._params
public_ip = None
if params['record_type'] == 'AAAA':
public_ip = get_public_ipv6()
elif params['record_type'] == 'A':
public_ip = get_public_ipv4()
if args.local_ip_type is None:
if params['record_type'] == 'AAAA':
public_ip = get_public_ipv6()
elif params['record_type'] == 'A':
public_ip = get_public_ipv4()
elif args.local_ip_type == 'A':
public_ip = get_local_ipv4()
elif args.local_ip_type == 'AAAA':
public_ip = get_local_ipv6()
if public_ip is None:
logger.error('IP unknown')
return
logger.error('IP unknown')
return
# get record_id of sub_domain
record_list = self.get_record_list(params)
if record_list['code'] == '10' or record_list['code'] == '26':
Expand All @@ -80,14 +102,19 @@ def run(self, params=None):
remote_ip = public_ip
elif record_list['code'] == '1':
# get record id
record_id = record_list['record_id']
remote_ip = record_list['ip_value']
if remote_ip == public_ip:
logger.warning('same ip: ' + remote_ip)
return -1
else:
logger.warning(record_list)
params['record_id'] = record_list['record_id']
res = self.ddns(params, public_ip)
logger.warning(res)
else:
logger.error('Update not work')
logger.error(record_list)
return -1
params['record_id'] = record_id

current_ip = remote_ip
logger.warning('current_ip: ' + current_ip)

Expand All @@ -104,6 +131,7 @@ def get_record_list(self, params):
code = jd['status']['code']
record_id = jd['records'][0]['id'] if code == '1' else ""
ip_value = jd['records'][0]['value'] if code == '1' else ""
logger.warning('query_record')
logger.warning(jd)
return dict(code=code, record_id=record_id, ip_value=ip_value)

Expand All @@ -116,22 +144,25 @@ def create_record(self, params, ip):
params['value'] = ip
record_create_url = 'https://dnsapi.cn/Record.Create'
r = self.post_data(record_create_url, data=params)
logger.warning('create new record %s.%s with IP %s' % (params['sub_domain'], params['domain'], ip))
jd = json.loads(r)
assert jd['status']['code'] == '1'
record_id = jd['record']['id']
logger.warning('create_record')
logger.warning(jd)
return record_id

def ddns(self, params, ip):
"""Update ddns ip.
https://www.dnspod.cn/docs/records.html#dns
"""
logger.warning(ip)
logger.warning(params)
params['value'] = ip
ddns_url = 'https://dnsapi.cn/Record.Ddns'
r = self.post_data(ddns_url, data=params)
jd = json.loads(r)
logger.info('status: %s, reason: %s' % (r.status_code, r.reason))
logger.warning('update_ddns')
logger.warning(jd)
return jd['status']['code'] == '1'


Expand All @@ -149,5 +180,9 @@ def main():
dnspod.run()


def test():
get_local_ipv4()

if __name__ == "__main__":
main()

0 comments on commit 23adf23

Please sign in to comment.