public ActionResult Download(Guid id, string encodedName, string encodedPath)
        {
            var name = PathEncoder.Decode(encodedName);
            var path = PathEncoder.Decode(encodedPath);

            //Response.BufferOutput = false;
            //Response.Charset = "";
            Response.ContentType = "application/zip";

            var    repo        = RepositoryRepository.GetRepository(id);
            string headerValue = ContentDispositionUtil.GetHeaderValue((name ?? repo.Name) + ".zip");

            Response.Headers.Add("Content-Disposition", headerValue);

            using (var outputZip = new ZipFile())
            {
                outputZip.UseZip64WhenSaving     = Zip64Option.Always;
                outputZip.AlternateEncodingUsage = ZipOption.AsNecessary;
                outputZip.AlternateEncoding      = Encoding.Unicode;

                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
                {
                    AddTreeToZip(browser, name, path, outputZip);
                }

                outputZip.Save(Response.Body);

                return(new EmptyResult());
            }
        }
Пример #2
0
        public ActionResult Download(string id, string encodedName, string encodedPath)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(HttpNotFound());
            }

            var name = PathEncoder.Decode(encodedName);
            var path = PathEncoder.Decode(encodedPath);

            Response.BufferOutput = false;
            Response.Charset      = "";
            Response.ContentType  = "application/zip";

            string headerValue = ContentDispositionUtil.GetHeaderValue((name ?? id) + ".zip");

            Response.AddHeader("Content-Disposition", headerValue);

            using (var outputZip = new ZipFile())
            {
                outputZip.UseZip64WhenSaving     = Zip64Option.Always;
                outputZip.AlternateEncodingUsage = ZipOption.AsNecessary;
                outputZip.AlternateEncoding      = Encoding.Unicode;

                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
                {
                    AddTreeToZip(browser, name, path, outputZip);
                }

                outputZip.Save(Response.OutputStream);

                return(new EmptyResult());
            }
        }
Пример #3
0
        public ActionResult Commits(Guid id, string encodedName, int?page = null)
        {
            page = page >= 1 ? page : 1;

            ViewBag.ID = id;
            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                string referenceName;
                int    totalCount;
                var    commits = browser.GetCommits(name, page.Value, 10, out referenceName, out totalCount);
                PopulateBranchesData(browser, referenceName);
                ViewBag.TotalCount = totalCount;

                var linksreg = repo.LinksUseGlobal ? UserConfiguration.Current.LinksRegex : repo.LinksRegex;
                var linksurl = repo.LinksUseGlobal ? UserConfiguration.Current.LinksUrl : repo.LinksUrl;
                foreach (var commit in commits)
                {
                    var links = new List <string>();
                    if (!string.IsNullOrEmpty(linksreg))
                    {
                        try
                        {
                            var matches = Regex.Matches(commit.Message, linksreg);
                            if (matches.Count > 0)
                            {
                                foreach (Match match in matches)
                                {
                                    IEnumerable <Group> groups = match.Groups.Cast <Group>();
                                    var link = "";
                                    try
                                    {
                                        var m = groups.Select(x => x.ToString()).ToArray();
                                        link = string.Format(linksurl, m);
                                    }
                                    catch (FormatException e)
                                    {
                                        link = "An error occured while trying to format the link. Exception: " + e.Message;
                                    }
                                    links.Add(link);
                                }
                            }
                        }
                        catch (ArgumentException e)
                        {
                            links.Add("An error occured while trying to match the regualar expression. Error: " + e.Message);
                        }
                    }
                    commit.Links = links;
                }
                return(View(new RepositoryCommitsModel {
                    Commits = commits,
                    Name = repo.Name,
                    Logo = new RepositoryLogoDetailModel(repo.Logo)
                }));
            }
        }
Пример #4
0
        public ActionResult Tags(Guid id, string encodedName, int page = 1)
        {
            page = page >= 1 ? page : 1;


            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            ViewBag.ID     = id;
            ViewBag.Name   = repo.Name;
            ViewBag.GitUrl = GitUrl(repo.Name);
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                string referenceName;
                int    totalCount;
                var    commits = browser.GetTags(name, page, 10, out referenceName, out totalCount);
                PopulateBranchesData(browser, referenceName);
                ViewBag.TotalCount = totalCount;
                return(View(new RepositoryCommitsModel
                {
                    Commits = commits,
                    Name = repo.Name,
                    Logo = new RepositoryLogoDetailModel(repo.Logo)
                }));
            }
        }
Пример #5
0
        public ActionResult Raw(Guid id, string encodedName, string encodedPath, bool display = false)
        {
            ViewBag.ID = id;

            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                var    path = PathEncoder.Decode(encodedPath);
                string referenceName;
                var    model = browser.BrowseBlob(name, path, out referenceName);

                if (!display)
                {
                    return(File(model.Data, "application/octet-stream", model.Name));
                }
                if (model.IsText)
                {
                    return(Content(model.Text, "text/plain", model.Encoding));
                }
                if (model.IsImage)
                {
                    return(File(model.Data, MimeTypeMap.GetMimeType(Path.GetExtension(model.Name.ToLower())), model.Name));
                }
            }

            return(HttpNotFound());
        }
Пример #6
0
        public ActionResult Raw(string id, string encodedName, string encodedPath, bool display = false)
        {
            ViewBag.ID = id;
            if (String.IsNullOrEmpty(id))
            {
                return(HttpNotFound());
            }

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
            {
                var    name = PathEncoder.Decode(encodedName);
                var    path = PathEncoder.Decode(encodedPath);
                string referenceName;
                var    model = browser.BrowseBlob(name, path, out referenceName);

                if (!display)
                {
                    return(File(model.Data, "application/octet-stream", model.Name));
                }
                if (model.IsText)
                {
                    return(Content(model.Text, "text/plain", model.Encoding));
                }
                if (model.IsImage)
                {
                    return(File(model.Data, FileDisplayHandler.GetMimeType(model.Name), model.Name));
                }
            }

            return(HttpNotFound());
        }
        public ActionResult Tree(string id, string encodedName, string encodedPath)
        {
            ViewBag.ID = id;
            if (!String.IsNullOrEmpty(id))
            {
                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
                {
                    var    name = PathEncoder.Decode(encodedName);
                    var    path = PathEncoder.Decode(encodedPath);
                    string referenceName;
                    var    files = browser.BrowseTree(name, path, out referenceName);
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(name, path);

                    var model = new RepositoryTreeModel();
                    model.Name   = id;
                    model.Branch = name;
                    model.Path   = path;
                    model.Files  = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name);
                    return(View(model));
                }
            }

            return(View());
        }
Пример #8
0
        private static void AssertEncodeUsesOnlyIntendedCharacters(string input)
        {
            var encodedInput = PathEncoder.Encode(input);

            Assert.IsTrue(Rfc3986UnreservedCharacters.IsMatch(encodedInput ?? ""));
            encodedInput = PathEncoder.Encode(input, allowSlash: true);
            Assert.IsTrue(Rfc3986UnreservedCharactersAndSlash.IsMatch(encodedInput ?? ""));
            encodedInput = PathEncoder.Encode(input, allowSlash: false);
            Assert.IsTrue(Rfc3986UnreservedCharacters.IsMatch(encodedInput ?? ""));
        }
Пример #9
0
        private static void AssertDecodeOfEncodeMatches(string input)
        {
            var encodedInput = PathEncoder.Encode(input);

            Assert.AreEqual(input, PathEncoder.Decode(encodedInput));
            encodedInput = PathEncoder.Encode(input, allowSlash: true);
            Assert.AreEqual(input, PathEncoder.Decode(encodedInput));
            encodedInput = PathEncoder.Encode(input, allowSlash: false);
            Assert.AreEqual(input, PathEncoder.Decode(encodedInput));
        }
Пример #10
0
        /// <inheritdoc />
        public Task <string> GetOpenUrl(BuildSourceType buildSourceType, string buildLocation)
        {
            string path = PathEncoder.GetEncoded(buildLocation);

            string result = settings.BaseUrlsToOpenBuilds.TryGetValue(buildSourceType, out string baseUrl)
                ? Path.Combine(baseUrl, path)
                : throw new NotSupportedException($"Не удалось найти базовый путь для {buildSourceType:G}");

            return(Task.FromResult(result));
        }
Пример #11
0
        private static void AssertUrlDecodeDoesNotChange(string input)
        {
            var encodedInput = PathEncoder.Encode(input);
            var urlString    = "http://localhost/" + encodedInput;

            Assert.AreEqual(urlString, HttpUtility.UrlDecode(urlString));
            encodedInput = PathEncoder.Encode(input, allowSlash: true);
            urlString    = "http://localhost/" + encodedInput;
            Assert.AreEqual(urlString, HttpUtility.UrlDecode(urlString));
            encodedInput = PathEncoder.Encode(input, allowSlash: false);
            urlString    = "http://localhost/" + encodedInput;
            Assert.AreEqual(urlString, HttpUtility.UrlDecode(urlString));
        }
Пример #12
0
        public ActionResult Tree(Guid id, string encodedName, string encodedPath)
        {
            bool includeDetails = Request.IsAjaxRequest();


            var name = PathEncoder.Decode(encodedName);
            var path = PathEncoder.Decode(encodedPath);

            var repo = RepositoryRepository.GetRepository(id);
            var repositoryDetailModel = ConvertRepositoryModel(repo, User);

            ViewBag.ID     = id;
            ViewBag.Name   = repo.Name;
            ViewBag.GitUrl = GitUrl(repo.Name);
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                string referenceName;
                var    files = browser.BrowseTree(name, path, out referenceName, includeDetails).ToList();

                var    readme    = files.FirstOrDefault(x => x.Name.Equals("readme.md", StringComparison.OrdinalIgnoreCase));
                string readmeTxt = string.Empty;
                if (readme != null)
                {
                    string refereceName;
                    var    blob = browser.BrowseBlob(name, readme.Path, out refereceName);
                    readmeTxt = blob.Text;
                }
                var model = new RepositoryTreeModel
                {
                    Name   = repo.Name,
                    Branch = name ?? referenceName,
                    Path   = path,
                    Readme = readmeTxt,
                    Logo   = new RepositoryLogoDetailModel(repo.Logo),
                    Files  = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name)
                };

                if (includeDetails)
                {
                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(path);
                    return(View(model));
                }
            }
        }
Пример #13
0
        private IEnumerable <string> GetSelectedPaths()
        {
            foreach (var item in this.listView.SelectedResults)
            {
                foreach (var path in item.Paths.OrderBy(p => p, PathComparer.Instance))
                {
                    if (File.Exists(PathEncoder.ExtendPath(path)))
                    {
                        yield return(path);

                        break;
                    }
                }
            }
        }
        public ActionResult Commits(string id, string encodedName)
        {
            ViewBag.ID = id;
            if (!String.IsNullOrEmpty(id))
            {
                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
                {
                    var name = PathEncoder.Decode(encodedName);
                    string referenceName;
                    var commits = browser.GetCommits(name, out referenceName);
                    PopulateBranchesData(browser, referenceName);
                    return View(new RepositoryCommitsModel { Commits = commits, Name = id });
                }
            }

            return View();
        }
Пример #15
0
        public ActionResult History(Guid id, string encodedPath, string encodedName)
        {
            ViewBag.ID = id;
            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    path = PathEncoder.Decode(encodedPath);
                var    name = PathEncoder.Decode(encodedName);
                string referenceName;
                var    commits = browser.GetHistory(path, name, out referenceName);
                return(View(new RepositoryCommitsModel {
                    Commits = commits, Name = repo.Name
                }));
            }
        }
Пример #16
0
        public ActionResult Blob(Guid id, string encodedName, string encodedPath)
        {
            ViewBag.ID = id;
            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                var    path = PathEncoder.Decode(encodedPath);
                string referenceName;
                var    model = browser.BrowseBlob(name, path, out referenceName);
                PopulateBranchesData(browser, referenceName);
                PopulateAddressBarData(path);

                return(View(model));
            }
        }
Пример #17
0
        public ActionResult Blob(string id, string encodedName, string encodedPath)
        {
            ViewBag.ID = id;
            if (!String.IsNullOrEmpty(id))
            {
                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
                {
                    var    name = PathEncoder.Decode(encodedName);
                    var    path = PathEncoder.Decode(encodedPath);
                    string referenceName;
                    var    model = browser.BrowseBlob(name, path, out referenceName);
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(name, path);

                    return(View(model));
                }
            }
            return(View());
        }
Пример #18
0
        public ActionResult History(string id, string encodedPath, string encodedName)
        {
            ViewBag.ID = id;
            if (!String.IsNullOrEmpty(id))
            {
                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
                {
                    var    path = PathEncoder.Decode(encodedPath);
                    var    name = PathEncoder.Decode(encodedName);
                    string referenceName;
                    var    commits = browser.GetHistory(path, name, out referenceName);
                    return(View(new RepositoryCommitsModel {
                        Commits = commits, Name = id
                    }));
                }
            }

            return(View());
        }
Пример #19
0
        public ActionResult Blame(Guid id, string encodedName, string encodedPath)
        {
            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            ViewBag.ID     = id;
            ViewBag.Name   = repo.Name;
            ViewBag.GitUrl = GitUrl(repo.Name);
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                var    path = PathEncoder.Decode(encodedPath);
                string referenceName;
                var    model = browser.GetBlame(name, path, out referenceName);
                model.Logo = new RepositoryLogoDetailModel(repo.Logo);
                PopulateBranchesData(browser, referenceName);
                PopulateAddressBarData(path);

                return(View(model));
            }
        }
Пример #20
0
        public ActionResult Tree(string id, string encodedName, string encodedPath)
        {
            bool includeDetails = Request.IsAjaxRequest();

            if (String.IsNullOrEmpty(id))
            {
                return(View());
            }

            ViewBag.ID = id;
            var name = PathEncoder.Decode(encodedName);
            var path = PathEncoder.Decode(encodedPath);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
            {
                string referenceName;
                var    files = browser.BrowseTree(name, path, out referenceName, includeDetails);

                var model = new RepositoryTreeModel
                {
                    Name   = id,
                    Branch = name,
                    Path   = path,
                    Files  = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name),
                };

                if (includeDetails)
                {
                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(name, path);
                    return(View(model));
                }
            }
        }
Пример #21
0
        // Before 6.0.0 the mapping was done via the name property. After that the Guid is used.
        public static void UpdateADBackend()
        {
            // Make a copy of the current backendfolder if it exists, so we can use the modern models for saving
            // it all to the correct location directly
            var backendDirectory = PathEncoder.GetRootPath(ActiveDirectorySettings.BackendPath);
            var backupDirectory  = PathEncoder.GetRootPath(ActiveDirectorySettings.BackendPath + "_pre6.0.0_" + DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"));

            if (Directory.Exists(backendDirectory) && BackEndNeedsUpgrade(backendDirectory))
            {
                MakeBackupOfBackendDirectory(backendDirectory, backupDirectory);

                // We must create one that will not automatically update the items while we update them
                ADBackend.ResetSingletonWithoutAutomaticUpdate();

                var newUsers = UpdateUsers(Path.Combine(backupDirectory, "Users"));
                var newTeams = UpdateTeams(Path.Combine(backupDirectory, "Teams"), newUsers);
                UpdateRoles(Path.Combine(backupDirectory, "Roles"), newUsers);
                UpdateRepos(Path.Combine(backupDirectory, "Repos"), newUsers, newTeams);

                // We are done, enable automatic update again.
                ADBackend.ResetSingletonWithAutomaticUpdate();
            }
        }
Пример #22
0
        public ActionResult Detail(Guid id)
        {
            var mater = ConvertRepositoryModel(RepositoryRepository.GetRepository(id), User);

            if (mater != null)
            {
                mater.IsCurrentUserAdministrator = RepositoryPermissionService.HasPermission(User.Id(), mater.Id, RepositoryAccessLevel.Administer);
                SetGitUrls(mater);
            }
            ViewBag.ID     = id;
            ViewBag.Name   = mater.Name;
            ViewBag.GitUrl = mater.GitUrl;

            //using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, model.Name)))
            //{
            //    string defaultReferenceName;
            //    browser.BrowseTree(null, null, out defaultReferenceName);
            //    RouteData.Values.Add("encodedName", defaultReferenceName);
            //}
            bool includeDetails = Request.IsAjaxRequest();


            var name = PathEncoder.Decode(null);
            var path = PathEncoder.Decode(null);

            var repo = RepositoryRepository.GetRepository(id);
            var repositoryDetailModel = ConvertRepositoryModel(repo, User);


            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                string referenceName;
                var    files = browser.BrowseTree(name, path, out referenceName, includeDetails).ToList();
                PopulateBranchesData(browser, referenceName);
                var    readme    = files.FirstOrDefault(x => x.Name.Equals("readme.md", StringComparison.OrdinalIgnoreCase));
                string readmeTxt = string.Empty;
                if (readme != null)
                {
                    string refereceName;
                    var    blob = browser.BrowseBlob(name, readme.Path, out refereceName);
                    readmeTxt = blob.Text;
                }
                var model = new RepositoryTreeModel
                {
                    Name   = repo.Name,
                    Branch = name ?? referenceName,
                    Path   = path,
                    Readme = readmeTxt,
                    Logo   = new RepositoryLogoDetailModel(repo.Logo),
                    Files  = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name)
                };

                if (includeDetails)
                {
                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(path);
                    return(View(model));
                }
            }
        }
Пример #23
0
 public void MissingBothNibbles()
 {
     PathEncoder.Decode("~");
 }
Пример #24
0
 public void BadNibbleValues()
 {
     PathEncoder.Decode("~no");
 }
Пример #25
0
        public void DoubleEncodeDecode()
        {
            var input = GetStringCharacterRange(30, 126); // Printable characters

            Assert.AreEqual(input, PathEncoder.Decode(PathEncoder.Decode(PathEncoder.Encode(PathEncoder.Encode(input)))));
        }
Пример #26
0
 public void SlashEncodedByDefault()
 {
     Assert.AreEqual(0, PathEncoder.Encode("abc/def/ghi").Where(c => '/' == c).Count());
 }
Пример #27
0
 public void AllowSlashTrue()
 {
     Assert.AreEqual(2, PathEncoder.Encode("abc/def/ghi", allowSlash: true).Where(c => '/' == c).Count());
 }
Пример #28
0
 public void AllowSlashFalse()
 {
     Assert.AreEqual(0, PathEncoder.Encode("abc/def/ghi", allowSlash: false).Where(c => '/' == c).Count());
 }
Пример #29
0
 public void NonByteCharacterInput()
 {
     PathEncoder.Decode("\u0394");
 }
Пример #30
0
 public void MissingNoNibbles()
 {
     Assert.AreEqual("\0", PathEncoder.Decode("~00"));
 }