summaryrefslogtreecommitdiff
path: root/attic/netconf-service/initdb.js
blob: 813cc04a3e2d6c4d0940378e07cdc703e1e61dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Populates a new Redis database with data, which can be edited below.
 */

var INIT_DATA = {
	// Must be present in any database
	"zt1": 1,

	/* The network ID here must be set to the ZeroTier address of your netconf
	 * master (the node where netconf-master will be running) plus an arbitrary
	 * 24-bit network ID. This will create the full 16-digit network ID of the
	 * network you will join. This must be in the object name and in the "id"
	 * field within the object itself. */
	"zt1:network:31443a1a0a111111:~": {
		"id": "31443a1a0a111111",           // netconf master ZT address + 24-bit ID
		"name": "zerotier-testnet",         // short name, no spaces or special chars
		"desc": "Test Network",             // description
		"infrastructure": 0,                // unused by netconf-master
		"private": 0,                       // set to '1' to require member approval
		"creationTime": 0,                  // unused by netconf-master
		"owner": "",                        // unused by netconf-master
		"etherTypes": "0800,0806",          // hex ethernet frame types allowed
		"enableBroadcast": 1,               // set to '1' to enable ff:ff:ff:ff:ff:ff
		"v4AssignMode": "zt",               // 'zt' to assign, 'none' to let OS do it
		"v4AssignPool": "192.168.123.0/24", // IPv4 net block / netmask bits
		"v6AssignMode": "none"              // 'zt' to assign, 'none' to let OS do it
	}
};

var config = require('./config.js');

var async = require('async');
var redis = require('redis');
var DB = redis.createClient();
DB.on("error",function(err) { console.error('redis query error: '+err); });
DB.select(config.redisDb,function() {});

DB.get("zt1",function(err,value) {
	if ((value)&&(!err)) {
		console.log("Redis database #"+config.redisDb+" appears to already contain data; flush it first!");
		return process.exit(0);
	}

	async.eachSeries(Object.keys(INIT_DATA),function(key,next) {
		var value = INIT_DATA[key];
		if (typeof value === 'object') {
			console.log(key);
			async.eachSeries(Object.keys(value),function(hkey,next2) {
				var hvalue = value[hkey];
				if (hvalue === true)
					hvalue = 1;
				if (hvalue === false)
					hvalue = 0;
				if (typeof hvalue !== 'string')
					hvalue = hvalue.toString();
				console.log('\t'+hkey+': '+hvalue);
				DB.hset(key,hkey,hvalue,next2);
			},next);
		} else if ((typeof value !== 'undefined')&&(value !== null)) {
			if (value === true)
				value = 1;
			if (value === false)
				value = 0;
			if (typeof value !== 'string')
				value = value.toString();
			console.log(key+': '+value);
			DB.set(key,value,next);
		} else return next(null);
	},function(err) {
		console.log('Done!');
		return process.exit(0);
	});
});