freewifi 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Freewifi
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/freewifi.rb CHANGED
@@ -1,22 +1,153 @@
1
+ #$LOAD_PATH.unshift File.expand_path("../freewifi", __dir__)
2
+ $LOAD_PATH.unshift File.expand_path("../mikrotik", __dir__)
3
+ $LOAD_PATH.unshift File.expand_path("../database/mysql", __dir__)
4
+ $LOAD_PATH.unshift File.expand_path("../database/mongo", __dir__)
5
+ $LOAD_PATH.unshift File.expand_path("../additional", __dir__)
6
+
1
7
  require "freewifi/version"
8
+ require 'freewifi/mikrotik/hewhub_mtik_ssh'
9
+ require 'freewifi/database/mysql/database_methods'
10
+ require 'freewifi/database/mongo/mongoconnector'
11
+ require 'date'
12
+
13
+ #eoip tunnel ids generates between 10001 - 65535
14
+
2
15
 
3
16
  module Freewifi
4
- # Your code goes here...
5
- def initialize(hub1ip, hub2ip, username_hub, password_hub)
17
+ attr_accessor :mtik_hub1_ip,
18
+ :mtik_hub2_ip,
19
+ :user_hub,
20
+ :password_hub,
21
+ :cps_class,
22
+ :db_mysql,
23
+ :additional_func,
24
+ :ssh_mikrotik_connector,
25
+ :mongo_connector,
26
+ :remote_ip,
27
+ :real_ip,
28
+ :subscriber_ip
29
+
30
+ def initialize(hub1ip, hub2ip, username_hub, password_hub, database_username, database_password, database_host, mongo_ip, mongo_port, mongo_database, remote_ip, real_ip,subscriber_ip)
6
31
  @mtik_hub1_ip = hub1ip
7
32
  @mtik_hub2_ip = hub2ip
8
33
  @user_hub = username_hub
9
34
  @password_hub = password_hub
35
+ @db_mysql = DatabaseMethods.new(database_username, database_password, database_host)
36
+ @additional_func = InternalFunc.new
37
+ @ssh_mikrotik_connector = NEWhub.new
38
+ @mongo_connector = MongoWifi.new(mongo_ip, mongo_port, mongo_database)
39
+ @remote_ip = remote_ip
40
+ @real_ip = real_ip
41
+ @subscriber_ip = subscriber_ip
10
42
  end
11
43
 
12
- def self.init(hub1ip, hub2ip, username, password)
13
- #@@mtik_hub1_ip = hub1ip
44
+
45
+ def add_mikrotik_ap_mobile(sim_ipaddress, sim_msisdn, bridge_name_hub, company_name, subscribers_address, subscribers_region, subscribers_contacts, wifi_ssid, portalstyle, ap_serial_number, ap_model, description, note)
46
+
47
+ input_params = {:sim_ipaddress => sim_ipaddress,
48
+ :sim_msisdn => sim_msisdn,
49
+ :bridge_name_hub => bridge_name_hub,
50
+ :company_name => company_name,
51
+ :subscribers_address => subscribers_address,
52
+ :subscribers_region => subscribers_region,
53
+ :subscribers_contacts => subscribers_contacts,
54
+ :wifi_ssid => wifi_ssid,
55
+ :portalstyle => portalstyle,
56
+ :ap_serial_number => ap_serial_number,
57
+ :ap_model => ap_model,
58
+ :description => description,
59
+ :note => note
60
+ }
61
+ output_params = {}
62
+
63
+ begin
64
+
65
+ processed_comp_name = additional_func.company_check(company_name)
66
+ #p ap_state = db_mysql.check_mikrotik_ap_exists(sim_ipaddress, sim_msisdn).to_s
67
+ ap_state = mongo_connector.get_ap_info_sim_ip(sim_ipaddress, sim_msisdn).to_s
68
+
69
+ if ap_state == "" || ap_state == nil || ap_state == "[]" || ap_state == "fttx"
70
+ tunnel_addition = ssh_mikrotik_connector.add_eoip_for_mikr(bridge_name_hub,
71
+ sim_ipaddress,
72
+ processed_comp_name,
73
+ mtik_hub1_ip,
74
+ mtik_hub2_ip,
75
+ user_hub,
76
+ password_hub)
77
+
78
+
79
+ if tunnel_addition[:code] == 200
80
+
81
+ data = {:sim_ipaddress => sim_ipaddress,
82
+ :sim_msisdn => sim_msisdn,
83
+ :bridge_name_hub => bridge_name_hub,
84
+ :company_name => company_name,
85
+ :subscribers_address => subscribers_address,
86
+ :subscribers_region => subscribers_region,
87
+ :subscribers_contacts => subscribers_contacts,
88
+ :wifi_ssid => wifi_ssid,
89
+ :portalstyle => portalstyle,
90
+ :ap => "MikroTik",
91
+ :ap_serial_number => ap_serial_number,
92
+ :ap_model => ap_model,
93
+ :description => description,
94
+ :note => note,
95
+ :tunnel_id => tunnel_addition[:body][:eoip_tunnel_id],
96
+ :tunnel_name => tunnel_addition[:body][:eoip_tunnel_name],
97
+ :created_date => DateTime.now
98
+ }
99
+
100
+ mongo_response = mongo_connector.data_ap_auto_created_insert(data)
101
+ if mongo_response[:code]==200
102
+ output_params = {:code => 200, :result => "Request completed successfully", :body => {:tunnel_id => tunnel_addition[:body][:eoip_tunnel_id], :tunnel_name => tunnel_addition[:body][:eoip_tunnel_name]}}
103
+ else
104
+ output_params = {:code => 400, :result => "Something wrong with insertion to mongo"}
105
+ end
106
+ else
107
+ output_params = {:code => 401, :result => tunnel_addition[:result]}
108
+ end
109
+ else
110
+ output_params = {:code => 202, :result => "AP exists"}
111
+ end
112
+ rescue
113
+ output_params = {:code => 507, :result => "Unknown SDK error"}
114
+ end
115
+ mongo_connector.audit_logger("add_mikrotik_ap_mobile", remote_ip, input_params, output_params, real_ip, subscriber_ip)
116
+ #additional_func.printer_texter({:input_params => input_params, :output_params => output_params, :procedure => "add_mikrotik_ap_mobile", :file => "freewifi.rb"}, "info")
117
+ output_params
14
118
  end
15
119
 
16
- def add_eoip_for_mikr_hub(bridge_name, ap_ip_address, tunnel_id, tunnel_name)
120
+
121
+ def add_eoip_for_mikr_hub(bridge_name, ap_ip_address, tunnel_name)
17
122
  newhub = NEWhub.new
18
- newhub.add_eoip_for_mikr(bridge_name, ap_ip_address, tunnel_id, tunnel_name, @mtik_hub1_ip, @mtik_hub2_ip, @user_hub, @password_hub)
123
+ newhub.add_eoip_for_mikr(bridge_name,
124
+ ap_ip_address,
125
+ tunnel_name,
126
+ mtik_hub1_ip,
127
+ mtik_hub2_ip,
128
+ user_hub,
129
+ password_hub)
130
+ end
131
+
132
+ def del_one_eoip_from_mikr_hub(tunnel_id)
133
+ newhub1 = NEWhub.new
134
+ newhub1.del_eoip_for_mikr(tunnel_id, mtik_hub1_ip, mtik_hub2_ip, user_hub, password_hub)
135
+ p tid = tunnel_id.to_i
136
+ mongo_connector.tunnelid_remove_single_mongo(tid)
137
+ end
138
+
139
+ def test()
140
+ #newhub1 = NEWhub.new
141
+ #newhub1.hub_get_all_eoip_tunnels("172.24.223.132", "soapgw", "fr8Hn3Ed2k0Im4gWmav2Nh7Y1qAm8KlmRh3Dcu2Wcok5gBdm")
142
+ mongo_connector.data_ap_auto_created_insert(:test => "test")
19
143
  end
20
144
  end
21
145
 
22
146
 
147
+ class Fwifi
148
+ include Freewifi
149
+ end
150
+
151
+
152
+ #tested on 6.46.2 router os
153
+
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freewifi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-02 00:00:00.000000000 Z
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 2.1.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 13.0.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 13.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,90 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-ssh
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 4.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 4.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: ipaddr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: date
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: mysql2
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.3
125
+ - !ruby/object:Gem::Dependency
126
+ name: mongo
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 2.11.4
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 2.11.4
55
139
  description: description for my gem
56
140
  email:
57
141
  - imperituro.ard@gmail.com
@@ -76,7 +160,11 @@ files:
76
160
  - bin/setup
77
161
  - freewifi.gemspec
78
162
  - lib/freewifi.rb
79
- - lib/freewifi/hewhub_mtik.rb
163
+ - lib/freewifi/additional/additional_functions.rb
164
+ - lib/freewifi/database/mongo/mongoconnector.rb
165
+ - lib/freewifi/database/mysql/database_methods.rb
166
+ - lib/freewifi/mikrotik/getsubscribermikrotik.rb
167
+ - lib/freewifi/mikrotik/hewhub_mtik_ssh.rb
80
168
  - lib/freewifi/version.rb
81
169
  homepage: https://rubygems.org/gems/freewifi
82
170
  licenses:
@@ -1,85 +0,0 @@
1
- require 'net/ssh'
2
- require 'ipaddr'
3
-
4
-
5
-
6
- class NEWhub
7
-
8
-
9
- def add_eoip_for_mikr(bridge_name, ap_ip_address, tunnel_id, tunnel_name, hub1, hub2, user_hub, password_hub)
10
-
11
- Net::SSH.start(hub1, user_hub, :password => password_hub) do |ssh|
12
- result = ssh.exec!("/interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{tunnel_id} name=#{tunnel_name}")
13
- result2 = ssh.exec!("/interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name} unknown-multicast-flood=no unknown-unicast-flood=no")
14
- end
15
- #Net::SSH.stop
16
-
17
- Net::SSH.start(hub2, user_hub, :password => password_hub) do |ssh|
18
- result = ssh.exec!("/interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{tunnel_id} name=#{tunnel_name}")
19
- result2 = ssh.exec!("/interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name} unknown-multicast-flood=no unknown-unicast-flood=no")
20
- end
21
- #Net::SSH.stop
22
- end
23
-
24
- def del_eoip_for_mikr(bridge_name, ap_ip_address, tunnel_id, tunnel_name, hub1, hub2, user_hub, password_hub)
25
-
26
- Net::SSH.start(hub1, user_hub, :password => password_hub) do |ssh|
27
- #result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}")
28
- #p result
29
- result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}")
30
- regimsi = /\s+name=\"(.+)\"\s+/
31
- m1 = regimsi.match(result)[1]
32
- sleep 0.2
33
- result2 = ssh.exec!("/interface bridge port remove [/interface bridge port find interface=#{m1}]")
34
- sleep 0.2
35
- result3 = ssh.exec!("/interface eoip remove [/interface eoip find where tunnel-id=#{tunnel_id}]")
36
-
37
- #result2 = ssh.exec!("interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name}")
38
- end
39
- #Net::SSH.stop
40
-
41
- Net::SSH.start(hub2, user_hub, :password => password_hub) do |ssh|
42
- result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}")
43
- regimsi = /\s+name=\"(.+)\"\s+/
44
- m1 = regimsi.match(result)[1]
45
- sleep 0.2
46
- result2 = ssh.exec!("/interface bridge port remove [/interface bridge port find interface=#{m1}]")
47
- sleep 0.2
48
- result3 = ssh.exec!("/interface eoip remove [/interface eoip find where tunnel-id=#{tunnel_id}]")
49
-
50
- #result = ssh.exec!("interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{tunnel_id} name=#{tunnel_name}")
51
- #result2 = ssh.exec!("interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name}")
52
- end
53
- #Net::SSH.stop
54
- end
55
-
56
-
57
-
58
-
59
-
60
- def ap_get_info(ap_ip_address, ap_login, ap_password)
61
- res = ""
62
- Net::SSH.start(ap_ip_address, ap_login, :password => ap_password) do |ssh|
63
- result = ssh.exec!("system identity print")
64
- dff = result.to_s
65
- res = dff.gsub!("name: ","").gsub!("\r\n\r\n","").gsub!(" ","")
66
- end
67
- res
68
- end
69
-
70
- def ap_tun_rewrite(ap_ip_address,tun_id, ap_login, ap_password)
71
- res = ""
72
- Net::SSH.start(ap_ip_address, ap_login, :password => ap_password) do |ssh|
73
- result = ssh.exec!("/interface eoip set tunnel_to_hab1 tunnel-id=#{tun_id} remote-address=172.24.202.145")
74
- end
75
- res
76
- end
77
-
78
-
79
- def mikr_tunnelid_gen()
80
- t_id_min = 10001
81
- t_id_max = 65535
82
- end
83
-
84
-
85
- end