diff --git a/.gitignore b/.gitignore index f9c6874..24e95a5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /composer.phar **/src/**/om/* **/src/**/map/* +app/propel/ diff --git a/src/Deblan/Bundle/RtmpBundle/AuthProvider/AuthProvider.php b/src/Deblan/Bundle/RtmpBundle/AuthProvider/AuthProvider.php new file mode 100644 index 0000000..69393e2 --- /dev/null +++ b/src/Deblan/Bundle/RtmpBundle/AuthProvider/AuthProvider.php @@ -0,0 +1,17 @@ + + */ +interface AuthProvider +{ + /** + * Returns the authentication validity + * + * @return bool + */ + public function isValid(); +} diff --git a/src/Deblan/Bundle/RtmpBundle/AuthProvider/PropelAuthProvider.php b/src/Deblan/Bundle/RtmpBundle/AuthProvider/PropelAuthProvider.php new file mode 100644 index 0000000..e41e3a6 --- /dev/null +++ b/src/Deblan/Bundle/RtmpBundle/AuthProvider/PropelAuthProvider.php @@ -0,0 +1,181 @@ + + */ +class PropelAuthProvider implements AuthProvider +{ + /** + * @var string + */ + protected $host; + + /** + * @var string + */ + protected $path; + + /** + * @var string + */ + protected $key; + + /** + * @var string + */ + protected $name; + + + /** + * @param string $host + * + * @return __CLASS__ + */ + public function setHost($host) + { + $this->host = (string) $host; + + return $this; + } + + /** + * @return string + */ + public function getHost() + { + return $this->host; + } + + /** + * @param string $path + * + * @return __CLASS__ + */ + public function setPath($path) + { + $this->path = (string) $path; + + return $this; + } + + /** + * @return string + */ + public function getPath() + { + return $this->path; + } + + /** + * @param string $name + * + * @return PropelAuthProvider + */ + public function setName($name) + { + $this->name = (string) $name; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $key + * + * @return PropelAuthProvider + */ + public function setKey($key) + { + $this->key = (string) $key; + + return $this; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * Handles a request + * + * @param Request $request + * + * @return PropelAuthProvider + */ + public function handleRequest(Request $request) + { + $bag = $request->isMethod('post') ? $request->request : $request->query; + + $this->setName($bag->get('name')); + + $parse = parse_url($bag->get('swfurl')); + + if (!empty($parse['host'])) { + $this->setHost($parse['host']); + } + + if (!empty($parse['path'])) { + $this->setPath($parse['path']); + } + + if (!empty($parse['query'])) { + $regex = '/key=([^&]+)/'; + preg_match($regex, $parse['query'], $match); + + if (!empty($match[1])) { + $this->setKey($match[1]); + } + } + } + + /** + * {@inheritdoc} + */ + public function isValid() + { + $accounts = AccountQuery::create() + ->filterByChannel($this->getName()) + ->filterByKey($this->getKey()) + ->find(); + + if ($accounts->count() === 0) { + return false; + } + + $stream = StreamQuery::create() + ->filterByHost($this->getHost()) + ->filterByPath($this->getPath()) + ->findOne(); + + if ($stream === null) { + return false; + } + + foreach ($accounts as $account) { + if ($account->getStreams()->contains($stream)) { + return true; + } + } + + return false; + } +} diff --git a/src/Deblan/Bundle/RtmpBundle/Command/TestCommand.php b/src/Deblan/Bundle/RtmpBundle/Command/TestCommand.php new file mode 100644 index 0000000..0a555c8 --- /dev/null +++ b/src/Deblan/Bundle/RtmpBundle/Command/TestCommand.php @@ -0,0 +1,34 @@ + + */ +class TestCommand extends ContainerAwareCommand +{ + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('test'); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $foo = 'rtmp://local.stream-server/live?key=myPassword'; + $parse = parse_url($foo); + + var_dump($parse); + } +} diff --git a/src/Deblan/Bundle/RtmpBundle/Controller/AuthController.php b/src/Deblan/Bundle/RtmpBundle/Controller/AuthController.php index 9222b32..d380e22 100644 --- a/src/Deblan/Bundle/RtmpBundle/Controller/AuthController.php +++ b/src/Deblan/Bundle/RtmpBundle/Controller/AuthController.php @@ -5,6 +5,7 @@ namespace Deblan\Bundle\RtmpBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\HttpFoundation\Response; /** * @author Simon Vieille @@ -12,12 +13,18 @@ use Symfony\Component\Routing\Annotation\Route; class AuthController extends Controller { /** - * @Route("/auth", name="auth") * @param Request $request * - * @return \Symfony\Bundle\FrameworkBundle\Controller\Response + * @return Response + * + * @Route("/auth", name="auth") */ public function authAction(Request $request) { + $authProvider = $this->container->get('rtmp.auth.propel_provider'); + + $authProvider->handleRequest($request); + + return new Response(null, $authProvider->isValid() ? 200 : 401); } } diff --git a/src/Deblan/Bundle/RtmpBundle/Resources/config/propel/schema.xml b/src/Deblan/Bundle/RtmpBundle/Resources/config/propel/schema.xml index 81c2081..c995798 100644 --- a/src/Deblan/Bundle/RtmpBundle/Resources/config/propel/schema.xml +++ b/src/Deblan/Bundle/RtmpBundle/Resources/config/propel/schema.xml @@ -2,7 +2,8 @@ - + +
@@ -16,7 +17,7 @@ - +
diff --git a/src/Deblan/Bundle/RtmpBundle/Resources/config/services.xml b/src/Deblan/Bundle/RtmpBundle/Resources/config/services.xml index 787808a..3c88ec2 100644 --- a/src/Deblan/Bundle/RtmpBundle/Resources/config/services.xml +++ b/src/Deblan/Bundle/RtmpBundle/Resources/config/services.xml @@ -4,13 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> -