[vhffs-dev] [656] MySQL DB creation now uses only one page.

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


Revision: 656
Author:   beuss
Date:     2007-07-04 10:47:14 +0000 (Wed, 04 Jul 2007)

Log Message:
-----------
MySQL DB creation now uses only one page.
Added few doc to MySQL service.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Services/Mysql.pm
    trunk/vhffs-panel/cvs/create.pl
    trunk/vhffs-panel/mysql/create.pl
    trunk/vhffs-panel/templates/mysql/create.tmpl

Removed Paths:
-------------
    trunk/vhffs-panel/mysql/submit.pl


Modified: trunk/vhffs-api/src/Vhffs/Services/Mysql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mysql.pm	2007-07-04 10:23:51 UTC (rev 655)
+++ trunk/vhffs-api/src/Vhffs/Services/Mysql.pm	2007-07-04 10:47:14 UTC (rev 656)
@@ -53,11 +53,29 @@
 use strict;
 use DBI;
 
+=head2 check_dbname
+
+    die("Invalid DB name\n") unless Vhffs::Services::Mysql::check_dbname($dbname);
+
+Checks a DB name. Return false if the name isn't between 3 and 32 chars, all
+numbers, lowercase letters or underscore (the latter can't be in first or last
+position).
+
+=cut
+
 sub check_dbname($) {
     my $dbname = shift;
     return ($dbname =~ /^[a-z0-9][a-z0-9\_]{1,30}[a-z0-9]$/ );
 }
 
+=head2 check_dbuser
+
+    die("Invalid DB user\n") unless Vhffs::Services::Mysql::check_dbuser($dbuser);
+
+Checks that a DB username is valid. DB name rules apply.
+
+=cut
+
 sub check_dbuser($) {
     return check_dbname($_[0]);
 }

Modified: trunk/vhffs-panel/cvs/create.pl
===================================================================
--- trunk/vhffs-panel/cvs/create.pl	2007-07-04 10:23:51 UTC (rev 655)
+++ trunk/vhffs-panel/cvs/create.pl	2007-07-04 10:47:14 UTC (rev 656)
@@ -59,12 +59,14 @@
 my $cgi = $panel->{cgi};
 my $submitted = defined($cgi->param('cvs_submit'));
 
-my $repo_name = $cgi->param('REPOSITORY_NAME');
-my $description = $cgi->param('DESCRIPTION');
+my $repo_name;
+my $description;
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
 if($submitted) {
+    $repo_name = $cgi->param('REPOSITORY_NAME');
+    $description = $cgi->param('DESCRIPTION');
     if( $repo_name !~ /^[a-z0-9]+$/ ) {
         $panel->add_error( gettext('Your repository name is not correct. It must contains only caracter and numbers') );
     } elsif( length( $repo_name ) < 3 ) {
@@ -81,6 +83,10 @@
             $panel->add_error( gettext( 'An error occured while creating the object.It probably already exists' ) );
         }
     }
+} else {
+    # Avoid warnings with CGI::escapeHTML
+    $repo_name = '';
+    $description = '';
 }
 
 if(!$submitted || $panel->has_errors()) {
@@ -89,13 +95,13 @@
     $panel->set_title( gettext('Create a CVS Repository') );
 
     $template->param( REPOSITORY_NAME => gettext("Repository Name") );
-    $template->param( REPOSITORY_VALUE => $repo_name );
+    $template->param( REPOSITORY_VALUE => CGI::escapeHTML($repo_name) );
     $template->param( GROUP_NAME => gettext("Group owning this CVS") );
 
     $template->param( GROUP => $group->get_groupname );
     $template->param( SEND => gettext("Send") );
     $template->param( DESCRIPTION => gettext("Description") );
-    $template->param( DESCRIPTION_VALUE => $description);
+    $template->param( DESCRIPTION_VALUE => CGI::escapeHTML($description) );
 
     display Vhffs::Panel::Main($panel, $template->output);
 }

Modified: trunk/vhffs-panel/mysql/create.pl
===================================================================
--- trunk/vhffs-panel/mysql/create.pl	2007-07-04 10:23:51 UTC (rev 655)
+++ trunk/vhffs-panel/mysql/create.pl	2007-07-04 10:47:14 UTC (rev 656)
@@ -50,25 +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 = $panel->{'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.'/mysql/create.tmpl' );
+my $submitted = defined($cgi->param('mysql_submit'));
+my $dbprefix = $groupname.'_';
 
-my $template = new HTML::Template( filename => $templatedir."/mysql/create.tmpl" );
+my $dbsuffix;
+my $description;
 
-$template->param( TITLE => gettext("Create a MySQL database") );
-$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) );
-$template->param( GROUP_NAME => gettext("Group owning this database") );
-$template->param( DB_NAME_PREFIX => $groupname."_" );
-$template->param( DB_NAME => gettext("MySQL database name ") );
-$template->param( DB_PASS => gettext("MySQL password for this database ") );
-$template->param( GROUP => $group->get_groupname );
-$template->param( SEND => gettext("Send") );
-$template->param( DESCRIPTION => gettext("Description") );
+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::Mysql::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::Mysql::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::Mysql::create_mysql($vhffs, $dbname, $user, $group, $dbuser, $dbpass, $description)) {
+        my $url = '/panel.pl?project='.$panel->{groupname}.'&msg='.gettext('The MySQL 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 = '';
+}
 
-display Vhffs::Panel::Main($panel, $template->output);
+if(!$submitted || $panel->has_errors()) {
+    $panel->set_title( gettext('Create a MySQL 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("MySQL database name ") );
+    $template->param( DB_SUFFIX_VALUE => CGI::escapeHTML($dbsuffix) );
+    $template->param( DB_PASS => gettext("MySQL 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) );
+
+    display Vhffs::Panel::Main($panel, $template->output);
+}

Deleted: trunk/vhffs-panel/mysql/submit.pl
===================================================================
--- trunk/vhffs-panel/mysql/submit.pl	2007-07-04 10:23:51 UTC (rev 655)
+++ trunk/vhffs-panel/mysql/submit.pl	2007-07-04 10:47:14 UTC (rev 656)
@@ -1,111 +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 = $panel->{'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;
-
-my $mysql;
-
-# my $mysql = Vhffs::Panel::Mysql::create_mysql( $vhffs , "$dbname" , $user , $group , $dbpass );
-if( ( ! defined $dbuser ) || ( ! defined $dbpass ) || ( ! defined $dbname ) )
-{
-	$message = gettext( "CGI Error !");
-}
-elsif( length( $dbname ) > 32 )
-{
-	$message = gettext("The database name is too long. There is a 32 character limit");
-}
-elsif( length( $dbname ) < 3 )
-{
-	$message = gettext( "Database name must contain at least 3 caracters" );
-}
-elsif( length( $dbpass ) < 3 )
-{
-	$message = gettext( "Password must contain at least 3 caracters" );
-}
-elsif( ! ( $dbname =~ /^[0-9a-z][0-9a-z\_]+[0-9a-z]$/ ) )
-{
-	$message = gettext( "The database name is not valid" );
-}
-elsif( ! ( $dbpass =~ /^[0-9a-zA-Z]+$/ ) )
-{
-	$message = gettext( "The password is not valid" );
-}
-elsif( defined ( $mysql = Vhffs::Panel::Mysql::create_mysql($vhffs,$dbname,$user,$group,$dbuser,$dbpass,$description ) ) )
-{
-	$message = gettext("The MySQL object was successfully created !");
-}
-else
-{
-	$message = gettext( "An error occured while creating the object" );
-}
-
-
-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/mysql/create.tmpl
===================================================================
--- trunk/vhffs-panel/templates/mysql/create.tmpl	2007-07-04 10:23:51 UTC (rev 655)
+++ trunk/vhffs-panel/templates/mysql/create.tmpl	2007-07-04 10:47:14 UTC (rev 656)
@@ -1,9 +1,5 @@
-<h1><TMPL_VAR NAME="TITLE"></h1>
-
-<form method="post" action="submit.pl" class="largeLabel">
-	<p>		
-		<TMPL_VAR NAME="INFOS">
-	</p>
+<form method="post" action="#" class="largeLabel">
+    <p class="info"><TMPL_VAR NAME="INFOS"></p>
 	<p>
 		<label>		
 			<TMPL_VAR NAME="GROUP_NAME">: 
@@ -11,24 +7,24 @@
 		<TMPL_VAR NAME="GROUP">
 	</p>
 	<p>
-		<label for="DB_NAME">
-			<TMPL_VAR NAME="DB_NAME">: 
-		</label>
-		<TMPL_VAR NAME="DB_NAME_PREFIX"><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="PROJECT_USAGE">
+		<label for="description">
 			<TMPL_VAR NAME="DESCRIPTION">:
 		</label>
-		<textarea name="DESCRIPTION" id="PROJECT_USAGE" 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="mysql_submit"/>
 	</p>
 </form>


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