#include <u.h>
#include <libc.h>
#include <libsec.h>
#include <auth.h>
#include <thread.h>
void
usage(void)
{
fprint(2, "usage: dyndns [-k keyspec] [-s server] host [ip]\n");
threadexitsall("usage");
}
void
threadmain(int argc, char **argv)
{
char buf[100], *auth, *keyspec, *server;
int n, fd;
UserPasswd *up;
fmtinstall('[', encodefmt);
keyspec = "";
server = "members.dyndns.org";
ARGBEGIN{
case 's':
server = EARGF(usage());
break;
case 'k':
keyspec = EARGF(usage());
break;
default:
usage();
}ARGEND
if(argc < 1 || argc > 2)
usage();
if((up = auth_getuserpasswd(auth_getkey, "proto=pass role=client service=dyndns server=%s %s", server, keyspec)) == nil)
sysfatal("cannot get password: %r");
auth = smprint("%s:%s", up->user, up->passwd);
server = netmkaddr(server, "net", "http");
if((fd = dial(server, nil, nil, nil)) < 0)
sysfatal("dial %s: %r", server);
fprint(fd, "GET /nic/update?hostname=%s&myip=%s HTTP/1.0\r\n"
"Host: %s\r\n"
"Authorization: Basic %.*[\r\n"
"User-Agent: stupid\r\n"
"\r\n", argv[0], argc==2 ? argv[1] : "", server, strlen(auth), auth);
while((n = read(fd, buf, sizeof buf)) > 0)
write(1, buf, n);
threadexitsall(0);
}
|