keyboardUser input

circle-info

RouterOS scripts can interact with users through various input methods, from simple parameter passing to interactive prompts. Proper input handling ensures script reliability and security.

User input handling in RouterOS enables creation of interactive scripts, configuration wizards, and dynamic automation tools that adapt to user requirements.


Input methods overview

Script parameter passing

# Script with parameters - accessed via $1, $2, etc.
/system script add name=user-management source={
    # Parameters: $1=username, $2=password, $3=group
    :local userName $1;
    :local userPassword $2;
    :local userGroup $3;
    
    # Validate parameters
    :if ([:len $userName] = 0) do={
        /log error "Username parameter is required";
        :error "Missing username parameter";
    };
    
    :if ([:len $userPassword] = 0) do={
        /log error "Password parameter is required";
        :error "Missing password parameter";
    };
    
    # Set default group if not provided
    :if ([:len $userGroup] = 0) do={
        :set userGroup "read";
    };
    
    # Create user with provided parameters
    /user add name=$userName password=$userPassword group=$userGroup;
    /log info ("User " . $userName . " created with group " . $userGroup);
}

# Execute script with parameters
# /system script run user-management "john" "password123" "full"

Environment variable access


Interactive user prompts

Simple yes/no prompts

Configuration wizard simulation


Input validation and sanitization

Basic input validation

Input sanitization


Parameter processing patterns

Command-line style arguments

Configuration file input


Secure input handling

Password and sensitive data


Input processing workflows

Multi-step configuration wizard


Error handling for user input

Input validation errors


Best practices for user input

Security guidelines

  1. Always validate input - Never trust user input without validation

  2. Sanitize data - Remove or escape dangerous characters

  3. Use type checking - Ensure input matches expected data types

  4. Implement length limits - Prevent buffer overflow scenarios

  5. Clear sensitive data - Remove passwords and keys from memory after use

Usability recommendations

  1. Provide clear prompts - Tell users exactly what input is expected

  2. Give helpful error messages - Explain what went wrong and how to fix it

  3. Use defaults wisely - Provide sensible defaults for optional parameters

  4. Validate incrementally - Check input as it's provided, not just at the end

  5. Confirm destructive actions - Always confirm before making irreversible changes

Performance considerations

  1. Cache validation results - Don't re-validate the same input repeatedly

  2. Batch process inputs - Validate multiple inputs together when possible

  3. Use efficient validation - Implement validation logic that scales well

  4. Limit input processing - Set reasonable limits on input size and complexity

  5. Handle errors gracefully - Don't let input errors crash the entire script

Last updated

Was this helpful?