[vhffs-dev] [685] User can know change its shell in its preferences panel

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


Revision: 685
Author:   gradator
Date:     2007-07-07 22:15:51 +0000 (Sat, 07 Jul 2007)

Log Message:
-----------
User can know change its shell in its preferences panel

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Conf.pm
    trunk/vhffs-api/src/Vhffs/Panel/Main.pm
    trunk/vhffs-api/src/Vhffs/Panel/User.pm
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-backend/conf/vhffs.conf.dist.in
    trunk/vhffs-backend/conf/vhffs.conf.in
    trunk/vhffs-panel/templates/user/prefs.tmpl
    trunk/vhffs-panel/user/prefs.pl


Modified: trunk/vhffs-api/src/Vhffs/Conf.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Conf.pm	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-api/src/Vhffs/Conf.pm	2007-07-07 22:15:51 UTC (rev 685)
@@ -83,7 +83,7 @@
 	$Config{'users'}{'default_zipcode'} = "121231" if ( !defined $Config{'users'}{'default_zipcode'} );
 	$Config{'users'}{'default_address'} = "1 in the street" if ( !defined $Config{'users'}{'default_address'} );
 
-	$Config{'users'}{'shell'} = "/bin/false" if( ! defined $Config{'users'}{'shell'} );
+	$Config{'users'}{'default_shell'} = "/bin/false" if( ! defined $Config{'users'}{'default_shell'} );
 
     return \%Config;
 }

Modified: trunk/vhffs-api/src/Vhffs/Panel/Main.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2007-07-07 22:15:51 UTC (rev 685)
@@ -231,6 +231,7 @@
 }
 
 
+
 sub select_lang
 {
 	use Vhffs::Intl;

Modified: trunk/vhffs-api/src/Vhffs/Panel/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/User.pm	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-api/src/Vhffs/Panel/User.pm	2007-07-07 22:15:51 UTC (rev 685)
@@ -149,7 +149,7 @@
 {
 	my $user = shift;
 	return -1 if( ! defined $user );
-    return $user->get_lang;
+	return $user->get_lang;
 }
 
 
@@ -157,14 +157,28 @@
 {
 	my $user = shift;
 	return -1 if( ! defined $user );
-    my $theme = $user->get_theme;
-    unless(defined $theme) {
-        $theme = $user->get_main->get_config->get_default_theme;
-    }
-    return $user->get_theme;
+	my $theme = $user->get_theme;
+	$theme = $user->get_main->get_config->get_default_theme unless(defined $theme);
+	return $theme;
 }
 
 
+sub get_shell
+{
+	my $user = shift;
+	return -1 if( ! defined $user );
+	return $user->get_shell;
+}
+
+
+sub list_shells
+{
+	my $vhffs = shift;
+	return -1 if( ! defined $vhffs );
+	return split(/ /,$vhffs->get_config->get_users->{'available_shells'});
+}
+
+
 =pod
 
 =head2 get_groups

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2007-07-07 22:15:51 UTC (rev 685)
@@ -215,11 +215,11 @@
         $zipcode = $userconf->{'default_zipcode'} unless ( defined $zipcode );
         $city = $userconf->{'default_city'} unless ( defined $city );
         $mail = $userconf->{'default_mail'} unless ( defined $mail );
-        $gpg_key = " " unless ( defined $gpg_key && $gpg_key ne "" );
+        $gpg_key = "" unless ( defined $gpg_key && $gpg_key ne "" );
         $country = $userconf->{'default_country'} unless ( defined $country );
 
         my $sth = $dbh->prepare('INSERT INTO vhffs_users (uid, gid, username, shell, passwd, homedir, admin, firstname, lastname, address, zipcode, city, country, mail, gpg_key, note, language, theme, object_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, NULL, ?)');
-        $sth->execute($uid, $gid, $username, $userconf->{'shell'}, Vhffs::Functions::password_encrypt($password), $homedir, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, Vhffs::Constants::DEFAULT_LANG, $parent->get_oid);
+        $sth->execute($uid, $gid, $username, $userconf->{'default_shell'}, Vhffs::Functions::password_encrypt($password), $homedir, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, Vhffs::Constants::DEFAULT_LANG, $parent->get_oid);
         
         my $group = Vhffs::Group::create($main, $username, $uid, $gid);
         die('Error creating group') unless (defined $group);
@@ -278,7 +278,7 @@
 
     #Exec the super method !
 
-    $self->{'shell'} = $self->{'main'}->get_config->get_users->{'shell'} if (! defined $self->{'shell'} );
+    $self->{'shell'} = $self->{'main'}->get_config->get_users->{'default_shell'} if (! defined $self->{'shell'} );
     $self->{'status'} = 'I' if ( ! defined $self->{'status'} );
     $self->{'admin'} = 0 if ( ! defined $self->{'admin'} );
 	return -1 if ( ( ! defined $self->{'passwd'} ) || ( $self->{'passwd'} eq "" ) );

Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-07-07 22:15:51 UTC (rev 685)
@@ -138,12 +138,11 @@
 ################################################
 #the default configuration for users
 <users>
-	minuid	=	@MINUID@
-	shell	= 	/usr/bin/tuxshell
-	mingid	=	@MINGID@
-	default_quota	=	50
-	bad_username_file =	@CONFDIR@/badfile
-	bad_groupname_file	=	@CONFDIR@/badgroup
+	minuid = @MINUID@
+	mingid = @MINGID@
+	default_quota = 50
+	bad_username_file = @CONFDIR@/badfile
+	bad_groupname_file = @CONFDIR@/badgroup
 	default_firstname = Vhffs Firstname
 	default_lastname = Vhffs Lastname
 	default_address = Vhffs Address
@@ -151,18 +150,12 @@
 	default_zipcode = 123456
 	default_mail = dave@xxxxxxxx
 	default_country = Disneyland
+	available_shells = /bin/bash /bin/tcsh /bin/zsh /bin/tuxshell
+	default_shell = /bin/bash
 </users>
 
 
 
-<system>
-	<shells>
-		available	=	/bin/false /bin/tuxshell /bin/bash
-		default		= 	/bin/false
-	</shells>
-</system>
-
-
 #####################################
 # SERVICES
 #####################################

Modified: trunk/vhffs-backend/conf/vhffs.conf.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.in	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-backend/conf/vhffs.conf.in	2007-07-07 22:15:51 UTC (rev 685)
@@ -138,12 +138,11 @@
 ################################################
 #the default configuration for users
 <users>
-	minuid	=	@MINUID@
-	shell	= 	/usr/bin/tuxshell
-	mingid	=	@MINGID@
-	default_quota	=	50
-	bad_username_file =	@CONFDIR@/badfile
-	bad_groupname_file	=	@CONFDIR@/badgroup
+	minuid = @MINUID@
+	mingid = @MINGID@
+	default_quota = 50
+	bad_username_file = @CONFDIR@/badfile
+	bad_groupname_file = @CONFDIR@/badgroup
 	default_firstname = Vhffs Firstname
 	default_lastname = Vhffs Lastname
 	default_address = Vhffs Address
@@ -151,18 +150,12 @@
 	default_zipcode = 123456
 	default_mail = dave@xxxxxxxx
 	default_country = Disneyland
+	available_shells = /bin/bash /bin/tcsh /bin/zsh /bin/tuxshell
+	default_shell = /bin/bash
 </users>
 
 
 
-<system>
-	<shells>
-		available	=	/bin/false /bin/tuxshell /bin/bash
-		default		= 	/bin/false
-	</shells>
-</system>
-
-
 #####################################
 # SERVICES
 #####################################

Modified: trunk/vhffs-panel/templates/user/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/user/prefs.tmpl	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-panel/templates/user/prefs.tmpl	2007-07-07 22:15:51 UTC (rev 685)
@@ -63,6 +63,13 @@
 						<tmpl_var name="THEME_LIST">
 					</select>
 				</p>
+
+				<p>
+					<label for="SHELL"><tmpl_var name="TEXT_SHELL"> :</label>
+					<select name="SHELL" id="SHELL">
+						<tmpl_var name="SHELL_LIST">
+					</select>
+				</p>
 				
 				<tmpl_var name="MAILUSER">
 

Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl	2007-07-07 17:04:12 UTC (rev 684)
+++ trunk/vhffs-panel/user/prefs.pl	2007-07-07 22:15:51 UTC (rev 685)
@@ -67,6 +67,7 @@
 
     my $theme = $cgi->param( "THEME" );
     my $lang = $cgi->param( "LANG" );
+    my $shell = $cgi->param( "SHELL" );
 
     my $pwd_change = 0;
     my $mail_change = 0;
@@ -81,7 +82,7 @@
 
 
 # Commit all the changes for the current user
-if( ( ! defined $firstname ) || ( ! defined $lastname ) || ( ! defined $city ) || ( ! defined $mail ) || ( ! defined $zipcode ) || ( ! defined $country ) || ( ! defined $address ) ) {
+if( ( ! defined $firstname ) || ( ! defined $lastname ) || ( ! defined $city ) || ( ! defined $mail ) || ( ! defined $zipcode ) || ( ! defined $country ) || ( ! defined $address ) || ( ! defined $shell ) ) {
     $panel->add_error( gettext( "CGI Error!" ) );
 } else {
     # We don't really care about what user use as firstname, lastname, ... we just
@@ -107,10 +108,16 @@
     if( $address !~ /^[^<">]+$/ ) {
         $panel->add_error( gettext( 'Address is not correct !') );
     }
-
     if( $pass1 ne $pass2 ) {
         $panel->add_error( gettext( "Passwords don't match" ) );
     }
+    my $valid=0;
+    foreach( Vhffs::Panel::User::list_shells( $vhffs ) ) {
+        $valid = 1 if($shell eq $_);
+    }
+    unless( $valid ) {
+        $panel->add_error( gettext( "Wanted shell is not in the shell list" ) );
+    }
     if(! $panel->has_errors) {
         $user->set_firstname(  $firstname );
         $user->set_lastname(  $lastname );
@@ -118,6 +125,7 @@
         $user->set_zipcode( $zipcode );
         $user->set_country( $country );
         $user->set_address( $address );
+	$user->set_shell( $shell );
 
         if( ( length( $pass1 ) > 1 ) && ( $pass1 eq $pass2 ) ) { 
             $pwd_change = 1;
@@ -262,6 +270,7 @@
 $template->param( TEXT_PASSWORD2 => gettext("Confirm Password") );
 $template->param( TEXT_LANG => gettext("Language") );
 $template->param( TEXT_THEME => gettext("Theme") );
+$template->param( TEXT_SHELL => gettext("Shell") );
 $template->param( TEXT_SEND => gettext("Modify") );
 
 $template->param( VALUE_USERNAME => $user->get_username ); 
@@ -327,6 +336,26 @@
 }
 $template->param( LANG_LIST => $langlist );
 
+
+# shells
+
+my @shells = Vhffs::Panel::User::list_shells( $vhffs );
+my $curshell = Vhffs::Panel::User::get_shell( $user );
+my $shelllist;
+foreach( @shells )
+{
+	if($curshell ne $_)
+	{
+		$shelllist .= "<option value=\"".$_."\">".$_."</option>\n";
+	}
+	else
+	{
+		$shelllist .= "<option value=\"".$_."\" selected=\"selected\">".$_."</option>\n";
+	}
+}
+$template->param( SHELL_LIST => $shelllist );
+
+
 if( $mailuser == 1 )
 {
 	use Vhffs::Services::MailUser;


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