- char cmd[2048];
-
- if (!s) return 0;
- if (!s->opened) return 0;
-
- /* Note that we don't handle throttling/snooping/etc here
- * To do that, we'd need to send an end accounting record
- * then a radius auth, then start accouting again.
- * That means that we need the password (which garden has)
- * and a lot of code to check that the new set of params
- * (routes, IP, ACLs, etc) 'matched' the old one in a
- * 'compatable' way. (ie user's system doesn't need to be told
- * of the change)
- *
- * Thats a lot of pain/code for very little gain.
- * If we want them redone from scratch, just sessionkill them -
- * a user on garden isn't going to have any open TCP
- * connections which are worth caring about, anyway.
- *
- * Note that the user will be rethrottled shortly by the scan
- * script thingy if appropriate.
- *
- * Currently, garden only directly ungardens someone if
- * they haven't paid their bill, and then subsequently do so
- * online. This isn't something which can be set up by a malicious
- * customer at will.
- */
- if (flag == 1)
+ int i;
+ iam_master = 1; // We just became the master. Wow!
+
+ for (i = 0; up_commands[i] && *up_commands[i]; i++)
+ {
+ f->log(3, 0, 0, "Running %s\n", up_commands[i]);
+ if (-1 == system(up_commands[i])) f->log(0, 0, 0, "error command %s\n", up_commands[i]);
+ }
+
+ return PLUGIN_RET_OK;
+}
+
+// Called for each active session after becoming master
+int plugin_new_session_master(sessiont *s)
+{
+ if (s->walled_garden)
+ garden_session(s, F_GARDEN, 0);
+
+ return PLUGIN_RET_OK;
+}
+
+int garden_session(sessiont *s, int flag, char *newuser)
+{
+ char cmd[2048];
+ sessionidt sess;
+ int status;
+
+ if (!s) return 0;
+ if (!s->opened) return 0;
+
+ sess = f->get_id_by_session(s);
+ if (flag == F_GARDEN)
+ {
+ f->log(2, sess, s->tunnel, "Garden user %s (%s)\n", s->user,
+ f->fmtaddr(htonl(s->ip), 0));
+
+ snprintf(cmd, sizeof(cmd),
+ "iptables -t nat -A garden_users -s %s -j garden",
+ f->fmtaddr(htonl(s->ip), 0));
+
+ f->log(3, sess, s->tunnel, "%s\n", cmd);
+ status = system(cmd);
+ s->walled_garden = 1;
+ }
+ else
+ {
+ sessionidt other;
+ int count = 40;
+
+ // Normal User
+ f->log(2, sess, s->tunnel, "Un-Garden user %s (%s)\n", s->user, f->fmtaddr(htonl(s->ip), 0));
+ if (newuser)