import groovyx.net.http.*
freenas = "192.168.1.222"
username = "admin"
password = "password"
def http = new HTTPBuilder( "http://${freenas}/" )
http.client.params.setBooleanParameter "http.protocol.expect-continue", false
// ログイン
http.request( Method.POST ) {
uri.path = "login.php"
send ContentType.URLENC, [username :"${username}", password:"${password}" ]
response.failure = { resp ->
println "Error:${resp.statusLine}"
}
}
// シャットダウンページ取得
authtoken = ""
http.get( path:"shutdown.php" ){ resp, html ->
authtoken = html.depthFirst().collect(){it}
.findAll(){
it.@name.text() == "authtoken"
}.get(0).@value.text()
}
// シャットダウン実行
http.request( Method.POST ){
uri.path = "shutdown.php"
send ContentType.URLENC, [authtoken:"${authtoken}", Submit:"Yes" ]
response.success = { resp, html ->
println "shutdown."
}
response.failure = { resp ->
println "Error:${resp.statusLine}"
}
}
バージョン情報
Groovy 1.7.2, JDK6 Update20, HTTP Builder 0.5.0, FreeNAS 0.7.1
0 件のコメント:
コメントを投稿