コード例 #1
0
        public static SeachQuery ParseSearchQuery(UriExt url)
        {
            var query = url.QueryParam;

            string tmpValue;
            var    search = new SeachQuery();

            DateTime lastinvoked;

            if ((tmpValue = query["lastinvoked"]) != null && DateTime.TryParse(tmpValue, out lastinvoked))
            {
                search.LastInvokedAfter = lastinvoked;
            }

            uint userId;

            if ((tmpValue = query["userid"]) != null && uint.TryParse(tmpValue, out userId))
            {
                search.UserId = userId;
            }

            int max;

            if ((tmpValue = query["max"]) != null && int.TryParse(tmpValue, out max))
            {
                search.MaxResults = max;
            }

            search.TitlePart = query["title"];

            return(search);
        }
コード例 #2
0
ファイル: WebDisplay.cs プロジェクト: makindotcc/TS3AudioBot
        public override PreparedData PrepareSite(UriExt url)
        {
            try
            {
                var search = WebHistorySearch.ParseSearchQuery(url);
                var result = History.Search(search);

                var strb = new StringBuilder();
                foreach (var entry in result)
                {
                    strb.Append("<tr><td>").Append(entry.Id)
                    .Append("</td><td>").Append(entry.UserInvokeId)
                    .Append("</td><td class=\"fillwrap\">").Append(HttpUtility.HtmlEncode(entry.AudioResource.ResourceTitle))
                    .Append("</td><td>Options</td></tr>");
                }
                string finString = strb.ToString();
                byte[] finBlock  = Encoding.GetBytes(finString);

                return(new PreparedData(finBlock.Length, finBlock));
            }
            catch (CommandSystem.CommandException)
            {
                return(new PreparedData(0, new byte[0]));
            }
        }
コード例 #3
0
ファイル: WebDisplay.cs プロジェクト: makindotcc/TS3AudioBot
        public override PreparedData PrepareSite(UriExt url)
        {
            var search = ParseSearchQuery(url);

            try
            {
                var result = History.Search(search).Select(e => new
                {
                    id      = e.Id,
                    atype   = e.AudioResource.AudioType,
                    playcnt = e.PlayCount,
                    title   = HttpUtility.HtmlEncode(e.AudioResource.ResourceTitle),
                    time    = e.Timestamp,
                    userid  = e.UserInvokeId
                });

                string serialized = Util.Serializer.Serialize(result);
                var    dataArray  = Encoding.GetBytes(serialized);

                return(new PreparedData(dataArray.Length, dataArray));
            }
            catch (CommandSystem.CommandException)
            {
                return(new PreparedData(0, new byte[0]));
            }
        }
コード例 #4
0
        public override PreparedData PrepareSite(UriExt url)
        {
            ParseHtml();
            byte[] fetchBlock = provider.FetchFile();

            var prepInside = innerSite.PrepareSite(url);

            return(new PreparedData(PrepLen + prepInside.Length, new ContentSite(fetchBlock, innerSite, prepInside)));
        }
コード例 #5
0
        private void setOTPField(PwEntry pwEntry, bool protectSecret, GeneralSectionField sectionField, OTPFormat otpFormat)
        {
            if (otpFormat == OTPFormat.KeeWeb)
            {
                // KeeWeb uses the otpauth URI, same as 1Password
                pwEntry.Strings.Set("otp", new ProtectedString(protectSecret, sectionField.v));
            }
            else
            {
                // Decompose otpauth URI
                if (!Uri.IsWellFormedUriString(sectionField.v, UriKind.RelativeOrAbsolute))
                {
                    return;
                }

                Uri    totpUri     = new Uri(sectionField.v);
                string queryString = totpUri.Query;
                Dictionary <string, string> totpParams = UriExt.GetParams(queryString);

                string secret = null, period = null, digits = null;

                // If we have no secret, it's not worth setting the OTP field
                if (!totpParams.TryGetValue("secret", out secret))
                {
                    return;
                }

                totpParams.TryGetValue("period", out period);
                totpParams.TryGetValue("digits", out digits);

                if (otpFormat == OTPFormat.KeeOtp)
                {
                    StringBuilder keeOtpString = new StringBuilder();
                    keeOtpString.AppendFormat("key={0}", secret);

                    if (!string.IsNullOrEmpty(period))
                    {
                        keeOtpString.AppendFormat("&step={0}", period);
                    }
                    if (!string.IsNullOrEmpty(digits))
                    {
                        keeOtpString.AppendFormat("&size={0}", digits);
                    }

                    pwEntry.Strings.Set("otp", new ProtectedString(protectSecret, keeOtpString.ToString()));
                }
                else if (otpFormat == OTPFormat.TrayTOTP)
                {
                    pwEntry.Strings.Set("TOTP Seed", new ProtectedString(protectSecret, secret));
                    // Some Kee* implementations don't show the OTP unless these optional values are set
                    pwEntry.Strings.Set("TOTP Settings", new ProtectedString(false, string.Join(";", new string[] { period ?? OTP_DEFAULT_PERIOD, digits ?? OTP_DEFAULT_DIGITS })));
                }
            }
        }
コード例 #6
0
ファイル: WebApi.cs プロジェクト: davlast/TS3AudioBot
        private void ProcessApiV1Call(UriExt uri, HttpListenerResponse response, UserSession session)
        {
            string apirequest = uri.AbsolutePath.Substring("/api".Length);
            var    ast        = CommandParser.ParseCommandRequest(apirequest, '/', '/');

            UnescapeAstTree(ast);

            var command = MainBot.CommandManager.CommandSystem.AstToCommandResult(ast);

            var execInfo = new ExecutionInformation(session, null)
            {
                ApiCall = true
            };

            using (var token = execInfo.Session.GetLock())
            {
                try
                {
                    var res = command.Execute(execInfo, Enumerable.Empty <ICommand>(),
                                              new[] { CommandResultType.Json, CommandResultType.Empty });

                    if (res.ResultType == CommandResultType.Empty)
                    {
                        response.StatusCode = (int)HttpStatusCode.NoContent;
                    }
                    else if (res.ResultType == CommandResultType.Json)
                    {
                        response.StatusCode = (int)HttpStatusCode.OK;
                        var sRes = (JsonCommandResult)res;
                        using (var responseStream = new StreamWriter(response.OutputStream))
                            responseStream.Write(sRes.JsonObject.Serialize());
                    }
                }
                catch (CommandException ex)
                {
                    ReturnError(ex, response);
                }
                catch (Exception ex)
                {
                    if (ex is NotImplementedException)
                    {
                        response.StatusCode = (int)HttpStatusCode.NotImplemented;
                    }
                    else
                    {
                        response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    }
                    Log.Write(Log.Level.Error, "WA Unexpected command error: {0}", ex);
                    using (var responseStream = new StreamWriter(response.OutputStream))
                        responseStream.Write(new JsonError(ex.Message, CommandExceptionReason.Unknown).Serialize());
                }
            }
        }
コード例 #7
0
ファイル: WebApi.cs プロジェクト: davlast/TS3AudioBot
        public override void DispatchCall(HttpListenerContext context)
        {
            using (var response = context.Response)
            {
                var session = Authenticate(context);
                if (session == null)
                {
                    Log.Write(Log.Level.Debug, "Not authorized!");
                    ReturnError(CommandExceptionReason.Unauthorized, "", context.Response);
                    return;
                }

                var requestUrl = new UriExt(new Uri(dummy, context.Request.RawUrl));
                ProcessApiV1Call(requestUrl, context.Response, session);
            }
        }
コード例 #8
0
        public override void DispatchCall(HttpListenerContext context)
        {
            using (var response = context.Response)
            {
                response.AddHeader("Access-Control-Allow-Origin", "*");

                var invoker = Authenticate(context);
                if (invoker == null)
                {
                    Log.Write(Log.Level.Debug, "Not authorized!");
                    ReturnError(CommandExceptionReason.Unauthorized, "", context.Response);
                    return;
                }

                var requestUrl = new UriExt(new Uri(dummy, context.Request.RawUrl));
                ProcessApiV1Call(requestUrl, context.Response, invoker);
            }
        }
コード例 #9
0
        public override PreparedData PrepareSite(UriExt url)
        {
            ParseHtml();
            byte[] fetchBlock = provider.FetchFile();
            var    query      = url.QueryParam;

            var querySiteName = query["page"] ?? string.Empty;

            var querySite = siteFinder(new Uri(new Uri(url.GetLeftPart(UriPartial.Authority)), querySiteName));

            if (querySite == this)
            {
                querySite = siteFinder(null);
            }

            var prepInside = querySite.PrepareSite(url);

            return(new PreparedData(PrepLen + prepInside.Length, new ContentSite(fetchBlock, querySite, prepInside)));
        }
コード例 #10
0
        public override PreparedData PrepareSite(UriExt url)
        {
            switch (url.QueryParam["op"])
            {
            default:
            case null: break;

            case "volume":
                var volumeStr = url.QueryParam["volume"];
                int volume;
                if (int.TryParse(volumeStr, out volume))
                {
                    audio.Volume = volume;
                }
                break;

            case "prev": playMgr.Previous(new InvokerData()); break;             // HACK: use token-system to determine user when its available

            case "play": audio.Pause = !audio.Pause; break;

            case "next": playMgr.Next(new InvokerData()); break;             // HACK: use token-system to determine user when its available

            case "loop": audio.Repeat = !audio.Repeat; break;

            case "seek":
                var    seekStr = url.QueryParam["pos"];
                double seek;
                if (double.TryParse(seekStr, out seek))
                {
                    var pos = TimeSpan.FromSeconds(seek);
                    if (pos >= TimeSpan.Zero && pos <= audio.Length)
                    {
                        audio.Position = pos;
                    }
                }
                break;
            }
            return(new PreparedData(0, new byte[0]));
        }
コード例 #11
0
        private HttpRequestMessage CreateMessage(HttpMethod httpMethod, string endPoint)
        {
            string finalUrl = UriExt.Combine(_recaptchaClientSettings.Url, endPoint);

            return(new HttpRequestMessage(httpMethod, finalUrl));
        }
コード例 #12
0
 public sealed override PreparedData PrepareSite(UriExt url) => new PreparedData(long.MaxValue, null);
コード例 #13
0
 public override PreparedData PrepareSite(UriExt url)
 {
     byte[] prepData = provider.FetchFile();
     return(new PreparedData(prepData.Length, prepData));
 }
コード例 #14
0
 public abstract PreparedData PrepareSite(UriExt url);