public static async Task RequestAuthenticationAsync(bool isUnregistered = false) { try { string req; if (isUnregistered) { (_, req) = await Session.EncodeUnregisteredRequestAsync(Constants.AppId); } else { (_, req) = await GenerateEncodedAuthReqAsync(); } var url = UrlFormat.Format(Constants.AppId, req, true); var appLaunched = await DependencyService.Get <IPlatformService>().OpenUri(url); if (!appLaunched) { await Application.Current.MainPage.DisplayAlert( "Authorisation failed", "The SAFE Authenticator app is required to authorise this application", "OK"); } } catch (Exception ex) { Logger.Error(ex); throw; } }
public async Task HandleUrlActivationAsync(string url) { try { // Decode auth response and Initialise a new session var encodedRequest = UrlFormat.GetRequestData(url); var decodeResult = await Session.DecodeIpcMessageAsync(encodedRequest); if (decodeResult.GetType() == typeof(AuthIpcMsg)) { var ipcMsg = decodeResult as AuthIpcMsg; if (ipcMsg != null) { _session = await Session.AppRegisteredAsync(Constants.AppId, ipcMsg.AuthGranted); DialogHelper.ShowToast("Auth Granted", DialogType.Success); MessagingCenter.Send(this, MessengerConstants.NavigateToItemPage); } } else { Debug.WriteLine("Auth Req is not Auth Granted"); } } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", $"Description: {ex.Message}", "OK"); } }
public static UrlScheme Parse(string rawUrl, UrlFormat urlFormat) { UrlScheme scheme = new UrlScheme(); scheme.DoParse(rawUrl, urlFormat); return(scheme); }
public async Task <string> GenerateAppRequestAsync() { AuthReq authReq = new AuthReq { AppContainer = true, App = new AppExchangeInfo { Id = AppId, Scope = string.Empty, Name = "SAFE Todo App", Vendor = "MaidSafe.net Ltd" }, Containers = new List <ContainerPermissions> { new ContainerPermissions { ContName = "_publicNames", Access = { Insert = true, Update = true, Delete = true } } } }; (uint, string)encodedReq = await Session.EncodeAuthReqAsync(authReq); string formattedReq = UrlFormat.Format(AppId, encodedReq.Item2, true); Debug.WriteLine($"Encoded Req: {formattedReq}"); return(formattedReq); }
protected virtual HyperLink AddAnchor(Control container, PluginContext context) { string tooltip = Utility.GetResourceString(GlobalResourceClassName, Name + ".ToolTip") ?? ToolTip; string title = Utility.GetResourceString(GlobalResourceClassName, Name + ".Title") ?? Title; string alternative = Utility.GetResourceString(GlobalResourceClassName, Name + ".AlternativeText") ?? AlternativeText; HyperLink a = new HyperLink(); a.ID = "h" + Name; a.NavigateUrl = context.Rebase(context.Format(UrlFormat, true)); a.SkinID = "ToolBarLink_" + Name; a.Target = Target; a.Attributes["class"] = Name + " " + RequiredPermission.ToString() + (string.IsNullOrEmpty(IconUrl) ? "" : " iconed"); if (UrlFormat.Contains("{")) { a.Attributes["class"] += " templatedurl"; a.Attributes["data-url-template"] = context.Rebase(UrlFormat); } a.ToolTip = tooltip; a.Text = title; ApplyStyles(context, a); container.Controls.Add(a); return(a); }
internal async Task HandleUrlActivationAsync(string encodedUri) { try { if (await HandleUnregisteredAppRequest(encodedUri)) { return; } if (_authenticator == null) { AuthenticationReq = encodedUri; if (!_sessionConfig.KeepAlive) { //var response = await Application.Current.MainPage.DisplayAlert( // "Login Required", // "An application is requesting access, login to authorise", // "Login", // "Cancel"); //if (response) //{ // MessagingCenter.Send(this, MessengerConstants.NavPreviousPage); //} } return; } //if (Connectivity.NetworkAccess == NetworkAccess.Internet) //{ await CheckAndReconnect(); //} var encodedReq = UrlFormat.GetRequestData(encodedUri); var decodeResult = await _authenticator.DecodeIpcMessageAsync(encodedReq); var decodedType = decodeResult.GetType(); if (decodedType == typeof(IpcReqError)) { var error = decodeResult as IpcReqError; throw new FfiException(error.Code, error.Description); } else { //MessagingCenter.Send(this, MessengerConstants.NavPreviousPage); //var requestPage = new RequestDetailPage(encodedUri, decodeResult); //await Application.Current.MainPage.Navigation.PushPopupAsync(requestPage); } } catch (FfiException ex) { var errorMessage = Utilities.GetErrorMessage(ex); //await Application.Current.MainPage.DisplayAlert("Authorisation Error", errorMessage, "OK"); } catch (Exception ex) { //await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK"); } }
public void SendRequest(string encodedRequest, bool isUnregistered) { var formattedReqUrl = UrlFormat.Format(Constants.AppId, encodedRequest, true); Debug.WriteLine($"Encoded Req : {formattedReqUrl}"); Device.BeginInvokeOnMainThread(() => { Device.OpenUri(new Uri(formattedReqUrl)); }); }
public async Task ProcessAuthenticationResponseAsync(string url) { try { MessagingCenter.Send(this, MessageCenterConstants.ProcessingAuthResponse); var encodedResponse = UrlFormat.GetRequestData(url); var decodeResponse = await Session.DecodeIpcMessageAsync(encodedResponse); var decodedResponseType = decodeResponse.GetType(); if (decodedResponseType == typeof(UnregisteredIpcMsg)) { if (decodeResponse is UnregisteredIpcMsg ipcMsg) { App.AppSession = await Session.AppConnectAsync(Constants.AppId, encodedResponse); MessagingCenter.Send(this, MessageCenterConstants.Authenticated, encodedResponse); } } else if (decodedResponseType == typeof(AuthIpcMsg)) { if (decodeResponse is AuthIpcMsg ipcMsg) { using (UserDialogs.Instance.Loading(Constants.ConnectingProgressText)) { Session session = await Session.AppConnectAsync(Constants.AppId, encodedResponse); AppService.InitialiseSession(session); } } } } catch (FfiException ex) { Logger.Error(ex); if (ex.ErrorCode != -106) { if (ex.Message.Contains("AuthDenied")) { await Application.Current.MainPage.DisplayAlert( ErrorConstants.AuthenticationFailedTitle, ErrorConstants.RequestDeniedMsg, "OK"); } else { await Application.Current.MainPage.DisplayAlert( ErrorConstants.AuthenticationFailedTitle, ErrorConstants.AuthenticationFailedMsg, "OK"); } } } catch (Exception ex) { Logger.Error(ex); await Application.Current.MainPage.DisplayAlert("Authentication", "Authentication Failed", "OK"); } }
public async Task ProcessNonMockAuthentication() { // Send encoded AuthReq to SAFE Authenticator using Uri var encodedAuthReq = await GenerateEncodedAuthReqAsync(); var url = UrlFormat.Format(Constants.AppId, encodedAuthReq.Item2, true); Device.BeginInvokeOnMainThread(() => { Device.OpenUri(new Uri(url)); }); }
public async Task ProcessResponseAsync(string encodedResponse) { try { var encodedRequest = UrlFormat.GetRequestData(encodedResponse); var decodeResult = await Session.DecodeIpcMessageAsync(encodedRequest); var decodeResultType = decodeResult.GetType(); if (decodeResultType == typeof(AuthIpcMsg)) { Debug.WriteLine("Received Auth Granted from Authenticator"); // Update auth progress message var ipcMsg = decodeResult as AuthIpcMsg; await Application.Current.MainPage.DisplayAlert("Auth Request", $"Request granted", "OK"); var session = await Session.AppRegisteredAsync(Constants.AppId, ipcMsg.AuthGranted); DependencyService.Get <SafeAppService>().InitialiseSession(session, false); MessagingCenter.Send(this, "UpdateUI"); } else if (decodeResultType == typeof(ContainersIpcMsg)) { // Get container response and refresh container var ipcMsg = decodeResult as ContainersIpcMsg; await Application.Current.MainPage.DisplayAlert("Container Request", $"Request granted", "OK"); await DependencyService.Get <SafeAppService>().RefreshContainersAsync(); } else if (decodeResultType == typeof(ShareMDataIpcMsg)) { // Get Share MData response var ipcMsg = decodeResult as ShareMDataIpcMsg; await Application.Current.MainPage.DisplayAlert("ShareMData Request", $"Request granted", "OK"); } else if (decodeResultType == typeof(UnregisteredIpcMsg)) { //Create session object var ipcMsg = decodeResult as UnregisteredIpcMsg; await Application.Current.MainPage.DisplayAlert("Unregistred Request", $"Request granted", "OK"); var session = await Session.AppUnregisteredAsync(ipcMsg.SerialisedCfg); DependencyService.Get <SafeAppService>().InitialiseSession(session, true); MessagingCenter.Send(this, "UpdateUI"); } else { await Application.Current.MainPage.DisplayAlert("Error", $"Request not granted", "OK"); } } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", $"Description: {ex.Message}", "OK"); } }
public async Task <string> HandleUrlActivationAsync(string encodedUri) { try { if (_authenticator == null) { return(null); } await CheckAndReconnect(); var encodedReq = UrlFormat.GetRequestData(encodedUri); var decodeResult = await _authenticator.DecodeIpcMessageAsync(encodedReq); var decodedType = decodeResult.GetType(); if (decodedType == typeof(AuthIpcReq)) { var authReq = decodeResult as AuthIpcReq; Debug.WriteLine($"Decoded Req From {authReq?.AuthReq.App.Name}"); var isGranted = true; // await Application.Current.MainPage.DisplayAlert( //"Auth Request", //$"{authReq?.AuthReq.App.Name} is requesting access", //"Allow", //"Deny"); var encodedRsp = await _authenticator.EncodeAuthRespAsync(authReq, isGranted); var formattedRsp = UrlFormat.Format(authReq?.AuthReq.App.Id, encodedRsp, false); Debug.WriteLine($"Encoded Rsp to app: {formattedRsp}"); //Device.BeginInvokeOnMainThread(() => { Device.OpenUri(new Uri(formattedRsp)); }); return(formattedRsp); } else if (decodedType == typeof(IpcReqError)) { var error = decodeResult as IpcReqError; Debug.WriteLine("Auth Request", $"Error: {error?.Description}", "Ok"); } else { Debug.WriteLine("Decoded Req is not Auth Req"); } } catch (Exception ex) { var errorMsg = ex.Message; if (ex is ArgumentNullException) { errorMsg = "Ignoring Auth Request: Need to be logged in to accept app requests."; } Debug.WriteLine("Error", errorMsg, "OK"); } return(null); }
private void btn_detail_Click(object sender, EventArgs e) { UrlFormat urlFormat = new UrlFormat() { UrlName = txt_Urls.Text, UrlScan = this.UrlScan, }; using (FormScanDetail formFileScanDetail = new FormScanDetail(urlFormat)) { formFileScanDetail.ShowDialog(); } }
private IEnumerable <ModuleEvent> GetEventByUrl(string url, List <Analysis> analys, List <ModuleEvent> modulement) { var data = new UrlFormat(url); var analysis = analys.FirstOrDefault(x => x.Url == data.Url); if (analysis == null) { return(new List <ModuleEvent>()); } var moduleEvent = modulement.Where(x => x.AnalysisId == analysis.Id && x.Code == data.Code); return(moduleEvent); }
async Task <bool> HandleUnregisteredAppRequest(string encodedUri) { var encodedReq = UrlFormat.GetRequestData(encodedUri); var udecodeResult = await AuthSession.UnRegisteredDecodeIpcMsgAsync(encodedReq); if (udecodeResult.GetType() == typeof(UnregisteredIpcReq)) { //var requestPage = new RequestDetailPage(encodedUri, udecodeResult); //await Application.Current.MainPage.Navigation.PushPopupAsync(requestPage); return(true); } return(false); }
protected ABooru(string baseUrl, UrlFormat format, BooruOptions options) { Auth = null; HttpClient = null; _options = options; bool useHttp = UsesHttp(); // Cache returned value for faster access. #pragma warning disable CS0618 // Keep this field for a while in case someone still depends on it. _useHttp = useHttp; #pragma warning restore CS0618 _baseUrl = "http" + (useHttp ? "" : "s") + "://" + baseUrl; _format = format; _imageUrl = "http" + (useHttp ? "" : "s") + "://" + baseUrl + "/" + GetUrl(format, "post"); if (_format == UrlFormat.indexPhp) { _imageUrlXml = _imageUrl.Replace("json=1", "json=0"); } else if (_format == UrlFormat.postIndexJson) { _imageUrlXml = _imageUrl.Replace("index.json", "index.xml"); } _tagUrl = "http" + (useHttp ? "" : "s") + "://" + baseUrl + "/" + GetUrl(format, "tag"); if (HasWikiAPI()) { _wikiUrl = format == UrlFormat.danbooru ? "http" + (useHttp ? "" : "s") + "://" + baseUrl + "/" + GetUrl(format, "wiki_page") : "http" + (useHttp ? "" : "s") + "://" + baseUrl + "/" + GetUrl(format, "wiki"); } if (HasRelatedAPI()) { _relatedUrl = format == UrlFormat.danbooru ? "http" + (useHttp ? "" : "s") + "://" + baseUrl + "/" + GetUrl(format, "related_tag") : "http" + (useHttp ? "" : "s") + "://" + baseUrl + "/" + GetUrl(format, "tag", "related"); } if (HasCommentAPI()) { _commentUrl = "http" + (useHttp ? "" : "s") + "://" + baseUrl + "/" + GetUrl(format, "comment"); } }
public string GetUrlStr(string hashName) { //有三个参数 if (UrlFormat.IndexOf("{2}", StringComparison.Ordinal) > 0) { return(string.Format(UrlFormat, hashName.Substring(0, 2), hashName.Substring(hashName.Length - 2, 2), hashName)); } // //有两个参数 else if ((UrlFormat.IndexOf("{1}", StringComparison.Ordinal) > 0)) { return(string.Format(UrlFormat, hashName.Substring(0, 2), hashName)); } //有一个参数 else if ((UrlFormat.IndexOf("{0}", StringComparison.Ordinal) > 0)) { return(string.Format(UrlFormat, hashName)); } return(UrlFormat); }
private protected static string GetUrl(UrlFormat format, string query, string squery = "index") { switch (format) { case UrlFormat.postIndexJson: return(query + "/" + squery + ".json"); case UrlFormat.indexPhp: return("index.php?page=dapi&s=" + query + "&q=index&json=1"); case UrlFormat.danbooru: return(query == "related_tag" ? query + ".json" : query + "s.json"); case UrlFormat.sankaku: return(query == "wiki" ? query : query + "s"); default: return(null); } }
public static bool IsNeedProcess(string absolutePath) { if (StringUtil.EndsWithIgnoreCase(absolutePath, ".aspx") || StringUtil.EndsWith(absolutePath, '/')) { return(true); } UrlFormat urlFormat = AllSettings.Current.FriendlyUrlSettings.UrlFormat; switch (urlFormat) { case UrlFormat.Html: return(StringUtil.EndsWithIgnoreCase(absolutePath, ".html")); case UrlFormat.Folder: string ext = Path.GetExtension(absolutePath); return(string.Compare(ext, string.Empty, true) == 0); default: return(false); } }
public async Task RequestAuthenticationAsync(bool isUnregistered = false) { try { App.PendingRequest = true; var filePath = Path.Combine(ConfigFilePath, _defaultNodeConnectionFileName); if (File.Exists(filePath)) { File.Delete(filePath); } string req; if (isUnregistered) { (_, req) = await Session.EncodeUnregisteredRequestAsync(Constants.AppId); } else { (_, req) = await GenerateEncodedAuthReqAsync(); } var url = UrlFormat.Format(Constants.AppId, req, true); var appLaunched = await DependencyService.Get <IPlatformService>().OpenUri(url); if (!appLaunched) { await Application.Current.MainPage.DisplayAlert( ErrorConstants.AuthenticationFailedTitle, ErrorConstants.AuthenticatorAppNotFoundMsg, "OK"); } } catch (Exception ex) { Logger.Error(ex); throw; } }
private static void UpdateUrlFormat(UrlFormat urlFormat) { FriendlyUrlSettings setting = new FriendlyUrlSettings(); setting.UrlFormat = urlFormat; string sqlString = @" IF EXISTS (SELECT * FROM [sysobjects] WHERE [type]='U' AND [name]='bx_Settings') BEGIN IF EXISTS(SELECT * from [bx_Settings] WHERE [TypeName]='MaxLabs.bbsMax.Settings.FriendlyUrlSettings') UPDATE [bx_Settings] SET [Value]='" + setting.ToString() + @"' WHERE [TypeName]='MaxLabs.bbsMax.Settings.FriendlyUrlSettings'; ELSE INSERT INTO [bx_Settings]([Key],[TypeName],[Value]) VALUES('*','MaxLabs.bbsMax.Settings.FriendlyUrlSettings','" + setting.ToString() + @"'); END "; string connStr = Settings.Current.IConnectionString; using (SqlConnection conn = new SqlConnection(connStr)) { if (ConnectionState.Closed == conn.State) conn.Open(); SqlCommand cmd; cmd = new SqlCommand(sqlString, conn); cmd.ExecuteNonQuery(); conn.Close(); } }
public string PageRender() { int countpage = (int)Math.Ceiling((double)CountNum / CountPerPage); string url = UrlFormat.Replace("{&Page}", "&Page="); StringBuilder sb = new StringBuilder(); if (countpage <= displayNum)//总页数小于要显示的标签个数 { for (int i = 1; i <= countpage; i++) { if (i == CurrentPage) { sb.Append(i); } else { sb.Append("<a href=" + initURL(i) + ">" + i + "</a>"); } } } else { sb.Append("<a class='doublePage' href=" + initURL(1) + ">" + "首" + "</a>"); if (CurrentPage != 1) { sb.Append("<a class='doublePage' href=" + initURL(CurrentPage - 1) + ">" + "前" + "</a>"); } for (int i = 1; i <= displayNum; i++) { if (CurrentPage < (int)Math.Ceiling((double)displayNum / 2)) { if (i == CurrentPage)//当前页的输出不带超键接 { sb.Append(CurrentPage); } else { sb.Append("<a href=" + initURL(i) + ">" + i + "</a>"); } } else if ((int)(countpage - CurrentPage) < (int)Math.Ceiling((double)displayNum / 2)) { if (countpage - displayNum + i == CurrentPage)//当前页的输出不带超键接 { sb.Append(CurrentPage); } else { sb.Append("<a href=" + initURL(countpage - displayNum + i) + ">" + (countpage - displayNum + i) + "</a>"); } } else { if ((CurrentPage - (int)Math.Ceiling((double)displayNum / 2) + i) == CurrentPage) { sb.Append(CurrentPage); } else { sb.Append("<a href=" + initURL(CurrentPage - (int)Math.Ceiling((double)displayNum / 2) + i) + ">" + (CurrentPage - (int)Math.Ceiling((double)displayNum / 2) + i) + "</a>"); } } } if (CurrentPage != countpage) { sb.Append("<a class='doublePage' href=" + initURL(CurrentPage + 1) + ">" + "后" + "</a>"); } sb.Append("<a class='doublePage' href=" + initURL(countpage) + ">" + "末" + "</a>"); } return(sb.ToString()); }
} //要显示的页面标签条数(不包括首页,前页,后页和尾页) private string initURL(int i) { return(UrlFormat.Replace("{&Page}", "&Page=" + i)); }
public static string GetUrlInfo(string url) { string webRoot = Globals.AppRoot + "/"; string fullWebRoot = Globals.FullAppRoot + "/"; UrlFormat urlFormat = AllSettings.Current.FriendlyUrlSettings.UrlFormat; int baseUrlLength = 0;// = urlFormat == UrlFormat.Query ? 1 : 0; string urlInfo; if (StringUtil.StartsWithIgnoreCase(url, webRoot)) { baseUrlLength += webRoot.Length; } else if (StringUtil.StartsWithIgnoreCase(url, fullWebRoot)) { baseUrlLength += fullWebRoot.Length; } else { return(string.Empty); } if (urlFormat == UrlFormat.Query) { //确认是本程序内的地址以保证安全 if (UrlUtil.IsUrlInApp(url)) { if (url.IndexOf("default.aspx?", baseUrlLength) == baseUrlLength) { baseUrlLength += 13; } else if (url.IndexOf("index.aspx?", baseUrlLength) == baseUrlLength) { baseUrlLength += 11; } else { baseUrlLength += 1; } } else { baseUrlLength += 1; } } if (url.Length > baseUrlLength) { urlInfo = url.Substring(baseUrlLength); } else { urlInfo = "default"; } int queryIndex = urlInfo.IndexOf('?'); if (queryIndex != -1) { urlInfo = urlInfo.Substring(0, queryIndex); } if (urlFormat == UrlFormat.Aspx) { if (urlInfo.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase)) { urlInfo = urlInfo.Substring(0, urlInfo.Length - 5); } else { return(string.Empty); } } else if (urlFormat == UrlFormat.Html) { if (urlInfo.EndsWith(".html", StringComparison.OrdinalIgnoreCase)) { urlInfo = urlInfo.Substring(0, urlInfo.Length - 5); } else { return(string.Empty); } } return(urlInfo.ToLower()); }
public void DoParse(string rawUrl, UrlFormat urlFormat) { int appUrlLength = Globals.AppRoot.Length + 1; int queryIndex; string main, originalMain, query; string nameLink = null; int nameLinkIndex = rawUrl.IndexOf('#'); if (nameLinkIndex >= 0) { nameLink = rawUrl.Substring(nameLinkIndex); rawUrl = rawUrl.Remove(nameLinkIndex); } switch (urlFormat) { case UrlFormat.Aspx: case UrlFormat.Html: queryIndex = rawUrl.IndexOf('?', appUrlLength); if (queryIndex == -1) { originalMain = rawUrl.Substring(appUrlLength, rawUrl.Length - appUrlLength); query = string.Empty; } else { originalMain = rawUrl.Substring(appUrlLength, queryIndex - appUrlLength); query = rawUrl.Substring(queryIndex); } main = originalMain.Remove(originalMain.Length - 5); break; default: if (urlFormat == UrlFormat.Query) { int rawLength = rawUrl.Length; if (rawUrl[appUrlLength] == '?') { originalMain = "?"; appUrlLength++; } else if (rawLength > appUrlLength + 12 && rawUrl[appUrlLength + 12] == '?' && string.Compare(rawUrl.Substring(appUrlLength, 7), "default", true) == 0) { originalMain = "?"; appUrlLength += 13; } else if (rawLength > appUrlLength + 10 && rawUrl[appUrlLength + 10] == '?' && string.Compare(rawUrl.Substring(appUrlLength, 5), "index", true) == 0) { originalMain = "?"; appUrlLength += 11; } else if (rawLength == appUrlLength) { this.m_OriginalMain = string.Empty; this.m_Main = string.Empty; this.m_QueryString = string.Empty; return; } else { originalMain = string.Empty; } } else { originalMain = string.Empty; } queryIndex = rawUrl.IndexOf('?', appUrlLength); if (queryIndex == -1) { main = rawUrl.Substring(appUrlLength, rawUrl.Length - appUrlLength); query = string.Empty; } else { main = rawUrl.Substring(appUrlLength, queryIndex - appUrlLength); query = rawUrl.Substring(queryIndex); } originalMain += main; break; } if (main.Length > 5 && main[main.Length - 5] == '.' && (StringUtil.EndsWithIgnoreCase(main, ".aspx") || StringUtil.EndsWithIgnoreCase(main, ".html")) ) { main = main.Remove(main.Length - 5); } if (main.Length == 0 || (main.Length == 5 && string.Compare(main, "index", true) == 0)) { main = "default"; if (urlFormat == UrlFormat.Query) { originalMain = "?default"; } } else if (urlFormat == UrlFormat.Query && string.Compare(main, "default", true) == 0) { originalMain = "?default"; } //if (originalMain.Length == 0 || ) this.m_OriginalMain = originalMain; this.m_Main = main; this.m_QueryString = query; if (nameLink != null) { this.m_NameLink = nameLink; } }
protected ABooru(string baseUrl, UrlFormat format, params BooruOptions[] options) : this(baseUrl, format, MergeOptions(options)) { }