├── .gitignore ├── package.json ├── README.md ├── LICENSE ├── index.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | .env.* 2 | .env -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cloudxns2cloudflare", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "bluebird": "^3.5.0", 13 | "cloudflare": "^2.1.1", 14 | "lodash": "^4.17.4", 15 | "xml2js": "^0.4.19" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cloudxns2cloudflare 2 | =================== 3 | 4 | 事件: http://mp.weixin.qq.com/s/yGHn2PFN1XdvYz8xVsWmww 5 | 6 | 需要 Node 8。 7 | 8 | 1. `nvm use 8 && yarn` 9 | 1. 导出 CloudXNS 记录成 XML 格式。 10 | 1. 去 CloudFlare 添加域名,确保 DNS 记录为空,如果不为空就删光。 11 | 1. `export CLOUDFLARE_EMAIL=example@example.com` 12 | 1. `export CLOUDFLARE_KEY=MyGoalIsTheSeaOfStars` 13 | 1. `node index.js <域名> `,如 `node index.js orz.com xxx.xml`。 14 | 15 | 可惜,当然不支持私货啦,比如 LINK, AX, CNAMEX, 301跳转, 302跳转, 隐式跳转。 16 | 17 | 18 | Sponsor 19 | 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. 4 | 5 | In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | For more information, please refer to 10 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Promise = require('bluebird'); 3 | var fs = Promise.promisifyAll(require('fs')) 4 | var parseString = require('xml2js').parseString; 5 | 6 | var cf = require('cloudflare')({ 7 | email: process.env.CLOUDFLARE_EMAIL, 8 | key: process.env.CLOUDFLARE_KEY 9 | }); 10 | 11 | async function main() { 12 | let zones = await cf.zones.browse(); 13 | let zone = _.find(zones.result, { name: process.argv[2] }) 14 | //console.log(zone); 15 | if (!zone) throw new Error("zone not found"); 16 | 17 | let records = await cf.dnsRecords.browse(zone.id); 18 | if (records.result.length > 0) { 19 | console.log(records.result); 20 | throw new Error("already imported. please clean first"); 21 | } 22 | 23 | let xml = (await fs.readFileAsync(process.argv[3])).toString("utf-8"); 24 | let result = await Promise.fromNode((callback) => parseString(xml, callback)); 25 | let items = result.rdataset.rdata; 26 | 27 | for (var i = 0; i < items.length; i++) { 28 | let item = items[i]; 29 | console.log(item); 30 | await cf.dnsRecords.add(zone.id, { 31 | type: item.type[0], 32 | name: item.host[0], 33 | content: item.rd_data[0], 34 | ttl: item.rdata_ttl[0], 35 | priority: item.rr_pref[0] != 'N/A' ? item.rr_pref[0] : undefined, 36 | proxied: false, 37 | }); 38 | } 39 | } 40 | 41 | 42 | main().catch((e) => { 43 | console.error(e) 44 | }) -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | autocreate@^1.1.0: 6 | version "1.1.0" 7 | resolved "https://registry.yarnpkg.com/autocreate/-/autocreate-1.1.0.tgz#d85351fea404ea73ccd1d661c02877e96f0f090d" 8 | 9 | bluebird@^3.5.0: 10 | version "3.5.0" 11 | resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c" 12 | 13 | capture-stack-trace@^1.0.0: 14 | version "1.0.0" 15 | resolved "https://registry.yarnpkg.com/capture-stack-trace/-/capture-stack-trace-1.0.0.tgz#4a6fa07399c26bba47f0b2496b4d0fb408c5550d" 16 | 17 | cloudflare@^2.1.1: 18 | version "2.1.1" 19 | resolved "https://registry.yarnpkg.com/cloudflare/-/cloudflare-2.1.1.tgz#09942bfc48776e1256c96e05b592a3239f6719e1" 20 | dependencies: 21 | autocreate "^1.1.0" 22 | es-class "^2.1.1" 23 | got "^6.3.0" 24 | object-assign "^4.1.0" 25 | url-join "^1.1.0" 26 | url-pattern "^1.0.3" 27 | 28 | create-error-class@^3.0.0: 29 | version "3.0.2" 30 | resolved "https://registry.yarnpkg.com/create-error-class/-/create-error-class-3.0.2.tgz#06be7abef947a3f14a30fd610671d401bca8b7b6" 31 | dependencies: 32 | capture-stack-trace "^1.0.0" 33 | 34 | duplexer3@^0.1.4: 35 | version "0.1.4" 36 | resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" 37 | 38 | es-class@^2.1.1: 39 | version "2.1.1" 40 | resolved "https://registry.yarnpkg.com/es-class/-/es-class-2.1.1.tgz#6ec2243b5a1e3581c0b7eecee0130c9c0d6fb2b7" 41 | 42 | get-stream@^3.0.0: 43 | version "3.0.0" 44 | resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" 45 | 46 | got@^6.3.0: 47 | version "6.7.1" 48 | resolved "https://registry.yarnpkg.com/got/-/got-6.7.1.tgz#240cd05785a9a18e561dc1b44b41c763ef1e8db0" 49 | dependencies: 50 | create-error-class "^3.0.0" 51 | duplexer3 "^0.1.4" 52 | get-stream "^3.0.0" 53 | is-redirect "^1.0.0" 54 | is-retry-allowed "^1.0.0" 55 | is-stream "^1.0.0" 56 | lowercase-keys "^1.0.0" 57 | safe-buffer "^5.0.1" 58 | timed-out "^4.0.0" 59 | unzip-response "^2.0.1" 60 | url-parse-lax "^1.0.0" 61 | 62 | is-redirect@^1.0.0: 63 | version "1.0.0" 64 | resolved "https://registry.yarnpkg.com/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24" 65 | 66 | is-retry-allowed@^1.0.0: 67 | version "1.1.0" 68 | resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz#11a060568b67339444033d0125a61a20d564fb34" 69 | 70 | is-stream@^1.0.0: 71 | version "1.1.0" 72 | resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" 73 | 74 | lodash@^4.17.4: 75 | version "4.17.4" 76 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" 77 | 78 | lowercase-keys@^1.0.0: 79 | version "1.0.0" 80 | resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306" 81 | 82 | object-assign@^4.1.0: 83 | version "4.1.1" 84 | resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" 85 | 86 | prepend-http@^1.0.1: 87 | version "1.0.4" 88 | resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" 89 | 90 | safe-buffer@^5.0.1: 91 | version "5.1.1" 92 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" 93 | 94 | sax@>=0.6.0: 95 | version "1.2.4" 96 | resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" 97 | 98 | timed-out@^4.0.0: 99 | version "4.0.1" 100 | resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f" 101 | 102 | unzip-response@^2.0.1: 103 | version "2.0.1" 104 | resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97" 105 | 106 | url-join@^1.1.0: 107 | version "1.1.0" 108 | resolved "https://registry.yarnpkg.com/url-join/-/url-join-1.1.0.tgz#741c6c2f4596c4830d6718460920d0c92202dc78" 109 | 110 | url-parse-lax@^1.0.0: 111 | version "1.0.0" 112 | resolved "https://registry.yarnpkg.com/url-parse-lax/-/url-parse-lax-1.0.0.tgz#7af8f303645e9bd79a272e7a14ac68bc0609da73" 113 | dependencies: 114 | prepend-http "^1.0.1" 115 | 116 | url-pattern@^1.0.3: 117 | version "1.0.3" 118 | resolved "https://registry.yarnpkg.com/url-pattern/-/url-pattern-1.0.3.tgz#0409292471b24f23c50d65a47931793d2b5acfc1" 119 | 120 | xml2js@^0.4.19: 121 | version "0.4.19" 122 | resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.19.tgz#686c20f213209e94abf0d1bcf1efaa291c7827a7" 123 | dependencies: 124 | sax ">=0.6.0" 125 | xmlbuilder "~9.0.1" 126 | 127 | xmlbuilder@~9.0.1: 128 | version "9.0.4" 129 | resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.4.tgz#519cb4ca686d005a8420d3496f3f0caeecca580f" 130 | --------------------------------------------------------------------------------