Opened 3 years ago

Closed 3 years ago

#18893 closed enhancement (fixed)

Redirect Globe requests to Atlas

Reported by: karsten Owned by: irl
Priority: Medium Milestone:
Component: Metrics/Globe Version:
Severity: Normal Keywords: complete-before-abandoning-globe
Cc: saint, iang, irl Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Quoting Tim, isis, and Lunar from tor-project@:

Tim: Can we redirect globe.torproject.org to atlas.torproject.org?

isis: We could probably do this without so much effort, yes. For fingerprints the redirect would be from e.g.:

https://globe.torproject.org/#/relay/A10C4F666D27364036B562823E5830BC448E046A to
https://atlas.torproject.org/#details/A10C4F666D27364036B562823E5830BC448E046A

For searches it would be:

https://globe.torproject.org/#/search/query=noether to
https://atlas.torproject.org/#search/noether

Lunar: As far as I understand web technologies, the anchor is not sent to the HTTP server. So the rewriting can only be done via JavaScript and not through Apache.

Suggestion: How's this code? (Please improve, this is the result of ten minutes searching on the internets!)

<html>
<body>
<script type="text/javascript">
(function () {
    var atlas = "https://atlas.torproject.org/"
    var hash = window.location.hash.substring(1);
    if (!hash) {
        window.location.replace(atlas);
    } else if (hash.startsWith("/relay/")) {
        window.location.replace(atlas + "#details/" + hash.substring(7));
    } else if (hash.startsWith("/search/query=")) {
        window.location.replace(atlas + "#search/" + hash.substring(14));
    } else {
        window.location.replace(atlas);
    }
})();
</script>
</body>
</html>

Child Tickets

TicketTypeStatusOwnerSummary
#15395defectclosedirladd support for more than 40 results
#19350defectclosedSebastianGlobe should be removed from volunteering page

Change History (17)

comment:1 Changed 3 years ago by saint

If you are planning to continue using Apache, it's possible to do this with mod_rewrite (even with anchors). For anchor links, it requires the NE flag with a 301 http code. This will keep Apache from converting # into its hex equivalent.

So something like:

RewriteEngine On

Rewrit­eCond %{HTTP­_HOST} ^globe.torproject.org/#/relay/(.*)$ [NC]
RewriteRule ^atlas.torproject.org/#details/$1[NE,R=301]

Rewrit­eCond %{HTTP­_HOST} ^globe.torproject.org/#/search/query=(.*)$ [NC]
RewriteRule ^atlas.torproject.org/#search/$1[NE,R=301]

should work.

comment:2 Changed 3 years ago by saint

Cc: saint added

comment:3 in reply to:  1 Changed 3 years ago by iang

Replying to saint:

If you are planning to continue using Apache, it's possible to do this with mod_rewrite (even with anchors). For anchor links, it requires the NE flag with a 301 http code. This will keep Apache from converting # into its hex equivalent.

So something like:

RewriteEngine On

Rewrit­eCond %{HTTP­_HOST} ^globe.torproject.org/#/relay/(.*)$ [NC]
RewriteRule ^atlas.torproject.org/#details/$1[NE,R=301]

Rewrit­eCond %{HTTP­_HOST} ^globe.torproject.org/#/search/query=(.*)$ [NC]
RewriteRule ^atlas.torproject.org/#search/$1[NE,R=301]

should work.

I'm pretty sure the NE trick is for rewriting *to* a URL with an anchor. But Apache will never see the *original* anchor, as Lunar points out above.

comment:4 Changed 3 years ago by iang

Cc: iang added

comment:5 Changed 3 years ago by karsten

Keywords: complete-before-abandoning-globe added

comment:6 Changed 3 years ago by karsten

Cc: irl added
Status: newneeds_review

Hi irl, you did some great work on other Atlas tickets, so I hope you don't mind if I cc you on this ticket. It's one of the few remaining tickets that we should resolve before shutting down Globe. And this ticket already comes with a patch (see description above). If you'd want to take a look, that would be really cool. Thanks!

comment:7 Changed 3 years ago by irl

Adding in a redirect for the top 10 page, assuming my patch in #5430 (comment 12) is merged. Also adding some text for those with javascript disabled.

<html>
<head>
<script type="text/javascript">
(function () {
    var atlas = "https://atlas.torproject.org/"
    var hash = window.location.hash.substring(1);
    if (!hash) {
        window.location.replace(atlas);
    } else if (hash.startsWith("/relay/")) {
        window.location.replace(atlas + "#details/" + hash.substring(7));
    } else if (hash.startsWith("/search/query=")) {
        window.location.replace(atlas + "#search/" + hash.substring(14));
    } else if (hash.startsWith("/top10")) {
        window.location.replace(atlas + "#top10");
    } else {
        window.location.replace(atlas);
    }
})();
</script>
</head>
<body>
<h1>Globe is shutdown</h1>
<p>Globe has been shut down. <a href="https://atlas.torproject.org/">Atlas</a>
provides the same functionality that Globe has provided in the past. If you
have JavaScript enabled, you will be redirected shortly.</p>
</body>
</html>

comment:8 Changed 3 years ago by irl

Had a realisation that that / after the # is optional, so don't merge this yet!

e.g. https://globe.torproject.org/#top10 is valid.

comment:9 Changed 3 years ago by karsten

irl, your patch looks good to me, but can you clarify what realization you had there? Thanks!

comment:10 Changed 3 years ago by irl

You can have #/top10 or #top10 which will both be valid routes and both show the top 10 page, same with all the other routes.

The fix would be to remove a '/' from the start of the hash variable if it exists, and then only match on the remainder of the hash.

comment:11 Changed 3 years ago by irl

Owner: changed from isis to irl
Status: needs_reviewaccepted

Will look at this later today and produce a final version.

comment:12 Changed 3 years ago by irl

Ok, looked at this, code is at:

https://gitweb.torproject.org/user/irl/atlas.git/tree/index.html?h=task/18893

I'm quite happy with this. If you'd like to experiment, try putting different "hash" portions on the end of:

https://gitweb.torproject.org/user/irl/atlas.git/plain/index.html?h=task/18893

For example:

This update can now cope with hash portions that start with and without a leading forward slash.

An example without a leading slash:

Relay with fingerprint 81B75D534F91BFB7C57AB67DA10BCEF622582AE8 (no leading slash)

comment:13 Changed 3 years ago by irl

Status: acceptedneeds_review

comment:14 Changed 3 years ago by karsten

Status: needs_reviewmerge_ready

Looks great to me. Deployed on https://globe.torproject.org/. Thanks!

Would you want to add that patch to globe.git rather than atlas.git? I'd guess simply putting it in the root directory as index.html would be sufficient. If that's too cumbersome for you, I'm happy to do that for you. Thanks in advance.

comment:15 Changed 3 years ago by irl

It's an orphaned branch in my personal repo, I figured if Globe is going away then doing a patch for gitolite for a branch that's only ever going to have that one commit was probably too much.

I don't think clobbering the globe Git repo is necessarily the right thing to do either, as the code should be preserved in case it's wanted in the future. Perhaps adding the orphaned branch to the git repo and swapping around which branch is master?

I'll leave it up to you how you want to handle it.

comment:16 Changed 3 years ago by irl

karsten: Can we close this one?

comment:17 Changed 3 years ago by karsten

Resolution: fixed
Status: merge_readyclosed

Alright, we probably don't need the redirection code in a Git repo. Let me paste the final version that is deployed here, and it'll be archived in Trac and all our inboxes (or at least the inboxes of those who are subscribed to tor-bugs@):

<html>
<head>
<title>Redirecting to Tor Atlas...</title>
<script type="text/javascript">
(function () {
    var atlas = "https://atlas.torproject.org/"
    var hash = window.location.hash;
    hash = hash.startsWith("#/") ? hash.substring(2) : hash.substring(1);
    if (!hash) {
        window.location.replace(atlas);
    } else if (hash.startsWith("relay/")) {
        window.location.replace(atlas + "#details/" + hash.substring(6));
    } else if (hash.startsWith("search/query=")) {
        window.location.replace(atlas + "#search/" + hash.substring(13));
    } else if (hash.startsWith("top10")) {
        window.location.replace(atlas + "#top10");
    } else {
        window.location.replace(atlas);
    }
})();
</script>
</head>
<body>
        <h1>Globe is shutdown</h1>
        <p>Globe has been shut down. <a
        href="https://atlas.torproject.org/">Atlas</a> provides the same
        functionality that Globe has provided in the past. If you have
        JavaScript enabled, you will be redirected shortly.</p>
</body>
</html>

Thanks again! Closing.

Note: See TracTickets for help on using tickets.