Sunday, September 25, 2022

Vue in Laravel9 with vite

 

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
 
export default defineConfig({
    plugins: [
        laravel(['resources/js/app.js','resources/css/app.css']),
        vue({
            template: {
                transformAssetUrls: {
                    // The Vue plugin will re-write asset URLs, when referenced
                    // in Single File Components, to point to the Laravel web
                    // server. Setting this to `null` allows the Laravel plugin
                    // to instead re-write asset URLs to point to the Vite
                    // server instead.
                    base: null,
 
                    // The Vue plugin will parse absolute URLs and treat them
                    // as absolute paths to files on disk. Setting this to
                    // `false` will leave absolute URLs un-touched so they can
                    // reference assets in the public directory as expected.
                    includeAbsolute: false,
                },
            },
        }),
       
    ],
    resolve: {
        alias: {
          vue: 'vue/dist/vue.esm-bundler.js',
        },
    },
});

Thursday, September 22, 2022

Remote Desktop issue between windows 10/11 to VM- Server 2012 R2

 

Create New Key 

1) CredSSP->Parameters -> Deword 32 bit ->AllowEncryptionOracle ->2 (decimal)

Enable gpedit.msc in Windows 11

 run as administrator command prompt

paste

FOR %F IN ("%SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~*.mum") DO (
DISM /Online /NoRestart /Add-Package:"%F"
)
FOR %F IN ("%SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~*.mum") DO (
DISM /Online /NoRestart /Add-Package:"%F"
)

Tuesday, September 20, 2022

Windows Cannot Connect To The Printer

 1) regedit

Computer\HKLM\System\currentControlSet\Control\Print -> create Dword-32 

RpcAuthnLevelPrivacyEnabled ->0


2) Restart Print Spooler service

Monday, September 19, 2022

Authentication for Vue 3, Laravel 9 with Sanctum

 1) Kernel.php -> uncomment
'api' => [
             \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,

 2) php artisan make:controller API/AuthController

 

<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Models\User;
use Illuminate\Support\Facades\Auth;


class AuthController extends Controller
{
    public function register(Request $request){
        $validator = Validator::make($request->all(), [
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password'=> 'required',
            'c_password'=>'required|same:password'
        ],[
            'email.required' => 'The User Email must be a valid email address.'
         ]);
        if($validator->fails()){
            $response = [
                'success' =>false,
                'message'=>$validator->errors()
            ];
            return response()->json($response,400);
        }
        $input = $request->all();
        $input['password'] = bcrypt($input['password']);
        $user = User::create($input);
       
        $success['token']= $user->createToken('MyApp')->plainTextToken;
        $success['name'] = $user->name;

        $response = [
            'success' =>true,
            'data'=>$success,
            'message' =>'User register successfully',
           
        ];
        return response()->json($response,200);


    }
    public function login(Request $request){
        if(Auth::attempt(['email'=>$request->email,'password'=>$request->password])){
            $user = Auth::user();
            $success['token']= $user->createToken('MyApp')->plainTextToken;
            $success['name'] = $user->name;

        $response = [
            'success' =>true,
            'data'=>$success,
            'message' =>'User login successfully',
           
        ];
            return response()->json($response,200);
        }else{
            $response = [
                'success' =>false,
                'message' =>'Unauthorised Access'
            ];
            return response()->json($response);
        }
    }
}

3) register.vue

<template>
    <h1>Register here</h1>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-sm-6 mt-4">
                <p class="text-danger" v-for="error in errors" :key="error">
                    <span v-for="err in error" :key="err">{{ err }}</span>
                    </p>
                <form @submit.prevent="register" >
                    <div class="form-group">
                        <label for="name">Full Name</label>
                        <input type="text" class="form-control" v-model="form.name" >
                        <label for="username">Login Email</label>
                        <input type="text" class="form-control" v-model="form.email" >
                        <label for="password">Password</label>
                        <input type="password" class="form-control" v-model="form.password">
                        <label for="password">Confirm Password</label>
                        <input type="password" class="form-control" v-model="form.c_password">
                        <button type="submit" class="btn btn-primary mt-3">Submit</button>
                    </div>
                </form>

            </div>
   
        </div>
    </div>
</template>

<script>
    import axios from 'axios';
import { reactive, ref } from 'vue'
import { useRouter } from "vue-router"
export default {
    setup () {
        const router = useRouter();
        let form = reactive({
            name: '',
            email: '',
            password: '',
            c_password: ''
        });
        let errors = ref([])
        const register = async()=>{
            await axios.post('/api/register',form).then(res=>{
                if(res.data.success){
                    localStorage.setItem('token',res.data.data.token)
                    router.push({name:'dashboard'})
                }
            }).catch(e=>{
                errors.value = e.response.data.message
            })
        }
        return{
            form,
            register,
            errors
        }
    }
}
</script>

4) App.js or Routes.js

require('./bootstrap');

import {createApp} from 'vue'
import * as VueRouter from 'vue-router'

import login from './components/login.vue'
import TaskComponent from './components/TaskComponent.vue'
import CCTVComponent from './components/CCTVComponent.vue'
import SubComponent from './components/SubscriptionComponent.vue'
import dashboard from './components/dashboard.vue'
import register from './components/register.vue'

const routes = [
    {path: '/', name:'login', component: login, meta:{requiresAuth:false }},
    {path: '/tasks', component: TaskComponent, meta:{requiresAuth:true }},
    {path: '/cameras', component: CCTVComponent, meta:{requiresAuth:true }},
    {path: '/subs', component: SubComponent, meta:{requiresAuth:true }},
    {path: '/dashboard', name: 'dashboard', component: dashboard, meta:{requiresAuth:true }},
    {path: '/register', name: 'register', component: register, meta:{requiresAuth:false }}
]

const router = VueRouter.createRouter({
    history: VueRouter.createWebHistory(),
    routes,
    linkActiveClass: "active",
    linkExactActiveClass: "exact-active",
})
window.url = ''
const app = createApp({})


router.beforeEach((to,from)=>{
    if(to.meta.requiresAuth && !localStorage.getItem('token') ){
        return { name:'login' }
    }
    if(to.meta.requiresAuth == false && localStorage.getItem('token') ){
        return { name:'dashboard' }
    }
})


app.use(router)

app.mount('#app')


5) Dashboard or Logout 

<template lang="">
    <div class="container">
        <h2>Dashboard :</h2>
        <button type="button" class="btn btn-dark mt-2" @click="logout">Logout</button>
    </div>
</template>
<script>
    import { useRouter } from "vue-router"
export default {
    setup(){
        const router = useRouter();
        function logout(){
            localStorage.removeItem('token');
            router.push({name:'login'})
        }
        return {
            logout
        }
    }
}
</script>
<style lang="">
   
</style>

In API.php add those route

Route::controller(AuthController::class)->group(function () {
    Route::post('login', 'login');
    Route::post('register', 'register');
    Route::post('logout', 'logout');
    Route::post('refresh', 'refresh');
    Route::get('me', 'me');

});


 

6) login.vue

<template>
    <h1>Login here</h1>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-sm-6 mt-4">
                <p class="text-danger" v-if="error" >{{ error }}</p>
                <form @submit.prevent="login" >
                    <div class="form-group">
                       
                        <label for="username">Login Email</label>
                        <input type="email" class="form-control" v-model="form.email" >
                        <label for="password">Password</label>
                        <input type="password" class="form-control" v-model="form.password">
                        <button type="submit" class="btn btn-primary mt-3">Submit</button>
                    </div>
                </form>

            </div>
   
        </div>
    </div>
</template>

<script>
    import axios from 'axios';
import { reactive, ref } from 'vue'
import { useRouter } from "vue-router"
export default {
    setup () {
        const router = useRouter();
        let form = reactive({
            email: '',
            password: ''
        });
        let error = ref('')
        const login = async()=>{
            await axios.post('/api/login',form).then(res=>{
                if(res.data.success){
                    localStorage.setItem('token',res.data.data.token)
                    router.push({name:'dashboard'})
                }else{
                    error.value = res.data.message;
                }
            })
        }
        return{
            form,
            login,
            error
        }
    }
}
</script>

Saturday, September 17, 2022

Monday, September 12, 2022

Vue Live Search

 

export default {
    data() {
        return {
            keyword: null,
            Books: []
        };
    },
    watch: {
        keyword(after, before) {
            this.getResults();
        }
    },
    methods: {
        getResults() {
            axios.get('/livesearch', { params: { keyword: this.keyword } })
                .then(res => this.Books = res.data)
                .catch(error => {});
        }
    }
}

Saturday, September 10, 2022

Thursday, September 8, 2022

Monday, September 5, 2022

Allow remote connection MySQL/MariaDB

 

$ ps -ef | grep -i mysql

You should get the following output:

mysql        595       1  0 04:17 ?        00:00:00 /usr/sbin/mysqld
root        1350    1337  0 04:22 pts/0    00:00:00 grep --color=auto -i mysql

By default, the MariaDB server is listening on localhost only for security reasons. You can check it with the following command:

$ netstat -ant | grep 3306

In the following output, you should see that the MariaDB server is listening on localhost (127.0.0.1):

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN

Configure MariaDB

By default, MariaDB allows connection only from localhost, all connections from a remote server are denied by default.

The first thing you need to do is to configure the MariaDB server to listen to all IP addresses on the system.

You can do it by editing the MariaDB default configuration file /etc/mysql/my.cnf. You can open this file using your favorite text editor:

$ nano /etc/mysql/my.cnf

Change the value of the bind-address from 127.0.0.1 to 0.0.0.0 so that MariaDB server accepts connections on all host IPv4 interfaces.

bind-address = 0.0.0.0

Save and close the file when you are finished. Then, restart the MariaDB service to apply the changes:

$ sudo systemctl restart mariadb

You can now verify the MariaDB listening status with the following command:

$ netstat -ant | grep 3306

If everything is fine, you should get the following output:

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN

Now, the MariaDB server is set up to listen to all IP addresses.

Note : If your are running MySQL Server instead of MariaDB, the main configuration file is located at /etc/mysql/mysql.conf.d/mysqld.cnf. You can change the bind-address by editing this file.

The remaining steps are all the same as for MariaDB.

Grant Access to a User from a Remote System

In this section, we will create a new database named wpdb and a user named wpuser, and grant access to the remote system to connect to the database wpdb as user wpuser.

First, log in to the MariaDB shell with the following command:

$ mysql -u admin -p

Provide your admin (root) password as shown in the Webdock backend and when you get the prompt create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> CREATE USER  'wpuser'@'localhost' IDENTIFIED BY 'password';

Next, you will need to grant permissions to the remote system with IP address 208.117.84.50 to connect to the database named wpdb as user wpuser. You can do it with the following command:

MariaDB [(none)]> GRANT ALL ON wpdb.* to 'wpuser'@'208.117.84.50' IDENTIFIED BY 'password' WITH GRANT OPTION;

Next, flush the privileges and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

A brief explanation of each parameter is shown below:

  • wpdb: It is the name of the MariaDB database that the user wants to connect to.
  • wpuser: It is the name of the MariaDB database user.
  • 208.117.84.50: It is the IP address of the remote system from which the user wants to connect.
  • password: It is the password of the database user.

If you want to grant remote access on all databases for wpuser, run the following command:

MariaDB [(none)]> GRANT ALL ON *.* to 'wpuser'@'208.117.84.50' IDENTIFIED BY 'password' WITH GRANT OPTION;

If you want to grant access to all remote IP addresses on wpdb as wpuser, use % instead of IP address (208.117.84.50) as shown below:

MariaDB [(none)]> GRANT ALL ON wpdb.* to 'wpuser'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

If you want to grant access to all IP addresses in the subnet 208.117.84.0/24 on wpdb as user wpuser, run the following command:

MariaDB [(none)]> GRANT ALL ON wpdb.* to 'wpuser'@'208.117.84.%' IDENTIFIED BY 'password' WITH GRANT OPTION;

Configure Firewall

If your MariaDB server is configured with the UFW firewall (which is by default on all Webdock servers) then you will need to allow traffic on port 3306 from the remote system.

You can grant access to the remote system with IP 208.117.84.50 to connect the port 3306 with the following command:

$ sudo ufw allow from 208.117.84.50 to any port 3306

If you want to grant access from any IP address you would use the following command:

$ sudo ufw allow 3306

Next, reload the firewall with the following command:

$ sudo ufw reload

Once you are finished, you can proceed to the next step.

Test Connection from Remote System

At this point, the MariaDB server is configured to allow connection from the remote system with IP address 208.117.84.50. Now, it's time to test the connection from the client system to the MariaDB server. Here we show how to do this on the command line in Linux, but you can also test this from your desktop (if not on Linux) by utilizing any MySQL remote manager such as the ones listed in the introduction to this article.

First, you will need to install the MariaDB Client package in the remote system. You can install it with the following command:

$ sudo apt-get install mariadb-client -y

Once the installation is completed, connect to the MariaDB server by running the following command on the remote system:

mysql -u wpuser -h 45.148.28.101 -p

Check Serial Number

 wmic bios get serialnumber