void AdminLoginHandler::main(std::string url) { std::string username = request().post("username"); std::string password = request().post("password"); Login *login = new Login(); std::string usercode = login->user_login(username, password, 2); cppcms::json::value json_result; if (usercode.size() > 0){ json_result["result"] = "login success"; set_cookie("usercode", usercode); set_session(usercode, "admin"); } else { json_result["result"] = "login failed"; } response_as_json(json_result); delete login; }
void ChatUser::OnClose(SessionPtr session, CloseReason reason) { assert(reason != CloseReason::UNKNOWN); const bool is_offline = (CloseReason::READEOF == reason || CloseReason::NORESPONSE == reason); const uint32_t wait = server_->conf().offline_wait_seconds(); if (is_offline && wait > 0) { CS_LOG_DEBUG("user offline"); offline_timer_.expires_from_now(boost::posix_time::seconds(wait)); auto self(shared_from_this()); offline_timer_.async_wait([self](const boost::system::error_code& ec) { CS_LOG_DEBUG("user offline time out"); self->HandleUserLogoutRequest(); self->server_->remove_user(self); }); } else { HandleUserLogoutRequest(); server_->remove_user(shared_from_this()); } set_session(nullptr); }
unsigned int cmd_session(callbackp *callbacki) { if (strcmp(callbacki->param[2], "set") == 0 && (callbacki->nParam == 4 || callbacki->nParam == 5)) { if (callbacki->nParam == 5) { subuser *tmpSub = getsubuser(callbacki->call_user, callbacki->host); if (tmpSub != NULL) { tmpSub->need_update = 0; } } if (set_session(callbacki->call_user, callbacki->param[3], callbacki->param[4], (callbacki->nParam == 4 ? 0 : 1), callbacki->g_ape) == NULL) { send_error(callbacki->call_user, "SESSION_ERROR", "203", callbacki->g_ape); } } else if (strcmp(callbacki->param[2], "get") == 0 && callbacki->nParam >= 3) { int i; json *jlist = NULL, *jobj = NULL; RAW *newraw; set_json("sessions", NULL, &jlist); for (i = 3; i <= callbacki->nParam; i++) { if (strlen(callbacki->param[i]) > 32) { continue; } session *sTmp = get_session(callbacki->call_user, callbacki->param[i]); set_json(callbacki->param[i], (sTmp != NULL ? sTmp->val : NULL), &jobj); } json_attach(jlist, jobj, JSON_OBJECT); newraw = forge_raw("SESSIONS", jlist); newraw->priority = 1; /* Only sending to current subuser */ post_raw_sub(newraw, getsubuser(callbacki->call_user, callbacki->host), callbacki->g_ape); } else { send_error(callbacki->call_user, "SESSION_ERROR_PARAMS", "108", callbacki->g_ape); } return (FOR_NOTHING); }
/* Processes Reaver command line options */ int process_arguments(int argc, char **argv) { int ret_val = EXIT_SUCCESS; int c = 0, channel = 0; int long_opt_index = 0; char bssid[MAC_ADDR_LEN] = { 0 }; char mac[MAC_ADDR_LEN] = { 0 }; char *short_options = "b:e:m:i:t:d:c:T:x:r:g:l:o:p:s:C:KZA5ELfnqvDShwN6J"; struct option long_options[] = { { "pixie-dust", no_argument, NULL, 'K' }, { "interface", required_argument, NULL, 'i' }, { "bssid", required_argument, NULL, 'b' }, { "essid", required_argument, NULL, 'e' }, { "mac", required_argument, NULL, 'm' }, { "timeout", required_argument, NULL, 't' }, { "m57-timeout", required_argument, NULL, 'T' }, { "delay", required_argument, NULL, 'd' }, { "lock-delay", required_argument, NULL, 'l' }, { "fail-wait", required_argument, NULL, 'x' }, { "channel", required_argument, NULL, 'c' }, { "session", required_argument, NULL, 's' }, { "recurring-delay", required_argument, NULL, 'r' }, { "max-attempts", required_argument, NULL, 'g' }, { "out-file", required_argument, NULL, 'o' }, { "pin", required_argument, NULL, 'p' }, { "exec", required_argument, NULL, 'C' }, { "no-associate", no_argument, NULL, 'A' }, { "ignore-locks", no_argument, NULL, 'L' }, { "no-nacks", no_argument, NULL, 'N' }, { "eap-terminate", no_argument, NULL, 'E' }, { "dh-small", no_argument, NULL, 'S' }, { "fixed", no_argument, NULL, 'f' }, { "daemonize", no_argument, NULL, 'D' }, { "5ghz", no_argument, NULL, '5' }, { "repeat-m6", no_argument, NULL, '6' }, { "nack", no_argument, NULL, 'n' }, { "quiet", no_argument, NULL, 'q' }, { "verbose", no_argument, NULL, 'v' }, { "win7", no_argument, NULL, 'w' }, { "help", no_argument, NULL, 'h' }, { "timeout-is-nack", no_argument, NULL, 'J' }, { 0, 0, 0, 0 } }; /* Since this function may be called multiple times, be sure to set opt index to 0 each time */ optind = 0; while((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1) { switch(c) { case 'Z': case 'K': pixie.do_pixie = 1; break; case 'i': set_iface(optarg); break; case 'b': str2mac(optarg, (unsigned char *) &bssid); set_bssid((unsigned char *) &bssid); break; case 'e': set_ssid(optarg); break; case 'm': str2mac(optarg, (unsigned char *) &mac); set_mac((unsigned char *) &mac); break; case 't': set_rx_timeout(atoi(optarg)); break; case 'T': set_m57_timeout(strtof(optarg, NULL) * SEC_TO_US); break; case 'c': channel = strtod(optarg, NULL); set_fixed_channel(1); break; case '5': set_wifi_band(AN_BAND); break; case '6': set_repeat_m6(1); break; case 'd': set_delay(atoi(optarg)); break; case 'l': set_lock_delay(atoi(optarg)); break; case 'p': parse_static_pin(optarg); break; case 's': set_session(optarg); break; case 'C': set_exec_string(optarg); break; case 'A': set_external_association(1); break; case 'L': set_ignore_locks(1); break; case 'o': set_log_file(fopen(optarg, "w")); break; case 'x': set_fail_delay(atoi(optarg)); break; case 'r': parse_recurring_delay(optarg); break; case 'g': set_max_pin_attempts(atoi(optarg)); break; case 'D': daemonize(); break; case 'E': set_eap_terminate(1); break; case 'S': set_dh_small(1); break; case 'n': cprintf(INFO, "[+] ignoring obsolete -n switch\n"); break; case 'J': set_timeout_is_nack(1); break; case 'f': set_fixed_channel(1); break; case 'v': set_debug(get_debug() + 1); break; case 'q': set_debug(CRITICAL); break; case 'w': set_win7_compat(1); break; case 'N': set_oo_send_nack(0); break; default: ret_val = EXIT_FAILURE; } } if(channel) { change_channel(channel); } return ret_val; }
/* * cmd_set_session */ int cmd_set_session(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: usage(stdout); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: usage(stderr); ret = CMD_UNDEFINED; goto end; } } opt_session_name = (char *) poptGetArg(pc); if (opt_session_name == NULL) { ERR("Missing session name"); usage(stderr); ret = CMD_ERROR; goto end; } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = -LTTNG_ERR_NOMEM; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_set_session); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } } command_ret = set_session(); if (command_ret) { success = 0; } /* Mi closing */ if (lttng_opt_mi) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } /* Success ? */ ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL; } /* Overwrite ret if an error occured during set_session() */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; }
bool ChatUser::Initial(SessionPtr session) { set_session(session); return true; }