Lookup() 공개 메소드

Get a setting as a string value; throw an exception if its not found
public Lookup ( string key ) : string
key string key
리턴 string
예제 #1
0
	/// <summary>
	/// Append a line to the applicable log file
	/// </summary>
	/// <param name="logEntry">line to add to log</param>
	public void LogAppend(string logEntry)
	{
		// use the timestamp captured when the object was created to identify the file
		string fname = LogFilename(timestamp);
		WebSettings ws = new WebSettings();

		// create a full path to the target log file
		string logpath = ws.Lookup("LogPath", HttpContext.Current.Server.MapPath("~/App_Data"));
		logpath = Path.Combine(logpath, fname);

		// append to the log file or create it if it doesn't exist
		if (!File.Exists(logpath))
		{
			using (StreamWriter sw = File.CreateText(logpath))
			{
				sw.WriteLine(logEntry);
			}
		}
		else
		{
			using (StreamWriter sw = File.AppendText(logpath))
			{
				sw.WriteLine(logEntry);
			}
		}
	}
예제 #2
0
	protected void Page_Load(object sender, EventArgs e)
	{
		NewAccountButton.Click += new EventHandler(NewAccountButton_Click);
		// this page requires an authenticated user
		Master.ForceAuthentication();

		// this page requires an authenticated administrator
		Master.ForceAdministrator();

		// create the configuration related objects
		webSettings = new WebSettings();
		fz = new Filezilla(webSettings.Lookup("ConfigurationFile"));

		// load the user grid display
		List<FilezillaUser> userList = new List<FilezillaUser>();
		int count = fz.AddUsersToList(ref userList);
		UserGridView.DataSource = userList;
		UserGridView.DataBind();

		DataSet ds = new DataSet();
		ds.ReadXml(MapPath("~/App_Data/settings.xml"));
		SettingsGridView.DataSource = ds.Tables[0].DefaultView;
		SettingsGridView.DataBind();

		if (!Page.IsPostBack)
		{
			UserGridView.SortBy(UserGridView.Columns["Username"], ColumnSortOrder.Ascending);
			UserGridView.SettingsPager.PageSize = 100;
			SettingsGridView.SortBy(SettingsGridView.Columns["key"], ColumnSortOrder.Ascending);
			SettingsGridView.SettingsPager.PageSize = 100;
		}
	}
예제 #3
0
	protected void Page_Load(object sender, EventArgs e)
	{
		// wire the events
		GeneratePasswordButton.Click += new EventHandler(GeneratePasswordButton_Click);
		ForcePasswordButton.Click += new EventHandler(ForcePasswordButton_Click);

		// this page requires an authenticated user
		Master.ForceAuthentication();

		// this page requires an authenticated administrator
		Master.ForceAdministrator();

		// get the target user from the query string
		userName = WebConvert.ToString(Request.QueryString["ID"], "");

		// create the configuration related objects
		webSettings = new WebSettings();
		fz = new Filezilla(webSettings.Lookup("ConfigurationFile"));

		// load the user object
		fzu = fz.GetUser(userName);

		if (!Page.IsPostBack)
		{
			// load the display with the user values
			UsernameTitleLiteral.Text = fzu.Username;
			UsernameLabel.Text = fzu.Username;
			PasswordLabel.Text = fzu.Password;
			EnabledLabel.Text = (fzu.Enabled) ? "Yes" : "No";
			HomeDirectoryLabel.Text = fzu.Home;

			// load the first permission
			FilezillaPermission fzp = fzu.Permissions[0];
			DirectoryLabel.Text = fzp.Dir;
			AliasPathLabel.Text = fzp.AliasPath;
			IsHomeLabel.Text = (fzp.OptionIsHome) ? "Yes" : "No";
			FilePermissionsLabel.Text = "";
			FilePermissionsLabel.Text += DisplayPermission("Read", fzp.OptionFileRead );
			FilePermissionsLabel.Text += DisplayPermission("Write", fzp.OptionFileWrite);
			FilePermissionsLabel.Text += DisplayPermission("Delete", fzp.OptionFileDelete);
			FilePermissionsLabel.Text += DisplayPermission("Append", fzp.OptionFileAppend);
			DirPermissionsLabel.Text = "";
			DirPermissionsLabel.Text += DisplayPermission("List", fzp.OptionDirList);
			DirPermissionsLabel.Text += DisplayPermission("Create", fzp.OptionDirCreate);
			DirPermissionsLabel.Text += DisplayPermission("Delete", fzp.OptionDirDelete);
			DirPermissionsLabel.Text += DisplayPermission("Subdirs", fzp.OptionDirSubdirs);
			AutoCreateLabel.Text = (fzp.OptionAutoCreate) ? "Yes" : "No";
		}
	}
예제 #4
0
	/// <summary>
	/// Load the master page components - customization based on this instance
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e)
    {
		WebSettings webSettings = new WebSettings();
		InstanceNameLabel.Text = webSettings.Lookup("InstanceName", "N/A");

		// update the footer with the running version number
		VersionLiteral.Text = WebVersion.Latest();

		// display the active user account
		AccountLiteral.Text = UserName;

		// turn the account panel on only if a user has authenticated
		AccountPanel.Visible = IsAuthenticated();

		// prefix the page title with the instance marker
		Page.Title = webSettings.Lookup("InstancePageTitle", "") + " FileZilla.NET by )|( Sanctuary Software Studio, Inc.";

		// check to see if SSL is required and redirect there if it is required
		if (WebConvert.ToBoolean(webSettings.Lookup("ForceSSL", "0"), false))
		{
			// verify that we are on a secure connection
			ForceSSL();
		}
    }
예제 #5
0
	protected void Page_Load(object sender, EventArgs e)
	{
		// access the settings
		settings = new WebSettings();
		
		if (!Page.IsPostBack)
		{
			string contactEmail = settings.Lookup("ContactEMail");
			// load the literals from the settings
			NeedAccountEmailLiteral.Text = "<a href=\"mailto:" + contactEmail + "\">" + contactEmail + "</a>";
			ForgetPasswordLiteral.Text = "<a href=\"mailto:" + contactEmail + "\">" + contactEmail + "</a>";
		}

		// Wire the events
		LoginButton.Click += new EventHandler(LoginButton_Click);

		// set the focus
		AccAccountTextBox.Focus();
	}
예제 #6
0
	/// <summary>
	/// Send an email message.
	/// </summary>
	/// <param name="subject">Subject text for the message</param>
	/// <param name="body">Body text for the message</param>
	/// <param name="recipients">A comma-delimited list of recipients that will receive the message</param>
	/// <returns>True if the email is sent; otherwise false.</returns>
	public static bool Send(string subject, string body, string recipients)
	{
		if (recipients.Length < 1)
		{
			return false;
		}

		WebSettings ws = new WebSettings();

		// Get the configured EMail infromation from the web config
		string EmailAccount = ws.Lookup("EmailAccount");
		string EmailPassword = ws.Lookup("EmailPassword");
		string EmailSender = ws.Lookup("EmailSender");
		string EmailReplyTo = ws.Lookup("EmailReplyTo");
		string EmailSenderName = ws.Lookup("EmailSenderName");
		string EmailServer = ws.Lookup("EmailServer");
		int EmailPort = WebConvert.ToInt32(ws.Lookup("EmailPort", "25"), 25);

		// make the credentials for connecting to the server
		NetworkCredential smtpuser = new NetworkCredential(EmailAccount, EmailPassword);

		// create the mail message
		MailMessage mail = new MailMessage();
		mail.From = new MailAddress(EmailSender, EmailSenderName);
		mail.To.Add(recipients);
		mail.ReplyToList.Add(new MailAddress(EmailReplyTo));
		mail.Sender = new MailAddress(EmailSender);
		mail.Subject = subject;
		mail.Body = body;
		mail.IsBodyHtml = false;

		// connect to the smtp client and send the message
		SmtpClient client = new SmtpClient(EmailServer);
		client.UseDefaultCredentials = false;
		client.Credentials = smtpuser;
		client.Port = EmailPort;
		client.Send(mail);

		return true;
	}
예제 #7
0
	/// <summary>
	/// Create a new user account
	/// </summary>
	/// <param name="username"></param>
	/// <param name="password"></param>
	/// <returns></returns>
	public bool CreateUser(string username, string password, bool enabled, bool fileRead, bool fileWrite, bool fileDelete, bool fileAppend, 
		bool dirCreate, bool dirDelete, bool dirList, bool dirSubdirs, bool autoCreate)
	{
		WebSettings ws = new WebSettings();

		try
		{
			// create the new user 
			FilezillaUser fzu = new FilezillaUser();
			fzu.Username = username;
			fzu.Password = password;
			fzu.Enabled = enabled;

			// define the user's home directory
			string homeDir = ws.Lookup("NewUserRoot") + "\\" + username;

			// create the directory if it doesn't already exist
			if (!System.IO.Directory.Exists(homeDir))
			{
				System.IO.Directory.CreateDirectory(homeDir);
			}

			// create the user's home directory permission
			FilezillaPermission fzp = new FilezillaPermission();
			fzp.Dir = homeDir;
			fzp.OptionIsHome = true;
			fzp.OptionFileRead = fileRead;
			fzp.OptionFileWrite = fileWrite;
			fzp.OptionFileDelete = fileDelete;
			fzp.OptionFileAppend = fileAppend;
			fzp.OptionDirCreate = dirCreate;
			fzp.OptionDirDelete = dirDelete;
			fzp.OptionDirList = dirList;
			fzp.OptionDirSubdirs = dirSubdirs;
			fzp.OptionAutoCreate = autoCreate;

			// add the home directory to the user8
			fzu.Permissions.Add(fzp);

			// look up the user in the configuration
			XmlNode usersNode = config.SelectSingleNode("/FileZillaServer/Users");
			XmlNode newUserNode = fzu.Create(config);
			usersNode.AppendChild(newUserNode);

			// notify the administrator
			AccountNotification("Create User", username, password);
		}
		catch (Exception)
		{
			return false;
		}
		return true;
	}
예제 #8
0
	/// <summary>
	/// Notify the system administration email address of account information
	/// </summary>
	/// <param name="action">action description</param>
	/// <param name="username">account</param>
	/// <param name="password">password (unencrypted)</param>
	/// <returns></returns>
	protected void AccountNotification(string action, string username, string password)
	{
		WebSettings ws = new WebSettings();

		string subject = "[FILEZILLA] Account Notification (" + username + ")";
		StringBuilder sb = new StringBuilder();

		sb.Append( "FileZilla account notification message for the system administrator:\n");
		sb.Append( "Action: " + action + "\n" );
		sb.Append( "Username: "******"\n");
		sb.Append( "Password: "******"\n");
		EMail.Send( subject, sb.ToString(), ws.Lookup( "EmailRecipients" ) );
	}
예제 #9
0
	/// <summary>
	/// Force the server to reload the configuration
	/// </summary>
	/// <returns>true if configuration reloaded</returns>
	public bool ForceServerConfigurationLoad()
	{
		WebSettings ws = new WebSettings();
		string serverExe = ws.Lookup("ServerExecutable");
		Process.Start(serverExe, "/reload-config");
		return true;
	}
예제 #10
0
	/// <summary>
	/// Send the new password notification message
	/// </summary>
	/// <param name="username">account</param>
	/// <param name="password">password (unencrypted)</param>
	/// <returns></returns>
	protected void AccountNotification(string username, string password, string recipients)
	{
		WebSettings ws = new WebSettings();

		string subject = "[FILEZILLA] Password Assignment (" + username + ")";
		StringBuilder sb = new StringBuilder();

		sb.Append("A new password has been assigned for your " + ws.Lookup("InstanceName" ) + " FileZilla account.\n\n");
		
		sb.Append("Username: "******"\n");
		sb.Append("Password: "******"\n");

		sb.Append("\n");
		sb.Append("Web Interface: " + ws.Lookup("HTTPUrl") + "\n");
		sb.Append("FTP Interface: " + ws.Lookup("FTPUrl") + "\n");

		// send out notifications only if specified
		if (recipients.Trim() != "")
		{
			// send to the designate recipients
			EMail.Send(subject, sb.ToString(), recipients);
			// send to the administrator
			sb.Append("\nNotifications: " + recipients + "\n");
			EMail.Send(subject, sb.ToString(), ws.Lookup("EmailRecipients"));
		}
	}
예제 #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
		// this page requires an authenticated user
		Master.ForceAuthentication();

		// wire the file manager events
		FileManager.CustomThumbnail += new FileManagerThumbnailCreateEventHandler(FileManager_CustomThumbnail);
		FileManager.FileDownloading += new FileManagerFileDownloadingEventHandler(FileManager_FileDownloading);
		FileManager.FileUploading += new FileManagerFileUploadEventHandler(FileManager_FileUploading);
		FileManager.FolderCreating += new FileManagerFolderCreateEventHandler(FileManager_FolderCreating);
		FileManager.ItemDeleting += new FileManagerItemDeleteEventHandler(FileManager_ItemDeleting);
		FileManager.ItemMoving += new FileManagerItemMoveEventHandler(FileManager_ItemMoving);
		FileManager.ItemRenaming += new FileManagerItemRenameEventHandler(FileManager_ItemRenaming);

		// create the configuration related objects
		webSettings = new WebSettings();
		fz = new Filezilla(webSettings.Lookup("ConfigurationFile"));

		// create the activity related objects
		log = new ActivityLog();

		// get the root folder based on the authenticated user
		rootFolder = fz.HomeDirectory(Master.UserName);

		if (!Page.IsPostBack)
		{
			// configure the general settings of the file manager 
			FileManager.SettingsEditing.AllowCreate = WebConvert.ToBoolean(webSettings.Lookup("AllowCreate", "0"), false);
			FileManager.SettingsEditing.AllowDelete = WebConvert.ToBoolean(webSettings.Lookup("AllowDelete", "0"), false);
			FileManager.SettingsEditing.AllowMove = WebConvert.ToBoolean(webSettings.Lookup("AllowMove", "0"), false);
			FileManager.SettingsEditing.AllowRename = WebConvert.ToBoolean(webSettings.Lookup("AllowRename", "0"), false);
			FileManager.SettingsFolders.ShowFolderIcons = WebConvert.ToBoolean(webSettings.Lookup("ShowFolderIcons", "0"), false);
			FileManager.SettingsToolbar.ShowDownloadButton = WebConvert.ToBoolean(webSettings.Lookup("ShowDownloadButton", "0"), false);
			FileManager.Settings.ThumbnailFolder = webSettings.Lookup("ThumbnailFolder");
			// advanced upload mode requires Microsoft Silverlight ... really?
			if (Master.IsSilverlightAvailable)
			{
				// silverlight is available - check the system configuration to see if we want to utilize it
				FileManager.SettingsUpload.UseAdvancedUploadMode = WebConvert.ToBoolean(webSettings.Lookup("UseAdvancedUploadMode", "0"), false);
				FileManager.SettingsUpload.AdvancedModeSettings.EnableMultiSelect = WebConvert.ToBoolean(webSettings.Lookup("EnableMultiSelect", "0"), false);
			}
			else
			{
				// no silverlight - no advanced upload mode
				FileManager.SettingsUpload.UseAdvancedUploadMode = false;
				FileManager.SettingsUpload.AdvancedModeSettings.EnableMultiSelect = false;

				// if the user could be utilizing silverlight, let them know
				if (WebConvert.ToBoolean(webSettings.Lookup("UseAdvancedUploadMode", "0"), false))
				{
					SilverlightPanel.Visible = true;
				}
			}
			// set the max file size from the settings, default to 1MB
			FileManager.SettingsUpload.ValidationSettings.MaxFileSize = WebConvert.ToInt32(webSettings.Lookup("MaxFileSize","1000000"),1000000);
 
			// limit permissions based on the settings for the ftp share

			// disable creating folders if its not enabled in the configuration
			if (!fz.AllowDirCreate(Master.UserName, rootFolder))
			{
				FileManager.SettingsEditing.AllowCreate = false;
			}

			// disable deleting, moving items if its not enabled in the configuration
			if (!fz.AllowFileDelete(Master.UserName, rootFolder))
			{
				FileManager.SettingsEditing.AllowDelete = false;
				FileManager.SettingsEditing.AllowMove = false;
			}
			
			// disable upload, move, rename, delete if write is not enabled
			if (!fz.AllowFileWrite(Master.UserName, rootFolder))
			{
				FileManager.SettingsUpload.Enabled = false;
				FileManager.SettingsEditing.AllowMove = false;
				FileManager.SettingsEditing.AllowRename = false;
				FileManager.SettingsEditing.AllowDelete = false;
			}

			// assign the root folder to the user's normalized home directory
			FileManager.Settings.RootFolder = fz.NormalizeFolderName(rootFolder);


			// log the browse action
			log.LogActivity(LogAction.Browse, Master.UserName, FileManager.Settings.RootFolder, "Silverlight=" + WebConvert.ToString( Session["FZNET_SILVERLIGHT"], "false") );
		}
    }