Skip to content

Instantly share code, notes, and snippets.

@mm580486
Created March 22, 2020 20:41
Show Gist options
  • Save mm580486/b6ce8d822dc0204603fcc00322ee82ed to your computer and use it in GitHub Desktop.
Save mm580486/b6ce8d822dc0204603fcc00322ee82ed to your computer and use it in GitHub Desktop.
def create_login_key(name, value, options = {})
never_expires = options.fetch(:never_expires, true)
expiration = options[:expiration]
allow_htm = options.fetch(:allow_htm, true)
allowed_commands = options.fetch(:allowed_commands, ['ALL_*'])
allowed_ips = options.fetch(:allowed_ips, []).join("\r\n")
max_uses = options.fetch(:max_uses, 1)
clear_key = options.fetch(:clear_key, false)
params = {
"keyname" => name,
"key" => value,
"key2" => value,
"never_expires" => never_expires,
"max_uses" => max_uses,
"ips" => allowed_ips,
"passwd" => server_password,
"create" => "Create"
}
params["never_expires"] = "yes" if never_expires
params["clear_key"] = "yes" if clear_key
params["allow_htm"] = "yes" if allow_htm
if !never_expires && expiration
params["hour"] = expiration.hour
params["minute"] = expiration.minute
params["month"] = expiration.month
params["day"] = expiration.day
params["year"] = expiration.year
end
allowed_commands.each_with_index do |command, i|
params["select_allow#{i}"] = command
end
response = request(:post, "/CMD_API_LOGIN_KEYS", params)
return {response: response}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment