AngularJS 6 – ADAL Authentication

Today i want to talk to you about Microsoft ADAL (Azure Active Directory Authentication Library).
ADAL allows users to authenticate in Active Directory (AD) local or in the cloud and take token to protect the API.

How can i do to integrate it in a AngularJS 6 app?

1) Install the js library microsoft-adal-angular6

2) Open app.component.ts
2.1) Import the microsoft adal

2.2) In the export class AppComponent change the constructor

3) Open app.module.ts
3.1) Import the microsoft adal

3.2) We must to change our routes

3.3) In NgModule import library

If you want an example AngularJS 6 ADAL App click here.

AngularJS 6 Material – MatDatePicker italian format dd/MM/yyyy

Material Angular is very very useful library to generate beautiful app with material design and use all the power of angular.
Today we can see how to set the format for the MatDatePicker with dd/MM/yyyy so how to customize it, then you can change it.

In our Angular 6 project we must to install moment.
So execute in our project directory:

Then we must to open our
app.module.ts

At the end all the date in our project became with the format dd/mm/yyyy!!
Some question contact me.

Angular 6 – IE 11 method fill not supported

You have created your angular app and now you have some error about method fill, for example: “Object doesn’t support property or method ‘fill'”.
Line that fail: var HEADER_FILLER = new Array(HEADER_OFFSET).fill(null); (Angular core).

Don’t worry the solution is easy. You must open your file on: src/polyfill.ts
At line 21 of the file you see:

/** IE9, IE10 and IE11 requires all of the following polyfills. **/

and many “import ‘core-js/es6/BLABLA’” commented.

You must to uncomment all:

<br />
/** IE9, IE10 and IE11 requires all of the following polyfills. **/<br />
import 'core-js/es6/symbol';<br />
import 'core-js/es6/object';<br />
import 'core-js/es6/function';<br />
import 'core-js/es6/parse-int';<br />
import 'core-js/es6/parse-float';<br />
import 'core-js/es6/number';<br />
import 'core-js/es6/math';<br />
import 'core-js/es6/string';<br />
import 'core-js/es6/date';<br />
import 'core-js/es6/array';<br />
import 'core-js/es6/regexp';<br />
import 'core-js/es6/map';<br />
import 'core-js/es6/weak-map';<br />
import 'core-js/es6/set';<br />

Build and fun!

Complete Guide Ionic 3 Firebase with cordova plugin firebase

Okay let’s start to integrate in our Ionic 3 app the Firebase Google Cloud Message with the cordova plugin firebase.
In the Ionic 3 we can found the native integration with this plugin. For the documentation click here.
It work with IOS 10 and IOS 11 and latest version of Android, i have tested it.

In this guide we can see:
Install cordova plugin firebase on Ionic app
Setting cordova plugin firebase on Ionic app
Setting Firebase Cloud Message

 

Install the Ionic Firebase module

We must to install the npm library and the cordova plugin so let’s start to execute this command:

Then we must to use it on our app, so let’s start to include it in our app.module.ts, import it and then add into “providers” section.

 

Setting cordova plugin firebase on Ionic app

Now we can use it in our app.component.ts, for the grant permission, registration of token.
This is a simplest installation, import it, add in the constructor, and then use this.firebase to attach at the event.

For IOS is very important the method “grantPermission”

Now we must to setting up the account on the firebase cloud messaage, so we can generate two files:
google-services.json (Android)
GoogleService-Info.plist (IOS)

We can add this file in the root directory, with the config.xml and package.json file.

Setting Firebase Cloud Message

To setting up the firebase account remind to this guide: https://engineering.hexacta.com/managing-push-notifications-with-ionic2-3698249c07a

Remember, is very important that you upload you APN CERTIFICATE IOS, if you not load it the notifications not work.
This guide: https://firebase.google.com/docs/cloud-messaging/ios/certs

 

If you have some question write me.

ElasticSearch 5 – NEST Dynamic QueryContainer with QueryContainerDescriptor

How can i create a dynamic QueryContainer with many QueryContainerDescriptor?
How to dynamically build up a Bool query using the NEST client?

I will teach you how to create a dynamic nest query with and logic.

You must to write your QueryContainer:

Then we must to attach to them the many filters that we want

Add in and another filter to out QueryContainer. Just need to create the other QueryContainerDescriptor

We have created a query to extract: (student with age >= XX && age <= YY) && (school with alumn number > 0)

Now we must to use it:

Use the _ in the lambda expressions, because we don’t care about the parameter!
I use the Scroll() method in my query, if you want to know how to manage the Scroll, see this guide.

 

Do you know a simplest method?
There is some error in my article?
Or if you have a question write me!

 

ElasticSearch 5 – How to start using NEST C# .net

In this guide i want to show you how to start in c# .net framework with ElasticSearch version 5, with the library NEST.

WHAT IS ELASTICSEARCH 5

Elasticsearch is a Lucene-based search server with Full Text capability, with support for distributed architectures. All features are natively exposed through RESTful interface, while information is handled as JSON documents.
Is a database that contain many table and date, the table are called “index” and the date are called “documents” is like a no-sql database, as mongodb or couchbase.
In each “index” you can load many “documents” with many different “mapping”.

I suggest to install Kibana to manage ElasticSeach. Starter guide.

CHAPTER MAPPING LINK OFFICIAL DOC.

You can put the mapping on elastic search server throw Kibana dev console.
Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define:

  • which string fields should be treated as full text fields.
  • which fields contain numbers, dates, or geolocations.
  • whether the values of all fields in the document should be indexed into the catch-all _allfield.
  • the format of date values.
  • custom rules to control the mapping for dynamically added fields.

In the mapping you can define the field, and each field as a datatype. Read the official guide for all datatypes.
Principles datatype:
– boolean
– int | short | long
– date
– text
– keyword
– specialized type (as IP, Completion (autocomplete), Token count datatype)

NEST C#

NEST is a high level client that has the advantage of having mapped all the request and response objects, comes with a strongly typed query DSL that maps 1 to 1 with the Elasticsearch query DSL, and takes advantage of specific .NET features such as covariant results and auto mapping of POCOs. NEST internally uses and still exposes the low level Elasticsearch.Net client.
Link to download NEST.

PRATICAL USE OF NEST C#

Now we must to create the filter query to take data.
Using Nest to take this is very simple, i show you an example:

Mapping of data type and method:
Boolean => Exists
Date => DateRange
Number => Range
Text Like => WildCard
Text Exact => Term

Now i’have used the Bool Query type, but exist other type, remind you to this official link.

USING NEST SCROLL

The scroll API allows you to efficiently page through a large dataset as it keeps the query alive in the cluster. And if you want all / unlimited data, without pagination.
https://gist.github.com/Cicciokr/5300ae6e0d3690e87af02474d4890617

[CVE-2017-1000253] Linux kernel security bug fixed

How to report on zdnet on their article there is a serious bug with linux kernel identified as CVE-2017-1000253:

§ Centos6 con Kernel < 2.6.32-696.10.3
§ Centos7 con Kernel 7.4 kernels < 3.10.0-693

The bug how report zdnet:

This is a problem with how the Linux kernel loaded Executable and Linkable Format (ELF) executables. If an ELF application was built as Position Independent Executable (PIE), the loader could allow part of that application’s data segment to map over the memory area reserved for its stack. This could cause memory corruption. Then, an otherwise unprivileged local user with access to a Set owner User ID (SUID) or otherwise privileged flawed PIE binary, could gain higher-level user privileges.

The bug was fixed so you must to upgrade your kernel.

I used the guide on the site tecmint.com. It was very helpful and easy, consist to install a new kernel and then switch the boot on the new kernel. Suggest to take a snapshot or a backup of your machine / virtual machine.

 

 

Aruba VPS Centos VMware – Come aumentare lo spazio hdd

Oggi vedremo come aumentare lo spazio (ripartizionare) dell’hard disk, una volta eseguito l’upgrade sul vostro vps aruba.

fdisk -l

parted /dev/sda/

Per creare una nuova partizione per lo spazio aggiunto, lanciare mkpart e rispondere alle varie richieste. Dapprima vi viene chiesto di scegliere il “type” fra” primary” ed “extended” (sceglieremo primary) successivamente viene chiesto il tipo di “File System” (ad esempio scegliamo “ext3” e confermiamo); successivamente viene richiesto l’inizio e la fine della partizione (nel nostro esempio se vogliamo creare una partizione che corrisponda con tutto lo spazio aggiunto, basta indicare come inizio il valore “end” della partizione con il numero più alto e con la dimensione massima per la fine).

A questo punto rilanciando print possiamo verificare che è stata creata la nuova partizione 3.

Ora non resta che creare il Filesystem nella partizione creata: dapprima uscire da “parted” digitando quit e quindi lanciare mke2fs per la partizione creata.

df -h /home/

vgdisplay vg

lvextend -L +2G /dev/mapper/vg-lv_root

resize2fs /dev/mapper/vg-lv_root

Per arrivare a ciò ho seguito due guide, la prima di Aruba e la seconda di linuxtechi, che vi riporto qui di seguito:

http://kb.cloud.it/computing/creare-e-configurare-un-cloud-server/ri-formattare-un-disco-fisso-espanso-linux.aspx
http://www.linuxtechi.com/extend-lvm-partitions/

How to reset mysql root password

mysql

Pratical and best guide that i have tried from many others that founded on web about how to reset mysql root password on linux server.

When you have this error, on you Ubuntu or Centos server (I have tried on Centos, and the user in the original post tried on Ubuntu):

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

This is the guide to reset your mysql password:

$ sudo -s

# /etc/init.d/mysql stop

# mysqld_safe --skip-grant-tables &

# mysql -u root

 

After logged as user root, reset the password:

mysql> use mysql;

mysql> update user set password=PASSWORD(’__NEW__PASSWORD__’) where User=’root’;

mysql> flush privileges;

mysql> \q

# /etc/init.d/mysql start

 

And then, remember take a backup of your file!!

mysqldump -u root -p --all-databases > alldb.sql

Thank you to http://forum.ubuntu-it.org/viewtopic.php?t=293129

VestaCP upgrade PHP 5 to PHP 7 on CentOS 6

Hi guys,
today i will show to you how to upgrade on VestaCP PHP 5.x to a 2x faster PHP 7!

At start will upgrade EPEL, remember that we use the Centos 6, so EPEL must to be the 6 version.
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
# wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
# rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm

See what PHP version will have:
# yum list installed php*
Installed Packages
php55w.x86_64 5.5.38-1.w6
php55w-cli.x86_64 5.5.38-1.w6

See what PHP version will be available in our package:
# yum list available php* | grep php7
php70w.x86_64 7.0.11-1.w6 webtatic
php70w-bcmath.x86_64 7.0.11-1.w6 webtatic
php70w-cli.x86_64 7.0.11-1.w6 webtatic

remove the actual php 5 version:
# yum remove php*

Install the new php 7 version:
# yum install php70w php70w-cli php70w-common php70w-gd php70w-mbstring php70w-mysql php70w-pdo php70w-xml

Verify that all is good:
# php -v
PHP 7.0.11 (cli) (built: Sep 17 2016 12:52:22) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

Restart the web server:
# service httpd restart

Thank you to Shay Anderson for his guide.