dns_one 0.5.12 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f81dde3459b31d4c83ba7bb115f03a1ed708b21d
4
- data.tar.gz: bb87f0b070fda97d18cfc9923657619d99c257e4
3
+ metadata.gz: 2e10df9846e483364575b961388bc6836684c112
4
+ data.tar.gz: 81347e9f92e59419489a07f0a727654fce46d166
5
5
  SHA512:
6
- metadata.gz: 91830beaf2f9d7b72ae7b77e2d384b6d53701ee9f99337fa2845c6ea8c0657799ad2017e693164add1b3da7f1e84bff3648a6aa7cf1411e1b65ce4c082c88428
7
- data.tar.gz: b85b09c99d752241540905b2f578b7e59bc72f61a5e60426677dbbbcb0c46b3c8092d85aa21ed7ae4716b19a7e6917f5e7e5a7f47f2b35836259dbd0b7392bb5
6
+ metadata.gz: c3473af08292f70ff5558b6d0bba02daa508580bedc5d8659b4e73de50cb21ea0841ffac7a78103aabd88904a0f81b90553caccb35912e7d6d8f8c15c6f1a938
7
+ data.tar.gz: ccef86c94a4e2046cf89d466ec4cec5a944e8c23613d6f81c2133e967c64f8d9c29a7d3a8a8083255910cf5d8205e1a2b6bd87a1ea0ff7ca26662b6af7bbc286
@@ -28,8 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_runtime_dependency "thor", '~> 0.19'
29
29
  spec.add_runtime_dependency "rubydns", '~> 2.0'
30
30
  spec.add_runtime_dependency "rexec", '~> 1.6'
31
- spec.add_runtime_dependency "pg", '~> 0.21'
32
- spec.add_runtime_dependency "activerecord", '~> 5.0'
33
- spec.add_runtime_dependency "sqlite3", '~> 1.3'
34
31
 
35
32
  end
@@ -23,22 +23,21 @@ require "dns_one/core_ext/hash"
23
23
  require "dns_one/global"
24
24
  require "dns_one/util"
25
25
  require "dns_one/server"
26
- require "dns_one/req_log/db"
27
26
 
28
27
  module DnsOne; class DnsOne
29
28
 
30
29
  DEFAULTS = {
31
- conf_file: "/etc/dns_one.yml",
32
- work_dir: "/var/local/dns_one",
33
- log_file: "/var/log/dns_one/dns_one.log",
34
- rubydns_log_file: "/var/log/dns_one/dns_one_rubydns.log",
30
+ conf_file: "/etc/dnsone.yml",
31
+ work_dir: "/var/local/dnsone",
32
+ log_file: "/var/log/dns_one/dnsone.log",
33
+ rubydns_log_file: "/var/log/dns_one/dnsone_rubydns.log",
35
34
  run_as: "dnsone",
36
35
  interfaces: [ [:udp, "0.0.0.0", 53],
37
36
  [:tcp, "0.0.0.0", 53],
38
37
  [:udp, "::", 5300],
39
38
  [:tcp, "::", 5300]
40
39
  ],
41
- log_req_socket_file: '/tmp/dns_one_log_result.sock'
40
+ log_req_socket_file: '/tmp/dnsone_log_result.sock'
42
41
  }
43
42
 
44
43
  def initialize conf_file: nil
@@ -55,7 +54,9 @@ module DnsOne; class DnsOne
55
54
 
56
55
  def load_conf conf_file
57
56
  conf = DEFAULTS.clone
58
- conf.merge! YAML.load_file(conf_file).symbolize_keys
57
+ if File.exists? conf_file
58
+ conf.merge! YAML.load_file(conf_file).symbolize_keys
59
+ end
59
60
  Util.hash_to_ostruct_deep conf
60
61
 
61
62
  rescue => e
@@ -1,4 +1,3 @@
1
-
2
1
  module DnsOne; module Backend; class DB < Base
3
2
 
4
3
  def initialize conf
@@ -45,7 +44,7 @@ module DnsOne; module Backend; class DB < Base
45
44
  end
46
45
 
47
46
  def setup_db
48
- #require_deps
47
+ require_deps
49
48
  ActiveRecord::Base.logger = Global.logger
50
49
  ActiveRecord::Base.establish_connection @conf
51
50
  end
@@ -18,40 +18,16 @@ class DnsOne::CLI < Thor
18
18
  ).start
19
19
  end
20
20
 
21
- # INSTALL
22
-
23
- desc "install", "install dns_one"
24
- def install
25
- DnsOne::Setup.new.install
21
+ desc "setup", "setup dnsone"
22
+ def setup
23
+ DnsOne::Setup.new.setup
26
24
  end
27
25
 
28
- desc "uninstall", "uninstall dns_one"
29
- def uninstall
30
- DnsOne::Setup.new.uninstall
26
+ desc "remove", "remove dnsone"
27
+ def remove
28
+ DnsOne::Setup.new.remove
31
29
  end
32
30
 
33
- # MANAGE
34
-
35
- desc "start", "start dns_one"
36
- def start
37
- DnsOne::Util.ensure_sytemd
38
- DnsOne::Util.run "systemctl start #{DnsOne::Setup::SERVICE_NAME}"
39
- end
40
-
41
- desc "stop", "stop dns_one"
42
- def stop
43
- DnsOne::Util.ensure_sytemd
44
- DnsOne::Util.run "systemctl stop #{DnsOne::Setup::SERVICE_NAME}"
45
- end
46
-
47
- desc "status", "check dns_one status"
48
- def status
49
- DnsOne::Util.ensure_sytemd
50
- DnsOne::Util.run "systemctl status #{DnsOne::Setup::SERVICE_NAME}"
51
- end
52
-
53
- # STATS
54
-
55
31
  desc "stats", "show counters"
56
32
  def stats
57
33
  DnsOne::Stat.print
@@ -1,4 +1,4 @@
1
- module DnsOne; module Backend; class DB
1
+ module DnsOne; module ReqLog; class DB
2
2
 
3
3
  DB_FNAME = "stat.db"
4
4
  META_STAT_ON = false
@@ -1,8 +1,10 @@
1
- module DnsOne; module Backend; class File
2
- if @conf.req_log_file
3
- path = @conf.req_log_file.is_a?(String) ? @conf.req_log_file :
1
+ module DnsOne; module ReqLog; class File
2
+ if self.set_logger
3
+ path = @conf.req_log_file.is_a?(String) ? @conf.req_log_file : STDOUT
4
+
4
5
  l = Logger.new @conf.ruby_dns_logger, 10, (10 * 2**20)
5
6
  l.level = Logger::WARN
7
+
6
8
  Global.ruby_dns_logger = l
7
9
  end
8
10
 
@@ -2,6 +2,7 @@
2
2
  require "dns_one/zone_search"
3
3
  require "dns_one/req_log/req_log"
4
4
  require "dns_one/req_log/account"
5
+ require "dns_one/req_log/db"
5
6
 
6
7
  module DnsOne; class Server
7
8
  def initialize
@@ -1,115 +1,151 @@
1
1
  module DnsOne; class Setup
2
- # Currently tested version
3
- # TODO: flexibilize version and make checks/prompts/warnings during install
4
- REQUIRED_RUBY_VERSION = '2.3.3'
5
-
6
2
  SYSTEMD_SERVICES_DIR = "/lib/systemd/system/"
7
- SERVICE_NAME = 'dns_one'
3
+ SERVICE_NAME = 'dnsone'
8
4
  SYSTEMD_SERVICE_FILE = "#{SYSTEMD_SERVICES_DIR}/#{SERVICE_NAME}.service"
9
5
 
6
+ attr_accessor :conf
10
7
 
11
8
  def initialize
12
9
  @thisdir = File.join File.dirname(__FILE__)
10
+ DnsOne.new # just to load the configuration
11
+ # TODO: move conf to own class
12
+ @conf = Global.conf
13
13
  end
14
14
 
15
- def install
16
- check_root
17
- #check_ruby_version
18
- unless Util.has_systemd?
19
- STDERR.puts "DnsOne requires systemd. Aborting install."
20
- exit 1
21
- end
15
+ def setup
16
+ check_reqs
22
17
  add_user
23
18
  mkdirs
24
- #set_ruby_version
25
19
  copy_sample_conf
26
20
  install_systemd_service
27
21
  setup_finished_msg
28
22
  end
29
23
 
30
- def uninstall
31
- # File.delete DnsOne::DEFAULT_CONF_FILE # TODO: prompt user
32
- if File.exist?(SYSTEMD_SERVICE_FILE)
24
+ def remove
25
+ unless is_setup?
26
+ die "Nothing to remove. Exiting."
27
+ end
28
+
29
+ # SYSTEMD_SERVICE_FILE
30
+ if Util.has_systemd? and File.exist? SYSTEMD_SERVICE_FILE
33
31
  Util.run "systemctl stop #{SERVICE_NAME}"
34
32
  Util.run "systemctl disable #{SERVICE_NAME}"
35
33
  File.delete SYSTEMD_SERVICE_FILE
36
34
  end
37
- FileUtils.rm_rf DnsOne::WORK_DIR
38
- # TODO: prompt if should remove user
39
- puts "Uninstall complete."
35
+
36
+ # conf_file
37
+ if File.exists? conf.conf_file
38
+ if confirm? "Delete #{conf.conf_file}?"
39
+ FileUtils.rm conf.conf_file
40
+ end
41
+ end
42
+
43
+ # work_dir
44
+ if conf.work_dir == '/var/local/dnsone' # Only deletes if path matches the hardcoded one
45
+ if Dir.exists? conf.work_dir
46
+ if confirm? "Delete #{conf.work_dir}?"
47
+ FileUtils.rm_rf conf.work_dir
48
+ end
49
+ end
50
+ end
51
+
52
+ puts "Removed."
40
53
  end
41
54
 
42
55
  private
43
56
 
44
- def check_ruby_version
45
- if RUBY_VERSION != REQUIRED_RUBY_VERSION
46
- STDERR.puts "Currently dns_one supports #{REQUIRED_RUBY_VERSION} only. Aborting install."
47
- exit 1
57
+ def check_reqs
58
+ unless Process.uid == 0
59
+ die "Install requires root privileges. Run with sudo or login as root. Aborting."
60
+ end
61
+ unless Util.has_systemd?
62
+ warn "DnsOne will install without systemd."
48
63
  end
49
64
  end
50
65
 
51
66
  def add_user
52
- if `cat /etc/passwd|grep ^#{Server::DEFAULT_RUN_AS}:`.strip.present?
53
- STDOUT.puts "User #{Server::DEFAULT_RUN_AS} exists, skipping creation."
54
- else
55
- # TODO: prompt user
56
- system "adduser --system --no-create-home #{Server::DEFAULT_RUN_AS}"
67
+ if `cat /etc/passwd|grep ^#{conf.run_as}:`.strip.present?
68
+ warn "User #{conf.run_as} exists, skipping creation."
69
+ return
57
70
  end
58
- end
59
-
60
- def set_ruby_version
61
- File.write "#{DnsOne::WORK_DIR}/.ruby-version", REQUIRED_RUBY_VERSION
71
+ system "adduser --system --no-create-home '#{conf.run_as}'"
62
72
  end
63
73
 
64
74
  def mkdirs
65
- FileUtils.mkdir_p DnsOne::CONF_DIR
66
-
67
- FileUtils.mkdir_p DnsOne::WORK_DIR
68
- File.chmod 0755, DnsOne::WORK_DIR
69
- File.chown `id -u #{Server::DEFAULT_RUN_AS}`.to_i, nil, DnsOne::WORK_DIR
75
+ if Dir.exists? conf.work_dir
76
+ warn "Work dir #{conf.work_dir} exists, skipping creation."
77
+ return
78
+ end
79
+ FileUtils.mkdir_p conf.work_dir
80
+ File.chmod 0755, conf.work_dir
81
+ File.chown `id -u #{conf.run_as}`.to_i, nil, conf.work_dir
70
82
  end
71
83
 
72
84
  def setup_finished_msg
73
- puts "Installed.\n"
74
- puts "Now:"
75
- puts "1) Edit #{DnsOne::DEFAULT_CONF_FILE}. You can run 'ruby -Ilib/ exe/dns_one --conf util/dev_conf.yml --log=/dev/stdout' to test and adjust your configuration."
76
- puts "2) After configure run 'dns_one start'."
77
- puts "See startup logs with 'tail -f /var/log/syslog'"
78
- puts "See run logs with 'tail -f /var/log/dns_one.log' (or /var/log/dns_one_rubydns.log)"
79
- end
85
+ print <<~HEREDOC
80
86
 
81
- def is_setup?
82
- File.exist?(DnsOne::DEFAULT_CONF_FILE) &&
83
- File.exist?(SYSTEMD_SERVICE_FILE)
87
+ Installed successfully
88
+
89
+ Now:
90
+ 1) Edit #{conf.conf_file}
91
+ 2) After configuration run 'dnsone' (or 'systemctl start dnsone' if systemd is available)
92
+
93
+ Logs are sent to /var/log/dnsone.log
94
+ /var/log/dnsone_rubydns.log
95
+
96
+ HEREDOC
84
97
  end
85
98
 
86
- def check_root
87
- unless Process.uid == 0
88
- STDERR.puts "Install requires root privileges. Run with sudo or login as root. Aborting."
89
- exit 1
90
- end
99
+ def is_setup?
100
+ File.exist? conf.conf_file
91
101
  end
92
102
 
93
103
  def install_systemd_service
94
- copy "#{@thisdir}/../../util/dns_one.service",
104
+ copy "#{@thisdir}/../../util/dnsone.service",
95
105
  SYSTEMD_SERVICE_FILE
96
106
 
97
107
  Util.run "systemctl enable #{SERVICE_NAME}"
98
108
  end
99
109
 
100
110
  def copy_sample_conf
101
- if File.exist? DnsOne::DEFAULT_CONF_FILE
102
- STDOUT.puts "File #{DnsOne::DEFAULT_CONF_FILE} exists, skipping creation."
103
- else
104
- copy "#{@thisdir}/../../util/sample_conf.yml",
105
- DnsOne::DEFAULT_CONF_FILE
111
+ if File.exist? conf.conf_file
112
+ unless confirm? "File #{conf.conf_file} exists. Override it?"
113
+ return
114
+ end
106
115
  end
116
+ copy "#{@thisdir}/../../util/sample_conf.yml",
117
+ conf.conf_file
107
118
  end
108
119
 
109
120
  def copy from, to, mod = 0600
110
121
  puts "Copying #{from} to #{to}..."
111
122
  FileUtils.cp from, to
112
123
  FileUtils.chmod mod, to
124
+
125
+ rescue => e
126
+ warn "Error when copying #{from} to #{to}: #{e.message}"
127
+ unless confirm? "Ignore error?"
128
+ die "exiting"
129
+ end
130
+ end
131
+
132
+ def die msg
133
+ STDERR.puts msg
134
+ exit 1
135
+ end
136
+
137
+ def warn msg
138
+ STDERR.puts msg
139
+ end
140
+
141
+ def confirm? msg
142
+ typed = nil
143
+ loop do
144
+ print "#{msg} (y/n): "
145
+ typed = STDIN.gets.chomp
146
+ break if %w(y n).include? typed
147
+ end
148
+ typed == 'y'
113
149
  end
114
150
 
115
151
  end; end
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.5.12"
2
+ VERSION = "0.5.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.12
4
+ version: 0.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-29 00:00:00.000000000 Z
11
+ date: 2018-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,48 +94,6 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.6'
97
- - !ruby/object:Gem::Dependency
98
- name: pg
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.21'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.21'
111
- - !ruby/object:Gem::Dependency
112
- name: activerecord
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '5.0'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '5.0'
125
- - !ruby/object:Gem::Dependency
126
- name: sqlite3
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '1.3'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '1.3'
139
97
  description: Instead having a complex data schema to assign record sets to DNS zones,
140
98
  dns_one assigns one or a few record sets to many zones. Configure your record sets
141
99
  in YML files and fetch your domains from a database or YML backend.