What's wrong with my configuration of sonata admin for menu grouping? - admin

I'm programming my own website with symfony 4.2.8 and it's bundle, that is sonata admin. At First, I had installed the symfony and it's bundle sonata amdin. And according to configuration guides, I configured sonata admin bundle. Everything is ok until I configure dashboard groups. I don't know What is my fault in my configuration.
Error Message : An exception has been thrown during the rendering of a template ("Admin service "sonata.admin.user" not found in admin pool. Did you mean "app.admin.user" or one of those: []?").
http://enagape.net/admin/dashboard
My configuration is like these.
in config/packages/sonata_admin.yaml.
sonata_admin:
#persist_filters: true
#filter_persister: filter_persister_service_id
title: 'Sonata Admin'
dashboard:
blocks:
# display two dashboard blocks
-
position: left
type: sonata.admin.block.admin_list
settings:
groups: [users, pages, blog]
groups:
users:
label: Users
label_catalogue: ~
items:
- sonata.admin.user
# - sonata.admin.group
pages:
label: Pages
label_catalogue: ~
items:
# - sonata.admin.page
# - sonata.admin.site
blog:
label: Blog
label_catalogue: ~
items:
- sonata.admin.post
# - sonata.admin.comment
# - sonata.admin.category
# - sonata.admin.tag
sonata_block:
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
And in config/services.yaml.
parameters:
locale: 'en'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
# <Entity>Admin class
App\Admin\:
resource: '../src/Admin'
# for user
app.admin.user:
class: App\Admin\UserAdmin
arguments:
- ~
- App\Entity\User
- ~
tags:
-
name: sonata.admin
manager_type: orm
label: User
group: users
#filter_persister: filter_persister_service_id
# for post
app.admin.post:
class: App\Admin\PostAdmin
arguments:
- ~
- App\Entity\Post
- ~
tags:
-
name: sonata.admin
manager_type: orm
label: Post
group: blog
#filter_persister: filter_persister_service_id

I found a solution to configure sonata admin. This is best way to make wonderful admin.
After installation of sonata admin bundle, you can use symfony console.
For example,
php bin/console make:sonata:admin
That's it, you just enter the upper command line.

Related

How to solve context deadline exceeded error when executing a nuclei template?

I have made this personal nuclei template to detect if directory listing is enabled on a wordpress site, this template should request the endpoint /wp-content/uploads.and it does a regex match of the string "Index of", if found it should return the result, but so far i'm having this "context deadline exceeded"
Here's the template:
`
id: wordpress-directory-listing
info:
name: /wp-content/uploads - Directory Listing Enabled
author: winteri3coming
severity: high
description: detects if directory listing is enabled at /wp-content/uploads/.
tags: wordpress
requests:
- method: GET
path:
- "{{BaseURL}}/wp-content/uploads/"
unsafe: true
matchers:
- type: regex
regex:
- "[Ii]ndex of"
`
i've tried changing the request type to raw and back to basic and it didn't work, what could be the reason and how to fix it, what is wrong with my template, knowing that if i run other templates from the project discovery repo, they work just fine.

Integrate Swagger 0.3.x with Django and Rest Framework

Working on rather old project running Django 1.6 there's a need to integrate Swagger to describe REST endpoints.
I've installed compatible version of Django Rest Framework (3.2.5) and Django Rest Swagger (0.3.0), then imported both into INSTALLED APPS and included DRF-Swagger's urls in my url scheme:
...
url(r'^api/v1/$', include('rest_framework_swagger.urls')),
...
When I go to this URL I see that Swagger is working, but I can't understand what should I do next to make it work with my endpoints and show information about them? Should I add something to SWAGGER_SETTINGS to be able to read YAML insertions from methods?
The fastest way to configure this version of swagger to work with DRF is first to install both packages compatible with Django 1.6:
pip install djangorestframework==3.2.5
pip install django-rest-swagger==0.3.0
Then you should add both to installed apps in project settings:
INSTALLED_APPS = (
...
'rest_framework',
'rest_framework_swagger',
)
Optionally you can add SWAGGER_SETTINGS to project settings, but it's not mandatory, here's a link to SWAGGER_SETTINGS.
Then you should add this pattern to your urls:
url(r'^docs/', include('rest_framework_swagger.urls'))
you can make it extend existing path, for example:
url(r'^<your root path>/docs/', include('rest_framework_swagger.urls'))
but the key is that this url should end with exactly docs/ to be able to access swagger. At this point if everything is done correctly you should be able to access Swagger at:
<your root path>/docs/
Last thing you need to do is import and decorate your endpoint View with api_view decorator:
from rest_framework.decorators import api_view
...
#api_view(["GET"])
def my_api_view(request, parameter_a, parameter_b):
"""
Endpoint returns list of open orders
---
parameters:
- name: parameter_a
description: Description for parameter a
required: true
paramType: path
- name: parameter_b
description: Description for parameter b
required: true
paramType: path
"""
...rest of View...
This will tell Swagger that this endpoint is related to DRF and has description to be displayed at <your root path>/docs/

Redirects to external URLs are not allowed by default

Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it.
I am getting this error while enabling my custom module in Drupal 8.
Check you routing.yml and menu.yml
Your rout name that you have created should be there in menu.yml like:
In routing.yml
test_module.description:
path: 'testing/new-example'
defaults:
_controller: '\Drupal\test_module\Controller\Page::description'
_title: 'Form API Examples'
requirements:
_permission: 'access content'
and in menu.yml
test_module.description:
title: Form API Examples
description: Form examples using Drupal Form API.
route_name: test_module.description

Getting Facebook callback error even after enabling 'Embedded browser OAuth Login' and specifying the callback url

I have a rails(4.2.0) application that uses Facebook login functionality. The main gems are devise(3.4.0) and omniauth-facebook(2.0.0). I have registered the application on Facebook and have been using its test app for development. The Facebook login functionality works in the development env.
When trying to use the facebook login feature on the production server, I get error as "Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."
The details for settings for test app being used in the dev env are as -
Settings:
Basic:
App Domains: 'localhost'
Website:
Site URL: 'http://localhost:3000'
Advanced:
OAuth Settings:
Embedded browser OAuth Login: Yes
Valid OAuth redirect URIs: "http://localhost:3000/users/auth/facebook/callback"
The details for settings for registered app being used in the production env are as -
Settings:
Basic:
App Domains: 'www.mysite.co'
Website:
Site URL: 'http://www.mysite.co'
Advanced:
OAuth Settings:
Embedded browser OAuth Login: Yes
Valid OAuth redirect URIs: "http://www.mysite.co/users/auth/facebook/callback"
I have specified the following in my secrets.yml
development:
secret_key_base: some_secret_key
facebook:
app_id: test_app_id
app_secret: test_app_secret
production:
secret_key_base: some_secret_key
facebook:
app_id: registered_app_id
app_secret: registered_app_secret
And have been using the creds from secrets.yml in the devise initialiser as
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
require 'omniauth-facebook'
config.omniauth :facebook, Rails.application.secrets.facebook['app_id'], Rails.application.secrets.facebook['app_secret'], scope: ['user_photos', 'email', 'public_profile']
The actual domain name(blackened) has no typos anywhere and is same wherever it is used.
Contains of routes.rb related to omniauth are as
cat config/routes.rb
Rails.application.routes.draw do
root 'home#index'
devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
# routes related to other controllers
end
The routes are as below
bundle exec rake routes | grep user
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_omniauth_authorize GET|POST /users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/facebook/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#:action
The only code related to omniauth in the entire app is as
$ cat app/controllers/users/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
#You need to implement the method below in your model (e.g. app/models/user.rb)
#user = User.from_omniauth(request.env["omniauth.auth"])
if #user.persisted?
sign_in_and_redirect #user, event: :authentication #this will throw if #user is not activated
set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
Upon further digging the problem, it was observed that the error didnt occur when 'www.example.com' was specified in the url and hence, the callback worked. When 'example.com' was specified in the address bar and facebook login tried, the login crashed with the above error.
So, I fixed the above issue by making some changes to the settings in for the facebook app. I donno if this is the right approach but it worked out. Just making the change as in point 2 didnt solve the problem.
Changes are:
1) Specified the 'App Domains' with 'example.com' and 'www.example.com'
2) Enabled 'Client OAuth Login' to 'Yes'
3) Specified 'Valid OAuth redirect URIs' with 'http://example.com/users/auth/facebook/callback' and 'http://www.example.com/users/auth/facebook/callback'
Ok, so I assume that you have a web app NOT running on Facebook that simply uses the Facebook OAuth flow for login functionality, correct? If so, you must enable "Client OAuth Login" in your application settings for the production environment. If you don't, then the web OAuth flow will not work. See this article: https://developers.facebook.com/docs/facebook-login/security

Several templates for different tasks

I need to get two different layout for a typical authorization, registration, and to display in the popup window.
A good example of Facebook http://www.facebook.com/login.php?display=popup and http://www.facebook.com/login.php
But, in my case was called link /oauth/v2/auth and Security automatically redirects to the login page.
My security.yml:
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
form_login:
provider: fos_userbundle
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
failure_forward: true
logout: true
anonymous: true
Are you able to use twig include for the login form.
You can then have as many views as you like with the login form on?