pihole 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/pihole +64 -0
- data/lib/pi_hole.rb +9 -0
- data/lib/pi_hole/disable_command.rb +18 -0
- data/lib/pi_hole/endpoint.rb +29 -0
- data/lib/pi_hole/status_command.rb +9 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76c6991edc63b968bcdb8d757ed362d4606fce41005b3182c154e3cff8dca619
|
4
|
+
data.tar.gz: a6ffcc4fb6b86954940a1c30c7606a79241a4ffc7038386bd925741307f7145e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3c68305df91d72791f7b0b056a2fd290d269396670549a070a6a61f19ec79d56e3cd626e456fc81a4bd24392431151a4755f62cd731f56423336f60ad40d55b
|
7
|
+
data.tar.gz: 7104b23c43ad83d61abe4a836e7621806d4fbe1b820ac1f665f5ca360a73ade6b39589d4ca67ea523ac10af9d7f1702b0081d3eff675055761892c152835d879
|
data/bin/pihole
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require_relative '../lib/pi_hole'
|
5
|
+
|
6
|
+
class PiHoleCommand < Thor
|
7
|
+
class_option :location, {
|
8
|
+
type: :string,
|
9
|
+
banner: 'http://pihole-domain-or-ip-address',
|
10
|
+
desc: <<~HERE
|
11
|
+
The protocol and domain of the target Pi-Hole server. Can also be defined in the environment variable \
|
12
|
+
PIHOLE_LOCATION.
|
13
|
+
HERE
|
14
|
+
}
|
15
|
+
class_option :api_key, {
|
16
|
+
type: :string,
|
17
|
+
banner: 'api-key',
|
18
|
+
desc: <<~HERE.strip
|
19
|
+
The key used to authenticate with the server. It is strongly recommended to define the environment variable \
|
20
|
+
PIHOLE_API_KEY to prevent leaking this information to your command history.
|
21
|
+
HERE
|
22
|
+
}
|
23
|
+
|
24
|
+
desc 'status', 'Prints the status of the target Pi-Hole server'
|
25
|
+
def status
|
26
|
+
response = endpoint.execute PiHole::StatusCommand.new
|
27
|
+
puts response.body
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'disable', 'Temporarily disable Pi-Hole filtering'
|
31
|
+
method_option :duration, {
|
32
|
+
type: :string,
|
33
|
+
banner: '30',
|
34
|
+
desc: 'The length of time to disable filtering in seconds',
|
35
|
+
required: true
|
36
|
+
}
|
37
|
+
def disable
|
38
|
+
command = DisableCommand.new duration: options[:duration]
|
39
|
+
response = endpoint.execute command
|
40
|
+
puts response.body
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def location
|
46
|
+
@location ||= [
|
47
|
+
options[:location],
|
48
|
+
ENV['PIHOLE_LOCATION'],
|
49
|
+
].compact.first
|
50
|
+
end
|
51
|
+
|
52
|
+
def api_key
|
53
|
+
@api_key ||= [
|
54
|
+
options[:api_key],
|
55
|
+
ENV['PIHOLE_API_KEY'],
|
56
|
+
].compact.first
|
57
|
+
end
|
58
|
+
|
59
|
+
def endpoint
|
60
|
+
@endpoint ||= PiHole::Endpoint.new location: location, api_key: api_key
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
PiHoleCommand.start
|
data/lib/pi_hole.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PiHole
|
4
|
+
# Temporarily disable PiHole blocking
|
5
|
+
class DisableCommand
|
6
|
+
attr_accessor :duration
|
7
|
+
|
8
|
+
# @param [Integer] duration Number of seconds to disable PiHole blocking
|
9
|
+
def initialize(duration: 30)
|
10
|
+
@duration = duration
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return String
|
14
|
+
def query_string
|
15
|
+
"disable=#{@duration}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module PiHole
|
6
|
+
# The main entrypoint for this SDK. Describes the location and interaction with the PiHole API
|
7
|
+
class Endpoint
|
8
|
+
# @param [String] location The protocol and domain (or IP address) via which PiHole is served
|
9
|
+
# @param [String] api_key The API key to access the PiHole API
|
10
|
+
def initialize(location:, api_key:)
|
11
|
+
@location = location
|
12
|
+
@api_key = api_key
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [#query_string] command
|
16
|
+
def execute(command)
|
17
|
+
uri = URI "#{location}/admin/api.php?#{command.query_string}&#{auth_query_string}"
|
18
|
+
Net::HTTP.get_response uri
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :location, :api_key
|
24
|
+
|
25
|
+
def auth_query_string
|
26
|
+
"auth=#{api_key}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pihole
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Yockey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
executables:
|
30
|
+
- pihole
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/pihole
|
35
|
+
- lib/pi_hole.rb
|
36
|
+
- lib/pi_hole/disable_command.rb
|
37
|
+
- lib/pi_hole/endpoint.rb
|
38
|
+
- lib/pi_hole/status_command.rb
|
39
|
+
homepage: https://github.com/yock/pihole-ruby
|
40
|
+
licenses:
|
41
|
+
- Unlicense
|
42
|
+
metadata:
|
43
|
+
course_code_uri: https://github.com/yock/pihole-ruby
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.2.3
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: A Ruby SDK and command-line tool for interacting with the Pi-Hole HTTP API
|
63
|
+
test_files: []
|