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