+ unsigned int i;
+ struct userData *uData;
+ struct chanData *cData;
+ struct chanInfo *cInfo;
+ struct trusted_account *ta;
+ struct string_list *templist;
+ struct handle_info *hi;
+
+ if (!(channel = GetChannel(argv[2]))) {
+ ss_reply("SSMSG_NOT_REGISTERED", argv[2]);
+ return 0;
+ }
+
+ cInfo = get_chanInfo(channel->name);
+ cData = channel->channel_info;
+ uData = GetChannelUser(cData, user->handle_info);
+
+ if (!cInfo || !channel->channel_info) {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if (CHECK_SUSPENDED(cInfo)) {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if (!uData || (uData->access < UL_MANAGER)) {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ if (!(hi = modcmd_get_handle_info(user, argv[1]))) {
+ return 0;
+ }
+
+ if ((ta = dict_find(spamserv_trusted_accounts, argv[1], NULL))) {
+ if (ta->channel->used && (argc > 1)) {
+ for (i=0; i < ta->channel->used; i++) {
+ if (!strcmp(ta->channel->list[i], argv[2])) {
+ ss_reply("SSMSG_ALREADY_TRUSTED", hi->handle);
+ return 0;
+ }
+ }
+ }
+
+ string_list_append(ta->channel, argv[2]);
+ ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi->handle, argv[2]);
+ return 1;
+ }
+
+ templist = alloc_string_list(sizeof(argv[2])+1);
+// templist = alloc_string_list(1);
+ string_list_append(templist, argv[2]);
+
+ spamserv_add_trusted_account(hi->handle, templist, user->handle_info->handle, now);
+ ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi->handle, argv[2]);
+ return 1;
+}
+
+static SPAMSERV_FUNC(cmd_oaddtrust)
+{
+ unsigned int i, global = 0;
+ struct chanInfo *cInfo;
+ struct chanData *cData;
+ struct trusted_account *ta;
+ struct string_list *templist;
+ struct handle_info *hi;
+
+ if (!strcmp(argv[2], "global"))
+ global = 1;
+
+ if (!(channel = GetChannel(argv[2])) && (global == 0)) {
+ ss_reply("SSMSG_NOT_REGISTERED", channel ? channel->name : (global ? "global" : ""));
+ return 0;
+ }
+
+ if (channel) {
+ cInfo = get_chanInfo(channel->name);
+ cData = channel->channel_info;
+
+ if (!cInfo || !cData) {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+ }
+
+ if (!(hi = modcmd_get_handle_info(user, argv[1]))) {
+ return 0;
+ }
+
+ if ((ta = dict_find(spamserv_trusted_accounts, argv[1], NULL))) {
+ if (ta->channel->used && (argc > 1)) {
+ for (i=0; i < ta->channel->used; i++) {
+ if (!strcmp(ta->channel->list[i], argv[2])) {
+ ss_reply("SSMSG_ALREADY_TRUSTED", argv[1]);
+ return 0;
+ }
+ }
+ }
+
+ string_list_append(ta->channel, argv[2]);
+
+ if (global == 1)
+ ss_reply("SSMSG_ADDED_TRUSTED", argv[1]);
+ else
+ ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", argv[1], argv[2]);
+
+ return 1;
+ }
+
+ templist = alloc_string_list(sizeof(argv[2])+1);
+// templist = alloc_string_list(1);
+ string_list_append(templist, argv[2]);
+
+ spamserv_add_trusted_account(hi->handle, templist, user->handle_info->handle, now);
+
+ if (global == 1)
+ ss_reply("SSMSG_ADDED_TRUSTED", hi->handle);
+ else
+ ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi->handle, argv[2]);
+
+ return 1;
+}
+
+static SPAMSERV_FUNC(cmd_deltrust)
+{
+ unsigned int i;
+ int rem = 0;
+ struct trusted_account *ta;
+ struct userData *uData;
+ struct chanData *cData;
+ struct chanInfo *cInfo;
+ struct handle_info *hi;
+
+ if (!(channel = GetChannel(argv[2]))) {
+ ss_reply("SSMSG_NOT_REGISTERED", argv[2]);
+ return 0;
+ }
+
+ cInfo = get_chanInfo(channel->name);
+ cData = channel->channel_info;
+ uData = GetChannelUser(cData, user->handle_info);
+
+ if (!cInfo || !channel->channel_info) {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if (CHECK_SUSPENDED(cInfo)) {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if (!uData || (uData->access < UL_MANAGER)) {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ if (!(hi = modcmd_get_handle_info(user, argv[1]))) {
+ return 0;
+ }
+
+ ta = dict_find(spamserv_trusted_accounts, hi->handle, NULL);
+
+ if (!ta) {
+ ss_reply("SSMSG_NOT_TRUSTED", argv[2]);
+ return 0;
+ }
+
+ if (argc > 1) {
+ if (ta->channel->used) {
+ for (i=0; i < ta->channel->used; i++) {
+ if (!strcmp(ta->channel->list[i], argv[2])) {
+ string_list_delete(ta->channel, i);
+ rem = 1;
+ }
+ }
+ }
+
+ if (rem == 1)
+ ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi->handle, argv[2]);
+ else {
+ ss_reply("SSMSG_NOT_TRUSTED", hi->handle, argv[2]);
+ return 0;
+ }
+ } else {
+ dict_remove(spamserv_trusted_accounts, hi->handle);
+ ss_reply("SSMSG_REMOVED_TRUSTED", hi->handle);
+ }
+
+ return 1;
+}
+
+static SPAMSERV_FUNC(cmd_odeltrust)
+{
+ unsigned int i;
+ int rem = 0, global = 0;
+ struct trusted_account *ta;
+ struct chanInfo *cInfo;
+ struct chanData *cData;
+ struct handle_info *hi;
+
+ if (!strcmp(argv[2], "global"))
+ global = 1;
+
+ if (!(channel = GetChannel(argv[2])) && (global == 0)) {
+ ss_reply("SSMSG_NOT_REGISTERED", channel ? channel->name : (global ? "global" : ""));
+ return 0;
+ }
+
+ if (channel) {
+ cInfo = get_chanInfo(channel->name);
+ cData = channel->channel_info;
+
+ if (!cInfo || !cData) {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+ }
+
+ if (!(hi = modcmd_get_handle_info(user, argv[1]))) {
+ return 0;
+ }
+
+ ta = dict_find(spamserv_trusted_accounts, hi->handle, NULL);
+
+ if (!ta) {
+ ss_reply("SSMSG_NOT_TRUSTED", argv[2]);
+ return 0;
+ }
+
+ if (argc > 1) {
+ if (ta->channel->used) {
+ for (i=0; i < ta->channel->used; i++) {
+ if (!strcmp(ta->channel->list[i], argv[2])) {
+ string_list_delete(ta->channel, i);
+ rem = 1;
+ }
+ }
+ }
+
+ if (rem == 1)
+ ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi->handle, argv[2]);
+ else {
+ ss_reply("SSMSG_NOT_TRUSTED", argv[2]);
+ return 0;
+ }
+ } else {
+ dict_remove(spamserv_trusted_accounts, hi->handle);
+ ss_reply("SSMSG_REMOVED_TRUSTED", hi->handle);
+ }
+
+ return 1;
+}
+
+static SPAMSERV_FUNC(cmd_listtrust) {
+ dict_iterator_t it;
+ struct trusted_account *ta;
+ char issued[INTERVALLEN];
+ char *chan;
+ unsigned int i;
+
+ if (argc > 0) {
+ if (!strcmp(argv[1], "global")) {
+ if (!IsHelping(user)) {
+ reply("SSMSG_MUST_BE_HELPING");
+ return 0;
+ } else
+ chan = "global";
+ } else {
+ channel = GetChannel(argv[1]);
+ if (channel)
+ chan = strdup(channel->name);
+ else {
+ ss_reply("SSMSG_NOT_REGISTERED", argv[1]);
+ return 0;
+ }
+ }
+ } else {
+ reply("MSG_INVALID_CHANNEL");
+ return 0;
+ }
+
+ reply("SSMSG_TRUSTED_LIST");
+ reply("SSMSG_TRUSTED_LIST_BAR");
+ reply("SSMSG_TRUSTED_LIST_HEADER");
+ reply("SSMSG_TRUSTED_LIST_BAR");
+ for (it = dict_first(spamserv_trusted_accounts); it; it = iter_next(it)) {
+ ta = iter_data(it);
+
+ if (ta->channel->used) {
+ for (i=0; i < ta->channel->used; i++) {
+
+ if (!strcmp(ta->channel->list[i], chan)) {
+ if (ta->issued)
+ intervalString(issued, now - ta->issued, user->handle_info);
+
+ ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it),
+ (ta->issuer ? ta->issuer : "<unknown>"),
+ (ta->issued ? issued : "some time"));
+
+ } else if (!strcmp(ta->channel->list[i], "global") && (!strcmp(chan, "global"))) {
+ if (ta->issued)
+ intervalString(issued, now - ta->issued, user->handle_info);
+
+ ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it),
+ (ta->issuer ? ta->issuer : "<unknown>"),
+ (ta->issued ? issued : 0));
+ }
+ }
+ }
+ }
+ ss_reply("SSMSG_TRUSTED_LIST_END");
+ return 1;