Compare commits
1 commit
master
...
dev-master
Author | SHA1 | Date | |
---|---|---|---|
Simon Vieille | 9f21fc2ca0 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,3 +12,4 @@
|
||||||
/composer.phar
|
/composer.phar
|
||||||
**/src/**/om/*
|
**/src/**/om/*
|
||||||
**/src/**/map/*
|
**/src/**/map/*
|
||||||
|
app/propel/
|
||||||
|
|
17
src/Deblan/Bundle/RtmpBundle/AuthProvider/AuthProvider.php
Normal file
17
src/Deblan/Bundle/RtmpBundle/AuthProvider/AuthProvider.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\Bundle\RtmpBundle\AuthProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AuthProvider
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
interface AuthProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the authentication validity
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isValid();
|
||||||
|
}
|
181
src/Deblan/Bundle/RtmpBundle/AuthProvider/PropelAuthProvider.php
Normal file
181
src/Deblan/Bundle/RtmpBundle/AuthProvider/PropelAuthProvider.php
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\Bundle\RtmpBundle\AuthProvider;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Deblan\Bundle\RtmpBundle\Model\StreamQuery;
|
||||||
|
use Deblan\Bundle\RtmpBundle\Model\AccountQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PropelAuthProvider.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
34
src/Deblan/Bundle/RtmpBundle/Command/TestCommand.php
Normal file
34
src/Deblan/Bundle/RtmpBundle/Command/TestCommand.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\Bundle\RtmpBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ namespace Deblan\Bundle\RtmpBundle\Controller;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
@ -12,12 +13,18 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||||
class AuthController extends Controller
|
class AuthController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @Route("/auth", name="auth")
|
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response
|
* @return Response
|
||||||
|
*
|
||||||
|
* @Route("/auth", name="auth")
|
||||||
*/
|
*/
|
||||||
public function authAction(Request $request)
|
public function authAction(Request $request)
|
||||||
{
|
{
|
||||||
|
$authProvider = $this->container->get('rtmp.auth.propel_provider');
|
||||||
|
|
||||||
|
$authProvider->handleRequest($request);
|
||||||
|
|
||||||
|
return new Response(null, $authProvider->isValid() ? 200 : 401);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
<database defaultIdMethod="native" name="default" namespace="Deblan\Bundle\RtmpBundle\Model">
|
<database defaultIdMethod="native" name="default" namespace="Deblan\Bundle\RtmpBundle\Model">
|
||||||
<table name="stream">
|
<table name="stream">
|
||||||
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/>
|
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/>
|
||||||
<column name="uri" type="VARCHAR" size="255" required="true" />
|
<column name="host" type="VARCHAR" size="255" required="true" />
|
||||||
|
<column name="path" type="VARCHAR" size="255" required="true" />
|
||||||
|
|
||||||
<behavior name="timestampable"/>
|
<behavior name="timestampable"/>
|
||||||
</table>
|
</table>
|
||||||
|
@ -16,7 +17,7 @@
|
||||||
<behavior name="timestampable"/>
|
<behavior name="timestampable"/>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table name="account_has_stream">
|
<table name="account_has_stream" isCrossRef="true">
|
||||||
<column name="stream_id" type="integer" required="true" primaryKey="true" />
|
<column name="stream_id" type="integer" required="true" primaryKey="true" />
|
||||||
<column name="account_id" type="integer" required="true" primaryKey="true" />
|
<column name="account_id" type="integer" required="true" primaryKey="true" />
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,8 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
<!--
|
|
||||||
<services>
|
<services>
|
||||||
<service id="deblan_rtmp.example" class="Deblan\Bundle\RtmpBundle\Example">
|
<service id="rtmp.auth.propel_provider" class="Deblan\Bundle\RtmpBundle\AuthProvider\PropelAuthProvider">
|
||||||
<argument type="service" id="service_id" />
|
|
||||||
<argument>plain_value</argument>
|
|
||||||
<argument>%parameter_name%</argument>
|
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
-->
|
|
||||||
</container>
|
</container>
|
||||||
|
|
Loading…
Reference in a new issue