summaryrefslogtreecommitdiff
path: root/netconf-plugin
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-07-31 17:24:59 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-07-31 17:24:59 -0400
commitf260c2839c73afa9898547398e1911c585904132 (patch)
tree0e4b1f9880bc9c42ea0a4bfef1007a41e8050f86 /netconf-plugin
parent2ba97fb46b1b405161a3d391842566b057800f4c (diff)
downloadinfinitytier-f260c2839c73afa9898547398e1911c585904132.tar.gz
infinitytier-f260c2839c73afa9898547398e1911c585904132.zip
Local service plugin stuff... work in progress.
Diffstat (limited to 'netconf-plugin')
-rw-r--r--netconf-plugin/Makefile0
-rw-r--r--netconf-plugin/netconf.cpp127
2 files changed, 127 insertions, 0 deletions
diff --git a/netconf-plugin/Makefile b/netconf-plugin/Makefile
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/netconf-plugin/Makefile
diff --git a/netconf-plugin/netconf.cpp b/netconf-plugin/netconf.cpp
new file mode 100644
index 00000000..57d3653b
--- /dev/null
+++ b/netconf-plugin/netconf.cpp
@@ -0,0 +1,127 @@
+/*
+ * ZeroTier One - Global Peer to Peer Ethernet
+ * Copyright (C) 2012-2013 ZeroTier Networks LLC
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+/*
+ * This is the netconf service. It's currently used only by netconf nodes that
+ * are run by ZeroTier itself. There is nothing to prevent you from running
+ * your own if you wanted to create your own networks outside our system.
+ *
+ * That being said, we'd like to charge for private networks to support
+ * ZeroTier One and future development efforts. So while this software is
+ * open source and we're not going to stop you from sidestepping this, we
+ * do ask -- honor system here -- that you pay for private networks if you
+ * are going to use them for any commercial purpose such as a business VPN
+ * alternative.
+ *
+ * This will at the moment only build on Linux and requires the mysql++
+ * library, which is available here:
+ *
+ * http://tangentsoft.net/mysql++/
+ *
+ * (Packages are available for CentOS via EPEL and for any Debian distro.)
+ *
+ * This program must be built and installed in the services.d subfolder of
+ * the ZeroTier One home folder of the node designated to act as a master
+ * for networks. Doing so will enable the NETWORK_CONFIG_REQUEST protocol
+ * verb.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <iostream>
+#include <string>
+#include <map>
+#include <list>
+#include <vector>
+#include <algorithm>
+
+#include <mysql++.h>
+
+#include "../node/Dictionary.hpp"
+
+using namespace ZeroTier;
+using namespace mysqlpp;
+
+static Connection *dbCon = (Connection *)0;
+
+static void connectOrReconnect()
+{
+ if (dbCon)
+ delete dbCon;
+ dbCon = new Connection(mysqlDatabase,mysqlHost,mysqlUser,mysqlPassword,(unsigned int)strtol(mysqlPort,(char **)0,10));
+ if (dbCon->connected())
+ break;
+ else {
+ fprintf(stderr,"Unable to connect to database server.\n");
+ usleep(1000);
+ }
+}
+
+int main(int argc,char **argv)
+{
+ char mysqlHost[64],mysqlPort[64],mysqlDatabase[64],mysqlUser[64],mysqlPassword[64];
+
+ {
+ char *ee = getenv("ZT_NETCONF_MYSQL_HOST");
+ if (!ee) {
+ fprintf(stderr,"Missing environment variable: ZT_NETCONF_MYSQL_HOST\n");
+ return -1;
+ }
+ strcpy(mysqlHost,ee);
+ ee = getenv("ZT_NETCONF_MYSQL_PORT");
+ if (ee == null)
+ strcpy(mysqlPort,"3306");
+ else strcpy(mysqlPort,ee);
+ ee = getenv("ZT_NETCONF_MYSQL_DATABASE");
+ if (!ee) {
+ fprintf(stderr,"Missing environment variable: ZT_NETCONF_MYSQL_DATABASE\n");
+ return -1;
+ }
+ strcpy(mysqlDatabase,ee);
+ ee = getenv("ZT_NETCONF_MYSQL_USER");
+ if (!ee) {
+ fprintf(stderr,"Missing environment variable: ZT_NETCONF_MYSQL_USER\n");
+ return -1;
+ }
+ strcpy(mysqlUser,ee);
+ ee = getenv("ZT_NETCONF_MYSQL_PASSWORD");
+ if (!ee) {
+ fprintf(stderr,"Missing environment variable: ZT_NETCONF_MYSQL_PASSWORD\n");
+ return -1;
+ }
+ strcpy(mysqlPassword,ee);
+ }
+
+ connectOrReconnect();
+ for(;;) {
+ if (!dbCon->connected())
+ connectOrReconnect();
+ }
+}