lib/freewifi.rb in freewifi-0.1.4 vs lib/freewifi.rb in freewifi-0.1.5
- old
+ new
@@ -3,48 +3,67 @@
$LOAD_PATH.unshift File.expand_path("../database/mysql", __dir__)
$LOAD_PATH.unshift File.expand_path("../database/mongo", __dir__)
$LOAD_PATH.unshift File.expand_path("../additional", __dir__)
require "freewifi/version"
-require 'freewifi/mikrotik/hewhub_mtik_ssh'
+require "freewifi/params"
+require "freewifi/config"
+require 'freewifi/mikrotik/newhub_mtik_ssh'
+require 'freewifi/mikrotik/schemes_conf_gen'
require 'freewifi/database/mysql/database_methods_wifi'
require 'freewifi/database/mongo/mongoconnector'
require 'date'
+require 'json'
#eoip tunnel ids generates between 10001 - 65535
+#frewifi SDK with SDK id = 1
-
-module Freewifi
+module Freewifi_1
attr_accessor :mtik_hub1_ip,
:mtik_hub2_ip,
:user_hub,
:password_hub,
:cps_class,
:db_mysql,
- :additional_func_wifi,
- :ssh_mikrotik_connector,
- :mongo_connector_wifi,
+ :additional_func_wifi_1,
+ :ssh_mikrotik_connector_1,
+ :mongo_connector_wifi_1,
:remote_ip,
:real_ip,
- :subscriber_ip
+ :subscriber_ip,
+ :capsman_ip_man,
+ :capsman_user,
+ :capsman_password,
+ :mtik_config_gen_1,
+ :hub_vip,
+ :ap_admin_password,
+ :capsman_ip_wifi
- 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)
+
+ 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, capsman_ip, capsman_user, capsman_password, hub_vip, ap_admin_password, capsman_ip_wifi)
@mtik_hub1_ip = hub1ip
@mtik_hub2_ip = hub2ip
@user_hub = username_hub
@password_hub = password_hub
- @db_mysql = DatabaseMethodsWifi.new(database_username, database_password, database_host)
- @additional_func_wifi = InternalFunc.new
- @ssh_mikrotik_connector = NEWhubWifi.new
- @mongo_connector_wifi = MongoWifiCl.new(mongo_ip, mongo_port, mongo_database)
+ @db_mysql = DatabaseMethodsWifi_1.new(database_username, database_password, database_host)
+ @additional_func_wifi_1 = InternalFunc_1.new
+ @ssh_mikrotik_connector_1 = NEWhubWifi_1.new
+ @mongo_connector_wifi_1 = MongoWifiCl_1.new(mongo_ip, mongo_port, mongo_database)
@remote_ip = remote_ip
@real_ip = real_ip
@subscriber_ip = subscriber_ip
+ @capsman_ip = capsman_ip
+ @capsman_user = capsman_user
+ @capsman_password = capsman_password
+ @mtik_config_gen_1 = MtikSchemesGen_1.new
+ @hub_vip = hub_vip
+ @ap_admin_password = ap_admin_password
+ @capsman_ip_wifi = capsman_ip_wifi
end
- 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)
+ def add_mikrotik_ap_mobile_1(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)
input_params = {:sim_ipaddress => sim_ipaddress,
:sim_msisdn => sim_msisdn,
:bridge_name_hub => bridge_name_hub,
:company_name => company_name,
@@ -60,22 +79,22 @@
}
output_params = {}
begin
- processed_comp_name = additional_func_wifi.company_check_wifi(company_name)
+ processed_comp_name = additional_func_wifi_1.company_check_wifi_1(company_name)
#p ap_state = db_mysql.check_mikrotik_ap_exists(sim_ipaddress, sim_msisdn).to_s
- ap_state = mongo_connector_wifi.get_ap_info_sim_ip_wifi(sim_ipaddress, sim_msisdn).to_s
+ ap_state = mongo_connector_wifi_1.get_ap_info_sim_ip_wifi_1(sim_ipaddress, sim_msisdn)[:body]
- if ap_state == "" || ap_state == nil || ap_state == "[]" || ap_state == "fttx"
- tunnel_addition = ssh_mikrotik_connector.add_eoip_for_mikr_wifi(bridge_name_hub,
- sim_ipaddress,
- processed_comp_name,
- mtik_hub1_ip,
- mtik_hub2_ip,
- user_hub,
- password_hub)
+ if ap_state[:all_mongo].to_s == "" || ap_state[:all_mongo].to_s == nil || ap_state[:all_mongo].to_s == "[]" || ap_state[:all_mongo].to_s == "fttx"
+ tunnel_addition = ssh_mikrotik_connector_1.add_eoip_for_mikr_wifi_1(bridge_name_hub,
+ sim_ipaddress,
+ processed_comp_name,
+ mtik_hub1_ip,
+ mtik_hub2_ip,
+ user_hub,
+ password_hub)
if tunnel_addition[:code] == 200
data = {:sim_ipaddress => sim_ipaddress,
@@ -95,58 +114,115 @@
:tunnel_id => tunnel_addition[:body][:eoip_tunnel_id],
:tunnel_name => tunnel_addition[:body][:eoip_tunnel_name],
:created_date => DateTime.now
}
- mongo_response = mongo_connector_wifi.data_ap_auto_created_insert(data)
+ mongo_response = mongo_connector_wifi_1.data_ap_auto_created_insert_1(data)
if mongo_response[:code]==200
+ newcapsman1 = NEWhubWifi_1.new
+
+ threads = []
+ capsman_ip.each do |capsman|
+ threads << Thread.new do
+ newcapsman1.set_capsman_config_1(additional_func_wifi_1.prep_ssid_for_config_1(wifi_ssid), capsman, capsman_user, capsman_password, sim_ipaddress, additional_func_wifi_1.prep_comp_name_for_config_1(company_name))
+ end
+ end
+ threads.each(&:join)
+
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]}}
else
output_params = {:code => 400, :result => "Something wrong with insertion to mongo"}
end
else
output_params = {:code => 401, :result => tunnel_addition[:result]}
end
else
- output_params = {:code => 202, :result => "AP exists"}
+ output_params = {:code => 202, :result => "AP exists", :body => {:tunnel_id => ap_state[:tunnel_id].to_s}}
end
rescue
output_params = {:code => 507, :result => "Unknown SDK error"}
end
- mongo_connector_wifi.audit_logger_wifi("add_mikrotik_ap_mobile", remote_ip, input_params, output_params, real_ip, subscriber_ip)
+ mongo_connector_wifi_1.audit_logger_wifi_1("add_mikrotik_ap_mobile", remote_ip, input_params, output_params, real_ip, subscriber_ip)
#additional_func.printer_texter({:input_params => input_params, :output_params => output_params, :procedure => "add_mikrotik_ap_mobile", :file => "freewifi.rb"}, "info")
output_params
end
+ def mtik_sch1_config_gen_1(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)
+ input_params = {:sim_ipaddress => sim_ipaddress,
+ :sim_msisdn => sim_msisdn,
+ :bridge_name_hub => bridge_name_hub,
+ :company_name => company_name,
+ :subscribers_address => subscribers_address,
+ :subscribers_region => subscribers_region,
+ :subscribers_contacts => subscribers_contacts,
+ :wifi_ssid => wifi_ssid,
+ :portalstyle => portalstyle,
+ :ap_serial_number => ap_serial_number,
+ :ap_model => ap_model,
+ :description => description,
+ :note => note
+ }
+ output_params = {}
+
+ begin
+
+ res = self.add_mikrotik_ap_mobile_1(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)
+ tun_id = res[:body][:tunnel_id]
+ hostname = additional_func_wifi_1.ap_hostname_generator(company_name, tun_id)
+ conf_1 = mtik_config_gen_1.scheme1_3g_config_gen_1(hostname, tun_id, hub_vip, ap_admin_password, wifi_ssid, capsman_ip_wifi)
+ output_params = {:code => 200, :result => "Request completed successfully", :body => {:ap_configuration => conf_1}}
+
+ rescue
+ output_params = {:code => 507, :result => "Unknown SDK error"}
+ end
+ mongo_connector_wifi_1.audit_logger_wifi_1("mtik_sch1_config_gen_1", remote_ip, input_params, conf_1, real_ip, subscriber_ip)
+ output_params
+ end
+
+
def add_eoip_for_mikr_hub(bridge_name, ap_ip_address, tunnel_name)
- newhub = NEWhubWifi.new
- newhub.add_eoip_for_mikr_wifi(bridge_name,
- ap_ip_address,
- tunnel_name,
- mtik_hub1_ip,
- mtik_hub2_ip,
- user_hub,
- password_hub)
+ newhub_1 = NEWhubWifi_1.new
+ newhub_1.add_eoip_for_mikr_wifi_1(bridge_name,
+ ap_ip_address,
+ tunnel_name,
+ mtik_hub1_ip,
+ mtik_hub2_ip,
+ user_hub,
+ password_hub)
end
- def del_one_eoip_from_mikr_hub(tunnel_id)
- newhub1 = NEWhubWifi.new
- newhub1.del_eoip_for_mikr(tunnel_id, mtik_hub1_ip, mtik_hub2_ip, user_hub, password_hub)
+ def del_one_eoip_from_mikr_hub_1(tunnel_id)
+ newhub1 = NEWhubWifi_1.new
+ newhub1.del_eoip_for_mikr_1(tunnel_id, mtik_hub1_ip, mtik_hub2_ip, user_hub, password_hub)
p tid = tunnel_id.to_i
- mongo_connector_wifi.tunnelid_remove_single_mongo(tid)
+ mongo_connector_wifi_1.tunnelid_remove_single_mongo_1(tid)
end
+ def cellular_mtik_ap_conf_gen_1(scheme_number)
+
+ end
+
def test()
- #newhub1 = NEWhub.new
- #newhub1.hub_get_all_eoip_tunnels("172.24.223.132", "soapgw", "fr8Hn3Ed2k0Im4gWmav2Nh7Y1qAm8KlmRh3Dcu2Wcok5gBdm")
- mongo_connector_wifi.data_ap_auto_created_insert(:test => "test")
+ newcapsman1 = NEWhubWifi_1.new
+
+ threads = []
+ capsman_ip.each do |capsman|
+ threads << Thread.new do
+ newcapsman1.set_capsman_config_1("test_ss", capsman, capsman_user, capsman_password, "172.25.208.14", "test_company")
+ end
+ end
+ threads.each(&:join)
+
+ #newhub1.hub_get_all_eoip_tunnels_1("172.24.223.132", "soapgw", "fr8Hn3Ed2k0Im4gWmav2Nh7Y1qAm8KlmRh3Dcu2Wcok5gBdm")
+ #mongo_connector_wifi_1.data_ap_auto_created_insert_1(:test => "test")
end
+
end
-class Fwifi
- include Freewifi
+class Fwifi_1
+ include Freewifi_1
end
#tested on 6.46.2 router os