pdf file does not open in a new tab, It keeps downloading.

I had recently encountered an issue with a pdf that keeps downloading.

We wanted the pdf to open in a new tab.

  1. This is a href link to a flask endpoint.
  2. Clicking on the link keeps make a call to an api and we get a pdf file as response. \
  3. The pdf file does NOT open in a new tab. Have tried target = “_blank” for href.
  4. Have also tried javascript window.open.
  5. Using the window.open , firefox does open the pdf in new tab.
  6. In chrome, the file is downloading all the time. Cant get it to open in new tab.

After much research, it appears, the api endpoint is adding a header “Content disposition: attachment”.

Once this header is deleted, the pdf started opening in a new tab!

How to access dictionary elements using dot notation in python?

This is how we define a dictionary in python:

dict1={'name':'raj', 'age':99 }

to access the elements of the dictionary, we do this:

dict1['name'] and
dict1['age']

What if we want to access the elements of the dictionary like this:

dict1.name

This will fail. We can easily fix this by creating a pointdict class .. like so:

class pointdict(dict):
    def __getattr__(self,name):
        try:
            return self[name]
        except KeyError:
            return None

now, we can convert our dictionary as a pointdict like so:

dict2=pointdict(dict1)

and we can use it like this:

dict2.name

“`


Powershell script to prevent Windows Screen lock

I have used this simple powershell script to prevent Windows Screen lock.


param($minutes = 300)
write "….Screen will be awake for …$minutes"
$myshell = New-Object -com "WScript.Shell"
for ($i = 0; $i -lt $minutes; $i++) {
Write-Output "….screen will be awake for " ($minutes-$i)
Start-Sleep -Seconds 60
$myshell.sendkeys("{F15}")
}

Screen Recording in Ubuntu 20.04

Gnome desktop that gets installed with Ubuntu 20.04 comes with a screen recording feature.

CTRL + ALT + SHIFT + R

will start the screen recording.

The recording will be done only for 20 seconds.

We want to change this so it records till be stop recording.

How to change this? run this command:

gsettings set org.gnome.settings-daemon.plugins.media-keys max-screencast-length 0


How to stop recording?
CTRL + ALT + SHIFT + R will do the trick.

Where are my recording stored?
They are stored in Videos folder.

Shutdown and Startup scripts

I want my cloud instances to shutdown at a particular time. How to do that?
Simple, edit the file
sudo vi /etc/crontab

and add a line

00 16   * * *   root    shutdown -h now 

This will shutdown your server everyday at 16 PM server time.

I need to run a few processes at startup. How to do that?

Login as root using the commands
su
or
sudo su

and then edit the crontab

crontab -e

Add the scripts you need to add towards the end.

One word of caution, if you are adding the scripts here, be aware that the network services and other key elements of the os may still be starting up.

So, its better to add a sleep command.

Here is how my crontab looks like:

OWASP ZAP Security Scanning

We installed docker on ubuntu 18.04 ubuntu instance.

Install a zap docker image:
docker pull owasp/zap2docker-stable

Run the owasp zap image as a daemon:
docker run -d -u zap -p 8080:8080 -p 8090:8090 -i owasp/zap2docker-stable zap-webswing.sh

Remember to open the ports 8080 and 8090 in your server.

Once the ports are open, you may access the zap using the urls:
http://ec2-18-217-117-172.us-east-2.compute.amazonaws.com:8080/zap/


In the UI that displays, select the quick start tab,
In the url to attack, mention the site

Click on Attack and explore the results!

Docker installation on ubuntu 18.04 aws instance

Steps to install Docker in ubuntu 18.04 ( or any version of Ubuntu)

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –

Now, we need install docker. We know our server is ubuntu 18.04. However, we need to know the name of the ubuntu release – like trusty / bionic etc. How to find that?
This command will help with this:
cat /etc/lsb-release

We now know its bionic, and this is the command to install docker:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache-policy docker-ce
sudo apt install docker-ce


check is docker has been installed:
sudo systemctl status docker

Add the current user to the docker group:
sudo usermod -aG docker ${USER}

check the docker versions:
docker -v
docker info



Connect to Google Cloud Instance ( Unix) using Mobaxterm or putty.

Using puttygen or equivalent feature in mobaxterm ( Tools-> MobaKeyGen ) , generate RSA key, make sure you select the right options. like so:

Save the private key to a file in your local machine. Save the public key also in the local machine.

Open Google instance, and paste the public key at the right place.


Start your instance.

While connecting to the instance, use the private key to connect.

You will see the error: “Server refused our key”

Basically, you need to add the private key to the authorized keys.
Login to the instance. Edit the file $HOME/.ssh/authorized_keys

Add the private key in a new line and save.

Make sure the premission of the file are

rw-r–r–

Now, you may login to the instance without an error.

When the server restarted, the ip changed However, i kept trying the old IP and it was showing this error: “No supported authentication methods available (server sent: publickey)”.
Make sure you are connecting to the right IP address.

You could get that error message for other reasons aswell . this has been well documented in this blog:
https://medium.com/@omar.merghany95/how-to-solve-disconnected-no-supported-authentication-methods-available-server-sent-publickey-eb012ffbd159

Design a site like this with WordPress.com
Get started