From d0cae6a99a332af79b2506205aa25aad4313d912 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 21 Jul 2012 19:43:50 +0200 Subject: [PATCH 01/35] Very basic conversion of ocs to Symfony Routing Component --- .gitmodules | 3 + 3rdparty/Symfony/Component/Routing | 1 + lib/base.php | 3 + lib/ocs.php | 146 ++++++++++++++++++----------- 4 files changed, 97 insertions(+), 56 deletions(-) create mode 100644 .gitmodules create mode 160000 3rdparty/Symfony/Component/Routing diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..0f4ad58807 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "3rdparty/Symfony/Component/Routing"] + path = 3rdparty/Symfony/Component/Routing + url = git://github.com/symfony/Routing.git diff --git a/3rdparty/Symfony/Component/Routing b/3rdparty/Symfony/Component/Routing new file mode 160000 index 0000000000..d724838908 --- /dev/null +++ b/3rdparty/Symfony/Component/Routing @@ -0,0 +1 @@ +Subproject commit d72483890880a987afa679503af096d2aaf7d2ee diff --git a/lib/base.php b/lib/base.php index 631ed4fcce..fcca1e77d2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -86,6 +86,9 @@ class OC{ elseif(strpos($className,'Sabre_')===0) { require_once str_replace('_','/',$className) . '.php'; } + elseif(strpos($className,'Symfony\\')===0){ + require_once str_replace('\\','/',$className) . '.php'; + } elseif(strpos($className,'Test_')===0){ require_once 'tests/lib/'.strtolower(str_replace('_','/',substr($className,5)) . '.php'); } diff --git a/lib/ocs.php b/lib/ocs.php index 77dd437d6c..7e84d0e544 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -21,7 +21,11 @@ * */ - +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\Exception\ResourceNotFoundException; /** * Class to handle open collaboration services API requests @@ -95,73 +99,103 @@ class OC_OCS { exit(); } - // preprocess url - $url=$_SERVER['REQUEST_URI']; - if(substr($url,(strlen($url)-1))<>'/') $url.='/'; - $ex=explode('/',$url); - $paracount=count($ex); - - // eventhandler + $routes = new RouteCollection(); // CONFIG - // apiconfig - GET - CONFIG - if(($method=='get') and (strtolower($ex[$paracount-3])=='v1.php') and (strtolower($ex[$paracount-2])=='config')){ - $format=OC_OCS::readdata('format','text'); - OC_OCS::apiconfig($format); + $routes->add('config', + new Route('/config.{format}', + array('format'=>'', + 'action' => function ($parameters) { + OC_OCS::apiconfig($parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text')); + }), + array('format'=>'xml|json'))); // PERSON - // personcheck - POST - PERSON/CHECK - }elseif(($method=='post') and (strtolower($ex[$paracount-4])=='v1.php') and (strtolower($ex[$paracount-3])=='person') and (strtolower($ex[$paracount-2])=='check')){ - $format=OC_OCS::readdata('format','text'); - $login=OC_OCS::readdata('login','text'); - $passwd=OC_OCS::readdata('password','text'); - OC_OCS::personcheck($format,$login,$passwd); + $routes->add('person_check', + new Route('/person/check.{format}', + array('format'=>'', + 'action' => function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $login=OC_OCS::readdata('login','text'); + $passwd=OC_OCS::readdata('password','text'); + OC_OCS::personcheck($format,$login,$passwd); + }), + array('_method'=>'post', + 'format'=>'xml|json'))); // ACTIVITY // activityget - GET ACTIVITY page,pagesize als urlparameter - }elseif(($method=='get') and (strtolower($ex[$paracount-3])=='v1.php')and (strtolower($ex[$paracount-2])=='activity')){ - $format=OC_OCS::readdata('format','text'); - $page=OC_OCS::readdata('page','int'); - $pagesize=OC_OCS::readdata('pagesize','int'); - if($pagesize<1 or $pagesize>100) $pagesize=10; - OC_OCS::activityget($format,$page,$pagesize); - + $routes->add('activity_get', + new Route('/activity.{format}', + array('format'=>'', + 'action' => function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $page=OC_OCS::readdata('page','int'); + $pagesize=OC_OCS::readdata('pagesize','int'); + if($pagesize<1 or $pagesize>100) $pagesize=10; + OC_OCS::activityget($format,$page,$pagesize); + }), + array('format'=>'xml|json'))); // activityput - POST ACTIVITY - }elseif(($method=='post') and (strtolower($ex[$paracount-3])=='v1.php')and (strtolower($ex[$paracount-2])=='activity')){ - $format=OC_OCS::readdata('format','text'); - $message=OC_OCS::readdata('message','text'); - OC_OCS::activityput($format,$message); - + $routes->add('activity_put', + new Route('/activity.{format}', + array('format'=>'', + 'action' => function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $message=OC_OCS::readdata('message','text'); + OC_OCS::activityput($format,$message); + }), + array('_method'=>'post', + 'format'=>'xml|json'))); // PRIVATEDATA // get - GET DATA - }elseif(($method=='get') and (strtolower($ex[$paracount-4])=='v1.php')and (strtolower($ex[$paracount-2])=='getattribute')){ - $format=OC_OCS::readdata('format','text'); - OC_OCS::privateDataGet($format); - - }elseif(($method=='get') and (strtolower($ex[$paracount-5])=='v1.php')and (strtolower($ex[$paracount-3])=='getattribute')){ - $format=OC_OCS::readdata('format','text'); - $app=$ex[$paracount-2]; - OC_OCS::privateDataGet($format, $app); - }elseif(($method=='get') and (strtolower($ex[$paracount-6])=='v1.php')and (strtolower($ex[$paracount-4])=='getattribute')){ - $format=OC_OCS::readdata('format','text'); - $key=$ex[$paracount-2]; - $app=$ex[$paracount-3]; - OC_OCS::privateDataGet($format, $app,$key); - + $routes->add('privatedata_get', + new Route('/privatedata/getattribute/{app}/{key}.{format}', + array('app' => '', + 'key' => '', + 'format' => '', + 'action' => function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $app = addslashes(strip_tags($parameters['app'])); + $key = addslashes(strip_tags($parameters['key'])); + OC_OCS::privateDataGet($format, $app, $key); + }), + array('format'=>'xml|json'))); // set - POST DATA - }elseif(($method=='post') and (strtolower($ex[$paracount-6])=='v1.php')and (strtolower($ex[$paracount-4])=='setattribute')){ - $format=OC_OCS::readdata('format','text'); - $key=$ex[$paracount-2]; - $app=$ex[$paracount-3]; - $value=OC_OCS::readdata('value','text'); - OC_OCS::privatedataset($format, $app, $key, $value); + $routes->add('privatedata_set', + new Route('/privatedata/setattribute/{app}/{key}.{format}', + array('format'=>'', + 'action' => function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $app = addslashes(strip_tags($parameters['app'])); + $key = addslashes(strip_tags($parameters['key'])); + $value=OC_OCS::readdata('value','text'); + OC_OCS::privateDataSet($format, $app, $key, $value); + }), + array('_method'=>'post', + 'format'=>'xml|json'))); // delete - POST DATA - }elseif(($method=='post') and (strtolower($ex[$paracount-6])=='v1.php')and (strtolower($ex[$paracount-4])=='deleteattribute')){ - $format=OC_OCS::readdata('format','text'); - $key=$ex[$paracount-2]; - $app=$ex[$paracount-3]; - OC_OCS::privatedatadelete($format, $app, $key); + $routes->add('privatedata_delete', + new Route('/privatedata/deleteattribute/{app}/{key}.{format}', + array('format'=>'', + 'action' => function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $app = addslashes(strip_tags($parameters['app'])); + $key = addslashes(strip_tags($parameters['key'])); + OC_OCS::privateDataDelete($format, $app, $key); + }), + array('_method'=>'post', + 'format'=>'xml|json'))); - }else{ + $context = new RequestContext($_SERVER['REQUEST_URI'], $method); + + $matcher = new UrlMatcher($routes, $context); + + try { + $parameters = $matcher->match($_SERVER['PATH_INFO']); + $action = $parameters['action']; + unset($parameters['action']); + call_user_func($action, $parameters); + } catch (ResourceNotFoundException $e) { $format=OC_OCS::readdata('format','text'); $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; $txt.=OC_OCS::getdebugoutput(); From 768b44b9b685a07af6030e484ab6322ba44b5b7e Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 23 Jul 2012 18:58:52 +0200 Subject: [PATCH 02/35] Convert routing to ownCloud fluid interface --- lib/ocs.php | 186 +++++++++++++++++++++---------------------------- lib/route.php | 50 +++++++++++++ lib/router.php | 50 +++++++++++++ 3 files changed, 178 insertions(+), 108 deletions(-) create mode 100644 lib/route.php create mode 100644 lib/router.php diff --git a/lib/ocs.php b/lib/ocs.php index 7e84d0e544..2700707666 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -21,12 +21,6 @@ * */ -use Symfony\Component\Routing\Matcher\UrlMatcher; -use Symfony\Component\Routing\RequestContext; -use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\Exception\ResourceNotFoundException; - /** * Class to handle open collaboration services API requests * @@ -87,114 +81,89 @@ class OC_OCS { // overwrite the 404 error page returncode header("HTTP/1.0 200 OK"); + $router = new OC_Router(); + $router->useCollection('ocs'); + // CONFIG + $router->create('config', '/config.{format}') + ->defaults(array('format'=>'')) + ->action('OC_OCS', 'apiConfig') + ->requirements(array('format'=>'xml|json')); - if($_SERVER['REQUEST_METHOD'] == 'GET') { - $method='get'; - }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { - $method='put'; - }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { - $method='post'; - }else{ - echo('internal server error: method not supported'); - exit(); - } + // PERSON + $router->create('person_check', '/person/check.{format}') + ->post() + ->defaults(array('format'=>'')) + ->action(function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $login=OC_OCS::readdata('login','text'); + $passwd=OC_OCS::readdata('password','text'); + OC_OCS::personcheck($format,$login,$passwd); + }) + ->requirements(array('format'=>'xml|json')); - $routes = new RouteCollection(); - // CONFIG - $routes->add('config', - new Route('/config.{format}', - array('format'=>'', - 'action' => function ($parameters) { - OC_OCS::apiconfig($parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text')); - }), - array('format'=>'xml|json'))); - - // PERSON - $routes->add('person_check', - new Route('/person/check.{format}', - array('format'=>'', - 'action' => function ($parameters) { - $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); - $login=OC_OCS::readdata('login','text'); - $passwd=OC_OCS::readdata('password','text'); - OC_OCS::personcheck($format,$login,$passwd); - }), - array('_method'=>'post', - 'format'=>'xml|json'))); - - // ACTIVITY - // activityget - GET ACTIVITY page,pagesize als urlparameter - $routes->add('activity_get', - new Route('/activity.{format}', - array('format'=>'', - 'action' => function ($parameters) { - $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); - $page=OC_OCS::readdata('page','int'); - $pagesize=OC_OCS::readdata('pagesize','int'); - if($pagesize<1 or $pagesize>100) $pagesize=10; - OC_OCS::activityget($format,$page,$pagesize); - }), - array('format'=>'xml|json'))); - // activityput - POST ACTIVITY - $routes->add('activity_put', - new Route('/activity.{format}', - array('format'=>'', - 'action' => function ($parameters) { - $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + // ACTIVITY + // activityget - GET ACTIVITY page,pagesize als urlparameter + $router->create('activity_get', '/activity.{format}') + ->defaults(array('format'=>'')) + ->action(function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $page=OC_OCS::readdata('page','int'); + $pagesize=OC_OCS::readdata('pagesize','int'); + if($pagesize<1 or $pagesize>100) $pagesize=10; + OC_OCS::activityget($format,$page,$pagesize); + }) + ->requirements(array('format'=>'xml|json')); + // activityput - POST ACTIVITY + $router->create('activity_put', '/activity.{format}') + ->post() + ->defaults(array('format'=>'')) + ->action(function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); $message=OC_OCS::readdata('message','text'); OC_OCS::activityput($format,$message); - }), - array('_method'=>'post', - 'format'=>'xml|json'))); - // PRIVATEDATA - // get - GET DATA - $routes->add('privatedata_get', - new Route('/privatedata/getattribute/{app}/{key}.{format}', - array('app' => '', - 'key' => '', - 'format' => '', - 'action' => function ($parameters) { - $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); - $app = addslashes(strip_tags($parameters['app'])); - $key = addslashes(strip_tags($parameters['key'])); - OC_OCS::privateDataGet($format, $app, $key); - }), - array('format'=>'xml|json'))); - // set - POST DATA - $routes->add('privatedata_set', - new Route('/privatedata/setattribute/{app}/{key}.{format}', - array('format'=>'', - 'action' => function ($parameters) { - $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); - $app = addslashes(strip_tags($parameters['app'])); - $key = addslashes(strip_tags($parameters['key'])); - $value=OC_OCS::readdata('value','text'); - OC_OCS::privateDataSet($format, $app, $key, $value); - }), - array('_method'=>'post', - 'format'=>'xml|json'))); - // delete - POST DATA - $routes->add('privatedata_delete', - new Route('/privatedata/deleteattribute/{app}/{key}.{format}', - array('format'=>'', - 'action' => function ($parameters) { - $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); - $app = addslashes(strip_tags($parameters['app'])); - $key = addslashes(strip_tags($parameters['key'])); - OC_OCS::privateDataDelete($format, $app, $key); - }), - array('_method'=>'post', - 'format'=>'xml|json'))); + }) + ->requirements(array('format'=>'xml|json')); - $context = new RequestContext($_SERVER['REQUEST_URI'], $method); - - $matcher = new UrlMatcher($routes, $context); + // PRIVATEDATA + // get - GET DATA + $router->create('privatedata_get', + '/privatedata/getattribute/{app}/{key}.{format}') + ->defaults(array('app' => '', 'key' => '', 'format' => '')) + ->action(function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $app = addslashes(strip_tags($parameters['app'])); + $key = addslashes(strip_tags($parameters['key'])); + OC_OCS::privateDataGet($format, $app, $key); + }) + ->requirements(array('format'=>'xml|json')); + // set - POST DATA + $router->create('privatedata_set', + '/privatedata/setattribute/{app}/{key}.{format}') + ->post() + ->defaults(array('format'=>'')) + ->action(function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $app = addslashes(strip_tags($parameters['app'])); + $key = addslashes(strip_tags($parameters['key'])); + $value=OC_OCS::readdata('value','text'); + OC_OCS::privateDataSet($format, $app, $key, $value); + }) + ->requirements(array('format'=>'xml|json')); + // delete - POST DATA + $router->create('privatedata_delete', + '/privatedata/deleteattribute/{app}/{key}.{format}') + ->post() + ->defaults(array('format'=>'')) + ->action(function ($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); + $app = addslashes(strip_tags($parameters['app'])); + $key = addslashes(strip_tags($parameters['key'])); + OC_OCS::privateDataDelete($format, $app, $key); + }) + ->requirements(array('format'=>'xml|json')); try { - $parameters = $matcher->match($_SERVER['PATH_INFO']); - $action = $parameters['action']; - unset($parameters['action']); - call_user_func($action, $parameters); + $router->match($_SERVER['PATH_INFO']); } catch (ResourceNotFoundException $e) { $format=OC_OCS::readdata('format','text'); $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; @@ -388,7 +357,8 @@ class OC_OCS { * @param string $format * @return string xml/json */ - private static function apiConfig($format) { + public static function apiConfig($parameters) { + $format = $parameters['format'] ? $parameters['format'] : OC_OCS::readdata('format','text'); $xml['version']='1.5'; $xml['website']='ownCloud'; $xml['host']=OCP\Util::getServerHost(); diff --git a/lib/route.php b/lib/route.php new file mode 100644 index 0000000000..4344c97711 --- /dev/null +++ b/lib/route.php @@ -0,0 +1,50 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +use Symfony\Component\Routing\Route; + +class OC_Route extends Route { + public function method($method) { + $this->setRequirement('_method', $method); + return $this; + } + + public function post() { + $this->method('post'); + return $this; + } + + public function defaults($defaults) { + $action = $this->getDefault('action'); + $this->setDefaults($defaults); + if (isset($defaults['action'])) { + $action = $defaults['action']; + } + $this->action($action); + return $this; + } + + public function requirements($requirements) { + $method = $this->getRequirement('_method'); + $this->setRequirements($requirements); + if (isset($requirements['_method'])) { + $method = $requirements['_method']; + } + $this->method($method); + return $this; + } + + public function action($class, $function = null) { + $action = array($class, $function); + if (is_null($function)) { + $action = $class; + } + $this->setDefault('action', $action); + return $this; + } +} diff --git a/lib/router.php b/lib/router.php new file mode 100644 index 0000000000..f037ecdfef --- /dev/null +++ b/lib/router.php @@ -0,0 +1,50 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Routing\RouteCollection; +//use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\Exception\ResourceNotFoundException; + +class OC_Router { + protected $collections = array(); + protected $collection = null; + + public function useCollection($name) { + if (!isset($this->collections[$name])) { + $this->collections[$name] = new RouteCollection(); + } + $this->collection = $this->collections[$name]; + } + + public function create($name, $pattern, array $defaults = array(), array $requirements = array()) { + $route = new OC_Route($pattern, $defaults, $requirements); + $this->collection->add($name, $route); + return $route; + } + + public function match($url) { + $context = new RequestContext($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']); + $matcher = new UrlMatcher($this->collection, $context); + $parameters = $matcher->match($url); + if (isset($parameters['action'])) { + $action = $parameters['action']; + if (!is_callable($action)) { + var_dump($action); + throw new Exception('not a callable action'); + } + unset($parameters['action']); + call_user_func($action, $parameters); + } elseif (isset($parameters['file'])) { + include ($parameters['file']); + } else { + throw new Exception('no action available'); + } + } +} From ac9dbd4b83852d137d35cb87911ebd6b21c494db Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 25 Jul 2012 17:45:29 +0200 Subject: [PATCH 03/35] Add functions for the common HTTP methods --- lib/route.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/route.php b/lib/route.php index 4344c97711..0d3339add6 100644 --- a/lib/route.php +++ b/lib/route.php @@ -19,6 +19,21 @@ class OC_Route extends Route { return $this; } + public function get() { + $this->method('get'); + return $this; + } + + public function put() { + $this->method('put'); + return $this; + } + + public function delete() { + $this->method('delete'); + return $this; + } + public function defaults($defaults) { $action = $this->getDefault('action'); $this->setDefaults($defaults); From 5a0d476ab15f4b6a42c713aa503c18a6148bb24b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 25 Jul 2012 17:59:50 +0200 Subject: [PATCH 04/35] Convert new actions --- lib/ocs.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/ocs.php b/lib/ocs.php index 570f5ac3e5..61df38d2db 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -177,8 +177,14 @@ class OC_OCS { // CLOUD // systemWebApps - }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-4]=='cloud') and ($ex[$paracount-3] == 'system') and ($ex[$paracount-2] == 'webapps')){ - OC_OCS::systemwebapps($format); + $router->create('system_webapps', + '/cloud/system/webapps.{format}') + ->defaults(array('format' => $format)) + ->action(function ($parameters) { + $format = $parameters['format']; + OC_OCS::systemwebapps($format); + }) + ->requirements(array('format'=>'xml|json')); // quotaget $router->create('quota_get', @@ -204,14 +210,26 @@ class OC_OCS { ->requirements(array('format'=>'xml|json')); // keygetpublic - }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'publickey')){ - $user=$ex[$paracount-3]; - OC_OCS::publicKeyGet($format,$user); + $router->create('keygetpublic', + '/cloud/user/{user}/publickey.{format}') + ->defaults(array('format' => $format)) + ->action(function ($parameters) { + $format = $parameters['format']; + $user = $parameters['user']; + OC_OCS::publicKeyGet($format,$user); + }) + ->requirements(array('format'=>'xml|json')); // keygetprivate - }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')){ - $user=$ex[$paracount-3]; - OC_OCS::privateKeyGet($format,$user); + $router->create('keygetpublic', + '/cloud/user/{user}/privatekey.{format}') + ->defaults(array('format' => $format)) + ->action(function ($parameters) { + $format = $parameters['format']; + $user = $parameters['user']; + OC_OCS::privateKeyGet($format,$user); + }) + ->requirements(array('format'=>'xml|json')); // add more calls here From b3848581bf5f77008a71cf79ba6e3d61b33baed6 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 25 Jul 2012 18:00:03 +0200 Subject: [PATCH 05/35] Small cleanup --- lib/ocs.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ocs.php b/lib/ocs.php index 61df38d2db..d7a7951fab 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -90,8 +90,6 @@ class OC_OCS { exit(); } - // preprocess url - $url = strtolower($_SERVER['REQUEST_URI']); $format = self::readData($method, 'format', 'text', ''); $router = new OC_Router(); From 9e80f0954d45465dfba261c5b5a501e77eb595c9 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 30 Jul 2012 20:48:03 +0200 Subject: [PATCH 06/35] Add loading of routes in OC_Router --- lib/router.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/router.php b/lib/router.php index f037ecdfef..4b6b076e21 100644 --- a/lib/router.php +++ b/lib/router.php @@ -16,6 +16,19 @@ class OC_Router { protected $collections = array(); protected $collection = null; + /** + * loads the api routes + */ + public function loadRoutes(){ + // TODO cache + foreach(OC_APP::getEnabledApps() as $app){ + $file = OC_App::getAppPath($app).'/appinfo/routes.php'; + if(file_exists($file)){ + require_once($file); + } + } + } + public function useCollection($name) { if (!isset($this->collections[$name])) { $this->collections[$name] = new RouteCollection(); From 3e8b6e816a3f89ac20f22fdde630946058e5d184 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 30 Jul 2012 20:50:32 +0200 Subject: [PATCH 07/35] Create OC_Router in OC::init --- lib/base.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/base.php b/lib/base.php index 5041f43648..29a3502e35 100644 --- a/lib/base.php +++ b/lib/base.php @@ -62,6 +62,10 @@ class OC{ * requested file of app */ public static $REQUESTEDFILE = ''; + /* + * OC router + */ + public static $router = null; /** * check if owncloud runs in cli mode */ @@ -354,6 +358,8 @@ class OC{ OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); + OC::$router = new OC_Router(); + // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; From ca1454ab1a9a20f51544d8822b4c16ef00c35264 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 31 Jul 2012 22:33:11 +0200 Subject: [PATCH 08/35] Routing: Method needs to be uppercase --- lib/route.php | 10 +++++----- lib/router.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/route.php b/lib/route.php index 0d3339add6..df3a18e844 100644 --- a/lib/route.php +++ b/lib/route.php @@ -10,27 +10,27 @@ use Symfony\Component\Routing\Route; class OC_Route extends Route { public function method($method) { - $this->setRequirement('_method', $method); + $this->setRequirement('_method', strtoupper($method)); return $this; } public function post() { - $this->method('post'); + $this->method('POST'); return $this; } public function get() { - $this->method('get'); + $this->method('GET'); return $this; } public function put() { - $this->method('put'); + $this->method('PUT'); return $this; } public function delete() { - $this->method('delete'); + $this->method('DELETE'); return $this; } diff --git a/lib/router.php b/lib/router.php index 4b6b076e21..5dd51e7915 100644 --- a/lib/router.php +++ b/lib/router.php @@ -49,7 +49,7 @@ class OC_Router { if (isset($parameters['action'])) { $action = $parameters['action']; if (!is_callable($action)) { - var_dump($action); + var_dump($action); throw new Exception('not a callable action'); } unset($parameters['action']); From 3722928c46d0e4ec1935e4da4087b76aee24dd5d Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 2 Aug 2012 17:47:38 +0200 Subject: [PATCH 09/35] Change access to router object to getter function --- lib/base.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/base.php b/lib/base.php index 29a3502e35..43588944d0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -62,14 +62,14 @@ class OC{ * requested file of app */ public static $REQUESTEDFILE = ''; - /* - * OC router - */ - public static $router = null; /** * check if owncloud runs in cli mode */ public static $CLI = false; + /* + * OC router + */ + protected static $router = null; /** * SPL autoload */ @@ -275,6 +275,14 @@ class OC{ } } + public static function getRouter() { + if (!isset(OC::$router)) { + OC::$router = new OC_Router(); + } + + return OC::$router; + } + public static function init(){ // register autoloader spl_autoload_register(array('OC','autoload')); @@ -358,8 +366,6 @@ class OC{ OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); - OC::$router = new OC_Router(); - // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; From 72b2324b68c51baf140c6fab7957b59c31de4832 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 2 Aug 2012 17:59:18 +0200 Subject: [PATCH 10/35] Move loading of routes to OC::getRouter function --- lib/base.php | 1 + lib/router.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index 43588944d0..0d9ececc0c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -278,6 +278,7 @@ class OC{ public static function getRouter() { if (!isset(OC::$router)) { OC::$router = new OC_Router(); + OC::$router->loadRoutes(); } return OC::$router; diff --git a/lib/router.php b/lib/router.php index 5dd51e7915..a721255f29 100644 --- a/lib/router.php +++ b/lib/router.php @@ -16,10 +16,15 @@ class OC_Router { protected $collections = array(); protected $collection = null; + public function __construct() { + // TODO cache + $this->loadRoutes(); + } + /** * loads the api routes */ - public function loadRoutes(){ + public function loadRoutes() { // TODO cache foreach(OC_APP::getEnabledApps() as $app){ $file = OC_App::getAppPath($app).'/appinfo/routes.php'; From f63b9b44d8ac62a136d4cd6844e72af7a8044703 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 2 Aug 2012 21:51:31 +0200 Subject: [PATCH 11/35] Routing: combine all routes into one set --- lib/router.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/router.php b/lib/router.php index a721255f29..3ba2125465 100644 --- a/lib/router.php +++ b/lib/router.php @@ -15,30 +15,34 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException; class OC_Router { protected $collections = array(); protected $collection = null; - - public function __construct() { - // TODO cache - $this->loadRoutes(); - } + protected $root = null; /** * loads the api routes */ public function loadRoutes() { // TODO cache + $this->root = $this->getCollection('root'); foreach(OC_APP::getEnabledApps() as $app){ $file = OC_App::getAppPath($app).'/appinfo/routes.php'; if(file_exists($file)){ + $this->useCollection($app); require_once($file); + $collection = $this->getCollection($app); + $this->root->addCollection($collection, '/apps/'.$app); } } } - public function useCollection($name) { + protected function getCollection($name) { if (!isset($this->collections[$name])) { $this->collections[$name] = new RouteCollection(); } - $this->collection = $this->collections[$name]; + return $this->collections[$name]; + } + + public function useCollection($name) { + $this->collection = $this->getCollection($name); } public function create($name, $pattern, array $defaults = array(), array $requirements = array()) { @@ -49,7 +53,7 @@ class OC_Router { public function match($url) { $context = new RequestContext($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']); - $matcher = new UrlMatcher($this->collection, $context); + $matcher = new UrlMatcher($this->root, $context); $parameters = $matcher->match($url); if (isset($parameters['action'])) { $action = $parameters['action']; From 87d1cdb94567d5514e0a2988f69935d932b58ff6 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 11 Aug 2012 00:04:43 +0200 Subject: [PATCH 12/35] Fix for running doing routing in lib/ocs.php --- lib/ocs.php | 7 ++++++- lib/route.php | 4 +++- lib/router.php | 8 +++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/ocs.php b/lib/ocs.php index d7a7951fab..1df08df9fa 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -23,6 +23,9 @@ * */ +use Symfony\Component\Routing\Exception\ResourceNotFoundException; +use Symfony\Component\Routing\Exception\MethodNotAllowedException; + /** * Class to handle open collaboration services API requests * @@ -93,7 +96,7 @@ class OC_OCS { $format = self::readData($method, 'format', 'text', ''); $router = new OC_Router(); - $router->useCollection('ocs'); + $router->useCollection('root'); // CONFIG $router->create('config', '/config.{format}') ->defaults(array('format' => $format)) @@ -247,6 +250,8 @@ class OC_OCS { $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; $txt.=OC_OCS::getdebugoutput(); echo(OC_OCS::generatexml($format,'failed',999,$txt)); + } catch (MethodNotAllowedException $e) { + OC_Response::setStatus(405); } exit(); } diff --git a/lib/route.php b/lib/route.php index df3a18e844..772446e561 100644 --- a/lib/route.php +++ b/lib/route.php @@ -50,7 +50,9 @@ class OC_Route extends Route { if (isset($requirements['_method'])) { $method = $requirements['_method']; } - $this->method($method); + if ($method) { + $this->method($method); + } return $this; } diff --git a/lib/router.php b/lib/router.php index 3ba2125465..dbcaff4026 100644 --- a/lib/router.php +++ b/lib/router.php @@ -10,19 +10,21 @@ use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; //use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\Exception\ResourceNotFoundException; class OC_Router { protected $collections = array(); protected $collection = null; protected $root = null; + public function __construct() { + // TODO cache + $this->root = $this->getCollection('root'); + } + /** * loads the api routes */ public function loadRoutes() { - // TODO cache - $this->root = $this->getCollection('root'); foreach(OC_APP::getEnabledApps() as $app){ $file = OC_App::getAppPath($app).'/appinfo/routes.php'; if(file_exists($file)){ From 1763de08d0a4e8374cd21bf71d825b92426509f1 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 11 Aug 2012 00:57:46 +0200 Subject: [PATCH 13/35] Routing: Fix construction of RequestContext --- lib/router.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/router.php b/lib/router.php index dbcaff4026..eca59d6dc3 100644 --- a/lib/router.php +++ b/lib/router.php @@ -54,7 +54,11 @@ class OC_Router { } public function match($url) { - $context = new RequestContext($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']); + $baseUrl = OC_Helper::linkTo('', 'index.php'); + $method = $_SERVER['REQUEST_METHOD']; + $host = OC_Request::serverHost(); + $schema = OC_Request::serverProtocol(); + $context = new RequestContext($baseUrl, $method, $host, $schema); $matcher = new UrlMatcher($this->root, $context); $parameters = $matcher->match($url); if (isset($parameters['action'])) { From 1025e451a7610a9e5b50e7e99e808cb2d1915236 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 11 Aug 2012 01:00:26 +0200 Subject: [PATCH 14/35] Add router match to OC::handleRequest --- lib/base.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/base.php b/lib/base.php index b276cf5924..a05d84fbae 100644 --- a/lib/base.php +++ b/lib/base.php @@ -421,6 +421,15 @@ class OC{ header('location: '.OC_Helper::linkToRemote('webdav')); return; } + try { + OC::getRouter()->match(OC_Request::getPathInfo()); + return; + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { + //header('HTTP/1.0 404 Not Found'); + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { + OC_Response::setStatus(405); + return; + } // Handle app css files if(substr(OC::$REQUESTEDFILE,-3) == 'css') { self::loadCSSFile(); From 8c024947440e2f15a9effe5fe6d91e60e8571a07 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 12 Aug 2012 16:16:22 +0200 Subject: [PATCH 15/35] Routing: Prepare load funtions to be called from OC_Router --- lib/base.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/base.php b/lib/base.php index a05d84fbae..0d7e224d35 100644 --- a/lib/base.php +++ b/lib/base.php @@ -430,9 +430,12 @@ class OC{ OC_Response::setStatus(405); return; } + $app = OC::$REQUESTEDAPP; + $file = OC::$REQUESTEDFILE; + $param = array('app' => $app, 'file' => $file); // Handle app css files - if(substr(OC::$REQUESTEDFILE,-3) == 'css') { - self::loadCSSFile(); + if(substr($file,-3) == 'css') { + self::loadCSSFile($param); return; } // Someone is logged in : @@ -442,14 +445,12 @@ class OC{ OC_User::logout(); header("Location: ".OC::$WEBROOT.'/'); }else{ - $app = OC::$REQUESTEDAPP; - $file = OC::$REQUESTEDFILE; if(is_null($file)) { - $file = 'index.php'; + $param['file'] = 'index.php'; } - $file_ext = substr($file, -3); + $file_ext = substr($param['file'], -3); if ($file_ext != 'php' - || !self::loadAppScriptFile($app, $file)) { + || !self::loadAppScriptFile($param)) { header('HTTP/1.0 404 Not Found'); } } @@ -459,7 +460,9 @@ class OC{ self::handleLogin(); } - protected static function loadAppScriptFile($app, $file) { + public static function loadAppScriptFile($param) { + $app = $param['app']; + $file = $param['file']; $app_path = OC_App::getAppPath($app); $file = $app_path . '/' . $file; unset($app, $app_path); @@ -470,9 +473,9 @@ class OC{ return false; } - protected static function loadCSSFile() { - $app = OC::$REQUESTEDAPP; - $file = OC::$REQUESTEDFILE; + public static function loadCSSFile($param) { + $app = $param['app']; + $file = $param['file']; $app_path = OC_App::getAppPath($app); if (file_exists($app_path . '/' . $file)) { $app_web_path = OC_App::getAppWebPath($app); From db4111f6d50d5bf2195d4a082ffc9dcea1d911ce Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 12 Aug 2012 16:52:36 +0200 Subject: [PATCH 16/35] Routing: Add some core routes --- core/routes.php | 19 +++++++++++++++++++ lib/base.php | 3 ++- lib/router.php | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 core/routes.php diff --git a/core/routes.php b/core/routes.php new file mode 100644 index 0000000000..04b42d2059 --- /dev/null +++ b/core/routes.php @@ -0,0 +1,19 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +$this->create('app_css', '/apps/{app}/{file}') + ->requirements(array('file' => '.*.css')) + ->action('OC', 'loadCSSFile'); +$this->create('app_index_script', '/apps/{app}/') + ->defaults(array('file' => 'index.php')) + //->requirements(array('file' => '.*.php')) + ->action('OC', 'loadAppScriptFile'); +$this->create('app_script', '/apps/{app}/{file}') + ->defaults(array('file' => 'index.php')) + ->requirements(array('file' => '.*.php')) + ->action('OC', 'loadAppScriptFile'); diff --git a/lib/base.php b/lib/base.php index 0d7e224d35..3abfdb3566 100644 --- a/lib/base.php +++ b/lib/base.php @@ -440,8 +440,8 @@ class OC{ } // Someone is logged in : if(OC_User::isLoggedIn()) { - OC_App::loadApps(); if(isset($_GET["logout"]) and ($_GET["logout"])) { + OC_App::loadApps(); OC_User::logout(); header("Location: ".OC::$WEBROOT.'/'); }else{ @@ -461,6 +461,7 @@ class OC{ } public static function loadAppScriptFile($param) { + OC_App::loadApps(); $app = $param['app']; $file = $param['file']; $app_path = OC_App::getAppPath($app); diff --git a/lib/router.php b/lib/router.php index eca59d6dc3..65fc51aff2 100644 --- a/lib/router.php +++ b/lib/router.php @@ -34,6 +34,8 @@ class OC_Router { $this->root->addCollection($collection, '/apps/'.$app); } } + $this->useCollection('root'); + require_once('core/routes.php'); } protected function getCollection($name) { From 16dacba4900ce2bbb4f26040f6f5c2b698eae5da Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 12 Aug 2012 16:53:00 +0200 Subject: [PATCH 17/35] Routing: And start using them from php --- lib/helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index 8c362747a2..3cdb3e53c2 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -42,8 +42,8 @@ class OC_Helper { // Check if the app is in the app folder if( $app_path && file_exists( $app_path.'/'.$file )){ if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){ - $urlLinkTo = OC::$WEBROOT . '/?app=' . $app; - $urlLinkTo .= ($file!='index.php')?'&getfile=' . urlencode($file):''; + $urlLinkTo = OC::$WEBROOT . '/index.php/apps/' . $app; + $urlLinkTo .= ($file!='index.php') ? '/' . $file : ''; }else{ $urlLinkTo = OC_App::getAppWebPath($app) . '/' . $file; } From 4954e46bb2ba36c749b638111dc90500e12cedf7 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 15 Aug 2012 17:38:55 +0200 Subject: [PATCH 18/35] Use core routes in js too --- core/js/js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/js/js.js b/core/js/js.js index 7bded8e141..6881090f62 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -54,9 +54,9 @@ OC={ var isCore=OC.coreApps.indexOf(app)!=-1; var link=OC.webroot; if((file.substring(file.length-3) == 'php' || file.substring(file.length-3) == 'css') && !isCore){ - link+='/?app=' + app; + link+='/index.php/apps/' + app; if (file != 'index.php') { - link+='&getfile='; + link+='/'; if(type){ link+=encodeURI(type + '/'); } From ddfb9de14747b363bfcb70df00cea34b47abc0a3 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 15 Aug 2012 18:13:08 +0200 Subject: [PATCH 19/35] Fix linkTo calls for new routing --- apps/contacts/js/contacts.js | 2 +- apps/contacts/lib/search.php | 2 +- apps/files/index.php | 4 ++-- apps/files/js/fileactions.js | 2 +- apps/files/js/filelist.js | 2 +- apps/files_archive/js/archive.js | 4 ++-- apps/gallery/lib/tiles.php | 4 ++-- apps/gallery/templates/index.php | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 35637de050..2e62b5cf13 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -1477,7 +1477,7 @@ OC.Contacts={ } var contact = params.data ? $('
  • ' + params.data.displayname+'
  • ') diff --git a/apps/contacts/lib/search.php b/apps/contacts/lib/search.php index 53aa2b4849..c86bc12c5b 100644 --- a/apps/contacts/lib/search.php +++ b/apps/contacts/lib/search.php @@ -11,7 +11,7 @@ class OC_Search_Provider_Contacts extends OC_Search_Provider{ $vcards = OC_Contacts_VCard::all($addressbook['id']); foreach($vcards as $vcard){ if(substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) { - $link = OCP\Util::linkTo('contacts', 'index.php').'&id='.urlencode($vcard['id']); + $link = OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']); $results[]=new OC_Search_Result($vcard['fullname'], '', $link, (string)$l->t('Contact'));//$name,$text,$link,$type } } diff --git a/apps/files/index.php b/apps/files/index.php index 79bed8e357..ffe9493272 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -75,11 +75,11 @@ foreach( explode( '/', $dir ) as $i ){ // make breadcrumb und filelist markup $list = new OCP\Template( 'files', 'part.list', '' ); $list->assign( 'files', $files, false ); -$list->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'&dir=', false); +$list->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'?dir=', false); $list->assign( 'downloadURL', OCP\Util::linkTo('files', 'download.php').'?file=', false); $breadcrumbNav = new OCP\Template( 'files', 'part.breadcrumb', '' ); $breadcrumbNav->assign( 'breadcrumb', $breadcrumb, false ); -$breadcrumbNav->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'&dir=', false); +$breadcrumbNav->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'?dir=', false); $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index b6f4d0b089..cecfddbf1c 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -168,7 +168,7 @@ FileActions.register('all','Rename',function(){return OC.imagePath('core','actio }); FileActions.register('dir','Open','',function(filename){ - window.location=OC.linkTo('files', 'index.php') + '&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); + window.location=OC.linkTo('files', 'index.php') + '?dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); FileActions.setDefault('dir','Open'); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a414c5f830..0bfc810baf 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -41,7 +41,7 @@ FileList={ html = $('').attr({ "data-type": "dir", "data-size": size, "data-file": name}); td = $('').attr({"class": "filename", "style": 'background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')' }); td.append(''); - var link_elem = $('').attr({ "class": "name", "href": OC.linkTo('files', 'index.php')+"&dir="+ encodeURIComponent($('#dir').val()+'/'+name).replace(/%2F/g, '/') }); + var link_elem = $('').attr({ "class": "name", "href": OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent($('#dir').val()+'/'+name).replace(/%2F/g, '/') }); link_elem.append($('').addClass('nametext').text(name)); link_elem.append($('').attr({'class': 'uploadtext', 'currentUploads': 0})); td.append(link_elem); diff --git a/apps/files_archive/js/archive.js b/apps/files_archive/js/archive.js index 9fb9853e29..48ec031be6 100644 --- a/apps/files_archive/js/archive.js +++ b/apps/files_archive/js/archive.js @@ -8,11 +8,11 @@ $(document).ready(function() { if(typeof FileActions!=='undefined'){ FileActions.register('application/zip','Open','',function(filename){ - window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); + window.location=OC.linkTo('files', 'index.php')+'?dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); FileActions.setDefault('application/zip','Open'); FileActions.register('application/x-gzip','Open','',function(filename){ - window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); + window.location=OC.linkTo('files', 'index.php')+'?dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); FileActions.setDefault('application/x-gzip','Open'); } diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index e36d26d319..3903d2dde7 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -95,11 +95,11 @@ class TileSingle extends TileBase { public function get($extra = '') { // !HACK! file path needs to be encoded twice because files app decode twice url, so any special chars like + or & in filename // !HACK! will result in failing of opening them - return ''; + return ''; } public function getMiniatureSrc() { - return \OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'&filepath='.urlencode($this->getPath()); + return \OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'?filepath='.urlencode($this->getPath()); } public function getPath() { diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index b2efd5342f..b0f2203603 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -18,7 +18,7 @@ $(document).ready(function() { for ($i = 0; $i < count($paths); $i++) { $path .= urlencode($paths[$i]).'/'; $classess = 'crumb'.($i == count($paths)-1?' last':''); - echo ''; + echo ''; } } From 3b9fac8f81b76af988ea620a207e6c65fa665589 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 15 Aug 2012 19:55:26 +0200 Subject: [PATCH 20/35] Fix gallery image view --- apps/gallery/lib/tiles.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index 3903d2dde7..54fb613a8b 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -93,9 +93,7 @@ class TileSingle extends TileBase { } public function get($extra = '') { - // !HACK! file path needs to be encoded twice because files app decode twice url, so any special chars like + or & in filename - // !HACK! will result in failing of opening them - return ''; + return ''; } public function getMiniatureSrc() { From ceec5e593c677ed9e9339739d0a66a28e4f25d12 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 7 Sep 2012 16:19:08 +0200 Subject: [PATCH 21/35] Remove redundant loadApps --- lib/base.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index fc682fecfc..6af558ae9d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -465,7 +465,6 @@ class OC{ OC_App::loadApps(); OC_User::setupBackends(); if(isset($_GET["logout"]) and ($_GET["logout"])) { - OC_App::loadApps(); OC_User::logout(); header("Location: ".OC::$WEBROOT.'/'); }else{ From 3efe1d3b24e65ed76d521c24b0cfe4e0ff2e7af5 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 12 Sep 2012 18:00:33 +0200 Subject: [PATCH 22/35] Add linkToRoute functionality --- lib/helper.php | 14 ++++++++++++++ lib/router.php | 29 +++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index ed4bf53250..269327b531 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -28,6 +28,20 @@ class OC_Helper { private static $mimetypes=array(); private static $tmpFiles=array(); + /** + * @brief Creates an url using a defined route + * @param $route + * @param $parameters + * @param $args array with param=>value, will be appended to the returned url + * @returns the url + * + * Returns a url to the given app and file. + */ + public static function linkToRoute( $route, $parameters = array() ) { + $urlLinkTo = OC::getRouter()->generate($route, $parameters); + return $urlLinkTo; + } + /** * @brief Creates an url * @param $app app diff --git a/lib/router.php b/lib/router.php index 65fc51aff2..da491e217f 100644 --- a/lib/router.php +++ b/lib/router.php @@ -7,6 +7,7 @@ */ use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; //use Symfony\Component\Routing\Route; @@ -16,7 +17,14 @@ class OC_Router { protected $collection = null; protected $root = null; + protected $generator= null; + public function __construct() { + $baseUrl = OC_Helper::linkTo('', 'index.php'); + $method = $_SERVER['REQUEST_METHOD']; + $host = OC_Request::serverHost(); + $schema = OC_Request::serverProtocol(); + $this->context = new RequestContext($baseUrl, $method, $host, $schema); // TODO cache $this->root = $this->getCollection('root'); } @@ -56,12 +64,7 @@ class OC_Router { } public function match($url) { - $baseUrl = OC_Helper::linkTo('', 'index.php'); - $method = $_SERVER['REQUEST_METHOD']; - $host = OC_Request::serverHost(); - $schema = OC_Request::serverProtocol(); - $context = new RequestContext($baseUrl, $method, $host, $schema); - $matcher = new UrlMatcher($this->root, $context); + $matcher = new UrlMatcher($this->root, $this->context); $parameters = $matcher->match($url); if (isset($parameters['action'])) { $action = $parameters['action']; @@ -77,4 +80,18 @@ class OC_Router { throw new Exception('no action available'); } } + + public function getGenerator() + { + if (null !== $this->generator) { + return $this->generator; + } + + return $this->generator = new UrlGenerator($this->root, $this->context); + } + + public function generate($name, $parameters = array(), $absolute = false) + { + return $this->getGenerator()->generate($name, $parameters, $absolute); + } } From dbdf3bde7ccf721cfc1efa4d13262bd6f444de73 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 28 Sep 2012 22:19:37 +0200 Subject: [PATCH 23/35] Implement route for download in OC_Search_Provider_File --- apps/files/appinfo/routes.php | 12 ++++++++++++ lib/route.php | 5 +++++ lib/search/provider/file.php | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 apps/files/appinfo/routes.php diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php new file mode 100644 index 0000000000..e1ab560803 --- /dev/null +++ b/apps/files/appinfo/routes.php @@ -0,0 +1,12 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +$this->create('download', 'download{file}') + ->requirements(array('file' => '.*')) + ->actionInclude('files/download.php'); + diff --git a/lib/route.php b/lib/route.php index 772446e561..ba9d1724d1 100644 --- a/lib/route.php +++ b/lib/route.php @@ -64,4 +64,9 @@ class OC_Route extends Route { $this->setDefault('action', $action); return $this; } + + public function actionInclude($file) { + $function = create_function('$param', 'unset($param["_route"]);$_GET=$param;unset($param);require_once "'.$file.'";'); + $this->action($function); + } } diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php index 21fae0c1ce..e4e976ed7f 100644 --- a/lib/search/provider/file.php +++ b/lib/search/provider/file.php @@ -10,12 +10,11 @@ class OC_Search_Provider_File extends OC_Search_Provider{ $name = basename($path); $text = ''; - $path = urlencode($path); if($mime=='httpd/unix-directory') { $link = OC_Helper::linkTo( 'files', 'index.php', array('dir' => $path)); $type = 'Files'; }else{ - $link = OC_Helper::linkTo( 'files', 'download.php', array('file' => $path)); + $link = OC_Helper::linkToRoute( 'download', array('file' => $path)); $mimeBase = $fileData['mimepart']; switch($mimeBase) { case 'audio': From d0bd2bbf2728cdf472044d76aea97f0d4809774a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 28 Sep 2012 23:15:19 +0200 Subject: [PATCH 24/35] Convert menu entries of settings pages to use router --- core/routes.php | 15 +++++++++++++++ lib/app.php | 18 ++++++++++++------ settings/admin.php | 2 +- settings/apps.php | 2 +- settings/help.php | 3 +-- settings/personal.php | 2 +- settings/settings.php | 2 +- settings/users.php | 4 ++-- 8 files changed, 34 insertions(+), 14 deletions(-) diff --git a/core/routes.php b/core/routes.php index 04b42d2059..9a84eb64a3 100644 --- a/core/routes.php +++ b/core/routes.php @@ -6,6 +6,21 @@ * See the COPYING-README file. */ +// Core settings pages +$this->create('settings_help', '/settings/help') + ->actionInclude('settings/help.php'); +$this->create('settings_personal', '/settings/personal') + ->actionInclude('settings/personal.php'); +$this->create('settings_settings', '/settings') + ->actionInclude('settings/settings.php'); +$this->create('settings_users', '/settings/users') + ->actionInclude('settings/users.php'); +$this->create('settings_apps', '/settings/apps') + ->actionInclude('settings/apps.php'); +$this->create('settings_admin', '/settings/admin') + ->actionInclude('settings/admin.php'); + +// Not specifically routed $this->create('app_css', '/apps/{app}/{file}') ->requirements(array('file' => '.*.css')) ->action('OC', 'loadCSSFile'); diff --git a/lib/app.php b/lib/app.php index 7889339e42..71add88380 100755 --- a/lib/app.php +++ b/lib/app.php @@ -282,33 +282,33 @@ class OC_App{ // by default, settings only contain the help menu if(OC_Config::getValue('knowledgebaseenabled', true)==true) { $settings = array( - array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "help.php" ), "name" => $l->t("Help"), "icon" => OC_Helper::imagePath( "settings", "help.svg" )) + array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkToRoute( "settings_help" ), "name" => $l->t("Help"), "icon" => OC_Helper::imagePath( "settings", "help.svg" )) ); } // if the user is logged-in if (OC_User::isLoggedIn()) { // personal menu - $settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" )); + $settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkToRoute( "settings_personal" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" )); // if there are some settings forms if(!empty(self::$settingsForms)) // settings menu - $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" )); + $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkToRoute( "settings_settings" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" )); //SubAdmins are also allowed to access user management if(OC_SubAdmin::isSubAdmin($_SESSION["user_id"]) || OC_Group::inGroup( $_SESSION["user_id"], "admin" )) { // admin users menu - $settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" )); + $settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkToRoute( "settings_users" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" )); } // if the user is an admin if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) { // admin apps menu - $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" )); + $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkToRoute( "settings_apps" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" )); - $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" )); + $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkToRoute( "settings_admin" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" )); } } @@ -485,6 +485,12 @@ class OC_App{ public static function getCurrentApp() { $script=substr($_SERVER["SCRIPT_NAME"], strlen(OC::$WEBROOT)+1); $topFolder=substr($script, 0, strpos($script, '/')); + if (empty($topFolder)) { + $path_info = OC_Request::getPathInfo(); + if ($path_info) { + $topFolder=substr($path_info, 1, strpos($path_info, '/', 1)-1); + } + } if($topFolder=='apps') { $length=strlen($topFolder); return substr($script, $length+1, strpos($script, '/', $length+1)-$length-1); diff --git a/settings/admin.php b/settings/admin.php index a36f219038..9cb70353f9 100755 --- a/settings/admin.php +++ b/settings/admin.php @@ -5,8 +5,8 @@ * See the COPYING-README file. */ -require_once '../lib/base.php'; OC_Util::checkAdminUser(); +OC_App::loadApps(); OC_Util::addStyle( "settings", "settings" ); OC_Util::addScript( "settings", "admin" ); diff --git a/settings/apps.php b/settings/apps.php index a1c1bf6aa5..8134b44143 100644 --- a/settings/apps.php +++ b/settings/apps.php @@ -21,8 +21,8 @@ * */ -require_once '../lib/base.php'; OC_Util::checkAdminUser(); +OC_App::loadApps(); // Load the files we need OC_Util::addStyle( "settings", "settings" ); diff --git a/settings/help.php b/settings/help.php index 9157308dd5..69a5ec9c14 100644 --- a/settings/help.php +++ b/settings/help.php @@ -5,9 +5,8 @@ * See the COPYING-README file. */ -require_once '../lib/base.php'; OC_Util::checkLoggedIn(); - +OC_App::loadApps(); // Load the files we need OC_Util::addStyle( "settings", "settings" ); diff --git a/settings/personal.php b/settings/personal.php index 4f92985c79..ce9065247d 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -5,8 +5,8 @@ * See the COPYING-README file. */ -require_once '../lib/base.php'; OC_Util::checkLoggedIn(); +OC_App::loadApps(); // Highlight navigation entry OC_Util::addScript( 'settings', 'personal' ); diff --git a/settings/settings.php b/settings/settings.php index 24099ef574..1e05452ec4 100644 --- a/settings/settings.php +++ b/settings/settings.php @@ -5,8 +5,8 @@ * See the COPYING-README file. */ -require_once '../lib/base.php'; OC_Util::checkLoggedIn(); +OC_App::loadApps(); OC_Util::addStyle( 'settings', 'settings' ); OC_App::setActiveNavigationEntry( 'settings' ); diff --git a/settings/users.php b/settings/users.php index e76505cc78..6eaae47453 100644 --- a/settings/users.php +++ b/settings/users.php @@ -5,8 +5,8 @@ * See the COPYING-README file. */ -require_once '../lib/base.php'; OC_Util::checkSubAdminUser(); +OC_App::loadApps(); // We have some javascript foo! OC_Util::addScript( 'settings', 'users' ); @@ -57,4 +57,4 @@ $tmpl->assign( 'subadmins', $subadmins); $tmpl->assign( 'numofgroups', count($accessiblegroups)); $tmpl->assign( 'quota_preset', $quotaPreset); $tmpl->assign( 'default_quota', $defaultQuota); -$tmpl->printPage(); \ No newline at end of file +$tmpl->printPage(); From 210ea4d9d9a3488918c898beb6d6508c60686ad1 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 29 Sep 2012 18:03:34 +0200 Subject: [PATCH 25/35] fix actioninclude --- lib/route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/route.php b/lib/route.php index ba9d1724d1..c5a8bd2aa3 100644 --- a/lib/route.php +++ b/lib/route.php @@ -66,7 +66,7 @@ class OC_Route extends Route { } public function actionInclude($file) { - $function = create_function('$param', 'unset($param["_route"]);$_GET=$param;unset($param);require_once "'.$file.'";'); + $function = create_function('$param', 'unset($param["_route"]);$_GET=array_merge($_GET,$param);unset($param);require_once "'.$file.'";'); $this->action($function); } } From bb136b9adf021cb154ff05222d3439373312bbc5 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 29 Sep 2012 18:08:54 +0200 Subject: [PATCH 26/35] Make the settings ajax calls use the router --- core/js/js.js | 7 +++- core/routes.php | 14 +------ settings/ajax/apps/ocs.php | 3 -- settings/ajax/changepassword.php | 2 - settings/ajax/creategroup.php | 2 - settings/ajax/createuser.php | 2 - settings/ajax/disableapp.php | 2 - settings/ajax/enableapp.php | 2 - settings/ajax/getlog.php | 3 -- settings/ajax/lostpassword.php | 2 - settings/ajax/openid.php | 3 -- settings/ajax/removegroup.php | 3 -- settings/ajax/removeuser.php | 3 -- settings/ajax/setlanguage.php | 3 -- settings/ajax/setloglevel.php | 1 - settings/ajax/setquota.php | 3 -- settings/ajax/togglegroups.php | 3 -- settings/ajax/togglesubadmins.php | 5 +-- settings/ajax/userlist.php | 4 +- settings/js/users.js | 2 +- settings/routes.php | 62 +++++++++++++++++++++++++++++++ 21 files changed, 72 insertions(+), 59 deletions(-) create mode 100644 settings/routes.php diff --git a/core/js/js.js b/core/js/js.js index 39a58a2459..ffe3507a4e 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -88,7 +88,12 @@ var OC={ } link+=file; }else{ - link+='/'; + if (app == 'settings' && type == 'ajax') { + link+='/index.php/'; + } + else { + link+='/'; + } if(!isCore){ link+='apps/'; } diff --git a/core/routes.php b/core/routes.php index 9a84eb64a3..b0f41dd286 100644 --- a/core/routes.php +++ b/core/routes.php @@ -6,19 +6,7 @@ * See the COPYING-README file. */ -// Core settings pages -$this->create('settings_help', '/settings/help') - ->actionInclude('settings/help.php'); -$this->create('settings_personal', '/settings/personal') - ->actionInclude('settings/personal.php'); -$this->create('settings_settings', '/settings') - ->actionInclude('settings/settings.php'); -$this->create('settings_users', '/settings/users') - ->actionInclude('settings/users.php'); -$this->create('settings_apps', '/settings/apps') - ->actionInclude('settings/apps.php'); -$this->create('settings_admin', '/settings/admin') - ->actionInclude('settings/admin.php'); +require_once('settings/routes.php'); // Not specifically routed $this->create('app_css', '/apps/{app}/{file}') diff --git a/settings/ajax/apps/ocs.php b/settings/ajax/apps/ocs.php index fb78cc8924..4d6f1116e7 100644 --- a/settings/ajax/apps/ocs.php +++ b/settings/ajax/apps/ocs.php @@ -6,9 +6,6 @@ * See the COPYING-README file. */ -// Init owncloud -require_once '../../../lib/base.php'; - OC_JSON::checkAdminUser(); $l = OC_L10N::get('settings'); diff --git a/settings/ajax/changepassword.php b/settings/ajax/changepassword.php index b251fea504..200fdec26d 100644 --- a/settings/ajax/changepassword.php +++ b/settings/ajax/changepassword.php @@ -1,7 +1,5 @@ OC_Preferences::getValue($user, 'files', 'quota', 'default')); } } -OC_JSON::success(array('data' => $users)); \ No newline at end of file +OC_JSON::success(array('data' => $users)); diff --git a/settings/js/users.js b/settings/js/users.js index 20bd94993b..81a3181ba5 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -130,7 +130,7 @@ var UserList={ if (typeof UserList.offset === 'undefined') { UserList.offset = $('tbody tr').length; } - $.get(OC.filePath('settings', 'ajax', 'userlist.php'), { offset: UserList.offset }, function(result) { + $.get(OC.filePath('settings', 'ajax', 'userlist'), { offset: UserList.offset }, function(result) { if (result.status === 'success') { $.each(result.data, function(index, user) { var tr = UserList.add(user.name, user.groups, user.subadmin, user.quota, false); diff --git a/settings/routes.php b/settings/routes.php new file mode 100644 index 0000000000..b64a357be0 --- /dev/null +++ b/settings/routes.php @@ -0,0 +1,62 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +// Settings pages +$this->create('settings_help', '/settings/help') + ->actionInclude('settings/help.php'); +$this->create('settings_personal', '/settings/personal') + ->actionInclude('settings/personal.php'); +$this->create('settings_settings', '/settings') + ->actionInclude('settings/settings.php'); +$this->create('settings_users', '/settings/users') + ->actionInclude('settings/users.php'); +$this->create('settings_apps', '/settings/apps') + ->actionInclude('settings/apps.php'); +$this->create('settings_admin', '/settings/admin') + ->actionInclude('settings/admin.php'); +// Settings ajax actions +// users +$this->create('settings_admin', '/settings/ajax/userlist') + ->actionInclude('settings/ajax/userlist.php'); +$this->create('settings_ajax_createuser', '/settings/ajax/createuser.php') + ->actionInclude('settings_ajax_createuser'); +$this->create('settings_ajax_removeuser', '/settings/ajax/removeuser.php') + ->actionInclude('settings/ajax/removeuser.php'); +$this->create('settings_ajax_setquota', '/settings/ajax/setquota.php') + ->actionInclude('settings/ajax/setquota.php'); +$this->create('settings_ajax_creategroup', '/settings/ajax/creategroup.php') + ->actionInclude('settings_ajax_creategroup'); +$this->create('settings_ajax_togglegroups', '/settings/ajax/togglegroups.php') + ->actionInclude('settings/ajax/togglegroups.php'); +$this->create('settings_ajax_togglesubadmins', '/settings/ajax/togglesubadmins.php') + ->actionInclude('settings/ajax/togglesubadmins.php'); +$this->create('settings_ajax_removegroup', '/settings/ajax/removegroup.php') + ->actionInclude('settings/ajax/removegroup.php'); +$this->create('settings_ajax_changepassword', '/settings/ajax/changepassword.php') + ->actionInclude('settings/ajax/changepassword.php'); +// personel +$this->create('settings_ajax_lostpassword', '/settings/ajax/lostpassword.php') + ->actionInclude('settings/ajax/lostpassword.php'); +$this->create('settings_ajax_setlanguage', '/settings/ajax/setlanguage.php') + ->actionInclude('settings/ajax/setlanguage.php'); +// apps +$this->create('settings_ajax_apps_ocs', '/settings/ajax/apps/ocs.php') + ->actionInclude('settings/ajax/apps/ocs.php'); +$this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php') + ->actionInclude('settings/ajax/enableapp.php'); +$this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php') + ->actionInclude('settings/ajax/disableapp.php'); +// admin +$this->create('settings_ajax_getlog', '/settings/ajax/getlog.php') + ->actionInclude('settings/ajax/getlog.php'); +$this->create('settings_ajax_setloglevel', '/settings/ajax/setloglevel.php') + ->actionInclude('settings/ajax/setloglevel.php'); + +// apps/user_openid +$this->create('settings_ajax_openid', '/settings/ajax/openid.php') + ->actionInclude('settings/ajax/openid.php'); From de1bfe9d6b50c37c6999ff652a31535b0a2faf41 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 2 Oct 2012 21:57:51 +0200 Subject: [PATCH 27/35] Make the core ajax calls use the router --- core/ajax/appconfig.php | 1 - core/ajax/requesttoken.php | 1 - core/ajax/share.php | 1 - core/ajax/translations.php | 3 --- core/ajax/vcategories/add.php | 1 - core/ajax/vcategories/delete.php | 1 - core/ajax/vcategories/edit.php | 1 - core/js/js.js | 2 +- core/routes.php | 21 +++++++++++++++++++++ 9 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/ajax/appconfig.php b/core/ajax/appconfig.php index 1b43afa74f..4f26dedc79 100644 --- a/core/ajax/appconfig.php +++ b/core/ajax/appconfig.php @@ -5,7 +5,6 @@ * See the COPYING-README file. */ -require_once "../../lib/base.php"; OC_Util::checkAdminUser(); OCP\JSON::callCheck(); diff --git a/core/ajax/requesttoken.php b/core/ajax/requesttoken.php index 96d5402e62..84089de8b9 100644 --- a/core/ajax/requesttoken.php +++ b/core/ajax/requesttoken.php @@ -26,7 +26,6 @@ * @return json: success/error state indicator including a fresh request token * @author Christian Reiner */ -require_once '../../lib/base.php'; // don't load apps or filesystem for this task $RUNTIME_NOAPPS = TRUE; diff --git a/core/ajax/share.php b/core/ajax/share.php index 446d4cc32e..b6f96bfd34 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -18,7 +18,6 @@ * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see . */ -require_once '../../lib/base.php'; OC_JSON::checkLoggedIn(); OCP\JSON::callCheck(); diff --git a/core/ajax/translations.php b/core/ajax/translations.php index 75679da2c0..e22cbad470 100644 --- a/core/ajax/translations.php +++ b/core/ajax/translations.php @@ -21,9 +21,6 @@ * */ -// Init owncloud -require_once '../../lib/base.php'; - $app = $_POST["app"]; $l = OC_L10N::get( $app ); diff --git a/core/ajax/vcategories/add.php b/core/ajax/vcategories/add.php index 81fa06dbf1..8d31275dbf 100644 --- a/core/ajax/vcategories/add.php +++ b/core/ajax/vcategories/add.php @@ -14,7 +14,6 @@ function debug($msg) { OC_Log::write('core', 'ajax/vcategories/add.php: '.$msg, OC_Log::DEBUG); } -require_once '../../../lib/base.php'; OC_JSON::checkLoggedIn(); $category = isset($_GET['category'])?strip_tags($_GET['category']):null; $app = isset($_GET['app'])?$_GET['app']:null; diff --git a/core/ajax/vcategories/delete.php b/core/ajax/vcategories/delete.php index cd46a25b79..74b0220870 100644 --- a/core/ajax/vcategories/delete.php +++ b/core/ajax/vcategories/delete.php @@ -15,7 +15,6 @@ function debug($msg) { OC_Log::write('core', 'ajax/vcategories/delete.php: '.$msg, OC_Log::DEBUG); } -require_once '../../../lib/base.php'; OC_JSON::checkLoggedIn(); $app = isset($_POST['app'])?$_POST['app']:null; $categories = isset($_POST['categories'])?$_POST['categories']:null; diff --git a/core/ajax/vcategories/edit.php b/core/ajax/vcategories/edit.php index a0e67841c5..caeebcaa94 100644 --- a/core/ajax/vcategories/edit.php +++ b/core/ajax/vcategories/edit.php @@ -15,7 +15,6 @@ function debug($msg) { OC_Log::write('core', 'ajax/vcategories/edit.php: '.$msg, OC_Log::DEBUG); } -require_once '../../../lib/base.php'; OC_JSON::checkLoggedIn(); $app = isset($_GET['app'])?$_GET['app']:null; diff --git a/core/js/js.js b/core/js/js.js index ffe3507a4e..8f3b5a6af1 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -88,7 +88,7 @@ var OC={ } link+=file; }else{ - if (app == 'settings' && type == 'ajax') { + if ((app == 'settings' || app == 'core') && type == 'ajax') { link+='/index.php/'; } else { diff --git a/core/routes.php b/core/routes.php index b0f41dd286..d396ddd647 100644 --- a/core/routes.php +++ b/core/routes.php @@ -8,6 +8,27 @@ require_once('settings/routes.php'); +// Core ajax actions +// AppConfig +$this->create('core_ajax_appconfig', '/core/ajax/appconfig.php') + ->actionInclude('core/ajax/appconfig.php'); +// RequestToken +$this->create('core_ajax_requesttoken', '/core/ajax/requesttoken.php') + ->actionInclude('core/ajax/requesttoken.php'); +// Share +$this->create('core_ajax_share', '/core/ajax/share.php') + ->actionInclude('core/ajax/share.php'); +// Translations +$this->create('core_ajax_translations', '/core/ajax/translations.php') + ->actionInclude('core/ajax/translations.php'); +// VCategories +$this->create('core_ajax_vcategories_add', '/core/ajax/vcategories/add.php') + ->actionInclude('core/ajax/vcategories/add.php'); +$this->create('core_ajax_vcategories_delete', '/core/ajax/vcategories/delete.php') + ->actionInclude('core/ajax/vcategories/delete.php'); +$this->create('core_ajax_vcategories_edit', '/core/ajax/vcategories/edit.php') + ->actionInclude('core/ajax/vcategories/edit.php'); + // Not specifically routed $this->create('app_css', '/apps/{app}/{file}') ->requirements(array('file' => '.*.css')) From 167e9c1cc025ce920e48032ff5331fcb4f84de3d Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 5 Oct 2012 09:41:27 +0200 Subject: [PATCH 28/35] Fix route name --- settings/routes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/routes.php b/settings/routes.php index b64a357be0..4f4f83e454 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -21,7 +21,7 @@ $this->create('settings_admin', '/settings/admin') ->actionInclude('settings/admin.php'); // Settings ajax actions // users -$this->create('settings_admin', '/settings/ajax/userlist') +$this->create('settings_ajax_userlist', '/settings/ajax/userlist') ->actionInclude('settings/ajax/userlist.php'); $this->create('settings_ajax_createuser', '/settings/ajax/createuser.php') ->actionInclude('settings_ajax_createuser'); From f3a211c03c3dd017e263ac5226a52eb62562d198 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 5 Oct 2012 09:42:36 +0200 Subject: [PATCH 29/35] Implement routing on javascript side --- core/js/router.js | 73 ++++++++++++++++++++++++++++++++++++++++++++ core/routes.php | 3 ++ lib/base.php | 1 + lib/router.php | 18 +++++++++++ settings/js/users.js | 2 +- 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 core/js/router.js diff --git a/core/js/router.js b/core/js/router.js new file mode 100644 index 0000000000..8b66f5a05c --- /dev/null +++ b/core/js/router.js @@ -0,0 +1,73 @@ +OC.router_base_url = OC.webroot + '/index.php/', +OC.Router = { + routes_request: $.ajax(OC.router_base_url + 'core/routes.json', { + dataType: 'json', + success: function(jsondata) { + if (jsondata.status == 'success') { + OC.Router.routes = jsondata.data; + } + } + }), + generate:function(name, opt_params) { + if (!('routes' in this)) { + if(this.routes_request.state() != 'resolved') { + alert('wait');// wait + } + } + if (!(name in this.routes)) { + throw new Error('The route "' + name + '" does not exist.'); + } + var route = this.routes[name]; + var params = opt_params || {}; + var unusedParams = $.extend(true, {}, params); + var url = ''; + var optional = true; + $(route.tokens).each(function(i, token) { + if ('text' === token[0]) { + url = token[1] + url; + optional = false; + + return; + } + + if ('variable' === token[0]) { + if (false === optional || !(token[3] in route.defaults) + || ((token[3] in params) && params[token[3]] != route.defaults[token[3]])) { + var value; + if (token[3] in params) { + value = params[token[3]]; + delete unusedParams[token[3]]; + } else if (token[3] in route.defaults) { + value = route.defaults[token[3]]; + } else if (optional) { + return; + } else { + throw new Error('The route "' + name + '" requires the parameter "' + token[3] + '".'); + } + + var empty = true === value || false === value || '' === value; + + if (!empty || !optional) { + url = token[1] + encodeURIComponent(value).replace(/%2F/g, '/') + url; + } + + optional = false; + } + + return; + } + + throw new Error('The token type "' + token[0] + '" is not supported.'); + }); + if (url === '') { + url = '/'; + } + + unusedParams = $.param(unusedParams); + if (unusedParams.length > 0) { + url += '?'+unusedParams; + } + + return OC.router_base_url + url; + } +}; diff --git a/core/routes.php b/core/routes.php index d396ddd647..8d83681626 100644 --- a/core/routes.php +++ b/core/routes.php @@ -28,6 +28,9 @@ $this->create('core_ajax_vcategories_delete', '/core/ajax/vcategories/delete.php ->actionInclude('core/ajax/vcategories/delete.php'); $this->create('core_ajax_vcategories_edit', '/core/ajax/vcategories/edit.php') ->actionInclude('core/ajax/vcategories/edit.php'); +// Routing +$this->create('core_ajax_routes', '/core/routes.json') + ->action('OC_Router', 'JSRoutes'); // Not specifically routed $this->create('app_css', '/apps/{app}/{file}') diff --git a/lib/base.php b/lib/base.php index 2d82d5a40f..f7967329c2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -253,6 +253,7 @@ class OC{ OC_Util::addScript( "config" ); //OC_Util::addScript( "multiselect" ); OC_Util::addScript('search', 'result'); + OC_Util::addScript('router'); if( OC_Config::getValue( 'installed', false )) { if( OC_Appconfig::getValue( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax' ) { diff --git a/lib/router.php b/lib/router.php index da491e217f..04a3d41006 100644 --- a/lib/router.php +++ b/lib/router.php @@ -94,4 +94,22 @@ class OC_Router { { return $this->getGenerator()->generate($name, $parameters, $absolute); } + + public static function JSRoutes() + { + // TODO: http caching + $routes = array(); + $router = OC::getRouter(); + $root = $router->getCollection('root'); + foreach($root->all() as $name => $route) { + $compiled_route = $route->compile(); + $defaults = $route->getDefaults(); + unset($defaults['action']); + $routes[$name] = array( + 'tokens' => $compiled_route->getTokens(), + 'defaults' => $defaults, + ); + } + OCP\JSON::success ( array( 'data' => $routes ) ); + } } diff --git a/settings/js/users.js b/settings/js/users.js index 81a3181ba5..1474ebcdd8 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -130,7 +130,7 @@ var UserList={ if (typeof UserList.offset === 'undefined') { UserList.offset = $('tbody tr').length; } - $.get(OC.filePath('settings', 'ajax', 'userlist'), { offset: UserList.offset }, function(result) { + $.get(OC.Router.generate('settings_ajax_userlist', { offset: UserList.offset }), function(result) { if (result.status === 'success') { $.each(result.data, function(index, user) { var tr = UserList.add(user.name, user.groups, user.subadmin, user.quota, false); From c2b4e534534e083147bbad9b564179832cfa2912 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 5 Oct 2012 17:42:42 +0200 Subject: [PATCH 30/35] Add API description to OC_Route and OC_Router --- lib/route.php | 40 ++++++++++++++++++++++++++++++++++++++++ lib/router.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/lib/route.php b/lib/route.php index c5a8bd2aa3..89af829d3d 100644 --- a/lib/route.php +++ b/lib/route.php @@ -9,31 +9,53 @@ use Symfony\Component\Routing\Route; class OC_Route extends Route { + /** + * Specify the method when this route is to be used + * + * @param string $method HTTP method (uppercase) + */ public function method($method) { $this->setRequirement('_method', strtoupper($method)); return $this; } + /** + * Specify POST as the method to use with this route + */ public function post() { $this->method('POST'); return $this; } + /** + * Specify GET as the method to use with this route + */ public function get() { $this->method('GET'); return $this; } + /** + * Specify PUT as the method to use with this route + */ public function put() { $this->method('PUT'); return $this; } + /** + * Specify DELETE as the method to use with this route + */ public function delete() { $this->method('DELETE'); return $this; } + /** + * Defaults to use for this route + * + * @param array $defaults The defaults + */ public function defaults($defaults) { $action = $this->getDefault('action'); $this->setDefaults($defaults); @@ -44,6 +66,11 @@ class OC_Route extends Route { return $this; } + /** + * Requirements for this route + * + * @param array $requirements The requirements + */ public function requirements($requirements) { $method = $this->getRequirement('_method'); $this->setRequirements($requirements); @@ -56,6 +83,14 @@ class OC_Route extends Route { return $this; } + /** + * The action to execute when this route matches + * @param string|callable $class the class or a callable + * @param string $function the function to use with the class + * + * This function is called with $class set to a callable or + * to the class with $function + */ public function action($class, $function = null) { $action = array($class, $function); if (is_null($function)) { @@ -65,6 +100,11 @@ class OC_Route extends Route { return $this; } + /** + * The action to execute when this route matches, includes a file like + * it is called directly + * @param $file + */ public function actionInclude($file) { $function = create_function('$param', 'unset($param["_route"]);$_GET=array_merge($_GET,$param);unset($param);require_once "'.$file.'";'); $this->action($function); diff --git a/lib/router.php b/lib/router.php index 04a3d41006..a471a06802 100644 --- a/lib/router.php +++ b/lib/router.php @@ -53,16 +53,34 @@ class OC_Router { return $this->collections[$name]; } + /** + * Sets the collection to use for adding routes + * + * @param string $name Name of the colletion to use. + */ public function useCollection($name) { $this->collection = $this->getCollection($name); } + /** + * Create a OC_Route. + * + * @param string $name Name of the route to create. + * @param string $pattern The pattern to match + * @param array $defaults An array of default parameter values + * @param array $requirements An array of requirements for parameters (regexes) + */ public function create($name, $pattern, array $defaults = array(), array $requirements = array()) { $route = new OC_Route($pattern, $defaults, $requirements); $this->collection->add($name, $route); return $route; } + /** + * Find the route matching $url. + * + * @param string $url The url to find + */ public function match($url) { $matcher = new UrlMatcher($this->root, $this->context); $parameters = $matcher->match($url); @@ -81,6 +99,10 @@ class OC_Router { } } + /** + * Get the url generator + * + */ public function getGenerator() { if (null !== $this->generator) { @@ -90,11 +112,20 @@ class OC_Router { return $this->generator = new UrlGenerator($this->root, $this->context); } + /** + * Generate url based on $name and $parameters + * + * @param string $name Name of the route to use. + * @param array $parameters Parameters for the route + */ public function generate($name, $parameters = array(), $absolute = false) { return $this->getGenerator()->generate($name, $parameters, $absolute); } + /** + * Generate JSON response for routing in javascript + */ public static function JSRoutes() { // TODO: http caching From 44287d680bd0e8799724a7595db43c0fafcaff40 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 17 Oct 2012 14:06:25 +0200 Subject: [PATCH 31/35] Check for file exists before loading app version file --- lib/app.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/app.php b/lib/app.php index 594f057709..cb68ea3ddd 100755 --- a/lib/app.php +++ b/lib/app.php @@ -390,9 +390,8 @@ class OC_App{ */ public static function getAppVersion($appid) { $file= self::getAppPath($appid).'/appinfo/version'; - $version=@file_get_contents($file); - if($version) { - return trim($version); + if(is_file($file) && $version = trim(file_get_contents($file))) { + return $version; }else{ $appData=self::getAppInfo($appid); return isset($appData['version'])? $appData['version'] : ''; From 0a614429af21193f1da47c94d1382953b8d6ba8c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 17 Oct 2012 17:24:49 +0200 Subject: [PATCH 32/35] Change the lostpassword flow to a controller --- core/lostpassword/controller.php | 82 +++++++++++++++++++ core/lostpassword/index.php | 35 -------- core/lostpassword/resetpassword.php | 27 ------ core/lostpassword/templates/lostpassword.php | 6 +- core/lostpassword/templates/resetpassword.php | 4 +- core/routes.php | 14 ++++ 6 files changed, 101 insertions(+), 67 deletions(-) create mode 100644 core/lostpassword/controller.php delete mode 100644 core/lostpassword/index.php delete mode 100644 core/lostpassword/resetpassword.php diff --git a/core/lostpassword/controller.php b/core/lostpassword/controller.php new file mode 100644 index 0000000000..6037fefa4b --- /dev/null +++ b/core/lostpassword/controller.php @@ -0,0 +1,82 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_Core_LostPassword_Controller { + protected static function displayLostPasswordPage($error, $requested) { + OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => $error, 'requested' => $requested)); + } + + protected static function displayResetPasswordPage($success, $args) { + $route_args = array(); + $route_args['token'] = $args['token']; + $route_args['user'] = $args['user']; + OC_Template::printGuestPage('core/lostpassword', 'resetpassword', array('success' => $success, 'args' => $route_args)); + } + + protected static function checkToken($user, $token) { + return OC_Preferences::getValue($user, 'owncloud', 'lostpassword') === hash('sha256', $token); + } + + public static function index($args) { + self::displayLostPasswordPage(false, false); + } + + public static function sendEmail($args) { + if (OC_User::userExists($_POST['user'])) { + $token = hash('sha256', OC_Util::generate_random_bytes(30).OC_Config::getValue('passwordsalt', '')); + OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token)); // Hash the token again to prevent timing attacks + $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', ''); + if (!empty($email)) { + $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token)); + $link = OC_Helper::makeURLAbsolute($link); + + $tmpl = new OC_Template('core/lostpassword', 'email'); + $tmpl->assign('link', $link, false); + $msg = $tmpl->fetchPage(); + $l = OC_L10N::get('core'); + $from = 'lostpassword-noreply@' . OCP\Util::getServerHost(); + OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud'); + echo('Mailsent'); + + self::displayLostPasswordPage(false, true); + } else { + self::displayLostPasswordPage(true, false); + } + } else { + self::displayLostPasswordPage(true, false); + } + } + + public static function reset($args) { + // Someone wants to reset their password: + if(self::checkToken($args['user'], $args['token'])) { + self::displayResetPasswordPage(false, $args); + } else { + // Someone lost their password + self::displayLostPasswordPage(false, false); + } + } + + public static function resetPassword($args) { + if (self::checkToken($args['user'], $args['token'])) { + if (isset($_POST['password'])) { + if (OC_User::setPassword($args['user'], $_POST['password'])) { + OC_Preferences::deleteKey($args['user'], 'owncloud', 'lostpassword'); + self::displayResetPasswordPage(true, $args); + } else { + self::displayResetPasswordPage(false, $args); + } + } else { + self::reset($args); + } + } else { + // Someone lost their password + self::displayLostPasswordPage(false, false); + } + } +} diff --git a/core/lostpassword/index.php b/core/lostpassword/index.php deleted file mode 100644 index 906208dcbc..0000000000 --- a/core/lostpassword/index.php +++ /dev/null @@ -1,35 +0,0 @@ - $_POST['user'], 'token' => $token)); - $tmpl = new OC_Template('core/lostpassword', 'email'); - $tmpl->assign('link', $link, false); - $msg = $tmpl->fetchPage(); - $l = OC_L10N::get('core'); - $from = 'lostpassword-noreply@' . OCP\Util::getServerHost(); - OC_MAIL::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud'); - echo('sent'); - } - OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => true)); - } else { - OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => true, 'requested' => false)); - } -} else { - OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => false)); -} diff --git a/core/lostpassword/resetpassword.php b/core/lostpassword/resetpassword.php deleted file mode 100644 index 896c8da76e..0000000000 --- a/core/lostpassword/resetpassword.php +++ /dev/null @@ -1,27 +0,0 @@ - true)); - } else { - OC_Template::printGuestPage('core/lostpassword', 'resetpassword', array('success' => false)); - } - } else { - OC_Template::printGuestPage('core/lostpassword', 'resetpassword', array('success' => false)); - } -} else { - // Someone lost their password - OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => false)); -} diff --git a/core/lostpassword/templates/lostpassword.php b/core/lostpassword/templates/lostpassword.php index 4b871963b8..55c070f3e0 100644 --- a/core/lostpassword/templates/lostpassword.php +++ b/core/lostpassword/templates/lostpassword.php @@ -1,11 +1,11 @@ -
    +
    t('You will receive a link to reset your password via Email.'); ?> - t('Requested'); ?> + t('Reset email send.'); ?> - t('Login failed!'); ?> + t('Request failed!'); ?>

    diff --git a/core/lostpassword/templates/resetpassword.php b/core/lostpassword/templates/resetpassword.php index 56257de7f1..0ab32acca6 100644 --- a/core/lostpassword/templates/resetpassword.php +++ b/core/lostpassword/templates/resetpassword.php @@ -1,8 +1,8 @@ - +

    t('Your password was reset'); ?>

    -

    t('To login page'); ?>

    +

    t('To login page'); ?>

    diff --git a/core/routes.php b/core/routes.php index 8d83681626..7cf2749884 100644 --- a/core/routes.php +++ b/core/routes.php @@ -32,6 +32,20 @@ $this->create('core_ajax_vcategories_edit', '/core/ajax/vcategories/edit.php') $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); +OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; +$this->create('core_lostpassword_index', '/lostpassword/') + ->get() + ->action('OC_Core_LostPassword_Controller', 'index'); +$this->create('core_lostpassword_send_email', '/lostpassword/') + ->post() + ->action('OC_Core_LostPassword_Controller', 'sendEmail'); +$this->create('core_lostpassword_reset', '/lostpassword/reset/{token}/{user}') + ->get() + ->action('OC_Core_LostPassword_Controller', 'reset'); +$this->create('core_lostpassword_reset_password', '/lostpassword/reset/{token}/{user}') + ->post() + ->action('OC_Core_LostPassword_Controller', 'resetPassword'); + // Not specifically routed $this->create('app_css', '/apps/{app}/{file}') ->requirements(array('file' => '.*.css')) From a8d0f8482926e7780edc6ffa60f772da1f20e40a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 17 Oct 2012 17:26:12 +0200 Subject: [PATCH 33/35] Resetting the password should also invalidate the token login cookies --- core/lostpassword/controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lostpassword/controller.php b/core/lostpassword/controller.php index 6037fefa4b..e616fe7dff 100644 --- a/core/lostpassword/controller.php +++ b/core/lostpassword/controller.php @@ -67,6 +67,7 @@ class OC_Core_LostPassword_Controller { if (isset($_POST['password'])) { if (OC_User::setPassword($args['user'], $_POST['password'])) { OC_Preferences::deleteKey($args['user'], 'owncloud', 'lostpassword'); + OC_User::unsetMagicInCookie(); self::displayResetPasswordPage(true, $args); } else { self::displayResetPasswordPage(false, $args); From 43e8293d9ce92b42f2dd944847c7e4d8d1b17b9f Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 27 Oct 2012 11:32:16 +0200 Subject: [PATCH 34/35] Change Symfony/Component/Routing from submodule to composer fetching --- .gitignore | 4 ++++ .gitmodules | 3 --- 3rdparty/Symfony/Component/Routing | 1 - composer.json | 8 ++++++++ lib/base.php | 4 ++-- 5 files changed, 14 insertions(+), 6 deletions(-) delete mode 100644 .gitmodules delete mode 160000 3rdparty/Symfony/Component/Routing create mode 100644 composer.json diff --git a/.gitignore b/.gitignore index 4749dea19d..4ae39ed7fa 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,7 @@ nbproject # WebFinger .well-known /.buildpath +3rdparty/autoload.php +3rdparty/composer/ +3rdparty/symfony/ +composer.lock diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 0f4ad58807..0000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "3rdparty/Symfony/Component/Routing"] - path = 3rdparty/Symfony/Component/Routing - url = git://github.com/symfony/Routing.git diff --git a/3rdparty/Symfony/Component/Routing b/3rdparty/Symfony/Component/Routing deleted file mode 160000 index d724838908..0000000000 --- a/3rdparty/Symfony/Component/Routing +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d72483890880a987afa679503af096d2aaf7d2ee diff --git a/composer.json b/composer.json new file mode 100644 index 0000000000..628ee60110 --- /dev/null +++ b/composer.json @@ -0,0 +1,8 @@ +{ + "require": { + "symfony/routing": "2.0.*" + }, + "config": { + "vendor-dir": "3rdparty" + } +} diff --git a/lib/base.php b/lib/base.php index c8a54d1c65..c688d78533 100644 --- a/lib/base.php +++ b/lib/base.php @@ -97,8 +97,8 @@ class OC{ elseif(strpos($className, 'Sabre_')===0) { $path = str_replace('_', '/', $className) . '.php'; } - elseif(strpos($className, 'Symfony\\')===0) { - $path = str_replace('\\', '/', $className) . '.php'; + elseif(strpos($className, 'Symfony\\Component\\Routing\\')===0) { + $path = 'symfony/routing/'.str_replace('\\', '/', $className) . '.php'; } elseif(strpos($className, 'Test_')===0) { $path = 'tests/lib/'.strtolower(str_replace('_', '/', substr($className, 5)) . '.php'); From beaaf5425dc2dfb7456efa934fa8eb91ac28c677 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 27 Oct 2012 11:56:51 +0200 Subject: [PATCH 35/35] More info for composer.json --- composer.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/composer.json b/composer.json index 628ee60110..7916b15cb9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,15 @@ { + "description": "ownCloud gives you universal access to your files/contacts/calendar through a web interface or WebDAV.", + "homepage": "http://owncloud.org", + "license": "AGPL-3.0+", + "support": { + "email": "owncloud@kde.org", + "irc": "irc://irc.freenode.org/owncloud", + "forum": "http://forum.owncloud.org/", + "issues": "https://github.com/owncloud/core/issues" + }, "require": { + "php": ">=5.3.2", "symfony/routing": "2.0.*" }, "config": {