| 1 | package API::DirectAdmin::User; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Modern::Perl '2010'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use base 'API::DirectAdmin::Component'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | our $VERSION = 0.06; | |||||||||
| 9 | |||||||||||
| 10 | # Return list of users (only usernames) | ||||||||||
| 11 | 1 | ▶ | sub list { | ||||||||
|
Subroutine
list: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||
| 12 | 1 | my ($self ) = @_; | |||||||||
| 13 | |||||||||||
| 14 | 1 | my $responce = $self->directadmin->query( | |||||||||
| 15 | command => 'CMD_API_SHOW_ALL_USERS', | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | return $responce->{list} if ref $responce eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | return []; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | # Create a New User | ||||||||||
| 23 | # params: username, domain, passwd, passwd2, package, ip, email | ||||||||||
| 24 | 2 | ▶ | sub create { | ||||||||
|
Subroutine
create: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 25 | 2 | my ($self, $params ) = @_; | |||||||||
| 26 | |||||||||||
| 27 | 2 | my %add_params = ( | |||||||||
| 28 | action => 'create', | ||||||||||
| 29 | add => 'submit', | ||||||||||
| 30 | notify => 'no', | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | 2 | my %params = (%$params, %add_params); | |||||||||
| 34 | |||||||||||
| 35 | 2 | my $responce = $self->directadmin->query( | |||||||||
| 36 | params => \%params, | ||||||||||
| 37 | command => 'CMD_API_ACCOUNT_USER', | ||||||||||
| 38 | allowed_fields => | ||||||||||
| 39 | 'action | ||||||||||
| 40 | add | ||||||||||
| 41 | notify | ||||||||||
| 42 | username | ||||||||||
| 43 | domain | ||||||||||
| 44 | passwd | ||||||||||
| 45 | passwd2 | ||||||||||
| 46 | package | ||||||||||
| 47 | ip | ||||||||||
| 48 | email', | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | 2 | ▶ | carp "Creating account: $responce->{text}, $responce->{details}" if $self->{debug}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 2 | return $responce; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | # Suspend user | ||||||||||
| 56 | # params: select0 | ||||||||||
| 57 | 1 | ▶ | sub disable { | ||||||||
|
Subroutine
disable: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 58 | 1 | my ($self, $params ) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 1 | my %add_params = ( | |||||||||
| 61 | suspend => 'Suspend', | ||||||||||
| 62 | location => 'CMD_SELECT_USERS', | ||||||||||
| 63 | ); | ||||||||||
| 64 | |||||||||||
| 65 | 1 | my %params = (%$params, %add_params); | |||||||||
| 66 | |||||||||||
| 67 | 1 | my $responce = $self->directadmin->query( | |||||||||
| 68 | command => 'CMD_API_SELECT_USERS', | ||||||||||
| 69 | method => 'POST', | ||||||||||
| 70 | params => \%params, | ||||||||||
| 71 | allowed_fields => 'location | ||||||||||
| 72 | suspend | ||||||||||
| 73 | select0', | ||||||||||
| 74 | ); | ||||||||||
| 75 | |||||||||||
| 76 | 1 | ▶ | carp "Suspend account: $responce->{text}, $responce->{details}" if $self->{debug}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 1 | return $responce; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | # Unsuspend user | ||||||||||
| 81 | # params: select0 | ||||||||||
| 82 | 1 | ▶ | sub enable { | ||||||||
|
Subroutine
enable: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 83 | 1 | my ($self, $params ) = @_; | |||||||||
| 84 | |||||||||||
| 85 | 1 | my %add_params = ( | |||||||||
| 86 | suspend => 'Unsuspend', | ||||||||||
| 87 | location => 'CMD_SELECT_USERS', | ||||||||||
| 88 | ); | ||||||||||
| 89 | |||||||||||
| 90 | 1 | my %params = (%$params, %add_params); | |||||||||
| 91 | |||||||||||
| 92 | 1 | my $responce = $self->directadmin->query( | |||||||||
| 93 | command => 'CMD_API_SELECT_USERS', | ||||||||||
| 94 | method => 'POST', | ||||||||||
| 95 | params => \%params, | ||||||||||
| 96 | allowed_fields => 'location | ||||||||||
| 97 | suspend | ||||||||||
| 98 | select0', | ||||||||||
| 99 | ); | ||||||||||
| 100 | |||||||||||
| 101 | 1 | ▶ | carp "Unsuspend account: $responce->{text}, $responce->{details}" if $self->{debug}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 1 | return $responce; | |||||||||
| 103 | |||||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | # Delete user | ||||||||||
| 107 | # params: select0 | ||||||||||
| 108 | 2 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 109 | 2 | my ($self, $params ) = @_; | |||||||||
| 110 | |||||||||||
| 111 | 2 | my %add_params = ( | |||||||||
| 112 | confirmed => 'Confirm', | ||||||||||
| 113 | delete => 'yes', | ||||||||||
| 114 | ); | ||||||||||
| 115 | |||||||||||
| 116 | 2 | my %params = (%$params, %add_params); | |||||||||
| 117 | |||||||||||
| 118 | 2 | my $responce = $self->directadmin->query( | |||||||||
| 119 | command => 'CMD_API_SELECT_USERS', | ||||||||||
| 120 | method => 'POST', | ||||||||||
| 121 | params => \%params, | ||||||||||
| 122 | allowed_fields => 'confirmed | ||||||||||
| 123 | delete | ||||||||||
| 124 | select0', | ||||||||||
| 125 | ); | ||||||||||
| 126 | |||||||||||
| 127 | 2 | ▶ | carp "Delete account: $responce->{text}, $responce->{details}" if $self->{debug}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | 2 | return $responce; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | # Change passwd | ||||||||||
| 132 | # params: username, passwd, passwd2 | ||||||||||
| 133 | 1 | ▶ | sub change_password { | ||||||||
|
Subroutine
change_password: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 134 | 1 | my ($self, $params ) = @_; | |||||||||
| 135 | |||||||||||
| 136 | 1 | my $responce = $self->directadmin->query( | |||||||||
| 137 | command => 'CMD_API_USER_PASSWD', | ||||||||||
| 138 | method => 'POST', | ||||||||||
| 139 | params => $params, | ||||||||||
| 140 | allowed_fields => 'passwd | ||||||||||
| 141 | passwd2 | ||||||||||
| 142 | username', | ||||||||||
| 143 | ); | ||||||||||
| 144 | |||||||||||
| 145 | 1 | ▶ | carp "Change passwd account: $responce->{text}, $responce->{details}" if $self->{debug}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 1 | return $responce; | |||||||||
| 147 | } | ||||||||||
| 148 | |||||||||||
| 149 | # Change package for user | ||||||||||
| 150 | # params: user, package | ||||||||||
| 151 | 1 | ▶ | sub change_package { | ||||||||
|
Subroutine
change_package: called CC=4 SCAR=19.2
Pod
undocumented
| |||||||||||
| 152 | 1 | my ($self, $params ) = @_; | |||||||||
| 153 | |||||||||||
| 154 | 1 | my $package = $params->{package}; | |||||||||
| 155 | |||||||||||
| 156 | 1 | ▶ | unless ( $self->{fake_answer} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 1 | ▶ | unless ( $package ~~ $self->show_packages() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 1 | return {error => 1, text => "No such package $package on server"}; | |||||||||
| 159 | } | ||||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | 0 | my %add_params = ( | |||||||||
| 163 | action => 'package', | ||||||||||
| 164 | ); | ||||||||||
| 165 | |||||||||||
| 166 | 0 | my %params = (%$params, %add_params); | |||||||||
| 167 | |||||||||||
| 168 | 0 | my $responce = $self->directadmin->query( | |||||||||
| 169 | command => 'CMD_API_MODIFY_USER', | ||||||||||
| 170 | method => 'POST', | ||||||||||
| 171 | params => \%params, | ||||||||||
| 172 | allowed_fields => 'action | ||||||||||
| 173 | package | ||||||||||
| 174 | user', | ||||||||||
| 175 | ); | ||||||||||
| 176 | |||||||||||
| 177 | 0 | ▶ | carp "Change package: $responce->{text}, $responce->{details}" if $self->{debug}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 178 | 0 | return $responce; | |||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||
| 181 | # Show a list of user packages | ||||||||||
| 182 | # no params | ||||||||||
| 183 | 1 | ▶ | sub show_packages { | ||||||||
|
Subroutine
show_packages: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 184 | 1 | my ($self ) = @_; | |||||||||
| 185 | |||||||||||
| 186 | my $responce = $self->directadmin->query( | ||||||||||
| 187 | command => 'CMD_API_PACKAGES_USER', | ||||||||||
| 188 | 1 | )->{list}; | |||||||||
| 189 | |||||||||||
| 190 | 1 | return $responce; | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | # Show user config | ||||||||||
| 194 | # params: user | ||||||||||
| 195 | 0 | ▶ | sub show_user_config { | ||||||||
|
Subroutine
show_user_config: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 196 | 0 | my ( $self, $params ) = @_; | |||||||||
| 197 | |||||||||||
| 198 | 0 | my $responce = $self->directadmin->query( | |||||||||
| 199 | command => 'CMD_API_SHOW_USER_CONFIG', | ||||||||||
| 200 | params => $params, | ||||||||||
| 201 | allowed_fields => 'user', | ||||||||||
| 202 | ); | ||||||||||
| 203 | |||||||||||
| 204 | 0 | return $responce; | |||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | 1 | 1; | |||||||||