From 21c7463f8099d87d4c61826444ca6fb07b5691ff Mon Sep 17 00:00:00 2001 From: ziggi Date: Fri, 15 Dec 2017 02:06:38 +0200 Subject: [PATCH] Added quota form/handlers for domain and user --- Makefile.am | 2 ++ Makefile.in | 2 ++ configure | 20 ++++++++++---------- configure.ac | 2 +- maacom.pl | 30 +++++++++++++++++++++++------- schema.sql | 4 ++-- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Makefile.am b/Makefile.am index ff281df..8d45b53 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ \ diff --git a/Makefile.in b/Makefile.in index 68b42d8..0328d23 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 \ \ diff --git a/configure b/configure index c2226f4..96c9d27 100755 --- a/configure +++ b/configure @@ -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 $@ @@ -2272,7 +2272,7 @@ fi # Define the identity of the package. PACKAGE='maacom-pl' - VERSION='0.02' + VERSION='0.03' cat >>confdefs.h <<_ACEOF @@ -3455,7 +3455,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 +3508,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\\" diff --git a/configure.ac b/configure.ac index 07efec6..38e724e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(maacom.pl,0.02) +AC_INIT(maacom.pl,0.03) AM_INIT_AUTOMAKE AC_PREFIX_DEFAULT(/usr/local) diff --git a/maacom.pl b/maacom.pl index f3f5360..c399b5f 100755 --- a/maacom.pl +++ b/maacom.pl @@ -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"); @@ -471,7 +475,7 @@ sub user_add { return undef unless $name; return undef unless $password; return undef unless $domain_id; - $quota ||= 1024*1024*1024*10; + $quota ||= 1024*10; return undef if $self->user_exist($name, $domain_id); return undef unless $self->domain_profile($domain_id); @@ -479,7 +483,7 @@ 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, $quota) + $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); } @@ -908,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'); @@ -1248,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' ); @@ -1341,7 +1357,7 @@ $app->log(Mojo::Log->new( my $user = $app->config('user'); my $group = $app->config('group'); my $d = Daemon->new($user, $group); -#$d->fork; +$d->fork; $app->hook(before_dispatch => sub { my $c = shift; @@ -1381,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; diff --git a/schema.sql b/schema.sql index 9c897e4..d5c2452 100644 --- a/schema.sql +++ b/schema.sql @@ -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 10737418240 + quota int DEFAULT 10240 ); CREATE TABLE aliases ( id int unique NOT NULL PRIMARY KEY,