Cloud Commander

repository·master·Indexed 24 days ago

https://github.com/coderaiser/cloudcmd

A web-based file manager featuring a built-in console and text editor. It can be deployed as a standalone CLI tool via npm, as a Docker container, or integrated into Node.js applications as Express and Socket.IO middleware. The project includes a modular client-side API for managing file systems, UI panels, and event handling.

Tokens
15K
Snippets
19
Records
90
Agent score
83%

What's inside cloudcmd

  1. Use Vim mode in Cloud Commander

    master

    You can enable Vim-style hotkeys by providing the --vim flag during startup or setting vim: true in your configuration. This applies to both the file manager and the editor.

    Vim Hotkeys:

    KeyOperation
    jNavigate to next file
    kNavigate to previous file
    ddRemove current file
    G or $Navigate to bottom file
    gg or ^Navigate to top file
    vVisual mode
    yCopy (selected in visual mode)
    pPaste files
    /Find file in current directory
    eEdit file
    mmMove file
    rrRename file
  2. Start and use Cloud Commander

    master

    After installation, start the server by running the global npm binary from your terminal:

    cloudcmd

    By default, the server runs on port 8000. You can access the web client by navigating to:

    http://localhost:8000

    If you need to change the port or other settings, use the command-line parameters (see CLI Reference). For options not provided via CLI, Cloud Commander reads from ~/.cloudcmd.json.

  3. Install and Configure the Terminal

    master

    The terminal is disabled by default. To enable it, you must install gritty globally and then configure the terminal path in Cloud Commander.

    1. Install Gritty

    npm i gritty -g

    2. Set the Terminal Path

    Use the --terminal and --terminal-path flags. You can use the gritty --path command to find the correct path.

    Unix/Linux/macOS:

    cloudcmd --terminal --terminal-path `gritty --path` --save

    Windows: If you encounter issues installing gritty on Windows, install windows-build-tools first:

    npm install windows-build-tools -g

    Then, find the path using gritty --path and save it:

    cloudcmd --save --terminal --terminal-path "C:\Users\coderaiser\AppData\Roaming\npm\node_modules\gritty"

    Terminal Hotkeys

    • Shift + ~: Open terminal
    • Shift + Esc: Close terminal
    npm i gritty -g
  4. Perform file operations via Drag and Drop

    master

    Cloud Commander supports drag-and-drop operations between the file panels and your desktop:

    Drag Mouse ButtonKeyOriginDestinationOperation
    LeftPanelPanelCopy files
    LeftShiftPanelPanelRename/move files
    LeftPanelDesktopDownload files
    LeftDesktopPanelUpload files
  5. Use Cloud Commander as middleware for Express and Socket.IO

    master

    You can integrate Cloud Commander into an existing Node.js application using Express and Socket.IO. This allows you to mount the file manager at a specific route prefix.

    Prerequisites

    Install the required dependencies:

    npm init -y
    npm i cloudcmd express socket.io -S

    Implementation

    To use it, create an HTTP server, initialize a Socket.IO server, and pass the socket instance to the cloudcmd middleware. You can also provide a config object, custom modules, and a configManager to customize the instance.

    import http from 'node:http';
    import {cloudcmd} from 'cloudcmd';
    import {Server} from 'socket.io';
    import express from 'express';
    
    const app = express();
    const port = 1337;
    const prefix = '/';
    
    const server = http.createServer(app);
    const socket = new Server(server, {
        path: `${prefix}socket.io`,
    });
    
    const config = {
        name: 'cloudcmd :)',
    };
    
    const modules = {};
    
    const { 
        createConfigManager, 
        configPath 
    } = cloudcmd;
    
    const configManager = createConfigManager({
        configPath,
    });
    
    app.use(prefix, cloudcmd({
        socket, // required for Console and Edit
        config, // optional
        modules, // optional
        configManager, // optional
    }));
    
    server.listen(port);
  6. Install Cloud Commander via npm

    master

    To install Cloud Commander, ensure you have node.js installed, then use the following command to install it globally via npm:

    npm i cloudcmd -g

    If you encounter installation issues, you can force the installation using:

    npm i cloudcmd -g --force
  7. Use Cloud Commander as Express/Socket.IO middleware

    master

    You can integrate Cloud Commander into an existing Node.js application using Express and Socket.IO. This allows you to embed the file manager within your own server.

    Key requirements:

    • An express application instance.
    • A socket.io server instance.
    • The cloudcmd middleware function.

    You can pass an optional config object, modules for overriding options, and a configManager (created via createConfigManager) to manage configurations.

    import http from 'node:http';
    import {cloudcmd} from 'cloudcmd';
    import {Server} from 'socket.io';
    import express from 'express';
    
    const app = express();
    
    const port = 1337;
    const prefix = '/';
    
    const server = http.createServer(app);
    const socket = new Server(server, {
        path: `${prefix}socket.io`,
    });
    
    const config = {
        name: 'cloudcmd :)',
    };
    
    const filePicker = {
        data: {
            FilePicker: {
                key: 'key',
            },
        },
    };
    
    // override option from json/modules.json
    const modules = {
        filePicker,
    };
    
    const { 
        createConfigManager, 
        configPath 
    } = cloudcmd;
    
    const configManager = createConfigManager({
        configPath,
    });
    
    app.use(prefix, cloudcmd({
        socket, // used by Config, Edit (optional) and Console (required)
        config, // config data (optional)
        modules, // optional
        configManager, // optional
    }));
    
    server.listen(port);
  8. Distribute Configuration via Export/Import

    master

    Cloud Commander allows you to distribute configurations between instances using an export server and an import client.

    Setup

    1. Export Server: Start an instance with the --export flag and a shared --export-token.
    2. Import Client: Start an instance with the --import flag, providing the --import-url of the export server and the matching --import-token.

    To receive live updates whenever the export server's configuration changes, use the --import-listen flag on the client.

    Example

    Export Server:

    cloudcmd --port 1234 --export --export-token=cloudcmd

    Import Client:

    cloudcmd --name importer --port 4321 --import-url http://127.0.0.1:1234 --import-token=cloudcmd --no-server --save

    Note: The export server will not export sensitive or connection-specific fields like auth, username, password, ip, port, or root.

    cloudcmd --port 1234 --export --export-token=cloudcmd
    
    cloudcmd --name importer --port 4321 --import-url http://127.0.0.1:1234 --import-token=cloudcmd --no-server --save
  9. Update Cloud Commander

    master

    To update Cloud Commander to the latest version:

    1. Stop the running server.
    2. Reinstall the package globally:
      npm install cloudcmd -g
    3. Start the server again with cloudcmd and reload your web browser.
    npm install cloudcmd -g
  10. Run Cloud Commander with Docker

    master

    You can run Cloud Commander as a container. By default, it reads configuration from the home directory and mounts the host's root filesystem to /mnt/fs inside the container.

    Docker CLI

    docker run -t --rm -v ~:/root -v /:/mnt/fs -w=/root -p 8000:8000 coderaiser/cloudcmd

    Docker Compose

    Create a docker-compose.yml file:

    version: '2'
    services:
      web:
        ports:
          - 8000:8000
        volumes:
          - ~:/root
          - /:/mnt/fs
        image: coderaiser/cloudcmd

    Then run docker-compose up.

  11. Enable authorization and password hashing

    master

    To secure Cloud Commander, enable auth in your configuration. For security, passwords should be stored as hashes in ~/.cloudcmd.json rather than plain text.

    Generating a secure hash via CLI

    You can generate a hash and save it to your config file without starting the server using the following command:

    cloudcmd --username name --password password --auth --save --no-server

    Configuration Object

    When using the middleware approach, pass the following to the config object:

    • auth: boolean (set to true to enable)
    • username: string
    • password: string (the hash)
    • algo: string (optional hashing algorithm, e.g., 'sha512WithRSAEncryption')