validationRegex to accept/validate listed characters

5 to 16 alpha or alphanumeric to include special characters such as:
◦*Hyphen ( – )
◦*Slash ( / )
◦*Backslash ( )
◦*Asterisk ( * )
◦*Dollar Sign ( $ )
◦*Period ( . )
◦*Ampersand ( & )
◦*Comma ( , )
◦*Number Sign ( # )
◦*Open Parenthesis ( ( )
◦*Closed Parenthesis ( ) )
◦*Colon ( : )

Current code example:

PASSWORD: {id: password, label: PASSWORD, name: PASSWORD, validationRegex: ^[a-zA-Z0-9]+$, minLength: 5, maxLength: 16, errorMsg: message}

Go to Source
Author: Marcus

ubuntu stuck on login page – can’t login with keyboard

I don’t know why but my ubuntu session got stuck at the login page suddenly and I can’t ge through any longer. When starting the VM, i get the following screen :

enter image description here

I’ve tried CTRL+ALT+F1 and CTRL+ALT+F7 but no luck… my keyboard and mouse aren’t working. I’ve also tried CTRL+ALT+F3 and ran

sudo apt install --reinstall ubuntu-desktop

sudo apt install --reinstall ubuntu-session

but still the same.

enter image description here

I’m wondering what’s wrong and what I can do. If ever it is not possible to recover my session, is there a way to create another VM with the disk of this one… i’d hate to loose everything.

Go to Source
Author: Boris M

Is this an anti-pattern to have a service have both APIs and listening to events?

I am planning to make a service which will have simple REST APIs and will have a database in backend. I also wanted to add a logic to listen to notifications emitted by other service and there is some business logic which will update the row in the database.

For updating the database row from Notifications, I can think of 2 approaches:

  1. Should I create a API which is kind of internal to just used by service and this listener process calls this API instead of directly updating the database?

  2. Listener process directly updates the service.

I can see some pros and cons of each approach. In Approach 1, we are adding a REST API unnecessarily which is never used by clients.

In Approach 2, we are giving one backside way to reach the database instead of all the requests coming from REST API.

Can someone help me here to tell if one of them is anti-pattern and which one is better to use?

Go to Source
Author: hatellaCollege

How can I install more than one Desktop Environment in my Ubuntu without damaging the system?

How can I install more than one Desktop Environment in my Ubuntu without damaging the system? I want just to try those desktop. I know I can install them by sudo apt install kubuntu/xubuntu/lubuntu-desktop . But it will remove my existing Desktop Environment, right? I want that whenever I want to change the Desktop Environment, I will log out and log in to that. Is it possible to do that? Don’t say to download ISO image of Kubuntu, Xubuntu, Lubuntu as I want to see them in my current installation.

Go to Source
Author: Akib Azmain

What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler?

Q: What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler?

Q: Am I calling the php function correctly?


Page Element
The user clicks a button.

Action:
The click should connect to an external server using the following params:

  1. User Name 2. IP Address 3. Port 4. Public Key 5. Service

Purpose:
Send an vote string (from host A) to an external Gaming server (host B).
I do not need to update any wordpress content.

WordPress Version: 5.4.1
I put my custom php code into “/wp-contents/plugins/my-plugin/votifier.php”

I made sure the custom plugin is activated.

I have WordPress in Debug mode. i.e. Debug mode is true.

The Button

<div id="frm_field_61_container">
<button type="button">Try it</button>
</div>

WordPress JQuery with AJAX

jQuery(document).ready( function($) {
 $("#frm_field_61_container").click(function(){

      jQuery.ajax({

         type : "post",

         dataType : "json",

         url : myAjax.ajaxurl,

         data : {    action: "my_vote_count"
                    ,username: $('input[name="item_meta[59]"]').val()
                    ,key: $.trim($("#field_yjr62").val())
                    ,ip: $('input[name="item_meta[40]"]').val()
                    ,port: $('input[name="item_meta[42]"]').val()
                    ,service: "Votifier"
                },

        success:    function(data,status,xhr){
                    alert("Data: " + data);
                    alert("Status: " + status);
                    alert("xhr: " + xhr);
                }
      });   
   });
});

My Custom PHP Script

<?php


function mainVotifier($username, $public_key, $server_ip, $port, $service_name) {

define( 'VOTE_FORMAT', 'VOTEn%sn%sn%sn%dn' );
define( 'PUBLIC_KEY_FORMAT', '-----BEGIN PUBLIC KEY-----n%sn-----END PUBLIC KEY-----' );

$key    = wordwrap($public_key, 65, "n", true);
$key    = sprintf(PUBLIC_KEY_FORMAT, $key);


  if (php_sapi_name() !== 'cli') {
            //Detect proxy and use correct IP.
            $address = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
        } else {
            //Script is run via CLI, use server name.
            $address = $_SERVER['SERVER_NAME'];
        }

    $data = sprintf(VOTE_FORMAT, $service_name, $username, $address, time());
    openssl_public_encrypt($data, $crypted, $key);
    $socket = @fsockopen($server_ip, $port);

    if ($socket) {
        if (fwrite($socket, $crypted)) {
            fclose($socket);
            return true;
        }
    }

}

?>

/* ===== WP_ENQUEUE SCRIPTS ==== */

/* ===== JQuery Ajax Script to call votifier.php ==== */
add_action( 'wp_enqueue_scripts', 'my_script_enqueuer' );
function my_script_enqueuer() {

   wp_enqueue_script( 'my_voter_script',  plugins_url('sendvote.js', __FILE__), array( 'jquery'),   '1.0', true);

   wp_localize_script( 'my_voter_script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));

}

/* ===== My AJAX Handler ==== */

/* add_action( 'wp_ajax_nopriv_my_vote_count', 'my_ajax_handler' ); */ 
add_action( 'wp_ajax_my_vote_count', 'my_ajax_handler');
function my_ajax_handler() {

/*  check_ajax_referer('votifier_response_key'); */

    $username       = $_POST["username"];
    $public_key     = $_POST['key'];
    $server_ip      = $_POST["ip"];
    $port           = $_POST["port"];   
    $service_name   = $_POST["service"];

   echo "mainVotifier("" . $username . "", "" . $public_key . "", "" . $server_ip . "", "" . $port . "", "" . $service_name . "");";


    wp_die(); // All ajax handlers die when finished

}

Console Results

The console results are good, but the other server is not responding.
I tested the PHP code locally from my personal computer and Server B is responding.


Request URL:https://bestminecraftserverlist.com/wp-admin/admin-ajax.php
Request Method:POST
Remote Address:192.169.170.42:443
Status Code:
200
Version:HTTP/2

Go to Source
Author: ScottUSA

How to add PPA source for this gcc-10 package?

I know that to add a PPA, we use:

add-apt-repository ppa:user/ppa-name

But for this package : gcc-10, what is user and ppa-name?

I have tried:

add-apt-repository ppa:ubuntu/gcc-10
add-apt-repository ppa:gcc-10
add-apt-repository ppa:focal/gcc-10

They all fails with:

user or team does not exist.

Go to Source
Author: kilasuelika

How can I ensure the client and server both have access to all API calls in use?

On multiple occasions, we’ve deployed frontend code to production only to find out the backend (REST or GraphQL) hasn’t shipped their side yet. Worse yet, we expectedly find out a param name changed which may throw an error. Another example: the backend removes an API thinking that clients no longer use the removed API and the frontend crashes. If any layer of communication between frontend and backend breaks down, then we may end up with catastrophic errors.

I think the “best solution” is to use a tool like Cypress or Codecept to create a suite of integration tests which checks every API call the frontend may use. Sadly, that’s a heavyweight solution that requires significant upfront investment in developer time.

Anyway, I’m looking for simple solution to this problem. Maybe something that checks affected APIs when the frontend opens a PR and/or something that checks the frontend repo when the backend deploys to production.

Any ideas or experience solving this problem?

Go to Source
Author: Brandon

Synchronize time among several concurrent users

I’m using Google Sheets to come up with a quick Jeopardy-style game with an improvised buzzer. All players type in the timestamp shortcut (Ctrl+Shift+0) into a cell and the lowest value is presumed to buzz in first, but we’ve realized that some people are a few seconds, even minutes, ahead (or behind). We’ve diagnosed that it’s related to each person’s time set in each’s OS.

Is there a way to sync times through the Sheets app? Or at the very least determine who input first?

I’ve tried to remedy with a series of nested array formula with if and count statements, but to no avail. Any help would be appreciated. Otherwise I’m going to set my OS’s time to 1899 and smoke everyone.

Go to Source
Author: Rudy A

Need help with .htaccess redirection for WordPress websites

I am changing the domain of my website.

But, I am struggling with the domain redirection. I need to implement this wildcard redirection.

So that I visit.

https://www.oldomain.com/page1

It should go to

https://newdomain.com/page1

Note: The new domain is without www.

Can anyone help me how to implement this?

Go to Source
Author: Nirmal Kumar

ANSWER

A 301 Redirect, or permanent redirect, is recommended when dealing with something similar to this one.

If you just want to hard redirect anything hitting oldomain.com to newdomain.com then a simple Redirect should do like so:

<VirtualHost *:443>
	ServerName oldomain.com
        ServerAlias www.oldomain.com
	Redirect 301 / https://newdomain.com
</VirtualHost>

The above example is also something that you will want to write in a server config like httpd.conf but not in a .htaccess file somewhere on your site directory. It is also clumsy since your old site’s pages – e.g https://www.domain.com/some/page/123 – will redirect only to https://newdomain.com which is the index page of the site.

So the other option would be Rewrite. It is also in case you don’t have root access to the server, and/or other sites that are not yours are sharing it as well. It would look like the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301,NC]

The above considers whether the request is written with or without the www subdomain in it. The old links or pages will also get carried over to the new one.

How is a source RPM different from unpacking an RPM with rpm2cpio and cpio?

I am attempting to understand the use of a .srpm aka “source rpm” Red Hat Package Manager package. From what I understand so far, a .srpm is different from a standard .rpm in that it provides the source code and is commonly used during development. I am puzzled on why this is useful because if I run rpm2cpio ./myrpm-1.1-1.x86_64.rpm | cpio -idmv, I can still view the source code. As I understand, even standard RPMs pull down a .tar.gz/bz file which contains the source, and eventually builds this. Could you please clarify how source RPMs are different and why I would want to use one?

Go to Source
Author: the_endian

how to get specific character from a log file in linux

ANSWER

Assuming that (1) the log file looks as it is AND (2) it is multi-line, then a simple Linux grep command like below should work (even with multiple lines of that line you’re looking for in one log file):

INPUT | Tested it on dummy logs from sample

COMMAND | grep -Pn "^Id\s+:\s+(.*)$" *.log

OUTPUT |

log101.log:2:Id : UN123P

log102.log:2:Id : HELLO321

log103.log:2:Id : STUDE23P

log104.log:2:Id : Lorem

log104.log:7:Id : IPsum

log104.log:12:Id : Dolor

have a log file , having multiple contents inside the file like and example below is the content of U123.log . I have n number of logs..

Accepted password for hoover from 10.0.2.2 port 4792 ss

Id : UN123P 

ID_MTCH : UnixProduction

Accepted password for hoover from 10.0.2.2 port 4792 ss

Accepted password for hoover from 10.0.2.2 port 4792 ss

Is there any we can fetch “Id : UN123P” as an output of linux command. We have some 1000’s of logs and from all the logs , trying to fetch the value only starts with ID : and output as “Id : UN123P”

Pls suggest

Go to Source
Author: Arya

no wifi connection with ubuntu

no wifi connection with ubuntu

I recently purchased a used Samsung Galaxy Book and after experiencing the Win 10 dual booted with Ubuntu 20.04.
I have been researching the forums but I am still unable to make the wifi work or even find any signals.
As a last resort I have also installed Connman hoping it would find the connection but no luck.
Some of the information is listed below
Thank you
Code:

ubuntu@ubuntu-Galaxy-Book-12:~$ rfkill list
0: hci0: Bluetooth
Soft blocked: no
Hard blocked: no

*-network
description: Network controller
product: QCA6174 802.11ac Wireless Network Adapter
vendor: Qualcomm Atheros
physical id: 0
bus info: pci@0000:01:00.0
version: 32
width: 64 bits
clock: 33MHz
capabilities: bus_master cap_list
configuration: driver=ath10k_pci latency=0
resources: irq:131 memory:df400000-df5fffff
*-network
description: Ethernet interface
physical id: 1
bus info: usb@2:4.2.2
logical name: enx00909e9dd80e
serial: 00:90:9e:9d:d8:0e
size: 1Gbit/s
capacity: 1Gbit/s
capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=ax88179_178a duplex=full ip=192.168.1.64 link=yes multicast=yes port=MII speed=1Gbit/s

ubuntu@ubuntu-Galaxy-Book-12:~$ sudo ifconfig wlan0 up
[sudo] password for ubuntu:
wlan0: ERROR while getting interface flags: No such device
ubuntu@ubuntu-Galaxy-Book-12:~$ ip link set wlan0 up
Cannot find device “wlan0”
ubuntu@ubuntu-Galaxy-Book-12:~$ iwconfig
enx00909e9dd80e no wireless extensions.

lo no wireless extensions.

Go to Source
Author: Smokeyone