Advertisement
westor

geoip_tag

Mar 30th, 2022
2,549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *   IRC - Internet Relay Chat, src/modules/geoip-tag.c
  3.  *   (C) 2020 Syzop & The UnrealIRCd Team
  4.  *
  5.  *   See file AUTHORS in IRC package for additional names of
  6.  *   the programmers.
  7.  *
  8.  *   This program is free software; you can redistribute it and/or modify
  9.  *   it under the terms of the GNU General Public License as published by
  10.  *   the Free Software Foundation; either version 1, or (at your option)
  11.  *   any later version.
  12.  *
  13.  *   This program is distributed in the hope that it will be useful,
  14.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *   GNU General Public License for more details.
  17.  *
  18.  *   You should have received a copy of the GNU General Public License
  19.  *   along with this program; if not, write to the Free Software
  20.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include "unrealircd.h"
  24.  
  25. ModuleHeader MOD_HEADER
  26.   = {
  27.     "geoip-tag",
  28.     "5.0",
  29.     "geoip message tag",
  30.     "UnrealIRCd Team",
  31.     "unrealircd-6",
  32.     };
  33.  
  34. /* Variables */
  35. long CAP_ACCOUNT_TAG = 0L;
  36. // No idea if this needs somewhere
  37. // (same having account-tag + userip-tag + userhost-tag modules but only in account-tag is being used)
  38.  
  39. int geoip_mtag_is_ok(Client *client, const char *name, const char *value);
  40. int geoip_mtag_should_send_to_client(Client *target);
  41. void mtag_add_geoip(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
  42.  
  43. MOD_INIT()
  44. {
  45.     MessageTagHandlerInfo mtag;
  46.  
  47.     MARK_AS_OFFICIAL_MODULE(modinfo);
  48.  
  49.     memset(&mtag, 0, sizeof(mtag));
  50.     mtag.name = "unrealircd.org/geoip";
  51.     mtag.is_ok = geoip_mtag_is_ok;
  52.     mtag.should_send_to_client = geoip_mtag_should_send_to_client;
  53.     mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
  54.     MessageTagHandlerAdd(modinfo->handle, &mtag);
  55.  
  56.     HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_geoip);
  57.  
  58.     return MOD_SUCCESS;
  59. }
  60.  
  61. MOD_LOAD()
  62. {
  63.     return MOD_SUCCESS;
  64. }
  65.  
  66. MOD_UNLOAD()
  67. {
  68.     return MOD_SUCCESS;
  69. }
  70.  
  71. /** This function verifies if the client sending
  72.  * 'geoip-tag' is permitted to do so and uses a permitted
  73.  * syntax.
  74.  * We simply allow geoip-tag ONLY from servers and with any syntax.
  75.  */
  76. int geoip_mtag_is_ok(Client *client, const char *name, const char *value)
  77. {
  78.     if (IsServer(client))
  79.         return 1;
  80.  
  81.     return 0;
  82. }
  83.  
  84. void mtag_add_geoip(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
  85. {
  86.     MessageTag *m;
  87.    
  88.     GeoIPResult *geoip = geoip_lookup(client->ip);
  89.     // geoip_lookup(client->ip); OR geoip_client(client); ?????????
  90.  
  91.     if (IsUser(client) && geoip)
  92.     {
  93.         MessageTag *m = find_mtag(recv_mtags, "unrealircd.org/geoip");
  94.         if (m)
  95.         {
  96.             m = duplicate_mtag(m);
  97.         } else {
  98.             m = safe_alloc(sizeof(MessageTag));
  99.             safe_strdup(m->name, "unrealircd.org/geoip");
  100.             safe_strdup(m->value, geoip->country_code);
  101.         }
  102.         AddListItem(m, *mtag_list);
  103.     }
  104. }
  105.  
  106. /** Outgoing filter for this message tag */
  107. int geoip_mtag_should_send_to_client(Client *target)
  108. {
  109.     if (IsServer(target) || IsOper(target))
  110.         return 1;
  111.     return 0;
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement