Exemplo n.º 1
0
        public bool Authenticate(MoxieManager.Core.Auth.User user)
        {
            if (!TSAuthentication.IsAuthenticated())
            {
                return(false);
            }
            var config = ManagerContext.Current.Config;

            //string root = SystemSettings.ReadString(TSAuthentication.GetLoginUser(), "FilePath", "C:\\TSData");
            Data.FilePaths filePaths = new FilePaths(TSAuthentication.GetLoginUser());
            filePaths.LoadByID(1);
            string root = filePaths[0].Value;

            root = Path.Combine(root, "WikiDocs\\" + TSAuthentication.OrganizationID.ToString());
            Directory.CreateDirectory(Path.Combine(root, "images"));
            Directory.CreateDirectory(Path.Combine(root, "documents"));
            config.Put("filesystem.rootpath", root);
            config.Put("filesystem.local.wwwroot", root);
            config.Put("filesystem.local.urlprefix", "{proto}://{host}/Wiki/WikiDocs/" + TSAuthentication.OrganizationID.ToString());
            return(true);
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {            //https://host/wiki/wikidocs/{path}
                         //https://app.teamsupport.com/Wiki/WikiDocs/1078/images/Misc%20Graphics/BlueBadge.png


                StringBuilder builder = new StringBuilder();
                bool          flag    = false;
                foreach (string item in context.Request.Url.Segments)
                {
                    string segment = item.ToLower().TrimEnd('/');
                    if (!flag)
                    {
                        if (segment == "wiki")
                        {
                            flag = true;
                        }
                    }
                    else
                    {
                        builder.Append(segment);
                        builder.Append("\\");
                    }
                }

                string path = HttpUtility.UrlDecode(builder.ToString().TrimEnd('\\'));
                //string root = SystemSettings.ReadString("FilePath", "");
                FilePaths filePaths = new FilePaths(TSAuthentication.GetLoginUser());
                filePaths.LoadByID(1);
                string   root     = filePaths[0].Value;
                string   fileName = Path.Combine(root, path);
                FileInfo info     = new FileInfo(fileName);
                context.Response.ContentType = DataUtils.MimeTypeFromFileName(fileName);
                context.Response.AddHeader("Content-Length", info.Length.ToString());
                context.Response.WriteFile(fileName);

                //bool allowAttachmentViewing = false;
                //int organizationId = 0;

                ////See above for how the Wiki url is supposed to look like, based on that the following check of the Segments
                //if (context.Request.Url.Segments.Any()
                //	&& context.Request.Url.Segments.Length > 3
                //	&& int.TryParse(context.Request.Url.Segments[3].TrimEnd('/'), out organizationId))
                //{
                //	Organization organization = Organizations.GetOrganization(LoginUser.Anonymous, organizationId);
                //	allowAttachmentViewing = organizationId == TSAuthentication.OrganizationID || organization.AllowUnsecureAttachmentViewing;
                //}

                //if (allowAttachmentViewing)
                //{
                //	string path = HttpUtility.UrlDecode(builder.ToString().TrimEnd('\\'));
                //	string root = SystemSettings.ReadString("FilePath", "");
                //	string fileName = Path.Combine(root, path);
                //	FileInfo info = new FileInfo(fileName);
                //	context.Response.ContentType = DataUtils.MimeTypeFromFileName(fileName);
                //	context.Response.AddHeader("Content-Length", info.Length.ToString());
                //	context.Response.WriteFile(fileName);
                //}
                //else
                //{
                //	context.Response.Write("Unauthorized");
                //	context.Response.ContentType = "text/html";
                //	return;
                //}
            }
            catch (Exception ex)
            {
                context.Response.ContentType = "text/html";
                context.Response.Write(ex.Message + "<br />" + ex.StackTrace);
            }
            context.Response.End();
        }