4 Commits
0.02 ... 0.03

Author SHA1 Message Date
ziggi
c637d26eed Release 0.03 2017-12-15 02:07:51 +02:00
ziggi
21c7463f80 Added quota form/handlers for domain and user 2017-12-15 02:06:38 +02:00
ziggi
e959b27efb Added quota form/handlers for domain and user 2017-12-15 02:03:39 +02:00
ziggi
b5caee2df4 Added quota to form 2017-12-14 23:36:44 +02:00
18 changed files with 183 additions and 41 deletions

View File

@@ -67,6 +67,8 @@ nobase_dist_pkgdata_DATA = \
templs/domain-add-handler.html.ep \
templs/domain-update-form.html.ep \
templs/domain-update-handler.html.ep \
templs/domain-rename-form.html.ep \
templs/domain-rename-handler.html.ep \
templs/domain-delete-form.html.ep \
templs/domain-delete-handler.html.ep \
\

View File

@@ -330,6 +330,8 @@ nobase_dist_pkgdata_DATA = \
templs/domain-add-handler.html.ep \
templs/domain-update-form.html.ep \
templs/domain-update-handler.html.ep \
templs/domain-rename-form.html.ep \
templs/domain-rename-handler.html.ep \
templs/domain-delete-form.html.ep \
templs/domain-delete-handler.html.ep \
\

21
configure vendored
View File

@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for maacom.pl 0.02.
# Generated by GNU Autoconf 2.69 for maacom.pl 0.03.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -576,8 +576,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='maacom.pl'
PACKAGE_TARNAME='maacom-pl'
PACKAGE_VERSION='0.02'
PACKAGE_STRING='maacom.pl 0.02'
PACKAGE_VERSION='0.03'
PACKAGE_STRING='maacom.pl 0.03'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@@ -1234,7 +1234,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures maacom.pl 0.02 to adapt to many kinds of systems.
\`configure' configures maacom.pl 0.03 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1304,7 +1304,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of maacom.pl 0.02:";;
short | recursive ) echo "Configuration of maacom.pl 0.03:";;
esac
cat <<\_ACEOF
@@ -1392,7 +1392,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
maacom.pl configure 0.02
maacom.pl configure 0.03
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1409,7 +1409,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by maacom.pl $as_me 0.02, which was
It was created by maacom.pl $as_me 0.03, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -1757,6 +1757,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
am__api_version='1.15'
ac_aux_dir=
@@ -2272,7 +2273,7 @@ fi
# Define the identity of the package.
PACKAGE='maacom-pl'
VERSION='0.02'
VERSION='0.03'
cat >>confdefs.h <<_ACEOF
@@ -3455,7 +3456,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by maacom.pl $as_me 0.02, which was
This file was extended by maacom.pl $as_me 0.03, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -3508,7 +3509,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
maacom.pl config.status 0.02
maacom.pl config.status 0.03
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"

View File

@@ -1,4 +1,5 @@
AC_INIT(maacom.pl,0.02)
AC_INIT(maacom.pl,0.03)
AM_INIT_AUTOMAKE
AC_PREFIX_DEFAULT(/usr/local)

View File

@@ -284,11 +284,13 @@ sub domain_nextid {
}
sub domain_add {
my ($self, $name) = @_;
my ($self, $name, $quota) = @_;
return undef unless $name;
return undef if $self->domain_exist($name);
$quota ||= 1024*1024;
my $next_id = $self->domain_nextid;
$self->db->do("insert into domains (id, name) values ($next_id, '$name')");
$self->db->do("insert into domains (id, name, quota) values ($next_id, '$name', $quota)");
$self->domain_exist($name);
}
@@ -304,8 +306,10 @@ sub domain_update {
return undef unless $prof;
my $name = $args{name} || $prof->{name};
my $quota = $args{quota} || $prof->{quota};
my $quota = $args{quota}*1;
$quota ||= $prof->{quota};
my $size = $prof->{size};
$args{size} ||= -1;
$size = $args{size} if $args{size} >= 0;
$self->db->do("update domains set name = '$name', size = $size, quota = $quota where id = $id");
@@ -467,10 +471,11 @@ sub user_nextid {
}
sub user_add {
my ($self, $name, $password, $domain_id) = @_;
my ($self, $name, $password, $domain_id, $quota) = @_;
return undef unless $name;
return undef unless $password;
return undef unless $domain_id;
$quota ||= 1024*10;
return undef if $self->user_exist($name, $domain_id);
return undef unless $self->domain_profile($domain_id);
@@ -478,8 +483,8 @@ sub user_add {
my $salt = substr(sha512_base64(sprintf("%X", rand(2**31-1))), 4, 16);
my $hash = crypt($password,'$6$'.$salt.'$');
$self->db->do("insert into users (id, name, password, domain_id, hash)
values ($next_id, '$name', '$password', $domain_id, '$hash')");
$self->db->do("insert into users (id, name, password, domain_id, hash, quota)
values ($next_id, '$name', '$password', $domain_id, '$hash', $quota)");
$self->user_exist($name, $domain_id);
}
@@ -907,6 +912,16 @@ sub domain_update_handler {
$self->render(template => 'domain-update-handler');
}
sub domain_rename_form {
my $self = shift;
$self->render(template => 'domain-rename-form');
}
sub domain_rename_handler {
my $self = shift;
$self->render(template => 'domain-rename-handler');
}
sub domain_delete_form {
my $self = shift;
$self->render(template => 'domain-delete-form');
@@ -1247,6 +1262,8 @@ $r->any('/domain/add/form')->over('auth')->to('controller#domain_add_form' );
$r->any('/domain/add/handler')->over('auth')->to('controller#domain_add_handler' );
$r->any('/domain/update/form')->over('auth')->to('controller#domain_update_form' );
$r->any('/domain/update/handler')->over('auth')->to('controller#domain_update_handler' );
$r->any('/domain/rename/form')->over('auth')->to('controller#domain_rename_form' );
$r->any('/domain/rename/handler')->over('auth')->to('controller#domain_rename_handler' );
$r->any('/domain/delete/form')->over('auth')->to('controller#domain_delete_form' );
$r->any('/domain/delete/handler')->over('auth')->to('controller#domain_delete_handler' );
@@ -1342,8 +1359,6 @@ my $group = $app->config('group');
my $d = Daemon->new($user, $group);
$d->fork;
$app->hook(before_dispatch => sub {
my $c = shift;
@@ -1382,7 +1397,7 @@ sub du {
$maxdeep ||= 10;
$deep ||= 0;
my $stat = stat($subj);
return int($stat->size/1024) if -f $subj;
return int($stat->size/(1024*1024)+0.5) if -f $subj;
$deep += 1;
return 0 if $deep > $maxdeep;

View File

@@ -3,7 +3,7 @@ CREATE TABLE domains (
id int unique NOT NULL PRIMARY KEY,
name text unique,
size int DEFAULT 0,
quota int DEFAULT 0
quota int DEFAULT 1048576
);
CREATE TABLE users (
id int unique NOT NULL PRIMARY KEY,
@@ -12,7 +12,7 @@ CREATE TABLE users (
password text,
hash text,
size int DEFAULT 0,
quota int DEFAULT 0
quota int DEFAULT 10240
);
CREATE TABLE aliases (
id int unique NOT NULL PRIMARY KEY,

View File

@@ -7,6 +7,7 @@
% use Mojo::Util qw(dumper);
% my $u = $c->app->user;
% my $quota = 1024*1024;
<div class="grid-container">
<div class="grid-x grid-padding-x">
@@ -18,6 +19,12 @@
<input type="text" name="domain_name" placeholder="domain.org" required pattern="[_.-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{5,42}"/>
<span class="form-error">Mandatory, 5 or more letter</span>
</label>
<label>Domain quota
<input type="number" name="quota" value="<%= $quota %>" required pattern="[0-9]{1,15}"/>
<span class="form-error">Mandatory, one or more ciphers</span>
</label>
<div class="text-center">
<button type="submit" class="button">Accept</button>
<a class="button" href="/domain/list">Escape</a>

View File

@@ -9,13 +9,14 @@
% my $u = $c->app->user;
% my $name = $c->req->param('domain_name');
% my $id = $u->domain_exist($name);
% my $quota = $c->req->param('quota') || 0;
% if ($id) {
<div class="callout warning">Domain <%= $name %> already exists</div>
% }
% unless ($id) {
% my $res = $u->domain_add($name);
% my $res = $u->domain_add($name, $quota);
% if ($res) {
<div class="callout success">Domain <%= $name %> has been added.</div>
% }

View File

@@ -30,8 +30,10 @@
<th>#</th>
<th>domain</th>
<th><i class="fi-graph-pie"></i></th>
<th><i class="fi-alert"></i></th>
<th><i class="fi-male"></i></th>
<th><i class="fi-male-female"></i></th>
<th><i class="fi-address-book"></i></th>
<th><i class="fi-pencil"></i></th>
<th><i class="fi-trash"></i></th>
</tr>
@@ -45,12 +47,15 @@
% my $id = $row->{id};
% my $name = $row->{name};
% my $size = $row->{size};
% my $quota = $row->{quota};
<tr>
<td><%= $n %></td>
<td><%= $name %></td>
<td><%= $size %></td>
<td><%= $quota %></td>
<td><a href="/user/list?domain_id=<%= $id %>"><%= $u->domain_user_count($id) %></a></td>
<td><a href="/alias/list?domain_id=<%= $id %>"><%= $u->domain_alias_count($id) %></a></td>
<td><a href="/domain/rename/form?domain_id=<%= $id %>"><i class="fi-address-book"></i></a></td>
<td><a href="/domain/update/form?domain_id=<%= $id %>"><i class="fi-pencil"></i></a></td>
<td><a href="/domain/delete/form?domain_id=<%= $id %>"><i class="fi-trash"></i></a></td>
</tr>

View File

@@ -0,0 +1,44 @@
%#
%# $Id$
%#
% layout 'default';
% title 'Maacom';
% use Mojo::Util qw(dumper);
% my $u = $c->app->user;
% my $domain_id = $c->req->param('domain_id') || 0;
% my $profile = $u->domain_profile($domain_id);
% if ($profile) {
% my $domain_name = $profile->{name};
<div class="grid-container">
<div class="grid-x grid-padding-x">
<div class="medium-6 medium-centered cell">
<form accept-charset="UTF-8" action="/domain/rename/handler" method="post" data-abide novalidate>
<h5 class="text-center">Edit domain</h5>
<input type="hidden" name="domain_id" value="<%= $domain_id %>"/>
<label>Domain name
<input type="text" value="<%= $domain_name %>" name="domain_name" required pattern="[_.-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{5,42}"/>
<span class="form-error">Mandatory, 5 or more letter</span>
</label>
<div class="text-center">
<button type="submit" class="button">Accept</button>
<a class="button" href="/domain/list">Escape</a>
</div>
</form>
</div>
</div>
</div>
% }
% unless ($profile) {
<div class="callout warning">Domain with id <%= $domain_id %> not exist</div>
% }
%#EOF

View File

@@ -0,0 +1,42 @@
%#
%# $Id$
%#
% layout 'default';
% title 'Maacom';
% use Mojo::Util qw(dumper);
% my $u = $c->app->user;
% my $new_name = $c->req->param('domain_name');
% my $domain_id = $c->req->param('domain_id') || 0;
% my $profile = $u->domain_profile($domain_id);
% if ($profile) {
% my $name = $profile->{name};
% my $cid = $u->domain_exist($new_name);
% if ($cid) {
<div class="callout warning">Domain <%= $new_name %> already exists, domain name <%= $name %> was not changed.</div>
% }
% unless ($cid) {
% my $res = $u->domain_update($domain_id, name => $new_name);
% if ($res) {
<div class="callout success">Domain <%= $name %> has been renamed to <%= $new_name %>.</div>
% }
% unless ($res) {
<div class="callout alert">Domain <%= $name %> was not updated.</div>
% }
% }
% }
% unless ($profile) {
<div class="callout warning">Domain with id <%= $domain_id %> not exist</div>
% }
%#EOF

View File

@@ -13,6 +13,7 @@
% if ($profile) {
% my $domain_name = $profile->{name};
% my $quota = $profile->{quota} || 0;
<div class="grid-container">
<div class="grid-x grid-padding-x">
@@ -21,9 +22,9 @@
<form accept-charset="UTF-8" action="/domain/update/handler" method="post" data-abide novalidate>
<h5 class="text-center">Edit domain</h5>
<input type="hidden" name="domain_id" value="<%= $domain_id %>"/>
<label>Domain name
<input type="text" value="<%= $domain_name %>" name="domain_name" required pattern="[_.-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{5,42}"/>
<span class="form-error">Mandatory, 5 or more letter</span>
<label>Quota
<input type="number" name="quota" value="<%= $quota %>" required pattern="[0-9]{1,15}"/>
<span class="form-error">Mandatory, one or more ciphers</span>
</label>
<div class="text-center">
<button type="submit" class="button">Accept</button>

View File

@@ -8,25 +8,19 @@
% my $u = $c->app->user;
% my $name = $c->req->param('domain_name');
% my $domain_id = $c->req->param('domain_id') || 0;
% my $profile = $u->domain_profile($domain_id);
% my $quota = $c->req->param('quota') || $profile->{quota};
% if ($profile) {
% my $cid = $u->domain_exist($name);
% if ($cid) {
<div class="callout warning">Domain <%= $name %> already exists</div>
% my $name = $profile->{name};
% my $res = $u->domain_update($domain_id, quota => $quota);
% if ($res) {
<div class="callout success">Domain <%= $name %> has been updated.</div>
% }
% unless ($cid) {
% my $res = $u->domain_update($domain_id, name => $name);
% if ($res) {
<div class="callout success">Domain <%= $name %> has been updated.</div>
% }
% unless ($res) {
<div class="callout alert">Domain <%= $name %> was not updated.</div>
% }
% unless ($res) {
<div class="callout alert">Domain <%= $name %> was not updated.</div>
% }
% }

View File

@@ -9,6 +9,7 @@
% my $u = $c->app->user;
% my $domain_id = $c->req->param('domain_id');
% my $quota = 1024*10;
% if ($domain_id) {
% my $profile = $u->domain_profile($domain_id);
@@ -28,6 +29,12 @@
<input type="text" name="password" placeholder="xxxxxxxxx" required pattern="[_.-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{5,42}"/>
<span class="form-error">Mandatory, 6 or more letter</span>
</label>
<label>Quota
<input type="number" name="quota" value="<%= $quota %>" required pattern="[0-9]{1,15}"/>
<span class="form-error">Mandatory, one or more ciphers</span>
</label>
<div class="text-center">
<button type="submit" class="button">Accept</button>
<a class="button" href="/user/list?domain_id=<%= $domain_id %>">Escape</a>
@@ -63,6 +70,10 @@
% }
</select >
</label>
<label>Quota
<input type="number" name="quota" value="<%= $quota %>" required pattern="[0-9]{1,15}"/>
<span class="form-error">Mandatory, one or more ciphers</span>
</label>
<div class="text-center">
<button type="submit" class="button">Accept</button>

View File

@@ -11,6 +11,8 @@
% my $user_name = $c->req->param('user_name');
% my $domain_id = $c->req->param('domain_id');
% my $password = $c->req->param('password');
% my $quota = $c->req->param('quota');
% my $cid = $u->user_exist($user_name, $domain_id);
@@ -19,7 +21,7 @@
% }
% unless ($cid) {
% my $id = $u->user_add($user_name, $password, $domain_id);
% my $id = $u->user_add($user_name, $password, $domain_id, $quota);
% if ($id) {
<div class="callout success">User <%= $user_name %> has been added.</div>
% }

View File

@@ -28,6 +28,7 @@
<th>#</th>
<th>address</th>
<th><i class="fi-graph-pie"></i></th>
<th><i class="fi-alert"></i></th>
<th><i class="fi-address-book"></i></th>
<th><i class="fi-pencil"></i></th>
<th><i class="fi-trash"></i></th>
@@ -42,10 +43,12 @@
% my $user_id = $row->{id};
% my $domain_id = $row->{domain_id};
% my $size = $row->{size} || 0;
% my $quota = $row->{quota} || 0;
<tr>
<td><%= $n %></td>
<td><%= $address %></td>
<td><%= $size %></td>
<td><%= $quota %></td>
<td><a href="/user/rename/form?user_id=<%= $user_id %>"><i class="fi-address-book"></i></a></td>
<td><a href="/user/update/form?user_id=<%= $user_id %>"><i class="fi-pencil"></i></a></td>
<td><a href="/user/delete/form?user_id=<%= $user_id %>"><i class="fi-trash"></i></a></td>
@@ -72,6 +75,7 @@
<th>#</th>
<th>address</th>
<th><i class="fi-graph-pie"></i></th>
<th><i class="fi-alert"></i></th>
<th><i class="fi-at-sign"></i></th>
<th><i class="fi-address-book"></i></th>
<th><i class="fi-pencil"></i></th>
@@ -87,10 +91,12 @@
% my $user_id = $row->{id};
% my $domain_id = $row->{domain_id};
% my $size = $row->{size} || 0;
% my $quota = $row->{quota} || 0;
<tr>
<td><%= $n %></td>
<td><%= $address %></td>
<td><%= $size %></td>
<td><%= $quota %></td>
<td><a href="/user/list?domain_id=<%= $domain_id %>"><i class="fi-at-sign"></i></a></td>
<td><a href="/user/rename/form?user_id=<%= $user_id %>"><i class="fi-address-book"></i></a></td>
<td><a href="/user/update/form?user_id=<%= $user_id %>"><i class="fi-pencil"></i></a></td>

View File

@@ -17,6 +17,7 @@
% my $domain_id = $profile->{domain_id};
% my $password = $profile->{password};
% my $address = $profile->{address};
% my $quota = $profile->{quota};
<div class="grid-container">
<div class="grid-x grid-padding-x">
@@ -29,6 +30,11 @@
<input type="text" value="<%= $password %>" name="password" required pattern="[_.-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{6,42}"/>
<span class="form-error">Mandatory, 6 or more letter</span>
</label>
<label>Quota
<input type="number" name="quota" value="<%= $quota %>" required pattern="[0-9]{1,15}"/>
<span class="form-error">Mandatory, one or more ciphers</span>
</label>
<div class="text-center">
<button type="submit" class="button">Accept</button>
<a class="button" href="/user/list?">Escape</a>

View File

@@ -10,6 +10,7 @@
% my $user_id = $c->req->param('user_id') || 0;
% my $password = $c->req->param('password');
% my $quota = $c->req->param('quota');
% my $profile = $u->user_profile($user_id);
@@ -17,8 +18,9 @@
% my $domain_id = $profile->{domain_id};
% my $domain_name = $profile->{domain_name};
% my $address = $profile->{address};
% my $quota = $quota || $profile->{quota};
% my $res = $u->user_update($user_id, password => $password);
% my $res = $u->user_update($user_id, password => $password, quota => $quota);
% if ($res) {
<div class="callout success">User <%= $address %> has been updated.</div>
% }