Apart from reading the server and host configuration files,
tinc can also run scripts at certain moments.
Under Windows (not Cygwin), the scripts should have the extension
-.Pa .bat .
+.Pa .bat
+or
+.Pa cmd .
.Bl -tag -width indent
.It Pa @sysconfdir@/tinc/ Ns Ar NETNAME Ns Pa /tinc-up
This is the most important script.
The Subnet and the node it belongs to are passed in environment variables.
.It Pa @sysconfdir@/tinc/ Ns Ar NETNAME Ns Pa /subnet-down
This script is started when a Subnet becomes unreachable.
+.It Pa @sysconfdir@/tinc/ Ns Ar NETNAME Ns Pa /invitation-created
+This script is started when a new invitation has been created.
+.It Pa @sysconfdir@/tinc/ Ns Ar NETNAME Ns Pa /invitation-accepted
+This script is started when an invitation has been used.
.El
.Pp
The scripts are started without command line arguments, but can make use of certain environment variables.
in scripts.
Under Windows, in
.Pa .bat
+or
+.Pa .cmd
files, they have to be put between
.Li %
signs.
When a subnet becomes (un)reachable, this is set to the subnet.
.It Ev WEIGHT
When a subnet becomes (un)reachable, this is set to the subnet weight.
+.It Ev INVITATION_FILE
+When the
+.Pa invitation-created
+script is called, this is set to the file where the invitation details will be stored.
+.It Ev INVITATION_URL
+When the
+.Pa invitation-created
+script is called, this is set to the invitation URL that has been created.
.El
.Pp
Do not forget that under UNIX operating systems, you have to make the scripts executable, using the command
@item @value{sysconfdir}/tinc/@var{netname}/subnet-down
This script is started when a Subnet becomes unreachable.
+
+@item @value{sysconfdir}/tinc/@var{netname}/invitation-created
+This script is started when a new invitation has been created.
+
+@item @value{sysconfdir}/tinc/@var{netname}/invitation-accepted
+This script is started when an invitation has been used.
+
@end table
@cindex environment variables
@item SUBNET
When a subnet becomes (un)reachable, this is set to the subnet.
+@cindex WEIGHT
+@item WEIGHT
+When a subnet becomes (un)reachable, this is set to the subnet weight.
+
+@cindex INVITATION_FILE
+@item INVITATION_FILE
+When the @file{invitation-created} script is called,
+this is set to the file where the invitation details will be stored.
+
+@cindex INVITATION_URL
+@item INVITATION_URL
+When the @file{invitation-created} script is called,
+this is set to the invitation URL that has been created.
@end table
+Do not forget that under UNIX operating systems,
+you have to make the scripts executable, using the command @samp{chmod a+x script}.
+
@c ==================================================================
@node How to configure
free(filename);
return 1;
}
- free(filename);
f = fdopen(ifd, "w");
if(!f)
abort();
fprintf(f, "#---------------------------------------------------------------#\n");
fprintf(f, "Name = %s\n", myname);
- xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, myname);
- fcopy(f, filename);
+ char *filename2;
+ xasprintf(&filename2, "%s" SLASH "hosts" SLASH "%s", confbase, myname);
+ fcopy(f, filename2);
fclose(f);
+ free(filename2);
// Create an URL from the local address, key hash and cookie
- printf("%s/%s%s\n", address, hash, cookie);
+ char *url;
+ xasprintf(&url, "%s/%s%s", address, hash, cookie);
+
+ // Call the inviation-created script
+ setenv("NAME", myname, true);
+ setenv("NETNAME", netname, true);
+ setenv("NODE", argv[1], true);
+ setenv("INVITATION_FILE", filename, true);
+ setenv("INVITATION_URL", url, true);
+ char *scriptname;
+ xasprintf(&scriptname, "\"%s" SLASH "invitation-created\"", confbase);
+ system(scriptname);
+ free(scriptname);
+ unsetenv("NODE");
+ unsetenv("INVITATION");
+
+ puts(url);
+ free(url);
free(filename);
free(address);
#include "control_common.h"
#include "cipher.h"
#include "crypto.h"
+#include "device.h"
#include "digest.h"
#include "ecdsa.h"
#include "edge.h"
#include "netutl.h"
#include "node.h"
#include "prf.h"
+#include "process.h"
#include "protocol.h"
#include "rsa.h"
#include "sptps.h"
fclose(f);
logger(DEBUG_CONNECTIONS, LOG_INFO, "Key succesfully received from %s (%s)", c->name, c->hostname);
+
+ // Call invitation-accepted script
+ char *envp[7] = {NULL};
+ char *address, *port;
+
+ xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
+ xasprintf(&envp[1], "DEVICE=%s", device ? : "");
+ xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
+ xasprintf(&envp[3], "NODE=%s", c->name);
+ sockaddr2str(&c->address, &address, &port);
+ xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
+ xasprintf(&envp[5], "NAME=%s", myself->name);
+
+ execute_script("invitation-accepted", envp);
+
+ for(int i = 0; envp[i] && i < 7; i++)
+ free(envp[i]);
+
sptps_send_record(&c->sptps, 2, data, 0);
return true;
}