public function index()
 {
     $urls = [];
     $routes = Route::getRoutes();
     foreach ($routes as $route) {
         $path = $route->getPath();
         $actions = $route->getAction();
         $params = $route->parameterNames();
         $controller = $actions['controller'];
         if (starts_with($path, '_') or str_contains($controller, 'RedirectController') or count($params)) {
             continue;
         }
         $urls[] = url($path);
     }
     foreach (Campus::all() as $item) {
         $urls[] = url($item->url);
     }
     foreach (Event::all() as $item) {
         $urls[] = url($item->url);
     }
     foreach (Series::withDrafts()->get() as $item) {
         $urls[] = url($item->url);
     }
     foreach (Staff::all() as $item) {
         $urls[] = url($item->url);
     }
     foreach (MissionLocation::all() as $item) {
         $urls[] = url($item->url);
     }
     foreach (Video::withDrafts()->get() as $item) {
         $urls[] = url($item->url);
     }
     return response()->json($urls);
 }
 /**
  * Validates the user, password combination against the request.
  *
  * @param \Illuminate\Http\Request $request
  * @param string                   $user
  * @param string                   $password
  *
  * @return bool
  */
 protected function validate($request, $user, $password)
 {
     // Get current route name
     // Note: we do not have access to the current route in middleware, because
     // it has not been fully dispatched, therefore we must use the backwards
     // method of finding the route which matches the current request.
     $routeName = null;
     foreach (Route::getRoutes() as $route) {
         if ($route->matches($request)) {
             $routeName = $route->getName();
         }
     }
     // If we have a named route
     if ($routeName) {
         // Check if route username and password are set
         if ($routeUsername = env('ROUTE_RESTRICTOR_ROUTE_' . strtoupper($routeName) . '_USERNAME') && ($routePassword = env('ROUTE_RESTRICTOR_ROUTE_' . strtoupper($routeName) . '_PASSWORD'))) {
             // Check against route password
             if (trim($user) == $routeUsername && trim($password) == $routePassword) {
                 return true;
             } else {
                 return false;
             }
         }
     }
     // Check if global username and password are set
     if ($globalUsername = env('ROUTE_RESTRICTOR_GLOBAL_USERNAME') && ($globalPassword = env('ROUTE_RESTRICTOR_GLOBAL_PASSWORD'))) {
         // Check against global password
         if (trim($user) == $globalUsername && trim($password) == $globalPassword) {
             return true;
         } else {
             return false;
         }
     }
     return true;
 }
Exemple #3
0
 private function getAvailableRoutes()
 {
     $routeList = array();
     foreach (Route::getRoutes() as $route) {
         if ($route->getName() !== null) {
             $routeList[$route->getName()] = $route->getName();
         }
     }
     return $routeList;
 }
Exemple #4
0
 function canRead($routeName)
 {
     $route = Route::getRoutes()->getByName($routeName);
     if ($route == null) {
         return null;
     }
     $action = $route->getAction();
     list($controller, $action) = explode('@', $action['controller']);
     return app($controller)->getControllerModel()->allowsUserRead(auth()->user());
 }
 public function routeHasMiddlewareGroup($group)
 {
     $routes = Route::getRoutes()->getRoutes();
     foreach ($routes as $route) {
         $actions = (array) $route->getAction();
         if (array_key_exists('middleware', $actions) && in_array($group, (array) $actions['middleware'])) {
             return true;
         }
     }
     return false;
 }
 /**
  * Gets the route data
  *
  * @return array
  */
 protected function getRouteData()
 {
     $allRoutes = Route::getRoutes();
     $routeData = [];
     foreach ($allRoutes as $route) {
         if (!preg_match('/_debugbar/', $route->getUri())) {
             $uri = preg_replace('#/{[a-z\\?]+}|{_missing}|/{_missing}#', '', $route->getUri());
             $routeData[$route->getActionName()] = $uri;
         }
     }
     return $routeData;
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $this->setRootControllerNamespace();
     if ($this->app->routesAreCached()) {
         $this->loadCachedRoutes();
     } else {
         $this->loadRoutes();
         $this->app->booted(function () {
             Route::getRoutes()->refreshNameLookups();
         });
     }
 }
 /**
  * Handle the event.
  *
  * @param  CacheEvent  $event
  * @return void
  */
 public function handle(CacheEvent $event)
 {
     if (!Cache::get('routes') || !Cache::get('routes_simple')) {
         $route_collection = Route::getRoutes();
         $routes = [];
         foreach ($route_collection as $route) {
             if ($route->getName() && $route->getPrefix()) {
                 $group = explode('@', $route->getActionName());
                 $routes[$route->getPrefix()][$group[0]][$route->getName()] = $route->getName();
                 $routes_simple[] = $route->getName();
             }
         }
         Cache::forever('routes', $routes);
         Cache::forever('routes_simple', $routes_simple);
     }
     $this->initRoutesFormat();
 }
 public static function generate()
 {
     $router = Route::getRoutes();
     $routesByAction = array();
     $routesByName = array();
     foreach ($router as $route) {
         if ($route->getActionName() != 'Closure') {
             $routesByAction[$route->getActionName()]['route'] = str_replace('?}', '}', url($route->getPath()));
             $routesByAction[$route->getActionName()]['parameters'] = $route->parameterNames();
         }
         if ($route->getName() != '') {
             $routesByName[$route->getName()]['route'] = str_replace('?}', '}', url($route->getPath()));
             $routesByName[$route->getName()]['parameters'] = $route->parameterNames();
         }
     }
     return View::make('LaravelJsRouting::script', array('routesByAction' => $routesByAction, 'routesByName' => $routesByName));
 }
Exemple #10
0
 public function getIndex()
 {
     $routeCollection = Route::getRoutes();
     echo "<table style='width:100%'>";
     echo "<tr>";
     echo "<td width='10%'><h4>HTTP Method</h4></td>";
     echo "<td width='10%'><h4>Route</h4></td>";
     echo "<td width='80%'><h4>Corresponding Action</h4></td>";
     echo "</tr>";
     foreach ($routeCollection as $value) {
         echo "<tr>";
         echo "<td>" . $value->getMethods()[0] . "</td>";
         echo "<td>" . $value->getPath() . "</td>";
         echo "<td>" . $value->getActionName() . "</td>";
         echo "</tr>";
     }
     echo "</table>";
     //return view('administracija.admin.index');
 }
 public function getManagePermissions()
 {
     $roles = Role::all();
     $routes = Route::getRoutes();
     $permissions = array();
     $route_list = array();
     $enabled_permissions = array();
     foreach ($roles as $role) {
         $enabled_permissions[$role->name] = $role->permissions()->lists('route');
     }
     foreach ($routes as $route) {
         if (in_array($route->getActionName(), $route_list)) {
             continue;
         }
         $route_list[] = $route->getActionName();
         $permissions[] = array('route' => $route->getActionName(), 'display_route' => str_replace('App\\Http\\Controllers\\', '', $route->getActionName()));
     }
     return view('pages.admin.permissions', compact('permissions', 'roles', 'enabled_permissions'));
 }
Exemple #12
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //
     $routeCollection = Route::getRoutes();
     $data = array();
     foreach ($routeCollection as $routes) {
         if ($routes->getActionName() != "Closure") {
             $rota = $routes->getActionName();
             $data = array();
             $exp = explode('\\', $rota);
             $rota = $exp[3];
             $data['rota'] = $rota;
             $exp2 = explode("@", $exp[3]);
             $controller = $exp2[0];
             $action = $exp2[1];
             $exp3 = explode('Controller', $controller);
             $nome = $exp3[0];
             $data['nome'] = $nome;
             //dd(ngettext($data['nome']));
             $data['descricao'] = ucfirst($action) . " " . $nome;
             if ($action == "criar" || $action == "listar") {
                 $data['display'] = 1;
                 if ($action == "criar") {
                     $data['descricao'] = "Novo " . $nome;
                 }
             }
             $isExist = Perm::where('rota', $data['rota'])->count();
             if ($isExist == 0) {
                 $perm = Perm::create($data);
                 if (!$perm) {
                     echo "erro ao salvar " . $data['descricao'] . "\n";
                 } else {
                     echo "\nSalvo " . $data['descricao'];
                 }
             } else {
                 echo "rota " . $data['rota'] . " já foi salva em outro momento\n";
             }
         }
     }
     // return var_dump($data);
 }
 /**
  */
 public function apis()
 {
     $apis = [];
     foreach (Route::getRoutes() as $route) {
         $routeDomain = !empty($route->getAction()['domain']) ? $route->getAction()['domain'] : false;
         if ($routeDomain && $routeDomain != \Request::server('HTTP_HOST')) {
             continue;
         }
         // remove non apis and duplicate of PUT (ie PATCH)
         if (stripos($route->uri(), 'api/') === 0 && !in_array('PATCH', $route->getMethods()) && array_key_exists('controller', $route->getAction())) {
             $apis[] = new Api($route);
         }
     }
     uasort($apis, function (Api $a, Api $b) {
         $order = strcasecmp($a->group, $b->group);
         $order = $order ?: strcmp($a->path, $b->path);
         $order = $order ?: strcmp($this->methodOrder($a->httpMethod), $this->methodOrder($b->httpMethod));
         return $order;
     });
     return array_values($apis);
 }
 public function run()
 {
     DB::table('permissions')->truncate();
     $permissions = [];
     $routeCollection = Route::getRoutes();
     /*
      ** All route permission
      */
     foreach ($routeCollection as $value) {
         $action = $value->getAction();
         if (isset($action['prefix']) && ($action['prefix'] = '/api/v1/' && isset($action['as']))) {
             $route = explode(".", $action['as'], 3);
             $route = $route[2];
             $route_name = ucfirst(preg_replace('/\\./', ' ', $route));
             $route_group = explode(" ", $route_name);
             $route_group = $route_group[0];
             $permissions[] = ['name' => $route_name, 'name_group' => $route_group, 'slug' => $route, 'slug_view' => 'app.' . $route, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")];
         }
     }
     /*
      ** Custom route permission
      */
     $custom_permission = [['slug_view' => 'app.multimedia.upload'], ['slug_view' => 'app.activityLogs.index']];
     /*
      ** Re-define custom permission
      */
     foreach ($custom_permission as $value) {
         $slug_view = explode(".", $value['slug_view'], 2);
         $name_group = explode(".", $slug_view[1]);
         $route_name = ucfirst($name_group[0]) . ' ' . ucfirst($name_group[1]);
         $name_group = ucfirst($name_group[0]);
         $slug = $slug_view[1];
         $permissions[] = ['name' => $route_name, 'name_group' => $name_group, 'slug' => $slug, 'slug_view' => $value['slug_view'], 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")];
     }
     Permission::insert($permissions);
 }
 /**
  * @param $view
  *
  * @return mixed
  */
 public function compose(View $view)
 {
     /*
      * Stores all the routes for selection, defaults are stored in config
      */
     $allRoutes = $this->config->get('permissions.default');
     /*
      * Get all the routes in the application
      */
     $routes = Route::getRoutes();
     foreach ($routes as $route) {
         $routeName = $route->getName();
         /*
          * Make sure the route has a name
          */
         if ($routeName) {
             /*
              * Get the route filters
              */
             $filters = $route->beforeFilters();
             /*
              * Make sure only routes guarded by the permission filter are shown
              * in the route selection box
              */
             if (array_key_exists('maintenance.permission', $filters)) {
                 /*
                  * Explode the route into segments
                  */
                 $segments = explode('.', $routeName);
                 if (count($segments) >= 1) {
                     /*
                      * Pop the last segment off the route name
                      * so we can append a sentry wildcard to it ('*')
                      */
                     array_pop($segments);
                     /*
                      * Set the array pointer to the last element
                      */
                     end($segments);
                     /*
                      * Add the last element with the wildcard
                      */
                     $segments[] = '*';
                     /*
                      * Implode the array back into dot notation
                      */
                     $routeStar = implode('.', $segments);
                     /*
                      * Insert the route into the allRoutes array
                      */
                     $allRoutes[$segments[0]][$routeStar] = $routeStar;
                 }
                 /*
                  * We'll use the first segment entry to group the routes together
                  * for easier navigation
                  */
                 $allRoutes[$segments[0]][$routeName] = $routeName;
             }
         }
     }
     /*
      * Return the view with the routes for selection
      */
     return $view->with('allRoutes', $allRoutes);
 }
Exemple #16
0
 public function getDataForPagination($dataRequest, $config)
 {
     //Update path
     //get all route
     $routes = Route::getRoutes();
     $arr_routes = [];
     $allRoutes = [];
     //put route into array
     foreach ($routes as $value) {
         $path = $value->getPath();
         //check all route is of backend
         if (preg_match('/^admin/', $path)) {
             $allRoutes[] = $path;
         }
     }
     //delete all old
     //        $this->truncate();
     //foreach  add new permission
     $arr_routes = array_unique($allRoutes);
     foreach ($arr_routes as $route) {
         //check existed ?
         $count = $this->where('name', '1|' . $route)->count();
         if ($count == 0) {
             $new = new Permission();
             $new->name = '1|' . $route;
             $new->save();
         }
     }
     // check Role differ SA(1)
     $roles = Role::where('id', '!=', 1)->get(['id'])->toArray();
     $listRole = [];
     foreach ($roles as $role) {
         $listRole[] = $role['id'];
     }
     // Config sort
     $sortBy = 'id';
     $sortOrder = 'asc';
     if (isset($dataRequest['sort'])) {
         $sort = $dataRequest['sort'];
         $sortColum = ['id', 'name'];
         $sortBy = in_array(key($sort), $sortColum) ? key($sort) : 'id';
         $sortOrder = current($sort);
     }
     //check if user choice all then no orderby
     if (intval($dataRequest['rowCount']) == -1) {
         $permission = $this->where('name', 'like', '1|%')->get(['id', 'name'])->toArray();
     } else {
         $permission = $this->where('name', 'like', '1|%')->skip($config['offset'])->take($config['limit'])->get(['id', 'name'])->toArray();
     }
     //end
     $permissions = [];
     $listPermission = [];
     //get Data role
     foreach ($listRole as $roleID) {
         $listPermission[] = $this->where('name', 'like', $roleID . '|%')->get(['id', 'name'])->toArray();
     }
     //put permission into array
     foreach ($listPermission as $value) {
         foreach ($value as $subvalue) {
             $permissions[] = [$subvalue['id'], $subvalue['name']];
         }
     }
     $permission_key = array();
     $permission_name = array();
     $permission_uri = array();
     $permissionListUri = [];
     foreach ($listRole as $k => $role) {
         $permissionListUri[] = [];
     }
     $arrayPermission = [];
     for ($i = 0; $i < sizeof($listPermission); $i++) {
         $tmp = [];
         foreach ($listPermission[$i] as $per) {
             $tmp[] = substr($per['name'], 2);
         }
         $arrayPermission[] = $tmp;
     }
     foreach ($permission as $per) {
         $permission_uri[] = substr($per['name'], 2);
         $permission_name[] = $per['name'];
         $permission_key[] = $per['id'];
     }
     $num_uri = sizeof($permission_uri);
     for ($i = 0; $i < $num_uri; $i++) {
         for ($j = 0; $j < sizeof($arrayPermission); $j++) {
             $ck = false;
             foreach ($listRole as $k => $department) {
                 if ($j == $k) {
                     $col = $department;
                 }
             }
             $ic = '<input col=' . $col . ' data=' . $permission_uri[$i] . ' type=checkbox>';
             for ($m = 0; $m < sizeof($arrayPermission[$j]); $m++) {
                 if (strcmp($arrayPermission[$j][$m], $permission_uri[$i]) == 0) {
                     $ck = true;
                 }
             }
             if ($ck) {
                 $ic = '<input col=' . $col . ' data=' . $permission_uri[$i] . ' checked type=checkbox>';
             }
             $permissionListUri[$j][] = $ic;
         }
     }
     $rows = [];
     for ($i = 0; $i < $num_uri; $i++) {
         $rows[] = ['id' => $permission_key[$i], 'name' => $permission_uri[$i]];
         foreach ($listRole as $k => $role) {
             $rows[$i][$listRole[$k]] = $permissionListUri[$k][$i];
         }
     }
     $total = $permission = $this->where('name', 'like', '1|%')->count();
     return ['total' => $total, 'rows' => $rows];
 }
 /**
  * Fetch the route permissions.
  *
  * @param  Model  $permissible
  * @return \Illuminate\Support\Collection
  */
 private function routePermissions(Model $permissible)
 {
     return collect(Route::getRoutes()->getRoutes())->map(function ($route) use($permissible) {
         return $this->buildPermissibleLookup($permissible, $route->getName());
     });
 }
Exemple #18
0
<?php

use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Route;
Route::get('{any}', function ($url) {
    $definedRouteRedirection = config('smart-route.defined');
    $requestedPath = Request::path();
    if (array_has($definedRouteRedirection, $requestedPath)) {
        return redirect()->to($definedRouteRedirection[$requestedPath]);
    }
    $allRoutes = Route::getRoutes()->getRoutes();
    $words = [];
    $closest = '/';
    foreach ($allRoutes as $r) {
        $uriWords = preg_split('/[\\s,\\/\\-]+/', $r->uri());
        $ww = [];
        foreach ($uriWords as $w) {
            $ww[$w] = $r->uri();
        }
        $words = array_merge($words, $ww);
    }
    $shortest = -1;
    foreach ($words as $word => $uri) {
        $lev = levenshtein($url, $word);
        if ($lev == 0) {
            $closest = $uri;
            break;
        }
        if ($lev <= $shortest || $shortest < 0) {
            $closest = $uri;
            $shortest = $lev;
 /**
  * Get the referencable uri's from the App/routes.php.
  *
  * @return array
  */
 public function getAuthorizedRoutes()
 {
     $routeList = Route::getRoutes();
     $routes = array();
     foreach ($routeList as $route) {
         if (!is_null($route->getName())) {
             if (in_array('authorize', $route->middleware()) === true) {
                 array_push($routes, $route->uri());
             }
         }
     }
     $newRoutes = array_unique($routes);
     return array_values($newRoutes);
 }
 /**
  * @param $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function getAccessAttr()
 {
     $route_collection = Route::getRoutes();
     $routes = [];
     foreach ($route_collection as $route) {
         if (!$route->getName() || !$route->getPrefix()) {
             continue;
         }
         $this->permission->firstOrCreate(['name' => $route->getName(), 'slug' => $route->getName(), 'model' => $route->getPrefix()]);
     }
     return response()->json(['data' => $this->permission->all()]);
 }
Exemple #21
0
 public function getIndex()
 {
     $routeCollection = Route::getRoutes();
     echo "<table style='width:100%'>";
     echo "<tr>";
     echo "<td width='10%'><h4>HTTP Method</h4></td>";
     echo "<td width='10%'><h4>Route</h4></td>";
     echo "<td width='80%'><h4>Corresponding Action</h4></td>";
     echo "</tr>";
     foreach ($routeCollection as $value) {
         echo "<tr>";
         echo "<td>" . $value->getMethods()[0] . "</td>";
         echo "<td>" . $value->getPath() . "</td>";
         echo "<td>" . $value->getActionName() . "</td>";
         echo "</tr>";
     }
     echo "</table>";
     echo "</br>";
     return response()->json("Ivan Rep 0036475497", 200);
 }
 /**
  * @return mixed
  */
 private function getRoutes()
 {
     if ($this->option('router') === 'laravel') {
         return Route::getRoutes();
     } else {
         return app('Dingo\\Api\\Routing\\Router')->getRoutes()[$this->option('routePrefix')];
     }
 }