diff --git a/Gemfile b/Gemfile index 2f78414..362e134 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index dfb3f29..4dec3e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb deleted file mode 100644 index 49ba357..0000000 --- a/app/views/active_storage/blobs/_blob.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
attachment--<%= blob.filename.extension %>"> - <% if blob.representable? %> - <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> - <% end %> - -
- <% if caption = blob.try(:caption) %> - <%= caption %> - <% else %> - <%= blob.filename %> - <%= number_to_human_size blob.byte_size %> - <% end %> -
-
diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index d590c80..4621cb6 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -syO+xGqMH6A+HX2rarqdpxCMxrQ2YNAIkGsyvURFxjip5smTycl6Zwe7llyOxMx+HK7iCHKuVZQuWwpTXqmLGVvip337w/3elVr38Po4pk6H9O6hwEi7VBVQ8aHyZBEsCXfc6IV4fuMhMOxuvDHy01IzHQXLtyPuk6PO0St/bc7CGhalmueFB4JG4QgC1HaR65StysInwppa7V0mjH10xmM8Ovhx2upbdIPu4zXk1owGKfCgECT5auoh41Yq8mm9hvcwukXNOtMTM2wFxh0gwtRHjfRwPLpZZtSH9MWWFhlil9cui5TRZkM4lxenRCio37I3e8hsfgswhKODUzwMVkkF032PGCtUXmB7U5ZE13/m3Gvb5nAxeYMpjoOtQpqnXWOoQkCgP/Ta37RDeRxJD0k+RXNJQG1GR8CAtw/lECnotpVIh0HXih7CgKoz9mfWru/z9qqSvhBRCiIFb+IE9EA0uo3P29DKZcMzjTvMP0tD2vRQdbNGMjzihxOgD7bfWIi5XGQd6MfvRzCIJ3foZEDasW/uXp9m9T3s56VmrSFrWo+G1Mej8woEz10PC2cyKqaF1InCiB+vhiyfiPsdtUiDB0ss4/o+x2/uM9/5l+qgd53wJGIwstPT8nJ8k97UyQayVz045gIRyAXscL0PvaQTiUanl1Z3GDlYTGby9EVV5WFp6d9mpx4wO1ak1EOixOXVMysekeLamQHP9GIKeVkeoB2qSIVNkurHYo7+faw1Iu/FfsC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ZUxe8xmQY6oqJ0hGzS3hL++VT26+hHePyFf8OJg1OuN4cwIMaNS3YfelNfhT6vFKYuStfnnUGc7dlC7jnrY7U1AIgfi55Fb3NTcPXGfpzYAhTI=--e85cR1q38Hzng1vT--v+bCUhqpleNujxOW/n81nA== \ No newline at end of file diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 0000000..41b8ef3 --- /dev/null +++ b/config/schedule.rb @@ -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 diff --git a/lib/dns_update_job.rb b/lib/dns_update_job.rb new file mode 100644 index 0000000..b0a04dc --- /dev/null +++ b/lib/dns_update_job.rb @@ -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 diff --git a/lib/tasks/dns.rake b/lib/tasks/dns.rake new file mode 100644 index 0000000..0869547 --- /dev/null +++ b/lib/tasks/dns.rake @@ -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 diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml deleted file mode 100644 index 8b371ea..0000000 --- a/test/fixtures/action_text/rich_texts.yml +++ /dev/null @@ -1,4 +0,0 @@ -# one: -# record: name_of_fixture (ClassOfFixture) -# name: content -# body:

In a million stars!

diff --git a/test/fixtures/entities.yml b/test/fixtures/entities.yml index 1f47312..22a9654 100644 --- a/test/fixtures/entities.yml +++ b/test/fixtures/entities.yml @@ -3,11 +3,9 @@ one: name: MyString ha_id: MyString - type: member: one two: name: MyString ha_id: MyString - type: member: two diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/members.yml b/test/fixtures/members.yml index 5eef320..d24f694 100644 --- a/test/fixtures/members.yml +++ b/test/fixtures/members.yml @@ -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 diff --git a/test/fixtures/profiles.yml b/test/fixtures/profiles.yml index 7e4f2e9..7fa0a4f 100644 --- a/test/fixtures/profiles.yml +++ b/test/fixtures/profiles.yml @@ -5,9 +5,11 @@ one: bio: MyString picture: MyString member: one - + kind: artist two: name: MyString bio: MyString picture: MyString member: two + kind: member + diff --git a/test/jobs/dns_update_job_test.rb b/test/jobs/dns_update_job_test.rb new file mode 100644 index 0000000..72e0d90 --- /dev/null +++ b/test/jobs/dns_update_job_test.rb @@ -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