freewifi 0.2.1 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift File.expand_path("../huawei", __dir__)
5
5
  require 'freewifi/cisco/iwag/iwag_telnet_connector'
6
6
  require 'freewifi/mikrotik/newhub_mtik_api'
7
7
  require 'freewifi/huawei/hua_controller_class'
8
+ require 'freewifi/cisco/iwag/get_iwag_data'
8
9
  require 'rubygems'
9
10
  require 'savon'
10
11
 
@@ -18,10 +19,36 @@ class WiFiPortal_1
18
19
  :mtik_user,
19
20
  :mtik_password,
20
21
  :mtik_api_connector,
21
- :hua_controller_connector
22
-
23
- def initialize(apigw_wsdl, apigw_endpoint, apigw_namespace, apigw_wsse_aut_log, apigw_wsse_aut_pass, iwag1_host, iwag_username, iwag_password, mtik_control_ips_get, mtik_user, mtik_password, hua_wlc_1_ip, hua_wlc_2_ip, hua_wlc_login, hua_wlc_password)
24
- @iwag_telnet_connector = CSRtelnet_1.new(iwag1_host, iwag_username, iwag_password)
22
+ :hua_controller_connector,
23
+ :iwag_connector1,
24
+ :iwag_connector2,
25
+ :protocol_mtik,
26
+ :mtik_capsman_list
27
+
28
+ def initialize(apigw_wsdl,
29
+ apigw_endpoint,
30
+ apigw_namespace,
31
+ apigw_wsse_aut_log,
32
+ apigw_wsse_aut_pass,
33
+ iwag1_host,
34
+ iwag1_username,
35
+ iwag1_password,
36
+ iwag1_port,
37
+ mtik_control_ips_get,
38
+ mtik_user,
39
+ mtik_password,
40
+ hua_wlc_1_ip,
41
+ hua_wlc_2_ip,
42
+ hua_wlc_login,
43
+ hua_wlc_password,
44
+ iwag2_host,
45
+ iwag2_username,
46
+ iwag2_password,
47
+ iwag2_port,
48
+ protocol_mtik,
49
+ mtik_capsman_list
50
+ )
51
+ @iwag_telnet_connector = CSRtelnet_1.new(iwag1_host, iwag1_username, iwag1_password)
25
52
  @ard_api_gw_connector_wifi = Savon.client do
26
53
  #ssl_verify_mode :none
27
54
  wsdl apigw_wsdl
@@ -33,13 +60,18 @@ class WiFiPortal_1
33
60
  end
34
61
 
35
62
  @iwag1_host = iwag1_host
36
- @iwag_username = iwag_username
37
- @iwag_password = iwag_password
63
+ @iwag_username = iwag1_username
64
+ @iwag_password = iwag1_password
38
65
 
39
66
  @mtik_api_connector = NEWhubWifiApi_1.new(mtik_control_ips_get, mtik_user, mtik_password)
40
67
 
41
68
  @hua_controller_connector = HuaWifi_1.new(hua_wlc_1_ip, hua_wlc_2_ip, hua_wlc_login, hua_wlc_password)
42
69
 
70
+ @iwag_connector1 = IwagRequester.new(iwag1_host, iwag1_username, iwag1_password, iwag1_port)
71
+ @iwag_connector2 = IwagRequester.new(iwag2_host, iwag2_username, iwag2_password, iwag2_port)
72
+
73
+ @protocol_mtik = protocol_mtik
74
+ @mtik_capsman_list = mtik_capsman_list
43
75
  end
44
76
 
45
77
 
@@ -55,6 +87,16 @@ class WiFiPortal_1
55
87
  end
56
88
  end
57
89
 
90
+
91
+ def ssh_mac_iwag1_1(ipaddress)
92
+ begin
93
+ data_iw1 = iwag_connector1.iwag_get_dhcp_binding_ssh(ipaddress)
94
+ "#{data_iw1[:mac]} #{data_iw1[:iwaginterface]} #{data_iw1[:aphostname]} #{data_iw1[:SSID]}"
95
+ rescue
96
+ return "Unknown Unknown Unknown Unknown"
97
+ end
98
+ end
99
+
58
100
  def python_mac_iwag2_1(ipaddress)
59
101
  begin
60
102
  response = ard_api_gw_connector_wifi.call(:mts_python_mac_iwag2) do
@@ -67,6 +109,15 @@ class WiFiPortal_1
67
109
  end
68
110
  end
69
111
 
112
+ def ssh_mac_iwag2_1(ipaddress)
113
+ begin
114
+ data_iw1 = iwag_connector2.iwag_get_dhcp_binding_ssh(ipaddress)
115
+ "#{data_iw1[:mac]} #{data_iw1[:iwaginterface]} #{data_iw1[:aphostname]} #{data_iw1[:SSID]}"
116
+ rescue
117
+ return "Unknown Unknown Unknown Unknown"
118
+ end
119
+ end
120
+
70
121
  def get_subs_add_info3_1(ipaddress, access_interface)
71
122
 
72
123
 
@@ -80,7 +131,7 @@ class WiFiPortal_1
80
131
  begin
81
132
 
82
133
  dump =""
83
- connection = Net::Telnet.new("Host" => "172.24.247.183", "Timeout" => false, "Prompt" => /.*\#/) {|str|}
134
+ connection = Net::Telnet.new("Host" => "172.24.247.183", "Timeout" => false, "Prompt" => /.*#/) {|str|}
84
135
  connection.login({"Name" => iwag_username, "Password" => iwag_password, "LoginPrompt" => /Username:/}) {|str|}
85
136
  connection.cmd("show ip dhcp binding #{ipaddress}") {
86
137
  |c|
@@ -207,13 +258,7 @@ class WiFiPortal_1
207
258
 
208
259
  def get_subs_add_info4new_1(access_interface, subscribers_mac)
209
260
 
210
- capsman_list = [
211
- "172.24.247.15",
212
- "172.24.214.155",
213
- "172.24.214.140",
214
- "172.24.214.105",
215
- "172.24.223.105"
216
- ]
261
+ capsman_list = mtik_capsman_list
217
262
 
218
263
  answer = ""
219
264
 
@@ -226,11 +271,27 @@ class WiFiPortal_1
226
271
  capsman_list.each do |capsman|
227
272
  threads_mikro_wlc << Thread.new do
228
273
  begin
229
- p mikr_info5 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, capsman)
230
- splitting5 = mikr_info5.split("---")
231
- if splitting5[1] != "not on mikrotik controller" && splitting5[1]!="unknown" && splitting5[1]!=nil
232
- answer = mikr_info5
233
- p answer
274
+ if protocol_mtik == 'api'
275
+ p mikr_info5 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, capsman)
276
+ splitting5 = mikr_info5.split("---")
277
+ if splitting5[1] != "not on mikrotik controller" && splitting5[1]!="unknown" && splitting5[1]!=nil
278
+ answer = mikr_info5
279
+ p answer
280
+ end
281
+ elsif protocol_mtik == 'ssh'
282
+ p mikr_info5 = mtik_api_connector.get_info_subs_from_mik_ssh(subscribers_mac, capsman)
283
+ splitting5 = mikr_info5.split("---")
284
+ if splitting5[1] != "not on mikrotik controller" && splitting5[1]!="unknown" && splitting5[1]!=nil
285
+ answer = mikr_info5
286
+ p answer
287
+ end
288
+ else
289
+ p mikr_info5 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, capsman)
290
+ splitting5 = mikr_info5.split("---")
291
+ if splitting5[1] != "not on mikrotik controller" && splitting5[1]!="unknown" && splitting5[1]!=nil
292
+ answer = mikr_info5
293
+ p answer
294
+ end
234
295
  end
235
296
  rescue
236
297
  p "thr0 wrong"
@@ -626,5 +687,385 @@ class WiFiPortal_1
626
687
  end
627
688
 
628
689
 
690
+ def get_subs_info_ret_ssh_1(ip_address)
691
+
692
+ input_params = {:ip_address => ip_address}
693
+ output_params = {}
694
+
695
+ begin
696
+ ipaddr_transformed = IPAddr.new ip_address
697
+ ipaddr_network = ipaddr_transformed.mask(17).to_s
698
+
699
+ if ipaddr_network == "100.71.0.0" #iwag old
700
+
701
+ output_params = self.proc_100_71_0_0_ssh(ip_address)
702
+
703
+ elsif ipaddr_network == "100.75.0.0" #min11iwag2
704
+
705
+ output_params = self.proc_100_75_0_0_ssh(ip_address)
706
+
707
+ elsif ipaddr_network == "100.70.0.0" #min11iwag1
708
+
709
+ output_params = self.proc_100_70_0_0_ssh(ip_address)
710
+
711
+ else
712
+ output_params = {:code => 404, :result => "ERROR. Unknown IP Pool."}
713
+ end
714
+
715
+ rescue
716
+ output_params = {:code => 500, :result => "ERROR. Something wrong.", :body => "SOAP mts_wifi_get_subs_info_return errorMethod unknown error"}
717
+ end
718
+
719
+ output_params
720
+
721
+ end
722
+
723
+
724
+ def proc_100_71_0_0_ssh(ip_address)
725
+ begin
726
+ p access_int = iwag_telnet_connector.return_iwag_access_interface_1(ip_address)
727
+
728
+ ip_a = ip_address
729
+
730
+ access_poi = "unknown"
731
+ ssid_a = "unknown"
732
+ tx_rate_se = "unknown"
733
+ tx_rat = "unknown"
734
+ rx_rat = "unknown"
735
+ rx_signa = "unknown"
736
+ uptim = "unknown"
737
+ packet = "unknown"
738
+ byt = "unknown"
739
+
740
+ if access_int == "Tunnel5"
741
+ mikr_info2 = self.get_subs_add_info3_1(ip_address, access_int)
742
+ splitting2 = mikr_info2.split("---")
743
+ subs_mac = splitting2[0]
744
+ access_poi = "belrw_3_Cisco_ap1-1"
745
+ ssid_a = "BelRW_WiFi"
746
+ tx_rate_se = "unknown"
747
+ tx_rat = "unknown"
748
+ rx_rat = "unknown"
749
+ rx_signa = "unknown"
750
+ uptim = "unknown"
751
+ packet = "unknown"
752
+ byt = "unknown"
753
+ elsif access_int == "GigabitEthernet2.4008"
754
+ mikr_info3 = self.get_subs_add_info3_1(ip_address, access_int)
755
+ splitting3 = mikr_info3.split("---")
756
+ subs_mac = splitting3[0]
757
+ access_poi = "belrw_4_HP_ap1-1"
758
+ ssid_a = "BelRW_WiFi"
759
+ tx_rate_se = "unknown"
760
+ tx_rat = "unknown"
761
+ rx_rat = "unknown"
762
+ rx_signa = "unknown"
763
+ uptim = "unknown"
764
+ packet = "unknown"
765
+ byt = "unknown"
766
+ elsif access_int == "Tunnel9"
767
+ subs_mac = iwag_telnet_connector.get_subs_mac2_1(ip_address)
768
+ p resp1 = hua_controller_connector.get_sub_info_1(subs_mac)
769
+ p resp=resp1.split(",,,")
770
+
771
+ p access_poi = resp[1]
772
+ p ssid_a = resp[2]
773
+ p tx_rate_se = resp[3]
774
+ p tx_rat = resp[4]
775
+ p rx_rat = resp[5]
776
+ p rx_signa = resp[6]
777
+ p uptim = resp[7]
778
+ p packet = resp[8]
779
+ p byt = resp[9]
780
+ elsif access_int == "Tunnel16"
781
+ subs_mac = iwag_telnet_connector.get_subs_mac2_1(ip_address)
782
+ p resp1 = hua_controller_connector.get_sub_info2_1(subs_mac)
783
+ p resp=resp1.split(",,,")
784
+
785
+ p access_poi = resp[1]
786
+ p ssid_a = resp[2]
787
+ p tx_rate_se = resp[3]
788
+ p tx_rat = resp[4]
789
+ p rx_rat = resp[5]
790
+ p rx_signa = resp[6]
791
+ p uptim = resp[7]
792
+ p packet = resp[8]
793
+ p byt = resp[9]
794
+ else
795
+ p "before get info"
796
+ p mikr_info5 = self.get_subs_add_info3_1(ip_address, access_int)
797
+ p "after get info"
798
+ splitting5 = mikr_info5.split("---")
799
+ p subs_mac = splitting5[0]
800
+
801
+ p access_poi = splitting5[1]
802
+ p ssid_a = splitting5[2]
803
+ p tx_rate_se = splitting5[3]
804
+ p tx_rat = splitting5[4]
805
+ p rx_rat = splitting5[5]
806
+ p rx_signa = splitting5[6]
807
+ p uptim = splitting5[7]
808
+ p packet = splitting5[8]
809
+ p byt = splitting5[9]
810
+
811
+
812
+ if access_poi==nil || access_poi=="" || access_poi=="unknown"
813
+ access_poi = "not on mikrotik controller"
814
+ end
815
+
816
+ if ssid_a==nil || ssid_a=="" || ssid_a=="unknown"
817
+ ssid_a = "unknown"
818
+ tx_rate_se = "unknown"
819
+ tx_rat = "unknown"
820
+ rx_rat = "unknown"
821
+ rx_signa = "unknown"
822
+ uptim = "unknown"
823
+ packet = "unknown"
824
+ byt = "unknown"
825
+ end
826
+
827
+ end
828
+
829
+ if subs_mac=="unknown"
830
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
831
+ end
832
+
833
+ if subs_mac==""
834
+ subs_mac="unknown"
835
+ end
836
+
837
+
838
+ mess = {:iwag_access_interface => access_int,
839
+ :subscribers_mac => subs_mac,
840
+ :access_point => access_poi,
841
+ :ssid_ap => ssid_a,
842
+ :apid => "unknown",
843
+ :statistics =>
844
+ {:tx_rate_set => tx_rate_se,
845
+ :tx_rate => tx_rat,
846
+ :rx_rate => rx_rat,
847
+ :rx_signal => rx_signa,
848
+ :uptime => uptim,
849
+ :packets => packet,
850
+ :bytes => byt}
851
+ }
852
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
853
+ output_params = {:code => 200, :result => "Request completed", :body => {:message => mess}}
854
+ rescue
855
+
856
+ puts 'SOAP mts_wifi_get_subs_info_return errorMethod'
857
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
858
+ end
859
+ output_params
860
+ end
861
+
862
+ def proc_100_75_0_0_ssh(ip_address)
863
+
864
+ begin
865
+ result_iwag = self.ssh_mac_iwag2_1(ip_address)
866
+ if result_iwag.split(" ")[0]!="Unknown"
867
+ ppp = result_iwag.split(" ")
868
+
869
+ subs_mac = ppp[0]
870
+ access_int = ppp[1]
871
+ access_poi = ppp[2]
872
+ ssid_a = ppp[3]
873
+
874
+ tx_rate_se = "unknown"
875
+ tx_rat = "unknown"
876
+ rx_rat = "unknown"
877
+ rx_signa = "unknown"
878
+ uptim = "unknown"
879
+ packet = "unknown"
880
+ byt = "unknown"
881
+
882
+ if access_int=='GigabitEthernet4.3002'
883
+ access_poi = "belrw_4_HP_ap1-1"
884
+ ssid_a = "BelRW_WiFi"
885
+ elsif access_int=='GigabitEthernet4.3005'
886
+ access_poi = "belbiz-AP1-1"
887
+ ssid_a = "IMAGURU_GUEST"
888
+ end
889
+
890
+ if access_poi == "Unknown" && ssid_a == "Unknown" && subs_mac != "Unknown"
891
+ frommikrotik = self.get_subs_add_info4new_1(access_int, subs_mac)
892
+ splitting5 = frommikrotik.split("---")
893
+ p access_poi = splitting5[1]
894
+ p ssid_a = splitting5[2]
895
+ p tx_rate_se = splitting5[3]
896
+ p tx_rat = splitting5[4]
897
+ p rx_rat = splitting5[5]
898
+ p rx_signa = splitting5[6]
899
+ p uptim = splitting5[7]
900
+ p packet = splitting5[8]
901
+ p byt = splitting5[9]
902
+ end
903
+
904
+ if subs_mac=="unknown"
905
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
906
+ end
907
+
908
+ if subs_mac==""
909
+ subs_mac="unknown"
910
+ end
911
+
912
+
913
+ mess = {:iwag_access_interface => access_int,
914
+ :subscribers_mac => subs_mac,
915
+ :access_point => access_poi,
916
+ :ssid_ap => ssid_a,
917
+ :apid => "unknown",
918
+ :statistics =>
919
+ {:tx_rate_set => tx_rate_se,
920
+ :tx_rate => tx_rat,
921
+ :rx_rate => rx_rat,
922
+ :rx_signal => rx_signa,
923
+ :uptime => uptim,
924
+ :packets => packet,
925
+ :bytes => byt}
926
+ }
927
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
928
+ output_params = {:code => 200, :result => "Request completed", :body => {:message => mess}}
929
+ p output_params
930
+
931
+ else
932
+
933
+ mess = {:iwag_access_interface => "unknown",
934
+ :subscribers_mac => "unknown",
935
+ :access_point => "unknown",
936
+ :ssid_ap => "unknown",
937
+ :apid => "unknown",
938
+ :statistics =>
939
+ {:tx_rate_set => "unknown",
940
+ :tx_rate => "unknown",
941
+ :rx_rate => "unknown",
942
+ :rx_signal => "unknown",
943
+ :uptime => "unknown",
944
+ :packets => "unknown",
945
+ :bytes => "unknown"}
946
+ }
947
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{params[:ipaddress]} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
948
+ output_params = {:code => 202, :result => "Request completed", :body => {:message => mess}}
949
+ p output_params
950
+
951
+ end
952
+ rescue
953
+ puts 'SOAP mts_wifi_get_subs_info_return errorMethod'
954
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
955
+ end
956
+
957
+ output_params
958
+
959
+ ####
960
+ end
961
+
962
+
963
+ def proc_100_70_0_0_ssh(ip_address)
964
+ p "min11iwag1"
965
+
966
+ begin
967
+ result_iwag = self.ssh_mac_iwag1_1(ip_address)
968
+ p result_iwag
969
+ if result_iwag.split(" ")[0]!="Unknown"
970
+ ppp = result_iwag.split(" ")
971
+
972
+ subs_mac = ppp[0]
973
+ access_int = ppp[1]
974
+ access_poi = ppp[2]
975
+ ssid_a = ppp[3]
976
+
977
+
978
+ if access_int=='GigabitEthernet4.3002'
979
+ access_poi = "belrw_4_HP_ap1-1"
980
+ ssid_a = "BelRW_WiFi"
981
+ elsif access_int=='GigabitEthernet4.3005'
982
+ access_poi = "belbiz-AP1-1"
983
+ ssid_a = "IMAGURU_GUEST"
984
+ end
985
+
986
+ if access_poi == "Unknown" && ssid_a == "Unknown" && subs_mac != "Unknown"
987
+ frommikrotik = self.get_subs_add_info4new_1(access_int, subs_mac)
988
+ splitting5 = frommikrotik.split("---")
989
+ p access_poi = splitting5[1]
990
+ p ssid_a = splitting5[2]
991
+ p tx_rate_se = splitting5[3]
992
+ p tx_rat = splitting5[4]
993
+ p rx_rat = splitting5[5]
994
+ p rx_signa = splitting5[6]
995
+ p uptim = splitting5[7]
996
+ p packet = splitting5[8]
997
+ p byt = splitting5[9]
998
+ end
999
+
1000
+ tx_rate_se = "unknown"
1001
+ tx_rat = "unknown"
1002
+ rx_rat = "unknown"
1003
+ rx_signa = "unknown"
1004
+ uptim = "unknown"
1005
+ packet = "unknown"
1006
+ byt = "unknown"
1007
+
1008
+ if subs_mac=="unknown"
1009
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
1010
+ end
1011
+
1012
+ if subs_mac==""
1013
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
1014
+ end
1015
+
1016
+ mess = {:iwag_access_interface => access_int,
1017
+ :subscribers_mac => subs_mac,
1018
+ :access_point => access_poi,
1019
+ :ssid_ap => ssid_a,
1020
+ :apid => "unknown",
1021
+ :statistics =>
1022
+ {:tx_rate_set => tx_rate_se,
1023
+ :tx_rate => tx_rat,
1024
+ :rx_rate => rx_rat,
1025
+ :rx_signal => rx_signa,
1026
+ :uptime => uptim,
1027
+ :packets => packet,
1028
+ :bytes => byt}
1029
+ }
1030
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
1031
+ output_params = {:code => 200, :result => "Request completed", :body => {:message => mess}}
1032
+ p output_params
1033
+
1034
+ else
1035
+
1036
+ mess = {:iwag_access_interface => "unknown",
1037
+ :subscribers_mac => "unknown",
1038
+ :access_point => "unknown",
1039
+ :ssid_ap => "unknown",
1040
+ :apid => "unknown",
1041
+ :statistics =>
1042
+ {:tx_rate_set => "unknown",
1043
+ :tx_rate => "unknown",
1044
+ :rx_rate => "unknown",
1045
+ :rx_signal => "unknown",
1046
+ :uptime => "unknown",
1047
+ :packets => "unknown",
1048
+ :bytes => "unknown"}
1049
+ }
1050
+
1051
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
1052
+
1053
+ output_params = {:code => 405, :result => "ERROR. MAC address not found on IWAG."}
1054
+
1055
+ #render :soap => mess
1056
+
1057
+ end
1058
+ rescue
1059
+ puts 'SOAP mts_wifi_get_subs_info_return errorMethod'
1060
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
1061
+ end
1062
+
1063
+ output_params
1064
+
1065
+ ####
1066
+
1067
+ end
1068
+
1069
+
629
1070
  end
630
1071
 
File without changes
File without changes
File without changes