How to temporarily bypass content security policy CSP headers

Browser: Firefox
Extension: Mod Headers

https://addons.mozilla.org/en-US/firefox/addon/modheader-firefox/

Add A CSP policy like this:
Use “parse” option and paste this:

default-src *; script-src 'unsafe-inline' 'unsafe-eval' *; style-src 'unsafe-inline' *; img-src * blob: data:; font-src * data:;

To create a Content Security Policy (CSP) header that allows everything, you would use the 'unsafe-inline' and 'unsafe-eval' sources for scripts and styles, and the * wildcard to allow all other sources. This setup is generally not recommended for production environments because it exposes your site to potential security vulnerabilities. However, it can be useful for development or testing purposes. Here’s an example of what this CSP header might look like:

Content-Security-Policy: default-src *; script-src 'unsafe-inline' 'unsafe-eval' *; style-src 'unsafe-inline' *; img-src * blob: data:; font-src * data:;

This header includes:

  • default-src *;: Allows all sources for all types of content except those that have been explicitly specified by other directives.
  • script-src 'unsafe-inline' 'unsafe-eval' *;: Allows all scripts, inline scripts, and usage of eval().
  • style-src 'unsafe-inline' *;: Allows all styles and inline styles.
  • img-src * data:;: Allows all image sources and data URIs.
  • font-src * data:;: Allows all font sources and data URIs.

Remember, using this policy removes a significant part of the CSP’s protection. It is like not having a CSP at all because it allows resources to be loaded from anywhere, inline scripts and styles to be executed, and eval() to be used, which can lead to security vulnerabilities such as Cross-Site Scripting (XSS) attacks. Always aim to restrict your CSP to the minimum necessary sources for your application to function.

How to fix CORS error for amazon s3 files and resources?

Go to bucket

In the bucket permissions tab

There is a section for CORS, put the following in it and save.

[
    {
        "AllowedOrigins": [
            "*"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "MaxAgeSeconds": 3000,
        "ExposeHeaders": [
             "Content-Range",
             "Content-Length",
             "ETag"
        ],
        "AllowedHeaders": [
            "Authorization",
            "Content-Range",
            "Accept",
            "Content-Type",
            "Origin",
            "Range"
        ]
    }
]

centos web panel – vhost templates for proxying websocket traffic

http://wiki.centos-webpanel.com/webservers-vhost-templates

Templates location: /usr/local/cwpsrv/htdocs/resources/conf/web_servers/
– Folder main contains main configuration for WebServers
– Folder vhosts contains vhosts configuration for domains (this is what you need)

How to create a template file
The easiest way to do that is to simply copy an existing file and then edit a new file you have created.
Note that you need to have .tpl and .stpl files (tpl is for http and stpl is for https version)

Let’s do one example for apache vhost with nginx

cd /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/nginx/
cp default.tpl my-template.tpl
cp default.stpl my-template.stpl

Now you can edit these newly created template files.

Template folders explained
List from folder: /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/

httpd = apache templates
nginx = nginx templates
varnish = varnish templates
php-fpm = php-fpm service templates (used for all php-fpm versions)

add a block

map $http_upgrade $connection_upgrade {
	default upgrade;
	'' close;
}

also add these inside “location /” block

		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $connection_upgrade;
		proxy_set_header Host $host;

How to generate a patch with edited files? How to zip latest committed changes only

zip archive.zip $(git diff-tree --no-commit-id --name-only -r latest-commit-id)

Reference: https://stackoverflow.com/a/42971972/2229148

sometimes you need all the files that were updated so you can patch an external app which doesnt uses same git project or many other scenarios in which we need a zip or tar of those files. Use the above command to do so

There is a smarter way also, if you want all the changes from last 5 commits, use the command like this:

zip archive.zip $(git diff-tree --no-commit-id --name-only -r HEAD~5 HEAD)

Jenkins auto deploying flask in test env with last build process kill and pipenv

#!/bin/sh
cd $WORKSPACE
export PY=/usr/local/bin/python3
export FLASK_RUN_PORT=4005
$PY -m pip install pipenv
$PY -m pipenv install --dev
export VENV_HOME_DIR=$($PY -m pipenv --venv)
source $VENV_HOME_DIR/bin/activate
flask db upgrade
flask populate-initial-data
export BUILD_ID=XYZapi
$WORKSPACE/killlastbuild.sh
flask run &
deactivate

killlastbuild.sh can have anything inside it depending upon your project requirements. I put 2 process killers to kill background-ed daemon processes from previous build command

ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9
ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9

How to solve MySQL server gone away error Maria Db update on cPanel and WHM?

This is related to new MariaDb upgrade from 10.1.41 to 10.1.42 and also for servers which were updated from 10.2.27 to 10.2.28

Go to solution ( Special Thanks to @Valetia )

You will see errors in following formats/messages:

  • No file or input found
  • MySQL Server has gone away
  • Connection to MySQL Server failed
  • sqlstate[hy000]: general error: 2013 lost connection to mysql server during query
  • General error: 2006 MySQL server has gone away
  • ERROR 2006 (HY000): MySQL server has gone away
  • ERROR 2013 (HY000): Lost connection to MySQL server during query

Log files (/var/lib/mysql/$hostname.err) will have or can have any of these errors:

  • assertion fail /home/buildbot/buildbot/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/mariadb-10.2.28/storage/innobase/dict/dict0dict.cc line 1467
  • the resulting row size is greater than maximum allowed size (8126) for a record on index leaf page
  • stack_bottom = 0x0 thread_stack 0x49000 mysys/stacktrace.c:268(my_print_stacktrace)[0x5564e62807bb] sql/signal_handler.cc:209(handle_fatal_signal)[0x5564e5d4b4f5]

Other Symptoms:

/etc/init.d/mysql start
Starting MySQL/etc/init.d/mysql: line 159: kill: (10704) – No such process
[FAILED]


Solution:

yum downgrade MariaDB-* -y
whmapi1 update_updateconf RPMUP=manual UPDATES=manual

(run as root #)

This will downgrade MariaDb installation to previous version
Line 2 will cancel automatic update on WHM/CPanel installations

If you are not using WHM, use line 1 only OR you can downgrade the repository individually too

yum downgrade MariaDB-server MariaDB-common MariaDB-shared MariaDB-client MariaDB-compat MariaDB-devel

References:

A basic time difference calculator in google script js

In your Google Sheet, Click “Tools” and then choose “Script Editor“. Put the code given below. Don’t forget to use function in your result column as “=dodiff(cell1,cell2)

function dodiff(a, b) {
    if (a)
        a = fix(a);
    if (b)
        b = fix(b);
    if (Array.isArray(a) && Array.isArray(b)) {
        if (b[1] > a[1]) m = b[1] - a[1];
        else {
            m = b[1] - a[1] + 60;
            b[0]--;
        }
        if (b[0] >= a[0]) h = b[0] - a[0];
        else {
            h = b[0] - a[0] + 12;
        }
        m = m / 60;
        return (h + m).toPrecision(4);
    }
}

function fix(a) {
    if (a)
        x = a.toString().replace(" ", '').replace("am", "").replace("pm", "").replace("PM", "").replace("AM", "");
    x = x.split(":");
    x[0] = parseInt(x[0]);
    x[1] = parseInt(x[1]);
    return x;
}

How to reverse the ids in a mysql table column without breaking primary key constraint?

Let me explain the problem scenario: Let us assume we have a table with 4 columns in it out of which 1 is PRIMARY column and rest 3 contain some data.

What we want to do is to reverse the primary key IDs for that data keeping the rest of data intact. It is like shifting the first row to end and moving last row to starting.

Initial Data

idnameemailanything
1jacobwhateverhow to reverse
3nathanwhosoeverisnathanids in mysql table column
4jagmohanidontknowjagmohanwithout breaking
8monicaiamsexyprimary key constraint
9batmanidontexistinrealworldi am batman

Data after update

idnameemailanything
9jacobwhatever how to reverse
8nathanwhosoeverisnathan ids in mysql table column
4jagmohanidontknowjagmohan without breaking
3monicaiamsexy primary key constraint
1batman idontexistinrealworld i am batman

Dude, you are just reversing the column, what is so tough in this?

So, this seems simple to reverse an array if isolated by key “id“. But you have to understand that this column is the primary key. So if you run a command to change id for “jacob” to “9“. It will give you error: “Duplicate entry for id 9

So here is my proposed solution, I start with pair of first and last row and then swap them. Then swap second and second last row. and So on…

If total rows are odd, we will be left with 1 row which does not need correction because it will already be the middle row.

If total rows are even, we would swap middle two rows too.

Here is my solution in PHP

$possible_group_id="3";
$ai=12720; //can be any high int which does not exist in column `id` yet
$q="select id,email from table_name where `possible_group_id`=$possible_group_id order by id asc";
$r=mysqli_query($f,$q);
$row_collection=[];
$ct=[];
while($row=mysqli_fetch_row($r))
{
    $row_collection[]=$row;
    $ct[]=$row[0];
}
$pt=array_reverse($ct);
$size=count($row_collection);
for($i=0;$i<$size;$i++)
{
    $row_collection[$i][2]=$pt[$i];
}
echo "start transaction;<br>";
foreach($row_collection as $k=>$v)
{    
    if($k < floor($size/2)){
    echo 'UPDATE `table_name` SET `id`='.$ai.' WHERE `email`="'.$row_collection[$size-$k-1][1].'";<br>';
    echo 'UPDATE `table_name` SET `id`='.$v[2].' WHERE `email`="'.$v[1].'";<br>';
    echo 'UPDATE `table_name` SET `id`='.$row_collection[$k][0].' WHERE `email`="'.$row_collection[$size-$k-1][1].'";<br>';}
    else break;
}
echo "commit;<br>";

It would output this:

start transaction;
UPDATE `table_name` SET `id`=12720 WHERE `email`="idontexistinrealworld ";
UPDATE `table_name` SET `id`=9 WHERE `email`="whatever";
UPDATE `table_name` SET `id`=1 WHERE `email`="idontexistinrealworld ";
UPDATE `table_name` SET `id`=12720 WHERE `email`="iamsexy";
UPDATE `table_name` SET `id`=8 WHERE `email`="whosoeverisnathan";
UPDATE `table_name` SET `id`=3 WHERE `email`="iamsexy";
commit;

How to remove files with “No Content Changes Found” in Git Desktop

There are 3 possible ways git can find a file changed (even if you didn’t change it)

  1. Line Endings have changed
  2. File permissions have changed
  3. Bonus: if modification time has changed

for first case try these settings in bash shell. One of these will fix it for you

$ git config core.eol
$ git config core.autocrlf
$ git config core.safecrlf

For second case, here is the flag

git config core.filemode false

Bonus One: If Modification time was changed

If your working tree has files with updated “last modification time” and you see a huge list of files with “no content changes found”, try this:

git add .
 // ^ dont use . [DOT] if you want to fix for particular sub-folder

You can do git add for all affected files, after that it stops displaying them as modified in git status (and doesn’t actually stage them for commit if there are no changes).

References: https://stackoverflow.com/a/37221298/2229148