Читал где-то тут что МТ в пакетах MaxDSL Dynamic не собираются делать автоматический переход после 00:00 на 512/512 а утром по выбору на что-то другое, ну и ладно ) Набросал для себя такую вот штуку:
у меня по крону
в 00:05
ruby srvdi.rb логин пароль MDIX TESTNIGH
утром в 7:55
ruby srvdi.rb логин пароль MDIX 64
параметры
MDIX - 1мбит по молдове
TESTNIGH - то что после полуночи анлим 512кбпс
64 - платный 64/512
писал на ruby - ruby-lang.org, просто щас больше с ним завязан. Но думаю не трудно и на перле переписать.
может еще кому пригодится.
- Код: Выделить всё
#!/usr/bin/env ruby require 'net/http' require 'uri' =begin Voprosi napravliaite siuda: sunwinder@gmail.com =end module MT URL_MTS = "http://192.168.169.66:8080/" MT_MDIX_SERVICE = "PrSer4" MT_TESTNIGH_SERVICE = "testnigh" MT_64_SERVICE = "PrSer1" # GET /serviceStart/refresh/home?service=testnigh&group=2 HTTP/1.1 # GET /serviceStart/refresh/home?service=PrSer1&group=2 HTTP/1.1 class LiveCookie attr_reader :cookies def initialize @cookies = Hash.new end def add_raw(raw_cookie) raw_cookie =~ /(\w+)=([^|;]*)/ @cookies[$1] = $2 end def dump str = "" @cookies.each { |k, v| str += "#{k}=#{v}; " } str.chomp("; ") end alias << add_raw end class Service class MTSLoginFailure < StandardError; end def urlencode(kv) str = "" kv.each { |k, v| str += "&#{k}=#{v}" } URI.encode(str) end def initialize(username, password) @live_cookie = LiveCookie.new @username = username @password = password end def show_headers(resp) resp.each { |k, v| puts "#{k}: #{v}" } end def check_location(resp) resp.each { |k, v| if (k == 'location') then return v end } nil end def store_cookies(resp) resp.each { |k, v| if k == 'set-cookie' then v.split(/, (?=\w+=)/).each { |cookie| @live_cookie << cookie } end } end def init url = URL_MTS while (1) do puts "trying: #{url}" resp, rd = do_GET(url) url = check_location(resp) break if url.nil? end end def do_POST(rel_url, form) uri = URI.parse(URL_MTS + rel_url) http = Net::HTTP.new(uri.host, uri.port) req = uri.path req += "?" + uri.query if uri.query resp, rd = http.post(req, urlencode(form), @live_cookie.cookies) show_headers(resp) end def start_service(service) url = URL_MTS + "serviceStart/refresh/home?service=#{service}&group=2" do_GET(url) end def stop_service(service) url = "serviceStop/refresh/home?service=#{service}&group=2" confirm_stop = { 'confirmed' => 'true', 'submitButton' => 'OK+' } do_POST(url, confirm_stop) end def login url = "user/refresh/home?confirmed=true&submitButton=OK+" login_credentials = { 'username' => @username, 'password' => @password } do_POST(url, login_credentials) end def logoff url = "accountLogoff/home" confirm_logoff = { 'confirmed' => 'true', 'submitButton' => 'OK+' } do_POST(url, confirm_logoff) end def do_GET(url) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) req = uri.path req += "?" + uri.query if uri.query resp, rd = http.get(req, { "Cookie" => @live_cookie.dump }) show_headers(resp) store_cookies(resp) [ resp, rd ] end end end =begin mts = MT::Service.new('username_xyz', 'password_xyz') mts.init mts.logoff; sleep 2 # FIXME: mts.login mts.start_service(MT::MT_MDIX_SERVICE) mts.start_service(MT::MT_TESTNIGH_SERVICE) =end if $0 == __FILE__ username = ARGV[0] password = ARGV[1] mts = MT::Service.new(username, password) mts.init mts.logoff; sleep 2 # FIXME: mts.login ARGV[2...ARGV.size].each { |service| case (service) when "TESTNIGH" mts.start_service(MT::MT_TESTNIGH_SERVICE) when "MDIX" mts.start_service(MT::MT_MDIX_SERVICE) when "64" mts.start_service(MT::MT_64_SERVICE) else puts "Undefined service #{service}..." end } end