summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-08-02 06:55:26 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-08-02 06:55:26 +0000
commit2a008dc4abc86385b3059f82a2419b9514882dfe (patch)
treef5925786cb4cd1798c6dd8ff8c8fe235cabe0b38
parentba04cd2729b62daa1a7aa2d35814992c68c38430 (diff)
downloadampache-2a008dc4abc86385b3059f82a2419b9514882dfe.tar.gz
ampache-2a008dc4abc86385b3059f82a2419b9514882dfe.tar.bz2
ampache-2a008dc4abc86385b3059f82a2419b9514882dfe.zip
most of the new upload system, barely tested and not finished...
-rw-r--r--bin/quarantine_migration.php.inc150
-rw-r--r--config/ampache.cfg.php.dist8
-rwxr-xr-xdocs/CHANGELOG2
-rw-r--r--lib/class/catalog.class.php1
-rw-r--r--lib/class/view.class.php3
-rw-r--r--lib/general.lib.php16
-rw-r--r--lib/mpd.php2
-rw-r--r--lib/upload.php236
-rw-r--r--modules/init.php13
-rw-r--r--templates/show_upload.inc162
-rw-r--r--templates/show_uploads.inc69
-rw-r--r--upload.php546
12 files changed, 789 insertions, 419 deletions
diff --git a/bin/quarantine_migration.php.inc b/bin/quarantine_migration.php.inc
new file mode 100644
index 00000000..05c48a17
--- /dev/null
+++ b/bin/quarantine_migration.php.inc
@@ -0,0 +1,150 @@
+<?php
+/*
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ created by RosenSama 2005
+
+ call: php quarantine_migration.php
+
+*/
+
+/* This isn't working yet, don't let em try! */
+exit();
+
+$no_session='1';
+require_once( '../modules/init.php' );
+require_once( '../lib/upload.php' );
+usage();
+
+// check for correct db version
+$sql = "SELECT value FROM update_info WHERE `key` = 'db_version'";
+$db_results = mysql_query( $sql, dbh() );
+if( mysql_num_rows( $db_results ) != 1 ) {
+ $text = _( 'expected exactly 1 row in update_info table' );
+ cli_out( $text, 0 );
+ exit;
+}
+$results = mysql_fetch_object( $db_results );
+$db_ver = $results->value;
+
+if( $db_ver < $reqd_db_ver ) {
+ $text = _( "this script requires database version $reqd_db_ver or higher" );
+ cli_out( $text, 0 );
+ exit;
+}
+
+// grab list of files from table
+$sql = "SELECT id, file, user FROM upload WHERE action = 'quarantine'";
+$db_results = mysql_query( $sql, dbh() );
+while( $results = mysql_fetch_object( $db_results ) ) {
+ $file = $results->file
+ $dir = dirname( $file );
+ $cat_id = dir_catalog( $dir );
+ if( $cat_id != -1 ) { // then this file is is a catalog hierarchy
+ //check if it's been added to the catalog already
+ $catalog = new Catalog( $cat_id );
+ if( $catalog->check_local_mp3( $file ) ) {
+ $text = $file . _( ' is already in a catalog' );
+ cli_out( $text, 0 );
+ continue;
+ }
+ }
+
+ // getting ready to move
+ // check for each user's quar dir pref and source dir
+ // can we write to both?
+ $upload_user = new User( 0, $results->user );
+ $quar_dir = $upload_user->prefs['quarantine_dir'];
+ if( !is_writable( $quar_dir ) || !is_writable( $dir ) ) {
+ $text = $file . _( ' cannot write to file directory or quarantine directory' );
+ cli_out( $text, 0 );
+ continue;
+ }
+// move files
+ $dest_file = $quar_dir . '/' . basename( $file );
+ $file_move_ok = rename( $file, $dest_filename );
+ if( !$file_move_ok ) {
+ $text = $file . _( ' could not move file to quarantine directory ' ) . $dest_filename;
+ cli_out( $text, 0 );
+ continue;
+ } else {
+ $text = _( 'Moved ' ) . $file . _( ' to ' ) . $dest_filename . ".\n";
+ cli_out( $text, 1 );
+ }
+ // update upload table
+ $sql = "UPDATE upload SET file = $dest_filename WHERE id = $results->id";
+ $db_results = mysql_query( $sql, dbh() );
+} // while there are quarantined entries in the upload table
+
+exit;
+
+/*!
+ @function usage()
+ @discussion echo the help for this script
+*/
+
+function usage( ) {
+ $text = _( "
+*** WARNING ***
+This script will attempt to move your music files!
+*** WARNING ***
+
+This script will process any pending quarantine files for the new uploads system.
+You must be running update $reqd_db_ver or higher. Your old upload directory and
+your new quarantine directory must be readable and writable by your webserver user.
+It must be run from the ampache/bin directory.
+ \n" );
+ cli_out( $text, 1 );
+
+ $text = _( "Continue? (Y/N):\t" );
+ cli_out( $text, 1 );
+
+ // grab a character ignoring whitespace
+ do {
+ $input= fgetc( STDIN );
+ } while ( trim( $input ) == '' );
+
+ if( $input != 'Y' ) {
+ exit;
+ }
+} // usage()
+
+/*!
+ @function cli_out()
+ @discussion util for error formatting
+ @param $text the message to be output
+ @param $mode to STDERR (0) or STDOUT (1, default)
+*/
+
+function cli_out( $text, $mode = 1 ) {
+ switch( $mode ) {
+ case 0:
+ $dest = STDERR;
+ $pre = _( "Error: " );
+ $post = _( "!\n" );
+ break;
+ case 1:
+ default:
+ $dest = STDOUT;
+ $pre = "";
+ $post = "";
+ }
+ fwrite( $dest, $pre . $text . $post );
+} // error_out
+
+
+
+?>
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist
index 38940ad4..7bf9ff36 100644
--- a/config/ampache.cfg.php.dist
+++ b/config/ampache.cfg.php.dist
@@ -168,6 +168,14 @@ use_auth = "yes"
# DEFAULT: folder.jpg
#album_art_preferred_filename = "folder.jpg"
+# Resize Images * Requires PHP-GD *
+# Set this to true if you want Ampache to resize the Album
+# art on the fly, this increases load time and CPU useage
+# and also requires the PHP-GD library. This is very usefull
+# If you have high-quality album art and a small upload cap
+# DEFAULT: false
+#resize_images = "false"
+
# Album Art Gather Order
# Simply arrange the following in the order you would like
# ampache to search if you want to disable one of the search
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 3d8aefb2..434577e6 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -23,6 +23,8 @@
- Correctly deleted the session when deleting a user
- Added Search Bar to main page (Thx sigger)
- Added British English (Thx ??? <I need to look it up>)
+ - Added optional automatic resizing of thumbnails using php-gd
+ - Improved Upload System (Thx Rosensama)
--------------------------------------------------------------------------
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 090dc005..2ce3532c 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -1834,7 +1834,6 @@ class Catalog {
} // insert_remote_song
-
/*!
@function check_remote_song
@discussion checks to see if a remote song exists in the database or not
diff --git a/lib/class/view.class.php b/lib/class/view.class.php
index f9de4ee6..7d9bf79f 100644
--- a/lib/class/view.class.php
+++ b/lib/class/view.class.php
@@ -4,9 +4,6 @@
Copyright (c) 2004 Ampache.org
All rights reserved.
- $CVSHeader: ampache/modules/class/artist.php,v 1.1 2004/03/25 09:12:57 vollmerk Exp $
- $Source: /data/cvsroot/ampache/modules/class/artist.php,v $
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
diff --git a/lib/general.lib.php b/lib/general.lib.php
index f78a46b8..e343b75c 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -727,6 +727,21 @@ ECHO;
} // show_info_box
+/*!
+ @function get_file_extension
+ @discussion returns all characters after the last "." in $filename
+ Should I be using pathinfo() instead?
+*/
+function get_file_extension( $filename ) {
+ $file_name_parts = explode( ".", $filename );
+ $num_parts = count( $file_name_parts );
+ if( $num_parts <= 1 ) {
+ return;
+ } else {
+ return $file_name_parts[$num_parts - 1];
+ }
+} // get_file_extension
+
/**
* tbl_name
* This function takes a SQL table name and returns it with any prefix
@@ -741,5 +756,4 @@ function tbl_name($table) {
} // tbl_name
-
?>
diff --git a/lib/mpd.php b/lib/mpd.php
index d4ee10d1..5eacddad 100644
--- a/lib/mpd.php
+++ b/lib/mpd.php
@@ -35,7 +35,7 @@ function addToPlaylist( $myMpd, $song_ids=array()) {
if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
$ds = $GLOBALS['user']->prefs['sample_rate'];
}
- $song_url = conf('web_path') . "/play/index.php?song=$song_id&uid=" . $GLOBALS['user']->username . "&sid=$sess_id&ds=$ds&name=." . $song->type;
+ $song_url = conf('web_path') . "/play/index.php?song=$song_id&uid=" . $_SESSION['userdata']['username'] . "&sid=$sess_id&ds=$ds&name=." . $song->type;
if (is_null( $myMpd->PlAdd($song_url) ) ) {
$log_line = _("Error") . ": " . _("Could not add") . ": " . $song_url . " : " . $myMpd->errStr;
echo "<font class=\"error\">$log_line</font><br />\n";
diff --git a/lib/upload.php b/lib/upload.php
new file mode 100644
index 00000000..b78e4e5b
--- /dev/null
+++ b/lib/upload.php
@@ -0,0 +1,236 @@
+<?php
+/*
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+/*!
+ @function check_upload_extension
+ @discussion checks the extension against the allow list
+*/
+function check_upload_extension($name='file') {
+
+
+ $filename = $_FILES[$name]['name'];
+
+ $path_parts = pathinfo($filename);
+
+ $extension = $path_parts['extension'];
+
+ $allowed_extensions = "/" . conf('catalog_file_pattern') . "/";
+ if (preg_match($allowed_extensions,$extension)) {
+ return true;
+ }
+
+ if (conf('debug')) {
+ log_event($_SESSION['userdata']['username'],' upload ',"Error: Invalid Extension $extension");
+ }
+
+ return false;
+
+} // check_upload_extension
+
+/*!
+ @function check_upload_size
+ @discussion checks the filesize of the upload
+*/
+function check_upload_size($name='file') {
+
+
+ $size = $_FILES[$name]['size'];
+
+ if ($size > conf('max_upload_size')) {
+ if (conf('debug')) {
+ log_event($_SESSION['userdata']['username'],' upload ',"Error: Upload to large, $size");
+ }
+ return false;
+ }
+
+ return true;
+
+} // check_upload_size
+
+/*!
+ @function check_upload_directory
+ @discussion this functions checks to make sure that you can actually write to the upload directory
+*/
+function check_upload_directory($directory) {
+
+ /* We need to make sure we can write to said dir */
+ if (@is_writable($directory)) {
+ return true;
+ }
+
+ return false;
+
+} // check_upload_directory
+
+/*!
+ @function find_upload_catalog
+ @dicussion all upload directories must be contained within another catalog, this checks
+ to make sure that is true. returns id of catalog found or false
+*/
+function find_upload_catalog($directory) {
+ $cat_error = -1;
+ $cat_id = $cat_error;
+
+ $sql = "SELECT id, path FROM catalog";
+ $db_results = mysql_query($sql, dbh());
+
+ while( $results = mysql_fetch_object($db_results)) {
+
+ if( substr($dir, 0, strlen($results->path)) == $results->path ) {
+ return $results->id;
+ } // end if file path is in a catalog path
+
+ } // end while loop through catalog records
+
+ return false;
+
+} // find_upload_catalog
+
+/*!
+ @function upload_file
+ @discussion this uploads a file to ampache
+*/
+function upload_file($file,$target_directory) {
+
+ /* Build target file names */
+ $full_filename = $target_directory . "/" . $_FILES[$file]['name'];
+
+ /* Check to make sure the file doesn't exist already */
+ if (file_exists($full_filename)) {
+ $GLOBALS['error']->add_error($file,"Error: $full_filename already exists");
+ return false;
+ }
+
+ /* Attempt to move the file */
+ if (!$upload_code = @move_uploaded_file($_FILES[$file]['tmp_name'],$full_filename)) {
+ $GLOBALS['error']->add_error($file,"Error: Unable to move $full_filename");
+ return false;
+ }
+
+ return $full_filename;
+
+} // upload_file
+
+/*!
+ @function insert_quarantine_record
+ @discussion this inserts the record that a file has been added
+*/
+function insert_quarantine_record($username,$action,$filename) {
+
+ /* First make sure this file isn't listed already */
+ $sql = "SELECT id FROM " . tbl_name('upload') . " WHERE file='" . sql_escape($filename) . "'";
+ $db_results = mysql_query($sql, dbh());
+
+ /* If no rows, insert using ugly sql statement */
+ if (!mysql_num_rows($db_results)) {
+ $sql = "INSERT INTO " . tbl_name('upload') . " (`user`,`file`,`action`,`addition_time`)" .
+ " VALUES ('$username','" . sql_escape($filename) . "','$action','" . time() . "')";
+ $db_results = mysql_query($sql, dbh());
+ }
+
+ else {
+ $sql = "UPDATE " . tbl_name('upload') . " SET action='$action' WHERE file='" . sql_escape($filename) . "'";
+ $db_results = mysql_query($sql, dbh());
+ }
+
+} // insert_quarantine_record
+
+/*!
+ @function update_quarantine_record
+ @discusison this updates an existing quarantine record
+*/
+function update_quarantine_record($id, $new_action) {
+
+ $sql = "UPDATE " . tbl_name('upload') . " SET action='$new_action' WHERE id='" . sql_escape($id) . "'";
+ $db_results = mysql_query($sql, dbh());
+
+ return true;
+
+} // update_quarantine_record
+
+/*!
+ @function get_uploads
+ @discussion gets uploads and returns an array of em
+*/
+function get_uploads() {
+
+ $sql = "SELECT * FROM " . tbl_name('upload');
+ $db_results = mysql_query($sql, dbh());
+
+ $audio_info = new Audioinfo();
+ $results = array();
+
+ while ($r = mysql_fetch_assoc($db_results)) {
+
+ /* Create the Audioinfo object and get info */
+ $data = $audio_info->Info($r['file']);
+ $data['file'] = $r['file'];
+
+ $key = get_tag_type($data);
+
+ /* Fill Empty info from filename/path */
+ $data = clean_tag_info($data,$key,$data['file']);
+
+ $data['id'] = $r['id'];
+ $data['user'] = $r['user'];
+ $data['action'] = $r['action'];
+ $data['addition_time'] = $r['addition_time'];
+
+ $results[] = $data;
+
+ } // end while
+
+ return $results;
+
+} // get_uploads
+
+/*!
+ @function show_upload
+ @discussion This shows the upload templates
+*/
+function show_upload() {
+
+ require_once( "templates/show_upload.inc" );
+ echo( "\n<br /><br />\n" );
+ require_once( "templates/show_uploads.inc" );
+
+} // show_upload
+
+/*!
+ @function report_file_error
+ @discussion use with $_FILES and move_uploaded_file
+ if move_uploaded_file returns false (error), pass
+ $file['error'] here for interpretation
+*/
+function report_file_error( $error_code ) {
+
+ $codes = array(
+ 0 => _( "The file uploaded successfully" ),
+ 1 => _( "The uploaded file exceeds the upload_max_filesize directive in php.ini" ),
+ 2 => _( "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form" ),
+ 3 => _( "The uploaded file was only partially uploaded" ),
+ 4 => _( "No file was uploaded" ),
+ 6 => _( "Missing a temporary folder" )
+ );
+
+ return $codes[$error_code];
+
+} // report_file_error
+
+?>
diff --git a/modules/init.php b/modules/init.php
index 51e120b8..efcef4b8 100644
--- a/modules/init.php
+++ b/modules/init.php
@@ -83,7 +83,7 @@ if (!$results['conf']['allow_stream_playback']) {
}
$results['conf']['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['conf']['web_path'];
-$results['conf']['version'] = '3.3.2-Alpha2 Build (002)';
+$results['conf']['version'] = '3.3.2-Alpha2 Build (003)';
$results['conf']['catalog_file_pattern']= 'mp3|mpc|m4p|m4a|mp4|aac|ogg|rm|wma|asf|flac|spx';
$results['libglue']['local_table'] = 'session';
$results['libglue']['local_sid'] = 'id';
@@ -173,11 +173,8 @@ require_once(conf('prefix') . "/modules/catalog.php");
require_once(conf('prefix') . "/modules/id3/audioinfo.class.php");
require_once(conf('prefix') . "/modules/amazon/Snoopy.class.php");
require_once(conf('prefix') . "/modules/amazon/AmazonSearchEngine.class.php");
-
-if (conf('xml_rpc')) {
- require_once(conf('prefix') . "/modules/xmlrpc/xmlrpc.inc");
- require_once(conf('prefix') . "/lib/xmlrpc.php");
-}
+require_once(conf('prefix') . "/lib/xmlrpc.php");
+require_once(conf('prefix') . "/modules/xmlrpc/xmlrpc.inc");
if (conf('allow_slim_playback')) {
require_once(conf('prefix') . "/modules/slimserver/slim.class.php");
@@ -187,6 +184,10 @@ if (conf('allow_mpd_playback')) {
require_once(conf('prefix') . "/modules/mpd/mpd.class.php");
}
+if (conf('allow_xmms2_playback')) {
+ require_once(conf('prefix') . "/modules/xmms2/xmms2.class.php");
+}
+
// Classes
require_once(conf('prefix') . "/lib/class/catalog.class.php");
require_once(conf('prefix') . "/lib/class/stream.class.php");
diff --git a/templates/show_upload.inc b/templates/show_upload.inc
index 2fbef3e6..8cc7e8f4 100644
--- a/templates/show_upload.inc
+++ b/templates/show_upload.inc
@@ -1,84 +1,78 @@
-<?php
-/*
-
- Copyright (c) 2001 - 2005 Ampache.org
- All rights reserved.
-
- *Created by Lamar*
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
-?>
-<center>
- <h3>
- <?php echo _("Please Ensure All Files Are Tagged Correctly"); ?>!<br />
- </h3>
- <p>
- <?php echo _("Ampache relies on id3 tags to sort data. If your file is not tagged it may be deleted."); ?>
- </p>
-
-<form action="<?php echo conf('web_path'); ?>/upload.php?" method="post" name="upload_form" enctype="multipart/form-data" id="upload_form">
- <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo _("max_upload_size"); ?>" />
- <table class="tabledata" cellspacing="0" cellpadding="0" border="0" width="90%" align="center">
- <tr align="center">
- <td>
- <input size="40" type="file" name="ul_path1" id="ul_path1" />
- </td>
- </tr>
- <tr align="center">
- <td>
- <input size="40" type="file" name="ul_path2" id="ul_path2" />
- </td>
- </tr>
- <tr align="center">
- <td>
- <input size="40" type="file" name="ul_path3" id="ul_path3" />
- </td>
- </tr>
- <tr align="center">
- <td>
- <input size="40" type="file" name="ul_path4" id="ul_path4" />
- </td>
- </tr>
- <tr align="center">
- <td>
- <input type="hidden" name="action" value="upload_now" />
- <input type="submit" value="<?php echo _("Upload"); ?>" />
- </td>
- </tr>
- </table>
-</form>
-
-<table align="center" border = "0">
- <tr>
- <td>
- Acceptable formats include:
- <ul>
- <li>.mp3</li>
- <li>.ogg</li>
- <li>.wma</li>
- <li>.flac</li>
- </ul>
- </td>
- </tr>
-</table>
-<!--
-<p>
- <?php echo _("Minimum Accepted Bitrate is"); ?> <?php echo $site->prefs['upload_bitrate'] ?> kbps
-</p>
--->
-</center>
-
+<?php
+/*
+
+ Copyright (c) 2001 - 2005 Ampache.org
+ All rights reserved.
+
+ *Created by Lamar*
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+?>
+
+<form action="<?php echo conf('web_path'); ?>/upload.php?" method="post" name="upload_form" enctype="multipart/form-data" id="upload_form">
+<table class="text-box" cellspacing="0" cellpadding="0" border="0">
+<tr>
+ <td>
+ <h3><?php echo _("Uploading Music to Ampache"); ?><br></h3>
+ <p>
+ <b><?php echo _("The following Audio file formats are supported"); ?></b>
+ <ul>
+ <li>OGG</li>
+ <li>Mp3</li>
+ <li>Mpc</li>
+ <li>Flac</li>
+ <li>WMA</li>
+ <li>Mp4/M4a/AAC</li>
+ </ul>
+ </p>
+ <?php $GLOBALS['error']->print_error('general'); ?>
+ </td>
+</tr>
+<tr>
+ <td>
+ <input size=40 type="file" name="ul_path1" id="ul_path1">
+ <?php $GLOBALS['error']->print_error('ul_path1'); ?>
+ </td>
+</tr>
+<tr>
+ <td>
+ <input size=40 type="file" name="ul_path2" id="ul_path2">
+ <?php $GLOBALS['error']->print_error('ul_path2'); ?>
+ </td>
+</tr>
+<tr>
+ <td>
+ <input size=40 type="file" name="ul_path3" id="ul_path3">
+ <?php $GLOBALS['error']->print_error('ul_path3'); ?>
+ </td>
+</tr>
+<tr>
+ <td>
+ <input size=40 type="file" name="ul_path4" id="ul_path4">
+ <?php $GLOBALS['error']->print_error('ul_path3'); ?>
+ </td>
+</tr>
+<tr>
+ <td>
+ <input type="hidden" name="action" value="upload">
+ <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo _("max_upload_size"); ?>" />
+ <input type="submit" value="<?php echo _("Upload"); ?>">
+ </td>
+</tr>
+</table>
+</form>
+
diff --git a/templates/show_uploads.inc b/templates/show_uploads.inc
new file mode 100644
index 00000000..04d43dd3
--- /dev/null
+++ b/templates/show_uploads.inc
@@ -0,0 +1,69 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2005 Ampache.org
+ All rights reserved.
+
+ *Created by Rosensama*
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+/* Get the current Quarantined Uploads */
+$uploads = get_uploads();
+
+if (count($uploads)) {
+?>
+<table class="tabledata" cellspacing="0" cellpadding="0" border="1" align="center">
+<tr class="table-header">
+ <td><?php echo _('Action'); ?></td>
+ <td><?php echo _('Status'); ?></td>
+ <td><?php echo _('Song'); ?></td>
+ <td><?php echo _('Artist'); ?></td>
+ <td><?php echo _('Album'); ?></td>
+ <td><?php echo _('Genre'); ?></td>
+ <td><?php echo _('Time'); ?></td>
+ <td><?php echo _('Bitrate'); ?></td>
+ <td><?php echo _('Size'); ?></td>
+ <td><?php echo _('Filename'); ?></td>
+ <td><?php echo _('User'); ?></td>
+ <td><?php echo _('Date'); ?></td>
+</tr>
+<?php foreach ($uploads as $upload) { ?>
+<tr class="<?php echo flip_class(); ?>">
+ <?php if($GLOBALS['user']->has_access(100)) { ?>
+ <td>
+ <a href="<?php echo conf('web_path'); ?>/upload.php?action=add&id=<?php echo $upload['id']; ?>"><?php echo _('Add'); ?></a>&nbsp;|&nbsp;
+ <a href="<?php echo conf('web_path'); ?>/upload.php?action=delete&id=<?php echo $upload['id']; ?>"><?php echo _('Delete'); ?></a>
+ </td>
+ <?php } else { ?>
+ <td>N/A</td>
+ <?php } ?>
+ <td><?php echo ucfirst($upload['action']); ?></td>
+ <td><?php echo $upload['title']; ?></td>
+ <td><?php echo $upload['artist']; ?></td>
+ <td><?php echo $upload['album']; ?></td>
+ <td><?php echo $upload['time']; ?></td>
+ <td><?php echo $upload['genre']; ?></td>
+ <td><?php echo intval($upload['bitrate']/1000); ?> - <?php echo $upload['mode']; ?></td>
+ <td><?php echo sprintf("%.2f",($upload['size']/1048576)); ?>MB</td>
+ <td><?php echo $upload['file']; ?></td>
+ <td><?php echo $upload['user']; ?></td>
+ <td><?php echo date('m/d/Y H:i:s',$upload['addition_time']); ?></td>
+</tr>
+<?php } ?>
+</table>
+<?php } // if count uploads ?>
diff --git a/upload.php b/upload.php
index 4619d111..367efe0a 100644
--- a/upload.php
+++ b/upload.php
@@ -1,323 +1,223 @@
-<?php
-/*
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
-/*
-
- Copyright (c) 2003 Lamar
- All rights reserved.
-
- **Revised by Vollmerk**
-
- upload.php script.
- saves all uploaded files to the temp/ directory
- then processes the files and moves them to the
- proper directory.
-
- There are two basic modes of operation. HTML
- mode and GUI mode. If GUI mode is enabled a response
- with header 200 will be sent to the GUI.
-
-*/
-
-require_once ("modules/init.php");
-
-
-
-// Set page header
-show_template('header');
-show_menu_items('Upload');
-
-// Access Control
-if(!$user->prefs['upload'] || conf('demo_mode')) {
- access_denied();
-}
-
-/* Action Settings */
-$action = scrub_in($_REQUEST['action']);
-
-
-/*
- FILE UPLOAD SECTION
- This section handles file uploads. File types should
- be declared in the $types hash. This will provide
- an easy lookup mechanism.
-*/
-$types = array(
- 'mp3'=>'music',
- 'MP3'=>'music',
- 'ogg'=>'music',
- 'OGG'=>'music',
- 'WMA'=>'music',
- 'FLAC'=>'music',
- 'flac'=>'music',
- 'm4a' =>'music',
- 'aac' =>'music',
- '.gz'=>'compressed',
- 'tar'=>'compressed',
- 'zip'=>'compressed',
- 'ZIP'=>'compressed',
- );
-
-/* Upload Section Which Processes All Files Sent As Post */
-$audio_info = new Audioinfo();
-
-switch ($action) {
- case 'upload_now':
- // Verify the needed settings are in place
- if (!@chdir($user->prefs['upload_dir']) || strlen($user->prefs['upload_dir']) < 1) {
- break;
- }
-
- //FIXME: Set which catalog it goes into somewhere....
- $sql = "SELECT * FROM catalog LIMIT 1";
- $db_results = mysql_query($sql, dbh());
-
- $results = mysql_fetch_object($db_results);
-
- $catalog = new Catalog($results->id);
-
- // Create arrays
- $filelist = array();
-
- foreach($_FILES as $tagname=>$file){
- /* Skip blank file names */
-
- if( strlen($file['name'] ) ){
-
- // Determine tempfile name
- $tempfile = $file['tmp_name'];
-
- // Determine real file name
- $realname = $user->prefs['upload_dir'] . "/" . $file['name'];
-
- /* Determine Extension */
- $ext = substr( $file['name'], -3 );
-
- /* Prevent Unauthorized file types */
- if( $types[$ext] == 'compressed' ){
- // This section is currently disabled
- }
- elseif( $types[$ext] == 'music' ){
- $error = @move_uploaded_file($tempfile, $realname );
- if( $error )
- {
- $filelist = array( $realname => $file['name'] );
- }
- else{
- switch ($file['error']) {
- case '1':
- $error_text = _("The uploaded file exceeds the upload_max_filesize directive in php.ini");
- break;
- case '2':
- $error_text = _("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.");
- break;
- case '3':
- $error_text = _("The uploaded file was only partially uploaded.");
- break;
- case '4':
- $error_text = _("No file was uploaded.");
- break;
- default:
- $error_text = _("An Unknown Error has occured.");
- break;
- } // end switch
- if (conf('debug')) {
- log_event($_SESSION['userdata']['username'],'upload',$error_text);
- }
- $message[$file['name']] .= "Error: $error_text";
- $errorenum[$file['name']]=true;
- }
- } // end if known
- // If unknown filetype
- else{
- $message[$file['name']] .= "Error: Unsupported File Type- $ext<br />";
- $errorenum[$file['name']]=true;
- }
- // foreach through files uploaded
- foreach( $filelist as $fullpath => $music ) {
-
- // If we are quarantining the file
- if ($user->prefs['quarantine']) {
- // Log the upload but don't do anything
- $message[$music] .= _("Successfully-Quarantined");
- /* Log the upload */
- $sql = "INSERT INTO upload (`user`,`file`,`addition_time`)" .
- " VALUES ('$user->username','" . sql_escape($fullpath) . "','" . time() . "')";
- $db_results = mysql_query($sql, dbh());
- } // if quarantine
-
- // Go ahead and insert the file
- else {
- $catalog->insert_local_song($fullpath,filesize($fullpath));
- $message[$music] .= _("Successfully-Cataloged");
- } // end foreach
- flush();
- }
- }
-
- } // end foreach
-
- flush();
- /* Display Upload results */
- if( $message ){
- print( "<table align='center'>\n" );
- print( "<th>Filename</th><th>Result</th>\n" );
-
- foreach ( $message as $key => $value ){
- if( $errorenum[$key] ){
- $color="color='red'";
- }
- else{
- $color="color='green'";
- }
- print( "<tr>\n");
- print( "<td><font $color>$key</font></td><td><font $color>$value</font></td>\n");
- print( "</tr>\n");
- }
- print( "</table>\n" );
- }
- require_once(conf('prefix') . "/templates/show_upload.inc");
- break;
- case 'add':
- case 'delete':
- default:
- require_once(conf('prefix') . "/templates/show_upload.inc");
- break;
-} // end of switch on action
-
-echo "\n<br /><br />\n";
-
-/*
- SHOW QUARANTINE SONGS
- This Section Displays Quarantined Songs
- Always process all files in quarantine directory.
- Make a list (and check it twice)
-*/
-$songs = array();
-
-if ( $handle = @opendir($user->prefs['upload_dir'] ) ){
- /* Loop Through the directory */
- while( false !== ($file = readdir( $handle ))){
-
- /* Find extension */
- $ext = substr( $file, -4 );
-
- if(( $ext == '.mp3' )||( $ext == '.ogg' )){
- $songs[$file]=$user->prefs['upload_dir'] . "/" . "$file";
- }
- }
-} // end if upload_dir
-?>
-
-<table class="tabledata" cellspacing="0" cellpadding="0" align="center">
- <tr class="table-header">
- <td><?php echo _("Action"); ?></td>
- <td><?php echo _("Song"); ?></td>
- <td><?php echo _("Artist"); ?></td>
- <td><?php echo _("Album"); ?></td>
- <td><?php echo _("Genre"); ?></td>
- <td><?php echo _("Time"); ?></td>
- <td><?php echo _("Bitrate"); ?></td>
- <td><?php echo _("Size"); ?></td>
- <td><?php echo _("Filename"); ?></td>
- <td><?php echo _("User"); ?></td>
- <td><?php echo _("Date"); ?></td>
- </tr>
-
-<?
- /* Only populate table if valid songs exist */
- if( sizeof($songs) ) {
-
- /* Get file info */
- $audio_info = new Audioinfo();
- $order = conf('id3tag_order');
-
- foreach( $songs as $file=>$song ){
-
- if( $class == "odd" ){
- $class = "even";
- }
- else{
- $class = "odd";
- }
-
- $sql = "SELECT user,addition_time FROM upload WHERE file = '$song'";
- $db_result = mysql_query($sql, dbh());
-
- if( $r = mysql_fetch_object($db_result) ){
- $temp_user = new User($r->user);
- $uname = $temp_user->fullname;
- }
- else{
- $uname = _("Unknown");
- }
-
- /* Get filesize */
- $filesize = @filesize( $song );
- $add_time = date( "r",filemtime( $song ) );
-
- /* get audio information */
- $results = $audio_info->Info($song);
-
- $key = get_tag_type($results);
-
- // Crappy Math time boys and girls!
- //FIXME: Do this right
- $min = floor($results['playing_time']/60);
- $sec = floor($results['playing_time'] - ($min*60));
- $time = $min . ":" . $sec;
-
- echo " <tr class=\"".$class."\">\n";
-
- if( $user->access === 'admin' ){
- echo " <td>\n" .
- " <a href=\"" . $web_path . "upload.php/?action=add&amp;song=$file\">" . _("Add") . "</a><br />\n" .
- " <a href=\"" . $web_path . "upload.php/?action=delete&amp;song=$file\">" . _("Delete") . "</a><br />\n" .
- " </td>\n";
- }
- else{
- echo " <td>" . _("Quarantined") . "</td>\n";
- }
-
-
- echo " <td><a href='" . $web_path .
- "/play/pupload.php?action=m3u&amp;song=$file&amp;uid=$user->username'>" .
- $results[$key][title] . "</a></td>\n";
-
-
- echo " <td>" . $results[$key]['artist'] . "&nbsp</td>\n";
- echo " <td>" . $results[$key]['album'] . "&nbsp</td>\n";
- echo " <td>" . $results[$key]['genre'] . "</td>\n";
- echo " <td>" . $time . " </td>\n";
- echo " <td>" . intval($results['avg_bit_rate']/1000) . "-" . $results['bitrate_mode'] . "</td>\n";
- echo " <td>" . sprintf("%.2f",($filesize/1048576)) . "</td>\n";
- echo " <td>$file </td>\n";
- echo " <td>$uname</td>\n";
- echo " <td>$add_time </td>\n";
- echo " </tr>\n";
- }
- }
-
-
-?>
- </table>
-<br />
-<br />
-<br />
-<?php show_page_footer ('Upload', '',$user->prefs['display_menu']); ?>
-
+<?php
+/*
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+/*
+
+ Copyright (c) 2003 Lamar
+ All rights reserved.
+
+ **Revised by Vollmerk**
+ **Chopped to bits and made into PHP nuggets by RosenSama** 2005
+
+*/
+
+/* FIXME: Things left to do
+ --need to add debug logging
+ --Add purge link in catalog admin
+ --Why do I need to echo something before the message table to show it?
+ --Handle when uploaded file is a compressed arvchive
+ --play quar song by admin
+ --TEST!
+*/
+
+require_once( "modules/init.php" );
+require_once( "lib/upload.php" );
+// Set page header
+show_template('header');
+show_menu_items('Upload');
+show_clear();
+
+// Access Control
+if(!$user->prefs['upload'] || conf('demo_mode')) {
+ access_denied();
+}
+
+$action = scrub_in( $_REQUEST['action'] );
+
+switch( $action ) {
+ case 'upload':
+
+ /* Break if they don't have rights */
+ if (!$user->prefs['upload'] OR !$user->has_access(25)) {
+ break;
+ }
+
+ /* IF we need to quarantine this */
+ if ($user->prefs['quarantine']) {
+ /* Make sure the quarantine dir is writeable */
+ if (!check_upload_directory(conf('quarantine_dir'))) {
+ $GLOBALS['error']->add_error('general',"Error: Quarantine Directory isn't writeable");
+ if (conf('debug')) {
+ log_event($user->username,' upload ',"Error: Quarantine Directory isn't writeable");
+ }
+ } // if unwriteable
+
+ /* Make sure that it's not in a catalog dir */
+ if (find_upload_catalog(conf('quarantine_dir'))) {
+ $GLOBALS['error']->add_error('general',"Error: Quarantine Directory inside a catalog");
+ if (conf('debug')) {
+ log_event($user->username,' upload ',"Error: Quarantine Directory inside a catalog");
+ }
+ } // if in catalog dir
+
+ foreach ($_FILES as $key => $file) {
+
+ if (strlen($_FILES[$key]['name'])) {
+ /* Check size and extension */
+ if (!check_upload_extension($key)) {
+ $GLOBALS['error']->add_error($key,"Error: Invalid Extension");
+ }
+ if (!check_upload_size($key)) {
+ $GLOBALS['error']->add_error($key,"Error: File to large");
+ }
+
+ if (!$GLOBALS['error']->error_state) {
+ $new_filename = upload_file($key,conf('quarantine_dir'));
+ /* Record this upload then we're done */
+ if ($new_filename) { insert_quarantine_record($user->username,'quarantine',$new_filename); }
+ } // if we havn't had an error
+
+ } // end if there is a file to check
+
+ } // end foreach files
+
+ if ($GLOBALS['error']->error_state) {
+ show_upload();
+ }
+ else {
+ show_confirmation("Upload Quarantined", "Your Upload(s) have been quarantined and will be reviewed for addition","upload.php");
+ }
+
+ } // if quarantine
+
+ /* Else direct upload time baby! */
+ else {
+ /* Make sure the quarantine dir is writeable */
+ if (!check_upload_directory($user->prefs['upload_dir'])) {
+ $GLOBALS['error']->add_error('general',"Error: Upload Directory isn't writeable");
+ if (conf('debug')) {
+ log_event($user->username,' upload ',"Error: Upload Directory isn't writeable");
+ }
+ } // if unwriteable
+
+ /* Make sure that it's not in a catalog dir */
+ if (!$catalog = find_upload_catalog($user->prefs['upload_dir'])) {
+ $GLOBALS['error']->add_error('general',"Error: Upload Directory not inside a catalog");
+ if (conf('debug')) {
+ log_event($user->username,' upload ',"Error: Upload Directory not inside a catalog");
+ }
+ } // if in catalog dir
+
+ foreach ($_FILES as $key => $file) {
+
+ if (strlen($_FILES[$key]['name'])) {
+ /* Check size and extension */
+ if (!check_upload_extension($key)) {
+ $GLOBALS['error']->add_error($key,"Error: Invalid Extension");
+ }
+ if (!check_upload_size($key)) {
+ $GLOBALS['error']->add_error($key,"Error: File to large");
+ }
+
+ if (!$GLOBALS['error']->error_state) {
+ $new_filename = upload_file($key,$user->prefs['upload_dir']);
+
+ /* We aren't doing the quarantine thing, so just insert it */
+ if ($new_filename) { $catalog->insert_local_song($new_filename,filesize($new_filename)); }
+ } // if we havn't had an error
+
+ } // if there is a file to check
+
+ } // end foreach files
+
+ if ($GLOBALS['error']->error_state) {
+ show_upload();
+ }
+ else {
+ show_confirmation("Files Uploaded", "Your Upload(s) have been inserted into Ampache and are now live","upload.php");
+ }
+
+ } // man this is a bad idea, the catch all should be the conservative option... oooh well
+
+ break;
+ case 'add':
+ /* Make sure they have access */
+ if($user->has_access(100)) {
+ $id = scrub_in($_REQUEST['id']);
+ update_quarantine_record($id,'add');
+ show_confirmation("Upload Added","The Upload has been scheduled for a catalog add, please run command line script to add file","upload.php");
+ }
+ else {
+ access_denied();
+ }
+ break;
+ case 'delete':
+ /* Make sure they got them rights */
+ if($user->has_access(100)) {
+ $id = scrub_in($_REQUEST['id']);
+ update_quarantine_record($id,'delete');
+ show_confirmation("Upload Deleted","The Upload has been scheduled for deletion, please run command line script to permently delete this file","upload.php");
+
+ }
+ else {
+ access_denied();
+ }
+ break;
+ case 'ack':
+ // everything is ready to bulk ack once we pass multiple ids and put them in $id[]
+ if( $user->has_access( 100 ) ) {
+ $id[] = scrub_in( $_REQUEST['id'] );
+ $status = upload_ack( $id );
+ } else {
+ access_denied();
+ }
+ break;
+
+ case 'purge':
+ if( $user->has_access( 100 ) ) {
+ $status = upload_purge();
+ } else {
+ access_denied();
+ }
+ break;
+
+ default:
+ show_upload();
+ break;
+} // end switch on $action
+
+// display any messages
+if( $status ) {
+ print( "<table align='center'>\n" );
+ print( "<th>Filename</th><th>Result</th>\n" );
+ foreach( $status as $status_row ) {
+ $filename = $status_row[0];
+ $result = $status_row[1];
+ $color = "color='green'";
+ if( $status_row[2] ) {
+ $color = "color='red'";
+ }
+ print( "<tr>\n");
+ print( "<td><font $color>$filename</font></td><td><font $color>$result</font></td>\n");
+ print( "</tr>\n");
+ } // end for each status element
+ print( "</table>\n" );
+} // end if any messages
+
+
+?>