Beispiel #1
0
        public ArchivedDirectory(ArchiveSite site, DirectoryInfo dir) : base(site)
        {
            subDirs   = new List <ArchivedDirectory>();
            subFiles  = new List <ArchivedFile>();
            this.info = dir;

            //Load the metadata if it has some. If it doesn't create it
            if (File.Exists(dir.FullName + "/INFO.dirmeta"))
            {
                metadata = JsonConvert.DeserializeObject <ArchivedDirectoryMetadata>(File.ReadAllText(dir.FullName + "/INFO.dirmeta"));
            }
            else
            {
                throw new Exception("No info found for dir!");
            }
            uploadedDate = new FileInfo(dir.FullName + "/INFO.dirmeta").LastWriteTimeUtc;

            //Load the custom footer, if any
            if (File.Exists(dir.FullName + "/FOOTER.dirmeta"))
            {
                footer = File.ReadAllText(dir.FullName + "/FOOTER.dirmeta");
            }
            else
            {
                footer = "";
            }

            //Set rich metadata
            rich_metadata_status = MetadataStatus.NO_METADATA;
        }
        public static async Task OnSignoutRequest(ArchiveSite site, HttpContext e)
        {
            //Clear token
            site.activeToken = null;

            //Return
            RedirectBack(site, e);
        }
Beispiel #3
0
        public static ArchivedDirectory GetRootDirectory(ArchiveSite site, string dirPathname)
        {
            ArchivedDirectory d = new ArchivedDirectory(site, new DirectoryInfo(dirPathname));

            d.path = "/";
            d.SeekSubObjects();
            d.isRoot = true;
            site.AddStoredObject(d);
            return(d);
        }
 private static bool AuthenticateForm(ArchiveSite site, IFormCollection form)
 {
     if (!form.ContainsKey("key"))
     {
         return(false);
     }
     if (site.config.admin_key == null)
     {
         return(false);
     }
     return(site.config.admin_key == form["key"]);
 }
        public static void RedirectBack(ArchiveSite site, HttpContext e, string overridePath = null)
        {
            string returnPath = site.config.client_pathname_prefix;

            if (e.Request.Headers.ContainsKey("Referer"))
            {
                returnPath = e.Request.Headers["Referer"];
            }
            if (overridePath != null)
            {
                returnPath = overridePath;
            }
            e.Response.Redirect(returnPath, false);
        }
Beispiel #6
0
        /// <summary>
        /// Enregistre le commencement de la modification du catalogue du site.
        /// </summary>
        /// <param name="site"></param>
        /// <returns></returns>
        public async Task <RetourDeService <ArchiveSite> > CommenceEtatCatalogue(Site site)
        {
            site.Ouvert = false;
            _context.Site.Update(site);
            // ajout de l'archive
            ArchiveSite archive = new ArchiveSite
            {
                Id     = site.Id,
                Ouvert = false,
                Date   = DateTime.Now
            };

            _context.ArchiveSite.Add(archive);

            return(await SaveChangesAsync(archive));
        }
        public static async Task OnLoginRequest(ArchiveSite site, HttpContext e)
        {
            if (e.Request.Method == "GET")
            {
                //Write form
                e.Response.ContentType = "text/html";
                await e.WriteString($"<u>Sign in</u><br><br><form method=\"post\"><textarea id=\"key\" name=\"key\" placeholder=\"Key\" rows=\"4\" cols=\"80\"></textarea><br><br><input type=\"hidden\" value=\"{e.Request.Headers["referer"]}\" id=\"return\" name=\"return\" /><input type=\"submit\" value=\"Sign In\"></form>");
            }
            else
            {
                //Delay
                if (busy)
                {
                    //Multiple requests at once!
                    e.Response.ContentType = "text/html";
                    await e.WriteString("<span style=\"color: red;\">There is an ongoing login attempt. Please wait and try again.</span>");
                }
                busy = true;

                //Parse form
                var form = await e.Request.ReadFormAsync();

                if (AuthenticateForm(site, form))
                {
                    //Generate a token string
                    site.activeToken = GenerateSecureString(32, "1234567890ABCDEF".ToCharArray());

                    //Set it
                    e.Response.Cookies.Append(ArchiveSite.ADMIN_TOKEN_COOKIE, site.activeToken);

                    //Redirect
                    RedirectBack(site, e, form["return"]);
                }
                else
                {
                    //Failed
                    await Task.Delay(3000);

                    e.Response.ContentType = "text/html";
                    await e.WriteString("<span style=\"color: red;\">Could not log in. Please try again.</span>");
                }

                busy = false;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Enregistre la fin de la modification du catalogue du site.
        /// </summary>
        /// <param name="site"></param>
        /// <param name="dateCatalogue">présent si le catalogue a été modifié</param>
        /// <returns></returns>
        public async Task <RetourDeService <ArchiveSite> > TermineEtatCatalogue(Site site, DateTime?dateCatalogue)
        {
            site.Ouvert = true;
            if (dateCatalogue.HasValue)
            {
                site.DateCatalogue = dateCatalogue.Value;
            }
            _context.Site.Update(site);
            // ajout de l'archive
            ArchiveSite archive = new ArchiveSite
            {
                Id     = site.Id,
                Ouvert = true,
                Date   = dateCatalogue ?? DateTime.Now
            };

            _context.ArchiveSite.Add(archive);

            return(await SaveChangesAsync(archive));
        }
        public ArchivedFile(ArchiveSite site, ArchivedDirectory dir, string metadataFilePath) : base(site)
        {
            //Set
            this.parent           = dir;
            this.metadataFilePath = metadataFilePath;

            //Load metadata
            metadata = JsonConvert.DeserializeObject <ArchivedFileMetadata>(File.ReadAllText(metadataFilePath));

            //Get uploaded date
            if (metadata.uploaded_date.HasValue)
            {
                uploadedDate = metadata.uploaded_date.Value;
            }
            else
            {
                uploadedDate           = new FileInfo(metadataFilePath).LastWriteTimeUtc;
                metadata.uploaded_date = uploadedDate;
            }

            //Get file if it's not remote
            if (!metadata.is_remote)
            {
                file = new FileInfo(metadataFilePath.Substring(0, metadataFilePath.Length - 5)); //trim off .meta
            }
            //Create path
            path = dir.path + GetName();

            //Check if we have rich metadata
            if (metadata.rich_metadata == null)
            {
                rich_metadata_status = MetadataStatus.NOT_GENERATED;
            }
            else
            {
                rich_metadata_status = MetadataStatus.OK;
            }

            //Add
            this.site.AddStoredObject(this);
        }
 public ArchivedObject(ArchiveSite site)
 {
     this.site = site;
 }