2018-07-16

Service worker and 401 authorization

What happens


  • The website area (/admin) is protected by an `htpasswd` authorization (Apache: AuthType Basic, Require valid-user, etc.).
  • A "standard" service worker script is loaded at the home page, doing its usual stuff (install, fetch, cache).
  • When you go to the protected page, you are not asked for the user/password, but see the "Not Authorized" message immediately.
  • If you clear the service worker (in Chrome, F12 - Application - Clear storage), you can enter the admin area.

One way to cure

Your service-worker.js script probably has a piece of code that looks like:

self.addEventListener('fetch', event => {
    // Let the browser do its default thing
    // for non-GET requests.
    if (event.request.method !== 'GET') {
        return;
    }

Add the following lines immediately after that part:

    // Exclude admin panel.
    if (0 === event.request.url.indexOf("https://www.my-site.com/admin")) {
        return;
    }

It should help.

2018-06-21

Currency conversion in Google Sheets using the GoogleFinance function

Formula:


[A2] --> =INDEX(GoogleFinance("CURRENCY:USDCAD","price",A2),2,2)

Example:




2018-03-06

ACE Editor: submit, beautify and minify

A code example to use ACE Editor in HTML form, submit minified JS and CSS and beautify it.
This is just a sketch. The server side is not shown.

Developed for use in the WPGlobus Multilingual WordPress plugin's options panel.



2018-01-04

Cygwin: Permissions 0660 for '~/.ssh/id_rsa' are too open.

Environment:

  • MS Windows 8.1
  • Cygwin 64bit
  • ssh keys copied from somewhere and placed to ~/.ssh/

Problem:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0660 for '~/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: ~/.ssh/id_rsa

Did not work:

  • chmod 600 id_rsa
  • chmod 700 .ssh
  • Playing with Windows security panels
  • Setting group to SYSTEM
  • Everything else

Solution:

Found on Vineet Gupta's blog http://vineetgupta.com/blog/cygwin-permissions-bug-on-windows-8

chgrp Users id_rsa
chmod 600 id_rsa

Now, all works. Thank you, Vineet!

2017-01-15

Cannot disconnect USB drive? Close the Task Manager!

Excuses
Yes, I am still using a WD "Passport" for downloaded movies. Copy on PC and connect the drive to TV's port. Yes, I know that I can stream. Yes, I have a good router. Never mind :-)
Oh, yes, I am still using Windows. Dear Mac users, I love you, too, but not as much as I love Bill Gates :)

<jokes aside>

Problem
"Windows cannot disconnect your USB drive". Close the programs, blah-blah-blah.

Obvious
Well, closing File Manager's windows surely helps.
Waiting a bit after the file is "copied" helps, too. I guess, some portions of it are not flushed to the drive yet (who knows, it's Windows).

Who cares?
My TV. Sometimes. Just does not see the files if the drive wasn't properly dismounted.

Not so obvious
The TASK MANAGER!
I believe, it monitors the disk activity. So, shut it down.

Not obvious at all
Atlassian's SourceTree.
Why? Who knows. I do not want to know. These days, I am using PHPStorm's Git or a command line. SourceTree is kept for some strange cases when I am not 100% sure what I just did... :-)

</off to watch>

2016-11-27

ln -s on Windows? Use mklink for symbolic links !

I needed to make Apache server seeing a folder via a symbolic link - on MS Windows. The standard Windows' shortcuts look like links, but Apache does not see them...

Apparently, there is a way to make REAL symbolic links under Windows. (Must run command prompt as administrator).

For example:

mklink C:\etc\hosts C:\Windows\System32\Drivers\etc\hosts

results in

C:\>dir c:\etc

2013-01-02  21:37    <DIR>          .
2013-01-02  21:37    <DIR>          ..
2013-01-02  21:37    <SYMLINK>      hosts [C:\Windows\System32\Drivers\etc\hosts]


The syntax for folders is:

mklink /D linkName target



Note: do not forget the drive letter (C:), or the link may not work in some situations.

Read more:



2016-09-06

"Disallow ia_archiver" does not remove pages from archive.org

The experiment (September 2016):

- A site exists since 2008 and has many snapshots on archive.org.

- The FAQ says:
You can exclude your site from display in the Wayback Machine by placing a robots.txt file on your web server that is set to disallow User-Agent: ia_archiver.
- Made the robots.txt as follows:

User-agent: ia_archiver
Disallow: /

- In a couple of days, indeed, instead of the site snapshots, a message saying that the archive is not available because of the robots.txt instruction. Success!

- Removed the robots.txt.

My expectations:

The old pages had disappeared from the archive completely, but the current one is now being crawled and included into the archive.

The reality:

All the old pages are back!

The bottom line:

Using the robots.txt, one can instruct Wayback Machine to stop displaying the site (which is exactly what the FAQ says!) but not to remove the pages from the  archive.