示例#1
0
文件: core.c 项目: steeve85/proxenet
int proxenet_initialize_plugins_list()
{
	if(proxenet_create_list_plugins(cfg->plugins_path) < 0) {
		xlog(LOG_ERROR, "%s\n", "Failed to build plugins list, leaving");
		return -1;
	}
	
	if(cfg->verbose) {
		xlog(LOG_INFO, "%s\n", "Plugins loaded");
		if (cfg->verbose > 1) {
			xlog(LOG_INFO, "%d plugin(s) found\n", proxenet_plugin_list_size());
			proxenet_print_plugins_list(-1);
		}
	}
	
	return 0;
}
示例#2
0
/**
 * This function is called when proxenet is loaded. Therefore, only the scripts
 * located in the `autoload_path` must be loaded.
 * Additionnal plugins can be added via the command line client.
 *
 * @return 0 on success
 * @return -1 on error
 */
int proxenet_initialize_plugins_list()
{
        /* NULL as 2nd arg means to try to add all valid plugins from the path */
        if(proxenet_add_new_plugins(cfg->autoload_path, NULL) < 0) {
                xlog(LOG_CRITICAL, "%s\n", "Failed to build plugins list, leaving");
                return -1;
        }

        if(cfg->verbose) {
                xlog(LOG_INFO, "%s\n", "Plugins loaded");
                if (cfg->verbose > 1) {
                        xlog(LOG_INFO, "%d plugin(s) found\n", proxenet_plugin_list_size());
                        proxenet_print_plugins_list(-1);
                }
        }

        return 0;
}
示例#3
0
void info_cmd(sock_t fd, char *options, unsigned int nb_options)
{
	char msg[BUFSIZE] = {0, };
	char *msg2 = NULL;
	
	snprintf(msg, BUFSIZE,
		 "Infos:\n"
		 "- Listening interface: %s/%s\n"
		 "- Supported IP version: %s\n"
		 "- Logging to %s\n"
		 "- Running/Max threads: %d/%d\n"
		 "- SSL private key: %s\n"
		 "- SSL certificate: %s\n"
		 "- Proxy: %s [%s]\n"
		 "- Plugins directory: %s\n"
		 , 
		 cfg->iface, cfg->port,
		 (cfg->ip_version==AF_INET)? "IPv4": (cfg->ip_version==AF_INET6)?"IPv6": "ANY",
		 (cfg->logfile)?cfg->logfile:"stdout",
		 get_active_threads_size(), cfg->nb_threads,
		 cfg->keyfile,
		 cfg->certfile,
		 cfg->proxy.host ? cfg->proxy.host : "None",
		 cfg->proxy.host ? cfg->proxy.port : "direct",
		 cfg->plugins_path  
		);

	proxenet_write(fd, (void*)msg, strlen(msg));
	
	if (proxenet_plugin_list_size()) {
		msg2 = proxenet_build_plugins_list();
		proxenet_write(fd, (void*)msg2, strlen(msg2));
		proxenet_xfree(msg2);

	} else {
		proxenet_write(fd, (void*)"No plugin loaded\n", 17);
	}
	
	return;
}
示例#4
0
void plugin_cmd(sock_t fd, char *options, unsigned int nb_options)
{
	char msg[BUFSIZE] = {0, };
	char *ptr, *plist_str;
	int n, res;
	
	ptr = strtok(options, " \n");
	if (!ptr){
		n = snprintf(msg, BUFSIZE, "Invalid action\nSyntax\n plugin [list]|[toggle <num>]\n");
		proxenet_write(fd, (void*)msg, n);
		return;
	}

	if (strcmp(ptr, "list") == 0) {
		plist_str = proxenet_build_plugins_list();
		proxenet_write(fd, (void*)plist_str, strlen(plist_str));
		proxenet_xfree(plist_str);
		return;
		
	} else if (strcmp(ptr, "toggle") == 0) {
		ptr = strtok(NULL, " \n");
		if (!ptr)
			return;

		n = atoi(ptr);
		if (0 < n && n <= proxenet_plugin_list_size() ) {
			res = proxenet_toggle_plugin(n);
			n = snprintf(msg, BUFSIZE, "Plugin %d is now %sACTIVE\n", n, res?"":"IN");
			proxenet_write(fd, (void*)msg, n);
			return;
		}
	}
	
	n = snprintf(msg, BUFSIZE, "Invalid action\nSyntax\n plugin [list]|[toggle <num>]\n");
	proxenet_write(fd, (void*)msg, n);
	return;
}
示例#5
0
static void insert_new_plugin_in_list(char* name, supported_plugins_t type, short priority)
{
	plugin_t *cur_ptr, *old_ptr;
	plugin_t *plugin;

	plugin 			= (plugin_t*)proxenet_xmalloc(sizeof(plugin_t));

	plugin->id 		= proxenet_plugin_list_size() + 1;
	plugin->type		= type;
	plugin->priority	= priority;
	plugin->next 		= NULL;
	plugin->state		= INACTIVE;

	plugin->interpreter 	= &vms[type];
	plugin->pre_function	= NULL;
	plugin->post_function	= NULL;


        if (!strcpy(plugin->filename, name)){
                xlog(LOG_CRITICAL, "strcpy() failed for '%s': %s", name, strerror(errno));
                abort();
        }

        if (snprintf(plugin->fullpath, sizeof(plugin->fullpath), "%s/%s", cfg->plugins_path, name) < 0){
                xlog(LOG_CRITICAL, "snprintf() failed for '%s/%s': %s", cfg->plugins_path, name, strerror(errno));
                abort();
        }

        if (!plugin_basename(plugin->name, name, type)){
                xlog(LOG_CRITICAL, "plugin_basename() failed for '%s': %s", name, strerror(errno));
                abort();
        }

	/* if first plugin */
	if (!plugins_list) {
		plugins_list = plugin;

	} else {
		old_ptr = NULL;
		cur_ptr = plugins_list;

		/* browse the plugins list */
		while (true)  {

			/* stop if current node priority is lower (i.e. integer higher) than new node's */
			if (cur_ptr->priority > priority) {
				plugin->next = cur_ptr;

				/* if current node is first node, make it first */
				if (!old_ptr)
					plugins_list = plugin;
				/* otherwise, append */
				else
					old_ptr->next = plugin;
				break;
			}

			/* stop if last element */
			if (cur_ptr->next == NULL) {
				cur_ptr->next = plugin;
				break;
			}

			/* otherwise move on to next node */
			old_ptr = cur_ptr;
			cur_ptr = cur_ptr->next;
		}
	}

	if (cfg->verbose > 1)
		xlog(LOG_INFO, "Adding %s plugin '%s'\n", supported_plugins_str[type], plugin->name);
}