move dns update job here

This commit is contained in:
Torsten 2023-02-11 22:35:45 +02:00
parent df6af95ff9
commit 41771ad5c1
13 changed files with 97 additions and 26 deletions

View File

@ -22,6 +22,9 @@ gem "sucker_punch", "~> 3.1"
gem 'carrierwave', '>= 3.0.0.beta', '< 4.0'
gem "dnsimple"
gem 'whenever', require: false
gem 'kaminari'
gem "ruby2js" , git: "https://github.com/ruby2js/ruby2js/" , branch: "haml_fix"
gem 'thredded', '~> 1.0'

View File

@ -122,6 +122,7 @@ GEM
image_processing (~> 1.1)
marcel (~> 1.0.0)
ssrf_filter (~> 1.0)
chronic (0.10.2)
coderay (1.1.3)
concurrent-ruby (1.2.0)
crass (1.0.6)
@ -140,6 +141,8 @@ GEM
devise-async (1.0.0)
activejob (>= 5.0)
devise (>= 4.0)
dnsimple (8.1.0)
httparty
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
erubi (1.12.0)
@ -190,6 +193,9 @@ GEM
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
@ -246,6 +252,7 @@ GEM
minitest (5.17.0)
msgpack (1.6.0)
multi_json (1.15.0)
multi_xml (0.6.0)
mustache (1.1.1)
nenv (0.3.0)
net-imap (0.3.4)
@ -427,6 +434,8 @@ GEM
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.6)
@ -441,6 +450,7 @@ DEPENDENCIES
debug
devise
devise-async
dnsimple
guard
guard-minitest
haml-rails
@ -467,6 +477,7 @@ DEPENDENCIES
thredded (~> 1.0)
web-console
webdrivers
whenever
RUBY VERSION
ruby 3.1.3p185

View File

@ -1,14 +0,0 @@
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.representable? %>
<%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
<% end %>
<figcaption class="attachment__caption">
<% if caption = blob.try(:caption) %>
<%= caption %>
<% else %>
<span class="attachment__name"><%= blob.filename %></span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
<% end %>
</figcaption>
</figure>

View File

@ -1 +1 @@
syO+xGqMH6A+HX2rarqdpxCMxrQ2YNAIkGsyvURFxjip5smTycl6Zwe7llyOxMx+HK7iCHKuVZQuWwpTXqmLGVvip337w/3elVr38Po4pk6H9O6hwEi7VBVQ8aHyZBEsCXfc6IV4fuMhMOxuvDHy01IzHQXLtyPuk6PO0St/bc7CGhalmueFB4JG4QgC1HaR65StysInwppa7V0mjH10xmM8Ovhx2upbdIPu4zXk1owGKfCgECT5auoh41Yq8mm9hvcwukXNOtMTM2wFxh0gwtRHjfRwPLpZZtSH9MWWFhlil9cui5TRZkM4lxenRCio37I3e8hsfgswhKODUzwMVkkF032PGCtUXmB7U5ZE13/m3Gvb5nAxeYMpjoOtQpqnXWOoQkCgP/Ta37RDeRxJD0k+RXNJQG1GR8CAtw/lECnotpVIh0HXih7CgKoz9mfWru/z9qqSvhBRCiIFb+IE9EA0uo3P29DKZcMzjTvMP0tD2vRQdbNGMjzihxOgD7bfWIi5XGQd6MfvRzCIJ3foZEDasW/uXp9m9T3s56VmrSFrWo+G1Mej8woEz10PC2cyKqaF1InCiB+vhiyfiPsdtUiDB0ss4/o+x2/uM9/5l+qgd53wJGIwstPT8nJ8k97UyQayVz045gIRyAXscL0PvaQTiUanl1Z3GDlYTGby9EVV5WFp6d9mpx4wO1ak1EOixOXVMysekeLamQHP9GIKeVkeoB2qSIVNkurHYo7+faw1Iu/FfsC0WCoRpjFXoP4c/PWiWw4Re3eyf5gucUSPIFC6zxiJHVEitq8m+e4ZtR0u/1wFFxOfXaDyXMFYS5cWwbPEP1a9cxc7A6rX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YAhTI=--e85cR1q38Hzng1vT--v+bCUhqpleNujxOW/n81nA==

10
config/schedule.rb Normal file
View File

@ -0,0 +1,10 @@
# Use this file to easily define all of your cron jobs.
#
set :output, "/home/feenix/hubfeenix/shared/log/whenever.log"
every :hour do
rake "dns:update"
end
# Learn more: http://github.com/javan/whenever

27
lib/dns_update_job.rb Normal file
View File

@ -0,0 +1,27 @@
require "dnsimple"
class DnsUpdateJob
def client
@client ||= Dnsimple::Client.new(access_token: Rails.application.credentials.simple_token)
end
def simple_id
Rails.application.credentials.simple_id
end
def my_ip
@ip ||= HTTParty.get("https://jsonip.com/")["ip"]
end
def find_record(name , host)
zones = client.zones.list_zone_records(simple_id, host, filter: { type: 'A' , name: name })
zones.data.first
end
def same_ip(name , host)
my_ip == find_record(name , host).content
end
def update_ip(name , host)
record = find_record(name , host)
client.zones.update_zone_record(simple_id, host , record.id , content: my_ip)
end
end

10
lib/tasks/dns.rake Normal file
View File

@ -0,0 +1,10 @@
require "dns_update_job"
namespace :dns do
desc "Update own dyn dns records"
task update: :environment do
job = DnsUpdateJob.new
puts "My ip is #{job.my_ip}"
job.update_ip("gateway" , "hubfeenix.fi")
end
end

View File

@ -1,4 +0,0 @@
# one:
# record: name_of_fixture (ClassOfFixture)
# name: content
# body: <p>In a <i>million</i> stars!</p>

View File

@ -3,11 +3,9 @@
one:
name: MyString
ha_id: MyString
type:
member: one
two:
name: MyString
ha_id: MyString
type:
member: two

View File

View File

@ -1,9 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
public: false
email: email1
two:
name: MyString
public: false
email: email2

View File

@ -5,9 +5,11 @@ one:
bio: MyString
picture: MyString
member: one
kind: artist
two:
name: MyString
bio: MyString
picture: MyString
member: two
kind: member

View File

@ -0,0 +1,30 @@
require "test_helper"
require "dns_update_job"
class DnsJobTest < ActiveJob::TestCase
def test_update_ip
updater = DnsUpdateJob.new
updater.update_ip("dnsimple_test","hubfeenix.fi")
zone = updater.find_record("dnsimple_test","hubfeenix.fi")
assert_equal zone.content, updater.my_ip
end
def test_get_ip
res = DnsUpdateJob.new.my_ip
assert res.start_with? "84"
end
def test_init_client
client = DnsUpdateJob.new.client
assert_equal client.class, Dnsimple::Client
end
def test_find_domain
updater = DnsUpdateJob.new
zone = updater.find_record("dnsimple_test","hubfeenix.fi")
assert_equal zone.class, Dnsimple::Struct::ZoneRecord
assert_equal zone.name, "dnsimple_test"
assert_equal zone.content, updater.my_ip
end
end