Author Archive: walter

Windows 10 connect to NAS with smb1 (Samba, the old one)

Since Windows 10, microsoft remove the support for Samba 1, the problem is that I still have that old NAS who only support SMB1, so here’s the error shown:

You can't connect to the file share because it's not secure. This share requires the obsolete SMB1 protocol, which is unsafe and could expose your system to attack.
Your system requires SMB2 or higher. For more info on resolving this issue, see: https://go.microsoft.com/fwlink/?linkid=852747

And the solution is realy easy.

  1. Open control panel
  2. Search for Turn Windows features on or off
  3. Scroll down to SMB 1.0/CIFS File Sharing Support and activate the checkbox to activate que option
  4. Restart and you’re done

Android FX Explorer can’t connect to Raspberry pi with OSMC via SSH

Since the last update of OSMC in my Raspberry PI I was unable to connect from my smartphone using this awesome app called FX Explorer on the other and I still can use Juiced SSH.

So I had to dig on that problem!

After I little search I finally manage to find the problem, the last version of OSMC had a different configuration

1
$ sudo vim /etc/ssh/ssh_config

That was a missing algorithm in that line:

1
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256

Just add

1
diffie-hellman-group-exchange-sha1

So the line looks like:

1
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1

Now save, exit and restart sshd service

1
$ sudo systemctl restart sshd

And you’re done!

Inject a custom Controller in Sonata

I had this problem, I needed to inject a Storage to my controller so I can create a custom action and connect to my db using a storage service.

All I needed was configure the services as following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
services:
  app.admin.document
:
    class
: AppBundle\Admin\DocumentAdmin
    arguments
: [~, AppBundle\Entity\Document, 'app.controller.document']
    tags
:
      - { name
: sonata.admin, manager_type: orm, group: Documentation, label: Documents }

app.controller.document
:
    class
: AppBundle\Controller\DocumentAdminController
    calls
:
      - [ setContainer,[ "@service_container" ] ]
    arguments
:
      - "@security.token_storage"
      - "@app.storage.document"

app.repository.document
:
    class
: AppBundle\Repository\DocumentRepository
    factory
: ["@doctrine.orm.entity_manager", getRepository]
    arguments
:
      - AppBundle\Entity\Document

app.storage.document
:
    class
: AppBundle\Storage\DocumentStorage
    arguments
:
      - "@app.repository.document"

Ignore modified file from commit

Sometimes you need to change some files, just for your development environment and you don’t want to commit those changes. With Git there a way to fix your problem.

First of all, made all the change you need in the file(s) to ignore then run this command:

1
$ git update-index --assume-unchanged path/to/the/file/to/ignore

and it’s done, now your changes are ignored.

Sure, you can roolback those changes by running the command

1
$ git update-index --no-assume-unchanged path/to/the/file/to/version/again

At any point, if you feel that you lost the count of the untracked files, you can list all the files versioned with the files the that starts with a lowercase letter are ignored from versioning.

1
git ls-files -v

To simplify the output run this command, it will only show the ignored files:

1
git ls-files -v | grep '^[[:lower:]]'

append and prepend script with apache

Sometimes we need to run a script in our localhost (or maybe in production) but we don’t want to edit our application to test the current environment. To solve this problem we can just add the file via apache virtual host configuration.

So go on and edit your virtual host, and add this line to the <Directory> directive.

To execute at the end:

1
php_value auto_append_file "/Users/walter/workspace/append.php"

To execute before everything:

1
php_value auto_prepend_file "/Users/walter/workspace/prepend.php"

Don’t forget to restart apache before reloading the app.

Composer update creates a lack of memory

While using Symfony 2 it’s common that you have to run the command composer update. Sometimes we’re graced with the error:

1
2
3
4
5
6
7
8
9
10
The following exception is caused by a lack of memory and not having swap configured

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:954
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 954, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(954): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(754): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(715): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(648): Symfony\Component\Console\Application->getTerminalWidth()
#5 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(130): Symfony\Component\Console\Application->renderException(Object(ErrorException),  in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 954

The easiest way to fix it it’s by creating a virtual swap partition using the following commands:

1
2
3
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

WordPress configurations for Heroku

Starting…

Download the last version of wordpress, then create a directory called “wordpress” (or anything you want else to call it) and extract the content of the zip to the directory.

WordPress Configuration

Jump to your directory and create the Procfile with this line

1
web: vendor/bin/heroku-php-apache2 /

Add a file for composer, named composer.json

1
2
3
4
5
6
7
{
  "name" : "Wordpress",
  "require" : {
    "php" : ">=5.3.3",
    "ext-mbstring" : "*"
  }
}

Edit the wp-config.php file and replace the first lines with

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$db = parse_url(getenv('CLEARDB_DATABASE_URL'));

define('DB_NAME', str_replace('/', '', $db['path']));
define('DB_USER', $db['user']);
define('DB_PASSWORD', $db['pass']);
define('DB_HOST', $db['host']);

define('AUTH_KEY',         '{%AUTH_KEY%}');
define('SECURE_AUTH_KEY',  '{%SECURE_AUTH_KEY%}');
define('LOGGED_IN_KEY',    '{%LOGGED_IN_KEY%}');
define('NONCE_KEY',        '{%NONCE_KEY%}');
define('AUTH_SALT',        '{%AUTH_SALT%}');
define('SECURE_AUTH_SALT', '{%SECURE_AUTH_SALT%}');
define('LOGGED_IN_SALT',   '{%LOGGED_IN_SALT%}');
define('NONCE_SALT',       '{%NONCE_SALT%}');

Git repository

1
2
3
4
5
6
7
8
9
10
11
$ git init
Initialized empty Git repository
$ echo "/wp-content/plugins/" >> .gitignore
$ echo "/wp-content/themes/" >> .gitignore
$ git add .
$ git commit -am 'First commit'
[master (root-commit) 83b5792] First commit
 1014 files changed, 384288 insertions(+)
 create mode 100644 .gitignore
....
 create mode 100644 xmlrpc.php

Configure Heroku

Create an App with heroku toolbelt setting up the app name my-wordpress-app and the region eu

1
$ heroku apps:create --region eu my-wordpress-app

Database

Creating the database, this will create a free cleardb on heroku and add the system variable CLEARDB_DATABASE_URL:

1
2
3
4
5
$ heroku addons:create cleardb:ignite
Creating giving-gently-8505... done, (free)
Adding giving-gently-8505 to my-wordpress-app... done
Setting CLEARDB_DATABASE_URL and restarting my-wordpress-app... done, v3
Use <code>heroku addons:docs cleardb</code> to view documentation.

The Deploy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
git push heroku master
Counting objects: 1101, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1079/1079), done.
Writing objects: 100% (1101/1101), 4.61 MiB | 282.00 KiB/s, done.
Total 1101 (delta 63), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PHP app detected
remote: -----> Resolved composer.json requirement for PHP to version 5.6.11.
remote: -----> Installing system packages...
remote:        - PHP 5.6.11
remote:        - Apache 2.4.10
remote:        - Nginx 1.6.0
remote: -----> Installing PHP extensions...
remote:        - mbstring (composer.json; bundled)
remote:        - zend-opcache (automatic; bundled)
remote: -----> Installing dependencies...
remote:        Composer version 1.0.0-alpha10 2015-04-14 21:18:51
remote:        Loading composer repositories with package information
remote:        Installing dependencies
remote:        Nothing to install or update
remote:        Writing lock file
remote:        Generating optimized autoload files
remote: -----> Preparing runtime environment...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 77.0MB
remote: -----> Launching... done, v4
remote:        https://my-wordpress-app.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/my-wordpress-app.git
   83b2946..4274dc2  master -> master

Finally, load your website and finish the wordpress configurations.
Screen Shot 2015-07-30 at 16.43.29

I hope it was usefull.

Install FOS User in Symfony 2

After finished the tutorial I needed a user Bundle, the FOS Bundle (Friend of Symfony) is for Symfony 2 what SfGuardUser was for Symfony 1, so we gonna continue the tutorial started in the previous post.

Installing the bunddles:

1
2
composer require sonata-project/user-bundle --no-update
composer update

Add to your registerbundles function in the AppKernel class

1
2
3
new FOSUserBundleFOSUserBundle(),
new SonataUserBundleSonataUserBundle('FOSUserBundle'),
new ApplicationSonataUserBundleApplicationSonataUserBundle(),

Add to the config.yml

1
2
3
4
5
6
7
8
9
10
11
12
sonata_user:
    security_acl
: true
    manager_type
: orm # can be orm or mongodb
fos_user
:
    db_driver
: orm # can be orm or odm
    firewall_name
: main
    user_class
: ApplicationSonataUserBundleEntityUser
    group
:
        group_class
: ApplicationSonataUserBundleEntityGroup
        group_manager
: sonata.user.orm.group_manager # If you're using doctrine orm (use sonata.user.mongodb.user_manager for mongodb)
    service
:
        user_manager
: sonata.user.orm.user_manager # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb)

In the config.yml, add to the doctrine configuration under the dbal option the types lines

1
2
types:
    json
: SonataDoctrineTypesJsonType

Change the security.yml for this one

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
security:

    encoders
:
        FOSUserBundleModelUserInterface
: sha512

    acl
:
        connection
: default

    role_hierarchy
:
        ROLE_ADMIN
:      [ROLE_USER, ROLE_SONATA_ADMIN]
        ROLE_SUPER_ADMIN
: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
        SONATA
:
           - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT  # if you are using acl then this line must be commented

    providers
:
        fos_userbundle
:
            id
: fos_user.user_manager

    firewalls
:
       # Disabling the security for the web debug toolbar, the profiler and Assetic.
        dev
:
            pattern
: ^/(_(profiler|wdt)|css|images|js)/
            security
: false

        # -> custom firewall for the admin area of the URL
        admin
:
            pattern
:           /admin(.*)
            context
:           user
            form_login
:
                provider
:      fos_userbundle
                login_path
:    /admin/login
                use_forward
:   false
                check_path
:    /admin/login_check
                failure_path
:  null
            logout
:
                path
:          /admin/logout
            anonymous
:         true

        # -> end custom configuration

        # default login area for standard users

        # This firewall is used to handle the public login area
        # This part is handled by the FOS User Bundle
        main
:
            pattern
:            .*
            context
:            user
            form_login
:
                provider
:      fos_userbundle
                login_path
:    /login
                use_forward
:   false
                check_path
:    /login_check
                failure_path
:  null
            logout
:            true
            anonymous
:         true

        default
:
            anonymous
: ~


    access_control
:
       # URL of FOSUserBundle which need to be available to anonymous users
        - { path
: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path
: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path
: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

        # Admin login page needs to be access without credential
        - { path
: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path
: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path
: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }

        # Secured part of the site
        # This config requires being logged for the whole site and having the admin role for the admin part.
        # Change these rules to adapt them to your needs
        - { path
: ^/admin/, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
        - { path
: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }

Update the routing.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
app:
    resource
: "@AppBundle/Controller/"
    type
:    annotation

admin
:
    resource
: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix
: /admin

_sonata_admin
:
    resource
: .
    type
: sonata_admin
    prefix
: /admin

sonata_user_security
:
    resource
: "@SonataUserBundle/Resources/config/routing/sonata_security_1.xml"

sonata_user_resetting
:
    resource
: "@SonataUserBundle/Resources/config/routing/sonata_resetting_1.xml"
    prefix
: /resetting

sonata_user_profile
:
    resource
: "@SonataUserBundle/Resources/config/routing/sonata_profile_1.xml"
    prefix
: /profile

sonata_user_register
:
    resource
: "@SonataUserBundle/Resources/config/routing/sonata_registration_1.xml"
    prefix
: /register

sonata_user_change_password
:
    resource
: "@SonataUserBundle/Resources/config/routing/sonata_change_password_1.xml"
    prefix
: /profile

sonata_user
:
    resource
: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
    prefix
: /admin

Now generate the entities

1
php app/console sonata:easy-extends:generate SonataUserBundle -d src

You can clone the project from my github account here.