Skip to content

Instantly share code, notes, and snippets.

@fenrir-naru
Last active July 23, 2024 15:19
Show Gist options
  • Save fenrir-naru/86d60962e7b4e6463cf82f7e9dacf14f to your computer and use it in GitHub Desktop.
Save fenrir-naru/86d60962e7b4e6463cf82f7e9dacf14f to your computer and use it in GitHub Desktop.
HDL-AAX shutdown script
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
# 設定内容
url = "http://192.168.1.XXX" # TODO
password = "password" # TODO
module Kernel # required for version below 2.6
def then
return to_enum(__method__) { 1 } unless block_given?
yield self
end unless method_defined? :then
end
# 以下処理内容
require 'mechanize'
agent = Mechanize.new
# ログイン
agent.get(url).then{|page|
form = page.form_with(:name => 'form')
form.field_with(:type => 'password').value = password
button = form.button_with(name: 'login')
agent.submit(form, button)
}
agent.get(url + "/admin/system/power/shutdown").then{|page|
# シャットダウンページ
form = page.form_with(:name => 'form')
button = form.button_with(name: 'shutdown')
agent.submit(form, button)
}.then{|page|
# 確認画面
form = page.form_with(:name => 'form')
button = form.button_with(name: 'execute')
agent.submit(form, button) rescue nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment