[vhffs-dev] [657] PostgreSQL database creation now uses only one page.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 657
Author:   beuss
Date:     2007-07-04 13:06:54 +0000 (Wed, 04 Jul 2007)

Log Message:
-----------
PostgreSQL database creation now uses only one page.
Removed references to no more existing files in Makefile.am.

Modified Paths:
--------------
    trunk/vhffs-backend/src/pgsql/initdb.sql.in
    trunk/vhffs-panel/Makefile.am
    trunk/vhffs-panel/pgsql/create.pl
    trunk/vhffs-panel/templates/pgsql/create.tmpl

Removed Paths:
-------------
    trunk/vhffs-panel/pgsql/pgsql_submit.pl


Modified: trunk/vhffs-backend/src/pgsql/initdb.sql.in
===================================================================
--- trunk/vhffs-backend/src/pgsql/initdb.sql.in	2007-07-04 10:47:14 UTC (rev 656)
+++ trunk/vhffs-backend/src/pgsql/initdb.sql.in	2007-07-04 13:06:54 UTC (rev 657)
@@ -261,7 +261,7 @@
 (
 	pgsql_id serial,
 	dbname varchar(200) NOT NULL,
-	dbuser varchar(16) NOT NULL,
+	dbuser varchar(32) NOT NULL,
 	dbpass varchar(32) NOT NULL,
 	owner_uid int4, 
 	owner_gid int4,

Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am	2007-07-04 10:47:14 UTC (rev 656)
+++ trunk/vhffs-panel/Makefile.am	2007-07-04 13:06:54 UTC (rev 657)
@@ -137,12 +137,10 @@
 	mysql/index.pl \
 	mysql/prefs_save.pl \
 	mysql/prefs.pl \
-	mysql/submit.pl \
 	object/upavatar.pl \
 	pgsql/create.pl \
 	pgsql/delete.pl \
 	pgsql/index.pl \
-	pgsql/pgsql_submit.pl \
 	pgsql/prefs_save.pl \
 	pgsql/prefs.pl \
 	public/allgroups.pl \

Modified: trunk/vhffs-panel/pgsql/create.pl
===================================================================
--- trunk/vhffs-panel/pgsql/create.pl	2007-07-04 10:47:14 UTC (rev 656)
+++ trunk/vhffs-panel/pgsql/create.pl	2007-07-04 13:06:54 UTC (rev 657)
@@ -50,27 +50,59 @@
     exit 0;
 }
 
-my $vhffs = $panel->{'vhffs'};
-my $session = $panel->{'session'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-my $group = $panel->{'group'};
-my $groupname = $group->get_groupname;
+my $groupname = $panel->{groupname};
+my $templatedir = $panel->{templatedir};
+my $cgi = $panel->{cgi};
 
-my $templatedir = $vhffs->get_config->get_templatedir;
+my $template = new HTML::Template( filename => $templatedir.'/pgsql/create.tmpl' );
+my $submitted = defined($cgi->param('pgsql_submit'));
+my $dbprefix = $groupname.'_';
 
-my $template = new HTML::Template( filename => $templatedir."/pgsql/create.tmpl" );
+my $dbsuffix;
+my $description;
 
-$template->param( TITLE => gettext("Create a Postgres database") );
-$template->param( DB_NAME => gettext("PostgreSQL database name") );
-$template->param( DB_PASS => gettext("PostgreSQL password for this database") );
-$template->param( GROUP_NAME => gettext("Group owning this database") );
-$template->param( GROUPNAME => $groupname );
+if($submitted) {
+    my $vhffs = $panel->{vhffs};
+    my $user = $panel->{user};
+    my $group = $panel->{group};
+    my $dbpass = $cgi->param('db_pass');
+    $dbsuffix = $cgi->param('db_suffix');
+    my $dbname = $dbprefix.$dbsuffix;
+    my $dbuser = $dbname;
+    $description = $cgi->param('description');
+    if(!(defined $dbpass && defined $dbsuffix && defined $description)) {
+        $panel->add_error( gettext('CGI error') );
+    } elsif($description =~ /^\s*$/) {
+        $panel->add_error( gettext('You must enter a description') );
+    } elsif(!Vhffs::Services::Postgres::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::Postgres::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') );
+    } elsif(defined Vhffs::Panel::Pgsql::create_pgsql($vhffs, $dbname, $user, $group, $dbuser, $dbpass, $description)) {
+        my $url = '/panel.pl?project='.$panel->{groupname}.'&msg='.gettext('The PostgreSQL DB was successfully created !');
+        $panel->redirect($url);
+    } else {
+        $panel->add_error( 'An error occured while creating the object.' );
+    }
+    
+} else {
+# Avoid warnings with escapeHTML
+    $dbsuffix = '';
+    $description = '';
+}
 
-$template->param( INFOS => sprintf( gettext("The prefix of your databases is constant, so the names of your databases will be %s_DBNAME<br>. One user will be created, which will be called %s_DBNAME") , $groupname, $groupname, $groupname) );
+if(!$submitted || $panel->has_errors()) {
+    $panel->set_title( gettext('Create a PostgreSQL database') );
+    $template->param( INFOS => sprintf( gettext('The database name is prefixed by your groupname followed by an underscore (%s_dbname). The database user is the database full name (%s_dbname).') , $groupname, $groupname) );
+    $template->param( GROUP_NAME => gettext("Group owning this database") );
+    $template->param( DB_PREFIX => $dbprefix );
+    $template->param( DB_SUFFIX => gettext("PostgreSQL database name ") );
+    $template->param( DB_SUFFIX_VALUE => CGI::escapeHTML($dbsuffix) );
+    $template->param( DB_PASS => gettext("PostgreSQL password for this database ") );
+    $template->param( GROUP => $groupname );
+    $template->param( SEND => gettext("Send") );
+    $template->param( DESCRIPTION => gettext("Description") );
+    $template->param( DESCRIPTION_VALUE => CGI::escapeHTML($description) );
 
-$template->param( GROUP => $group->get_groupname );
-$template->param( SEND => gettext("Send") );
-$template->param( DESCRIPTION => gettext("Description") );
-
-display Vhffs::Panel::Main($panel, $template->output);
+    display Vhffs::Panel::Main($panel, $template->output);
+}

Deleted: trunk/vhffs-panel/pgsql/pgsql_submit.pl
===================================================================
--- trunk/vhffs-panel/pgsql/pgsql_submit.pl	2007-07-04 10:47:14 UTC (rev 656)
+++ trunk/vhffs-panel/pgsql/pgsql_submit.pl	2007-07-04 13:06:54 UTC (rev 657)
@@ -1,107 +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::Group;
-use Vhffs::Main;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Panel::Group;
-
-my $panel = new Vhffs::Panel::Main;
-if(!$panel)  {
-        exit 0;
-}
-
-my $vhffs = $panel->{'vhffs'};
-my $session = $panel->{'session'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-my $group = $panel->{'group'};
-my $groupname = $group->get_groupname;
-my $cgi = $panel->{'cgi'};
-my $message;
-
-my $dbname = $groupname ."_". $cgi->param("DB_NAME");
-my $dbuser = $dbname;
-my $dbpass = $cgi->param("DB_PASS");
-
-my $description = $cgi->param("DESCRIPTION");
-
-my $templatedir = $vhffs->get_config->get_templatedir;
-
-if( ( ! defined $description ) || ( ! defined $dbpass ) || ( ! defined $dbuser ) )
-{
-	$message = gettext("CGI Error!");
-}
-elsif( length( $dbpass ) < 3 )
-{
-	$message = gettext("Database password must contains at least 3 characters");
-}
-elsif( ! ( $dbpass =~ /^[a-zA-Z0-9]+$/ ) )
-{
-	$message = gettext("Password must contains only alphanum caracters");
-}
-elsif( ! Vhffs::Services::Postgres::check_dbname($dbname) )
-{
-	$message = gettext( "Database name must contain between 3 and 16 characters" );
-}
-else
-{
-
-	my $postgres = Vhffs::Panel::Pgsql::create_pgsql( $vhffs , $dbname , $user , $group , $dbuser , $dbpass, $description );
-
-
-	if( defined $postgres )
-	{
-		$message = gettext("The PostgreSQL object was successfully created !");
-	}
-	else
-	{
-		$message = sprintf( gettext("An error occured while creating the object %s %s"), $dbname, $dbuser );
-	}
-}
-
-my $template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-$template->param( MESSAGE => $message );
-
-set_refresh_url Vhffs::Panel::Main($panel, "/panel.pl?project=$groupname", 0);
-display Vhffs::Panel::Main($panel, $template->output);

Modified: trunk/vhffs-panel/templates/pgsql/create.tmpl
===================================================================
--- trunk/vhffs-panel/templates/pgsql/create.tmpl	2007-07-04 10:47:14 UTC (rev 656)
+++ trunk/vhffs-panel/templates/pgsql/create.tmpl	2007-07-04 13:06:54 UTC (rev 657)
@@ -1,34 +1,30 @@
-<h1><TMPL_VAR NAME="TITLE"></h1>
-
-<form method="post" action="pgsql_submit.pl" class="largeLabel">
+<form method="post" action="#" class="largeLabel">
+    <p class="info"><TMPL_VAR NAME="INFOS"></p>
 	<p>
-		<TMPL_VAR NAME="INFOS">
-	</p>
-	<p>
 		<label>		
 			<TMPL_VAR NAME="GROUP_NAME">: 
 		</label>
 		<TMPL_VAR NAME="GROUP">
 	</p>
 	<p>
-		<label for="DB_NAME">
-			<TMPL_VAR NAME="DB_NAME">: 
-		</label>
-		<TMPL_VAR NAME="GROUPNAME">_<input type="text" name="DB_NAME" id="DB_NAME"/>
+        <label for="db_suffix">
+            <TMPL_VAR NAME="DB_SUFFIX">: 
+        </label>
+		<TMPL_VAR NAME="DB_PREFIX"><input type="text" name="db_suffix" id="db_suffix" value="<tmpl_var name="DB_SUFFIX_VALUE">"/>
 	</p>
 	<p>
-		<label for="DB_PASS">
+		<label for="db_pass">
 			<TMPL_VAR NAME="DB_PASS">: 
 		</label>
-		<input type="PASSWORD" name="DB_PASS" id="DB_PASS"/>
+		<input type="PASSWORD" name="db_pass" id="db_pass"/>
 	</p>
 	<p>
-		<label for="DESCRIPTION">
+		<label for="description">
 			<TMPL_VAR NAME="DESCRIPTION">:
 		</label>
-		<textarea name="DESCRIPTION" id="DESCRIPTION" cols="45" rows="7"></textarea>
+		<textarea name="description" id="description" cols="45" rows="7"><tmpl_var name="DESCRIPTION_VALUE"></textarea>
 	</p>
 	<p class="button" id="buttonSend">
-		<input type="submit" value="<TMPL_VAR NAME="SEND">" />
+		<input type="submit" value="<TMPL_VAR NAME="SEND">" name="pgsql_submit"/>
 	</p>
 </form>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/