lib/freewifi/mikrotik/newhub_mtik_api.rb in freewifi-0.2.9 vs lib/freewifi/mikrotik/newhub_mtik_api.rb in freewifi-0.2.10

- old
+ new

@@ -1,6 +1,7 @@ require 'mtik' +require 'net/ssh' class NEWhubWifiApi_1 attr_accessor :mtik_control_ips_get, :mtik_user, :mtik_password @@ -9,89 +10,185 @@ @mtik_user = mtik_user @mtik_password = mtik_password end -def get_info_subs_from_mik_1(subs_mac, controllers_ip) - input_parameters = {:subs_mac => subs_mac, :controllers_ip => controllers_ip} - #region get additional information + def get_info_subs_from_mik_1(subs_mac, controllers_ip) + input_parameters = {:subs_mac => subs_mac, :controllers_ip => controllers_ip} + #region get additional information - subscribers_mac = subs_mac - access_point ="" - ssid_ap ="" - tx_rate_set = "" - tx_rate = "" - rx_rate = "" - rx_signal = "" - uptime = "" - packets = "" - bytes = "" + subscribers_mac = subs_mac + access_point ="" + ssid_ap ="" + tx_rate_set = "" + tx_rate = "" + rx_rate = "" + rx_signal = "" + uptime = "" + packets = "" + bytes = "" - MTik::verbose = false - mikrot_connection1 = MTik::Connection.new :host => controllers_ip, :user => mtik_user, :pass => mtik_password, :conn_timeout => 7, :cmd_timeout => 7 - mikrot_connection1.get_reply('/caps-man/registration-table/getall') do |req, sentence| + MTik::verbose = false + mikrot_connection1 = MTik::Connection.new :host => controllers_ip, :user => mtik_user, :pass => mtik_password, :conn_timeout => 7, :cmd_timeout => 7 + mikrot_connection1.get_reply('/caps-man/registration-table/getall') do |req, sentence| - req.reply.each do |reply| - if reply.key?('mac-address') - #p reply - if reply['mac-address'] == subscribers_mac + req.reply.each do |reply| + if reply.key?('mac-address') + #p reply + if reply['mac-address'] == subscribers_mac - access_point = reply['interface'] - ssid_ap = reply['ssid'] - tx_rate = reply['tx-rate'] - rx_rate = reply['rx-rate'] - rx_signal = reply['rx-signal'] - uptime = reply['uptime'] - packets = reply['packets'] - bytes = reply['bytes'] - tx_rate_set = reply['tx-rate-set'] + access_point = reply['interface'] + ssid_ap = reply['ssid'] + tx_rate = reply['tx-rate'] + rx_rate = reply['rx-rate'] + rx_signal = reply['rx-signal'] + uptime = reply['uptime'] + packets = reply['packets'] + bytes = reply['bytes'] + tx_rate_set = reply['tx-rate-set'] + end end end end - end - if access_point=="" || ssid_ap=="" || packets=="" - access_point = "not on mikrotik controller" - ssid_ap = "unknown" - tx_rate_set = "unknown" - tx_rate = "0" - rx_rate = "0" - rx_signal = "0" - uptime = "0" - packets = "0" - bytes = "0" - end + if access_point=="" || ssid_ap=="" || packets=="" + access_point = "not on mikrotik controller" + ssid_ap = "unknown" + tx_rate_set = "unknown" + tx_rate = "0" + rx_rate = "0" + rx_signal = "0" + uptime = "0" + packets = "0" + bytes = "0" + end - if access_point==nil - access_point= "unknown" + if access_point==nil + access_point= "unknown" + end + if ssid_ap==nil + ssid_ap= "unknown" + end + if tx_rate_set==nil + tx_rate_set= "unknown" + end + if tx_rate==nil + tx_rate= "unknown" + end + if rx_rate==nil + rx_rate= "unknown" + end + if rx_signal==nil + rx_signal= "unknown" + end + if uptime==nil + uptime= "unknown" + end + if packets==nil + packets= "unknown" + end + if bytes==nil + bytes= "unknown" + end + + #endregion + subscribers_mac+ "---" + access_point + "---" + ssid_ap + "---" + tx_rate_set + "---"+ tx_rate + "---"+ rx_rate + "---"+ rx_signal + "---"+ uptime + "---"+ packets + "---"+ bytes + end - if ssid_ap==nil - ssid_ap= "unknown" - end - if tx_rate_set==nil - tx_rate_set= "unknown" - end - if tx_rate==nil - tx_rate= "unknown" - end - if rx_rate==nil - rx_rate= "unknown" - end - if rx_signal==nil - rx_signal= "unknown" - end - if uptime==nil - uptime= "unknown" - end - if packets==nil - packets= "unknown" - end - if bytes==nil - bytes= "unknown" - end - #endregion - subscribers_mac+ "---" + access_point + "---" + ssid_ap + "---" + tx_rate_set + "---"+ tx_rate + "---"+ rx_rate + "---"+ rx_signal + "---"+ uptime + "---"+ packets + "---"+ bytes -end + def get_info_subs_from_mik_ssh(subs_mac, controllers_ip) + input_parameters = {:subs_mac => subs_mac, :controllers_ip => controllers_ip} + #region get additional information + + + subscribers_mac = subs_mac + access_point ="" + ssid_ap ="" + tx_rate_set = "" + tx_rate = "" + rx_rate = "" + rx_signal = "" + uptime = "" + packets = "" + bytes = "" + + begin + Net::SSH.start(controllers_ip, mtik_user, :password => mtik_password) do |ssh| + #result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}") + #p result + result = ssh.exec!("/caps-man registration-table print detail value-list where mac-address=#{subs_mac}") + p result + access_point_reg = /interface:\s(.+)\r\n/ + access_point = result.scan(access_point_reg)[0][0] + ssid_reg = /ssid:\s(.+)\r\n/ + ssid_ap = result.scan(ssid_reg)[0][0] + + tx_rate_set = "unknown" + tx_rate = "0" + rx_rate = "0" + rx_signal = "0" + uptime = "0" + packets = "0" + bytes = "0" + + p access_point + p ssid_ap + #regimsi = /\s+name="(.+)"\s+/ + #m1 = regimsi.match(result)[1] + + #result2 = ssh.exec!("interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name}") + end + #Net::SSH.stop + rescue + nil + end + + p "1111111111111111111" + + if access_point=="" || ssid_ap=="" || packets=="" + access_point = "not on mikrotik controller" + ssid_ap = "unknown" + tx_rate_set = "unknown" + tx_rate = "0" + rx_rate = "0" + rx_signal = "0" + uptime = "0" + packets = "0" + bytes = "0" + end + + if access_point==nil || access_point=='' + access_point= "unknown" + end + if ssid_ap==nil || ssid_ap=='' + ssid_ap= "unknown" + end + if tx_rate_set==nil || tx_rate_set=='' + tx_rate_set= "unknown" + end + if tx_rate==nil || tx_rate=='' + tx_rate= "unknown" + end + if rx_rate==nil || rx_rate=='' + rx_rate= "unknown" + end + if rx_signal==nil || rx_signal=='' + rx_signal= "unknown" + end + if uptime==nil || uptime=='' + uptime= "unknown" + end + if packets==nil || packets=='' + packets= "unknown" + end + if bytes==nil || bytes=='' + bytes= "unknown" + end + + #endregion + subscribers_mac+ "---" + access_point + "---" + ssid_ap + "---" + tx_rate_set + "---"+ tx_rate + "---"+ rx_rate + "---"+ rx_signal + "---"+ uptime + "---"+ packets + "---"+ bytes + + end + end