using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using System.Globalization; namespace Repository { /// ///

Displays archive list and allows publishing/unpublishing.
/// Calls RepoArchs.

/// Methods created or modified: ///

Copyright (c) 2002 Alexis Grandemange
/// Mail: alexis.grandemange@pagebox.net

///
This program is free software; you can redistribute it and/or
	/// modify it under the terms of the GNU Lesser General Public
	/// License as published by the Free Software Foundation; version
	/// 2.1 of the License.
	/// This library is distributed in the hope that it will be useful,
	/// but WITHOUT ANY WARRANTY; without even the implied warranty of
	/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	/// GNU Lesser General Public License for more details.
	/// A copy of the GNU Lesser General Public License lesser.txt should be
	/// included in the distribution.
///
public class publisher : System.Web.UI.Page { protected System.Web.UI.WebControls.HyperLink logo; protected System.Web.UI.WebControls.DataGrid archiveDB; protected System.Web.UI.HtmlControls.HtmlInputFile archFile; protected System.Web.UI.HtmlControls.HtmlInputButton btnUpload; protected System.Web.UI.HtmlControls.HtmlInputText docURL; protected System.Web.UI.WebControls.Label LabStatus; protected System.Web.UI.HtmlControls.HtmlInputButton btnRefresh; protected System.Web.UI.WebControls.Label PublisherLab; protected System.Web.UI.WebControls.HyperLink Support; public publisher() { Page.Init += new System.EventHandler(Page_Init); } /// /// Called on Page load event. /// Builds a list of archives and binds it to archiveDB (DataGrid). /// private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) bind(); } private void bind() { string user = User.Identity.Name; bool isAdministrator = false; bool isPublisher = false; if (User.Identity.IsAuthenticated) { isAdministrator = Global.archRep.isAdministrator(user); isPublisher = Global.archRep.isPublisher(user); if (!isAdministrator && !isPublisher) { LabStatus.Text = "You are not allowed to publish archives"; return; } } ArrayList al = new ArrayList(); IDictionaryEnumerator ide = Global.archRep.archives.GetEnumerator(); while(ide.MoveNext()) { string owner = (string)ide.Value; if (User.Identity.IsAuthenticated && isPublisher) { if (!user.Equals(owner)) continue; } string arch = (string)ide.Key; string doc = (string)Global.archRep.docs[arch]; string size = "-1"; DateTime dt = new DateTime(0L); if (File.Exists(Global.archRep.downloadPath + arch)) { dt = File.GetLastWriteTime(Global.archRep.downloadPath + arch); FileStream fs = File.Open(Global.archRep.downloadPath + arch, FileMode.Open, FileAccess.Read); size = "" + fs.Length; fs.Close(); } al.Add(new PublisherEntry(arch, dt.ToString("u", DateTimeFormatInfo.InvariantInfo), owner, doc, size)); } archiveDB.DataSource = al; archiveDB.DataBind(); } /// /// Called on archUpload event. Publishes an archive. /// public void archUpload(object sender, EventArgs e) { string owner = User.Identity.Name; string arch = archFile.PostedFile.FileName; string host = Request.ServerVariables["REMOTE_HOST"]; if (User.Identity.IsAuthenticated) { if (!Global.archRep.isAdministrator(owner) && !Global.archRep.isPublisher(owner)) { LabStatus.Text = "You are not allowed to publish archives"; Log.write(owner, host, "publish(" + arch + ") returned " + LabStatus.Text); return; } } int pos = arch.LastIndexOf("\\"); arch = arch.Substring(pos + 1); if (Global.archRep.archives.Contains(arch)) { string o = (string)Global.archRep.archives[arch]; if (!o.Equals(owner)) { LabStatus.Text = arch + " already exists and doesn't belongs to you"; Log.write(owner, host, "publish(" + arch + ") returned " + LabStatus.Text); return; } } if (!Directory.Exists(Global.archRep.downloadPath)) Directory.CreateDirectory(Global.archRep.downloadPath); archFile.PostedFile.SaveAs(Global.archRep.downloadPath + arch); LabStatus.Text = Global.archRep.add(owner, host, arch, owner, docURL.Value); Log.write(owner, host, "publish(" + arch + ") returned " + LabStatus.Text); bind(); } /// /// Called on refresh event. Refresh archive display. /// public void refresh(object sender, EventArgs e) { LabStatus.Text = ""; bind(); } private void Page_Init(object sender, EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); } #region Web Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.archiveDB.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.archiveDB_delete); this.Load += new System.EventHandler(this.Page_Load); } #endregion /// /// Called on archiveDB_delete event. Unpublishes an archive. /// No need to check authorization: if the user came here, it was allowed to display archives. /// private void archiveDB_delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int sel = e.Item.ItemIndex; if (sel != -1) { string arch = (string)archiveDB.DataKeys[sel]; string host = Request.ServerVariables["REMOTE_HOST"]; Button b = (Button)e.CommandSource; if (b.CommandName.Equals("delete")) LabStatus.Text = Global.archRep.delete(User.Identity.Name, host, arch, false); else LabStatus.Text = Global.archRep.delete(User.Identity.Name, host, arch, true); Log.write(User.Identity.Name, host, "unpublish(" + arch + ") returned " + LabStatus.Text); bind(); } } } /// /// Describes an archive. Element of the archive list. /// public sealed class PublisherEntry { /// /// Archive name. /// private string archive; /// /// Archive last modified time. /// private string date; /// /// User who published the archive. /// private string owner; /// /// URL of the archive documentation. /// private string doc; /// /// Size of the archive. /// private string size; /// /// Constructor. /// /// Archive name /// Archive last modified time /// User who published the archive /// URL of the archive documentation /// Size of the archive public PublisherEntry(string a, string t, string o, string d, string s) { archive = a; date = t; owner = o; doc = d; size = s; } /// Archive name public string Archive { get { return archive; } } /// Archive last modified time public string Date { get { return date; } } /// User who published the archive public string Owner { get { return owner; } } /// URL of the archive documentation public string Documentation { get { return doc; } } /// Size of the archive public string Size { get { return size; } } } }