freewifi 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/freewifi.gemspec CHANGED
@@ -30,7 +30,13 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.16"
34
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "bundler", "2.1.4"
34
+ spec.add_development_dependency "rake", "13.0.1"
35
35
  spec.add_development_dependency "minitest", "~> 5.0"
36
+ spec.add_development_dependency "net-ssh", '4.0.1'
37
+ spec.add_development_dependency "json", "2.3.0"
38
+ spec.add_development_dependency "ipaddr", "1.2.2"
39
+ spec.add_development_dependency "date", "3.0.0"
40
+ spec.add_development_dependency "mysql2", "0.5.3"
41
+ spec.add_development_dependency "mongo", "2.11.4"
36
42
  end
@@ -0,0 +1,38 @@
1
+ require 'date'
2
+
3
+ class InternalFunc
4
+
5
+ def datetimenow()
6
+ d_curr = DateTime.now
7
+ time_zone = 'Europe/Minsk'
8
+ # DateTime.new
9
+ # .in_time_zone(time_zone)
10
+ # .change(year: d_curr.year, month: d_curr.month, day: d_curr.day, hour: d_curr.hour, min: d_curr.min, sec: d_curr.sec)
11
+ d_curr.to_s
12
+ end
13
+
14
+ def printer_texter(text, log_level)
15
+ begin
16
+ mess = {:datetime => datetimenow, :sdk => "freewifi", :sdk_version => Freewifi::VERSION, :message => text}
17
+ p mess
18
+ rescue
19
+ p "Failed print message"
20
+ end
21
+ end
22
+
23
+ def hub_tunnelname_generator(tunnel_id, company_name)
24
+ comp_name = company_name
25
+ "#{tunnel_id.to_s}_eoip_hub_auto_#{comp_name}"
26
+ end
27
+
28
+ def company_check(compname)
29
+ compname2=""
30
+ if compname.include?(" ")
31
+ compname2 = compname.gsub(" ","")
32
+ else
33
+ compname2 = compname
34
+ end
35
+ compname2
36
+ end
37
+
38
+ end
@@ -0,0 +1,89 @@
1
+ require 'mongo'
2
+
3
+ require 'json'
4
+ require 'rubygems'
5
+ require 'freewifi/additional/additional_functions'
6
+
7
+ #class for communication with mongo database for iot API
8
+ class MongoWifi
9
+
10
+ attr_accessor :mongo_ip, :mongo_port, :client, :mongo_database, :additional_func
11
+
12
+ def initialize(mongo_ip, mongo_port, mongo_database)
13
+ @mongo_database = mongo_database
14
+ @mongo_ip = mongo_ip
15
+ @mongo_port = mongo_port
16
+ client_host = [mongo_ip + ":" + mongo_port]
17
+ @client = Mongo::Client.new(client_host, :database => mongo_database)
18
+ @additional_func = InternalFunc.new
19
+ end
20
+
21
+ def audit_logger(proc_name, src_ip, input_json, output_json, real_ip, subscriber_ip)
22
+ out_resp = {}
23
+ begin
24
+ current = additional_func.datetimenow
25
+ collection = client[:audit]
26
+ doc = {
27
+ :proc_name => proc_name,
28
+ :date => current,
29
+ :sender => {:src_ip => src_ip, :real_ip => real_ip, :subscriber_ip => subscriber_ip},
30
+ :input_params => input_json,
31
+ :output_params => output_json,
32
+ :sdk_version => Freewifi::VERSION
33
+ }
34
+ result = collection.insert_one(doc)
35
+ out_resp = {:code => 200, :result => "audit_logger: Request completed successfully", :body => result}
36
+ rescue
37
+ out_resp = {:code => 507, :result => "audit_logger: Unknown SDK error"}
38
+ end
39
+ additional_func.printer_texter(out_resp, "debug")
40
+ out_resp
41
+ end
42
+
43
+
44
+ def data_ap_auto_created_insert(data)
45
+ input_params = {:data => data}
46
+ output_params = {}
47
+ begin
48
+ collection = client[:ap_auto_created]
49
+ result = collection.insert_one(data)
50
+ output_params = {:code => 200, :result => "data_ap_auto_created_insert: Request completed successfully", :body => result}
51
+ rescue
52
+ output_params = {:code => 500, :result => "data_ap_auto_created_insert: failed insert data to mongo"}
53
+ end
54
+ additional_func.printer_texter({:input_params => input_params, :output_params => output_params, :procedure => "data_ap_auto_created_insert", :file => "freewifi/database/mongo/mongoconnector.rb"}, "debug")
55
+ output_params
56
+ end
57
+
58
+ def get_ap_info_sim_ip(sim_ipaddress, sim_msisdn)
59
+ begin
60
+ result_ps = []
61
+ collection = client[:ap_auto_created]
62
+ collection.find({"sim_ipaddress" => sim_ipaddress, "sim_msisdn" => sim_msisdn}).each {|row|
63
+ result_ps << row
64
+ #result_ps.append(row)
65
+ }
66
+ result_ps[0]
67
+ rescue
68
+ []
69
+ end
70
+ end
71
+
72
+ def tunnelid_remove_single_mongo(tunnel_id)
73
+ out_resp = {}
74
+ begin
75
+ collection = client[:ap_auto_created]
76
+ doc = {
77
+ "tunnel_id" => tunnel_id
78
+ }
79
+ result = collection.delete_many(doc)
80
+ p result
81
+ out_resp = {:code => 200, :result => "tunnelid_remove_single_mongo: Request completed successfully"}
82
+ rescue
83
+ out_resp = {:code => 507, :result => "tunnelid_remove_single_mongo: Unknown SDK error"}
84
+ end
85
+ #internal_func.printer_texter(out_resp, "debug")
86
+ out_resp
87
+ end
88
+
89
+ end
@@ -0,0 +1,89 @@
1
+
2
+
3
+ require 'mysql2'
4
+
5
+ class DatabaseMethods
6
+
7
+ attr_accessor :database_username, :database_password, :database_host
8
+
9
+ def initialize(database_username, database_password, database_host)
10
+ @database_username = database_username
11
+ @database_password = database_password
12
+ @database_host = database_host
13
+ end
14
+
15
+
16
+ def wifi_get_max_ap_number
17
+ client = Mysql2::Client.new(:host => database_host, :username => database_username, :password => database_password)
18
+ client.query("use mtsPortalWiFI", :cast => false)
19
+ client.query("SELECT MAX(AP_ID) AS AP_ID FROM List_mikroTik_AP",:as => :array).each do |row|
20
+ client.close
21
+ #"row" + row[0]
22
+ return row [0]
23
+ end
24
+ end
25
+
26
+ def wifi_get_max_tunnel_id
27
+ client = Mysql2::Client.new(:host => database_host, :username => database_username, :password => database_password)
28
+ client.query("use mtsPortalWiFI", :cast => false)
29
+ client.query("SELECT MAX(EoIP_ID) AS EoIP_ID FROM List_mikroTik_eoip_tunnels",:as => :array).each do |row|
30
+ client.close
31
+ #"row" + row[0]
32
+ return row [0]
33
+ end
34
+ end
35
+
36
+ def add_mikrotik_ap_3g_eoip_data(apid, phonenumber, eoipid_man, simip, companyname, bridgename_athub, bridgeip_athub)
37
+ client = Mysql2::Client.new(:host => database_host, :username => database_username, :password => database_password)
38
+ client.query("use mtsPortalWiFI", :cast => false)
39
+ row = ""
40
+ client.query("INSERT INTO List_mikroTik_eoip_tunnels (AP_ID, Phone_number, EoIP_ID, SIM_ip, bridge_ip_at_AP_site, tunnel_name_at_hub_site, MikroTik_hub_ip, state, IWAG_gateway_ip, subscribers_network_mask, tunnel_name_at_ap_site, bridge_name_at_hub_site, bridge_name_at_ap_site, bridge_ip_at_hub_site ) VALUES ( #{apid}, '#{phonenumber}', #{eoipid_man + 1}, '#{simip}', '100.71.112.#{apid.to_s}', '#{apid.to_s}_tunnel_ap1_hub1_#{companyname}', '172.24.211.11', 'on', '100.71.112.1', '21', 'tunnel_to_hab1', '#{bridgename_athub}', 'bridge_tunnel', '#{bridgeip_athub}' )", :cast => false)
41
+ # client.query("INSERT INTO List_mikroTik_eoip_tunnels (AP_ID, Phone_number, EoIP_ID, SIM_ip, bridge_ip_at_AP_site, tunnel_name_at_hub_site, MikroTik_hub_ip, state, IWAG_gateway_ip, subscribers_network_mask, tunnel_name_at_ap_site, bridge_name_at_hub_site, bridge_name_at_ap_site, bridge_ip_at_hub_site ) VALUES ( 89, '67567', 45, '5236256', '100.71.112.45', '45_tunnel_ap1_hub1_45', '172.24.211.11', 'on', '100.71.112.1', '21', 'tunnel_to_hab1', 'gfhhdgh', 'bridge_tunnel', '5452453' )", :cast => false)
42
+ client.close
43
+ end
44
+
45
+ def add_mikrotik_ap_3g_eoip_man(apid, phonenumber, eoipid_man, simip, companyname)
46
+ client = Mysql2::Client.new(:host => database_host, :username => database_username, :password => database_password)
47
+ client.query("use mtsPortalWiFI", :cast => false)
48
+ row = ""
49
+ client.query("INSERT INTO List_mikroTik_eoip_tunnels (AP_ID, Phone_number, EoIP_ID, SIM_ip, bridge_ip_at_AP_site, tunnel_name_at_hub_site, MikroTik_hub_ip, state, IWAG_gateway_ip, subscribers_network_mask, tunnel_name_at_ap_site, bridge_name_at_hub_site, bridge_name_at_ap_site, bridge_ip_at_hub_site ) VALUES ( #{apid}, '#{phonenumber}', #{eoipid_man}, '#{simip}', '100.71.104.#{apid.to_s}', '#{apid.to_s}_tunnel_management_ap1_hub1_#{companyname}', '172.24.211.11', 'on', '100.71.104.1', '21', 'tunnel_Management_to_hab1', 'bridge_management_hub1', 'bridge_tunnel', '100.71.104.2' )", :cast => false)
50
+ # client.query("INSERT INTO List_mikroTik_eoip_tunnels (AP_ID, Phone_number, EoIP_ID, SIM_ip, bridge_ip_at_AP_site, tunnel_name_at_hub_site, MikroTik_hub_ip, state, IWAG_gateway_ip, subscribers_network_mask, tunnel_name_at_ap_site, bridge_name_at_hub_site, bridge_name_at_ap_site, bridge_ip_at_hub_site ) VALUES ( 89, '67567', 45, '5236256', '100.71.112.45', '45_tunnel_ap1_hub1_45', '172.24.211.11', 'on', '100.71.112.1', '21', 'tunnel_to_hab1', 'gfhhdgh', 'bridge_tunnel', '5452453' )", :cast => false)
51
+ client.close
52
+ end
53
+
54
+ def add_mikrotik_ap_3g(apid, phonenumber, eoipid_data, simip, companyname, bridgename_athub, bridgeip_athub)
55
+ client = Mysql2::Client.new(:host => database_host, :username => database_username, :password => database_password)
56
+ client.query("use mtsPortalWiFI", :cast => false)
57
+ row = ""
58
+ client.query("INSERT INTO List_mikroTik_eoip_tunnels (AP_ID, Phone_number, EoIP_ID, SIM_ip, bridge_ip_at_AP_site, tunnel_name_at_hub_site, MikroTik_hub_ip, state, IWAG_gateway_ip, subscribers_network_mask, tunnel_name_at_ap_site, bridge_name_at_hub_site, bridge_name_at_ap_site, bridge_ip_at_hub_site ) VALUES ( #{apid}, '#{phonenumber}', #{eoipid_data}, '#{simip}', '100.71.112.#{apid.to_s}', '#{apid.to_s}_tunnel_ap1_hub1_#{companyname}', '172.24.211.11', 'on', '100.71.112.1', '21', 'tunnel_to_hab1', '#{bridgename_athub}', 'bridge_tunnel', '#{bridgeip_athub}' )", :cast => false)
59
+ # client.query("INSERT INTO List_mikroTik_eoip_tunnels (AP_ID, Phone_number, EoIP_ID, SIM_ip, bridge_ip_at_AP_site, tunnel_name_at_hub_site, MikroTik_hub_ip, state, IWAG_gateway_ip, subscribers_network_mask, tunnel_name_at_ap_site, bridge_name_at_hub_site, bridge_name_at_ap_site, bridge_ip_at_hub_site ) VALUES ( 89, '67567', 45, '5236256', '100.71.112.45', '45_tunnel_ap1_hub1_45', '172.24.211.11', 'on', '100.71.112.1', '21', 'tunnel_to_hab1', 'gfhhdgh', 'bridge_tunnel', '5452453' )", :cast => false)
60
+ client.close
61
+ end
62
+
63
+
64
+ def add_mikrotik_ap_3g_to_list(apid, companyname, app_address, simmsisdn, simimsi, region, contacts, ssid, portal_style, ap_serial_number, ap_model, description)
65
+ client = Mysql2::Client.new(:host => database_host, :username => database_username, :password => database_password)
66
+ client.query("use mtsPortalWiFI", :cast => false)
67
+ row = ""
68
+ client.query("INSERT INTO List_mikroTik_AP (AP_ID, Company_name, AP_address, SIM_MSISDN, SIM_IMSI, Region, Contacts, SSID, Portal_style, AP_serial_number, AP_model, Description) VALUES (#{apid}, '#{companyname}', '#{app_address}', '#{simmsisdn}', '#{simimsi}', '#{region}', '#{contacts}', '#{ssid}', '#{portal_style}', '#{ap_serial_number}', '#{ap_model}', '#{description}')", :cast => false)
69
+ # client.query("INSERT INTO List_mikroTik_eoip_tunnels (AP_ID, Phone_number, EoIP_ID, SIM_ip, bridge_ip_at_AP_site, tunnel_name_at_hub_site, MikroTik_hub_ip, state, IWAG_gateway_ip, subscribers_network_mask, tunnel_name_at_ap_site, bridge_name_at_hub_site, bridge_name_at_ap_site, bridge_ip_at_hub_site ) VALUES ( 89, '67567', 45, '5236256', '100.71.112.45', '45_tunnel_ap1_hub1_45', '172.24.211.11', 'on', '100.71.112.1', '21', 'tunnel_to_hab1', 'gfhhdgh', 'bridge_tunnel', '5452453' )", :cast => false)
70
+ client.close
71
+ end
72
+
73
+
74
+ def check_mikrotik_ap_exists(sim_ipaddr, simmsisdn)
75
+ client = Mysql2::Client.new(:host => database_host, :username => database_username, :password => database_password)
76
+ client.query("use mtsPortalWiFI", :cast => false)
77
+ row = ""
78
+ dffd1= client.query("SELECT AP_ID FROM List_mikroTik_eoip_tunnels WHERE SIM_ip='#{sim_ipaddr}' or Phone_number='#{simmsisdn}'",:as => :array).each do |row|
79
+ client.close
80
+ row[0]
81
+ # if row[0].length ==4
82
+ # return '3'
83
+ # else return nil
84
+ # end
85
+ return row[0]
86
+ #Mysql2::Client#close
87
+ end
88
+ end
89
+ end
File without changes