Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
38 views
in CompleteFTP by (51.6k points)
A CompleteFTP user asked us how to use a JSS custom command extension to add a Windows user.

1 Answer

0 votes
by (51.6k points)
 
Best answer

Adding the Custom Command:

1. Open CompleteFTP Manager
2. Select Extensions
3. Click Add extension -> Javascript (JSS) extension -> Command Commands
4. Enter CustomAdmin (or some other name) in the Name field
5. Copy the following script into the script editor:

function CreateWindowsUser(userName, virtualFolderPath, windowsMappingPath) {
    // Step 1: Get the system configuration
    var config = system.getConfig();

    // Step 2: Check arguments
    if (config.users.get(userName))
        throw 'Error: User already exists';
    if (config.folders.get(virtualFolderPath))
        throw 'Error: Folder already exists';
    
    // Step 3: Create a new non-Windows user
    var newUser = config.users.add('Windows');
    
    // Step 4: Assign username
    newUser.userName = userName;

    // Step 5: Add a Windows folder with a mapping path
    var folderType = "WindowsFolder";
    var windowsFolder = config.folders.add(virtualFolderPath, folderType, windowsMappingPath);

    // Step 6: Assign the Windows folder as the home folder for the user
    newUser.siteMapping[0].homeFolder = windowsFolder.fullPath;

    // Step 7: Set permissions for the Windows folder (optional)
    windowsFolder.access.owner.userName = newUser.userName;
    windowsFolder.access.owner.permissions = ["All"];
    windowsFolder.access.group.groupName = "users";
    windowsFolder.access.group.permissions = [];
    windowsFolder.access.allUsers.permissions = [];
    windowsFolder.access.inherits = false;

    // Step 8: Apply changes to the configuration
    config.applyChanges();
    
    return `Windows user ${userName} added successfully`;
}

6. Select the Permissions tab
7. Add a group permission for the admins group to access the CustomAdmin extension.
8. Select the Sites tab
9. Select the Admin site (won’t be visible unless Options -> Show system users/folders/sites is checked)
10. Enable SSH terminal access
11. Apply changes

Invoking the command:

Essentially you just log into via SSH to port 14983 and execute a command like the following:

CreateWindowsUser theusername /the/home/folder/in/CompleteFTP C:\the\windows\directory

There are many ways to do this. Since Windows includes OpenSSH, you can execute the following command:

ssh admin@localhost -p 14983 "CreateWindowsUser theusername /the/home/folder/in/CompleteFTP C:\the\windows\directory"

You can also set up public key authentication for the admin user if you like, so that you don’t have to enter the password every time. You can also add a new admin user and user that if you’d like to separate this from standard admin.

Categories

...