示例#1
0
文件: config.c 项目: massar/talamasca
/* channel link <channeltag> <channeltag> */
bool cfg_conf_channel_link(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag_a[25], tag_b[25];
	struct channel	*ch_a, *ch_b;

	/* Link requires 2 variables */
	if (	fields != 2 ||
		!copyfield(args, 1, tag_a, sizeof(tag_a)) ||
		!copyfield(args, 2, tag_b, sizeof(tag_b)))
	{
		sock_printf(cmd->sock, "400 The command is: channel link <channeltag> <channeltag>\n");
		return false;
	}

	ch_a = channel_find_tag(tag_a);
	if (!ch_a)
	{
		sock_printf(cmd->sock, "400 Channel '%s' does not exist\n", tag_a);
		return false;
	}
	ch_b = channel_find_tag(tag_b);
	if (!ch_b)
	{
		sock_printf(cmd->sock, "400 Channel '%s' does not exist\n", tag_b);
		return false;
	}

	channel_link(ch_a, ch_b);

	sock_printf(cmd->sock, "200 Channels are linked\n");
	return true;
}
示例#2
0
文件: config.c 项目: massar/talamasca
/* server connect <servertag> */
bool cfg_conf_server_connect(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag[25], var[25], val[1000];
	struct server	*srv;
	struct channel	*ch;

	/* Add requires 1 variables */
	if (	fields != 1 ||
		!copyfield(args, 1, tag, sizeof(tag)))
	{
		sock_printf(cmd->sock, "400 The command is: server connect <servertag>\n");
		return false;
	}

	srv = server_find_tag(tag);

	if (!srv)
	{
		sock_printf(cmd->sock, "400 Server '%s' does not exist\n");
		return false;
	}
	
	server_connect(srv);

	sock_printf(cmd->sock, "200 Connecting to server\n");
	return true;
}
示例#3
0
文件: config.c 项目: massar/talamasca
bool cfg_info_status(struct cfg_state *cmd, char *args)
{
	int	fields = countfields(args);
	char	buf[42];

	sock_printf(cmd->sock, "201 Status\n", buf);
	sock_printf(cmd->sock, "I am running ;)\n", buf);
	sock_printf(cmd->sock, "202 Status complete\n", buf);
	return true;
}
示例#4
0
文件: main.c 项目: mingodad/citadel
void do_room(int sock, char *roomname, char *salearnargs)
{
#define MAXMSGS 1000
	char buf[1024];
	long msgs[MAXMSGS];
	int num_msgs = 0;
	FILE *fp;
	int i;

	if (verbose) printf("%s: ", roomname);
	fflush(stdout);
	sock_printf(sock, "GOTO %s\n", roomname);
	sock_getln(sock, buf, sizeof buf);
	if (buf[0] != '2') {
		if (verbose) printf("%s\n", &buf[4]);
		return;
	}

	/* Only fetch enough message pointers to fill our buffer.
	 * Since we're going to delete them, if there are more we will get them on the next run.
	 */
	sock_printf(sock, "MSGS LAST|%d\n", MAXMSGS);
	sock_getln(sock, buf, sizeof buf);
	if (buf[0] != '1') {
		if (verbose) printf("%s\n", &buf[4]);
		return;
	}
	while (sock_getln(sock, buf, sizeof buf), strcmp(buf, "000")) {
		msgs[num_msgs++] = atol(buf);
	}
	if (verbose) printf("%d messages\n", num_msgs);

	if (num_msgs == 0) return;
	for (i=0; i<num_msgs; ++i) {
		snprintf(buf, sizeof buf, "sa-learn %s", salearnargs);
		if (!verbose) strcat(buf, " >/dev/null");
		fp = popen(buf, "w");
		if (fp == NULL) return;
		if (verbose) printf("Submitting message %ld\n", msgs[i]);
		sock_printf(sock, "MSG2 %ld\n", msgs[i]);
		sock_getln(sock, buf, sizeof buf);
		if (buf[0] == '1') {
			while (sock_getln(sock, buf, sizeof buf), strcmp(buf, "000")) {
				fprintf(fp, "%s\n", buf);
			}
		}
		if (pclose(fp) == 0) {
			sock_printf(sock, "DELE %ld\n", msgs[i]);
			sock_getln(sock, buf, sizeof buf);
			if (verbose) printf("%s\n", &buf[4]);
		}
	}
}
示例#5
0
文件: config.c 项目: massar/talamasca
/* server add <servertag> <RFC1459|Timestamp|P10|User|BitlBee> <hostname> <service|portnumber> <nickname|none> <localname> <password|none> <identity> */
bool cfg_conf_server_add(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag[25], type[10], hostname[24], service[24], nick[24], local[24], pass[24], identity[24];
	enum srv_types	typ = SRV_BITLBEE;

	/* Add requires 8 variables */
	if (	fields != 8 ||
		!copyfield(args, 1, tag,	sizeof(tag)) ||
		!copyfield(args, 2, type,	sizeof(type)) ||
		!copyfield(args, 3, hostname,	sizeof(hostname)) ||
		!copyfield(args, 4, service,	sizeof(service)) ||
		!copyfield(args, 5, nick,	sizeof(nick)) ||
		!copyfield(args, 6, local,	sizeof(local)) ||
		!copyfield(args, 7, pass,	sizeof(pass)) ||
		!copyfield(args, 8, identity,	sizeof(identity)))
	{
		sock_printf(cmd->sock, "400 The command is: server add <servertag> <RFC1459|Timestamp|P10|User|BitlBee> <hostname> <service|portnumber> <nickname|none> <localname> <password> <identity>\n");
		return false;
	}

	if (	 strcasecmp(type, "rfc1459"	) == 0) typ = SRV_RFC1459;
	else if (strcasecmp(type, "timestamp"	) == 0) typ = SRV_TS;
	else if (strcasecmp(type, "bitlbee"	) == 0) typ = SRV_BITLBEE;
	else if (strcasecmp(type, "user"	) == 0) typ = SRV_USER;
	else
	{
		sock_printf(cmd->sock, "400 '%s' is an unsupported server type\n", type);
		return false;
	}
	
	if (server_find_tag(tag))
	{
		sock_printf(cmd->sock, "400 Server '%s' already exists\n", tag);
		return false;
	}

	if (server_add(tag, typ, hostname, service,
		strcasecmp(nick, "none") == 0 ? NULL : nick,
		local,
		strcasecmp(pass, "none") == 0 ? NULL : pass,
		identity, g_conf->service_description))
	{
		sock_printf(cmd->sock, "200 Added server %s\n", tag);
		return true;
	}
	sock_printf(cmd->sock, "400 Server addition failed\n");
	return false;
}
示例#6
0
文件: smtp.c 项目: icyfork/ecartis
int try_connect_HELO(const char *hostname)
{
    char dbg_hostname[BIG_BUF];
    char dbg_version[BIG_BUF];
    char buf[BIG_BUF];
    char testme[BIG_BUF];

    /* Try the HELO protocal */
    if(my_socket != -1)
        sock_close(my_socket);

    if (sock_open(get_string("mailserver"), get_number("smtp-socket", 25), &my_socket))
        return 0;

    if (sock_readline(my_socket, buf, sizeof(buf)) == 0)
        return 0;

    if(!sscanf(buf,"220 %s %s", &dbg_hostname[0], &dbg_version[0]))
        return 0;
    log_printf(9, "Connected: %s (%s)\n", dbg_hostname, dbg_version);

    sock_printf(my_socket, "HELO %s\r\n", hostname);
    if(sock_readline(my_socket, buf, sizeof(buf)) == 0)
        return 0;
    if(!sscanf(buf, "250 %s", testme))
        return 0;
    return 1;
}
示例#7
0
文件: config.c 项目: massar/talamasca
bool cfg_misc_quit(struct cfg_state *cmd, char *args)
{
	char *byers[] = {
		"Zij die gaan, groeten u",
		"See you later alligator",
		"A bitter thought, but I have to go",
		"This is not our farewell",
		"Something I can never have",
		"Ajuuu paraplu",
		"Thank you for the information",
		"It was lovely talking to you again",
		"And All That Could Have Been...",
		"Tschussss...",
		"Aufwiedersehen",
		"Till the next time",
		"I'll be back. Ha, you didn't know I was going to say that!",
		"We will be the only two people left in the world, Yes--Adam and Evil!",
		"Tschau!",
		"Ciao",
        };
	sock_printf(cmd->sock, "200 %s\n", byers[random()%(sizeof(byers)/sizeof(char *))]);

	/* Set the quit flag */
	cmd->quit = true;

	/* This command succeeded */
	return true;
}
示例#8
0
文件: main.c 项目: emteejay/lcdproc
/** Enables or disables (and deletes) a screen */
static int
set_mode(int shortname, char *longname, int state)
{
	int k;

	for (k = 0; sequence[k].which != 0; k++) {
		if (((sequence[k].longname != NULL) &&
		     (0 == strcasecmp(longname, sequence[k].longname))) ||
		    (toupper(shortname) == sequence[k].which)) {
			if (!state) {
				/*
				 * clean both the active and initialized bits
				 * since we delete the screen
				 */
				sequence[k].flags &= (~ACTIVE & ~INITIALIZED);
				/* delete the screen if we are connected */
				if (sock >= 0) {
					sock_printf(sock, "screen_del %c\n", sequence[k].which);
				}
			}
			else
				sequence[k].flags |= ACTIVE;
			return 1;	/* found */
		}
	}
	return 0;		/* not found */
}
/**
 * The sleep_func was intended to make the server sleep for some seconds.
 * This function is currently ignored as making the server sleep actually
 * stalls it and disrupts other clients.
 *
 *\verbatim
 * Usage: sleep <seconds>
 *\endverbatim
 */
int
sleep_func(Client *c, int argc, char **argv)
{
	int secs;
	long out;
	char *endptr;

#define MAX_SECS 60
#define MIN_SECS 1

	if (c->state != ACTIVE)
		return 1;

	if (argc != 2) {
		sock_send_error(c->sock, "Usage: sleep <secs>\n");
		return 0;
	}

	/* set errno to be able to detect errors in strtol() */
	errno = 0;

	out = strtol(argv[1], &endptr, 0);

	/* From the man page for strtol(3)
	 *
	 * In particular, if *nptr is not `\0' but **endptr is
	 * `\0' on return, the entire string is valid.
	 *
	 * In this case, argv[1] is *nptr, and &endptr is **endptr.
	 */

	if (errno) {
		sock_printf_error(c->sock, "number argument: %s\n", strerror(errno));
		return 0;
	}
	else if ((*argv[1] != '\0') && (*endptr == '\0')) {
		/* limit seconds to range: MIN_SECS - MAX_SECS */
		out = (out > MAX_SECS) ? MAX_SECS : out;
		out = (out < MIN_SECS) ? MIN_SECS : out;
		secs = out;
	}
	else {
		sock_send_error(c->sock, "invalid parameter...\n");
		return 0;
	}

	/* Repeat until no more remains - should normally be zero
	 * on exit the first time...*/
	sock_printf(c->sock, "sleeping %d seconds\n", secs);

	/* whoops.... if this takes place as planned, ALL screens
	 * will "freeze" for the alloted time...
	 *
	 * while ((secs = sleep(secs)) > 0)
	 */	;

	sock_send_error(c->sock, "ignored (not fully implemented)\n");
	return 0;
}
示例#10
0
文件: ftpsend.c 项目: sebastinas/yafc
/* abort routine originally from Cftp by Dieter Baron
 */
int ftp_abort(Socket* fp)
{
	char buf[4096];

#ifdef HAVE_LIBSSH
	if(ftp->session)
		/* FIXME: what? */
		return 0;
#endif

	if(!ftp_connected())
		return -1;

	ftp_set_close_handler();

	if (sock_check_pending(fp, false) == 1) {
		ftp_trace("There is data on the control channel, won't send ABOR\n");
		/* read remaining bytes from connection */
		while(fp && sock_read(fp, buf, sizeof(buf)) > 0)
			/* LOOP */ ;
		return 0;
	}

	ftp->ti.interrupted = true;
	ftp_err(_("Waiting for remote to finish abort...\n"));

	ftp_trace("--> telnet interrupt\n");
	if(sock_telnet_interrupt(ftp->ctrl) != 0)
		ftp_err("telnet interrupt: %s\n", strerror(errno));

	/* ftp_cmd("ABOR") won't work here,
	 * we must flush data between the ABOR command and ftp_read_reply()
	 */
	sock_krb_printf(ftp->ctrl, "ABOR");
	sock_printf(ftp->ctrl, "\r\n");
	sock_flush(ftp->ctrl);
	if(ftp_get_verbosity() == vbDebug)
		ftp_err("--> [%s] ABOR\n", ftp->url->hostname);
	else
		ftp_trace("--> [%s] ABOR\n", ftp->url->hostname);

    /* read remaining bytes from connection */
	while(fp && sock_read(fp, buf, sizeof(buf)) > 0)
		/* LOOP */ ;

	/* we expect a 426 or 226 reply here... */
	ftp_read_reply();
	if(ftp->fullcode != 426 && ftp->fullcode != 226)
		ftp_trace("Huh!? Expected a 426 or 226 reply\n");

	/* ... and a 226 or 225 reply here, respectively */
	/* FIXME: should skip this reply if prev. reply wasn't 426 or 226 ? */
	ftp_read_reply();
	if(ftp->fullcode != 226 && ftp->fullcode != 225)
		ftp_trace("Huh!? Expected a 226 or 225 reply\n");

	return -1;
}
示例#11
0
文件: config.c 项目: massar/talamasca
bool cfg_auth_authenticate(struct cfg_state *cmd, char *args)
{
	struct MD5Context	md5;
	int			fields = countfields(args);
	char			buf[256], res[256];
	unsigned char		challenge[20];
	int			i;

	if (	fields != 1 ||
		!copyfield(args, 1, buf, sizeof(buf)))
	{
		sock_printf(cmd->sock, "400 Command is: authenticate <response>\n");
		return false;
	}

	/* Generate a MD5 from the password and the challenge */
	MD5Init(&md5);
	MD5Update(&md5, g_conf->config_password, (unsigned int)strlen((const char *)g_conf->config_password));
	MD5Update(&md5, (const unsigned char *)&cmd->challenge, (unsigned int)strlen((const char *)&cmd->challenge));
	MD5Final(challenge, &md5);

	memset(res, 0, sizeof(res));

	/* Generate the Digest */
        for (i = 0; i < 16; i++)
        {
                snprintf(&res[i*2], 3, "%02x", challenge[i]);
        }

	if (strcmp(buf, res) != 0)
	{
		sock_printf(cmd->sock, "400 Incorrect authentication token (user: '******', us: '%s')\n", buf, res);
		return false;
	}

	sock_printf(cmd->sock, "200 Welcome to The Talamasca (C) Copyright Jeroen Massar 2004 All Rights Reserved on %s\n", g_conf->service_name);

	/*
	 * The user logged in so set the level and title accordingly
	 * At the moment we don't have any user classes, thus
	 * we simply set everybody to allow Configuration commands
	 */
	cmd->level = LEVEL_CONFIG;
	return true;
}
示例#12
0
文件: config.c 项目: massar/talamasca
bool cfg_fromfile(struct cfg_state *cmd, char *filename)
{
	FILE		*file = NULL;
	char		buf[1024];
	size_t		n;
	unsigned int	line = 0;
	bool		ret = true;

	errno = 0;
	file = fopen(filename, "r");
	if (file == NULL)
	{
		sock_printf(cmd->sock, "Couldn't open configuration file %s (%d): %s\n", filename, errno, strerror(errno));
		return false;
	}

	sock_printf(cmd->sock, "Configuring from file %s\n", filename);
	
	/* Walk through the file line by line */
	while (	!cmd->quit &&
		fgets(buf, sizeof(buf), file) == buf)
	{
		/* The last char is -1 ;) */
		n = strlen(buf)-1;

		/* Empty line -> continue */
		if (n <= 0) continue;

		if (buf[n] == '\n') {buf[n] = '\0'; n--;}
		if (buf[n] == '\r') {buf[n] = '\0'; n--;}

		sock_printf(cmd->sock, "Line %u: %s\n", line, buf);

		ret = cfg_handlecommand(cmd, buf);
		if (!ret) break;

		line++;
	}

	sock_printf(cmd->sock, "Configuration file parsing complete\n");

	/* Close the file */
	fclose(file);
	return ret;
}
示例#13
0
文件: config.c 项目: massar/talamasca
bool cfg_misc_help(struct cfg_state *cmd, char *args)
{
	int i=0;

	sock_printf(cmd->sock, "201 The following commands are available:\n");
	for (i=0; cfg_cmds[i].cmd; i++)
	{
		/*
		 * If there is no function (thus the command can be ignored)
		 * or the authentication level is not high enough, skip the command
		 */
		if (	cfg_cmds[i].func == NULL ||
			cfg_cmds[i].level > cmd->level) continue;

		sock_printf(cmd->sock, "%-20s %s\n", cfg_cmds[i].cmd, cfg_cmds[i].desc);
	}
	sock_printf(cmd->sock, "202 End of Help\n");
	return true;
}
示例#14
0
文件: config.c 项目: massar/talamasca
bool cfg_conf_channel(struct cfg_state *cmd, char *args)
{
	if (strncasecmp(args, "add ", 4) == 0)
	{
		return cfg_conf_channel_add(cmd, &args[4]);
	}
	if (strncasecmp(args, "link ", 5) == 0)
	{
		return cfg_conf_channel_link(cmd, &args[5]);
	}
	sock_printf(cmd->sock, "400 Unknown command\n");
	return false;
}
示例#15
0
文件: tic.c 项目: twikz/maiccu
struct TIC_POP *tic_GetPOP(struct TIC_conf *tic, const char *sId)
{
	char			buf[1024];
	struct TIC_POP		*pop;

	/* Get a Tunnel */
	sock_printf(tic->sock, "pop show %s\n", sId);

	/* Fetch the answer */
	if (sock_getline(tic->sock, tic_buf, sizeof(tic_buf), &tic_filled, buf, sizeof(buf)) == -1)
	{
		return NULL;
	}

	/* 201 (start of info) ? */
	if (buf[0] != '2' || buf[1] != '0' || buf[2] != '1')
	{
		dolog(LOG_ERR, "Couldn't show POP %s: %s.\n", sId, buf);
		return NULL;
	}

	/* Allocate a new struct */
	pop = (struct TIC_POP *)malloc(sizeof(*pop));
	if (!pop)
	{
		dolog(LOG_ERR, "Memory problem while getting POP\n");
		return NULL;
	}
	memset(pop, 0, sizeof(*pop));

	/* Gather the information */
	while (sock_getline(tic->sock, tic_buf, sizeof(tic_buf), &tic_filled, buf, sizeof(buf)) != -1)
	{
		/* 202 (end of list) ? */
		if (buf[0] == '2' && buf[1] == '0' && buf[2] == '2') break;
		
		parseline(buf, ": ", pop_rules, pop);
	}
	/* All went okay? */
	if (buf[0] == '2' && buf[1] == '0' && buf[2] == '2')
	{
		dolog(LOG_INFO, "Succesfully retrieved POP information for %s\n", sId);
		return pop;
	}

	/* Free the structure, it is broken anyway */
	tic_Free_POP(pop);

	dolog(LOG_ERR, "POP Get for %s went wrong: %s\n", sId, buf);
	return NULL;
}
示例#16
0
文件: main.c 项目: emteejay/lcdproc
int
menus_init()
{
	int k;

	for (k = 0; sequence[k].which; k++) {
		if (sequence[k].longname) {
			sock_printf(sock, "menu_add_item {} %c checkbox {%s} -value %s\n",
				    sequence[k].which, sequence[k].longname,
			       (sequence[k].flags & ACTIVE) ? "on" : "off");
		}
	}

#ifdef LCDPROC_CLIENT_TESTMENUS
	/*
	 * to be entered on escape from test_menu (but overwritten for
	 * test_{checkbox,ring}
	 */
	sock_send_string(sock, "menu_add_item {} ask menu {Leave menus?} -is_hidden true\n");
	sock_send_string(sock, "menu_add_item {ask} ask_yes action {Yes} -next _quit_\n");
	sock_send_string(sock, "menu_add_item {ask} ask_no action {No} -next _close_\n");
	sock_send_string(sock, "menu_add_item {} test menu {Test}\n");
	sock_send_string(sock, "menu_add_item {test} test_action action {Action}\n");
	sock_send_string(sock, "menu_add_item {test} test_checkbox checkbox {Checkbox}\n");
	sock_send_string(sock, "menu_add_item {test} test_ring ring {Ring} -strings {one\ttwo\tthree}\n");
	sock_send_string(sock, "menu_add_item {test} test_slider slider {Slider} -mintext < -maxtext > -value 50\n");
	sock_send_string(sock, "menu_add_item {test} test_numeric numeric {Numeric} -value 42\n");
	sock_send_string(sock, "menu_add_item {test} test_alpha alpha {Alpha} -value abc\n");
	sock_send_string(sock, "menu_add_item {test} test_ip ip {IP} -v6 false -value 192.168.1.1\n");
	sock_send_string(sock, "menu_add_item {test} test_menu menu {Menu}\n");
	sock_send_string(sock, "menu_add_item {test_menu} test_menu_action action {Submenu's action}\n");
	/*
	 * no successor for menus. Since test_checkbox and test_ring have
	 * their own predecessors defined the "ask" rule will not work for
	 * them.
	 */
	sock_send_string(sock, "menu_set_item {} test -prev {ask}\n");

	sock_send_string(sock, "menu_set_item {test} test_action -next {test_checkbox}\n");
	sock_send_string(sock, "menu_set_item {test} test_checkbox -next {test_ring} -prev test_action\n");
	sock_send_string(sock, "menu_set_item {test} test_ring -next {test_slider} -prev {test_checkbox}\n");
	sock_send_string(sock, "menu_set_item {test} test_slider -next {test_numeric} -prev {test_ring}\n");
	sock_send_string(sock, "menu_set_item {test} test_numeric -next {test_alpha} -prev {test_slider}\n");
	sock_send_string(sock, "menu_set_item {test} test_alpha -next {test_ip} -prev {test_numeric}\n");
	sock_send_string(sock, "menu_set_item {test} test_ip -next {test_menu} -prev {test_alpha}\n");
	sock_send_string(sock, "menu_set_item {test} test_menu_action -next {_close_}\n");
#endif				/* LCDPROC_CLIENT_TESTMENUS */

	return 0;
}
示例#17
0
文件: config.c 项目: massar/talamasca
/* channel add <servertag> <channeltag> <name> */
bool cfg_conf_channel_add(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		stag[24], ctag[24], name[24];
	struct server	*srv;

	/* Add requires 3 variables */
	if (	fields != 3 ||
		!copyfield(args, 1, stag,	sizeof(stag)) ||
		!copyfield(args, 2, ctag,	sizeof(ctag)) ||
		!copyfield(args, 3, name,	sizeof(name)))
	{
		sock_printf(cmd->sock, "400 The command is: channel add <servertag> <channeltag> <name>\n");
		return false;
	}
	
	srv = server_find_tag(stag);
	if (!srv)
	{
		sock_printf(cmd->sock, "400 Server '%s' does not exist\n", stag);
		return false;
	}

	if (channel_find_tag(ctag))
	{
		sock_printf(cmd->sock, "400 Channel '%s' does already exist\n", ctag);
		return false;
	}

	if (channel_add(srv, name, ctag))
	{
		sock_printf(cmd->sock, "200 Added channel %s\n", ctag);
		return true;
	}
	sock_printf(cmd->sock, "400 Channel addition failed\n");
	return false;
}
示例#18
0
文件: config.c 项目: massar/talamasca
bool cfg_handlecommand(struct cfg_state *cmd, char *command)
{
	unsigned int	i=0;
	size_t		len;

	/* Ignore the line? */
	if (	strlen(command) == 0 ||
		strncmp(command, "#", 1) == 0 ||
		strncmp(command, "//", 2) == 0)
	{
		/*
		 * We don't output anything for these when we are not bound
		 * to a socket
		 */
		if (cmd->sock != -1) sock_printf(cmd->sock, "200 Ignoring...\n");
		return true;
	}

	for (i=0; cfg_cmds[i].cmd; i++)
	{
		/* If the authentication level is not high enough, skip the command */
		if (cfg_cmds[i].level > cmd->level) continue;

		len = strlen(cfg_cmds[i].cmd);
		if (strncasecmp(cfg_cmds[i].cmd, command, len) != 0 ||
			(command[len] != ' ' && command[len] != '\0')) continue;
		if (cfg_cmds[i].func == NULL)
		{
			sock_printf(cmd->sock, "200 Ignoring...\n");
			return true;
		}
		else return cfg_cmds[i].func(cmd, &command[len+1]);
	}
	sock_printf(cmd->sock, "400 Command unknown '%s'\n", command);
	return false;
}
示例#19
0
文件: config.c 项目: massar/talamasca
bool cfg_conf_server(struct cfg_state *cmd, char *args)
{
	if (strncasecmp(args, "add ", 4) == 0)
	{
		return cfg_conf_server_add(cmd, &args[4]);
	}
	if (strncasecmp(args, "set ", 4) == 0)
	{
		return cfg_conf_server_set(cmd, &args[4]);
	}
	if (strncasecmp(args, "connect ", 8) == 0)
	{
		return cfg_conf_server_connect(cmd, &args[8]);
	}
	sock_printf(cmd->sock, "400 Unknown command\n");
	return false;
}
示例#20
0
文件: pop3.c 项目: theappleman/dmc
static int doword(char *word) {
	int ret = 1;
	free (cmd);
	cmd = strdup (word);

	if (*word == '\0') {
		/* Do nothing */
	} else
	if (!strcmp (word, "exit")) {
		sock_printf ("QUIT\n");
		waitreply (1);
		ret = 0;
	} else
	if (!strcmp (word, "help") || !strcmp (word, "?")) {
		printf ("Use: ls cat head rm login exit\n");
	} else
	if (!strcmp (word, "ls")) {
		sock_printf ("LIST\n");
		waitreply (1);
	} else
	if (!strcmp (word, "cat")) {
		sock_printf ("RETR %d\n", atoi (getword ()));
		waitreply (1);
	} else
	if (!strcmp (word, "head")) {
		sock_printf ("TOP %d 50\n", atoi (getword ()));
		waitreply (1);
	} else
	if (!strcmp (word, "rm")) {
		sock_printf ("DELE %d\n", atoi (getword ()));
		waitreply (1);
	} else
	if (!strcmp (word, "login")) {
		sock_printf ("USER %s\n", getword ());
		waitreply (0); // TODO: if user fail, do not send pass
		sock_printf ("PASS %s\n", getword ());
		waitreply (1);
	} else sock_printf ("NOOP\n");
	return ret;
}
示例#21
0
/**
 * MiniClock Screen displays the current time with hours & minutes only
 *
 *\verbatim
 *
 * +--------------------+	+--------------------+
 * |                    |	|       11:32        |
 * |       11:32        |	|                    |
 * |                    |	+--------------------+
 * |                    |
 * +--------------------+
 *
 *\endverbatim
 *
 * \param rep        Time since last screen update
 * \param display    1 if screen is visible or data should be updated
 * \param flags_ptr  Mode flags
 * \return  Always 0
 */
int
mini_clock_screen(int rep, int display, int *flags_ptr)
{
	char now[40];
	time_t thetime;
	struct tm *rtime;
	static const char *timeFormat = NULL;
	static int heartbeat = 0;
	int xoffs;

	/* toggle colon display */
	heartbeat ^= 1;

	if ((*flags_ptr & INITIALIZED) == 0) {
		*flags_ptr |= INITIALIZED;

		/* get config values */
		timeFormat = config_get_string("MiniClock", "TimeFormat", 0, "%H:%M");

		sock_send_string(sock, "screen_add N\n");
		sock_send_string(sock, "screen_set N -name {Mini Clock Screen} -heartbeat off\n");
		sock_send_string(sock, "widget_add N one string\n");
	}

	time(&thetime);
	rtime = localtime(&thetime);

	if (strftime(now, sizeof(now), timeFormat, rtime) == 0)
		*now = '\0';
	tickTime(now, heartbeat);

	xoffs = (lcd_wid > strlen(now)) ? (((lcd_wid - strlen(now)) / 2) + 1) : 1;
	sock_printf(sock, "widget_set N one %d %d {%s}\n", xoffs, (lcd_hgt / 2), now);

	return 0;
}				/* End mini_clock_screen() */
示例#22
0
/**
 * TimeDate Screen displays current time and date, uptime, OS ver...
 *
 *\verbatim
 *
 * +--------------------+	+--------------------+
 * |## Linux 2.6.11 ###@|	|### TIME: myhost ##@|
 * |Up xxx days hh:mm:ss|	|17.05.2005 11:32:57a|
 * |  Wed May 17, 1998  |	+--------------------+
 * |11:32:57a  100% idle|
 * +--------------------+
 *
 *\endverbatim
 *
 * \param rep        Time since last screen update
 * \param display    1 if screen is visible or data should be updated
 * \param flags_ptr  Mode flags
 * \return  Always 0
 */
int
time_screen(int rep, int display, int *flags_ptr)
{
	char now[40];
	char today[40];
	int xoffs;
	int days, hour, min, sec;
	static int heartbeat = 0;
	static const char *timeFormat = NULL;
	static const char *dateFormat = NULL;
	time_t thetime;
	struct tm *rtime;
	double uptime, idle;

	if ((*flags_ptr & INITIALIZED) == 0) {
		*flags_ptr |= INITIALIZED;

		/* get config values */
		timeFormat = config_get_string("TimeDate", "TimeFormat", 0, "%H:%M:%S");
		dateFormat = config_get_string("TimeDate", "DateFormat", 0, "%b %d %Y");

		sock_send_string(sock, "screen_add T\n");
		sock_printf(sock, "screen_set T -name {Time Screen: %s}\n", get_hostname());
		sock_send_string(sock, "widget_add T title title\n");
		sock_send_string(sock, "widget_add T one string\n");
		if (lcd_hgt >= 4) {
			sock_send_string(sock, "widget_add T two string\n");
			sock_send_string(sock, "widget_add T three string\n");

			/* write title bar: OS name, OS version, hostname */
			sock_printf(sock, "widget_set T title {%s %s: %s}\n",
				get_sysname(), get_sysrelease(), get_hostname());
		}
		else {
			/* write title bar: hostname */
			sock_printf(sock, "widget_set T title {TIME: %s}\n", get_hostname());
		}
	}

	/* toggle colon display */
	heartbeat ^= 1;

	time(&thetime);
	rtime = localtime(&thetime);

	if (strftime(today, sizeof(today), dateFormat, rtime) == 0)
		*today = '\0';
	if (strftime(now, sizeof(now), timeFormat, rtime) == 0)
		*now = '\0';
	tickTime(now, heartbeat);

	if (lcd_hgt >= 4) {
		char tmp[40];	/* should be large enough */

		machine_get_uptime(&uptime, &idle);

		/* display the uptime... */
		days = (int) uptime / 86400;
		hour = ((int) uptime % 86400) / 3600;
		min  = ((int) uptime % 3600) / 60;
		sec  = ((int) uptime % 60);

		if (lcd_wid >= 20)
			sprintf(tmp, "Up %3d day%s %02d:%02d:%02d",
				days, ((days != 1) ? "s" : ""), hour, min, sec);
		else
			sprintf(tmp, "Up %dd %02d:%02d:%02d", days, hour, min, sec);

		xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T one %i 2 {%s}\n", xoffs, tmp);

		/* display the date */
		xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T two %i 3 {%s}\n", xoffs, today);

		/* display the time & idle time... */
		sprintf(tmp, "%s %3i%% idle", now, (int) idle);
		xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T three %i 4 {%s}\n", xoffs, tmp);
	}
	else {			/* 2 line version of the screen */
		xoffs = (lcd_wid > (strlen(today) + strlen(now) + 1))
			? ((lcd_wid - ((strlen(today) + strlen(now) + 1))) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T one %i 2 {%s %s}\n", xoffs, today, now);
	}

	return 0;
}				/* End time_screen() */
示例#23
0
文件: cpu_smp.c 项目: mezcua/lcdproc
//////////////////////////////////////////////////////////////////////////
// CPU screen shows info about percentage of the CPU being used
//
int
cpu_smp_screen (int rep, int display, int *flags_ptr)
{
#undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 4
	int z;
	static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1];	// last buffer is scratch
	load_type load[MAX_CPUS];
	int num_cpus = MAX_CPUS;
	int bar_size;
	int lines_used;

	// get SMP load - inform about max #CPUs allowed
	machine_get_smpload(load, &num_cpus);

	// restrict num_cpus to max. twice the display height
	if (num_cpus > 2 * lcd_hgt)
		num_cpus = 2 * lcd_hgt;

	// 2 CPUs per line if more CPUs than lines
	bar_size = (num_cpus > lcd_hgt) ? (lcd_wid / 2 - 6) : (lcd_wid - 6);
	lines_used = (num_cpus > lcd_hgt) ? (num_cpus + 1) / 2 : num_cpus;

	if ((*flags_ptr & INITIALIZED) == 0) {
		*flags_ptr |= INITIALIZED;

		sock_send_string(sock, "screen_add P\n");
		
		// print title if he have room for it
		if (lines_used < lcd_hgt) {
			sock_send_string(sock, "widget_add P title title\n");
			sock_printf(sock, "widget_set P title {SMP CPU %s}\n", get_hostname());
		}
		else {
			sock_send_string(sock, "screen_set P -heartbeat off\n");
		}	

		sock_printf(sock, "screen_set P -name {CPU Use: %s}\n", get_hostname());

		for (z = 0; z < num_cpus; z++) {
			int y_offs = (lines_used < lcd_hgt) ? 2 : 1;
			int x = (num_cpus > lcd_hgt) ? ((z % 2) * (lcd_wid/2) + 1) : 1;
			int y = (num_cpus > lcd_hgt) ? (z/2 + y_offs) : (z + y_offs);

			sock_printf(sock, "widget_add P cpu%d_title string\n", z);
			sock_printf(sock, "widget_set P cpu%d_title %d %d \"CPU%d[%*s]\"\n",
					z, x, y, z, bar_size, "");
			sock_printf(sock, "widget_add P cpu%d_bar hbar\n", z);
		}

		return 0;
	}

	for (z = 0; z < num_cpus; z++) {
		int y_offs = (lines_used < lcd_hgt) ? 2 : 1;
		int x = (num_cpus > lcd_hgt) ? ((z % 2) * (lcd_wid/2) + 6) : 6;
		int y = (num_cpus > lcd_hgt) ? (z/2 + y_offs) : (z + y_offs);
		float value = 0.0;
		int i, n;

		// Shift values over by one
		for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
			cpu[z][i] = cpu[z][i + 1];

		// Read new data
		cpu[z][CPU_BUF_SIZE-1] = (load[z].total > 0L)
				    ? (((float) load[z].user + (float) load[z].system + (float) load[z].nice) / (float) load[z].total) * 100.0
				    : 0.0;

		// Average values for final result
		for (i = 0; i < CPU_BUF_SIZE; i++) {
			value += cpu[z][i];
		}
		value /= CPU_BUF_SIZE;

		n = (int) ((value * lcd_cellwid * bar_size) / 100.0 + 0.5);
		sock_printf(sock, "widget_set P cpu%d_bar %d %d %d\n", z, x, y, n);
	}

	return 0;
}										  // End cpu_screen()
示例#24
0
文件: config.c 项目: massar/talamasca
bool cfg_conf_set(struct cfg_state *cmd, char *args)
{
	int	fields = countfields(args);
	char	var[50], val[1024], val2[1024], val3[1024];

	/* Require a value */
	if (	fields < 2 ||
		!copyfield(args, 1, var, sizeof(var)) ||
		!copyfield(args, 2, val, sizeof(val)))
	{
		sock_printf(cmd->sock, "400 The command is: set <variable> <value> [<value> ...]\n");
		return false;
	}

	if (fields > 2) copyfield(args, 3, val2, sizeof(val2));
	if (fields > 3) copyfields(args, 4, 0, val3, sizeof(val3));

	if (strcasecmp(var, "service_name") == 0 && fields == 2)
	{
		if (g_conf->service_name) free(g_conf->service_name);
		g_conf->service_name = strdup(val);
		return true;
	}
	if (strcasecmp(var, "service_description") == 0 && fields == 2)
	{
		if (g_conf->service_description) free(g_conf->service_description);
		g_conf->service_description = strdup(val);
		return true;
	}
	if (strcasecmp(var, "admin_location1") == 0 && fields == 2)
	{
		if (g_conf->admin_location1) free(g_conf->admin_location1);
		g_conf->admin_location1 = strdup(val);
		return true;
	}
	if (strcasecmp(var, "admin_location2") == 0 && fields == 2)
	{
		if (g_conf->admin_location2) free(g_conf->admin_location2);
		g_conf->admin_location2 = strdup(val);
		return true;
	}
	if (strcasecmp(var, "admin_email") == 0 && fields == 2)
	{
		if (g_conf->admin_email) free(g_conf->admin_email);
		g_conf->admin_email = strdup(val);
		return true;
	}
	if (strcasecmp(var, "motd_file") == 0 && fields == 2)
	{
		if (g_conf->motd_file) free(g_conf->motd_file);
		g_conf->motd_file = strdup(val);
		return true;
	}
	if (strcasecmp(var, "config_password") == 0 && fields == 2)
	{
		if (g_conf->config_password) free(g_conf->config_password);
		g_conf->config_password = (unsigned char *)strdup(val);
		return true;
	}
	if (strcasecmp(var, "bitlbee_auto_add") == 0 && fields == 2)
	{
		if (	strcasecmp(val, "true") == 0 ||
			strcasecmp(val, "on") == 0)
		{
			g_conf->bitlbee_auto_add = true;
		}
		else g_conf->bitlbee_auto_add = false;
		return true;
	}

	if (strcasecmp(var, "verbose") == 0 && fields == 2)
	{
		if (	strcasecmp(val, "on") == 0 ||
			strcasecmp(val, "true") == 0 )
		{
			g_conf->verbose = true;

			/* Report back */
			sock_printf(cmd->sock, "200 Verbosity Activated\n");
			return true;
		}
		else if (strcasecmp(val, "off") == 0 ||
			strcasecmp(val, "false") == 0 )
		{
			g_conf->verbose = true;

			/* Report back */
			sock_printf(cmd->sock, "200 Verbosity Disabled\n");
			return true;
		}
		sock_printf(cmd->sock, "400 verbose only accepts 'on' and 'off' and not '%s'\n", var);
		return false;
	}

	sock_printf(cmd->sock, "400 Unknown settable value '%s' with %u fields\n", var, fields);
	return false;
}
示例#25
0
文件: main.c 项目: emteejay/lcdproc
/** Main program loop... */
void
main_loop(void)
{
	int i = 0, j;
	int connected = 0;
	char buf[8192];
	char *argv[256];
	int argc, newtoken;
	int len;

	while (!Quit) {
		/* Check for server input... */
		len = sock_recv(sock, buf, 8000);

		/* Handle server input... */
		while (len > 0) {
			/* Now split the string into tokens... */
			argc = 0;
			newtoken = 1;

			for (i = 0; i < len; i++) {
				switch (buf[i]) {
					case ' ':
						newtoken = 1;
						buf[i] = 0;
						break;
					default:	/* regular chars, keep
							 * tokenizing */
						if (newtoken)
							argv[argc++] = buf + i;
						newtoken = 0;
						break;
					case '\0':
					case '\n':
						buf[i] = 0;
						if (argc > 0) {
							if (0 == strcmp(argv[0], "listen")) {
								for (j = 0; sequence[j].which; j++) {
									if (sequence[j].which == argv[1][0]) {
										sequence[j].flags |= VISIBLE;
										debug(RPT_DEBUG, "Listen %s", argv[1]);
									}
								}
							}
							else if (0 == strcmp(argv[0], "ignore")) {
								for (j = 0; sequence[j].which; j++) {
									if (sequence[j].which == argv[1][0]) {
										sequence[j].flags &= ~VISIBLE;
										debug(RPT_DEBUG, "Ignore %s", argv[1]);
									}
								}
							}
							else if (0 == strcmp(argv[0], "key")) {
								debug(RPT_DEBUG, "Key %s", argv[1]);
							}
#ifdef LCDPROC_MENUS
							else if (0 == strcmp(argv[0], "menuevent")) {
								if (argc == 4 && (0 == strcmp(argv[1], "update"))) {
									set_mode(argv[2][0], "", strcmp(argv[3], "off"));
								}
							}
#else
							else if (0 == strcmp(argv[0], "menu")) {
							}
#endif
							else if (0 == strcmp(argv[0], "connect")) {
								int a;
								for (a = 1; a < argc; a++) {
									if (0 == strcmp(argv[a], "wid"))
										lcd_wid = atoi(argv[++a]);
									else if (0 == strcmp(argv[a], "hgt"))
										lcd_hgt = atoi(argv[++a]);
									else if (0 == strcmp(argv[a], "cellwid"))
										lcd_cellwid = atoi(argv[++a]);
									else if (0 == strcmp(argv[a], "cellhgt"))
										lcd_cellhgt = atoi(argv[++a]);
								}
								connected = 1;
								if (displayname != NULL)
									sock_printf(sock, "client_set -name \"%s\"\n", displayname);
								else
									sock_printf(sock, "client_set -name {LCDproc %s}\n", get_hostname());
#ifdef LCDPROC_MENUS
								menus_init();
#endif
							}
							else if (0 == strcmp(argv[0], "bye")) {
								exit_program(EXIT_SUCCESS);
							}
							else if (0 == strcmp(argv[0], "success")) {
							}
							else {
								/*
								int j;
								for (j = 0; j < argc; j++)
									printf("%s ", argv[j]);
								printf("\n");
								*/
							}
						}

						/* Restart tokenizing */
						argc = 0;
						newtoken = 1;
						break;
				}	/* switch( buf[i] ) */
			}

			len = sock_recv(sock, buf, 8000);
		}

		/* Gather stats and update screens */
		if (connected) {
			for (i = 0; sequence[i].which > 0; i++) {
				sequence[i].timer++;

				if (!(sequence[i].flags & ACTIVE))
					continue;

				if (sequence[i].flags & VISIBLE) {
					if (sequence[i].timer >= sequence[i].on_time) {
						sequence[i].timer = 0;
						/* Now, update the screen... */
						update_screen(&sequence[i], 1);
					}
				}
				else {
					if (sequence[i].timer >= sequence[i].off_time) {
						sequence[i].timer = 0;
						/* Now, update the screen... */
						update_screen(&sequence[i], sequence[i].show_invisible);
					}
				}
				if (islow > 0)
					usleep(islow * 10000);
			}
		}

		/* Now sleep... */
		usleep(TIME_UNIT);
	}
}
示例#26
0
文件: config.c 项目: massar/talamasca
bool cfg_misc_reply(struct cfg_state *cmd, char *args)
{
	sock_printf(cmd->sock, "200 %s\n", args);
	return true;
}
示例#27
0
文件: config.c 项目: massar/talamasca
/* server set <servertag> <variable> <value> */
bool cfg_conf_server_set(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag[25], var[25], val[1000];
	struct server	*srv;
	struct channel	*ch;

	/* Add requires 8 variables */
	if (	fields != 3 ||
		!copyfield(args, 1, tag, sizeof(tag)) ||
		!copyfield(args, 2, var, sizeof(var)) ||
		!copyfield(args, 3, val, sizeof(val)))
	{
		sock_printf(cmd->sock, "400 The command is: server set <servertag> <variable> <value>\n");
		return false;
	}

	srv = server_find_tag(tag);

	if (!srv)
	{
		sock_printf(cmd->sock, "400 Server '%s' does not exist\n");
		return false;
	}

	if (strcasecmp(var, "bitlbee_identifypass") == 0)
	{
		if (srv->bitlbee_identifypass) free(srv->bitlbee_identifypass);
		srv->bitlbee_identifypass = strdup(val);
		
		sock_printf(cmd->sock, "200 Configured the BitlBee password\n");
		return true;
	}

	if (strcasecmp(var, "defaultchannel") == 0)
	{
		if (	srv->type != SRV_USER &&
			srv->type != SRV_BITLBEE)
		{
			sock_printf(cmd->sock, "400 Defaultchannels are only required for user and BitlBee links\n", val);
			return false;
		}

		ch = channel_find_tag(val);
		if (!ch)
		{
			sock_printf(cmd->sock, "400 Channel '%s' does not exist\n", val);
			return false;
		}
		srv->defaultchannel = ch;

		/* Make sure that our user is also there */
		channel_adduser(ch, srv->user);

		sock_printf(cmd->sock, "200 Configured the default channel\n");
		return true;
	}

	sock_printf(cmd->sock, "400 Unknown settable value '%s'\n", var);
	return false;
}
示例#28
0
/**
 * Big Clock Screen displays current time...
 *
 *\verbatim
 *
 * +--------------------+
 * |    _   _      _  _ |
 * |  ||_ . _||_|. _|  ||
 * |  ||_|. _|  |.|_   ||
 * |                    |
 * +--------------------+
 *
 *\endverbatim
 *
 * \param rep        Time since last screen update
 * \param display    1 if screen is visible or data should be updated
 * \param flags_ptr  Mode flags
 * \return  Always 0
 */
int
big_clock_screen(int rep, int display, int *flags_ptr)
{
	time_t thetime;
	struct tm *rtime;
	int pos[] = {1, 4, 8, 11, 15, 18};
	char fulltxt[16];
	static char old_fulltxt[16];
	static int heartbeat = 0;
	static int TwentyFourHour = 1;
	int j = 0;
	int digits = (lcd_wid >= 20) ? 6 : 4;
	int xoffs = (lcd_wid + 1 - (pos[digits - 1] + 2)) / 2;

	/* toggle colon display */
	heartbeat ^= 1;

	if ((*flags_ptr & INITIALIZED) == 0) {
		*flags_ptr |= INITIALIZED;

		sock_send_string(sock, "screen_add K\n");
		sock_send_string(sock, "screen_set K -name {Big Clock Screen} -heartbeat off\n");
		sock_send_string(sock, "widget_add K d0 num\n");
		sock_send_string(sock, "widget_add K d1 num\n");
		sock_send_string(sock, "widget_add K d2 num\n");
		sock_send_string(sock, "widget_add K d3 num\n");
		sock_send_string(sock, "widget_add K c0 num\n");

		if (digits > 4) {
			sock_send_string(sock, "widget_add K d4 num\n");
			sock_send_string(sock, "widget_add K d5 num\n");
			sock_send_string(sock, "widget_add K c1 num\n");
		}

		strcpy(old_fulltxt, "      ");
	}

	time(&thetime);
	rtime = localtime(&thetime);

	sprintf(fulltxt, "%02d%02d%02d",
			((TwentyFourHour) ? rtime->tm_hour : (((rtime->tm_hour + 11) % 12) + 1)),
			rtime->tm_min, rtime->tm_sec);

	for (j = 0; j < digits; j++) {
		if (fulltxt[j] != old_fulltxt[j]) {
			sock_printf(sock, "widget_set K d%d %d %c\n", j, xoffs+pos[j], fulltxt[j]);
			old_fulltxt[j] = fulltxt[j];
		}
	}

	if (heartbeat) {	/* 10 means: colon */
		sock_printf(sock, "widget_set K c0 %d 10\n", xoffs + 7);
		if (digits > 4)
			sock_printf(sock, "widget_set K c1 %d 10\n", xoffs + 14);
	}
	else {			/* kludge: use illegal number to clear colon display */
		sock_printf(sock, "widget_set K c0 %d 11\n", xoffs + 7);
		if (digits > 4)
			sock_printf(sock, "widget_set K c1 %d 11\n", xoffs + 14);
	}

	return 0;
}				/* End big_clock_screen() */
示例#29
0
文件: config.c 项目: massar/talamasca
bool cfg_auth_login(struct cfg_state *cmd, char *args)
{
	unsigned char		secret[20] = "TheTalamasca", c, challenge[16];
	unsigned int		i,r;
	struct MD5Context	md5;
	int			fields = countfields(args);

	/* Require a username */
	if (fields != 1 ||
		!copyfield(args, 1, cmd->user, sizeof(cmd->user)))
	{
		sock_printf(cmd->sock, "400 The command is: login <username>\n");
		return false;
	}

	/*
	 * Check that the username is in lower case
	 * and contains only ascii
	 */
	for (i=0; i < strlen(cmd->user); i++)
	{
		if (	cmd->user[i] < 'a' ||
			cmd->user[i] > 'z')
		{
			sock_printf(cmd->sock, "400 Username contains unacceptable characters\n");
			return false;
		}
	}

	/* Clear out the secret */
	memset(secret, 0, sizeof(secret));

	/* Randomize the string */
	for (i=0; i < (sizeof(secret)-1); i++)
	{
		/* Pick random number between 1 and 62 */
		r = (random() % 63) + 1;

		/* [ 1,10] => [0,9] */
		if (r < 11)		c = (r+48-1);
		/* [11,36] => [A,Z] */
		else if (r < 37)	c = (r+65-10);
		/* [37,62] => [a,z] */
		else			c = (r+97-36);

		/* Randomize */
		secret[i] = c;
	}

	/* Generate a MD5 */
	MD5Init(&md5);
	MD5Update(&md5, (const unsigned char *)&secret, (unsigned int)strlen((const char *)&secret));
	MD5Final(challenge, &md5);

	memset(&cmd->challenge, 0, sizeof(cmd->challenge));

	/* Generate the Digest */
        for (i = 0; i < sizeof(challenge); i++)
        {
                snprintf(&cmd->challenge[i*2], 3, "%02x", challenge[i]);
        }

	/* Return the challenge to the client */
	sock_printf(cmd->sock, "200 %s\n", cmd->challenge);

	/* Upgrade the level */
	cmd->level = LEVEL_LOGIN;

	return true;
}
示例#30
0
/**
 * Uptime Screen shows info about system uptime and OS version
 *
 *\verbatim
 *
 * +--------------------+	+--------------------+
 * |## SYSTEM UPTIME ##@|	|# Linux 2.6.11: my#@|
 * |       myhost       |	| xxx days hh:mm:ss  |
 * | xxx days hh:mm:ss  |	+--------------------+
 * |   Linux 2.6.11     |
 * +--------------------+
 *
 *\endverbatim
 *
 * \param rep        Time since last screen update
 * \param display    1 if screen is visible or data should be updated
 * \param flags_ptr  Mode flags
 * \return  Always 0
 */
int
uptime_screen(int rep, int display, int *flags_ptr)
{
	int xoffs;
	int days, hour, min, sec;
	double uptime, idle;
	static int heartbeat = 0;
	char tmp[257];	/* should be large enough for host name */

	if ((*flags_ptr & INITIALIZED) == 0) {
		*flags_ptr |= INITIALIZED;

		sock_send_string(sock, "screen_add U\n");
		sock_printf(sock, "screen_set U -name {Uptime Screen: %s}\n", get_hostname());
		sock_send_string(sock, "widget_add U title title\n");
		if (lcd_hgt >= 4) {
			sock_send_string(sock, "widget_add U one string\n");
			sock_send_string(sock, "widget_add U two string\n");
			sock_send_string(sock, "widget_add U three string\n");

			sock_send_string(sock, "widget_set U title {SYSTEM UPTIME}\n");

			sprintf(tmp, "%s", get_hostname());
			xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
			sock_printf(sock, "widget_set U one %i 2 {%s}\n", xoffs, tmp);

			sprintf(tmp, "%s %s", get_sysname(), get_sysrelease());
			xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
			sock_printf(sock, "widget_set U three %i 4 {%s}\n", xoffs, tmp);
		}
		else {
			sock_send_string(sock, "widget_add U one string\n");

			sock_printf(sock, "widget_set U title {%s %s: %s}\n",
					get_sysname(), get_sysrelease(), get_hostname());
		}
	}

	/* toggle colon display */
	heartbeat ^= 1;

	machine_get_uptime(&uptime, &idle);
	days = (int) uptime / 86400;
	hour = ((int) uptime % 86400) / 3600;
	min =  ((int) uptime % 3600) / 60;
	sec =  ((int) uptime % 60);
	if (lcd_wid >= 20)
		sprintf(tmp, "%d day%s %02d:%02d:%02d",
			days, ((days != 1) ? "s" : ""), hour, min, sec);
	else
		sprintf(tmp, "%dd %02d:%02d:%02d", days, hour, min, sec);

	if (display) {
		xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
		if (lcd_hgt >= 4)
			sock_printf(sock, "widget_set U two %d 3 {%s}\n", xoffs, tmp);
		else
			sock_printf(sock, "widget_set U one %d 2 {%s}\n", xoffs, tmp);
	}

	return 0;
}				/* End uptime_screen() */