Пример #1
0
function deleteFile()
{
    global $cfg, $db;
    authenticate('access_admin', false, true, true);
    if ($cfg['delete_file'] == false) {
        message(__FILE__, __LINE__, 'error', '[b]Error[/b][br]Delete file disabled');
    }
    $referer = get('referer');
    $relative_file = get('relative_file');
    $file = $cfg['media_dir'] . $relative_file;
    $query = mysql_query('SELECT relative_file
		FROM track
		WHERE relative_file	= BINARY "' . mysql_real_escape_string($relative_file) . '"');
    $track = mysql_fetch_assoc($query);
    if ($track == false) {
        message(__FILE__, __LINE__, 'error', '[b]Error[/b][br]relative_file not found in database');
    }
    if (is_file($file) && @unlink($file) == false) {
        message(__FILE__, __LINE__, 'error', '[b]Failed to delete file:[/b][br]' . $file);
    }
    mysql_query('DELETE FROM track 
		WHERE relative_file	= BINARY "' . mysql_real_escape_string($relative_file) . '"');
    cacheCleanup();
    header('Location: ' . NJB_HOME_URL . $referer);
    exit;
}
Пример #2
0
function batchTranscodeInit()
{
    global $cfg, $db;
    authenticate('access_admin', false, true, true);
    ini_set('max_execution_time', 0);
    $cfg['menu'] = 'config';
    $profile = (int) get('profile');
    if (isset($cfg['encode_name'][$profile]) == false) {
        message(__FILE__, __LINE__, 'error', '[b]Unsupported input value for[/b][br]profile');
    }
    // formattedNavigator
    $nav = array();
    $nav['name'][] = 'Configuration';
    $nav['url'][] = 'config.php';
    $nav['name'][] = 'Batch transcode';
    $nav['url'][] = 'config.php?action=batchTranscode';
    $nav['name'][] = $cfg['encode_name'][$profile];
    require_once 'include/header.inc.php';
    ?>
<table cellspacing="0" cellpadding="0" class="border">
<tr class="header">
	<td class="space"></td>
	<td>Progress</td>
	<td class="textspace"></td>
	<td></td>
	<td class="space"></td>
</tr>
<tr class="line"><td colspan="5"></td></tr>
<tr class="even">
	<td></td>
	<td>Initialize</td>
	<td></td>
	<td><span id="initialize"></span></td>
	<td></td>
</tr>
</table>
<?php 
    $cfg['footer'] = 'dynamic';
    require 'include/footer.inc.php';
    echo '<script type="text/javascript">';
    echo 'document.getElementById(\'initialize\').innerHTML=\'<img src="' . $cfg['img'] . 'small_animated_progress.gif" alt="" class="small">\';' . "\n";
    echo '</script>';
    @ob_flush();
    flush();
    cacheCleanup();
    mysql_query('UPDATE track SET transcoded = 0');
    mysql_query('UPDATE track SET transcoded = 1 WHERE EXISTS (SELECT * FROM cache WHERE track_id = id AND cache.profile = ' . (int) $profile . ')');
    $query = mysql_query('SELECT track_id, audio_bitrate,
		LOWER(SUBSTRING_INDEX(track.relative_file, ".", -1)) AS extension
		FROM track
		WHERE transcoded = 0');
    while ($track = mysql_fetch_assoc($query)) {
        if (sourceFile($track['extension'], $track['audio_bitrate'], $profile)) {
            // File will be downloaded from source
            mysql_query('UPDATE track SET transcoded = 1
				WHERE track_id = "' . mysql_real_escape_string($track['track_id']) . '"');
        }
    }
    echo '<script type="text/javascript">';
    echo 'document.getElementById(\'initialize\').innerHTML=\'<img src="' . $cfg['img'] . 'small_check.png" alt="" class="small">\';' . "\n";
    echo '</script>' . "\n";
    @ob_flush();
    flush();
    authenticate('access_admin', false, false, true);
    // Get up to date sign
    exit('<script type="text/javascript">window.location.href="' . NJB_HOME_URL . 'download.php?action=batchTranscode&profile=' . $profile . '&sign=' . $cfg['sign'] . '";</script>');
}
Пример #3
0
function cacheValidate()
{
    global $cfg, $db;
    cacheCreateRoot();
    cacheCleanup();
    mysql_query('UPDATE cache SET updated = 0');
    recursiveValidate(NJB_HOME_DIR . 'cache/');
    mysql_query('DELETE FROM cache WHERE NOT updated');
}
Пример #4
0
        } else {
            $cmd = $cfg['decode_stdout'][$extension] . ' 2>&1';
        }
        $cmd = str_replace('%source', escapeCmdArg($source), $cmd);
        $cmd = $cmd . ' > ' . escapeCmdArg($destination);
        $cmd_output = array();
        $cmd_return = 0;
        @exec($cmd, $cmd_output, $cmd_return);
        if ($cmd_return != 0) {
            message(__FILE__, __LINE__, 'error', '[b]Exec error[/b][br][b]Command:[/b] ' . $cmd . '[br][b]System output:[/b] ' . implode('[br]', $cmd_output) . '[br][b]System return code:[/b] ' . $cmd_return);
        }
        if (is_file($destination) == false) {
            message(__FILE__, __LINE__, 'error', '[b]Destination file not created[/b][br]File: ' . $destination . '[br]Command: ' . $cmd);
        }
        cacheUpdateFile($track['track_id'], -2, $destination);
        cacheCleanup();
    }
    echo '<script type="text/javascript">document.getElementById(\'status' . $i . '\').innerHTML=\'<img src="' . $cfg['img'] . 'small_check.png" alt="" class="small">\';</script>' . "\n";
    @ob_flush();
    flush();
}
echo '<script type="text/javascript">document.getElementById(\'record\').innerHTML=\'<img src="' . $cfg['img'] . 'small_animated_record.gif" alt="" class="small">\';</script>' . "\n";
@ob_flush();
flush();
// Record to disc
$cache_dir = cacheGetDir($track_id, $profile);
$pathinfo = pathinfo($track['relative_file']);
$destination = $pathinfo['filename'];
$destination = $cache_dir . $destination . '.' . $cfg['encode_extension'][$profile];
// Transcode
if (NJB_WINDOWS) {
Пример #5
0
function databaseCleanup()
{
    global $cfg, $db;
    // Clean up database
    mysql_query('DELETE FROM session WHERE idle_time = 0 AND create_time < ' . (int) (time() - 600));
    mysql_query('DELETE FROM random WHERE create_time < ' . (int) (time() - 3600));
    mysql_query('DELETE FROM share_download WHERE expire_time < ' . (int) time());
    mysql_query('DELETE FROM share_stream WHERE expire_time < ' . (int) time());
    mysql_query('DELETE share_download
		FROM share_download LEFT JOIN album
		ON share_download.album_id = album.album_id
		WHERE album.album_id IS NULL');
    mysql_query('DELETE share_stream
		FROM share_stream LEFT JOIN album
		ON share_stream.album_id = album.album_id
		WHERE album.album_id IS NULL');
    mysql_query('DELETE counter
		FROM counter LEFT JOIN album
		ON counter.album_id = album.album_id
		WHERE album.album_id IS NULL');
    mysql_query('DELETE counter
		FROM counter LEFT JOIN user
		ON counter.user_id = user.user_id
		WHERE user.user_id IS NULL');
    mysql_query('DELETE FROM favoriteitem WHERE track_id NOT IN (SELECT track_id FROM track) AND stream_url = ""');
    // Delete unavailable files from cache
    cacheCleanup();
    // Optimize tables
    $list = array();
    $query = mysql_query('SHOW TABLES');
    while ($table = mysql_fetch_row($query)) {
        $list[] = $table[0];
    }
    $list = implode(', ', $list);
    mysql_query('OPTIMIZE TABLE ' . $list);
}