RADIUS

Before you start learning about Radius, it is important that you understand:

AAA :

Authentication, authorization, and accounting (AAA) is a term for a framework for intelligently controlling access to computer resources, enforcing policies, auditing usage, and providing the information necessary to bill for services. These combined processes are considered important for effective network management and security.

Authentication, authorization, and accounting services are often provided by a dedicated AAA server, a program that performs these functions. A current standard by which network access servers interface with the AAA server is the Remote Authentication Dial-In User Service (RADIUS).

RADIUS(Remote Authentication Dial-In User Service):

Radius is a protocol for carrying information related to authentication, authorization, and configuration between a Network Access Server (NAS) that desires to authenticate its links and a shared Authentication Server.

What is Network Access Server?


The Network Access Server (NAS) is a service element that clients dial in order to get access to the network.

Basic Architecture for NAS / RADIUS / AAA


Features of Radius:

  1. Client/Server Model
  • NAS works as a client for the Radius server.
  • A Radius server can act as a proxy client to other Radius servers.
  1. Network Security
  • Transactions between a client and a server are authenticated through the use of a shared key. This key is never sent over the network.
  • Password is encrypted before sending it over the network.

How to install FreeRADIUS in Ubuntu server:

Installing FreeRADIUS is the easiest part. It can be done with.


$ sudo apt-get install freeradius

Verify FreeRADIUS version


Verify it was installed by checking the version.


$ freeradius -v


FreeRADIUS should be able to run successfully with all the defaults.


Run a quick config check.


$ sudo freeradius –CX

Review the Configuration Files


The FreeRADIUS files are located in /etc:


$ cd /etc/freeradius
$ sudo nano /etc/freeradius/radiusd.conf


Here is where we tell FreeRADIUS to look for authorized clients (authenticators).


$INCLUDE clients.conf

Add Clients


Open the clients.conf file to add your authenticator(s).
And then add these lines


client 192.168.1.1{
hostname = TP_LINK
secret = password@123
}


Add Users


$ sudo nano /etc/freeradius/users


Add an account to the file:


usertest Cleartext-Password := “Password123”

Test Authentication


Run a quick test to see if FreeRADIUS will accept the newly created username and password. Running this from the server means you will have to use the secret configured for the localhost which is defined in the clients.conf file:


$ radtest usertest Password123 127.0.0.1 0 testing123


Start FreeRadius


$ service freeradius start


Stop FreeRadius


$ service freeradius stop

References :

https://www.tutorialspoint.com/radius/aaa_and_nas.htm

https://searchsecurity.techtarget.com/definition/authentication-authorization-and-accounting

https://whatis.techtarget.com/definition/access

https://wiki.freeradius.org/guide/SQL-HOWTO-for-freeradius-3.x-on-Debian-Ubuntu

Flutter

what is a flutter:-

It’s an open-source software development kit (SDK), developed by Google, to quickly build iOS and Android apps, sharing most of the code. It works in conjunction with the Android and iOS SDKs, which also means you still need a macOS machine to build for iOS (just like you do for React Native and Xamarin)

Language :-

It uses the Dart programming language, also developed by Google. Yes, another language to learn but don’t worry, it’s super easy if you’re familiar with Java, JS, Kotlin, Swift or C#.

Advantages of Flutter and Dart:-

1- Hot reloading is just too useful, in the editor, and the app reloads in a sec on the sim! Goodbye to the endless build / wait / run / wait / test / start-over endless process.

2-small reusable components that react to a change in the ‘state’.

3-Dart is simple but a powerful and complete language, comparable to Swift, Kotlin or Java..

4- Flutter and Dart have built-in support for both unit testing for logic, and widget testing for UI/interactions.

5-Bonus: This is an advantage of any cross-platform technology in reality, not just Flutter, but I’m still going to mention it: creating an app for both platforms at the same time makes it much easier to keep them aligned at all times

Minimum Requirements :

for linux installation :

*Operating Systems: Linux (64-bit)

* Disk Space: 600 MB (does not include disk space for IDE/tools).

Installation :-

there is many way installing flutter depend on OS .i flow this link step to install flutter in linux .


problems and Tips :-

after i complete the installation steps . flutter doctor Diagnosis say flutter SDK can’t found android SDK , it solved by adding steps in this link .

Flutter Example :

this is an simple example of flutter it’s app generate random number

create class first screen.dart extent from StatelessWidget class this class return widget , and function call random_num( ) return an int value generated by random calss

import ‘dart:math’;

import ‘package:flutter/material.dart’;

class first_screen extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Material(
color: Colors.lightBlue,
child:Center(
child: Text(
“Generated Random number is =${random_num()},
textDirection: TextDirection.ltr,
style: TextStyle(color: Colors.brown ,fontSize: 30.0),
),
),

);
}

}

int random_num(){
var random = Random();
int num = random.nextInt(22);
return num;
}

in main.dart create myapp class and call the first_screan.dart class inside the body :

i
import ‘package:flutter/material.dart’;
import ‘package:flutter_app/app_screen/first_screen.dart’;

void main()=>runApp( new myapp());


class myapp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
title:“flutter app”,
home:Scaffold(
appBar: AppBar(
title:Text(“my first app flutter”),),
body: new first_screen()
),
);
}

}

View App screan :-

Reference:-

Installation :-https://flutter.dev/docs/get-started/install

linux PATH problem :- https://blog.gauravagarwalr.com/posts/2018-04-11-setting-up-flutter/

Flutter tutorial :- https://www.youtube.com/watch?v=HAPQ3oUGgnE&list=PLlxmoA0rQ-Lw6tAs2fGFuXGP13-dWdKsB&index=3

https://flutter.dev/docs/development/ui/widgets-intro


WebSocket using Golang

Inspired by the previous Article of Implementing WebSocket with NodeJS, I have tried successfully WebSocket in Go language.

Steps:

First install WebSocket package for Go:

go get github.com/gorilla/websocket

Start new project in Go, and write this HTML content in websockets.html file in project directory:

<!-- websockets.html -->
<h2>WebSocket using Golang</h2>
<h3>Server time</h3>
<pre id="output"></pre>
<script>

    var input = document.getElementById("input");
    var output = document.getElementById("output");
output.innerHTML = location.host;
    var socket = new WebSocket("ws://" + location.host + "/time");

    socket.onopen = function () {
        output.innerHTML = "Status: Connected";
    };

    socket.onmessage = function (e) {
        output.innerHTML = "From Server: <b>" + e.data + "</b>";
    };


</script>

</script>

Then write Go source code as main.go in the same directory of .HTML file :

// GorillaWebSocket project main.go
package main

import (
    "fmt"
    "net/http"
    "strconv"
    "time"

    "github.com/gorilla/websocket"
)

var upgrader = websocket.Upgrader{
    ReadBufferSize: 1024,
    WriteBufferSize: 1024,
}

var id = 0

func main() {
    http.HandleFunc("/time", timer)

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        http.ServeFile(w, r, "websockets.html")
    })

    http.ListenAndServe(":1234", nil)
}

func timer(w http.ResponseWriter, r *http.Request) {

    conn, err := upgrader.Upgrade(w, r, nil)
    id++
    localID := id
    fmt.Println("Connected to: ", r.RemoteAddr, " as client # ", localID)
    fmt.Println(localID, r.UserAgent())
    if err != nil {
        fmt.Println("Error: ", err.Error())
    }

    for {

        time.Sleep(time.Second)
        now := time.Now()

        msg := "(" + strconv.Itoa(localID) + ") " + now.String()[:19]
        // Write time to browser
        err = conn.WriteMessage(websocket.TextMessage, []byte(msg))
        if err != nil {
            fmt.Println("Closed client # ", localID, ": Error: ", err.Error())
            return
        }
    }
}

Then run it and in the browser open

http://localhost:1234

You can open many tabs, or open many browsers or clients, and note that timer function will be instantiated with every client and it keeps working, which means every client will have it’s own running timer function, until the browser disconnects, then it will exist and will be removed from memory

Reference: https://gowebexamples.com/websockets/

ServiceCkeck

ServiceCheck is a native Linux 64 bit utility to check background service and run it if it is not up.

Usage:

  1. Configure checklist.ini file in the same directory of servicecheck application. Put all services to be checked in that file in the format

app1name      "/home/user/app1/app1name"
appn2name "sh /home/user/app2/app2.sh"


Application name (that appear in Linux processes (ps -ef)), then script to run the application if it is closed

2. Put servicecheck in crontab job to work periodiacly, for example every 5 minutes, e.g.

*/5 * * * * /home/user/checker/servicecheck

Note: to run applications in sudo privilege configure servicecheck in sudo crontab, for normal user, use crontal for normal user


Implementing WebSocket Server with NodeJS

What is WebSocket ?!

Web sockets are defined as a two-way communication between the servers and the clients, which mean both the parties, communicate and exchange data at the same time.

How WebSocket Connection Works ?!

Conceptually, the WebSocket protocol is an extension to HTTP which allows clients to “upgrade” an HTTP connection with an additional bi-directional connection which remains established, like this:

  • Client opens HTTP connection to server and asks for document
  • Server responds with an HTML document
  • HTTP connection is closed
  • JavaScript code in the HTML document opens another HTTP connection in which it asks the server to upgrade this connection to a WebSocket connection
  • A WebSocket connection between client and server is established and remains open for sending and receiving data in both directions

What is NodeJS ?!

NodeJS is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Installation

To install nodeJS on Ubuntu 16.04

$ sudo apt-get install nodejs

Then we’ll install npm, which is the Node.js package manager.

sudo apt-get install npm

The Project

First Lets create a folder for our a project and name it ” websocket “, in that folder we will create a package.json file ( which is a plain JSON file contains all metadata information about NodeJS Project or application).

{
"name": "websocket",
"version": "0.0.1",
"description": "WebSocket Testing Project",
"dependencies": {}
}

Then we will install express (which is a web framework) using npm

 npm install express --save  

Now let’s create a very basic web application using express, in app.js file.

var app = require('express')();
var http = require('http').Server(app);

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/index.html');
});

http.listen(3000, function() {
  console.log('Listening on Port: 3000');
});

This creates an HTTP Server listening on port 3000 but the index.html file doesn’t exist yet so let’s create it.

<!doctype html>
<html>
  <head>
    <title>Free Memory Monitor</title>
  </head>
  <body>
    Free Memory: <span id="freemem">no data yet</span>
  </body>
</html>

Now we can start the application by typing

node app.js 

Now Let’s add the Socket.io which is the library that handles all the websoket connection for us. Also let’s update the app.js with the code that brings the total memory and the free memory information and send them to the clients every second.

npm install socket.io --save
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var os = require('os');

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', function(socket){
    console.log('A new WebSocket connection has been established');
});
  
setInterval(function() {
    io.emit('cpu usage', os.cpus());
    io.emit('total memory', os.totalmem());
    io.emit('free memory', os.totalmem(), os.freemem());
}, 1000);

http.listen(3000, function() {
  console.log('Listening on *:3000');
});

We have to update the index.html code so that it can make good use of the information sent

<!doctype html>
<html>
  <head>
    <title>Live stock price ticker</title>

    <script src="/socket.io/socket.io.js"></script>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

    <script>
      $(function () {
        var socket = io();

        socket.on('cpu usage', function(cpus) {
          for(cpu of cpus)
          $('#cpu').text(cpu.model);
          
        });

        socket.on('total memory', function(totalmem) {
          $('#totalmem').text(totalmem);
          
        });

        socket.on('free memory', function(totalmem, freemem) {
          $('#freemem').text(Number.parseFloat
((freemem/totalmem)* 100).toPrecision(4) + "%");
          
        });

      });
    </script>

  </head>
  <body>
    <h3> CPU Usage : <span id="cpu">no data yet</span> </h3>
    <h3> Total Memory : <span id="totalmem">no data yet</span> </h3>
    <h3> Free Memory : <span id="freemem">no data yet </span> </h3>
  </body>
</html>

Sources

https://www.tutorialspoint.com/websockets/index.htm

https://www.ably.io/concepts/websockets

https://hackernoon.com/implementing-a-websocket-server-with-node-js-d9b78ec5ffa8

CouchDB

Apache CouchDB is an open source NoSQL document based database engine that is written in Erlang. It uses RESTFull web service to be accessed for clients, so that you can use it though REST api or through drivers in each programming languages that has encapsulated REST calls into programming language methods/procedures calls.

CouchDB supports multi node clustering.

Installation

To install latest version of couchdb it in Ubuntu 16.04 (xenial):

echo "deb https://apache.bintray.com/couchdb-deb xenial main" | sudo tee -a /etc/apt/sources.list

For Ubuntu 18.04 (bionic):

echo "deb https://apache.bintray.com/couchdb-deb bionic main" | sudo tee -a /etc/apt/sources.list

Then add that new repository key:

curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | sudo apt-key add -

Note that if curl command is not found, you need to install it:

sudo apt-get install curl

Then update and install:

sudo apt-get update && sudo apt-get install couchdb

After installation, type this URL in browser to open administrative portal for CouchDB:

http://127.0.0.1:5984/_utils

Enter admin login and password that you have entered during installation, then you will get this view:

Then you can create databases, manage data, and users

REST API

Accessing server information :

curl http://127.0.0.1:5984/

Result:

{   
"couchdb": "Welcome", "version": "2.3.0", "git_sha": "07ea0c7",
"uuid": "8e99e2abff3f90efd7643ff8e04f7f8f",
"features": [ "pluggable-storage-engines", "scheduler" ],
"vendor": { "name": "The Apache Software Foundation" }
}

Creating a database named test :

curl -X PUT http://127.0.0.1:5984/test
result:
{"ok": true}

Retrieve information about the test database :

curl http://127.0.0.1:5984/test
result:

{ "db_name": "test", "purge_seq": "0-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMeC5BkeACk_gNBViIDQbUHIGrvE6N2AUTtfvxqkxyAZFI8QfuTFEDq7Il0ZwPE7vkEzEwAmVlP0MxEhiR5iKIsAD6cXo4", "update_seq": "1-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____sxIZ8ChKUgCSSfZgdYz41DmA1MUTNi8BpK6eoLo8FiDJ0ACkgErnE6N2AUTtfmLUHoCovU-M2gcQtSD3ZgEAX4Rejw", "sizes": { "file": 38120, "external": 40, "active": 318 }, "other": { "data_size": 40 }, "doc_del_count": 0, "doc_count": 1, "disk_size": 38120, "disk_format_version": 7, "data_size": 318, "compact_running": false, "cluster": { "q": 8, "n": 1, "w": 1, "r": 1 }, "instance_start_time": "0" }

Create a document, asking CouchDB to supply a document id :


curl -X POST -H "Content-Type: application/json" --data \ '{ "text" : "Wikipedia on CouchDB", "rating": 5 }' \ http://127.0.0.1:5984/wiki

result:
{
"ok": true,
"id": "123BAC",
"rev": "946B7D1C"
}

Reference:

https://en.wikipedia.org/wiki/Apache_CouchDB

Go lang connection

First you need to import a library, for example:

https://github.com/rhinoman/couchdb-go

And this is an example of creating and connecting to a database called (academy) using Go language:

It contains create database, insert document, and search for documents:

// CouchDBSample project main.go
package main
import (
	"encoding/json"
	"fmt"
	"time"
	"github.com/rhinoman/couchdb-go"
)
type TestDocument struct {
	Name          string
	Address       string
	InsertionTime time.Time
}
type DataList struct {
	Docs []TestDocument
}
func main() {
	var timeout = time.Duration(500 * time.Millisecond)
	conn, err := couchdb.NewConnection("127.0.0.1", 5984, timeout)
	if err != nil {
		println("Error: ", err.Error())
	}
	auth := couchdb.BasicAuth{Username: "motaz", Password: "help"}
	conn.CreateDB("academy", &auth)
	db := conn.SelectDB("academy", &auth)
	today := time.Now()
	theDoc := TestDocument{
		Name:          "Motaz",
		Address:       "Alsajana",
		InsertionTime: today,
	}
	insert(db, theDoc)
	selector := `{"Address":"Bahri"}`
	search(db, selector)
}

func insert(db *couchdb.Database, theDoc TestDocument) {

	now := time.Now()
	rev, err := db.Save(theDoc, now.String(), "")
	if err != nil {
		println("Error in .Save: ", err.Error())
	} else {
		println("Saved: ", rev)
	}
}

func search(db *couchdb.Database, selector string) {
	result := DataList{}
	var selectorObj interface{}
	err := json.Unmarshal([]byte(selector), &selectorObj)
	params := couchdb.FindQueryParams{Selector: &selectorObj}
	err = db.Find(&result, &params)
	if err != nil {
		println("Error in .Find: ", err.Error())
	}
	fmt.Println("Num: ", len(result.Docs))
	for _, x := range result.Docs {
		fmt.Println("%v", x)
	}
}

Comparison to MangoDB

Advantages over MongoDB:

  1. Its license is Apache free license, while MongoDB needs commercial license for close source application, otherwise you have to open source your projects that uses MongoDB, so that MongoDB has been dropped from famous Linux distributions such as: Debian and RedHat.
  2. Uses REST API that can be called from any programming language, or scripts, such as shell script, no driver is needed when using this method
  3. Available in Android and IOS
  4. Supports master to master clustering in addition to master to slave clustering

Disadvantages of CouchDB compared to MongoDB:

  1. Less popular in usage compared to MongoDB
  2. MongoDB is more faster in read
  3. MongoDB is better in rapid growth databases
  4. MongoDB supports more programming languages

Sources:

https://db-engines.com/en/system/CouchDB%3BMongoDB

https://blog.panoply.io/couchdb-vs-mongodb

Odoo

Installing Odoo 12 on Ubuntu

1. Downloading the script
The first step is to download the script from Github and to add the code in a new .sh file on your Ubuntu machine, wherever you’d like this.
For example right under /home. Open up an Ubuntu terminal and cd to the directory where you’d like to keep the script and then create the file:

sudo wget https://raw.githubusercontent.com/Yenthe666/InstallScript/12.0/odoo_install.sh

Now open up the file and edit the parameters to your liking:

sudo nano odoo_install.sh

Tip:
There are some things you can configure/change to your likings at the top of the script. If you want the enterprise version of V12 you should change the line

IS_ENTERPRISE="True"

If you want the community version you can just continue and keep the IS_ENTERPRISE key on “False” (which is the case by default):

IS_ENTERPRISE="False"

2. Making the Odoo installation file executable

The next step is to make this file executable. After you’ve made it executable you can execute it and everything will be installed automatically.
do this with the following command:

sudo chmod +x odoo_install.sh

3.Running the script

Now that the code is in your file and the file is executable you simply have to execute it with the following command:

./odoo_install.sh

You will see that the script automatically starts updates, downloads required packages, creates the user, downloads the code from Github, … Eventually, if you’ve chosen to install the enterprise version, you will need to give in your Github credentials to download the enterprise code (since this is a private repository). Fill in your details and let the script continue:

Give the script a few minutes to configure and install everything and eventually you will see something like this:

You now have a fully functional Odoo V12 community or enterprise on your system! Congratulations.