User input
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
Always validate input - Never trust user input without validation
Sanitize data - Remove or escape dangerous characters
Use type checking - Ensure input matches expected data types
Implement length limits - Prevent buffer overflow scenarios
Clear sensitive data - Remove passwords and keys from memory after use
Usability recommendations
Provide clear prompts - Tell users exactly what input is expected
Give helpful error messages - Explain what went wrong and how to fix it
Use defaults wisely - Provide sensible defaults for optional parameters
Validate incrementally - Check input as it's provided, not just at the end
Confirm destructive actions - Always confirm before making irreversible changes
Performance considerations
Cache validation results - Don't re-validate the same input repeatedly
Batch process inputs - Validate multiple inputs together when possible
Use efficient validation - Implement validation logic that scales well
Limit input processing - Set reasonable limits on input size and complexity
Handle errors gracefully - Don't let input errors crash the entire script
Last updated
Was this helpful?