Created
April 2, 2010 15:23
-
-
Save msadouni/353252 to your computer and use it in GitHub Desktop.
Redémarrage d'un pack Alwaysdata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/https' | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
username = 'courriel' | |
password = 'mot de passe' | |
pack = 'nom du pack' | |
urls = ['http://www.monsite.com', 'http://test.monsite.com'] | |
url = URI.parse('https://admin.alwaysdata.com/') | |
https = Net::HTTP.new(url.host, url.port) | |
https.use_ssl = true | |
https.start do |http| | |
# login et récupération du cookie | |
res = https.post('/login/', "username=#{username}&password=#{password}") | |
headers = {'Cookie' => res['set-cookie']} | |
# récupération du token csrf et changement du pack | |
res = https.get('/', headers) | |
doc = Nokogiri::HTML(res.body) | |
input = doc.css('#account-choice input[name=csrfmiddlewaretoken]') | |
token = input.attr('value') | |
# arrêt des processus | |
https.post('/advanced/processes/', "change-account=#{pack}&csrfmiddlewaretoken=#{token}", headers) | |
https.get('/advanced/processes/all/kill/', headers) | |
end | |
urls.each do |url| | |
puts "Redémarrage de #{url}" | |
Net::HTTP.get(URI.parse(url)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment