bump version to 4.0-2
[pve-access-control.git] / pveum
CommitLineData
7c410d63 1#!/usr/bin/perl
2c3a6c0a
DM
2
3use strict;
7c410d63 4use warnings;
2c3a6c0a
DM
5use Getopt::Long;
6use PVE::Tools qw(run_command);
7use PVE::Cluster;
8use PVE::SafeSyslog;
9use PVE::AccessControl;
10use File::Path qw(make_path remove_tree);
11use Term::ReadLine;
12use PVE::INotify;
13use PVE::RPCEnvironment;
14use PVE::API2::User;
15use PVE::API2::Group;
16use PVE::API2::Role;
17use PVE::API2::ACL;
18use PVE::API2::AccessControl;
19use PVE::JSONSchema qw(get_standard_option);
20use PVE::CLIHandler;
21
22use base qw(PVE::CLIHandler);
23
24use Data::Dumper; # fixme: remove
25
26$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
27
28initlog('pveum');
29
30#fixme: logging?
31
32die "please run as root\n" if $> != 0;
33
34PVE::INotify::inotify_init();
35
36my $rpcenv = PVE::RPCEnvironment->init('cli');
37
38$rpcenv->init_request();
39$rpcenv->set_language($ENV{LANG});
40$rpcenv->set_user('root@pam');
41
42# autmatically generate the private key if it does not already exists
43PVE::Cluster::gen_auth_key();
44
45my $read_password = sub {
46
47 # return $ENV{PVE_PW_TICKET} if defined($ENV{PVE_PW_TICKET});
48
49 my $term = new Term::ReadLine ('pveum');
50 my $attribs = $term->Attribs;
51 $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
52 my $input = $term->readline('Enter new password: ');
53 my $conf = $term->readline('Retype new password: ');
54 die "Passwords do not match.\n" if ($input ne $conf);
55 return $input;
56};
57
58my $cmddef = {
59 ticket => [ 'PVE::API2::AccessControl', 'create_ticket', ['username'], undef,
60 sub {
61 my ($res) = @_;
62 print "$res->{ticket}\n";
63 }],
bdc61d7a
DM
64
65 passwd => [ 'PVE::API2::AccessControl', 'change_passsword', ['userid'] ],
66
2c3a6c0a
DM
67 useradd => [ 'PVE::API2::User', 'create_user', ['userid'] ],
68 usermod => [ 'PVE::API2::User', 'update_user', ['userid'] ],
69 userdel => [ 'PVE::API2::User', 'delete_user', ['userid'] ],
70
71 groupadd => [ 'PVE::API2::Group', 'create_group', ['groupid'] ],
72 groupmod => [ 'PVE::API2::Group', 'update_group', ['groupid'] ],
73 groupdel => [ 'PVE::API2::Group', 'delete_group', ['groupid'] ],
74
75 roleadd => [ 'PVE::API2::Role', 'create_role', ['roleid'] ],
76 rolemod => [ 'PVE::API2::Role', 'update_role', ['roleid'] ],
77 roledel => [ 'PVE::API2::Role', 'delete_role', ['roleid'] ],
78
7a4c849e
DM
79 aclmod => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 0 }],
80 acldel => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 1 }],
2c3a6c0a
DM
81};
82
83my $cmd = shift;
84
362fe4c6 85PVE::CLIHandler::handle_cmd($cmddef, "pveum", $cmd, \@ARGV, $read_password, $0);
2c3a6c0a
DM
86
87exit 0;
88
89__END__
90
91=head1 NAME
92
93pveum - PVE User Manager
94
95=head1 SYNOPSIS
96
362fe4c6 97=include synopsis
2c3a6c0a
DM
98
99=head1 DESCRIPTION
100
362fe4c6
DM
101No description available.
102
103=include pve_copyright