$LOAD_PATH.unshift File.expand_path("../projects/iot", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/wttx", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/mhub", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/mhub/subs/dabrab", __dir__) $LOAD_PATH.unshift File.expand_path("../platforms/cps", __dir__) $LOAD_PATH.unshift File.expand_path("../platforms/public", __dir__) $LOAD_PATH.unshift File.expand_path("../projects", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/dns", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/autovpn", __dir__) require "imperituroard/version" require "imperituroard/settings" require "imperituroard/projects/wttx/phpipamdb" require "imperituroard/projects/wttx/phpipamcps" require "imperituroard/projects/iot/mongoconnector" require "imperituroard/projects/iot/hua_oceanconnect_adapter" require "imperituroard/projects/iot/add_functions" require "imperituroard/projects/iot/internal_functions" require 'imperituroard/projects/mhub/infobip' require 'imperituroard/projects/mhub/sk' require 'imperituroard/projects/mhub/subs/dabrab/dabrab_proced' require 'imperituroard/projects/mhub/subs/dabrab/dabrab_platform' require 'imperituroard/projects/mhub' require 'imperituroard/projects/iot' require 'imperituroard/projects/dns' require 'imperituroard/platforms/cps/qps_connector' require 'imperituroard/platforms/public/telegram' require 'imperituroard/projects/ukaz60' require 'imperituroard/projects/mhub/gms' require 'imperituroard/projects/autovpn/mongo_vpn' require 'imperituroard/projects/autovpn' require 'json' require 'ipaddr' require 'date' require 'net/http' require 'uri' module Imperituroard class Error < StandardError; end def initialize end def hhh(jjj) p jjj end # Your code goes here... end module PhpipamModule def test(ggg) p ggg end end class MyJSON def self.valid?(value) result = JSON.parse(value) result.is_a?(Hash) || result.is_a?(Array) rescue JSON::ParserError, TypeError false end end class Pipam attr_accessor :username, :password, :ip, :database_class, :cps_class def initialize(db_username, db_password, db_ip, cps_wsdl, cps_endpoint, cps_namespace) @username = db_username @password = db_password @ip = db_ip @database_class = Pdb.new("phpipam", db_username, db_password, db_ip, "3306") @cps_class = Pcps.new(cps_wsdl, cps_endpoint, cps_namespace) end def update_phpipam_rewr_msisdn(old_msisdn, new_msisdn) dst_num_exists = database_class.check_if_msisdn_exists(new_msisdn, "ipaddresses") if dst_num_exists == 0 database_class.update_database_rewrite_msisdn(old_msisdn, new_msisdn) "updated" else "failed" end end def final_change_msisdn(old_msisdn, new_msisdn) dst_num_exists = database_class.check_if_msisdn_exists(new_msisdn, "ipaddresses") if dst_num_exists == 0 response_from_db = database_class.update_database_rewrite_msisdn(old_msisdn, new_msisdn) if response_from_db=="success" response_from_cps = cps_class.change_attr_cps(old_msisdn, new_msisdn) if response_from_cps == "ok" "updated" else "cps failed" end else "db failed" end else "failed" end end include PhpipamModule end class Iot attr_accessor :param_all, :mongo_client, :add_functions_connector, #:real_ip, #real ip address of procedure caller #:remote_ip, #ip address of balancer :hua_aceanconnect_connector, :internal_func, :iot_connector def initialize(mongoip, mongoport, iotip, mongo_database, iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id #real_ip, #remote_ip ) @param_all = {:mongoip => mongoip, :mongoport => mongoport, :iotip => iotip, :mongo_database => mongo_database, :iotplatform_ip => iotplatform_ip, :cert_path => cert_path, :key_path => key_path } @mongo_client = MongoIot.new(param_all[:mongoip], param_all[:mongoport], param_all[:mongo_database]) @add_functions_connector = AdditionalFunc.new(telegram_api_url, telegram_chat_id) #@real_ip = real_ip #@remote_ip = remote_ip @hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path, param_all[:mongoip], param_all[:mongoport], param_all[:mongo_database]) @internal_func = InternalFunc.new @iot_connector = IotFunctions_2.new(param_all[:mongoip], param_all[:mongoport], iotip, param_all[:mongo_database], iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id) end #error list #:code => 507, :result => "Unknown SDK error" #{:code => 200, :result => "Request completed successfully", :body => result_ps} #!!1. Add device to profile (only for new device) #login - login for client identification #profile - profile for device #imei_list - device identificator #imei_list = [{"imei" => 131234123412341233, "description" => "dfdsf", "note"=>"second description", "profile"=>0, "device_type"=>"phone"}, #{"imei" => 56213126347645784, "description" => "dfdsf", "note"=>"second description", "profile"=>0}] #massive commands #+++ #iot logic added def add_device_to_profile(login, imei_list, real_ip, remote_ip) iot_connector.add_device_to_prof_2(login, imei_list, real_ip, remote_ip) end def add_device_to_profile2(request_f, real_ip, remote_ip) iot_connector.add_device_to_prof2_2(request_f, real_ip, remote_ip) end #!!2 Find device (only mongo datebase. IOT platform not need) # procedure for data selection from mongo database. # for this function IOT platform not need # login # imei # imei_list =[41234,23452345,132412] #++ def device_find(login, imei_list, real_ip, remote_ip) iot_connector.device_find_2(login, imei_list, real_ip, remote_ip) end #!3 device modify, change imei #login #imei_old #imei_new #massive commands #im_list = [{"imei_old"=>7967843245667, "imei_new"=>7967843245665}] #++ def imei_replace(login, im_list, real_ip, remote_ip) iot_connector.imei_replace_2(login, im_list, real_ip, remote_ip) end #!!4 remove device #login #imei # not massive commands #imei=11341341234 #login="test" #+++ #IOT logic added def device_remove(login, imei, real_ip, remote_ip) iot_connector.device_remove_2(login, imei, real_ip, remote_ip) end #!5 add address to device #login #imei = newdevice_list #address = newdevice_list #newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}] #+++ #iot platform integration completed def device_add_address(login, newdevice_list, real_ip, remote_ip) iot_connector.device_add_address_2(login, newdevice_list, real_ip, remote_ip) end #6 add service by SPA #imei #profile #imsi #msisdn #newdevice_list=[{:imei=>7967843245665, :attributes=>{:address=>"Golubeva51", :profile=>"wqeqcqeqwev", :msisdn=>375298766719, :imsi=>25702858586756875}}] #+ def add_service(login, device_list, real_ip, remote_ip) iot_connector.add_service_2(login, device_list, real_ip, remote_ip) end #7 procedure for subscriber autorization def autorize_subscriber(login, password, real_ip, remote_ip) iot_connector.autorize_subscriber_2(login, password, real_ip, remote_ip) end #8 get available profiles for login def get_available_profiles(login, real_ip, remote_ip) iot_connector.get_available_prof_2(login, real_ip, remote_ip) end #9 get available types for login def get_available_types(login, real_ip, remote_ip) iot_connector.get_available_types_2(login, real_ip, remote_ip) end #9-1 get available types for login and profile def get_available_types2(login, profile, real_ip, remote_ip) iot_connector.get_available_types2_2(login, profile, real_ip, remote_ip) end #10 get info for device type def get_info_data_type(type, real_ip, remote_ip) iot_connector.get_info_data_type_2(type, real_ip, remote_ip) end #11 get info for profile def get_info_data_profile(profile, real_ip, remote_ip) iot_connector.get_info_data_profile_2(profile, real_ip, remote_ip) end #13 replace data for imei. Replace Type and Profile #new procedure 2020-06-06 #params = # {"autorization"=>{"login"=>"test", "token"=>"token"}, "datalist"=>[{"imei"=>"524523654366", "new_profile"=>"3", "new_type"=>"1000001"}, {"imei"=>"53623413423", "new_profile"=>"1", "new_type"=>"1000003"}]} # answer = {:code=>200, :result=>"Success", :body=>{:processednum=>1, :failednum=>1, :deviceserr=>[{:failedimei=>524523654366}]}} def set_data_replace(soapgw_params, real_ip, remote_ip) iot_connector.set_data_replace_2(soapgw_params, real_ip, remote_ip) end #15 integration with SPA # add imei to correct profile def sdk_spa_service_set(soapgw_params, real_ip, remote_ip) #imei #imsi #msisdn #unp #note #descriptiot iot_connector.spa_service_set_2(soapgw_params, real_ip, remote_ip) end def logger_to_audit_database(proc_name, src_ip, input_json, output_json, real_ip) mongo_client.audit_logger(proc_name, src_ip, input_json, output_json, real_ip) end #################################################################### #######technological procedures #################################################################### def delete_all_iot_device_in_db iot_connector.delete_all_devices_in_database end def test111 iot_connector.test1278493 end end class Mhub_2 attr_accessor :sk_url, :sk_login, :sk_password, :mhub_connector, :internal_func, :dabrab_connecter, :static_callback, :crm_connector, :log_level def initialize(sk_url_simple, sk_login, sk_password, telegram_api_url, telegram_chat_id, sk_url_broadcast, static_callback, crm_callback_url, crm_login, crm_password, sms_alphaname, log_level="error") @sk_url = sk_url_simple @sk_login = sk_login @sk_password = sk_password @log_level = log_level @internal_func = InternalFunc.new @mhub_connector = Sksk_2.new(sk_url_simple, sk_login, sk_password, sk_url_broadcast, telegram_api_url, telegram_chat_id, log_level) @internal_func = InternalFunc.new @dabrab_connecter = Dabrab.new(log_level) @static_callback = static_callback @crm_connector = Crm_2.new(crm_callback_url, crm_login, crm_password, telegram_api_url, telegram_chat_id, log_level) @mhub_connector = MhubFunctions_2.new(sk_url_simple, sk_login, sk_password, telegram_api_url, telegram_chat_id, sk_url_broadcast, static_callback, crm_callback_url, crm_login, crm_password, sms_alphaname, log_level) end #{"destinations"=>[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}], # "scenarioKey"=>"1", "viber"=>nil, "sms"=>{"text"=>"карточка готова"}, # "sendAt"=>"2019-08-15T08:40:00.000", "notifyUrl"=>"https://bpmonline.bankdabrabyt.by:444/0/ServiceModel/ScGetReports.svc/GetReports", # "notifyContentType"=>"application/json", "controller"=>"bank", "action"=>"api", # "bank"=>{"destinations"=>[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}], "scenarioKey"=>"1", # "viber"=>nil, "sms"=>{"text"=>"карточка готова"}, "sendAt"=>"2019-08-15T08:40:00.000", # "notifyUrl"=>"https://bpmonline.bankdabrabyt.by:444/0/ServiceModel/ScGetReports.svc/GetReports", # "notifyContentType"=>"application/json"}} def get_send_message(params, ip_src, ip_real, ip_vip) mhub_connector.get_send_message_2(params, ip_src, ip_real, ip_vip) end def get_send_message_mass(params, ip_src, ip_real, ip_vip, slice_number=100, time_pause_minutes=5, viberttl=60, params_manual_set=0, smsttl=60) mhub_connector.get_send_message_mass_2(params, ip_src, ip_real, ip_vip, slice_number, time_pause_minutes, viberttl, params_manual_set, smsttl) end def recieve_delivery_report(params, ip_src, ip_real, ip_vip, crm_slice_num) mhub_connector.rec_deliv_report_2(params, ip_src, ip_real, ip_vip, crm_slice_num) end end #2020.09.02 function for some procedure for get message status class GmsFunctions_2 attr_accessor :gms_func def initialize(gms_t_login, gms_t_password, gms_r_login, gms_r_password, telegram_api_url, telegram_chat_id) @gms_func = Gmsgms_2.new(gms_t_login, gms_t_password, gms_r_login, gms_r_password, telegram_api_url, telegram_chat_id) end def get_t_status_external(external_id) gms_func.get_t_status_external_2(external_id) end def get_r_status_external(external_id) gms_func.get_r_status_external_2(external_id) end end class CpsFunctions_2 attr_accessor :qps_connector def initialize(cps_wsdl, cps_endpoint, cps_namespace) @qps_connector = Qps_2.new(cps_wsdl, cps_endpoint, cps_namespace) end def recreate_cps_profile(msisdn) p gettt = qps_connector.get_subscriber_msisdn(msisdn) p qps_connector.delete_subscriber(msisdn) p qps_connector.recreate_subscriber(gettt) end def get_subscriber_profile(msisdn) qps_connector.get_subscriber_msisdn(msisdn) end end class Ukaz60Automation_2 attr_accessor :dns, :ukaz60_func def initialize(telegram_api_url, telegram_chat_id, work_directory, filename_blocked, filename_tmp_blocked, ip_for_redirect, add_bl_memory_script, del_bl_memory_script, dns_login, dns_password, belgim_login, belgim_password, belgim_url, ###########for fortigate############ ansible_tmp_folder, #folder on fortigate ansible server where url list uploaded local_tmp_directory, #folder on local mashin where script work ansible_ssh_user, ansible_ssh_password, ansible_host, #fortigate ansible server url_backup_dir, #################################### #########for STAROS############# staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts ) =begin @ukaz69_dns_func = Dns_2.new(telegram_api_url, telegram_chat_id, work_directory, filename_blocked, filename_tmp_blocked, ip_for_redirect, add_bl_memory_script, del_bl_memory_script, dns_login, dns_password, belgim_login, belgim_password, belgim_url) =end @ukaz60_func = Ukaz60All_2.new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url, ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir, staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts) end #1 block all devices by belgim list def no_pasaran ukaz60_func.no_pasaran end end class Autovpn attr_accessor :vpn_connector, :mongo_connector def initialize @mongo_connector = MongoVpn.new @vpn_connector = AutovpnClass.new end def vpn_add_msisdn_by_example(new_msisdn, example_msisdn) vpn_connector.vpn_add_msisdn_by_example_2(new_msisdn, example_msisdn) end def vpn_test vpn_connector.get_attr_by_example_msisdn("375297776403") end end