amnuts / opcache-gui

A clean, effective and responsive interface for Zend OPcache
1.23k stars 198 forks source link

Add react *.js to the project, instad of load from external - CSP support #84

Closed GAS85 closed 2 years ago

GAS85 commented 2 years ago

Hey, like your product much. I have server with CSP enabled and opcache UI will not be opened without whitelisting of unpkg.com. Is this possible to add js files to the project so that it will be loaded from the same FQDN as UI? Or is there is an easy way to re-configure it locally? grafik

amnuts commented 2 years ago

Hi @GAS85,

One of the things I've always tried to do is keep it as only requiring one file. Even though there are multiple files in the repo, once it's built it's all in the one index.php, so I'm not keep on having separate js files. Ideally I'd not want to embed those js files into the finished result, either, as I'll always have to maintain the current version rather than letting unpkg.com do it for me.

There's nothing stopping you doing that, though. With a couple small tweaks to the template you should be able to do what you need.

For example, what you could possibly do is fork the repo and in your fork add the js files to the top-level. Then update build/template.phps so that the three script tags point to your local copies. Then when you build the index.php file (instructions at https://github.com/amnuts/opcache-gui#changing-the-look) you'll use your local files.

This should also keep your changes to a minimum, so that whenever I make changes to the origin you can replay your changes on top of them pretty easily.

As I'm writing this, I'm thinking that it shouldn't be too difficult for me to add that functionality into the little build script... 🤔 I'm a little busy for the next week or two, but I'll see if I can come up with anything. In the meantime, give the idea a go yourself and see if it helps you out.

GAS85 commented 2 years ago

Basically I solved it by simple script - externalJSDownloader.sh, but somehow github is slow now and I could not create any commit or MR.

It should be run once, will download JSs and replace all links directly in index.php to the relative local one. No rebuild required. It should be executed under web server user, otherwise file ownership must be updated afterwards.

#!/bin/bash

# By Georgiy Sitnikov.
#
# AS-IS without any warranty

file="index.php"

getJSLinks="$(grep "script src" $file | awk -F'["]' '{ print $2 }')"

echo "Backup $file to $file.origin"
cp $file $file.origin

while read JSLinks; do

    JSName="$(echo $JSLinks | awk -F'[/]' '{ print $NF }')"
    echo "Downloading $JSName from https:$JSLinks"
    curl -fsSL -m 10 https:$JSLinks -o $JSName

    echo "Replacing $JSLinks with $JSName in $file"
    sed -i "s,$JSLinks,$JSName," "$file"

done <<< "$getJSLinks" # Read from variable

echo "Done."
exit 0
amnuts commented 2 years ago

Nice one! I took a basically the same approach, but wanted to keep it all the PHP that was already there, so am doing it in the build.php file. I think for the most part, people wouldn't need to change it anyway, but if needs be it can be run with php build.php -l and it essentially does the same thing your great bash script does.

Currently in branch working/3.4.0, but probably going to be merged into master soon.

amnuts commented 2 years ago

Now merged into master