1 /*
2   This program is free software; you can redistribute it and/or
3   modify it under the terms of the GNU General Public License
4   as published by the Free Software Foundation; either version 2
5   of the License, or (at your option) any later version.
6 
7   This program is distributed in the hope that it will be useful,
8   but WITHOUT ANY WARRANTY; without even the implied warranty of
9   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11   See the GNU General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License
14   along with this program; if not, write to:
15                                    The Free Software Foundation, Inc.
16                                           59 Temple Place - Suite 330
17                                           Boston, MA  02111-1307, USA.
18 */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
26 #include <arpa/inet.h>
27 #include <netdb.h>
28 #include <stdarg.h>
29 
30 #include <time.h>
31 #include <unistd.h>
32 #include <ctype.h>
33 
34 #ifdef DEBUG
35 	#define MEMWATCH
36 	#define MW_STDIO
37 	#include "memwatch.h"
38 #endif
39 
40 #define VERSION					"2.60"
41 
42 #define CONFIGFILENAME			"cgichk.cfg"
43 
44 #ifdef _WIN32_
45 	#define CONFIG_PATH			"c:/windows/"CONFIGFILENAME
46 #else
47 	#define CONFIG_PATH			"/usr/local/etc/"CONFIGFILENAME
48 #endif
49 
50 #define PROXY_ENV				"HTTP_PROXY"
51 
52 #define DEFAULT_AGENT			"cgichk "VERSION
53 
54 #define TRUE					1
55 #define FALSE					0
56 
57 #define HTTP_PORT				80
58 #define BUFFER_SIZE				1024
59 
60 #define HTTP_OK					200
61 #define HTTP_MOVED				302
62 #define HTTP_NOEXIST			404
63 #define HTTP_FORBID				403
64 #define HTTP_AUTH				401
65 #define HTTP_SERVERR			500
66 #define HTTP_GATEWAY			502
67 
68 #define DEBUG_NONE				0
69 #define DEBUG_RESULT			1
70 #define DEBUG_FOUND				2
71 #define DEBUG_ALL				3
72 
73 #define BEEP()						{if(!parms.quiet) printf("\007");}
74 
75 #define DEFAULT_HTTP_BUFFER_LENGTH		1024	// Yup, 1k.  Expand this using
76 												// -b for pages with bloated pseudo-404 pages.
77 
78 typedef struct {
79    int			delay;
80    int			whois;
81    int			proxy;
82    int			quiet;     //Stops beepin
83    char			*config;
84    char			*URL;
85    char			*agent;
86    char			*alt_fake_404_string;
87    int			check_interest;
88    int			check_frontpage;
89    int			noua;
90    unsigned int port;
91    int			debugm;
92    int			sdebug;
93    int			ignore403;
94    int			only_head;
95    int			no_false_200_search;
96    int			buffer_length;
97    int			ignore;
98    FILE			*OUTPUT;
99 } parms_t;
100 
101 extern parms_t parms;
102 
103 typedef struct {
104 	char	*host;
105 	int		port;
106 } proxy_t;
107 
108 extern proxy_t	proxy;
109 
110 typedef struct {
111 	FILE	*F;
112 	char	**v;
113 	int		vnum;
114 } result_t;
115 
116 extern FILE *OUTPUT;       //For output redirection, defaults to stdout
117 extern char quiet;         //Stops beepin
118 
119 extern int  sock;
120 extern int  numin;
121 extern char *httpbuff;
122 
123 extern char *whois_host;
124 
125 extern char domain[1024];
126 extern char dir[1024];
127 
128 extern struct in_addr      addr;
129 extern struct sockaddr_in  _sin;
130 extern struct hostent      *he;
131 
132 void waitafew(unsigned int del);
133 void PRINT(char *arg, ...);
134 void CPRINT(char *arg, ...);
135 void close_config(result_t *r);
136 void read_config(result_t *r, char *section);
137 int setup_socket(char *host, int port);
138 void PerformWhois(char *domain);
139 result_t *open_config(char *fn);
140 void read_head();
141 int http_has(char *file, int result);
142 void free_strings(result_t *r);
143 void breakup_url(char *_url, char *_host, int hl, int *_port, int defport, char *_path, int pl);
144 char *cgichk_strnstr(const char *HAYSTACK, const char *NEEDLE);
145