Exemple #1
0
/*
 * set_log_file: sets the log file name.  If logging is on already, this
 * closes the last log file and reopens it with the new name.  This is called
 * automatically when you SET LOGFILE. 
 */
void set_log_file(Window * win, char *filename, int unused)
{
    char *expanded;

    if (filename) {
	if (strcmp(filename, get_string_var(LOGFILE_VAR)))
	    expanded = expand_twiddle(filename);
	else
	    expanded = expand_twiddle(get_string_var(LOGFILE_VAR));
	set_string_var(LOGFILE_VAR, expanded);
	new_free(&expanded);
	if (irclog_fp) {
	    logger(curr_scr_win, NULL, 0);
	    logger(curr_scr_win, NULL, 1);
	}
    }
}
Exemple #2
0
void do_log(int flag, char *logfile, FILE **fp)
{
#ifdef PUBLIC_ACCESS
	bitchsay("This command has been disabled on a public access system");
	return;
#else
	time_t	t = now;

	if (flag)
	{
		if (*fp)
			say("Logging is already on");
		else
		{
			if (!logfile)
				return;
			if (!(logfile = expand_twiddle(logfile)))
			{
				say("SET LOGFILE: No such user");
				return;
			}

			if ((*fp = fopen(logfile, get_int_var(APPEND_LOG_VAR)?"a":"w")) != NULL)
			{
				say("Starting logfile %s", logfile);
				chmod(logfile, S_IREAD | S_IWRITE);
				fprintf(*fp, "IRC log started %.24s\n", ctime(&t));
				fflush(*fp);
			}
			else
			{
				say("Couldn't open logfile %s: %s", logfile, strerror(errno));
				*fp = NULL;
			}
			new_free(&logfile);
		}
	}
	else
	{
		if (*fp)
		{
			fprintf(*fp, "IRC log ended %.24s\n", ctime(&t));
			fflush(*fp);
			fclose(*fp);
			*fp = NULL;
			say("Logfile ended");
		}
	}
#endif
}
Exemple #3
0
int save_formats(FILE *outfile)
{
char thefile[BIG_BUFFER_SIZE+1];
char *p;
int i;
int count = 0;
FsetNumber *tmp;

#if defined(__EMX__) || defined(WINNT)
	sprintf(thefile, "%s/%s.fmt", get_string_var(CTOOLZ_DIR_VAR), version);
#else
	sprintf(thefile, "%s/%s.formats", get_string_var(CTOOLZ_DIR_VAR), version);
#endif
	p = expand_twiddle(thefile);
	outfile = fopen(p, "w");
	if (!outfile)
	{
		bitchsay("Cannot open file %s for saving!", thefile);
		new_free(&p);
		return 1;
	}
	for (i = 0; i < NUMBER_OF_FSET; i++)	
	{

		if (fset_array[i].string)
			fprintf(outfile, "FSET %s %s\n", fset_array[i].name, fset_array[i].string);
		else
			fprintf(outfile, "FSET -%s\n", fset_array[i].name);
	}
	count = NUMBER_OF_FSET;
	for (tmp = numeric_fset; tmp; tmp = tmp->next) {
		fprintf(outfile, "FSET %d %s\n", tmp->numeric, tmp->format);
		count++;
	}
	
	fclose(outfile);
	bitchsay("Saved %d formats to %s", count, thefile);
	new_free(&p);
	return 0;
}
Exemple #4
0
void do_log(int flag, char *logfile, FILE ** fp)
{
    time_t t = time(NULL);

    if (flag) {
	if (*fp)
	    say("Logging is already on");
	else {
	    if (!logfile)
		return;
	    if (!(logfile = expand_twiddle(logfile))) {
		say("SET LOGFILE: No such user");
		return;
	    }

	    if ((*fp = fopen(logfile, get_int_var(APPEND_LOG_VAR) ? "a" : "w")) != NULL) {
		say("Starting logfile %s", logfile);
		chmod(logfile, S_IREAD | S_IWRITE);
		fprintf(*fp, "IRC log started %.24s\n", ctime(&t));
		fflush(*fp);
	    } else {
		say("Couldn't open logfile %s: %s", logfile, strerror(errno));
		*fp = NULL;
	    }
	    new_free(&logfile);
	}
    } else {
	if (*fp) {
	    fprintf(*fp, "IRC log ended %.24s\n", ctime(&t));
	    fflush(*fp);
	    fclose(*fp);
	    *fp = NULL;
	    say("Logfile ended");
	}
    }
}
Exemple #5
0
static	char	*parse_args (char *argv[], int argc, char **envp)
{
	int ac;
	int add_servers = 0;
	
	char *channel = NULL;
	char *ptr;
	
	*nickname = 0;
	*password = 0;

	if ((ptr = getenv("NAPNICK")))
		strmcpy(nickname, ptr, NICKNAME_LEN);
	if ((ptr = getenv("NAPPASS")))
		strmcpy(password, ptr, NICKNAME_LEN);
	if ((ptr = getenv("NAP_HOST")) || (ptr = getenv("NAPHOST")))
		malloc_strcpy(&LocalHostName, ptr);	

	for ( ac = 1; ac < argc; ac++ )
	{
		if (argv[ac][0] == '-')
		{
		    switch (argv[ac][1]) {

			case 'r': /* Load list of servers from this file */
			{
				char *what = empty_string;

				if (argv[ac][2])
					what = &argv[ac][2];
				else if (argv[ac+1] && argv[ac+1][0] != '-')
				{
					what = argv[ac+1];
					ac++;
				}
				else
					fprintf(stderr, "Missing argumenT to -r\n");

				if (*what)
				{
					add_servers = 1;
					malloc_strcpy(&ircservers_file, what);
				}
				break;
			}
			case 'a': /* add server, not replace */
			{
				add_servers = 1;
				if (argv[ac][2])
					fprintf(stderr, "Ignoring junk after -a\n");
				break;
			}
			case 'H':
			{
				char *what = empty_string;
				
				if (argv[ac][2])
					what = &(argv[ac][2]);
				else if (argv[ac+1] && argv[ac+1][0] != '-')
				{
					what = argv[ac+1];
					ac++;
				}
				else
				{
					fprintf(stderr, "Specify a hostname\n");
					exit(1);
				}
				malloc_strcpy(&LocalHostName, what);
				break;
			}
			case 'S': 
			{
				if (argv[ac][2])
				{
					char *what;
					what = &argv[ac][2];
					starting_server = my_atol(what);
				}
				else
				{
					ac++;
					starting_server = my_atol(argv[ac]);
				}
				break;
			}
			case 'n':
			{
				char *what = empty_string;

				if (argv[ac][2])
					what = &(argv[ac][2]);
				else if (argv[ac+1] && argv[ac+1][0] != '-')
				{
					what = argv[ac+1];
					ac++;
				}
				else
				{
					fprintf(stderr,"Missing argument for -n\n");
					exit(1);
				}
				strmcpy(nickname, what, NICKNAME_LEN);
				break;
			}
			case 'p':
			{
				char *pass = NULL;
				if ((pass = getpass("Enter Password :"******"%s %s\n", nap_version, internal_version); 
				exit(1);
#if defined(WINNT) || defined(EMX)
			case 's':
				setup_autoexec();
				exit(1);
#endif
			default:
				fprintf(stderr, "Unknown flag: %s\n",argv[ac]);
			case 'h':
				fprintf(stderr, "%s", switch_help);
#if defined(WINNT) || defined(EMX)
				fprintf(stderr, "%s", switch_help_w);
#endif
				exit(1);
		   } /* End of switch */
		}
		else
		{
			if (!strchr(argv[ac], '.'))
				strmcpy(nickname, argv[ac], NICKNAME_LEN);
			else
				build_server_list(argv[ac]);
		}
	}

	if ((ptr = getenv("NAPLIB")))
		irc_lib = m_opendup("/", ptr, "/", NULL);
	else
	{
		char *s;
		if ((s = expand_twiddle(NAPLIB)))
			irc_lib = s;
		else
			malloc_strcpy(&irc_lib, NAPLIB);
	}

	if ((ptr = getenv("NAPPATH")))
		malloc_strcpy(&irc_path, ptr);
	else
	{
#ifdef NAPPATH
		malloc_strcpy(&irc_path, NAPPATH);
#else
#ifdef WINNT
		malloc_strcpy(&irc_path, ".:~/TekNap:");
#else
		malloc_strcpy(&irc_path, ".:~/.TekNap:");
#endif
		irc_path = m_opendup(irc_lib, "/", "script", NULL);
#endif
	}

	if (LocalHostName)
	{
		struct hostent *hp;
		printf("Your hostname appears to be [%s]\n", LocalHostName);
		memset((void *)&LocalHostAddr, 0, sizeof(LocalHostAddr));
		if ((hp = gethostbyname(LocalHostName)))
			memcpy((void *)&LocalHostAddr.sin_addr, hp->h_addr, sizeof(struct in_addr));
 	} 
	
	if (!check_nickname(nickname))
	{
		fprintf(stderr, "\n Invalid Nickname\n");
		exit(1);
	}

	set_string_var(LOAD_PATH_VAR, irc_path);
	new_free(&irc_path);
	
	if ((ptr = getenv("HOME")))
		malloc_strcpy(&my_path, ptr);
	if (!my_path || !*my_path)
#ifdef WINNT
	{
		malloc_strcpy(&my_path, "//c/TekNap/");
		bsd_setenv("HOME", "//c/TekNap", 1);
	}
	if (access("//c/TekNap", F_OK) != 0)
	{
		fprintf(stderr, "Directory doesn't exist, creating //c/TekNap\n");
		mkdir("//c/TekNap", S_IWUSR|S_IRUSR|S_IXUSR);
	}		
#else
		malloc_strcpy(&my_path, "/");
#endif

#if defined(WINNT) || defined(__EMX__)
	convert_unix(my_path);
#endif
	if (!bircrc_file)
		malloc_sprintf(&bircrc_file, "%s%s", my_path, IRCRC_NAME);

	if ((ptr = getenv("NAPPORT")))
		nap_port = my_atol(ptr);


	if ((ptr = getenv("NAPSERVER")))
		build_server_list(ptr);
#ifdef DEFAULT_SERVER
	{
		if (!read_server_list())
		{
			ptr = LOCAL_COPY(DEFAULT_SERVER);
			build_server_list(ptr);
		}
	}	
#endif
	return (channel);
}
Exemple #6
0
void set_var_value(int var_index, char *value, IrcVariable *dll)
{
	char	*rest;
	IrcVariable *var;
	int	old;
	var = &(irc_variable[var_index]);
	switch (var->type)
	{
	case BOOL_TYPE_VAR:
		if (value && *value && (value = next_arg(value, &rest)))
		{
			old = var->integer;
			if (do_boolean(value, &(var->integer)))
			{
				say("Value must be either ON, OFF, or TOGGLE");
				break;
			}
			if (!(var->int_flags & VIF_CHANGED))
			{
				if (old != var->integer)
					var->int_flags |= VIF_CHANGED;
			}
			if (var->func)
				(var->func) (current_window, NULL, var->integer);
			say("Value of %s set to %s", var->name,
				var->integer ? var_settings[ON]
					     : var_settings[OFF]);
		}
		else
			say("Value of %s -> %s", var->name, var->integer?var_settings[ON] : var_settings[OFF]);
		break;
	case CHAR_TYPE_VAR:
		if (!value)
		{
			if (!(var->int_flags & VIF_CHANGED))
			{
				if (var->integer)
					var->int_flags |= VIF_CHANGED;
			}
			var->integer = ' ';
			if (var->func)
				(var->func) (current_window, NULL, var->integer);
			say("Value of %s set to '%c'", var->name, var->integer);
		}

		else if (value && *value && (value = next_arg(value, &rest)))
		{
			if (strlen(value) > 1)
				say("Value of %s must be a single character",
					var->name);
			else
			{
				if (!(var->int_flags & VIF_CHANGED))
				{
					if (var->integer != *value)
						var->int_flags |= VIF_CHANGED;
				}
				var->integer = *value;
				if (var->func)
					(var->func) (current_window, NULL, var->integer);
				say("Value of %s set to '%c'", var->name,
					var->integer);
			}
		}
		else
			say("Value of %s -> %c", var->name, var->integer);
		break;
	case INT_TYPE_VAR:
		if (value && *value && (value = next_arg(value, &rest)))
		{
			int	val;

			if (!is_number(value))
			{
				say("Value of %s must be numeric!", var->name);
				break;
			}
			if ((val = my_atol(value)) < 0)
			{
				say("Value of %s must be greater than 0", var->name);
				break;
			}
			if (!(var->int_flags & VIF_CHANGED))
			{
				if (var->integer != val)
					var->int_flags |= VIF_CHANGED;
			}
			var->integer = val;
			if (var->func)
				(var->func) (current_window, NULL, var->integer);
			say("Value of %s set to %d", var->name, var->integer);
		}
		else
			say("Value of %s -> %d", var->name, var->integer);
		break;
	case STR_TYPE_VAR:
		if (value)
		{
			if (*value)
			{
				char	*temp = NULL;

				if (var->flags & VF_EXPAND_PATH)
				{
					temp = expand_twiddle(value);
					if (temp)
						value = temp;
					else
						say("SET: no such user");
				}
				if ((!var->int_flags & VIF_CHANGED))
				{
					if ((var->string && ! value) ||
					    (! var->string && value) ||
					    my_stricmp(var->string, value))
						var->int_flags |= VIF_CHANGED;
				}
				malloc_strcpy(&(var->string), value);
				if (temp)
					new_free(&temp);
			}
			else
			{
				say("Value of %s -> %s", var->name, var->string ? var->string : "<null>");
				return;
			}
		}
		else
			new_free(&(var->string));
		if (var->func && !(var->int_flags & VIF_PENDING))
		{
			var->int_flags |= VIF_PENDING;
			(var->func) (current_window, var->string, 0);
			var->int_flags &= ~VIF_PENDING;
		}
		say("Value of %s set to %s", var->name, var->string ?
			var->string : "<EMPTY>");
		break;
	}
}