$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__) require "imperituroard/version" require "imperituroard/phpipamdb" require "imperituroard/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/iot' require 'imperituroard/platforms/cps/qps_connector' 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 :mongoip, :mongoport, :iotip, :mongo_database, :iotplatform_ip, :iotplatform_port, :cert_path, :key_path, :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) @mongoip = mongoip @mongoport = mongoport @iotip = iotip @mongo_database = mongo_database @iotplatform_ip = iotplatform_ip @iotplatform_port = iotplatform_port @cert_path = cert_path @key_path = key_path @mongo_client = MongoIot.new(mongoip, mongoport, 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) @internal_func = InternalFunc.new @iot_connector = IotFunctions_2.new(mongoip, mongoport, iotip, mongo_database, iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id, real_ip, remote_ip) 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) iot_connector.add_device_to_prof_2(login, imei_list) 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) iot_connector.device_find_2(login, imei_list) 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) iot_connector.imei_replace_2(login, im_list) end #!!4 remove device #login #imei # not massive commands #imei=11341341234 #login="test" #+++ #IOT logic added def device_remove(login, imei) iot_connector.device_remove_2(login, imei) 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) iot_connector.device_add_address_2(login, newdevice_list) 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) iot_connector.add_service_2(login, device_list) end #7 procedure for subscriber autorization def autorize_subscriber(login, password) iot_connector.autorize_subscriber_2(login, password) end #8 get available profiles for login def get_available_profiles(login) iot_connector.get_available_prof_2(login) end #9 get available types for login def get_available_types(login) iot_connector.get_available_types_2(login) end #10 get info for device type def get_info_data_type(type) iot_connector.get_info_data_type_2(type) end #11 get info for profile def get_info_data_profile(profile) iot_connector.get_info_data_profile_2(profile) 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 #additional procedure for checking status on iot platform def get_info_by_imeilist_from_iot(login, imei_list) resp_out={} begin dev_id_list = [] resss = {} data_from_db = mongo_client.get_imei_info_from_db(imei_list) p data_from_db for g in data_from_db[:body] dev_id_list.append(g["huadata"]["body"]["deviceId"]) end credentials = mongo_client.get_iot_oceanconnect_credent(login) if credentials[:code]==200 p apid = credentials[:body][:app_id] p secre = credentials[:body][:secret] resp_out = hua_aceanconnect_connector.quer_dev_query_list(apid, secre, dev_id_list) end rescue resp_out = {:code => "500", :message => "get_info_by_imeilist_from_iot: Something wrong", :body => {"devices" => []}} end internal_func.printer_texter(resp_out, "debug") resp_out end #for internal use. Add new device model def add_model_to_mongo(model, manufacture_id, manufacture_name, device_type, description, note) model = { model: model, ManufacturerID: manufacture_id, ManufacturerNAME: manufacture_name, device_type: device_type, description: description, note: note, created: DateTime.now } mongo_client.imei_insert_model(model) end def test() #ddd = MongoIot.new(mongoip, mongoport, mongo_database) #ddd.get_profiles_by_login("test") ff = [131234123412341233, 131234123127341233] #ddd.get_imsi_info_from_db(ff) #p ddd.get_profile_id_by_name("1341241") #p ddd.get_device_type_info_by_model("BGT_PPMC11") #fff = HuaIot.new("134.17.93.4", "443", "/Users/imperituroard/Desktop/cert.crt", "/Users/imperituroard/Desktop/key.pem") p hua_aceanconnect_connector.querying_device_id("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "eWllZpHgXgvgDAQlJjWs4QXaR94a", "91234") end end class Mhub_2 attr_accessor :sk_url, :sk_login, :sk_password, :mhub_connector, :internal_func, :dabrab_connecter, :static_callback, :crm_connector 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) @sk_url = sk_url_simple @sk_login = sk_login @sk_password = sk_password @internal_func = InternalFunc.new @mhub_connector = Sksk_1.new(sk_url_simple, sk_login, sk_password, sk_url_broadcast) @internal_func = InternalFunc.new @dabrab_connecter = Dabrab.new @add_functions_connector = AdditionalFunc.new(telegram_api_url, telegram_chat_id) @static_callback = static_callback @crm_connector = Crm_1.new(crm_callback_url, crm_login, crm_password) 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) input_params = {:params => params} output_params = {} hub_resp = {} null_statement = [nil, "nil", "", "null"] begin # if params["destinations"].length == 1 # msisdn = params["destinations"][0]["to"]["phoneNumber"] # if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_sms_one(msisdn, params["notifyUrl"], params["sms"]["text"], "TEST") # elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_one(msisdn, params["notifyUrl"], params["viber"]["text"]) # elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_sms_one(msisdn, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") # else # output_params = {"code": 501, "result": "Invalid input data st1", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} # end # elsif params["destinations"].length > 1 # # msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2]) # # if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], "TEST") # elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_list(msisdn2, params["notifyUrl"], params["viber"]["text"]) # elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") # else # output_params = {"code": 502, "result": "Invalid input data st2", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} # end # else # output_params = {"code": 503, "result": "Invalid recipients", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} # end if params["destinations"].length >= 1 msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2]) if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) hub_resp = mhub_connector.sk_send_sms_list(msisdn2, static_callback, params["sms"]["text"], "TEST") elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) hub_resp = mhub_connector.sk_send_viber_list(msisdn2, static_callback, params["viber"]["text"]) elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) p "vibersms" p msisdn2 hub_resp = mhub_connector.sk_send_viber_sms_list(msisdn2, static_callback, params["sms"]["text"], params["viber"]["text"], "TEST") else output_params = {"code": 502, "result": "Invalid input data st2", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end else output_params = {"code": 503, "result": "Invalid recipients", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end mes_data = dabrab_connecter.send_responce_formatter(hub_resp) p hub_resp output_params = {"code": 200, "result": "Data processed", "body": {"answer": mes_data[:body][:mess_to_recip], "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} rescue output_params = {"code": 500, "result": "Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => hub_resp, :procedure => "Mhub_2.get_send_message"}, "debug") output_params end def recieve_delivery_report(params, ip_src, ip_real, ip_vip) input_params = {:params => params, :ip_src => ip_src, :ip_real => ip_real, :ip_vip => ip_vip} output_params = {} hub_resp = {} null_statement = [nil, "nil", "", "null"] begin mes_report = dabrab_connecter.delivery_report_transform(params)[:body][:report_to_recip] result = crm_connector.crm_status_1(mes_report) output_params = {"code": 200, "result": "Data processed", "body": {"answer": {"code": 200, "status": "Success"}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} rescue output_params = {"code": 500, "result": "Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => hub_resp, :procedure => "Mhub_2.recieve_delivery_report"}, "debug") output_params end def test2 hh = Infobip_1.new hh.test 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