danielmarschall / oidplus

OIDplus 2.0 - An OpenSource online Registration Authority for OIDs and other Object Types
https://www.oidplus.com
Apache License 2.0
10 stars 6 forks source link

OID-IP URL is wrong on systems with canonical URLs #14

Closed wehowski closed 1 year ago

wehowski commented 1 year ago

https://registry.frdl.de/?goto=oidplus%3Awhois The Link/Button "Open in Browser" does not work in IE.

Chrome: OK FF: OK IE: Error with Slash / Link Edit: tested with Edge

danielmarschall commented 1 year ago

I can't reproduce it. registry.frdl.de does not work on IE at all (the menu looks funny, which means no JavaScript is loaded). JavaScript console shows that a webfan JavaScript has a JavaScript syntax error). Therefore, in OIDWHOIS I don't have any content. Can you please show a screenshot of the problem?

wehowski commented 1 year ago

Hello Daniel, unfortunatly there is nothing to see on a screenshot as everything works and looks fine!!! Except if I click the button "Open in web-browser" the link resolves to https://webfan.de/apps/registry/index.phpplugins/viathinksoft/publicPages/100_whois/whois/webwhois.php?query=oid%3A1.3.6.1.4.1 and redirects to an error page.

I am using Microsoft Edge Version 113.0.1774.50, other browsers work fine.

However as this is just a minor bug I can live with it, less important.

wehowski commented 1 year ago

Yes, you can see it in a screenshot: Unbenannt

danielmarschall commented 1 year ago

Ok, I tried it with Edge now. But I cannot reproduce it.

  1. I open Edge
  2. I visit registry.frdl.de
  3. On the left menu I click OID-Whois
  4. On the bottom of the page I click "Open in webbrowser"

For me, the URL is https://registry.frdl.de/plugins/viathinksoft/publicPages/100_whois/whois/webwhois.php?query=oid%3A1.3.6.1.4.1

wehowski commented 1 year ago

I can only reproduce the error at the canonical: https://webfan.de/apps/registry/index.php?goto=oidplus%3Awhois On registry.frdl.de it is working.

danielmarschall commented 1 year ago

Thank you. With the canonical URL I can reproduce that on Safari . It should be independent of the web browser, because IIRC the URL comes from the server side webpath() method.

danielmarschall commented 1 year ago

Bug seems to be in JavaScript actually:

OIDplusPagePublicWhois.js

$("#whois_url_bar")[0].innerText = getSystemUrl() + 'plugins/viathinksoft/publicPages/100_whois/whois/webwhois.php?query=' + encodeURIComponent(query);

_oidplusbase.js

function getSystemUrl(relative) {
    var url = new URL(window.location.href);
    if (relative) {
        return url.pathname;
    } else {
        return url.href.substr(0, url.href.length-url.search.length);
    }
}

OIDplusPagePublicWhois.js is the only file that makes use of getSystemUrl().

What I noticed / TODO:

  1. The argument relative is not defined, so this could be the reason why browsers handle it differently? TODO: Don't let it be undefined. (Fixed in SVN Rev 1287, file oidplus_base.js)
  2. Why do we use JavaScript at all? Why can't we let PHP handle the prefix and just let JavaScript add the variable parts? TODO: Check. (Won't fix)
  3. If you call this URL, it works: https://webfan.de/apps/registry/?goto=oidplus%3Awhois. So, the problem is the "index.php" . It needs to be removed by JavaScript. => TODO (Fixed in SVN Rev 1287, file oidplus_base.js)
  4. Also check if the PHP variant of getSystemUrl() works correctly. => TODO (Fixed in SVN Rev 1287, file OIDplus.class.php, error in function canonicalUrl())
danielmarschall commented 1 year ago

Fixed method:

function getSystemUrl(relative) {
        relative = (typeof relative === 'undefined') ? false : relative; // do not translate
        var url = new URL(window.location.href);
        var res = relative ? url.pathname : url.href.substr(0, url.href.length-url.search.length);
        if (res.endsWith("index.php")) res = res.substring(0, res.lastIndexOf('/')) + "/";
        return res;
}
wehowski commented 1 year ago

Hello Daniel, where do I find oidplus_base.js? Does it help to check if '/' === url.substr(0,1) ? As the canonical end with index.php and its a index file could remove index.php from canonical?

danielmarschall commented 1 year ago

oidplus_base.js is in includes/ . Did you try my fix I have written above?

Question to you:

  1. What should Does it help to check if '/' === url.substr(0,1) ? fix in your suggestion?

  2. How did index.php come from in the first place? The canonical URL should not contain index.php at all.

wehowski commented 1 year ago
  1. The "/" was missing?
  2. However, yes "oidplus_base.js is in includes/ ." Your fix is working!!!

Thank you!!!

wehowski commented 1 year ago
  1. Your fix is working! <link rel="canonical" href="https://webfan.de/apps/registry/index.php?goto=oidplus%3Awhois"> it contains index.php? However, the links are working now!
danielmarschall commented 1 year ago

Fixed this issue on serverside in canonicalURL():

                // Third part: File name
                $tmp = $_SERVER['SCRIPT_NAME'];
                $tmp = rtrim($tmp, 'index.php'); // <-- added
                $tmp = explode('/',$tmp);
                $tmp = end($tmp);
danielmarschall commented 1 year ago

Issues fixed in SVN Rev 1287

One last check (TODO): Check if there are other places where "index.php" is automatically added to the URL! --> oidplus_base.js contains index.php?goto= . That's not good => will be continued in #15