[vhffs-dev] [svn] commit: r216 - in /trunk: ./ vhffs-api/src/Vhffs/ vhffs-api/src/Vhffs/Panel/ vhffs-api/src/Vhffs/Robots/ vhffs-api/src/Vhffs/Services/ vhffs-backend/src/pgsql/ vhffs-panel/largefile/ vhffs-robots/src/

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


Author: soda
Date: Sun Aug 20 18:51:10 2006
New Revision: 216

Log:
add COPYING file, vhffs is now under revised BSD
Debug class added, you can simply make a debuglog( "mystring" ) to print debug messages
begin largefile robots


Added:
    trunk/COPYING
    trunk/vhffs-api/src/Vhffs/Debug.pm
Modified:
    trunk/vhffs-api/src/Vhffs/Panel/Main.pm
    trunk/vhffs-api/src/Vhffs/Robots.pm
    trunk/vhffs-api/src/Vhffs/Robots/Group.pm
    trunk/vhffs-api/src/Vhffs/Services/LargeFile.pm
    trunk/vhffs-backend/src/pgsql/initdb.sql
    trunk/vhffs-panel/largefile/create.pl
    trunk/vhffs-panel/largefile/submit.pl
    trunk/vhffs-robots/src/create_largefile.pl
    trunk/vhffs-robots/src/refused_largefile.pl
    trunk/vhffs-robots/src/refused_web.pl

Modified: trunk/vhffs-api/src/Vhffs/Panel/Main.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Main.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Panel/Main.pm Sun Aug 20 18:51:10 2006
@@ -1,6 +1,9 @@
 #!/usr/bin/perl -w
 
 package Vhffs::Panel::Main;
+require Exporter;
+@ISA    = qw(Exporter);
+@EXPORT = qw( open_template display display_light );
 
 use POSIX qw(locale_h);
 use HTML::Template;
@@ -9,6 +12,7 @@
 use CGI;
 use CGI::Session;
 use strict;
+
 use Vhffs::Main;
 use Vhffs::User;
 use Vhffs::Group;
@@ -521,6 +525,14 @@
 {
 	my ( $class , $panel , $content, $cookie, $cookie2 ) = @_;
 
+	if( ref( $class ) eq 'HASH' )
+	{
+		$cookie2 = $cookie;
+		$cookie = $content;
+		$content = $panel;
+		$panel = $class;
+	}
+
 	my $maintemplate = $panel->{'template'};
 	$maintemplate->param( CENTRE => $content );
 
@@ -530,6 +542,7 @@
 	}
 
 	my $theme = Vhffs::Panel::User::get_theme( $panel->{'user'} );
+
 	if( $theme )
 	{
 		$maintemplate->param( THEME => $theme );
@@ -539,7 +552,6 @@
 		$maintemplate->param( THEME => "default" );
 	}
 
-#	print "Content-Type: text/html; charset=utf-8\n\n"
 
 	if( ! $cookie )
 	{
@@ -668,5 +680,30 @@
     }
 }
 
+sub open_template
+{
+	my ( $arg1 , $arg2 , $vhffs , $path , $template ,  $tmp );
+	$vhffs = shift;
+	$arg1 = shift;
+	$arg2 = shift;
+	$path = $vhffs->get_config->get_templatedir;
+
+
+	$tmp = shift;
+	
+	if( $arg2 )
+	{
+		$path .= "/" . $arg1 . "/" . $arg2 . ".tmpl";
+	}
+	else
+	{
+		$path .= "/" . $arg1 . ".tmpl";
+	}
+
+	$template = new HTML::Template( filename => $path  , die_on_bad_params => 0  );
+
+	return( $template );
+}
+
  
 1;

Modified: trunk/vhffs-api/src/Vhffs/Robots.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Robots.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Robots.pm Sun Aug 20 18:51:10 2006
@@ -1,4 +1,11 @@
 #!/usr/bin/perl
+no warnings 'redefine';
+
+package Vhffs::Robots;
+
+require Exporter;
+@ISA    = qw(Exporter);
+@EXPORT = qw( vhffs_log lock unlock );
 
 use Vhffs::Functions;
 use LockFile::Simple qw(lock trylock unlock);
@@ -8,7 +15,6 @@
 	LOGFILE  => "/var/log/vhffs"
 };
 
-package Vhffs::Robots;
 
 sub lock
 {

Modified: trunk/vhffs-api/src/Vhffs/Robots/Group.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Group.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Robots/Group.pm Sun Aug 20 18:51:10 2006
@@ -46,7 +46,6 @@
 		$group->add_history("Ok, Robots will create the directory");
 		Vhffs::Functions::create_dir( $hash );
 		$group->add_history("Ok, Robots finish create the directory");
-
 		if( defined $group->get_owneruid )
 		{
 			chown( $group->get_owneruid , $group->get_gid , $hash );

Modified: trunk/vhffs-api/src/Vhffs/Services/LargeFile.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Services/LargeFile.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Services/LargeFile.pm Sun Aug 20 18:51:10 2006
@@ -107,22 +107,13 @@
     {
 		$self->{'object_id'} = $oid;
     }
-    
-    
+   
     #Finally, create the object
-    $request = "INSERT INTO vhffs_largefile 
-				(filename,size,type,creating_date,owner_uid,owner_gid,object_id)
-				VALUES( '".$self->{'filename'} . "', 
-						'".$self->{'size'}."', 
-						'".$self->{'type'}."' , 
-						NOW() , 
-						'".$self->{'user'}->get_uid."',
-						'".$self->{'group'}->get_gid."' , 
-						'".$self->{'object_id'}."' 
-				)";
+    $request = "INSERT INTO vhffs_largefile (filename,size,type,creating_date,owner_uid,owner_gid,object_id)
+				 VALUES( ? , ? , ? , NOW() , ? , ? , ? )";
     $handle = $self->{'db'}->{'DB_WRITE'}->prepare( $request );
-    $handle->execute or return -2;
-    
+    $handle->execute( $self->{'filename'} , $self->{'size'} , $self->{'type'} , $self->{'user'}->get_uid , $self->{'group'}->get_gid , $self->{'object_id'} ) or return( -2 );
+
     return 1;
 }
 
@@ -138,10 +129,6 @@
 
 	$query = "SELECT * FROM vhffs_largefile WHERE filename ='".$self->{'filename'}."' AND owner_gid='".$self->{'group'}->get_gid."'";
 	$handle = $self->{'db'}->{'DB_READ'}->prepare( $query )  or return -1;
-
-	open ( TOTO , ">/tmp/log" );
-	print TOTO $query;
-	close TOTO;
 
 	$rows = $handle->execute() or return -3;
 
@@ -182,15 +169,15 @@
 	$self->{'end_date'} = "NULL" if( ! defined $self->{'end_date'} );
 
 	$query = "UPDATE vhffs_largefile SET 
-										size				=	'".$self->{'size'}."',
-										licence				=	'".$self->{'licence'}."',
-										username			=	'".$self->{'username'}."',
-										password			=	'".$self->{'password'}."',
-										hash				=	'".$self->{'hash'}."'
-										WHERE file_id=$self->{'file_id'}";
+										size = ? ,
+										licence = ? ,
+										username = ? ,
+										password = ? ,
+										hash = ?
+										WHERE file_id= ? ";
 	
 	$handle = $self->{'db'}->{'DB_WRITE'}->prepare($query);
-	$handle->execute or return -1;
+	$handle->execute( $self->{'size'} , $self->{'licence'} , $self->{'username'} , $self->{'password'} , $self->{'hash'} , $self->{'file_id'} )  or return -1;
 
 	return -2 if( $self->SUPER::commit < 0 );
 

Modified: trunk/vhffs-backend/src/pgsql/initdb.sql
==============================================================================
--- trunk/vhffs-backend/src/pgsql/initdb.sql (original)
+++ trunk/vhffs-backend/src/pgsql/initdb.sql Sun Aug 20 18:51:10 2006
@@ -296,8 +296,8 @@
 	password		varchar,
 	home			varchar,
 	ncheck			int4 DEFAULT '0',
-	virtual_uid		int4 DEFAULT nextval('seq_virtualuid'::text),
-	virtual_gid		int4 NOT NULL DEFAULT nextval('seq_virtualgid'::text),
+	virtual_uid		int4,
+	virtual_gid		int4,
 	owner_uid int4 REFERENCES vhffs_users( uid ), 
 	owner_gid int4 REFERENCES vhffs_groups( gid ),
 	object_id int4 REFERENCES vhffs_object( object_id ),

Modified: trunk/vhffs-panel/largefile/create.pl
==============================================================================
--- trunk/vhffs-panel/largefile/create.pl (original)
+++ trunk/vhffs-panel/largefile/create.pl Sun Aug 20 18:51:10 2006
@@ -28,7 +28,7 @@
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
-my $template = new HTML::Template( filename => $templatedir."/largefile/create.tmpl" );
+my $template = open_template( $vhffs , 'largefile' , 'create' );
 
 $template->param( TITLE => gettext("Host a file") );
 $template->param( FILENAME => gettext("Filename") );
@@ -41,4 +41,4 @@
 $template->param( SEND => gettext("Send") );
 $template->param( DESCRIPTION => gettext("Description") );
 
-display Vhffs::Panel::Main($panel, $template->output);
+display($panel, $template->output);

Modified: trunk/vhffs-panel/largefile/submit.pl
==============================================================================
--- trunk/vhffs-panel/largefile/submit.pl (original)
+++ trunk/vhffs-panel/largefile/submit.pl Sun Aug 20 18:51:10 2006
@@ -63,7 +63,7 @@
 }
 else
 {
-	$message = gettext( "An error occured while creating the object. Parameters are invalid or the file already exists." );
+	$message = gettext( "An error occured while creating the object. Parameters are invalid or the file already exists.$file" );
 }
 
 

Modified: trunk/vhffs-robots/src/create_largefile.pl
==============================================================================
--- trunk/vhffs-robots/src/create_largefile.pl (original)
+++ trunk/vhffs-robots/src/create_largefile.pl Sun Aug 20 18:51:10 2006
@@ -1,79 +1,42 @@
 #!/usr/bin/perl
 
-use POSIX qw( locale_h );
-use Locale::gettext;
+use Vhffs::Services::LargeFile;
+use Vhffs::Robots;
+use Vhffs::Functions;
 use Vhffs::Main;
-use Vhffs::Robots;
-use Vhffs::Robots::LargeFile;
-use Vhffs::Services::LargeFile;
-use Vhffs::Constants;
-use Vhffs::Functions;
 
-my $vhffs;
-my $files;
+
+my $vhffs = init Vhffs::Main;
+
+lock( $vhffs );
+
+my $files = Vhffs::Services::LargeFile::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION , undef, undef );
 my $file;
-my $login;
-my $password;
-my $user;
-my $lang;
-my $message;
-my $host;
-my $subject;
-
-#Init the main VHFFS subsystem
-$vhffs = init Vhffs::Main;
-
-#Create or wait the lockfile if the VHFFS configuration need it
-Vhffs::Robots::lock( $vhffs );
-
-bindtextdomain("vhffs", $vhffs->get_config->get_intldir);
-textdomain("vhffs");
-
-# Get ALL files to create
-$files = Vhffs::Services::LargeFile::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION );
+my $groupname;
+my $path;
+my $pass;
 
 foreach $file ( @{$files} )
 {
-	#If fetch, the file exists in the database
-	if( $file->fetch >= 0)
-	{
-		$user = $file->get_user;
-		$lang = Vhffs::Panel::User::get_lang( $user );
-		setlocale( LC_ALL , $lang ) if( defined $lang );
+	$groupname = $file->get_group->get_groupname;
 
-		Vhffs::Robots::vhffs_log( sprintf( "LARGEFILE: Will create the directory and account for file %s" , $file->get_filename ) );
+    $path = $vhffs->get_config->get_datadir. "/largefile/queue/" . substr( $groupname , 0 , 1 ) . "/" . substr( $groupname , 1 , 1 ) . "/" . $groupname;    
 
-		$login = Vhffs::Robots::LargeFile::find_login( $vhffs , $file );
-		$password = Vhffs::Functions::generate_random_password( );
+	Vhffs::Functions::create_dir( $path );
+	chmod( 0770 , $path );
+	chown( $file->get_user->get_uid , $file->get_group->get_gid , $path );
 
-		$file->set_username( $login );
-		$file->set_password( $password );
-		$file->set_status( Vhffs::Constants::ACTIVATED );
+	$pass = Vhffs::Functions::generate_random_password;
 
-		if( $file->commit < 0 )
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "LARGEFILE: error while creating the file %s" , $file->get_filename ) );
-			exit( 1 );
-		}
+	$file->set_password( $pass );
+	$file->set_username( $groupname );
 
-		$host = $vhffs->get_config->get_upload_host;
-		$message  = sprintf( gettext( "Your request for hosting the file %s was accepted.\n" ) , $file->get_filename );
-		$message .= sprintf( gettext( "Now, you have to log in on the ftp server %s with\n" ) , $host );
-		$message .=          gettext( "the following login and password :\n" );
-		$message .=	sprintf( gettext( "Username: %s\n" ) , $file->get_username );
-		$message .=	sprintf( gettext( "Password: %s\n" ) , $password );
-		$message .=          gettext( "You have 24H to put your file on the FTP server. After\n" );
-		$message .=          gettext( "this delay, your request will be delete\n" );
+	$file->commit;
 
-		$subject = sprintf( gettext( "Your request on %s for hosting file" ) , $vhffs->get_config->get_host_name );
-
-		Vhffs::Functions::send_mail( $vhffs->get_config->get_moderator_mail , $user->get_mail , $subject , $message )
-
-
-	}
+	print $file->get_filename . "\n" ;
 }
 
+unlock( $vhffs );
 
-#Finally, delete the lockfile
-Vhffs::Robots::unlock( $vhffs );
 exit 0;
+

Modified: trunk/vhffs-robots/src/refused_largefile.pl
==============================================================================
--- trunk/vhffs-robots/src/refused_largefile.pl (original)
+++ trunk/vhffs-robots/src/refused_largefile.pl Sun Aug 20 18:51:10 2006
@@ -1,4 +1,6 @@
 #!/usr/bin/perl
+
+no warnings 'redefine';
 
 use POSIX qw(locale_h);
 use locale;
@@ -7,9 +9,9 @@
 use Vhffs::Main;
 use Vhffs::User;
 use Vhffs::Group;
-use Vhffs::Robots;
 use Vhffs::Services::LargeFile;
 use Vhffs::Panel::User;
+use Vhffs::Robots;
 
 
 my $vhffs;
@@ -37,7 +39,7 @@
 		setlocale( LC_ALL , $lang ) if( defined $lang );
 		if( $user->fetch > 0 )
 		{
-			$message  = sprintf( gettext("Your request for hosting the file: %s") , $object->get_filename);
+			$message  = sprintf( gettext("Your file hosting request for the file : %s\n") , $object->get_filename);
 			$message .= gettext("has been refused by the Moderators team")."\n";
 			$message .= gettext("In hope to keep you in our hosting service")."\n\n";
 			if( length( $object->get_description ) > 1 )
@@ -49,7 +51,7 @@
 			$message .= gettext("Cheers,")."\n";
 			$message .= gettext("The Moderator and Admin team");
 
-			$subject = gettext("Your file hosting request");
+			$subject = gettext("Your file-hosting request");
 			Vhffs::Functions::send_mail( $vhffs->get_config->get_master_mail , $user->get_mail , $subject , $message );
 		}
 		
@@ -59,5 +61,4 @@
 
 
 Vhffs::Robots::unlock( $vhffs );
-
 exit 0;

Modified: trunk/vhffs-robots/src/refused_web.pl
==============================================================================
--- trunk/vhffs-robots/src/refused_web.pl (original)
+++ trunk/vhffs-robots/src/refused_web.pl Sun Aug 20 18:51:10 2006
@@ -49,7 +49,7 @@
 			$message .= gettext("Cheers,")."\n";
 			$message .= gettext("The Moderator and Admin team");
 
-			$subject = gettext("Your Mail hosting request");
+			$subject = gettext("Your hosting request");
 			Vhffs::Functions::send_mail( $vhffs->get_config->get_master_mail , $user->get_mail , $subject , $message );
 		}
 		




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