From 8a4b19928a5df77ba97535928d1817fe50f18f64 Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 23 Aug 2017 18:42:18 +0000 Subject: [PATCH 1/4] can fully verify and upload a zipped website --- assets/oauth3.org | 2 +- js/controllers/website-controller.js | 41 ++++++++++++++++++++-------- js/www@daplie.com.js | 19 +++++++++++++ 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/assets/oauth3.org b/assets/oauth3.org index 5f68ea1..effee98 160000 --- a/assets/oauth3.org +++ b/assets/oauth3.org @@ -1 +1 @@ -Subproject commit 5f68ea19e22d05bebc6a289da0a89a714442e6d2 +Subproject commit effee987beca6f0522a93533d65de1e7ed246987 diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index b3498f9..ed57432 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -123,18 +123,19 @@ app.controller('websiteCtrl', [ }; vm._isSubDomain = function (sub, domain) { - return -1 === ('.' + sub).indexOf(('.' + domain)); + return -1 !== ('.' + sub).indexOf(('.' + domain)); }; vm.createWebsite = function () { + console.log('##### Auth.oauth3'); + console.log(Auth.oauth3); + var pkg = Auth.oauth3.pkg('www@daplie.com'); var parts; var sub; var sld; var tld; - console.log('Auth.oauth3', Auth.oauth3); - //vm.unlock('webpreneur'); if (!vm.currentFiles || !vm.currentFiles.length) { window.alert('No files chosen.'); @@ -172,25 +173,36 @@ app.controller('websiteCtrl', [ // (because two users could both claim a single domain) // We're claiming it at the top level (i.e. example.com) // but we could also claim it at the subdomain level (needs UI update) - return pkg.request({ sld: sld, tld: tld, sub: undefined }).then(function (result) { + var domainReq = { sld: sld, tld: tld, sub: undefined }; + return pkg.request(domainReq).then(function (result) { var sess; var prom; var def; console.log('[pkg www] request domain'); - console.log(result); + console.log(result.data); + + console.log('[pkg www] vm.domain.session:'); + console.log(vm.domain.session); + + console.log(vm.currentHost, vm.domain.domain); + console.log(vm._isSubDomain(vm.currentHost, vm.domain.domain)); // can validate automatically if (vm.domain.session && vm._isSubDomain(vm.currentHost, vm.domain.domain)) { // this should always succeed Auth.sessions.some(function (session) { + console.log('#', session.token.sub + '@' + session.token.iss); if (vm.domain.session === (session.token.sub + '@' + session.token.iss)) { + console.log('=', session.token.sub + '@' + session.token.iss); sess = session; return session; } }); if (sess) { + console.log('[pkg www] session selected', sess); prom = Auth.select(sess).then(function (oauth3) { + console.log('[pkg www] instance selected', oauth3); return oauth3.api('dns.set', { sld: sld, tld: tld, sub: ('' + result.data.prefix), type: 'TXT', ttl: 300, value: result.data.challenge }); }); } @@ -209,7 +221,12 @@ app.controller('websiteCtrl', [ } return prom.then(function () { - vm._createWebsite(pkg); + console.log('[pkg www] after pkg'); + console.log(pkg); + return pkg.claim(domainReq).then(function (result) { + console.log('[pkg www] claim', result); + return vm._createWebsite(pkg); + }); }); }); @@ -227,17 +244,17 @@ app.controller('websiteCtrl', [ console.log('[www] post pkg', oauth3._resourceProviderDirectives); return pkg.list().then(function (result) { - var sites = result.data; + var _sites = result.data; - if (Array.isArray(sites)) { - sites = sites.concat(sites); + if (Array.isArray(_sites)) { + sites = _sites.concat(sites); return; } - console.error('sites is not an array'); - console.error(sites); + console.error('_sites is not an array'); + console.error(_sites); }, function (err) { - console.error('sites had an error'); + console.error('_sites had an error'); console.error(err); }); }); diff --git a/js/www@daplie.com.js b/js/www@daplie.com.js index 472226b..c72db44 100644 --- a/js/www@daplie.com.js +++ b/js/www@daplie.com.js @@ -12,6 +12,7 @@ OAUTH3._pkgs['www@daplie.com'] = { method: 'POST' , url: OAUTH3.url.normalize(providerUri) + '/api/www@daplie.com/acl/add/' + opts.hostname + + '?' + OAUTH3.utils.query.stringify({ tld: opts.tld, sld: opts.sld/*, sub: opts.sub*/ }) , session: session , multipart: opts.multipart // special property to be figured out by browser request code }).then(function (result) { @@ -48,6 +49,24 @@ OAUTH3._pkgs['www@daplie.com'] = { }).then(function (result) { // result.data + return result; + }); + } +, claim: function (opts) { + var providerUri = opts.audience; + var session = opts.session; + + return OAUTH3.request({ + method: 'POST' + , url: OAUTH3.url.normalize(providerUri) + + '/api/www@daplie.com/acl/claim/:tld/:sld/:sub' + .replace(/(:tld)/, opts.tld) + .replace(/(:sld)/, opts.sld) + .replace(/(:sub)/, opts.sub || '') + , session: session + }).then(function (result) { + // result.data + return result; }); } From 37734638b863fb24991db0c1554c70fb0dae7fe5 Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 23 Aug 2017 18:54:50 +0000 Subject: [PATCH 2/4] fix some state issues --- js/controllers/website-controller.js | 8 +++----- js/services/auth-service.js | 14 +++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index ed57432..e5a4d3e 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -31,7 +31,7 @@ app.controller('websiteCtrl', [ return $q.all(Auth.sessions.map(function (session) { - return Auth.select(session).then(function (oauth3) { + return Auth.get(session).then(function (oauth3) { return oauth3.api(apiname, {}).then(function (collection) { @@ -201,7 +201,7 @@ app.controller('websiteCtrl', [ if (sess) { console.log('[pkg www] session selected', sess); - prom = Auth.select(sess).then(function (oauth3) { + prom = Auth.get(sess).then(function (oauth3) { console.log('[pkg www] instance selected', oauth3); return oauth3.api('dns.set', { sld: sld, tld: tld, sub: ('' + result.data.prefix), type: 'TXT', ttl: 300, value: result.data.challenge }); }); @@ -238,10 +238,8 @@ app.controller('websiteCtrl', [ return $q.all(Auth.sessions.map(function (session) { console.log('[www] select'); - return Auth.select(session).then(function (oauth3) { - console.log('[www] oauth3', oauth3._resourceProviderDirectives); + return Auth.get(session).then(function (oauth3) { var pkg = oauth3.pkg('www@daplie.com'); - console.log('[www] post pkg', oauth3._resourceProviderDirectives); return pkg.list().then(function (result) { var _sites = result.data; diff --git a/js/services/auth-service.js b/js/services/auth-service.js index 0bc7791..7acba02 100644 --- a/js/services/auth-service.js +++ b/js/services/auth-service.js @@ -66,7 +66,7 @@ app.factory('Auth', [ }); return Auth.session; } - , select: function (session) { + , get: function (session) { if (!session.issuer) { throw new Error("session doesn't have an issuer"); } @@ -97,12 +97,16 @@ app.factory('Auth', [ console.log('session.subject:', session.subject); console.log('session:', session); - promise.then(function (oauth3) { + return promise; + } + , select: function (session) { + return Auth.get(session).then(function (oauth3) { + var dapName = 'dap-' + session.subject + '|' + session.issuer; + localStorage.setItem(dapSession, dapName); + Auth.session = session; Auth.oauth3 = oauth3; - }) - - return promise; + }); } , signOut: function () { var session = Auth.session; From 3ba63bc818bc1c294146097d566b38ff710a0288 Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 23 Aug 2017 20:36:19 +0000 Subject: [PATCH 3/4] options for path, unzip, and strip-root-path --- js/controllers/website-controller.js | 12 +++++++++++- js/www@daplie.com.js | 2 +- templates/website.html | 10 +++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index e5a4d3e..bd31d3c 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -11,10 +11,15 @@ function handleFiles(ev) { return; } - $scope = angular.element(ev.target).scope(); + $scope = angular.element(ev.target).scope(); // 'vm' is the Controller As name. vm = $scope.vm; vm.currentFiles = ev.target.files; + var file = vm.currentFiles[0]; + vm.isZip = /\.zip$/.test(file.name); + vm.unzip = vm.isZip; + vm.stripZip = vm.isZip; + $scope.$digest(); console.log('vm.currentFiles', vm.currentFiles); } window.document.body.addEventListener('change', handleFiles); @@ -25,6 +30,8 @@ app.controller('websiteCtrl', [ var vm = this; vm.domains = []; + //vm.unzipPath = '/'; + vm.webPath = '/'; Auth.api = function (apiname, opts) { var els = []; @@ -117,6 +124,9 @@ app.controller('websiteCtrl', [ , sld: vm.domain.sld //, sub: vm.record.sub , multipart: { site: vm.currentFiles[0] } + , unzip: vm.unzip + , strip: vm.stripZip + , path: vm.webPath }).then(function (result) { window.alert(JSON.stringify(result)); }); diff --git a/js/www@daplie.com.js b/js/www@daplie.com.js index c72db44..28228fc 100644 --- a/js/www@daplie.com.js +++ b/js/www@daplie.com.js @@ -12,7 +12,7 @@ OAUTH3._pkgs['www@daplie.com'] = { method: 'POST' , url: OAUTH3.url.normalize(providerUri) + '/api/www@daplie.com/acl/add/' + opts.hostname - + '?' + OAUTH3.utils.query.stringify({ tld: opts.tld, sld: opts.sld/*, sub: opts.sub*/ }) + + '?' + OAUTH3.utils.query.stringify({ tld: opts.tld, sld: opts.sld/*, sub: opts.sub*/, unzip: opts.unzip, strip: opts.strip, path: opts.path }) , session: session , multipart: opts.multipart // special property to be figured out by browser request code }).then(function (result) { diff --git a/templates/website.html b/templates/website.html index da3db76..0dede8b 100644 --- a/templates/website.html +++ b/templates/website.html @@ -44,7 +44,15 @@
-->
- +
+ +
+ +
+ + + +
From 16f44e72aec15a53172d735f090fb99f6e77d8cb Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 23 Aug 2017 22:12:57 +0000 Subject: [PATCH 4/4] ability to upload file (without unpacking) to arbitrary locations --- js/controllers/website-controller.js | 48 ++++++++++++++++++++++------ js/www@daplie.com.js | 2 +- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index bd31d3c..3b26ead 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -87,6 +87,14 @@ app.controller('websiteCtrl', [ if (!vm.domain) { vm.domain = { domain: vm.newDomain }; } + + if (!vm.domain.tld) { + var parts = vm.domain.domain.split('.'); + vm.domain.sld = parts.shift(); + vm.domain.tld = parts.join('.'); + } + + vm.setRecord(); }; vm.selectDomain = function (domain) { @@ -110,6 +118,20 @@ app.controller('websiteCtrl', [ }); }; + vm.setRecord = function () { + // TODO set record based on (record.host === sub + domain.domain) + var sub = vm.newRecord; + + if ('@' === sub) { + sub = ''; + } + vm.record = { sub: sub, host: (sub ? sub + '.' : '') + vm.domain.domain }; + vm.currentHost = vm.record.host; + + console.log('vm.record', vm.record); + console.log('vm.currentHost', vm.currentHost); + }; + vm.selectRecord = function (record) { vm.record = record; vm.newRecord = record.sub; @@ -160,17 +182,15 @@ app.controller('websiteCtrl', [ return; } - // already validated - if (vm.sites.some(function (r) { - return -1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain)); - })) { - vm._createWebsite(pkg); - } - if (vm.domain) { - parts = vm.domain.domain.split('.'); - sld = parts.shift(); - tld = parts.join('.'); + if (!vm.domain.tld || !vm.domain.sld) { + parts = vm.domain.domain.split('.'); + sld = parts.shift(); + tld = parts.join('.'); + } else { + sld = vm.domain.sld; + tld = vm.domain.tld; + } } else { parts = vm.currentHost.split('.'); // TODO get list of tlds @@ -179,6 +199,14 @@ app.controller('websiteCtrl', [ sub = parts.join('.'); } + // already validated + if (vm.sites.some(function (r) { + return -1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain)); + })) { + vm._createWebsite(pkg); + return; + } + // We're making a request to claim a domain // (because two users could both claim a single domain) // We're claiming it at the top level (i.e. example.com) diff --git a/js/www@daplie.com.js b/js/www@daplie.com.js index 28228fc..2cb17b6 100644 --- a/js/www@daplie.com.js +++ b/js/www@daplie.com.js @@ -7,7 +7,7 @@ OAUTH3._pkgs['www@daplie.com'] = { add: function (opts) { var providerUri = opts.audience; var session = opts.session; - debugger; + return OAUTH3.request({ method: 'POST' , url: OAUTH3.url.normalize(providerUri)