21 #include "../misc/plugutils.h"
22 #include "../misc/vendorversion.h"
34 #include <gvm/base/prefs.h>
35 #include <gvm/util/kb.h>
42 #define G_LOG_DOMAIN "lib nasl"
64 ret = g_strdup (
name);
66 ret = g_strdup_printf (
"%s/%s", path,
name);
68 g_debug (
"Request => %s", ret);
69 ret2 = g_strdup_printf (
"%s %s %s", method, ret, httpver);
78 char *request, *auth, tmp[32];
86 if (item == NULL || port < 0)
89 "Error : http_* functions have the following syntax :\n");
90 nasl_perror (lexic,
"http_*(port:<port>, item:<item> [, data:<data>]\n");
94 if (port <= 0 || port > 65535)
96 nasl_perror (lexic,
"http_req: invalid value %d for port parameter\n",
102 g_snprintf (tmp,
sizeof (tmp),
"/tmp/http/auth/%d", port);
103 auth = kb_item_get_str (kb, tmp);
106 auth = kb_item_get_str (kb,
"http/auth");
108 g_snprintf (tmp,
sizeof (tmp),
"http/%d", port);
109 ver = kb_item_get_int (kb, tmp);
111 if ((ver <= 0) || (ver == 11))
113 char *
hostname, *ua, *hostheader, *url;
120 "HTTP User-Agent", -1);
121 if (!ua || strlen (g_strstrip (ua)) == 0)
125 ua = g_strdup_printf (
"Mozilla/5.0 [en] (X11, U; OpenVAS-VT %s)",
126 OPENVAS_NASL_VERSION);
128 ua = g_strdup_printf (
"Mozilla/5.0 [en] (X11, U; %s)",
139 if (port == 80 || port == 443)
142 hostheader = g_strdup_printf (
"%s:%d",
hostname, port);
145 request = g_strdup_printf (
"%s\r\n\
146 Connection: Close\r\n\
148 Pragma: no-cache\r\n\
149 Cache-Control: no-cache\r\n\
151 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\n\
152 Accept-Language: en\r\n\
153 Accept-Charset: iso-8859-1,*,utf-8\r\n",
154 url, hostheader, ua);
165 char *tmp = g_strconcat (request, auth,
"\r\n", NULL);
171 char content_length[128], *tmp;
173 g_snprintf (content_length,
sizeof (content_length),
174 "Content-Length: %zu\r\n\r\n", strlen (data));
175 tmp = g_strconcat (request, content_length, data, NULL);
181 char *tmp = g_strconcat (request,
"\r\n", NULL);
187 retc->
size = strlen (request);
249 const char *path = prefs_get (
"cgi_path");
254 path =
"/cgi-bin:/scripts";
257 retc->
size = strlen (path);