Esempio n. 1
0
        private void DownloadRevisionLog(int revision_id, bool diff /* diff or log */)
        {
            DBRevision revision;
            DBLane     lane;

            using (DB db = new DB()) {
                WebServiceLogin login = Authentication.CreateLogin(Request);

                revision = DBRevision_Extensions.Create(db, revision_id);

                // no access restricion on revision logs/diffs
                Authentication.VerifyAnonymousAccess(Context, db, login);

                Response.ContentType = MimeTypes.TXT;

                if (revision == null)
                {
                    Response.Write("Revision not found.");
                }
                else
                {
                    lane = DBLane_Extensions.Create(db, revision.lane_id);
                    using (Process git = new Process()) {
                        git.StartInfo.RedirectStandardOutput = true;
                        git.StartInfo.RedirectStandardError  = true;
                        git.StartInfo.UseShellExecute        = false;
                        git.StartInfo.FileName = "git";
                        if (diff)
                        {
                            git.StartInfo.Arguments = "diff --no-color --no-prefix " + revision.revision + "~ " + revision.revision;
                        }
                        else
                        {
                            git.StartInfo.Arguments = "log -1 --no-color --no-prefix " + revision.revision;
                        }
                        git.StartInfo.WorkingDirectory = Configuration.GetSchedulerRepositoryCacheDirectory(lane.repository);
                        git.OutputDataReceived        += (object sender, DataReceivedEventArgs ea) =>
                        {
                            Response.Write(ea.Data);
                            Response.Write('\n');
                        };
                        git.ErrorDataReceived += (object sender, DataReceivedEventArgs ea) =>
                        {
                            Response.Write(ea.Data);
                            Response.Write('\n');
                        };
                        // Logger.Log ("Executing: '{0} {1}' in {2}", git.StartInfo.FileName, git.StartInfo.Arguments, git.StartInfo.WorkingDirectory);
                        git.Start();
                        git.BeginErrorReadLine();
                        git.BeginOutputReadLine();
                        if (!git.WaitForExit(1000 * 60 * 5 /* 5 minutes */))
                        {
                            git.Kill();
                            Response.Write("Error: git diff didn't finish in 5 minutes, aborting.\n");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            var login = Authentication.CreateLogin(context.Request);

            using (var db = new DB())
                Authentication.VerifyUserInRole(context, db, login, Roles.Administrator, @readonly: true);

            var slot = new ObserverSlot(context, cb, extraData);

            lock (slots)
                slots.Add(slot);
            return(slot);
        }
Esempio n. 3
0
        private void DownloadNamedWorkFile(int work_id, string filename)
        {
            DBWorkFileView view = null;
            DBFile         file = null;
            string         compressed_mime;

            using (DB db = new DB()) {
                WebServiceLogin login = Authentication.CreateLogin(Request);

                view = DBWorkFileView_Extensions.Find(db, work_id, filename);

                if (view == null)
                {
                    throw new HttpException(404, "Could not find the file.");
                }

                if (view.@internal)                 // internal files need admin rights
                {
                    Authentication.VerifyUserInRole(Context, db, login, Roles.Administrator, false);
                }
                else
                {
                    Authentication.VerifyAnonymousAccess(Context, db, login);
                }

                file = DBWork_Extensions.GetFile(db, view.work_id, filename, false);
                if (file == null)
                {
                    throw new HttpException(404, string.Format("Could not find the filename '{0}'", filename));
                }

                compressed_mime = file.compressed_mime;

                Response.ContentType = file.mime;
                Response.AppendHeader("Content-Disposition", "filename=\"" + Path.GetFileName(filename) + "\"");

                if (view.file_file_id == null)
                {
                    DownloadMd5(view.md5);
                }
                else
                {
                    using (Stream str = db.Download(view)) {
                        DownloadStream(str, compressed_mime);
                    }
                }
            }
        }
Esempio n. 4
0
        private void DownloadWorkFile(int workfile_id, string md5)
        {
            DBWorkFileView view = null;
            DBFile         file = null;
            string         filename;
            string         mime;
            string         compressed_mime;

            using (DB db = new DB()) {
                WebServiceLogin login = Authentication.CreateLogin(Request);

                filename = Request ["filename"];

                if (!string.IsNullOrEmpty(md5))                    // md5 lookup needs admin rights
                {
                    Authentication.VerifyUserInRole(Context, db, login, Roles.Administrator, false);
                    file = DBFile_Extensions.Find(db, md5);

                    if (file == null)
                    {
                        throw new HttpException(404, "Could not find the file.");
                    }

                    mime            = file.mime;
                    filename        = file.filename;
                    compressed_mime = file.compressed_mime;
                }
                else
                {
                    view = DBWorkFileView_Extensions.Find(db, workfile_id);

                    if (view == null)
                    {
                        throw new HttpException(404, "Could not find the file.");
                    }

                    if (view.@internal)                     // internal files need admin rights
                    {
                        Authentication.VerifyUserInRole(Context, db, login, Roles.Administrator, false);
                    }
                    else
                    {
                        Authentication.VerifyAnonymousAccess(Context, db, login);
                    }

                    if (!string.IsNullOrEmpty(filename))
                    {
                        file = DBWork_Extensions.GetFile(db, view.work_id, filename, false);
                        if (file == null)
                        {
                            throw new HttpException(404, string.Format("Could not find the filename '{0}'", filename));
                        }

                        mime            = file.mime;
                        compressed_mime = file.compressed_mime;
                        md5             = file.md5;

                        view = null;
                    }
                    else
                    {
                        mime            = view.mime;
                        filename        = view.filename;
                        compressed_mime = view.compressed_mime;
                    }
                }

                Response.ContentType = mime;
                Response.AppendHeader("Content-Disposition", "filename=\"" + Path.GetFileName(filename) + "\"");

                // any access rights verified, serve the file

                if (view != null)
                {
                    if (view.file_file_id == null)
                    {
                        DownloadMd5(view.md5);
                    }
                    else
                    {
                        using (Stream str = db.Download(view)) {
                            DownloadStream(str, compressed_mime);
                        }
                    }
                }
                else
                {
                    DownloadFile(db, file);
                }
            }
        }