Module AxisNetcam::Camera::Users
In: lib/axis-netcam/camera.rb

Functionality related to managing the camera‘s user and group lists.

Methods

Public Instance methods

Same as add_user, but updates the user account instead of creating it if it already exists.

[Source]

# File lib/axis-netcam/camera.rb, line 257
      def add_or_update_user(user)
        if user_exists?(user[:username], user)
          update_user(user[:username], user)
        else
          add_user(user)
        end
      end

Adds a new user based on the given hash. The hash must have :username, :password, and :comment elements.

[Source]

# File lib/axis-netcam/camera.rb, line 228
      def add_user(user)
        params = {
          'action'  => 'add',
          'user'    => user[:username],
          'pwd'     => user[:password],
          'comment' => user[:comment],
          'grp'     => 'users',
          'sgrp'    => 'axview'
        }
        axis_action("admin/pwdgrp.cgi", params)
      end

Deletes the user with the given username.

[Source]

# File lib/axis-netcam/camera.rb, line 266
      def remove_user(username)
        params = {
          'action'  => 'remove',
          'user'    => username,
        }
        axis_action("admin/pwdgrp.cgi", params)
      end

Updates a user based on the given hash.

username :specifies the username of the user to update.
attributes :must be a hash with new values for :password and :comment.

[Source]

# File lib/axis-netcam/camera.rb, line 243
      def update_user(username, attributes)
        params = {
          'action'  => 'update',
          'user'    => username,
          'pwd'     => user[:password],
          'comment' => user[:comment],
          'grp'     => 'users',
          'sgrp'    => 'axview'
        }
        axis_action("admin/pwdgrp.cgi", params)
      end

Checks if the user with the given username exists.

[Source]

# File lib/axis-netcam/camera.rb, line 291
      def user_exists?(username)
        users.include? username
      end

Returns an array with the usernames of the users on the camera.

[Source]

# File lib/axis-netcam/camera.rb, line 275
      def users
        str = axis_action("admin/pwdgrp.cgi", {'action' => 'get'})
        return false unless str
        usernames = []
        str.split.collect do |u| 
          u =~ /.*?="(.*)"/
          if $~
            usernames += $~[1].split(',')
          else
            usernames += []
          end
        end
        usernames.uniq!
      end

[Validate]