/// <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; }
/// <summary> /// Load the object from an XML node /// </summary> /// <param name="node">xml root node of object</param> /// <returns>result of loading</returns> public bool Read(XmlNode user) { try { // get the username Username = user.SelectSingleNode("./@Name").ChildNodes[0].Value; // get the options that are supported Password = user.SelectSingleNode("./Option[@Name='Pass']").ChildNodes[0].Value; Enabled = (user.SelectSingleNode("./Option[@Name='Enabled']").ChildNodes[0].Value == "1"); // get the shared folders XmlNodeList folders = user.SelectNodes("./Permissions/Permission"); foreach (XmlNode folder in folders) { FilezillaPermission fzp = new FilezillaPermission(); if ( fzp.Read(folder) ) { Permissions.Add(fzp); } } } catch (Exception) { return false; } return true; }