diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dc1f64c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: php +php: + - 5.3 + - 5.4 + - 5.5 + - 7.0 + +before_script: + - curl -s http://getcomposer.org/installer | php + - php composer.phar install --dev + +script: php oil test diff --git a/composer.json b/composer.json index b1a79fb..4e11b3d 100755 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["application", "website", "development", "framework", "PHP", "PHP7"], "license": "MIT", "require": { - "php": ">=5.3.3", + "php": ">=5.6.33", "composer/installers": "~1.0", "fuel/core": "1.8.*", "fuel/auth": "1.8.*", diff --git a/fuel/app/classes/controller/install.php b/fuel/app/classes/controller/install.php index 59a8366..6523618 100755 --- a/fuel/app/classes/controller/install.php +++ b/fuel/app/classes/controller/install.php @@ -1,42 +1,48 @@ -set_safe('end_js', $js); - - $config_db = Config::load('db', true); - $config_db = $config_db['default']; - - $view->set('db_host', $config_db['connection']['hostname']); - $view->set('db_port', $config_db['connection']['port']); - $view->set('db_database', $config_db['connection']['database']); - $view->set('db_prefix', $config_db['table_prefix']); - $view->set('db_username', $config_db['connection']['username']); - $view->set('db_password', $config_db['connection']['password']); - - try { - $config_plex = Model_Server::find()[0]; - - if($config_plex) { - $view->set('plex_url', $config_plex->url); - $view->set('plex_port', $config_plex->port); - $view->set('plex_token', $config_plex->token); - } - }catch (FuelException $e){ - //@TODO - } - - return $view; - } +set_safe('end_js', $js); + + $config_db = Config::load('db', true); + $config_db = $config_db['default']; + + $view->set('db_host', $config_db['connection']['hostname']); + $view->set('db_port', $config_db['connection']['port']); + $view->set('db_database', $config_db['connection']['database']); + $view->set('db_prefix', $config_db['table_prefix']); + $view->set('db_username', $config_db['connection']['username']); + $view->set('db_password', $config_db['connection']['password']); + + try { + $config_plex = Model_Server::find()[0]; + + if($config_plex) { + $view->set('plex_url', $config_plex->url); + $view->set('plex_port', $config_plex->port); + $view->set('plex_token', $config_plex->token); + } + }catch (FuelException $e){ + //@TODO + } + + return $view; + } } \ No newline at end of file diff --git a/fuel/app/classes/controller/login.php b/fuel/app/classes/controller/login.php index 585602e..79ba833 100755 --- a/fuel/app/classes/controller/login.php +++ b/fuel/app/classes/controller/login.php @@ -11,6 +11,14 @@ use Fuel\Core\FuelException; class Controller_Login extends Controller { + public function before() + { + parent::before(); + $user = Session::get('user'); + + if($user) + Response::redirect('/home'); + } public function action_index() { diff --git a/fuel/app/classes/controller/register.php b/fuel/app/classes/controller/register.php index dc4a49d..b7f5113 100755 --- a/fuel/app/classes/controller/register.php +++ b/fuel/app/classes/controller/register.php @@ -9,6 +9,14 @@ use Fuel\Core\FuelException; class Controller_Register extends Controller { + public function before() + { + parent::before(); + $user = Session::get('user'); + + if($user) + Response::redirect('/home'); + } public function action_index() { diff --git a/fuel/app/classes/controller/rest/install.php b/fuel/app/classes/controller/rest/install.php index 327270c..9044145 100755 --- a/fuel/app/classes/controller/rest/install.php +++ b/fuel/app/classes/controller/rest/install.php @@ -1,463 +1,465 @@ -='); - $result['version'] = $version ? true : false; - - $result['mysql'] = extension_loaded('mysql') ? true : false; - $result['mysqli'] = extension_loaded('mysqli') ? true : false; - $result['pdo_mysql'] = extension_loaded('pdo_mysql') ? true : false; - $result['simplexml'] = extension_loaded('SimpleXML') ? true : false; - $result['curl'] = function_exists('curl_version') ? true : false; - $result['config'] = is_writable('../fuel/app/config/') ? true : false; - - return $this->response($result); - } - - public function post_config() - { - try { - $host = Input::post('host'); - $port = Input::post('port'); - $dbname = Input::post('database'); - $username = Input::post('username'); - $password = Input::post('password'); - - $boolean = Config::load('db', true); - - if(!$boolean) - throw new FuelException('Config db.php not work!'); - - $config = array( - 'active' => 'default', - 'default' => array( - 'type' => 'pdo', - 'connection' => array( - 'dsn' => 'mysql:host=' . $host . ($port ? ';port=' . $port : '') . ';dbname=' . $dbname, - 'hostname' => $host, - 'port' => $port, - 'database' => $dbname, - 'username' => $username, - 'password' => $password, - ), - 'table_prefix' => 'plex_', - 'charset' => 'utf8', - 'enable_cache' => true, - 'hash' => Str::random('alnum', 32) - ), - ); - - Config::save('db', $config); - - return $this->response(array('error' => false)); - }catch (FuelException $e) { - return $this->response(array('error' => true, 'message' => $e->getMessage()), 400); - } - } - - public function post_tables() - { - - Config::load('db', true); - - $logs = ''; - - try { - DB::start_transaction(); - - $logs .= 'Creation table user'."\r\n"; - /** - * CREATE TABLE USER - */ - DBUtil::create_table( - 'user', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'username' => array('constraint' => 255, 'type' => 'varchar'), - 'email' => array('constraint' => 255, 'type' => 'varchar'), - 'password' => array('constraint' => 255, 'type' => 'varchar'), - 'admin' => array('constraint' => 1, 'type' => 'int', 'default' => 0), - 'lastlogin' => array('constraint' => 11, 'type' => 'int'), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - - $logs .= 'Table user create!'."\r\n"; - - $logs .= 'Creation table server'."\r\n"; - /** - * CREATE TABLE SERVER - */ - DBUtil::create_table( - 'server', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'user_id' => array('constraint' => 36, 'type' => 'varchar'), - 'url' => array('constraint' => 255, 'type' => 'varchar'), - 'port' => array('constraint' => 2, 'type' => 'int', 'null' => true), - 'token' => array('constraint' => 255, 'type' => 'varchar'), - 'lastcheck' => array('constraint' => 11, 'type' => 'int'), - 'name' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'plateforme' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'platformVersion' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'version' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'online' => array('constraint' => 1, 'type' => 'int', 'default' => 0), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'Server table create!'."\r\n"; - - $logs .= 'Creation table library'."\r\n"; - /** - * CREATE TABLE LIBRARY - */ - DBUtil::create_table( - 'library', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'server_id' => array('constraint' => 36, 'type' => 'varchar'), - 'plex_key' => array('constraint' => 11, 'type' => 'int'), - 'name' => array('constraint' => 255, 'type' => 'varchar'), - 'type' => array('constraint' => 255, 'type' => 'varchar'), - 'updatedAt' => array('constraint' => 11, 'type' => 'int'), - 'createdAt' => array('constraint' => 11, 'type' => 'int'), - 'scannedAt' => array('constraint' => 11, 'type' => 'int'), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'Library table create!'."\r\n"; - - $logs .= 'Creation table tv_show'."\r\n"; - /** - * CREATE TABLE LIBRARY - */ - DBUtil::create_table( - 'tvshow', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'library_id' => array('constraint' => 36, 'type' => 'varchar'), - 'plex_key' => array('constraint' => 255, 'type' => 'varchar'), - 'studio' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'title' => array('constraint' => 255, 'type' => 'varchar'), - 'contentRating' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'summary' => array('type' => 'text', 'null' => true), - 'rating' => array('constraint' => 3, 'type' => 'varchar', 'null' => true), - 'year' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'thumb' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'banner' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'theme' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'originallyAvailableAt' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'leafCount' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'addedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'Library table create!'."\r\n"; - - $logs .= 'Creation table season'."\r\n"; - /** - * CREATE TABLE SEASON - */ - DBUtil::create_table( - 'season', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'tv_show_id' => array('constraint' => 36, 'type' => 'varchar'), - 'plex_key' => array('constraint' => 36, 'type' => 'varchar'), - 'number' => array('constraint' => 11, 'type' => 'int'), - 'title' => array('constraint' => 255, 'type' => 'varchar'), - 'thumb' => array('constraint' => 255, 'type' => 'varchar'), - 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'leafCount' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'addedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'Season table create!'."\r\n"; - - $logs .= 'Creation table movie'."\r\n"; - /** - * CREATE TABLE SEASON - */ - DBUtil::create_table( - 'movie', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'library_id' => array('constraint' => 36, 'type' => 'varchar', 'null' => true), - 'season_id' => array('constraint' => 36, 'type' => 'varchar', 'null' => true), - 'plex_key' => array('constraint' => 36, 'type' => 'varchar'), - 'type' => array('constraint' => 5, 'type' => 'varchar'), - 'number' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'studio' => array('constraint' => 36, 'type' => 'varchar', 'null' => true), - 'title' => array('constraint' => 255, 'type' => 'varchar'), - 'originalTitle' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'summary' => array('type' => 'text', 'null' => true), - 'rating' => array('constraint' => 3, 'type' => 'varchar', 'null' => true), - 'year' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'thumb' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), - 'duration' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'originallyAvailableAt' => array('constraint' => 11, 'type' => 'varchar', 'null' => true), - 'addedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'Movie table create!'."\r\n"; - - $logs .= 'Creation table configuration'."\r\n"; - /** - * CREATE TABLE CONFIGURATION - */ - DBUtil::create_table( - 'configurations', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'name' => array('constraint' => 255, 'type' => 'varchar'), - 'data' => array('constraint' => 255, 'type' => 'varchar') - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'Configuration table create!'."\r\n"; - - $logs .= 'Creation table permission'."\r\n"; - /** - * CREATE TABLE PERMISSION - */ - DBUtil::create_table( - 'permission', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'name' => array('constraint' => 255, 'type' => 'varchar'), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'Permission table create!'."\r\n"; - - $logs .= 'Creation table user permission'."\r\n"; - /** - * CREATE TABLE USER'S PERMISSION - */ - DBUtil::create_table( - 'user_permission', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'permission_id' => array('constraint' => 36, 'type' => 'varchar'), - 'user_id' => array('constraint' => 36, 'type' => 'varchar'), - 'library_id' => array('constraint' => 36, 'type' => 'varchar'), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'User Permission table create!'."\r\n"; - - $logs .= 'Creation table user watching'."\r\n"; - /** - * CREATE TABLE USER'S WATCHING - */ - DBUtil::create_table( - 'user_watching', - array( - 'id' => array('constraint' => 36, 'type' => 'varchar'), - 'file_id' => array('constraint' => 11, 'type' => 'int'), - 'user_id' => array('constraint' => 36, 'type' => 'varchar'), - 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) - ), - array('id'), false, 'InnoDB', 'utf8_unicode_ci' - ); - $logs .= 'User Watching table create!'."\r\n"; - - $logs .= 'Create Foreign key'."\r\n"; - /** - * FOREIGN KEY - */ - DBUtil::add_foreign_key('tvshow', array( - 'constraint' => 'constraintTvShowLibrary', - 'key' => 'library_id', - 'reference' => array( - 'table' => 'library', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - DBUtil::add_foreign_key('season', array( - 'constraint' => 'constraintSeasonTvShow', - 'key' => 'tv_show_id', - 'reference' => array( - 'table' => 'tvshow', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - DBUtil::add_foreign_key('movie', array( - 'constraint' => 'constraintMovieLibrary', - 'key' => 'library_id', - 'reference' => array( - 'table' => 'library', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - DBUtil::add_foreign_key('movie', array( - 'constraint' => 'constraintMovieSeason', - 'key' => 'season_id', - 'reference' => array( - 'table' => 'season', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - DBUtil::add_foreign_key('user_permission', array( - 'constraint' => 'constraintLibraryPermission', - 'key' => 'library_id', - 'reference' => array( - 'table' => 'library', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - DBUtil::add_foreign_key('user_watching', array( - 'constraint' => 'constraintUserWatching', - 'key' => 'user_id', - 'reference' => array( - 'table' => 'user', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - DBUtil::add_foreign_key('library', array( - 'constraint' => 'constraintServerLibrary', - 'key' => 'server_id', - 'reference' => array( - 'table' => 'server', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - DBUtil::add_foreign_key('server', array( - 'constraint' => 'constraintServerUser', - 'key' => 'user_id', - 'reference' => array( - 'table' => 'user', - 'column' => 'id', - ), - 'on_update' => 'NO ACTION', - 'on_delete' => 'NO ACTION', - )); - - $logs .= 'Foreign key create!'."\r\n"; - - DB::commit_transaction(); - - $logs .= 'All Tables and Foreign Key successfully!'."\r\n"; - - return $this->response(array('error' => false, 'message' => $logs)); - }catch (FuelException $e) { - DBUtil::drop_table('user_watching'); - DBUtil::drop_table('user_permission'); - DBUtil::drop_table('permission'); - DBUtil::drop_table('library'); - DBUtil::drop_table('server'); - DBUtil::drop_table('configurations'); - DBUtil::drop_table('user'); - DB::rollback_transaction(); - return $this->response(array('error' => true, 'message' => $e->getMessage()), 400); - } - } - - public function post_plex() - { - try { - $url = Input::post('url'); - - //@TODO CHECK AND REMOVE HTTP AND HTTPS - - $port = Input::post('port'); - $token = Input::post('token'); - - $curl = Request::forge('http://' . $url . ($port ? ':' . $port : '') . '/?X-Plex-Token=' . $token, 'curl'); - $result = $curl->execute(); - - if(!$result) - throw new FuelException('Can not connect to your server!'); - - $server = Model_Server::forge(); - $server->set([ - 'url' => $url, - 'port' => $port, - 'token' => $token, - 'lastcheck' => time() - ]); - $server->save(); - - return $this->response(array('error' => false)); - } catch (FuelException $e) { - return $this->response(array('error' => true, 'message' => $e->getMessage()), 400); - } - } - - public function post_admin() - { - try { - $config = Config::load('db', true); - - $email = Input::post('email'); - $username = Input::post('username'); - $password = Input::post('password'); - $Cpassword = Input::post('cpassword'); - - if($password !== $Cpassword) - throw new FuelException('Password match error!'); - - $user = Model_User::forge(array( - 'username' => $username, - 'email' => $email, - 'password' => hash('sha512', $config['default']['hash'] . $password), - 'admin' => 1, - 'lastlogin' => time() - )); - - if(!$user->validates()) { - throw new FuelException($user->validation()->show_errors()); - } - - $user->save(); - - return $this->response(array('error' => false)); - } catch (Exception $e) { - return $this->response(array('error' => true, 'message' => $e->getMessage()), 404); - } - } +='); + $result['version'] = $version ? true : false; + + $result['mysql'] = extension_loaded('mysql') ? true : false; + $result['mysqli'] = extension_loaded('mysqli') ? true : false; + $result['pdo_mysql'] = extension_loaded('pdo_mysql') ? true : false; + $result['simplexml'] = extension_loaded('SimpleXML') ? true : false; + $result['curl'] = function_exists('curl_version') ? true : false; + $result['config'] = is_writable('../fuel/app/config/') ? true : false; + + return $this->response($result); + } + + public function post_config() + { + try { + $host = Input::post('host'); + $port = Input::post('port'); + $dbname = Input::post('database'); + $username = Input::post('username'); + $password = Input::post('password'); + + $boolean = Config::load('db', true); + + if(!$boolean) + throw new FuelException('Config db.php not work!'); + + $config = array( + 'active' => 'default', + 'default' => array( + 'type' => 'pdo', + 'connection' => array( + 'dsn' => 'mysql:host=' . $host . ($port ? ';port=' . $port : '') . ';dbname=' . $dbname, + 'hostname' => $host, + 'port' => $port, + 'database' => $dbname, + 'username' => $username, + 'password' => $password, + ), + 'table_prefix' => 'plex_', + 'charset' => 'utf8', + 'enable_cache' => true, + 'hash' => Str::random('alnum', 32) + ), + ); + + Config::save('db', $config); + + return $this->response(array('error' => false)); + }catch (FuelException $e) { + return $this->response(array('error' => true, 'message' => $e->getMessage()), 400); + } + } + + public function post_tables() + { + + Config::load('db', true); + + $logs = ''; + + try { + DB::start_transaction(); + + $logs .= 'Creation table user'."\r\n"; + /** + * CREATE TABLE USER + */ + DBUtil::create_table( + 'user', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'username' => array('constraint' => 255, 'type' => 'varchar'), + 'email' => array('constraint' => 255, 'type' => 'varchar'), + 'password' => array('constraint' => 255, 'type' => 'varchar'), + 'admin' => array('constraint' => 1, 'type' => 'int', 'default' => 0), + 'lastlogin' => array('constraint' => 11, 'type' => 'int'), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + + $logs .= 'Table user create!'."\r\n"; + + $logs .= 'Creation table server'."\r\n"; + /** + * CREATE TABLE SERVER + */ + DBUtil::create_table( + 'server', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'user_id' => array('constraint' => 36, 'type' => 'varchar'), + 'url' => array('constraint' => 255, 'type' => 'varchar'), + 'port' => array('constraint' => 2, 'type' => 'int', 'null' => true), + 'token' => array('constraint' => 255, 'type' => 'varchar'), + 'lastcheck' => array('constraint' => 11, 'type' => 'int'), + 'name' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'plateforme' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'platformVersion' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'version' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'online' => array('constraint' => 1, 'type' => 'int', 'default' => 0), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'Server table create!'."\r\n"; + + $logs .= 'Creation table library'."\r\n"; + /** + * CREATE TABLE LIBRARY + */ + DBUtil::create_table( + 'library', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'server_id' => array('constraint' => 36, 'type' => 'varchar'), + 'plex_key' => array('constraint' => 11, 'type' => 'int'), + 'name' => array('constraint' => 255, 'type' => 'varchar'), + 'type' => array('constraint' => 255, 'type' => 'varchar'), + 'updatedAt' => array('constraint' => 11, 'type' => 'int'), + 'createdAt' => array('constraint' => 11, 'type' => 'int'), + 'scannedAt' => array('constraint' => 11, 'type' => 'int'), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'Library table create!'."\r\n"; + + $logs .= 'Creation table tv_show'."\r\n"; + /** + * CREATE TABLE LIBRARY + */ + DBUtil::create_table( + 'tvshow', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'library_id' => array('constraint' => 36, 'type' => 'varchar'), + 'plex_key' => array('constraint' => 255, 'type' => 'varchar'), + 'studio' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'title' => array('constraint' => 255, 'type' => 'varchar'), + 'contentRating' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'summary' => array('type' => 'text', 'null' => true), + 'rating' => array('constraint' => 3, 'type' => 'varchar', 'null' => true), + 'year' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'thumb' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'banner' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'theme' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'originallyAvailableAt' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'leafCount' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'addedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'Library table create!'."\r\n"; + + $logs .= 'Creation table season'."\r\n"; + /** + * CREATE TABLE SEASON + */ + DBUtil::create_table( + 'season', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'tv_show_id' => array('constraint' => 36, 'type' => 'varchar'), + 'plex_key' => array('constraint' => 36, 'type' => 'varchar'), + 'number' => array('constraint' => 11, 'type' => 'int'), + 'title' => array('constraint' => 255, 'type' => 'varchar'), + 'thumb' => array('constraint' => 255, 'type' => 'varchar'), + 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'leafCount' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'addedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'Season table create!'."\r\n"; + + $logs .= 'Creation table movie'."\r\n"; + /** + * CREATE TABLE SEASON + */ + DBUtil::create_table( + 'movie', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'library_id' => array('constraint' => 36, 'type' => 'varchar', 'null' => true), + 'season_id' => array('constraint' => 36, 'type' => 'varchar', 'null' => true), + 'plex_key' => array('constraint' => 36, 'type' => 'varchar'), + 'type' => array('constraint' => 5, 'type' => 'varchar'), + 'number' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'studio' => array('constraint' => 36, 'type' => 'varchar', 'null' => true), + 'title' => array('constraint' => 255, 'type' => 'varchar'), + 'originalTitle' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'summary' => array('type' => 'text', 'null' => true), + 'rating' => array('constraint' => 3, 'type' => 'varchar', 'null' => true), + 'year' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'thumb' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), + 'duration' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'originallyAvailableAt' => array('constraint' => 11, 'type' => 'varchar', 'null' => true), + 'addedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'updatedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'Movie table create!'."\r\n"; + + $logs .= 'Creation table configuration'."\r\n"; + /** + * CREATE TABLE CONFIGURATION + */ + DBUtil::create_table( + 'configurations', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'name' => array('constraint' => 255, 'type' => 'varchar'), + 'data' => array('constraint' => 255, 'type' => 'varchar') + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'Configuration table create!'."\r\n"; + + $logs .= 'Creation table permission'."\r\n"; + /** + * CREATE TABLE PERMISSION + */ + DBUtil::create_table( + 'permission', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'name' => array('constraint' => 255, 'type' => 'varchar'), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'Permission table create!'."\r\n"; + + $logs .= 'Creation table user permission'."\r\n"; + /** + * CREATE TABLE USER'S PERMISSION + */ + DBUtil::create_table( + 'user_permission', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'permission_id' => array('constraint' => 36, 'type' => 'varchar'), + 'user_id' => array('constraint' => 36, 'type' => 'varchar'), + 'library_id' => array('constraint' => 36, 'type' => 'varchar'), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'User Permission table create!'."\r\n"; + + $logs .= 'Creation table user watching'."\r\n"; + /** + * CREATE TABLE USER'S WATCHING + */ + DBUtil::create_table( + 'user_watching', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'file_id' => array('constraint' => 11, 'type' => 'int'), + 'user_id' => array('constraint' => 36, 'type' => 'varchar'), + 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'User Watching table create!'."\r\n"; + + $logs .= 'Create Foreign key'."\r\n"; + /** + * FOREIGN KEY + */ + DBUtil::add_foreign_key('tvshow', array( + 'constraint' => 'constraintTvShowLibrary', + 'key' => 'library_id', + 'reference' => array( + 'table' => 'library', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + DBUtil::add_foreign_key('season', array( + 'constraint' => 'constraintSeasonTvShow', + 'key' => 'tv_show_id', + 'reference' => array( + 'table' => 'tvshow', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + DBUtil::add_foreign_key('movie', array( + 'constraint' => 'constraintMovieLibrary', + 'key' => 'library_id', + 'reference' => array( + 'table' => 'library', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + DBUtil::add_foreign_key('movie', array( + 'constraint' => 'constraintMovieSeason', + 'key' => 'season_id', + 'reference' => array( + 'table' => 'season', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + DBUtil::add_foreign_key('user_permission', array( + 'constraint' => 'constraintLibraryPermission', + 'key' => 'library_id', + 'reference' => array( + 'table' => 'library', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + DBUtil::add_foreign_key('user_watching', array( + 'constraint' => 'constraintUserWatching', + 'key' => 'user_id', + 'reference' => array( + 'table' => 'user', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + DBUtil::add_foreign_key('library', array( + 'constraint' => 'constraintServerLibrary', + 'key' => 'server_id', + 'reference' => array( + 'table' => 'server', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + DBUtil::add_foreign_key('server', array( + 'constraint' => 'constraintServerUser', + 'key' => 'user_id', + 'reference' => array( + 'table' => 'user', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); + + $logs .= 'Foreign key create!'."\r\n"; + + DB::commit_transaction(); + + $logs .= 'All Tables and Foreign Key successfully!'."\r\n"; + + return $this->response(array('error' => false, 'message' => $logs)); + }catch (FuelException $e) { + DBUtil::drop_table('user_watching'); + DBUtil::drop_table('user_permission'); + DBUtil::drop_table('permission'); + DBUtil::drop_table('library'); + DBUtil::drop_table('server'); + DBUtil::drop_table('configurations'); + DBUtil::drop_table('user'); + DB::rollback_transaction(); + return $this->response(array('error' => true, 'message' => $e->getMessage()), 400); + } + } + + public function post_admin() + { + try { + $config = Config::load('db', true); + + $email = Input::post('email'); + $username = Input::post('username'); + $password = Input::post('password'); + $Cpassword = Input::post('cpassword'); + + if($password !== $Cpassword) + throw new FuelException('Password match error!'); + + $user = Model_User::forge(array( + 'username' => $username, + 'email' => $email, + 'password' => hash('sha512', $config['default']['hash'] . $password), + 'admin' => 1, + 'lastlogin' => time() + )); + + if(!$user->validates()) { + throw new FuelException($user->validation()->show_errors()); + } + + $user->save(); + + return $this->response(array('error' => false)); + } catch (Exception $e) { + return $this->response(array('error' => true, 'message' => $e->getMessage()), 404); + } + } + + public function post_plex() + { + try { + $url = Input::post('url'); + + //@TODO CHECK AND REMOVE HTTP AND HTTPS + + $port = Input::post('port'); + $token = Input::post('token'); + + $curl = Request::forge('http://' . $url . ($port ? ':' . $port : '') . '/?X-Plex-Token=' . $token, 'curl'); + $result = $curl->execute(); + + if(!$result) + throw new FuelException('Can not connect to your server!'); + + $server = Model_Server::forge(); + $server->set([ + 'url' => $url, + 'port' => $port, + 'token' => $token, + 'lastcheck' => time() + ]); + $server->save(); + + Config::save('lock', array('FUCK OFF!')); + + return $this->response(array('error' => false)); + } catch (FuelException $e) { + return $this->response(array('error' => true, 'message' => $e->getMessage()), 400); + } + } } \ No newline at end of file diff --git a/fuel/app/classes/controller/rest/settings.php b/fuel/app/classes/controller/rest/settings.php index f9ce24a..d8f0b20 100644 --- a/fuel/app/classes/controller/rest/settings.php +++ b/fuel/app/classes/controller/rest/settings.php @@ -1,7 +1,9 @@ execute(); + + if(!$result) + throw new FuelException('Can not connect to your server!'); + + $server = Model_Server::forge(); + $server->set([ + 'user_id' => Session::get('user')->id, + 'url' => $url, + 'port' => $port, + 'token' => $token, + 'lastcheck' => time() + ]); + $server->save(); + + return $this->response(array('error' => false)); + } catch (FuelException $e) { + return $this->response(array('error' => true, 'message' => $e->getMessage() ?: 'Wrong parameters'), 400); + } + } + + public function delete_server() + { + try { + $server = Input::delete('server_id'); + $user = Session::get('user'); + + $server = Model_Server::find_by_pk($server); + + if(!$server || $server->user_id !== $user->id) + throw new FuelException('No server found!'); + + $server->set(['disable' => 1]); + $server->save(); + + return $this->response(array('error' => false)); + } catch (FuelException $e) { + return $this->response(array('error' => true, 'message' => $e->getMessage() ?: 'Wrong parameters'), 400); + } + } } \ No newline at end of file diff --git a/fuel/app/classes/controller/settings.php b/fuel/app/classes/controller/settings.php index 94610a9..2ef432c 100644 --- a/fuel/app/classes/controller/settings.php +++ b/fuel/app/classes/controller/settings.php @@ -1,6 +1,7 @@ template->js_bottom = ['plex_alert.js']; + $body = View::forge('settings/servers'); - $servers = Model_Server::find_by('user_id',Session::get('user')->id); + $user_id = Session::get('user')->id; + + $servers = Model_Server::find(function($query) use($user_id) { + $query + ->where('user_id', $user_id) + ->and_where('disable', 0) + ; + }); $body->set('servers', $servers); $this->template->body = $body; } + + public function action_libraries() + { + $body = View::forge('settings/libraries'); + + $user_id = Session::get('user')->id; + + $libraries = Model_Library::find(function($query) use($user_id) { + $query + ->select('library.*') + ->join('server', 'LEFT') + ->on('server.id', '=','library.server_id' ) + ->where('server.user_id', $user_id) + ->and_where('server.disable', 0) + ; + }); + + $body->set('libraries', $libraries); + + $this->template->body = $body; + } } \ No newline at end of file diff --git a/fuel/app/classes/model/library.php b/fuel/app/classes/model/library.php index 3664b97..ad2b28d 100644 --- a/fuel/app/classes/model/library.php +++ b/fuel/app/classes/model/library.php @@ -17,6 +17,34 @@ class Model_Library extends Model_Overwrite 'disable' ); + private $_server = null; + + public function getServer() + { + if(!$this->_server) + $this->_server = Model_Server::find_by_pk($this->server_id); + + return $this->_server; + } + + public function getLastUpdate() + { + $dateString = date('Y/m/d H:i:s', time()); + $now = new DateTime($dateString); + + $dateString = date('Y-m-d H:i:s', $this->updatedAt); + $time = new DateTime($dateString); + + $diff = date_diff($now, $time); + + $days = $diff->days . 'd '; + $hours = $diff->h . 'h '; + $minutes = $diff->i . 'min '; + $seconds = $diff->s . 's'; + + return $days.$hours.$minutes.$seconds; + } + /** * List all libraries and register it in database * @param $server diff --git a/fuel/app/classes/model/server.php b/fuel/app/classes/model/server.php index bb543b3..e54741a 100755 --- a/fuel/app/classes/model/server.php +++ b/fuel/app/classes/model/server.php @@ -44,13 +44,6 @@ class Model_Server extends Model_Overwrite //$curl = Request::forge('http://' . $config['main']['server'] . ':' . $config['main']['port'] . '/:/prefs?X-Plex-Token=' . $config['main']['token'], 'curl'); - public function initialise() - { - $servers = Model_Server::find(); - - self::BrowseServeur($servers); - } - /** * Browse the list of server registered * @param null $_servers diff --git a/fuel/app/config/lock.php b/fuel/app/config/lock.php new file mode 100644 index 0000000..450ef01 --- /dev/null +++ b/fuel/app/config/lock.php @@ -0,0 +1,3 @@ +
-
-
- -
-
-
+
+
-
-
- - + type="button"> +
-
-
+
+
div').css('background-image', 'url("/cover/movie?movie_id='+ movie_id +'&width='+ 126 +'&height='+189+'")'); }, (index + 1) * 100); }); + $('.HubCell-hubActions-28w1- button').on('click', function(){ + var parent = $(this).closest('div[data-qa-id]'); + var select = $(parent).data('qa-id'); + var previous = $(parent).find('button[data-hubcell-action="previous"]'); + var next = $(parent).find('button[data-hubcell-action="next"]'); + + if($(this).data('hubcell-action') === 'previous') { + $('#' + select + '_list').animate({scrollLeft: $('#' + select + '_list').scrollLeft() - 152 * 2}, 500); + setTimeout(function(){ + if($('#' + select + '_list').scrollLeft() <= (150 * 19)) { + $(next).removeClass('isDisabled'); + } + + if($('#' + select + '_list').scrollLeft() === 0) { + $(previous).addClass('isDisabled'); + } + }, 500); + } + if($(this).data('hubcell-action') === 'next') { + $('#' + select + '_list').animate({scrollLeft: $('#' + select + '_list').scrollLeft() + 152 * 2}, 500); + setTimeout(function(){ + if($('#' + select + '_list').scrollLeft() > 0) { + $(previous).removeClass('isDisabled'); + } + + console.log($('#' + select + '_list').scrollLeft()); + + if($('#' + select + '_list').scrollLeft() >= (150 * 19)) { + $(next).addClass('isDisabled'); + } + }, 500); + } + }); }); \ No newline at end of file diff --git a/fuel/app/views/install/index.php b/fuel/app/views/install/index.php index 79059d3..51f5e70 100755 --- a/fuel/app/views/install/index.php +++ b/fuel/app/views/install/index.php @@ -36,8 +36,8 @@
  • Configuration
  • Configuration SQL
  • Create Tables
  • -
  • Add plex server
  • Create Admin Account
  • +
  • Add plex server
  • @@ -283,99 +283,99 @@ Next >
    -