Merge lp:~sil/libubuntuone/restrict-domains into lp:libubuntuone

Proposed by Stuart Langridge on 2010-03-24
Status: Merged
Approved by: Rodrigo Moya on 2010-03-25
Approved revision: 72
Merged at revision: not available
Proposed branch: lp:~sil/libubuntuone/restrict-domains
Merge into: lp:libubuntuone
Diff against target: 348 lines (+234/-55)
4 files modified
data/Makefile.am (+2/-0)
data/outside_domain.html (+56/-0)
data/trying_sso.html (+58/-0)
libubuntuone/u1-music-store.c (+118/-55)
To merge this branch: bzr merge lp:~sil/libubuntuone/restrict-domains
Reviewer Review Type Date Requested Status
Rodrigo Moya (community) Approve on 2010-03-25
Tim Cole (community) 2010-03-24 Approve on 2010-03-24
Review via email: mp+22063@code.launchpad.net

Commit message

Trap URLs that lead out of the Music Store (either to the non-U1 7digital.com, or to Ubuntu One authentication URLs) and show an error page instead, along with a way of logging the error in querystrings so that we can identify that it happened.

Description of the change

Trap URLs that lead out of the Music Store (either to the non-U1 7digital.com, or to Ubuntu One authentication URLs) and show an error page instead, along with a way of logging the error in querystrings so that we can identify that it happened.

To post a comment you must log in.
Martin Albisetti (beuno) wrote :

59 +<h2>There was a problem with what you just tried to do. Please go back and try something different.</h2>

I'm not sure that's the best error message ever written.

122 +<h2>An error has occurred. Please ensure that your
123 +computer is connected to Ubuntu One.</h2>

How about a link to somewhere explaining how to do that? I guess that would be an external link :)
Can you open up something in firefox though? or explain right there and then?

Tim Cole (tcole) wrote :

Looks alright. But it does need a better error message. I'd suggest "The link you clicked is currently unsupported. Please try exploring a different part of the music store."

review: Approve
Stuart Langridge (sil) wrote :

beuno: for the latter message, you only get it if the thing that was supposed to open up firefox has failed. This whole branch is there to provide a safety net if there are bugs in the existing code, to stop the user crashing and burning as a result of those bugs. In theory, no-one should ever see the messages.

tcole: I'll change the first one. I was feeling a bit too whimsical when I wrote it :)

72. By Stuart Langridge on 2010-03-24

slightly less whimsical error message

Rodrigo Moya (rodrigo-moya) wrote :

There are some improvements that can be done on the C code of this branch, but it still is correct as it is, so approving and will add those improvements in other branches

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/Makefile.am'
--- data/Makefile.am 2010-03-22 10:07:24 +0000
+++ data/Makefile.am 2010-03-24 23:55:36 +0000
@@ -4,6 +4,8 @@
4 u1-preview.js \4 u1-preview.js \
5 u1-songs-clickable.js \5 u1-songs-clickable.js \
6 load_error.html \6 load_error.html \
7 outside_domain.html \
8 trying_sso.html \
7 connecting.html \9 connecting.html \
8 in_development.html \10 in_development.html \
9 screen.css \11 screen.css \
1012
=== added file 'data/outside_domain.html'
--- data/outside_domain.html 1970-01-01 00:00:00 +0000
+++ data/outside_domain.html 2010-03-24 23:55:36 +0000
@@ -0,0 +1,56 @@
1<!doctype html>
2<html>
3<head>
4<title>Loading error</title>
5<link rel="stylesheet" href="reset.css" type="text/css" media="all">
6<link rel="stylesheet" href="screen.css" type="text/css" media="all">
7<script>
8function goback() {
9 // We should have been passed, to this page, the referrer and the URL they went to in error, separated by :::
10 if (location.search && location.search.indexOf(":::") != -1) {
11 var parts = location.search.substr(1).split(":::");
12 if (parts.length != 2) {
13 history.go(-1);
14 }
15 var from_url = parts[0];
16 var to_url = parts[1];
17 var combining = "&";
18 if (from_url.indexOf("?") == -1) {
19 combining = "?"
20 }
21 var go_back_url = from_url + combining + "went_to_url_in_error=" + escape(to_url);
22 location.href = go_back_url;
23 } else {
24 history.go(-1);
25 }
26}
27</script>
28</head>
29<body class="downloads">
30<div id="header">
31
32<div class="wrap">
33<h1 id="logo">Ubuntu One Music Store</h1>
34
35</div><!-- close .wrap -->
36</div><!-- close #header -->
37
38<div class="superfluous">
39<div id="content">
40<div class="access">
41 <h1>Sorry!</h1>
42<h2>The link you clicked is currently unsupported.
43Please try exploring a different part of the music store.</h2>
44
45<p><button onclick="goback()"><span>Go back</span></button></p>
46</div>
47</div>
48
49</div>
50</div>
51<div id="footer">
52<div class="wrap">
53</div>
54</div>
55</body>
56</html>
057
=== added file 'data/trying_sso.html'
--- data/trying_sso.html 1970-01-01 00:00:00 +0000
+++ data/trying_sso.html 2010-03-24 23:55:36 +0000
@@ -0,0 +1,58 @@
1<!doctype html>
2<html>
3<head>
4<title>Loading error</title>
5<link rel="stylesheet" href="reset.css" type="text/css" media="all">
6<link rel="stylesheet" href="screen.css" type="text/css" media="all">
7<script>
8function carry_on() {
9 // We should have been passed, to this page, the referrer, the URL they
10 // went to in error, and the store front page, separated by :::
11 if (location.search && location.search.indexOf(":::") != -1) {
12 var parts = location.search.substr(1).split(":::");
13 if (parts.length != 3) {
14 history.go(-1);
15 }
16 var from_url = parts[0];
17 var to_url = parts[1];
18 var front_page = parts[2];
19 var combining = "&";
20 if (front_page.indexOf("?") == -1) {
21 combining = "?"
22 }
23 var go_back_url = front_page + combining + "went_to_url_in_error=" +
24 escape(to_url) + "&came_from_url=" + escape(from_url);
25 location.href = go_back_url;
26 } else {
27 history.go(-1);
28 }
29}
30</script>
31</head>
32<body class="downloads">
33<div id="header">
34
35<div class="wrap">
36<h1 id="logo">Ubuntu One Music Store</h1>
37
38</div><!-- close .wrap -->
39</div><!-- close #header -->
40
41<div class="superfluous">
42<div id="content">
43<div class="access">
44 <h1>Sorry!</h1>
45<h2>An error has occurred. Please ensure that your
46computer is connected to Ubuntu One.</h2>
47<p><button onclick="carry_on()"><span>Go back</span></button></p>
48</div>
49</div>
50
51</div>
52</div>
53<div id="footer">
54<div class="wrap">
55</div>
56</div>
57</body>
58</html>
059
=== modified file 'libubuntuone/u1-music-store.c'
--- libubuntuone/u1-music-store.c 2010-03-23 12:19:23 +0000
+++ libubuntuone/u1-music-store.c 2010-03-24 23:55:36 +0000
@@ -25,6 +25,7 @@
25#include <webkit/webkit.h>25#include <webkit/webkit.h>
26#include <dbus/dbus-glib.h>26#include <dbus/dbus-glib.h>
27#include <libsoup/soup-gnome-features.h>27#include <libsoup/soup-gnome-features.h>
28#include <libsoup/soup-uri.h>
28#include <gnome-keyring.h>29#include <gnome-keyring.h>
29#include "oauth.h"30#include "oauth.h"
30#include "u1-music-store.h"31#include "u1-music-store.h"
@@ -39,6 +40,8 @@
39#define U1_NOT_REGISTERED_URL "https://one.ubuntu.com/music/notregistered?returnUrl="40#define U1_NOT_REGISTERED_URL "https://one.ubuntu.com/music/notregistered?returnUrl="
4041
41#define U1_DEFAULT_ERROR_PAGE "load_error.html"42#define U1_DEFAULT_ERROR_PAGE "load_error.html"
43#define U1_OUTSIDE_DOMAIN_ERROR_PAGE "outside_domain.html"
44#define U1_TRYING_SSO_ERROR_PAGE "trying_sso.html"
42#define U1_IN_DEVELOPMENT_PAGE "in_development.html"45#define U1_IN_DEVELOPMENT_PAGE "in_development.html"
43#define U1_CONNECTING_PAGE "connecting.html" 46#define U1_CONNECTING_PAGE "connecting.html"
44#define U1_INITIAL_PAGE "<html><body>Loading Ubuntu One music store</body></html>"47#define U1_INITIAL_PAGE "<html><body>Loading Ubuntu One music store</body></html>"
@@ -241,6 +244,63 @@
241 gchar *not_registered_url;244 gchar *not_registered_url;
242} NotRegisteredReplacementData;245} NotRegisteredReplacementData;
243246
247static gchar *
248get_url_to_use (U1MusicStore *music_store)
249{
250 gchar *oauth_token = NULL, *oauth_token_secret = NULL, *real_url;
251 const gchar *url_to_use;
252
253 /* If U1MUSICSTOREURL is defined, use that instead of the real URL */
254 if (! (url_to_use = g_getenv ("U1MUSICSTOREURL")))
255 url_to_use = "https://one.ubuntu.com";
256
257 if (music_store->priv->base_url != NULL)
258 g_free (music_store->priv->base_url);
259
260 music_store->priv->base_url = g_strdup (url_to_use);
261
262 /* OAUth sign the URL */
263 if (g_str_has_prefix (url_to_use, "http://localhost") || g_str_has_prefix (url_to_use, "http://127.0.0.1")) {
264 const gchar *oauthfile;
265
266 oauthfile = g_getenv ("OAUTHKEYFILE");
267 if (oauthfile != NULL) {
268 gchar *oauthstring;
269 gsize len;
270
271 if (g_file_get_contents (oauthfile, &oauthstring, &len, NULL)) {
272 parse_oauth_string (oauthstring, &oauth_token, &oauth_token_secret);
273 g_free (oauthstring);
274 }
275 } else {
276 webkit_web_view_load_string (WEBKIT_WEB_VIEW (music_store->priv->web_viewer),
277 "Fail! If you specify U1MUSICSTOREURL you must "
278 "also specify OAUTHKEYFILE as a file with OAuth keys in it",
279 "text/html", "utf-8", "file:///");
280 return NULL;
281 }
282 } else
283 get_credentials_from_keyring (&oauth_token, &oauth_token_secret);
284
285 if (oauth_token == NULL || oauth_token_secret == NULL)
286 real_url = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_NOT_LOGGED_IN_STORE_URL);
287 else {
288 gchar *s = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_STORE_URL);
289
290 real_url = oauth_sign_url2 (s, NULL, OA_HMAC, "GET",
291 "ubuntuone", "hammertime",
292 oauth_token, oauth_token_secret);
293 g_free (s);
294 }
295
296 g_free (oauth_token);
297 g_free (oauth_token_secret);
298
299 return real_url;
300}
301
302
303
244static void304static void
245got_new_dbus_credentials_cb (DBusGProxy *proxy, const gchar *realm, const gchar *consumer_key, gpointer user_data)305got_new_dbus_credentials_cb (DBusGProxy *proxy, const gchar *realm, const gchar *consumer_key, gpointer user_data)
246{306{
@@ -329,6 +389,64 @@
329 gpointer user_data)389 gpointer user_data)
330{390{
331 U1MusicStore *music_store = U1_MUSIC_STORE (user_data);391 U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
392 SoupURI *parsed_uri;
393
394 parsed_uri = soup_uri_new (webkit_network_request_get_uri (request));
395 if (parsed_uri != NULL) {
396 if (!g_strcmp0 ((const gchar *) parsed_uri->host, "www.7digital.com")) {
397 /* host is 7digital.com. It must be in our store. */
398 if (!g_str_has_prefix (parsed_uri->path, "/stores/")) {
399 /* a 7digital URL not in our store. Die */
400 gchar *to_and_from_error_uris;
401 g_debug("Hitting the unbranded store, so throwing an error");
402 to_and_from_error_uris = g_strdup_printf ("%s:::%s",
403 webkit_web_view_get_uri (web_view),
404 webkit_network_request_get_uri (request));
405 load_internal_html_page (web_view, U1_OUTSIDE_DOMAIN_ERROR_PAGE, to_and_from_error_uris);
406 g_free (to_and_from_error_uris);
407 }
408 }
409 if (!g_strcmp0 ((const gchar *) parsed_uri->host, "one.ubuntu.com")) {
410 /* host is one.ubuntu.com. It must not be the login page */
411 if (g_str_has_prefix (parsed_uri->path, "/auth/")) {
412 /* trying to log the user into o.u.c inside the webview. Die. */
413 gchar *real_url;
414 gchar *to_and_from_error_uris;
415 real_url = get_url_to_use (music_store);
416 to_and_from_error_uris = g_strdup_printf ("%s:::%s:::%s",
417 webkit_web_view_get_uri (web_view),
418 webkit_network_request_get_uri (request),
419 real_url);
420 g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error");
421 if (real_url != NULL) {
422 load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
423 g_free (real_url);
424 } else {
425 load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
426 }
427 g_free (to_and_from_error_uris);
428 }
429 }
430 if (!g_strcmp0 ((const gchar *) parsed_uri->host, "login.ubuntu.com")) {
431 /* host is SSO. Die. */
432 gchar *real_url;
433 gchar *to_and_from_error_uris;
434 real_url = get_url_to_use (music_store);
435 to_and_from_error_uris = g_strdup_printf ("%s:::%s:::%s",
436 webkit_web_view_get_uri (web_view),
437 webkit_network_request_get_uri (request),
438 real_url);
439 g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error");
440 if (real_url != NULL) {
441 load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
442 g_free (real_url);
443 } else {
444 load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
445 }
446 g_free (to_and_from_error_uris);
447 }
448
449 }
332450
333 /* Remove watching callback for the page */451 /* Remove watching callback for the page */
334 if (music_store->priv->watch_id != 0) {452 if (music_store->priv->watch_id != 0) {
@@ -681,61 +799,6 @@
681 return TRUE;799 return TRUE;
682}800}
683801
684static gchar *
685get_url_to_use (U1MusicStore *music_store)
686{
687 gchar *oauth_token = NULL, *oauth_token_secret = NULL, *real_url;
688 const gchar *url_to_use;
689
690 /* If U1MUSICSTOREURL is defined, use that instead of the real URL */
691 if (! (url_to_use = g_getenv ("U1MUSICSTOREURL")))
692 url_to_use = "https://one.ubuntu.com";
693
694 if (music_store->priv->base_url != NULL)
695 g_free (music_store->priv->base_url);
696
697 music_store->priv->base_url = g_strdup (url_to_use);
698
699 /* OAUth sign the URL */
700 if (g_str_has_prefix (url_to_use, "http://localhost") || g_str_has_prefix (url_to_use, "http://127.0.0.1")) {
701 const gchar *oauthfile;
702
703 oauthfile = g_getenv ("OAUTHKEYFILE");
704 if (oauthfile != NULL) {
705 gchar *oauthstring;
706 gsize len;
707
708 if (g_file_get_contents (oauthfile, &oauthstring, &len, NULL)) {
709 parse_oauth_string (oauthstring, &oauth_token, &oauth_token_secret);
710 g_free (oauthstring);
711 }
712 } else {
713 webkit_web_view_load_string (WEBKIT_WEB_VIEW (music_store->priv->web_viewer),
714 "Fail! If you specify U1MUSICSTOREURL you must "
715 "also specify OAUTHKEYFILE as a file with OAuth keys in it",
716 "text/html", "utf-8", "file:///");
717 return NULL;
718 }
719 } else
720 get_credentials_from_keyring (&oauth_token, &oauth_token_secret);
721
722 if (oauth_token == NULL || oauth_token_secret == NULL)
723 real_url = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_NOT_LOGGED_IN_STORE_URL);
724 else {
725 gchar *s = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_STORE_URL);
726
727 real_url = oauth_sign_url2 (s, NULL, OA_HMAC, "GET",
728 "ubuntuone", "hammertime",
729 oauth_token, oauth_token_secret);
730 g_free (s);
731 }
732
733 g_free (oauth_token);
734 g_free (oauth_token_secret);
735
736 return real_url;
737}
738
739static gboolean802static gboolean
740load_real_store_cb (gpointer user_data)803load_real_store_cb (gpointer user_data)
741{804{

Subscribers

People subscribed via source and target branches