Ejemplo n.º 1
0
        private void httpServer_OnPOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            switch (p.http_url)
            {
                case "/settings":
                    {
                        string data = inputData.ReadToEnd();
                        var dataList = GetDataList(data);
                        var command = (from item in dataList where item.Key == "command" select item).SingleOrDefault().Value;

                        p.writeSuccess();
                        Settings.Default.Save();
                        p.outputStream.WriteLine("<html><body><h3>Balance Checker settings saved</h3>");
                        p.outputStream.WriteLine("<a href=/>main</a><p>");
                    }
                    break;
                case "/sipgsmsettings":
                    {
                        string data = inputData.ReadToEnd();
                        var dataList = GetDataList(data);
                        p.outputStream.WriteLine("<html><body><h3>Balance Checker settings saved</h3>");
                        p.outputStream.WriteLine("<a href=/>main</a><p>");
                    }
                    break;
                case "/conf":
                    Log.Write("Получение конфигурации с сервера");
                    string postData = inputData.ReadToEnd();
                    try
                    {
                        Log.Write("Запись конфигурации в файл");
                        File.WriteAllText(@"../Cfg/conf.xml", postData);
                    }
                    catch (Exception ex)
                    {
                        Log.Write("[Ошибка] :: " + ex.Message);
                    }
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 2
0
        private void httpServer_OnGETRequest(HttpProcessor p)
        {
            switch (p.http_url)
            {
                case "/":
                    {
                        p.outputStream.WriteLine(@"
            <html>
            <head>" +
            "\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" +
            @"</head>
            <body>
            <h3>Balance Checker</h3>
            </body>
            </html>
            ");
                    }
                    break;
                case "/reconf":
                    {
                        p.writeSuccess();
                        p.outputStream.WriteLine(@"
            <html>
            <head>" +
            "\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" +
            @"</head>
            <body>
            <h4>Добавлены конфигурации для IMEI :</h4>
            ");
                        UpdateSipGSMConfig(p);
                        p.outputStream.WriteLine(@"
            <h4>Конфигурация обновлена!</h4>
            </body>
            </html>
            ");
                    }
                    break;
                case "/settings":
                    {
                        p.Show("html/settings.html");
                    }
                    break;
                case "/sipgsmsettings":
                    {
                        p.Show("html/sipgsmsettings.html");
                    }
                    break;
                case "/onoff":
                    {
                        OnOff();
                        var result = CheckSipGsm();
                        string htmlText = string.Format(Settings.Default.SipGsmStatusHtml, "Stopped" == result ? "#CC3300" : "#006600", result);
                        p.writeSuccess();
                        p.outputStream.WriteLine(htmlText);

                    }
                    break;
                case "/checksipgsm":
                    {
                        var result = CheckSipGsm();
                        string htmlText = string.Format(Settings.Default.SipGsmStatusHtml, ("Stopped" == result ? "#CC3300" : "#006600"), result);
                        p.writeSuccess();
                        p.outputStream.WriteLine(htmlText);
                    }
                    break;
                case "/check":
                    p.writeSuccess();
                    p.outputStream.WriteLine(@"
            <html>
            <head>" +
            "\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" +
            @"<title>Checking Balance</title>
            </head>
            <body>
            <h3>Processing...</h3>
            ");
                    StartCheckBalance();
                    p.outputStream.WriteLine(@"
            </body>
            </html>
            ");
                    break;
                case "/favicon.ico" :
                    Stream fs = File.Open("html/favicon.ico", FileMode.Open);
                    p.writeSuccess("image/x-icon");
                    fs.CopyTo (p.outputStream.BaseStream);
                    p.outputStream.BaseStream.Flush ();
                    break;
                default:
                    p.writeSuccess();
                    p.outputStream.WriteLine("<html><body><h5>Command \"" + p.http_url + "\" not founded</h5>");
                    break;
            }
        }