コード例 #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetConfigResponse response = new GetConfigResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;
            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("ConfigCred", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ConfigCred = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ConfigFile", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ConfigFile = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ConfigType", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ConfigType = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return response;
        }
コード例 #2
0
        public IActionResult Index()
        {
            manager.Login();
            ManagerResponse          response  = manager.SendAction(new GetConfigAction("manager.conf"));
            List <GetConfigResponse> getConfig = new List <GetConfigResponse>();

            if (response.IsSuccess())
            {
                GetConfigResponse responseConfig = (GetConfigResponse)response;
                getConfig.Add(responseConfig);
                return(View(getConfig));
            }
            else
            {
                Console.WriteLine("");
                return(View());
            }

            //{
            //    Console.WriteLine("\nUpdateConfig action");
            //    UpdateConfigAction config = new UpdateConfigAction("manager.conf", "manager.conf");
            //    config.AddCommand(UpdateConfigAction.ACTION_NEWCAT, "testadmin");
            //    config.AddCommand(UpdateConfigAction.ACTION_APPEND, "testadmin", "secret", "blabla");
            //    ManagerResponse Newresponse = manager.SendAction(config);
            //    Console.WriteLine(Newresponse);
            //}
        }
コード例 #3
0
        public async Task GetConfigsTest()
        {
            OpenvasApi        api    = new OpenvasApi(Address);
            GetConfigResponse config = await api.GetConfig();

            //string j = JsonConvert.SerializeObject(config);
        }
コード例 #4
0
        private static void AssertGetConfigRequest(GetConfigResponse response)
        {
            Assert.IsTrue(response.Version > 0);

            // devices node
            Assert.IsNotNull(response.Devices);
            Assert.IsTrue(response.Devices.Count > 0);

            foreach (var device in response.Devices)
            {
                Assert.IsFalse(String.IsNullOrWhiteSpace(device.DeviceId));
            }

            // folders node
            Assert.IsNotNull(response.Folders);
            Assert.IsTrue(response.Folders.Count > 0);

            foreach (var folder in response.Folders)
            {
                Assert.IsFalse(String.IsNullOrWhiteSpace(folder.Id));
                Assert.IsFalse(String.IsNullOrWhiteSpace(folder.Path));

                foreach (var device in folder.Devices)
                {
                    Assert.IsFalse(String.IsNullOrWhiteSpace(device.DeviceId));
                }
            }

            Assert.IsNotNull(response.Gui);
            Assert.IsFalse(String.IsNullOrWhiteSpace(response.Gui.ApiKey));
            Assert.IsFalse(String.IsNullOrWhiteSpace(response.Gui.ListeningAddress));
        }
コード例 #5
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetConfigResponse response = new GetConfigResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("configArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ConfigArn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("configData", targetDepth))
                {
                    var unmarshaller = ConfigTypeDataUnmarshaller.Instance;
                    response.ConfigData = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("configId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ConfigId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("configType", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ConfigType = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("name", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Name = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("tags", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #6
0
        public static GetConfigResponse Unmarshall(UnmarshallerContext context)
        {
            GetConfigResponse getConfigResponse = new GetConfigResponse();

            getConfigResponse.HttpResponse   = context.HttpResponse;
            getConfigResponse.RequestId      = context.StringValue("GetConfig.RequestId");
            getConfigResponse.Success        = context.BooleanValue("GetConfig.Success");
            getConfigResponse.Code           = context.StringValue("GetConfig.Code");
            getConfigResponse.Message        = context.StringValue("GetConfig.Message");
            getConfigResponse.HttpStatusCode = context.IntegerValue("GetConfig.HttpStatusCode");

            GetConfigResponse.GetConfig_ConfigItem configItem = new GetConfigResponse.GetConfig_ConfigItem();
            configItem.Name              = context.StringValue("GetConfig.ConfigItem.Name");
            configItem._Value            = context.StringValue("GetConfig.ConfigItem.Value");
            getConfigResponse.ConfigItem = configItem;

            return(getConfigResponse);
        }
コード例 #7
0
        public GetConfigResponse Execute(GetConfigRequest request)
        {
            var response = new GetConfigResponse();

            var configSettings = new Models.ConfigSettings
            {
                AvailableColor = getAvailableColor(),
                BusyColor = getBusyColor(),
                CompanyLogoImage = getCompanyLogoImage(),
                PollingIntervalSeconds = getPollingIntervalSeconds(),
                AvailableRoomText = getAvailableRoomText(),
                BusyRoomText = getBusyRoomText(),
                AdminMenuPassword = getAdminMenuPassword()
            };
            response.ConfigSettings = configSettings;
            response.Success = true;

            return response;
        }
コード例 #8
0
        public IActionResult Create(string nameUser, string pass, string fullName)
        {
            ManagerResponse response = manager.SendAction(new GetConfigAction("sip.conf"));

            if (response.IsSuccess())
            {
                GetConfigResponse responseConfig = (GetConfigResponse)response;
                foreach (var user in responseConfig.Categories.Keys)
                {
                    if (nameUser == responseConfig.Categories[user])
                    {
                        return(RedirectToAction("Error"));
                    }
                }
            }
            UpdateConfigAction config = new UpdateConfigAction("sip.conf", "sip.conf");

            config.AddCommand(UpdateConfigAction.ACTION_NEWCAT, nameUser);
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "secret", pass);
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "context", "dial_out");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "type", "friend");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "host", "dynamic");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "callerid", fullName);
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "pickupgroup", "1");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "canreinvite", "yes");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "nat", "force_rport,comedia");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "directmedia", "nonat");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "languages", "en-us");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "qualifyfreq", "60");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "qualify", "500");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "insecure", "port,invite");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "dtmfmode", "auto");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "disallow", "all");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "allow", "alaw");
            config.AddCommand(UpdateConfigAction.ACTION_APPEND, nameUser, "allow", "gsm");
            config.Reload = "yes";
            ManagerResponse Newresponse = manager.SendAction(config);

            return(RedirectToAction("Index"));
        }
コード例 #9
0
        public IActionResult Index(int page = 1)
        {
            int                      pageSize      = 10;
            int                      count         = 0;
            ManagerResponse          response      = manager.SendAction(new GetConfigAction("sip.conf"));
            List <GetConfigResponse> getConfig     = new List <GetConfigResponse>();
            List <string>            getLines      = new List <string>();
            List <string>            getCategories = new List <string>();

            if (response.IsSuccess())
            {
                GetConfigResponse responseConfig = (GetConfigResponse)response;
                getConfig.Add(responseConfig);
                foreach (var conf in responseConfig.Categories.Keys)
                {
                    count += responseConfig.Categories[conf].Count();
                    getCategories.Add(responseConfig.Categories[conf]);
                    foreach (var keyLine in responseConfig.Lines(conf).Keys)
                    {
                        getLines.Add(responseConfig.Lines(conf)[keyLine]);
                    }
                }

                var            items         = getCategories.Skip((page - 1) * pageSize).Take(pageSize).ToList();
                PageViewModel  pageViewModel = new PageViewModel(count, page, pageSize);
                IndexViewModel viewModel     = new IndexViewModel
                {
                    PageViewModel      = pageViewModel,
                    GetConfigResponses = getConfig,
                    Categories         = getCategories,
                    Lines = getLines
                };
                return(View(viewModel));
            }
            else
            {
                Console.WriteLine("");
                return(View());
            }
        }
コード例 #10
0
        private static void checkManagerAPI()
        {
            manager = new ManagerConnection(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);

            // Register user event class
            manager.RegisterUserEventClass(typeof(UserAgentLoginEvent));

            // Add or Remove events
            manager.UserEvents += new UserEventHandler(dam_UserEvents);

            // Dont't display this event
            manager.NewExten += new NewExtenEventHandler(manager_IgnoreEvent);

            // Display all other
            manager.UnhandledEvent += new ManagerEventHandler(dam_Events);

            // +++ Only to debug purpose
            manager.FireAllEvents = true;
            // manager.DefaultEventTimeout = 0;
            // manager.DefaultResponseTimeout = 0;
            manager.PingInterval = 0;
            // +++
            try
            {
                manager.Login();                                        // Login only (fast)

                Console.WriteLine("Asterisk version : " + manager.Version);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
                manager.Logoff();
                return;
            }

            {
                Console.WriteLine("\nGetConfig action");
                ManagerResponse response = manager.SendAction(new GetConfigAction("manager.conf"));
                if (response.IsSuccess())
                {
                    GetConfigResponse responseConfig = (GetConfigResponse)response;
                    foreach (int key in responseConfig.Categories.Keys)
                    {
                        Console.WriteLine(string.Format("{0}:{1}", key, responseConfig.Categories[key]));
                        foreach (int keyLine in responseConfig.Lines(key).Keys)
                        {
                            Console.WriteLine(string.Format("\t{0}:{1}", keyLine, responseConfig.Lines(key)[keyLine]));
                        }
                    }
                }
                else
                {
                    Console.WriteLine(response);
                }
            }

            {
                Console.WriteLine("\nUpdateConfig action");
                UpdateConfigAction config = new UpdateConfigAction("manager.conf", "manager.conf");
                config.AddCommand(UpdateConfigAction.ACTION_NEWCAT, "testadmin");
                config.AddCommand(UpdateConfigAction.ACTION_APPEND, "testadmin", "secret", "blabla");
                ManagerResponse response = manager.SendAction(config);
                Console.WriteLine(response);
            }

            // Originate call example
            Console.WriteLine("\nPress ENTER key to originate call.\n"
                              + "Start phone (or connect) or make a call to see events.\n"
                              + "After all events press a key to originate call.");
            Console.ReadLine();

            OriginateAction oc = new OriginateAction();

            oc.Context  = ORIGINATE_CONTEXT;
            oc.Priority = "1";
            oc.Channel  = ORIGINATE_CHANNEL;
            oc.CallerId = ORIGINATE_CALLERID;
            oc.Exten    = ORIGINATE_EXTEN;
            oc.Timeout  = ORIGINATE_TIMEOUT;
            // oc.Variable = "VAR1=abc|VAR2=def";
            // oc.SetVariable("VAR3", "ghi");
            ManagerResponse originateResponse = manager.SendAction(oc, oc.Timeout);

            Console.WriteLine("Response:");
            Console.WriteLine(originateResponse);

            Console.WriteLine("Press ENTER key to next test.");
            Console.ReadLine();

            //
            // Display result of Show Queues command
            //
            {
                CommandAction   command  = new CommandAction();
                CommandResponse response = new CommandResponse();
                if (manager.AsteriskVersion == AsteriskVersion.ASTERISK_1_6)
                {
                    command.Command = "queue show";
                }
                else
                {
                    command.Command = "show queues";
                }
                try
                {
                    response = (CommandResponse)manager.SendAction(command);
                    Console.WriteLine("Result of " + command.Command);
                    foreach (string str in response.Result)
                    {
                        Console.WriteLine("\t" + str);
                    }
                }
                catch (Exception err)
                {
                    Console.WriteLine("Response error: " + err);
                }
                Console.WriteLine("Press ENTER to next test or CTRL-C to exit.");
                Console.ReadLine();
            }
            //
            // Display Queues and Members
            //
            ResponseEvents re;

            try
            {
                re = manager.SendEventGeneratingAction(new QueueStatusAction());
            }
            catch (EventTimeoutException e)
            {
                // this happens with Asterisk 1.0.x as it doesn't send a QueueStatusCompleteEvent
                re = e.PartialResult;
            }

            foreach (ManagerEvent e in re.Events)
            {
                if (e is QueueParamsEvent)
                {
                    QueueParamsEvent qe = (QueueParamsEvent)e;
                    Console.WriteLine("QueueParamsEvent" + "\n\tQueue:\t\t" + qe.Queue + "\n\tServiceLevel:\t" + qe.ServiceLevel);
                }
                else if (e is QueueMemberEvent)
                {
                    QueueMemberEvent qme = (QueueMemberEvent)e;
                    Console.WriteLine("QueueMemberEvent" + "\n\tQueue:\t\t" + qme.Queue + "\n\tLocation:\t" + qme.Location);
                }
                else if (e is QueueEntryEvent)
                {
                    QueueEntryEvent qee = (QueueEntryEvent)e;
                    Console.WriteLine("QueueEntryEvent" + "\n\tQueue:\t\t" + qee.Queue + "\n\tChannel:\t" + qee.Channel + "\n\tPosition:\t" + qee.Position);
                }
            }

            Console.WriteLine("Press ENTER to next test or CTRL-C to exit.");
            Console.ReadLine();

            //
            //	To test create 3 extensions:
            //	1 - SIP/4012 w/o voicemail (with eyeBeam softphone)
            //	2 - IAX2/4008 w/o voicemail (with iaxComm softphone)
            //	3 - SIP/4010 w/ voicemal but no phone connect

            //	RedirectCall: call from IAX2/4008 to SIP/4012
            //	Don't answer on SIP/4012 and call must redirect to SIP/4010 (to voicemail really)
            //	Dial event used to define redirect channel

            Console.WriteLine("Redirect Call from " + ORIGINATE_CHANNEL + " to " + ORIGINATE_EXTRA_CHANNEL + " or press ESC.");
            // Wait for Dial Event from ORIGINATE_CHANNEL
            DialEventHandler de = new DialEventHandler(dam_Dial);

            manager.Dial += de;
            while (transferChannel == null)
            {
                System.Threading.Thread.Sleep(100);
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)
                {
                    break;
                }
            }
            manager.Dial -= de;

            // Now send Redirect action
            RedirectAction ra = new RedirectAction();

            ra.Channel      = transferChannel;
            ra.ExtraChannel = ORIGINATE_EXTRA_CHANNEL;
            ra.Context      = ORIGINATE_CONTEXT;
            ra.Exten        = ORIGINATE_EXTRA_EXTEN;
            ra.Priority     = 1;
            try
            {
                ManagerResponse mr = manager.SendAction(ra, 10000);
                Console.WriteLine("Transfer Call"
                                  + "\n\tResponse:" + mr.Response
                                  + "\n\tMessage:" + mr.Message
                                  );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //	Monitor call.
            //	Call from IA2/4008 to SIP/4012
            //	Link event used to define monitor channel
            Console.WriteLine("Monitor call. Please call " + ORIGINATE_CHANNEL + " and answer or press ESC.");
            // Wait for Link event
            LinkEventHandler le = new LinkEventHandler(dam_Link);

            manager.Link += le;
            while (monitorChannel == null)
            {
                System.Threading.Thread.Sleep(100);
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)
                {
                    break;
                }
            }
            manager.Link -= le;
            // Now send Monitor action
            MonitorAction ma = new MonitorAction();

            ma.Channel = monitorChannel;
            ma.File    = "voicefile";
            ma.Format  = "gsm";
            ma.Mix     = true;
            try
            {
                ManagerResponse mr = manager.SendAction(ma, 10000);
                Console.WriteLine("Monitor Call"
                                  + "\n\tResponse:" + mr.Response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            manager.Logoff();
        }
コード例 #11
0
        private static void AssertGetConfigRequest(GetConfigResponse response)
        {
            Assert.IsTrue(response.Version > 0);
            
            // devices node
            Assert.IsNotNull(response.Devices);
            Assert.IsTrue(response.Devices.Count > 0);

            foreach (var device in response.Devices)
            {
                Assert.IsFalse(String.IsNullOrWhiteSpace(device.DeviceId));
            }

            // folders node
            Assert.IsNotNull(response.Folders);
            Assert.IsTrue(response.Folders.Count > 0);

            foreach (var folder in response.Folders)
            {
                Assert.IsFalse(String.IsNullOrWhiteSpace(folder.Id));
                Assert.IsFalse(String.IsNullOrWhiteSpace(folder.Path));

                foreach (var device in folder.Devices)
                {
                    Assert.IsFalse(String.IsNullOrWhiteSpace(device.DeviceId));
                }
            }

            Assert.IsNotNull(response.Gui);
            Assert.IsFalse(String.IsNullOrWhiteSpace(response.Gui.ApiKey));
            Assert.IsFalse(String.IsNullOrWhiteSpace(response.Gui.ListeningAddress));
        }