89c6f1bb4704dc2d897d500d722be82616a92bc3
[cloudstore.git] / lib / CloudStore / API.pm
1 package CloudStore::API;
2 use warnings;
3 use strict;
4 use autodie;
5
6 sub new {
7         my $class = shift;
8         my $self = {@_};
9         bless $self, $class;
10
11         $self->{passwd} ||= '/var/lib/extrausers/passwd';
12         $self->{PORT}   ||= $ENV{PORT}  || die "no PORT in env";
13         $self->{SLICE}  ||= $ENV{SLICE} || die "no SLICE in env";
14
15         return $self;
16 }
17
18 sub create_user {
19         my ( $self, $new_email, $new_passwd, $new_quota ) = @_;
20
21         my $max_uid = 0;
22         my $found = 0;
23
24         open(my $fh, '<', $self->{passwd});
25         while(<$fh>) {
26                 my ( $login, $passwd, $uid, $gid, $email, $dir, $shell ) = split(/:/,$_);
27                 $max_uid = $uid if $uid > $max_uid;
28                 $found = $uid if $email eq $new_email;
29         }
30         close($fh);
31
32         if ( ! $found ) {
33                 $max_uid++;
34                 my $dir = "$self->{SLICE}/$max_uid";
35                 warn "# create_user $new_email $new_quota = $max_uid $dir";
36                 open(my $fh, '>>', $self->{passwd});
37                 print $fh "u$max_uid:$new_passwd:$max_uid:$self->{PORT}:$new_email:$dir:/bin/true\n";
38                 close($fh);
39                 $found = $max_uid;
40
41                 mkdir $dir;
42                 chown $max_uid, $self->{PORT}, $dir;
43         }
44
45         return $found;
46 }
47
48 sub send_file {
49         my ( $f_uid,$f_path, $t_uid,$t_path ) = @_;
50
51         
52 }
53
54 sub rename_file {
55         my ( $uid, $from, $to ) = @_;
56 }
57
58
59 sub delete {
60         my ( $uid, $path ) = @_;
61
62 }
63
64 sub usage {
65         my ( $uid ) = @_;
66
67 }
68
69 1;