[vhffs-dev] [1010] All PostgreSQL prefs are now handled by prefs.pl |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1010
Author: beuss
Date: 2007-10-21 18:24:54 +0000 (Sun, 21 Oct 2007)
Log Message:
-----------
All PostgreSQL prefs are now handled by prefs.pl
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm
trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm
trunk/vhffs-panel/Makefile.am
trunk/vhffs-panel/mysql/prefs.pl
trunk/vhffs-panel/pgsql/create.pl
trunk/vhffs-panel/pgsql/prefs.pl
trunk/vhffs-panel/templates/pgsql/prefs.tmpl
Removed Paths:
-------------
trunk/vhffs-panel/pgsql/prefs_save.pl
Modified: trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm 2007-10-21 18:24:54 UTC (rev 1010)
@@ -47,7 +47,7 @@
if( defined $pg )
{
- $db->do("ALTER USER " . $pg->get_dbusername ." WITH PASSWORD '".$pg->get_dbpassword."'");
+ $db->do('ALTER USER '.$pg->get_dbusername.' WITH PASSWORD ?', undef, $pg->get_dbpassword);
$pg->set_status( Vhffs::Constants::ACTIVATED );
$pg->commit;
$pg->blank_password;
@@ -65,8 +65,8 @@
if( defined $pg )
{
- $db->do("CREATE DATABASE ".$pg->get_dbname );
- $db->do("CREATE USER " . $pg->get_dbusername ." WITH PASSWORD '".$pg->get_dbpassword."'");
+ $db->do('CREATE DATABASE '.$pg->get_dbname );
+ $db->do('CREATE USER '.$pg->get_dbusername.' WITH PASSWORD ?', undef, $pg->get_dbpassword);
$pg->set_status( Vhffs::Constants::ACTIVATED );
$pg->commit;
$pg->blank_password;
@@ -82,10 +82,10 @@
if( ( defined $pg ) && ( $pg->get_status == Vhffs::Constants::TO_DELETE ) )
{
- $pg->add_history("Ok, robots will erased all data");
+ $pg->add_history("Ok, robots will erase all data");
$db->do("DROP DATABASE ".$pg->get_dbname );
$db->do("DROP USER " . $pg->get_dbusername );
- $pg->add_history("All data will be erased");
+ $pg->add_history("All data have been erased");
if( $pg->delete < 0 )
{
Modified: trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm 2007-10-21 18:24:54 UTC (rev 1010)
@@ -90,15 +90,14 @@
die('Bad DB pass') unless(Vhffs::Services::Pgsql::check_dbpass($pass));
-Indicates wether a DB password is valid or not (at least one alphanumeric
-char).
+Indicates wether a DB password is valid or not (at least three chars).
=cut
sub check_dbpass($) {
my $dbpass = shift;
- return ( $dbpass =~ /^[a-zA-Z0-9]+$/);
+ return ( $dbpass =~ /^.{3,}$/);
}
sub delete
@@ -207,7 +206,7 @@
{
my $self = shift;
my $value = shift;
- return -1 if( ! ( $value =~ /^[a-zA-Z0-9]+$/ ) );
+ return -1 if( ! check_dbpass( $value ) );
$self->{'dbpass'} = $value;
return 1;
}
Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-panel/Makefile.am 2007-10-21 18:24:54 UTC (rev 1010)
@@ -127,7 +127,6 @@
pgsql/create.pl \
pgsql/delete.pl \
pgsql/index.pl \
- pgsql/prefs_save.pl \
pgsql/prefs.pl \
repository/create.pl \
repository/delete.pl \
Modified: trunk/vhffs-panel/mysql/prefs.pl
===================================================================
--- trunk/vhffs-panel/mysql/prefs.pl 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-panel/mysql/prefs.pl 2007-10-21 18:24:54 UTC (rev 1010)
@@ -143,6 +143,7 @@
if($mysql->set_dbpassword($new_passwd) < 0) {
$panel->add_error( gettext('Bad password, should be at least 3 chars') );
+ return 0;
} else {
$mysql->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION);
if($mysql->commit < 0) {
Modified: trunk/vhffs-panel/pgsql/create.pl
===================================================================
--- trunk/vhffs-panel/pgsql/create.pl 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-panel/pgsql/create.pl 2007-10-21 18:24:54 UTC (rev 1010)
@@ -84,7 +84,7 @@
} elsif(!Vhffs::Services::Pgsql::check_dbname($dbname)) {
$panel->add_error( gettext('Invalid database name, it must contain only numbers, lowercase letters and underscore (the latter isn\'t allowed in first or last position) and be between 3 and 32 characters.') );
} elsif(!Vhffs::Services::Pgsql::check_dbpass($dbpass)) {
- $panel->add_error( gettext('Invalid password. It must be at least 3 characters and contain only letters (lower and uppercase) and numbers') );
+ $panel->add_error( gettext('Invalid password. It must be at least 3 chars') );
} elsif(defined Vhffs::Panel::Pgsql::create_pgsql($vhffs, $dbname, $user, $group, $dbuser, $dbpass, $description)) {
my $url = '/group/view.pl?project='.$panel->{groupname}.'&msg='.gettext('The PostgreSQL DB was successfully created !');
$panel->redirect($url);
Modified: trunk/vhffs-panel/pgsql/prefs.pl
===================================================================
--- trunk/vhffs-panel/pgsql/prefs.pl 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-panel/pgsql/prefs.pl 2007-10-21 18:24:54 UTC (rev 1010)
@@ -31,7 +31,6 @@
use POSIX qw(locale_h);
-use HTML::Template;
use locale;
use Locale::gettext;
use CGI;
@@ -44,6 +43,7 @@
use Vhffs::Main;
use Vhffs::Panel::Main;
use Vhffs::Panel::Menu;
+use Vhffs::Panel::Template;
my $panel = new Vhffs::Panel::Main();
exit 0 unless $panel;
@@ -63,32 +63,31 @@
my $templatedir = $vhffs->get_config->get_templatedir;
-if( ! defined $pgsql)
-{
-
+if( ! defined $pgsql) {
my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
$message = gettext( "Cannot get informations on this object");
$template->param( MESSAGE => $message );
-}
-elsif( Vhffs::Acl::what_perm_for_user( $user , $pgsql , $vhffs ) < Vhffs::Constants::ACL_VIEW )
-{
+} elsif( Vhffs::Acl::what_perm_for_user( $user , $pgsql , $vhffs ) < Vhffs::Constants::ACL_VIEW ) {
$template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
$message = gettext("You're not allowed to do this (ACL rights)");
$template->param( MESSAGE => $message );
-}
-elsif( $pgsql->get_status != Vhffs::Constants::ACTIVATED )
-{
+} elsif( $pgsql->get_status != Vhffs::Constants::ACTIVATED ) {
$template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
$message = gettext("Please wait modification, creation or deletion");
$template->param( MESSAGE => $message );
-}
-else
-{
- $template = new HTML::Template( filename => $templatedir."/panel/pgsql/prefs.tmpl" );
+} else {
+ if(defined($cgi->param('save_prefs_submit'))) {
+ # save_prefs issues a redirect on success
+ if(&save_prefs()) {
+ #exit;
+ }
+ }
- $template->param( TEXT_TITLE => gettext("PostgreSQL Administration") );
+ $template = new Vhffs::Panel::Template( filename => $templatedir."/panel/pgsql/prefs.tmpl" );
+ $panel->set_title( gettext("PostgreSQL Administration") );
+
$template->param( TEXT_DBNAME => gettext("Name of the database") );
$template->param( VALUE_DBNAME => $pgsql->get_dbname );
@@ -96,7 +95,6 @@
$template->param( VALUE_DBUSER => $pgsql->get_dbusername );
$template->param( TEXT_DBPASS => gettext("Password for this database") );
-# $template->param( VALUE_DBPASS => $pgsql->get_dbpassword );
$template->param( VALUE_OID => $pgsql->get_oid );
$template->param( TEXT_ACL_ADMIN => "Admin Rights on this object (ACL)" );
@@ -114,3 +112,34 @@
$panel->build( $template );
$panel->display;
+
+
+sub save_prefs {
+ if(!$user->can_modify($pgsql)) {
+ $panel->add_error('You are not allowed to modify this PostgreSQL object (ACL rights)');
+ return 0;
+ }
+
+ my $new_passwd = $cgi->param('newpassword');
+ if(!defined $new_passwd) {
+ $panel->add_error( gettext('CGI Error') );
+ return 0;
+ }
+
+ if($pgsql->set_dbpassword($new_passwd) < 0) {
+ $panel->add_error( gettext('Bad password, should be at least 3 chars') );
+ return 0;
+ } else {
+ $pgsql->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION);
+ if($pgsql->commit < 0) {
+ $panel->add_error( gettext('Unable to apply changes') );
+ $pgsql->blank_password;
+ return 0;
+ } else {
+ my $url = '/group/view.pl?project='.$panel->{groupname}.'&msg='.gettext('Password change request taken in account, please wait for processing');
+ $panel->redirect($url);
+ return 1;
+ }
+ }
+
+}
Deleted: trunk/vhffs-panel/pgsql/prefs_save.pl
===================================================================
--- trunk/vhffs-panel/pgsql/prefs_save.pl 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-panel/pgsql/prefs_save.pl 2007-10-21 18:24:54 UTC (rev 1010)
@@ -1,109 +0,0 @@
-#!%PERL% -w
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in
-# the documentation and/or other materials provided with the
-# distribution.
-#3. Neither the name of vhffs nor the names of its contributors
-# may be used to endorse or promote products derived from this
-# software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-
-use POSIX qw(locale_h);
-use HTML::Template;
-use locale;
-use Locale::gettext;
-use CGI;
-use CGI::Session;
-use strict;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Main;
-use Vhffs::Group;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Panel::Group;
-use Vhffs::Services::Pgsql;
-
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
-
-my $vhffs = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-my $group = $panel->{'group'};
-my $cgi = $panel->{'cgi'};
-my $message;
-my $owner = $cgi->param("PROJECT_OWNER");
-my $dbpass = $cgi->param("DBPASS");
-
-my $templatedir = $vhffs->get_config->get_templatedir;
-
-#We test if the owner exist
-
-my $dbname = $cgi->param("name");
-
-my $pgsql = Vhffs::Services::Pgsql::get_by_dbname( $vhffs , $dbname );
-
-
-
-if ( ! defined( $pgsql ) )
-{
- $message = gettext("This DB doesn't exist in VHFFS database");
-}
-elsif( $pgsql->get_status != Vhffs::Constants::ACTIVATED )
-{
- $message = gettext("Please wait modification, creation or deletion");
-}
-elsif( Vhffs::Acl::what_perm_for_user( $user , $pgsql , $vhffs ) < Vhffs::Constants::ACL_MODIFY )
-{
- $message = gettext("You're not allowed to do this (ACL rights)");
-}
-elsif( $pgsql->set_dbpassword( $dbpass ) < 0 )
-{
- $message = gettext("Your password is not correct. Please check it.");
-}
-else
-{
- $pgsql->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
- if( $pgsql->commit < 0 )
- {
- $message = gettext( "No modification can be applied. Please check your fields." );
- }
- else
- {
- $message = gettext( "Modifications applied to your database" );
- }
-}
-
-
-my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
-$template->param( MESSAGE => $message );
-
-$panel->set_refresh_url( "/pgsql/prefs.pl?name=$dbname" );
-$panel->build( $template );
-$panel->display;
Modified: trunk/vhffs-panel/templates/pgsql/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/pgsql/prefs.tmpl 2007-10-20 08:25:46 UTC (rev 1009)
+++ trunk/vhffs-panel/templates/pgsql/prefs.tmpl 2007-10-21 18:24:54 UTC (rev 1010)
@@ -1,28 +1,28 @@
-<h1><tmpl_var name="TEXT_TITLE"></h1>
-
-<form method="post" action="/pgsql/prefs_save.pl">
+<form method="post" action="/pgsql/prefs.pl">
<p>
- <label for="name">
+ <label>
<tmpl_var name="TEXT_DBNAME"> :
</label>
<tmpl_var name="VALUE_DBNAME">
- <input type="hidden" name="name" id="name" value="<tmpl_var name="VALUE_DBNAME">"/>
</p>
<p>
- <label for="DBUSER">
+ <label>
<tmpl_var name="TEXT_DBUSER"> :
</label>
<tmpl_var name="VALUE_DBUSER">
- <input type="hidden" name="DBUSER" id="DBUSER" value="<tmpl_var name="VALUE_DBUSER">"/>
</p>
+ <p class="info">
+ <TMPL_I18N KEY="Warning, password change isn't immediate, you've to check periodically to see if it's done">
+ </p>
<p>
- <label for="DBPASS">
+ <label for="newpassword">
<tmpl_var name="TEXT_DBPASS"> :
</label>
- <input type="password" name="DBPASS" id="DBPASS" value="<tmpl_var name="VALUE_DBPASS">"/>
+ <input type="password" name="newpassword" id="newpassword" value="<tmpl_var name="VALUE_DBPASS">"/>
</p>
- <p class="button" id="buttonModify">
- <input type="submit" value="<tmpl_var name="TEXT_SEND">"/>
+ <p class="button">
+ <input type="hidden" name="name" value="<TMPL_VAR NAME="value_dbname">"/>
+ <input type="submit" value="<tmpl_var name="TEXT_SEND">" name="save_prefs_submit"/>
</p>
</form>