+#define _XOPEN_SOURCE 500
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <fcntl.h>
+#include <ftw.h>
#include "setuid.h"
#include "netutil.h"
#include "libsmooth.h"
typedef struct connection_struct connection;
+static int recursive_remove_callback(const char* fpath, const struct stat* sb, int typeflag, struct FTW* ftwbuf) {
+ int rv = remove(fpath);
+ if (rv)
+ perror(fpath);
+
+ return rv;
+}
+
+static int recursive_remove(const char* path) {
+ return nftw(path, recursive_remove_callback, 64, FTW_DEPTH | FTW_PHYS);
+}
+
void exithandler(void)
{
if(kv)
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
-
+
if (strcmp(enableblue, "on") == 0) {
if (!findkey(kv, "BLUE_DEV", blueif)) {
exit(1);
exit(1);
}
- /* we got one device, so lets proceed further */
+ /* we got one device, so lets proceed further */
if (!findkey(kv, "DDEST_PORT", dport)){
fprintf(stderr, "Cannot read DDEST_PORT\n");
exit(1);
void startDaemon(void) {
char command[STRING_SIZE];
-
+
if (!((strcmp(enablered, "on") == 0) || (strcmp(enableblue, "on") == 0) || (strcmp(enableorange, "on") == 0))) {
fprintf(stderr, "OpenVPN is not enabled on any interface\n");
exit(1);
int killNet2Net(char *name) {
connection *conn = NULL;
connection *conn_iter;
+ int rc = 0;
conn_iter = getConnections();
snprintf(command, STRING_SIZE - 1, "/bin/rm -f %s", pidfile);
executeCommand(command);
+ char runfile[STRING_SIZE];
+ snprintf(runfile, STRING_SIZE - 1, "/var/run/openvpn/%s-n2n", conn->name);
+ rc = recursive_remove(runfile);
+ if (rc)
+ perror(runfile);
+
return 0;
}
int deleterrd(char *name) {
+ char rrd_dir[STRING_SIZE];
+
connection *conn = getConnections();
+ while(conn) {
+ if (strcmp(conn->name, name) != 0) {
+ conn = conn->next;
+ continue;
+ }
- char rrd_file[STRING_SIZE];
- snprintf(rrd_file, STRING_SIZE - 1, "/var/log/rrd/collectd/localhost/openvpn-%s/if_octets.rrd", name);
+ // Handle RW connections
+ if (strcmp(conn->type, "host") == 0) {
+ snprintf(rrd_dir, STRING_SIZE - 1, "/var/log/rrd/collectd/localhost/openvpn-%s/", name);
- char rrd_dir[STRING_SIZE];
- snprintf(rrd_dir, STRING_SIZE - 1, "/var/log/rrd/collectd/localhost/openvpn-%s", name);
+ // Handle N2N connections
+ } else if (strcmp(conn->type, "net") == 0) {
+ snprintf(rrd_dir, STRING_SIZE - 1, "/var/log/rrd/collectd/localhost/openvpn-%s-n2n/", name);
- while(conn) {
- /* Find only RW-Connections with the given name. */
- if (((strcmp(conn->type, "host") == 0) && (strcmp(conn->name, name) == 0))) {
- remove(rrd_file);
- remove(rrd_dir);
- return 0;
+ // Unhandled connection type
+ } else {
+ conn = conn->next;
+ continue;
}
- conn = conn->next;
+
+ return recursive_remove(rrd_dir);
}
return 1;
}
else {
ovpnInit();
-
+
if( (strcmp(argv[1], "-s") == 0) || (strcmp(argv[1], "--start") == 0) ) {
setFirewallRules();
startDaemon();