Hi folks,
I'm in the middle of helping setup Monowall for a coffee shop where we wanted to be able to automagically have the password change on a daily(?) basis. I didn't see any straight forward way to do this so I ended up writing a ruby script to do it. Hope someone else finds it useful:
This has only been tested on 1.231. If the web gui changes in the newer builds this might not work
require 'net/https'
class Monowall
CAPTIVE_PORTAL_UPDATE_USER = '/services_captiveportal_users_edit.php'
def initialize(user, password, address, port, use_ssl)
@user = user
@password = password
@address = address
@port = port
@use_ssl = use_ssl
end
def set_cp_password(user_id, user_name, password, user_full_name='', expiration='')
http = Net::HTTP.new(@address, @port)
http.use_ssl = @use_ssl
response = http.start do |h|
request = Net::HTTP::Post.new(CAPTIVE_PORTAL_UPDATE_USER)
request.basic_auth(@user, @password)
request.set_form_data({
'username' => user_name,
'password' => password,
'password2' => password,
'fullname' => user_full_name,
'expirationdate' => expiration,
'id' => user_id
})
h.request(request)
end
case response
when Net::HTTPFound
true
else
response.value # re-raise exception
end
end
end
# ruby is a user account that only has access to 'Services: Captive portal: Edit user'
# 192.168.123.168 is the monowall system
m = Monowall.new('ruby', '123456', '192.168.123.168', 443, true)
# guest is the account that wireless users will login with
# 0 is the internal user id associated with the account
# you can find out what the id is by clicking edit for a user and looking at the url
m.set_cp_password(0, 'guest', '123456')
I'll probably set this up as a cron job / scheduled task on another machine that plugs in a random password.