Update permission WIP, proxied download link, and fix css

master
root 2 years ago
parent 5363714131
commit d7c9baf791

@ -6,6 +6,7 @@ require COREPATH.'bootstrap.php';
// Add classes you want to override here
// Example: 'View' => APPPATH.'classes/view.php',
'Database_Query_Builder_Insert' => APPPATH.'classes/database/query/builder/insert.php',
'File' => APPPATH.'classes/file.php',
));
// Register the autoloader

@ -1,5 +1,7 @@
<?php
use Fuel\Core\FuelException;
use Fuel\Core\Input;
use Fuel\Core\Lang;
use Fuel\Core\Response;
use Fuel\Core\View;
@ -49,4 +51,62 @@ class Controller_Movie extends Controller_Home
$this->template->body = $body;
}
public function action_download()
{
try {
$movie_id = $this->param('movie_id');
if (!$movie_id)
throw new FuelException('No movie id');
$movie = Model_Movie::find_by_pk($movie_id);
if (!$movie)
throw new FuelException('No movie found');
if (Model_Permission::isGranted('RIGHT_DOWNLOAD_DISABLED', $movie->getLibrary()))
throw new FuelException('You dont have the permission to download in this library!');
$url = $movie->getDownloadLink();
$filename = '';
$size = 0;
if(isset($movie->getMetaData()['Media'][0])) {
$filename = $movie->getMetaData()['Media'][0]['Part']['@attributes']['file'];
$size = $movie->getMetaData()['Media'][0]['Part']['@attributes']['size'];
} else {
$filename = $movie->getMetaData()['Media']['Part']['@attributes']['file'];
$size = $movie->getMetaData()['Media']['Part']['@attributes']['size'];
}
$filename = explode('/', $filename);
$filename = $filename[count($filename) - 1];
ini_set('memory_limit', -1);
ini_set('max_execution_time', -1);
ini_set('max_input_time', -1);
header('Cache-control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Pragma: no-cache');
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Length: '.$size);
// @TODO: add it to admin panel and permission
$speed = 2000;
File::readChunked($url, $speed);
exit(200);
} catch (Exception $exception) {
return new Response($exception->getMessage(),500);
}
}
}

@ -494,6 +494,7 @@ class Controller_Rest_Install extends Controller_Rest
DB::insert('permission')->set(['id' => Str::random('uuid'), 'name' => 'RIGHT_MAX_QUALITY', 'parameters' => 1])->execute();
DB::insert('permission')->set(['id' => Str::random('uuid'), 'name' => 'RIGHT_MAX_CONCURRENT_STREAM', 'parameters' => 1])->execute();
DB::insert('permission')->set(['id' => Str::random('uuid'), 'name' => 'RIGHT_MAX_DOWNLOAD', 'parameters' => 1])->execute();
DB::insert('permission')->set(['id' => Str::random('uuid'), 'name' => 'RIGHT_MAX_DOWNLOAD_SPEED', 'parameters' => 1])->execute();
$logs .= 'Permission created!'."\r\n";

@ -22,22 +22,20 @@ class Controller_Rest_Movie extends Controller_Rest
/** @var Model_Movie $movie */
$movie = Model_Movie::find_by_pk($movie_id);
if (!$movie) {
if (!$movie)
throw new FuelException('No movie found');
}
if (!Model_Permission::isGranted('RIGHT_WATCH_DISABLED', $movie->getLibrary())) {
if (Model_Permission::isGranted('RIGHT_WATCH_DISABLED', $movie->getLibrary()))
throw new FuelException('You dont have the permission to watch in this library!');
}
$user_settings = Model_User_Settings::find_one_by('user_id', Session::get('user')->id);
if ($movie->type !== 'movie') {
if ($movie->type !== 'movie')
$episodes = $movie->getSeason()->getEpisodes();
}
else {
else
$episodes = [$movie];
}
$view = View::forge('player/index');
@ -81,66 +79,4 @@ class Controller_Rest_Movie extends Controller_Rest
return $this->response($exception->getMessage(), 500);
}
}
public function get_download() {
try {
$movie_id = Input::get('movie_id');
if (!$movie_id)
throw new FuelException('No movie id');
/** @var Model_Movie $movie */
$movie = Model_Movie::find_by_pk($movie_id);
if (!$movie)
throw new FuelException('No movie found');
if ( !Model_Permission::isGranted('RIGHT_DOWNLOAD_DISABLED', $movie->getLibrary()) )
throw new FuelException('You dont have the permission to watch in this library!');
$url = $movie->getDownloadLink();
$filename = '';
$size = 0;
if(isset($this->metadata['Media'][0])) {
$filename = $movie->getMetaData()['Media'][0]['Part']['@attributes']['file'];
$size = $movie->getMetaData()['Media'][0]['Part']['@attributes']['size'];
} else {
$filename = $movie->getMetaData()['Media']['Part']['@attributes']['file'];
$size = $movie->getMetaData()['Media']['Part']['@attributes']['size'];
}
$filename = explode('/', $filename);
$filename = $filename[count($filename) - 1];
ini_set('memory_limit', -1);
ini_set('max_execution_time', -1);
ini_set('max_input_time', -1);
$this->headers = array (
'Cache-Control' => 'no-cache, no-store, max-age=0, must-revalidate',
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Pragma' => 'no-cache',
"Content-Description" => "File Transfer",
"Content-Transfer-Encoding" => "binary",
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'inline; attachment; filename="'.$filename.'"',
'Content-Length' => $size
);
if(!File::exists(APPPATH.'tmp/'.$filename)) {
$file = file_get_contents($url);
File::create(APPPATH . 'tmp/', $filename, $file);
}
$file_info = File::file_info(APPPATH.'tmp/'.$filename);
File::download(APPPATH.'tmp/'.$filename, $filename, $file_info['mimetype'], null, true);
} catch (Exception $exception) {
return $this->response($exception->getMessage(), 500);
}
}
}

@ -26,8 +26,7 @@ class Controller_Rest_Settings extends Controller_Rest
$https = Input::post('https') === 'true' ? true : false;
//@TODO CHECK AND REMOVE HTTP AND HTTPS
$curl = Request::forge(($https ? 'https' : 'http') . '://' . $url . ($port ? ':' . $port : '') . '/?X-Plex-Token=' . $token, 'curl');
$curl = Request::forge(($https ? 'https' : 'http') . '://' . $url . (!empty($port) ? ':' . $port : '') . '/?X-Plex-Token=' . $token, 'curl');
if($https) {
$curl->set_options([
@ -46,7 +45,7 @@ class Controller_Rest_Settings extends Controller_Rest
'user_id' => Session::get('user')->id,
'https' => $https,
'url' => $url,
'port' => $port,
'port' => !empty($port) ? $port : null,
'token' => $token,
'lastcheck' => time()
]);

@ -0,0 +1,47 @@
<?php
class File extends Fuel\Core\File
{
/**
* To read file split by chunk
*
* @param string $file_path path to the file or url of the file
* @param int $speed_limit speed limit in KB/s
* @param boolean $return_bytes if you to return the totals bytes
*
* @return int
*/
public static function readChunked(string $file_path, int $speed_limit, bool $return_bytes = TRUE)
{
$buffer = '';
$speed_limit += $speed_limit * 0.2;
$tickrate = 1024;
$cnt = 0;
$handle = fopen($file_path, "rb");
if ($handle === false)
return false;
while (!feof($handle)) {
$buffer = fread($handle, $speed_limit * 1024 / $tickrate);
print $buffer;
ob_flush();
flush();
if ($return_bytes) {
$cnt += strlen($buffer);
}
usleep(1000000 / $tickrate);
}
$status = fclose($handle);
if ($return_bytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
}

@ -366,8 +366,7 @@ class Model_Movie extends Model_Overwrite
{
try {
$this->download = Cache::get($this->id . '.download');
if ($this->download)
return $this->download;
return $this->download;
} catch (CacheNotFoundException $e) {
if(!$this->_server)
$this->getServer();

@ -8,6 +8,7 @@ class Model_Permission extends Model_Overwrite
* RIGHT_WATCH_DISABLED
* RIGHT_DOWNLOAD_DISABLED
* RIGHT_MAX_DOWNLOAD
* RIGHT_MAX_DOWNLOAD_SPEED
* RIGHT_MAX_WATCH
* RIGHT_MAX_QUALITY
* RIGHT_MAX_CONCURRENT_STREAM
@ -24,9 +25,9 @@ class Model_Permission extends Model_Overwrite
/**
* @param string $permission
* @param Model_Movie $movie
* @return bool
* @return bool|int
*/
public static function isGranted($permission, Model_Library $library = null, $data = null )
public static function isGranted($permission, Model_Library $library = null, $data = null)
{
$user = Session::get('user');
@ -45,25 +46,17 @@ class Model_Permission extends Model_Overwrite
]);
if ($permission->name === 'RIGHT_WATCH_DISABLED') {
if($library_permission !== null && $library_permission->value === 1)
if($library_permission === null)
return false;
else if($library_permission !== null && $library_permission->value === 0)
return true;
else if($library_permission === null)
return true;
else
return false;
return true;
}
if ($permission->name === 'RIGHT_DOWNLOAD_DISABLED') {
if($library_permission !== null && $library_permission->value === 1)
if($library_permission === null)
return false;
else if($library_permission !== null && $library_permission->value === 0)
return true;
else if($library_permission === null)
return true;
else
return false;
return true;
}
if ($permission->name === 'RIGHT_MAX_DOWNLOAD') {
@ -75,6 +68,15 @@ class Model_Permission extends Model_Overwrite
return true;
}
if ($permission->name === 'RIGHT_MAX_DOWNLOAD_SPEED') {
/** @TODO IF (ENABLED)
* RETURN VALUE
* ELSE
* RETURN 0
*/
return true;
}
if ($permission->name === 'RIGHT_MAX_WATCH') {
/** @TODO IF (NUMBER_WATCH <= MAX_WATCH) // in last 24h
* RETURN TRUE

@ -1,14 +1,16 @@
<?php
return array(
'_root_' => 'index', // The default route
'_404_' => 'error/404', // The main 404 route
'_root_' => 'index', // The default route
'_404_' => 'error/404', // The main 404 route
'home(/:server_id)?'=> 'home/index',
'movie/list' => 'movie/list',
'library/:library_id' => 'library/index',
'tvshow/:tvshow_id' => 'tvshow/index',
'season/:season_id' => 'season/index',
'episode/:episode_id' => 'episode/index',
'movie/:movie_id' => 'movie/index',
'settings/libraries/premissions/:library_id' => 'settings/libraries/permissions'
'home(/:server_id)?' => 'home/index',
'movie/list' => 'movie/list',
'library/:library_id' => 'library/index',
'tvshow/:tvshow_id' => 'tvshow/index',
'season/:season_id' => 'season/index',
'episode/:movie_id/download' => 'movie/download',
'episode/:episode_id' => 'episode/index',
'movie/:movie_id/download' => 'movie/download',
'movie/:movie_id' => 'movie/index',
'settings/libraries/premissions/:library_id' => 'settings/libraries/permissions'
);

@ -17,9 +17,11 @@
<div class="PageHeaderRight-pageHeaderRight-2CT0g">
<div class="pageHeaderToolbar-toolbarContainer-2N-IJ Measure-container-2XznZ">
<div class="pageHeaderToolbar-toolbar-1lW-M">
<a title="<?php echo __('download'); ?>" href="<?php echo $episode->getDownloadLink(); ?>" data-placement="bottom" data-toggle="tooltip" role="button" class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO" type="button">
<?php if(!Model_Permission::isGranted('RIGHT_DOWNLOAD_DISABLED', $episode->getLibrary())) : ?>
<a title="<?php echo __('download'); ?>" href="/episode/<?php echo $episode->id; ?>/download" data-placement="bottom" data-toggle="tooltip" role="button" class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO" type="button">
<i class="plex-icon-toolbar-sync-560" aria-hidden="true"></i>
</a>
<?php endif; ?>
</div>
</div>
<div class="PrePlayPageHeader-divider-WQRk8 PageHeaderDivider-pageHeaderDivider-DvwUq"></div>

@ -5,8 +5,8 @@
<div class="PageHeaderRight-pageHeaderRight-2CT0g">
<div class="pageHeaderToolbar-toolbarContainer-2N-IJ Measure-container-2XznZ">
<div class="pageHeaderToolbar-toolbar-1lW-M">
<?php if(Model_Permission::isGranted('RIGHT_DOWNLOAD_DISABLED', $movie->getLibrary())) : ?>
<a title="<?php echo __('download'); ?>" href="<?php echo $movie->getDownloadLink() ?>" data-placement="bottom" data-toggle="tooltip" role="button" class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO" type="button">
<?php if(!Model_Permission::isGranted('RIGHT_DOWNLOAD_DISABLED', $movie->getLibrary())) : ?>
<a title="<?php echo __('download'); ?>" href="/movie/<?php echo $movie->id; ?>/download" data-placement="bottom" data-toggle="tooltip" role="button" class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO" type="button">
<i class="plex-icon-toolbar-sync-560" aria-hidden="true"></i>
</a>
<?php endif; ?>
@ -298,9 +298,9 @@
</div>
<div style="height: 183px; overflow: hidden;">
<div class="Measure-container-3yONE">
<div class="HubCell-hubScroller-2qgkr VirtualListScroller-scroller-37EU_ Scroller-horizontal-cOKsq Scroller-scroller-3GqQc Scroller-horizontal-cOKsq ">
<div class="HubCell-hubScroller-2qgkr VirtualListScroller-scroller-37EU_ Scroller-horizontal-1k8ET Scroller-scroller-d5-b- Scroller-horizontal-1k8ET ">
<?php $translate = -143; ?>
<div class=" " style="width: 5012px; height: 183px;">
<div class=" " style="width: auto; height: 183px;">
<?php foreach ($movie->getMetadata()['Role'] as $role) : ?>
<?php $translate += 148; ?>
<div data-qa-id="cellItem" style="position: absolute; width: 118px; height: 168px; transform: translate3d(<?php echo $translate; ?>px, 10px, 0px);">

@ -39,7 +39,7 @@
</div>
<div class="AudioVideoFullPlayerContentHeadingContainer-divider-1A1d_"></div>
</div>
<div class="AudioVideoPlayQueue-content-28l4x Scroller-vertical-VScFL Scroller-scroller-3GqQc Scroller-vertical-VScFL Scroller-auto-LsWiW" style="overflow-y: auto;">
<div class="AudioVideoPlayQueue-content-28l4x Scroller-vertical-VScFL Scroller-scroller-d5-b- Scroller-vertical-VScFL Scroller-auto-LsWiW" style="overflow-y: auto;">
<?php foreach ($episodes as $episode) : ?>
<div class="AudioVideoPlayQueueItemDragSource-container-3ncn7">
<div class="AudioVideoPlayQueueItem-container-2_nsg AudioVideoPlayQueueItem-isCurrentItem-3g1KW"

@ -1,6 +1,10 @@
<div class="settings-container">
<div class="filter-bar"><?php echo $library->getServer()->name; ?> > <?php echo $library->name; ?></div>
<div class="filter-bar" style="color: darkgrey;">By default a user can do everything without restriction. Use -1 to unlimited and 0 to block.</div>
<div class="filter-bar" style="color: darkgrey; height: auto">
By default a user can do everything without restriction. Use -1 to unlimited and 0 to block.
<br/>
<span class="text-danger"><i class="glyphicon warning-sign"></i></span> <span class="text-warning">Disable the permission, is like putting in unlimited mode.</span>
</div>
<?php if ($permissions) : ?>
<?php foreach ($permissions as $permission) : ?>
<div class="SettingsFormSection-sectionWrapper-1-gPg" style="background-color: rgba(0,0,0,0.15); margin-bottom: 15px; border-bottom: 1px solid rgb(97,97,97)">

@ -204,9 +204,9 @@
</div>
<div style="height: 183px; overflow: hidden;">
<div class="Measure-container-3yONE">
<div class="HubCell-hubScroller-2qgkr VirtualListScroller-scroller-37EU_ Scroller-horizontal-cOKsq Scroller-scroller-3GqQc Scroller-horizontal-cOKsq ">
<div class="HubCell-hubScroller-2qgkr VirtualListScroller-scroller-37EU_ Scroller-horizontal-1k8ET Scroller-scroller-d5-b- Scroller-horizontal-1k8ET ">
<?php $translate = -143; ?>
<div class=" " style="width: 5012px; height: 183px;">
<div class=" " style="width: auto; height: 183px;">
<?php if(isset($tvshow->getMetadata()['Role'])) : ?>
<?php foreach ($tvshow->getMetadata()['Role'] as $role) : ?>
<?php $translate += 148; ?>

Loading…
Cancel
Save