]> jfr.im git - irc/quakenet/newserv.git/blob - proxyscan/proxyscan.h
Merge pull request #132 from retropc/lua_country
[irc/quakenet/newserv.git] / proxyscan / proxyscan.h
1
2 #ifndef __PROXYSCAN_H
3 #define __PROXYSCAN_H
4
5 #include "../nick/nick.h"
6 #include "../lib/splitline.h"
7 #include <time.h>
8 #include <stdint.h>
9
10 /* string seen when:
11 * - a HTTP/SOCKS/... proxy connects directly to our listener (because we told it to)
12 * - it's a proxy that forwards directly to a QuakeNet ircd (we get this because we sent PRIVMSG)
13 */
14 #define MAGICSTRING ".quakenet.org 451 * :Register first.\r\n"
15 #define MAGICSTRINGLENGTH (sizeof(MAGICSTRING)-1)
16
17 /* string seen after a fake GET request */
18 #define MAGICROUTERSTRING "\r\nServer: Mikrotik HttpProxy\r\n"
19 #define MAGICROUTERSTRINGLENGTH (sizeof(MAGICROUTERSTRING)-1)
20
21 /* string seen if the external program decided it is a proxy */
22 #define MAGICEXTSTRING "DETECTED\n"
23 #define MAGICEXTTRINGLENGTH (sizeof(MAGICEXTSTRING)-1)
24
25 #define PSCAN_MAXSCANS 100
26
27 #define P_MAX(a,b) (((a)>(b))?(a):(b))
28 #define PSCAN_READBUFSIZE (P_MAX(MAGICSTRINGLENGTH, P_MAX(MAGICROUTERSTRINGLENGTH, MAGICEXTTRINGLENGTH)))*2
29
30 #define SSTATE_CONNECTING 0
31 #define SSTATE_SENTREQUEST 1
32 #define SSTATE_GOTRESPONSE 2
33
34 #define STYPE_SOCKS4 0
35 #define STYPE_SOCKS5_V4 1
36 #define STYPE_SOCKS5_V6 2
37 #define STYPE_HTTP_V4 3
38 #define STYPE_HTTP_V6 4
39 #define STYPE_WINGATE 5
40 #define STYPE_CISCO_V4 6
41 #define STYPE_CISCO_V6 7
42 #define STYPE_DIRECT 8
43 #define STYPE_ROUTER 9
44 #define STYPE_EXT 10
45
46 #define STYPE_MAX 10
47
48 #define SOUTCOME_INPROGRESS 0
49 #define SOUTCOME_OPEN 1
50 #define SOUTCOME_CLOSED 2
51
52 #define SCLASS_NORMAL 0
53 #define SCLASS_CHECK 1
54 #define SCLASS_PASS2 2
55 #define SCLASS_PASS3 3
56 #define SCLASS_PASS4 4
57
58 typedef struct scantype {
59 int type;
60 int port;
61 int hits;
62 } scantype;
63
64 typedef struct extrascan {
65 unsigned short port;
66 unsigned char type;
67 struct extrascan *next;
68 struct extrascan *nextbynode;
69 } extrascan;
70
71 typedef struct pendingscan {
72 patricia_node_t *node;
73 unsigned short port;
74 unsigned char type;
75 unsigned char class;
76 time_t when;
77 struct pendingscan *next;
78 } pendingscan;
79
80 typedef struct foundproxy {
81 short type;
82 unsigned short port;
83 struct foundproxy *next;
84 } foundproxy;
85
86 typedef struct cachehost {
87 time_t lastscan;
88 foundproxy *proxies;
89 int glineid;
90 time_t lastgline;
91 unsigned char marker;
92 #if defined(PROXYSCAN_MAIL)
93 sstring *lasthostmask; /* Not saved to disk */
94 time_t lastconnect; /* Not saved to disk */
95 #endif
96 struct cachehost *next;
97 } cachehost;
98
99 typedef struct scan {
100 int fd;
101 patricia_node_t *node;
102 short type;
103 unsigned short port;
104 unsigned short state;
105 unsigned short outcome;
106 unsigned short class;
107 struct scan *next;
108 void *sch;
109 char readbuf[PSCAN_READBUFSIZE];
110 int bytesread;
111 int totalbytesread;
112 } scan;
113
114 #if defined(PROXYSCAN_MAIL)
115 extern unsigned int ps_mailip;
116 extern unsigned int ps_mailport;
117 extern sstring *ps_mailname;
118 extern int psm_mailerfd;
119 #endif
120
121 extern int activescans;
122 extern int maxscans;
123 extern int numscans;
124 extern scantype thescans[];
125 extern int brokendb;
126 extern int ps_cache_ext;
127 extern int ps_scan_ext;
128 extern int ps_extscan_ext;
129 extern int ps_ready;
130 extern int rescaninterval;
131
132 extern sstring *exthost;
133 extern int extport;
134
135 extern unsigned int normalqueuedscans;
136 extern unsigned int prioqueuedscans;
137
138 extern unsigned int ps_start_ts;
139
140 extern unsigned long countpendingscan;
141
142 extern unsigned long scanspermin;
143
144 /* proxyscancache.c */
145 cachehost *addcleanhost(time_t timestamp);
146 cachehost *findcachehost(patricia_node_t *node);
147 void delcachehost(cachehost *);
148 void dumpcachehosts();
149 void loadcachehosts();
150 unsigned int cleancount();
151 unsigned int dirtycount();
152 void cachehostinit(time_t ri);
153 void scanall(int type, int port);
154
155 /* proxyscanalloc.c */
156 scan *getscan();
157 void freescan(scan *sp);
158 cachehost *getcachehost();
159 void freecachehost(cachehost *chp);
160 foundproxy *getfoundproxy();
161 void freefoundproxy(foundproxy *fpp);
162 pendingscan *getpendingscan();
163 void freependingscan(pendingscan *psp);
164 extrascan *getextrascan();
165 void freeextrascan(extrascan *esp);
166
167 /* proxyscanlisten.c */
168 int openlistensocket(int portnum);
169 void handlelistensocket(int fd, short events);
170
171 /* proxyscanconnect.c */
172 int createconnectsocket(struct irc_in_addr *ip, int socknum);
173
174 /* proxyscandb.c */
175 void loggline(cachehost *chp, patricia_node_t *node);
176 void proxyscandbclose();
177 int proxyscandbinit();
178 int proxyscandolistopen(void *sender, int cargc, char **cargv);
179 void proxyscanspewip(nick *mynick, nick *usernick, unsigned long a, unsigned long b, unsigned long c, unsigned long d);
180 void proxyscanshowkill(nick *mynick, nick *usernick, unsigned long a);
181 const char *scantostr(int type);
182
183 #if defined(PROXYSCAN_MAIL)
184 /* proxyscanmail.c */
185 void ps_makereportmail(scanhost *shp);
186 #endif
187
188 /* proxyscanqueue.c */
189 void queuescan(patricia_node_t *node, short scantype, unsigned short port, char class, time_t when);
190 void startqueuedscans();
191
192 /* proxyscan.c */
193 void startscan(patricia_node_t *node, int type, int port, int class);
194 void startnickscan(nick *nick);
195
196 /* proxyscanext.c */
197 unsigned int extrascancount();
198 void loadextrascans();
199 extrascan *findextrascan(patricia_node_t *node);
200 void delextrascan(extrascan *esp);
201 extrascan *addextrascan(unsigned short port, unsigned char type);
202
203 #endif