Ejemplo n.º 1
0
int c_server::connect(const char * ip, uint32_t port)
{

    if (!is_legal_ip(ip) || !is_legal_port(port))
    {
        return -1;
    }

    strncpy(m_ip, ip, sizeof(m_ip));
    m_port = port;
    return connect();
}
Ejemplo n.º 2
0
int metric_handler(int index, const char * arg, c_value * val)
{
    //index 应该在这个范围内[0, METRIC_NUM - 1]
    if (index < 0 || index >= (int)METRIC_NUM || NULL == arg)
    {
        return -1;
    }

    int port = atoi(arg);
    if (!is_legal_port(port))
    {
        return -1;
    }

    int ret = get_value_by_metric_name(port, g_metrics_info[index].name, val);

    return ret;
}
Ejemplo n.º 3
0
int c_server::connect()
{
    if (!is_legal_ip(m_ip) || !is_legal_port(m_port))
    {
        return -1;
    }

    m_fd = net_connect_ser(m_ip, m_port, 0);
    if (is_connected())
    {
        DEBUG_LOG("net_connect_ser: %s:%u, fd: %d", m_ip, m_port, m_fd);
        if (NULL != m_on_connected_func)
        {
            m_on_connected_func();
        }
        return 0;
    }
    else
    {
        return -1;
    }
}
Ejemplo n.º 4
0
static int load_conf()
{
	char *str;
	int	 port;
	int tmp_max_project_number;
	int tmp_max_page;
	//int tmp_accepted_proj;
	int tmp_upper_bound;
	int tmp_max_idc;

	str = config_get_strval("dbserver_ip");
	if (str != NULL && is_legal_ip( (const char *)str ))
		strncpy(dbserver_ip, str, sizeof(dbserver_ip));
	else
		ERROR_RETURN(("can't find legal dbserver ip\t"), -1);

	strncpy((char*)db_server_set[0].ip, dbserver_ip, sizeof(dbserver_ip));

	str = config_get_strval("bind_ip");
	if (str != NULL && is_legal_ip( (const char *)str ))
		strncpy(bind_ip, str, sizeof(bind_ip));
	else
		ERROR_RETURN(("can't find legal bind ip\t"), -1);

	port = config_get_intval("dbserver_port", dbserver_port);
	if (is_legal_port(port))
		dbserver_port = port;
	else
		ERROR_RETURN(("can't find legal dbserver port\t"), -1);

	db_server_set[0].port = dbserver_port;

	port = config_get_intval("bind_port", bind_port);
	if (is_legal_port(port))
		bind_port = port;
	else
		ERROR_RETURN(("can't find legal bind port\t"), -1);

	tmp_max_project_number = config_get_intval("max_project_number", max_project_number);
	if (tmp_max_project_number > 0 && tmp_max_project_number <= max_project_number)
		max_project_number = tmp_max_project_number;
	else
		ERROR_RETURN(("max_project_number is illegal, max value is:%u\t",max_project_number), -1);

	tmp_max_page = config_get_intval("max_page_per_proj", max_page_per_proj);
	if (tmp_max_page > 0 && tmp_max_page <= max_page_per_proj)
		max_page_per_proj = tmp_max_page;
	else
		ERROR_RETURN(("max_page_per_proj is illegal, max value is:%u\t",max_page_per_proj), -1);

	tmp_upper_bound = config_get_intval("delay_upper_bound", delay_upper_bound);
	if (tmp_upper_bound > 0 && tmp_upper_bound <= delay_upper_bound)
		delay_upper_bound = tmp_upper_bound;
	else
		ERROR_RETURN(("delay_upper_bound is illegal, max value is:%u\t",delay_upper_bound), -1);

	tmp_max_idc = config_get_intval("max_idc_number", max_idc_number);
	if (tmp_max_idc > 0 && tmp_max_idc <= max_idc_number)
		max_idc_number = tmp_max_idc;

	uint32_t tmp_max_cdn_speed;
	tmp_max_cdn_speed = config_get_intval("max_cdn_speed", cdn_max_speed);
	if (tmp_max_cdn_speed > 1024 && tmp_max_cdn_speed <= cdn_max_speed)
		cdn_max_speed = tmp_max_cdn_speed;


	str = config_get_strval("link_ip_config_file");
	if (str != NULL )
		strncpy(link_ip_config_file, str, sizeof(link_ip_config_file));
	else
		ERROR_RETURN(("can't find link_ip_config_file\t"), -1);

	int tmp_remove_or_rename = config_get_intval("remove_or_rename", remove_or_rename);
	if (tmp_remove_or_rename == REMOVE_IDC_FILE || tmp_remove_or_rename == RENAME_IDC_FILE)
		remove_or_rename = tmp_remove_or_rename;

	if (remove_or_rename == RENAME_IDC_FILE) {
		str = config_get_strval("idc_rename_dirpath");
		if (str != NULL)
			strncpy(idc_rename_dirpath, str, sizeof(idc_rename_dirpath));
		else
			ERROR_RETURN(("can't find idc_file_dirpath\t"), -1);
	}

	str = config_get_strval("idc_file_dirpath");
	if (str != NULL)
		strncpy(idc_file_dirpath, str, sizeof(idc_file_dirpath));
	else
		ERROR_RETURN(("can't find idc_file_dirpath\t"), -1);

	str = config_get_strval("mmap_tmpfile_dirpath");
	if (str != NULL)
		strncpy(mmap_tmpfile_dirpath, str, sizeof(mmap_tmpfile_dirpath));
	else
		ERROR_RETURN(("can't find mmap_tmpfile_dirpath\t"), -1);


	str = config_get_strval("idc_mmap_file_dirpath");
	if (str != NULL)
		strncpy(idc_mmap_file_dirpath, str, sizeof(idc_mmap_file_dirpath));
	else
		ERROR_RETURN(("can't find idc_mmap_file_dirpath\t"), -1);

	str = config_get_strval("cdn_mmap_file_dirpath");
	if (str != NULL)
		strncpy(cdn_mmap_file_dirpath, str, sizeof(cdn_mmap_file_dirpath));
	else
		ERROR_RETURN(("can't find cdn_mmap_file_dirpath\t"), -1);

	str = config_get_strval("url_mmap_file_dirpath");
	if (str != NULL)
		strncpy(url_mmap_file_dirpath, str, sizeof(url_mmap_file_dirpath));
	else
		ERROR_RETURN(("can't find url_mmap_file_dirpath\t"), -1);

    //add by singku for ignoring some projects
    str = config_get_strval("ignore_project");
	if (str != NULL) {
        uint32_t i;
        while(str != NULL) {
            i = strtoul(str, NULL, 10);
            if (i == 0 || i == ULONG_MAX) {
                ERROR_LOG("bad config file: 'ignore_project'!\n");
                break;
            }
            ignore_project[ i% MAX_PROJECT_NUMBER] = 1;
            str = strchr(str, ',');
            if (str == NULL)
                break;
            str += 1;
        }
    }

	return 0;
}
Ejemplo n.º 5
0
static int s_black_prefix_of_page( STPageInfo *pstPageInfo )
{
   char *error_message=NULL;

	if( NULL == pstPageInfo )
	{
		return -1;
	}		
 	
 	fprintf( cgiOut, "<style type=text/css>.a3{width:30px;border:0px; text-align:center}</style>" );
 	fprintf( cgiOut, "<script language=javascript src=/ip.js></script>\n" );
 	fprintf( cgiOut, "<script language=javascript src=/fw.js></script>\n" );



	
	if( cgiFormSubmitClicked(SUBMIT_NAME) == cgiFormSuccess)
	{
		int ret = -1;
		int ret_value = 0;

		char begin_ip1[4]={0};
		char begin_ip2[4]={0};
		char begin_ip3[4]={0};
		char begin_ip4[4]={0};
		char begin_ip[16]={0};

		char end_ip1[4]={0};
		char end_ip2[4]={0};
		char end_ip3[4]={0};
		char end_ip4[4]={0};
		char end_ip[16]={0};

		char ip_range[64];

		char ip_port[8]={0};
		char ip_intf[16]={0};
		int endip_flag = 0;

		RULE_TYPE type = RULE_IPADDR;

		cgiFormStringNoNewlines("begin_ip1",begin_ip1,sizeof(begin_ip1));
		cgiFormStringNoNewlines("begin_ip2",begin_ip2,sizeof(begin_ip2));
		cgiFormStringNoNewlines("begin_ip3",begin_ip3,sizeof(begin_ip3));
		cgiFormStringNoNewlines("begin_ip4",begin_ip4,sizeof(begin_ip4));

		//fprintf(stderr,"%s,%s,%s,%s@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",begin_ip1,begin_ip2,begin_ip3,begin_ip4);

		cgiFormStringNoNewlines("end_ip1",end_ip1,sizeof(end_ip1));
		cgiFormStringNoNewlines("end_ip2",end_ip2,sizeof(end_ip2));
		cgiFormStringNoNewlines("end_ip3",end_ip3,sizeof(end_ip3));
		cgiFormStringNoNewlines("end_ip4",end_ip4,sizeof(end_ip4));

		cgiFormStringNoNewlines("port",ip_port,sizeof(ip_port));

		cgiFormStringNoNewlines("intf",ip_intf,sizeof(ip_intf));

		if( strlen(begin_ip1) == 0 || strlen(begin_ip2) == 0 || strlen(begin_ip3) == 0 || strlen(begin_ip4) == 0  )
		{
			ShowAlert( search(pstPageInfo->lpublic, "input_illegal"));				  
			return 0;
		}	
		sprintf(begin_ip,"%s.%s.%s.%s",begin_ip1,begin_ip2,begin_ip3,begin_ip4);

		if( strlen(end_ip1) == 0 && strlen(end_ip2) == 0 && strlen(end_ip3) == 0 && strlen(end_ip4) == 0  )
		{
			endip_flag = 1;
		}	
		else if( strlen(end_ip1) == 0 || strlen(end_ip2) == 0 || strlen(end_ip3) == 0 || strlen(end_ip4) == 0 )
		{
			ShowAlert( search(pstPageInfo->lpublic, "input_illegal"));				  
			return 0;
		}
		else
		{
			sprintf(end_ip,"%s.%s.%s.%s",end_ip1,end_ip2,end_ip3,end_ip4);
		}
		if(0 == endip_flag)
		{
			sprintf(ip_range,"%s-%s",begin_ip,end_ip);
		}
		else
		{
			sprintf(ip_range,"%s",begin_ip);
		}

		if( strlen(ip_port) > 0 && 0 != strcmp(ip_port, "all") && ! is_legal_port(ip_port) )
		{
			ShowAlert( search(pstPageInfo->lpublic, "input_illegal"));
			return 0;
		}
		else if( strlen(ip_port)==0 )
		{
			strcpy( ip_port, "all" );
		}


		ret =  eag_conf_captive_list(ccgi_connection, 
									parameter.local_id,
									parameter.instance_id, 
									type,
									ip_range,
									ip_port,
									"",
									ip_intf,
									CP_ADD_LIST,
									CP_BLACK_LIST);

		if(0 != ret)
		{
			ShowAlert(search( pstPageInfo->lauth, "blacklist_add_err" ));
		}


	}



	
	return 0;		
}