Module: IpfixerClient
- Extended by:
- Logger
- Includes:
- Win32
- Defined in:
- lib/ipfixer_client.rb,
lib/ipfixer_client/logger.rb,
lib/ipfixer_client/version.rb,
lib/ipfixer_client/installer.rb,
lib/ipfixer_client/net_stuff.rb,
lib/ipfixer_client/ipfixer_svc.rb,
lib/ipfixer_client/config_stuff.rb
Defined Under Namespace
Modules: Logger
Classes: Installer
Constant Summary
collapse
- VERSION =
"0.0.3"
Class Method Summary
collapse
Methods included from Logger
dbg_post_ip, dbg_tell_ddns_our_new_ip, err_ddns_gave_wrong_response_code, err_getting_ip, err_tell_ddns_our_new_ip
Class Method Details
.client_svc ⇒ Object
39
40
41
|
# File 'lib/ipfixer_client.rb', line 39
def self.client_svc
DemoDaemon.mainloop
end
|
.create_the_log_folder ⇒ Object
8
9
10
11
|
# File 'lib/ipfixer_client/logger.rb', line 8
def self.create_the_log_folder
logs_folder = LOG_FOLDER
FileUtils.mkdir_p(logs_folder) unless File.directory?(logs_folder)
end
|
.default_config_settings ⇒ Object
30
31
32
33
34
35
|
# File 'lib/ipfixer_client/config_stuff.rb', line 30
def self.default_config_settings
return {'target_server' => "192.168.0.11",
"port" => 80,
"ip_lookup_url" => "http://api.externalip.net/ip/",
"security_token" => "secret pass"}
end
|
.get_config_file(file_path) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/ipfixer_client/config_stuff.rb', line 22
def self.get_config_file(file_path)
if File.exists?(file_path)
File.open(file_path, "rb")
else
StringIO.new('')
end
end
|
.get_configuration_settings(config_file_path = "C:\\it\\ipfixer\\conf\\config.yml") ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/ipfixer_client/config_stuff.rb', line 6
def self.get_configuration_settings(config_file_path = "C:\\it\\ipfixer\\conf\\config.yml")
return default_config_settings unless File.exists? config_file_path
config_file = get_config_file config_file_path
conf_contents = config_file.read
begin
config = YAML.load_file(config_file)
rescue Exception => e
File.open(LOG_FILE,'a+'){ |f| f.puts " ***YAML FILE PROBLEM DETECTED, The file was likely malformed... Check on it, or delete it and reinstall."; f.puts e.message }
exit!
end
return config
end
|
.get_ip_address(ip_lookup_url) ⇒ Object
You need to wait 300 seconds before using this function
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ipfixer_client/net_stuff.rb', line 3
def self.get_ip_address(ip_lookup_url)
begin
http_response = Net::HTTP.get_response(URI.parse(ip_lookup_url))
rescue Exception => e
err_getting_ip(ip_lookup_url, e.message)
return "failedToGetAddress"
end
if http_response.code == "200"
return http_response.body
else
return http_response.body + http_response.code end
end
|
.help ⇒ Object
35
36
37
|
# File 'lib/ipfixer_client.rb', line 35
def self.help
puts "This is ipfixer_client, a little client... see the docs"
end
|
.install ⇒ Object
43
44
45
46
|
# File 'lib/ipfixer_client.rb', line 43
def self.install
i = Installer.new
i.install
end
|
.invalid_ip?(ip) ⇒ Boolean
Returns true if the string supplied wasn’t actually a valid ip
19
20
21
|
# File 'lib/ipfixer_client/net_stuff.rb', line 19
def self.invalid_ip?(ip)
is_invalid = (ip =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/).nil? ? true : false
end
|
.my_logger(text) ⇒ Object
3
4
5
6
|
# File 'lib/ipfixer_client/logger.rb', line 3
def self.my_logger(text)
create_the_log_folder if !Dir.exists? LOG_FOLDER
File.open(LOG_FILE, "a"){ |f| f.puts text }
end
|
.post_ip(host_name, ip, security_token = nil) ⇒ Object
POST /ipfixes { “ipfix”: { “host”:“Host Name”, “ip”:“192.168.0.1” } }
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/ipfixer_client/net_stuff.rb', line 25
def self.post_ip(host_name, ip, security_token = nil)
security_token = security_token.nil? ? "secret pass" : security_token
path = '/ipfixes.json'
http = Net::HTTP.new(IP_FIXER_HUB, PORT)
req = Net::HTTP::Post.new(path)
req.content_type = 'application/json'
json_string = "{ 'ipfix': { 'host': '#{host_name}', 'ip': '#{ip}', 'security_token': '#{security_token}' } }"
req.body = json_string.gsub("'", '"')
begin
response = http.start {|htp| htp.request(req) }
rescue
my_logger "FAILURE TO POST TO ADDRESS: Check if address and port are operational."
return false
end
dbg_post_ip(host_name, ip, response, req.body) if DEBUG_MODE
return true if response.code == "200" || response.code == "201"
return response.code
end
|
.start ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/ipfixer_client.rb', line 53
def self.start
if IpfixerClient::Installer.service_installed?
puts "We can start"
if WINDOWS
result = `sc start #{SERVICE_NAME}`
puts result
elsif LINUX
end
else
puts "The service is not yet installed, please run the command `ipfixer install`"
end
end
|
.tell_ddns_our_new_ip(ddns_update_url) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ipfixer_client/net_stuff.rb', line 51
def self.tell_ddns_our_new_ip(ddns_update_url)
begin
http_response = Net::HTTP.get_response(URI.parse(ddns_update_url))
dbg_tell_ddns_our_new_ip(http_response.code) if DEBUG_MODE
rescue
err_tell_ddns_our_new_ip(ddns_update_url)
end
if http_response.code == "200"
true
else
err_ddns_gave_wrong_response_code
end
end
|
.uninstall ⇒ Object
48
49
50
51
|
# File 'lib/ipfixer_client.rb', line 48
def self.uninstall
i = Installer.new
i.uninstall
end
|