]> git.proxmox.com Git - pve-access-control.git/blame - pveum
cleanup: avoid writing user.cfg twice
[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
2c3a6c0a
DM
32my $read_password = sub {
33
34 # return $ENV{PVE_PW_TICKET} if defined($ENV{PVE_PW_TICKET});
35
36 my $term = new Term::ReadLine ('pveum');
37 my $attribs = $term->Attribs;
38 $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
39 my $input = $term->readline('Enter new password: ');
40 my $conf = $term->readline('Retype new password: ');
41 die "Passwords do not match.\n" if ($input ne $conf);
42 return $input;
43};
44
45my $cmddef = {
46 ticket => [ 'PVE::API2::AccessControl', 'create_ticket', ['username'], undef,
47 sub {
48 my ($res) = @_;
49 print "$res->{ticket}\n";
50 }],
bdc61d7a
DM
51
52 passwd => [ 'PVE::API2::AccessControl', 'change_passsword', ['userid'] ],
53
2c3a6c0a
DM
54 useradd => [ 'PVE::API2::User', 'create_user', ['userid'] ],
55 usermod => [ 'PVE::API2::User', 'update_user', ['userid'] ],
56 userdel => [ 'PVE::API2::User', 'delete_user', ['userid'] ],
57
58 groupadd => [ 'PVE::API2::Group', 'create_group', ['groupid'] ],
59 groupmod => [ 'PVE::API2::Group', 'update_group', ['groupid'] ],
60 groupdel => [ 'PVE::API2::Group', 'delete_group', ['groupid'] ],
61
62 roleadd => [ 'PVE::API2::Role', 'create_role', ['roleid'] ],
63 rolemod => [ 'PVE::API2::Role', 'update_role', ['roleid'] ],
64 roledel => [ 'PVE::API2::Role', 'delete_role', ['roleid'] ],
65
7a4c849e
DM
66 aclmod => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 0 }],
67 acldel => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 1 }],
2c3a6c0a
DM
68};
69
70my $cmd = shift;
71
ef740495 72if (defined($cmd) && $cmd ne 'verifyapi' && $cmd ne 'printmanpod') {
a8a4cd64
WB
73 die "please run as root\n" if $> != 0;
74
75 PVE::INotify::inotify_init();
76
77 my $rpcenv = PVE::RPCEnvironment->init('cli');
78
79 $rpcenv->init_request();
80 $rpcenv->set_language($ENV{LANG});
81 $rpcenv->set_user('root@pam');
82
83# autmatically generate the private key if it does not already exists
84 PVE::Cluster::gen_auth_key();
85}
86
362fe4c6 87PVE::CLIHandler::handle_cmd($cmddef, "pveum", $cmd, \@ARGV, $read_password, $0);
2c3a6c0a
DM
88
89exit 0;
90
91__END__
92
93=head1 NAME
94
95pveum - PVE User Manager
96
97=head1 SYNOPSIS
98
362fe4c6 99=include synopsis
2c3a6c0a
DM
100
101=head1 DESCRIPTION
102
362fe4c6
DM
103No description available.
104
105=include pve_copyright