diff --git a/package-lock.json b/package-lock.json index 785a17f..ff30532 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1510,6 +1510,37 @@ "file-uri-to-path": "1.0.0" } }, + "bl": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz", + "integrity": "sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -1701,6 +1732,11 @@ "resolved": "https://registry.npmjs.org/bulma/-/bulma-0.8.2.tgz", "integrity": "sha512-vMM/ijYSxX+Sm+nD7Lmc1UgWDy2JcL2nTKqwgEqXuOMU+IGALbXd5MLt/BcjBAPLIx36TtzhzBcSnOP974gcqA==" }, + "bytes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", + "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" + }, "cache-base": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz", @@ -2046,6 +2082,14 @@ "resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz", "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" }, + "copy-to-clipboard": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.1.tgz", + "integrity": "sha512-i13qo6kIHTTpCm8/Wup+0b1mVWETvu2kIMzKoK8FpkLkFxlt0znUAHcMzox+T8sPlqtZXq3CulEjQHsYiGFJUw==", + "requires": { + "toggle-selection": "^1.0.6" + } + }, "copyfiles": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/copyfiles/-/copyfiles-2.2.0.tgz", @@ -2818,6 +2862,14 @@ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" }, + "end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "requires": { + "once": "^1.4.0" + } + }, "entities": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", @@ -3555,6 +3607,11 @@ "js-yaml": "^3.4.6" } }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" + }, "fs-extra": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-3.0.1.tgz", @@ -5408,6 +5465,11 @@ "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.6.tgz", "integrity": "sha512-sol30LUpz1jQFBjOKwbjxijiE3b6pjd74YwfD0fJOKPjF+fONKb2Yg8rYgS6+bK6VDl+/wfr4IYpC7jDzLUIfw==" }, + "node-gzip": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/node-gzip/-/node-gzip-1.1.2.tgz", + "integrity": "sha512-ZB6zWpfZHGtxZnPMrJSKHVPrRjURoUzaDbLFj3VO70mpLTW5np96vXyHwft4Id0o+PYIzgDkBUjIzaNHhQ8srw==" + }, "node-libs-browser": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.1.tgz", @@ -6554,6 +6616,17 @@ "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" }, + "raw-body": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.1.tgz", + "integrity": "sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==", + "requires": { + "bytes": "3.1.0", + "http-errors": "1.7.3", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + } + }, "readable-stream": { "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", @@ -8067,6 +8140,30 @@ "string-width": "^3.0.0" } }, + "tar-stream": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.2.tgz", + "integrity": "sha512-UaF6FoJ32WqALZGOIAApXx+OdxhekNMChu6axLJR85zMMjXKWFGjbIRe+J6P4UnRGg9rAwWvbTT0oI7hD/Un7Q==", + "requires": { + "bl": "^4.0.1", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "terser": { "version": "3.17.0", "resolved": "https://registry.npmjs.org/terser/-/terser-3.17.0.tgz", @@ -8179,6 +8276,11 @@ "repeat-string": "^1.6.1" } }, + "toggle-selection": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/toggle-selection/-/toggle-selection-1.0.6.tgz", + "integrity": "sha1-bkWxJj8gF/oKzH2J14sVuL932jI=" + }, "toidentifier": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", @@ -8402,6 +8504,11 @@ "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", "dev": true }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, "unquote": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unquote/-/unquote-1.1.1.tgz", diff --git a/package.json b/package.json index bcf03ef..8a4f946 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,16 @@ "@babel/runtime": "^7.9.2", "babel-polyfill": "^6.26.0", "clone": "^2.1.2", + "copy-to-clipboard": "^3.3.1", "do-bulma": "git+https://github.com/do-community/do-bulma.git", "do-vue": "git+https://github.com/do-community/do-vue.git", + "node-gzip": "^1.1.2", "parcel-bundler": "^1.12.4", "pretty-checkbox-vue": "^1.1.9", "prismjs": "^1.20.0", "qs": "^6.9.4", + "raw-body": "^2.4.1", + "tar-stream": "^2.1.2", "vue": "^2.6.11", "vue-hot-reload-api": "^2.3.3", "vue-prism-component": "^1.2.0", diff --git a/src/nginxconfig/templates/app.vue b/src/nginxconfig/templates/app.vue index d132316..c567f37 100644 --- a/src/nginxconfig/templates/app.vue +++ b/src/nginxconfig/templates/app.vue @@ -58,7 +58,7 @@ limitations under the License. <Global :data="global"></Global> <h2>Setup</h2> - <Setup :data="{ domains, global }"></Setup> + <Setup :data="{ domains, global, confFiles }"></Setup> </div> <div :class="`column ${splitColumn ? 'is-half' : 'is-full'} is-full-mobile is-full-tablet`"> diff --git a/src/nginxconfig/templates/setup.vue b/src/nginxconfig/templates/setup.vue index 3042a3f..57332fb 100644 --- a/src/nginxconfig/templates/setup.vue +++ b/src/nginxconfig/templates/setup.vue @@ -44,13 +44,17 @@ limitations under the License. </div> <div class="buttons is-centered"> - <a class="button is-success" @click="downloadZip">Download Config</a> - <a class="button is-primary" @click="copyZip">Copy Base64</a> + <a class="button is-success" @click="downloadTar">Download Config</a> + <a class="button is-primary" @click="copyTar">Copy Base64</a> </div> </div> </template> <script> + import { pack } from 'tar-stream'; + import getRawBody from 'raw-body'; + import { gzip } from 'node-gzip'; + import copy from 'copy-to-clipboard'; import * as Sections from './setup_sections'; const tabs = Object.values(Sections); @@ -82,9 +86,9 @@ limitations under the License. nginxDir() { return this.$props.data.global.nginx.nginxConfigDirectory.computed.replace(/\/+$/, ''); }, - zipName() { + tarName() { const domains = this.$props.data.domains.filter(d => d !== null).map(d => d.server.domain.computed); - return `nginxconfig.io-${domains.join(',')}.zip`; + return `nginxconfig.io-${domains.join(',')}.tar.gz`; }, }, methods: { @@ -94,12 +98,46 @@ limitations under the License. if (tabs.indexOf(tab) < tabs.indexOf(this.$data.active)) return 'is-before'; return undefined; }, - downloadZip() { - alert('Imagine I\'m a working download'); + async tarContents() { + const tar = pack(); + + // Add all our config files to the tar + for (const conf of this.$props.data.confFiles) { + tar.entry({ name: conf[0] }, conf[1]); + + // If symlinks are enabled and this is in sites-available, symlink to sites-enabled + if (this.$props.data.global.tools.symlinkVhost.computed && conf[0].startsWith('sites-available')) + tar.entry({ + name: conf[0].replace(/^sites-available/, 'sites-enabled'), + type: 'symlink', + linkname: `../${conf[0]}`, + }); + } + + // Convert the tar to a buffer and gzip it + tar.finalize(); + const raw = await getRawBody(tar); + return gzip(raw); }, - copyZip() { - const command = `echo 'BASE64 HERE' | base64 --decode > ${this.nginxDir}/${this.zipName}`; - alert(`Imagine I'm a working copy to clipboard\n\n${command}`); + async downloadTar() { + // Get the config files as a compressed tar + const contents = await this.tarContents(); + + // Convert it to a blob and download + const blob = new Blob([ contents ], { type: 'application/tar+gzip' }); + const link = document.createElement('a'); + link.href = window.URL.createObjectURL(blob); + link.download = this.tarName; + link.click(); + }, + async copyTar() { + // Get the config files as a compressed tar + const contents = await this.tarContents(); + + // Convert it to base64 string + const b64 = Buffer.from(contents).toString('base64'); + const command = `echo '${b64}' | base64 --decode > ${this.nginxDir}/${this.tarName}`; + copy(command); }, }, }; diff --git a/src/nginxconfig/templates/setup_sections/download.vue b/src/nginxconfig/templates/setup_sections/download.vue index 2dccecb..4a65058 100644 --- a/src/nginxconfig/templates/setup_sections/download.vue +++ b/src/nginxconfig/templates/setup_sections/download.vue @@ -3,24 +3,16 @@ <ol> <li> <p> - <b>Download</b> the generated config: <b><a @click="$parent.downloadZip">{{ $parent.zipName }}</a></b> + <b>Download</b> the generated config: <b><a @click="$parent.downloadTar">{{ $parent.tarName }}</a></b> <br /> and <b>upload</b> it to your server's <code class="slim">{{ $parent.nginxDir }}</code> directory. </p> <p> - or, <b><a @click="$parent.copyZip">Copy a base64 string of the compressed config</a></b>, paste it in + or, <b><a @click="$parent.copyTar">Copy a base64 string of the compressed config</a></b>, paste it in your server's command line and execute it. </p> </li> - <li> - <p> - Check that you have <b>unzip</b> installed, or install it, on your server by running this command: - <br /> - <Prism language="bash" code="(unzip -v >/dev/null 2>&1 && echo 'unzip already installed') || sudo apt-get install unzip"></Prism> - </p> - </li> - <li> <p> Navigate to your NGINX <b>configuration directory</b> on your server: @@ -39,9 +31,9 @@ <li> <p> - <b>Unzip</b> the new compressed configuration archive: + <b>Extract</b> the new compressed configuration archive using tar: <br /> - <Prism language="bash" :code="`unzip -o ${$parent.nginxDir}`"></Prism> + <Prism language="bash" :code="`tar -xzvf ${$parent.tarName}`"></Prism> </p> </li> </ol>