#$LOAD_PATH.unshift File.expand_path("../freewifi", __dir__) $LOAD_PATH.unshift File.expand_path("../mikrotik", __dir__) $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__) $LOAD_PATH.unshift File.expand_path("../general", __dir__) $LOAD_PATH.unshift File.expand_path("../huawei", __dir__) require "freewifi/version" 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 'freewifi/general/wifi_portal_procedures' require 'date' require 'json' #eoip tunnel ids generates between 10001 - 65535 #frewifi SDK with SDK id = 1 module Freewifi_1 attr_accessor :mtik_hub1_ip, :mtik_hub2_ip, :user_hub, :password_hub, :cps_class, :db_mysql, :additional_func_wifi_1, :ssh_mikrotik_connector_1, :mongo_connector_wifi_1, :remote_ip, :real_ip, :subscriber_ip, :capsman_ip_man, :capsman_user, :capsman_password, :mtik_config_gen_1, :hub_vip, :ap_admin_password, :capsman_ip_wifi, :apigw_wsdl, :apigw_endpoint, :apigw_namespace, :apigw_wsse_aut_log, :apigw_wsse_aut_pass, :general_procedures 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_man, 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_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_man = capsman_ip_man @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 #1 procedure for creation mikrotik AP 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, :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 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_1.get_ap_info_sim_ip_wifi_1(sim_ipaddress, sim_msisdn)[:body] 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, :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 => "MikroTik", :ap_serial_number => ap_serial_number, :ap_model => ap_model, :description => description, :note => note, :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_1.data_ap_auto_created_insert_1(data) if mongo_response[:code]==200 newcapsman1 = NEWhubWifi_1.new threads_1 = [] capsman_ip_man.each do |capsman| threads_1 << Thread.new do wifi_ssid_processed = additional_func_wifi_1.prep_ssid_for_config_1(wifi_ssid) company_name_processed = additional_func_wifi_1.prep_comp_name_for_config_1(company_name) input_intern_data = {:wifi_ssid_processed => wifi_ssid_processed, :company_name_processed => company_name_processed, :capsman => capsman} mongo_connector_wifi_1.audit_logger_wifi_1("add_mikrotik_ap_mobile_1", remote_ip, input_intern_data, nil, real_ip, subscriber_ip) newcapsman1.set_capsman_config_1(wifi_ssid_processed, capsman, capsman_user, capsman_password, sim_ipaddress, company_name_processed) end end threads_1.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", :body => {:tunnel_id => ap_state[:tunnel_id].to_s}} end rescue output_params = {:code => 507, :result => "Unknown SDK error"} end mongo_connector_wifi_1.audit_logger_wifi_1("add_mikrotik_ap_mobile_1", 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 #2 procedure for generation configuration for mikrotik AP #scheme 1 MikroTik throw mobile network 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 => res[:code], :result => res[:result], :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_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_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_1.tunnelid_remove_single_mongo_1(tid) end def cellular_mtik_ap_conf_gen_1(scheme_number) end def 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_1 include Freewifi_1 end class PortalFwifi_1 attr_accessor :apigw_wsdl, :apigw_endpoint, :apigw_namespace, :apigw_wsse_aut_log, :apigw_wsse_aut_pass, :general_procedures, :mtik_control_ips_get, :mtik_user, :mtik_password, :mongo_connector_wifi_1, :remote_ip, :real_ip 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, mongo_ip, mongo_port, mongo_database, remote_ip, real_ip, hua_wlc_1_ip, hua_wlc_2_ip, hua_wlc_login, hua_wlc_password ) @apigw_wsdl = apigw_wsdl @apigw_endpoint = apigw_endpoint @apigw_namespace = apigw_namespace @apigw_wsse_aut_log = apigw_wsse_aut_log @apigw_wsse_aut_pass = apigw_wsse_aut_pass @general_procedures = WiFiPortal_1.new(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) @mtik_control_ips_get = mtik_control_ips_get @mtik_user = mtik_user @mtik_password = mtik_password @mongo_connector_wifi_1 = MongoWifiCl_1.new(mongo_ip, mongo_port, mongo_database) @remote_ip = remote_ip @real_ip = real_ip end def wifi_get_subs_info_return_1(ipaddress) input_params = {:ipaddress => ipaddress} output_params = {} begin resp_procedure = general_procedures.get_subs_info_return_1(ipaddress) output_params = resp_procedure rescue output_params = {:code => 507, :result => "Unknown SDK error"} end mongo_connector_wifi_1.audit_logger_wifi_portal_1("wifi_get_subs_info_return_1", remote_ip, input_params, output_params, real_ip) output_params end end #tested on 6.46.2 router os