Ejemplo n.º 1
0
void Server::authorize(struct mg_connection *conn, struct http_message *hm) {
	Server::session *session;
	std::string user = get_http_var(hm, "user");
	std::string password = get_http_var(hm, "password");

	std::string host;
	mg_str *host_hdr = mg_get_http_header(hm, "Host");
	if (host_hdr) {
		if (!CONFIG_STRING(m_config, "service.cert").empty()) {
			host += "https://";
		}
		else {
			host += "http://";
		}
		host += std::string(host_hdr->p, host_hdr->len);
	}

	if (check_password(user, password) && (session = new_session(user)) != NULL) {
		std::cout << "User authorized\n";
		mg_printf(conn, "HTTP/1.1 302 Found\r\n"
			"Set-Cookie: session=%s; max-age=3600; http-only\r\n"  // Session ID
			"Set-Cookie: user=%s\r\n"  // Set user, needed by Javascript code
			"Set-Cookie: admin=%s\r\n"  // Set user, needed by Javascript code
			"Set-Cookie: base_location=%s\r\n"  // Set user, needed by Javascript code
			"Set-Cookie: original_url=/; max-age=0\r\n"  // Delete original_url
			"Location: %s%sinstances\r\n\r\n",
			session->session_id, session->user, session->admin ? "1" : "0", CONFIG_STRING(m_config, "service.base_location").c_str(), host.c_str(), CONFIG_STRING(m_config, "service.base_location").c_str());
	} else {
		// Authentication failure, redirect to login.
		redirect_to(conn, hm, "/login");
	}
}
Ejemplo n.º 2
0
int RASocket::authenticate()
{
    if (send(std::string("Username: "******"Password: "******"Login attempt for user: %s", user.c_str());

    if (check_access_level(user) == -1)
        return -1;

    if (check_password(user, pass) == -1)
        return -1;

    sLog->outRemote("User login: %s", user.c_str());

    return 0;
}
Ejemplo n.º 3
0
int
main(int argc, const char **argv)
{
    jaro_credential_t cred = {0};
    int res = 0;

    if (argc < 2) {
	error("Usage: jaro-gnome-keyring <get|check|store|erase>");
	error("input from stdin: newline separated parameter=value tuples");
	error("i.e: protocol, path, username, host, password (password on store)");
	return 1;
    }

    if (read_credential(&cred)) {
	clear_credential(&cred);
	return 1;
    }

    if (strcmp(argv[1], "get") == 0) {
      res = get_password(&cred);
    }
    if (strcmp(argv[1], "check") == 0) {
      res = check_password(&cred);
    }
    else if (strcmp(argv[1], "store") == 0) {
      res = store_password(&cred);
    }
    else if (strcmp(argv[1], "erase") == 0) {
      res = erase_password(&cred);
    }
    clear_credential(&cred);

    return res;
}
Ejemplo n.º 4
0
/* Authenticates the user, returns 0 on success, 1 on fail */
static int check_auth()
{
    struct passwd *pw;
    uid_t uid;

#ifdef HAVE_AUDIT
    uid = audit_getloginuid();
    if (uid == (uid_t) -1)
        uid = getuid();
#else
    uid = getuid();
#endif

    pw = getpwuid(uid);
    if (!pw) {
        eerror("cannot find your entry in the passwd file.");
        return (-1);
    }

    printf("Authenticating %s.\n", pw->pw_name);

    /* do the actual check */
    if (check_password(pw->pw_name) == 0) {
        return 0;
    }

    eerrorx("Authentication failed for %s", pw->pw_name);
    return 1;
}
Ejemplo n.º 5
0
int create_account(DB *database, unsigned char *username, unsigned char *password)
{
    int user_hash = SearchHash(username);

    if (!strcmp(username, database->db[user_hash].username))
    {
        printf("Sorry, that username is already taken. Please try again.\n\n");
        return 0;
    }

    if (!check_password(password))
    {
        printf("Sorry, your password must be 8-20 characters in length and contain ");
        printf("either a number or one of these special characters: !@#$%%*.\n\n");
        return 0;
    }

    // copy username to db location
    strcpy(database->db[user_hash].username, username);

    // create new password with salt
    int new_length = strlen(password) + strlen(salt);
    char *salt_password = malloc(sizeof(char) * new_length + 1);
    strcpy(salt_password, password);
    strcat(salt_password, salt);
    database->db[user_hash].password = CryptoHash(salt_password);

    return 1;
}
Ejemplo n.º 6
0
//main function for running program
int main()
{
  bool is_permission = false;
  int attempt_number = 1;
  char password[] = PASSWORD;
  char password_attempt[100];
  
  print_intro();
  
  //password attempt loop
  do
  {
    print_security_level(attempt_number);
    scanf("%99s", password_attempt);
    is_permission = check_password(password, password_attempt);
    
    //print cases for password attempt
    if(is_permission == false && attempt_number == MAX_ATTEMPT)
    {
      print_password_denied(attempt_number, MAX_ATTEMPT);
      system("qlmanage -p ./data/ned.gif");
      animate();
    }
    else if(is_permission == true)
      print_access();
    else
    {
      print_password_denied(attempt_number, MAX_ATTEMPT);
      attempt_number++;
    }
    
  }while(is_permission == false);
  
  return 0;
}
Ejemplo n.º 7
0
int RASocket::authenticate()
{
    if (send(std::string("Username: "******"Password: "******"Login attempt for user: %s", user.c_str());

    if (check_access_level(user) == -1)
        return -1;

    if (check_password(user, pass) == -1)
        return -1;

    TC_LOG_INFO(LOG_FILTER_REMOTECOMMAND, "User login: %s", user.c_str());

    return 0;
}
Ejemplo n.º 8
0
int check_restriction(long idx_article)
{
	int fd;
	int len;
	char restriction_pass2[20];
	SHA1Context sha;
	char title[MAX_TITLE_ACTUAL];

	init_filtering = 0;
	if (restriction_filter_off == -1)
	{
		fd = wl_open("wiki.pas", WL_O_RDONLY);
		if (fd >= 0)
		{
			len = wl_read(fd, restriction_pass1, 20);
			if (len < 20)
				memset(restriction_pass1, 0, 20);
			memset(restriction_pass2, 0, 20);
			if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved
			{
				len = wl_read(fd, restriction_pass2, 20);
				if (len < 20)
					memset(restriction_pass2, 0, 20);

				SHA1Reset(&sha);
				SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20);
				SHA1Result(&sha);
				if (!memcmp(sha.Message_Digest, restriction_pass2, 20))
					restriction_filter_off = 1;
				else
					restriction_filter_off = 0;
			}
			wl_close(fd);
		}
	}

	if (restriction_filter_off == -1)
	{
		get_article_title_from_idx(saved_idx_article, title);
		memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8);
		render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0);
		first_time_password(0);
		return -1;
	} else if (restriction_filter_off)
		return 0; // ok
	else
	{
		get_article_title_from_idx(saved_idx_article, title);
		memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8);
		render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0);
		password_str_len = 0;
		check_password();
		return -1;
	}
}
Ejemplo n.º 9
0
/**
 * Parse username and password
 */
static int parse_auth(SSH *ssh) {
	byte *p;
	byte *out;
	byte aux;
	word32 outSz;

	p = ssh->sp.data;

	/* Get username */
	read_bin(&p, &out, &outSz);

	/* Size valid? */
	if (outSz > MAX_UN_LEN)
		return -1;

	memcpy(ssh->user, out, outSz);
	ssh->user[outSz] = 0;

	/* Get service */
	read_bin(&p, &out, &outSz);

	/* Get method */
	read_bin(&p, &out, &outSz);

	/* Only support password based autentication */
	if (memcmp(out, PASSWORD_STR, strlen(PASSWORD_STR)) != 0) {
		return 1;
	}

	/* Read byte */
	read_byte(&p, &aux);

	/* Get password */
	read_bin(&p, &out, &outSz);

	/* Size valid? */
	if (outSz > MAX_PW_LEN)
		return -1;

	memcpy(ssh->pass, out, outSz);
	ssh->pass[outSz] = 0;

	/* Check username and password */
	if (check_password(ssh->user, ssh->pass) < 0) {
		/* Limit auth attempts */
		if (ssh->authAtt++ > 1) {
			return -1;
		}
		return 1;
	}

	ssh->state = SSH_AUTH;

	return 0;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[]){
    if(argc >= 2){
        if(check_password(argv[1])){
            printf("%s", "Access granted\n");
        }else{
            printf("%s", "Access denied\n");
        }
    }else{
        printf("%s", "Please enter password!\n");
    }
}
Ejemplo n.º 11
0
/***************************************************************************
  Function: cgiMain
  Description: 
  Input:  
  Output: 
  Return: 0 OK, other Error
  Others:  none
***************************************************************************/
int cgiMain()
{
    char account[FEATURE_GDGL_ACCOUNT_MAX_LEN + 1]; //16 + terminating null
	char password[FEATURE_GDGL_PASSWD_MAX_LEN + 1]; //16 + terminating null
	char gateway_id[FEATURE_GDGL_ID_LEN + 1]; //12 + terminating null
	char gateway_alias[FEATURE_GDGL_ACCOUNT_MAX_LEN + 1];
	char gateway_passwd[FEATURE_GDGL_PASSWD_MAX_LEN + 1];
	cgiFormResultType cgi_re;
	int res;

	cgiHeaderContentType("application/json"); //MIME

    // Read ID
    res = read_id(gateway_id);
	if (res != 0) {
		client_admin_response("noid", res, clientAdminResultStr[res]);
		return res;
	}
	
	// Read alias
	res = read_alias(gateway_alias);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

    // Read password
	res = read_password(gateway_passwd);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

    // Check account
    cgi_re = cgiFormString("account", account, FEATURE_GDGL_ACCOUNT_MAX_LEN + 1);
	res = check_account(cgi_re, account, gateway_id, gateway_alias);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

	// Check password
	cgi_re = cgiFormString("password", password, FEATURE_GDGL_PASSWD_MAX_LEN + 1);
	res = check_password(cgi_re, password, gateway_passwd);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

    // account & password all right	
    client_admin_response(gateway_id, clientAdminSuccess, clientAdminResultStr[clientAdminSuccess]);
	return 0;
}
Ejemplo n.º 12
0
int pam_multipass_authenticate(json_object *hashes, const char *password)
{
    int ret = PAM_AUTH_ERR;
    json_object_object_foreach(hashes, name, obj) {
	const char *hash = json_object_get_string(json_object_object_get(obj, "hash"));
	if (hash == NULL) {
	    fprintf(stderr, "pam_multipass: no hash defined for %s\n", name);
	}
	ret = check_password(password, hash);
	if (ret == 0) break;
    }
    return ret;
}
Ejemplo n.º 13
0
int main(){
	char buf[BUFSIZE];
	// Read until newline
	fwrite("Enter the secret password: "******"Yay, your token is: %s\n", TOKEN);
	} else {
		printf("Wrong password!\n");
	}
	return 0;
}
Ejemplo n.º 14
0
void work(int newsockfd, struct sockaddr_in cli_addr) {
    if (newsockfd < 0) {
        FM_LOG_WARNING("ERROR on accept");
        return;
    }
    FM_LOG_NOTICE("connect from %s:%d", inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));

    char buffer[BUFF_SIZE];
    bzero(buffer, BUFF_SIZE);
    ssize_t n = read(newsockfd, buffer, BUFF_SIZE);
    if (n < 0) FM_LOG_WARNING("ERROR reading from socket");

    FM_LOG_NOTICE("Here is the password: %s", buffer);
    if (check_password(oj_config.password, buffer)) {
        FM_LOG_DEBUG("Authentication Ok.");
        n = write(newsockfd, "Authentication Ok.", 18);
        if (n < 0) FM_LOG_WARNING("ERROR writing to socket");

        bzero(buffer, BUFF_SIZE);
        n = read(newsockfd, buffer, BUFF_SIZE);
        if (n <= 0) {
            FM_LOG_WARNING("ERROR reading from socket");
            close(newsockfd);
            return;
        }
        FM_LOG_NOTICE("Here is the message: %s(%d)", buffer, n);
        oj_solution_t oj_solution{};
        if (parse_arguments(buffer, oj_solution) < 0) {
            FM_LOG_WARNING("Missing some parameters.");
            n = write(newsockfd, "Missing some parameters.", 24);
            if (n < 0) FM_LOG_WARNING("ERROR writing to socket");
            close(newsockfd);
            return;
        } else {
            n = write(newsockfd, "I got your request.", 19);
            if (n < 0) FM_LOG_WARNING("ERROR writing to socket");

            close(newsockfd);
            ProcessQueue.push(oj_solution);
            return;
        }
    } else {
        FM_LOG_WARNING("Authentication Failed.");
        n = write(newsockfd, "Authentication Failed.", 22);
        if (n < 0) FM_LOG_WARNING("ERROR writing to socket");
    }

    close(newsockfd);
}
Ejemplo n.º 15
0
void 
do_password(dbref player, const char *old, const char *newobj)
{
    if (!check_password(player, old)) 
    {
       notify(player, "Sorry");
    } 
    else if (!ok_password(newobj)) 
    {
       notify(player, "Bad new password.");
    } else {
       set_password(player, newobj);
       notify(player, "Password changed.");
    }
}
Ejemplo n.º 16
0
int main(void) {
  int pass = 0;

  printf("Enter the pin: ");
  pass = check_password();
  if (!pass) {
    puts("Access denied");
    return 1;
  }
  
  /* now give root privelege */
  puts("Correct pin! You are the root!");
  puts("Let do something fun!");

  return 0;
}
Ejemplo n.º 17
0
int cgiMain() {
	int sensor_num,sensor_idx;
	int i,j,k;
	char name[81];
	light_sensor *p_sensor ;

	cgiFormInteger("sensor_num", &sensor_num, 0);
	
	if(sensor_num > 100) sensor_num = 100;

	cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
	cgiHeaderContentType("text/html");

	OutHead();
	OutBodyStart();

	if(0 == check_password())
		return 0;

	if(0 == sensor_num)
	{
		fprintf(cgiOut, "<p>数据出错,退出!!</p>\n");
		OutBodyEnd();	
		return 0;
	}
	else
	{
		pwsw_h.sensor_num= sensor_num;

		for(i=0;i<sensor_num;i++)
		{
			p_sensor = &pwsw_h.sensor[i];
			p_sensor->lux = get_lux(i+1);
			p_sensor->voltage = get_voltage(i+1);
		}
	}

	save_to_xml_file();
	fprintf(cgiOut, "<p>保存成功,请返回!</p>\n");
	fprintf(cgiOut, "&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" name=\"rest\" onclick=\"javascript:history.go(-1)\" value=\"重新载入\" />\n");

	OutBodyEnd();

	return 0;
}
Ejemplo n.º 18
0
/* auth_flatfile_new_user_pass:
 * Attempt to authenticate user and pass using an alternate passwd file,
 * as configured at compile-time. This is a virtual-domains authenticator. */
authcontext auth_flatfile_new_user_pass(const char *user, const char *local_part, const char *domain, const char *pass, const char *clienthost /* unused */, const char *serverhost /* unused */) {
    authcontext a = NULL;
    char *pwhash, *who;

    if (!local_part) return NULL;
    
    who = username_string(user, local_part, domain);

    pwhash = read_user_passwd(local_part, domain);
    if (pwhash) {
        if (check_password(who, pwhash, pass, "{crypt}"))
            a = authcontext_new(virtual_uid, virtual_gid, NULL, NULL, NULL);
        else
            log_print(LOG_ERR, _("auth_flatfile_new_user_pass: failed login for %s"), who);
    }

    return a;
}
Ejemplo n.º 19
0
int main(int argc, char* argv[]){
	if(argc<2){
		printf("usage : %s [passcode]\n", argv[0]);
		return 0;
	}
	if(strlen(argv[1]) != 20){
		printf("passcode length should be 20 bytes\n");
		return 0;
	}

	if(hashcode == check_password( argv[1] )){
		system("/bin/cat flag");
		return 0;
	}
	else
		printf("wrong passcode.\n");
	return 0;
}
Ejemplo n.º 20
0
void
do_password(dbref player, const char *old, const char *newobj)
{

    if (Guest(player)) {
        anotify_fmt(player, CFAIL "%s", tp_noguest_mesg);
        return;
    }

    if (!check_password(player, old)) {
        anotify_nolisten2(player,
                          CFAIL "Syntax: @password <oldpass>=<newpass>");
    } else if (!ok_password(newobj)) {
        anotify_nolisten2(player, CFAIL "Bad new password.");
    } else {
        set_password(player, newobj);
        anotify_nolisten2(player, CFAIL "Password changed.");
    }
}
Ejemplo n.º 21
0
static const char *ircservices_crypt_string(const char *key, const char *salt)
{
	static char output[PASSMAX];
	if (salt[0] == '$' && salt[1] == '1') /* this is a new pw XXX */
	{
		myencrypt(key, strlen(key), output, PASSMAX);
		return output;
	}
	else
	{
		if (check_password(key, salt))
			return salt;
		else
		{
			output[0] = '\0';
			return output;
		}
	}
}
Ejemplo n.º 22
0
boost::tuple<shared_data::action, client_info> shared_data::process_user(const std::string& uname,
        const std::string& phash,
        int session_id)
{
    boost::mutex::scoped_lock lock(guard_);
    // XXX Get password from database.
    // if(lookup_username_in_database_fails) {
    //     return boost::make_tuple(user_not_found, it->second);
    // }
    auto it = clients_.find(uname);
    if(session_id == -1) {
        // No session id, check if user name in list already.
        if(it == clients_.end()) {
            // User name not in list. Let's add it.
            auto ret = clients_.insert(std::pair<std::string, client_info>(uname, client_info(generate_session_id(), true, generate_salt())));
            it = ret.first;
        }
    } else {
        if(it == clients_.end()) {
            // user not in list, but we've got a session id. Expire session and generate a new id.
            auto ret = clients_.insert(std::pair<std::string, client_info>(uname, client_info(generate_session_id(), true, generate_salt())));
            it = ret.first;
        } else {
            // We have been sent a session_id, check if it's valid.
            if(it->second.session_id != session_id) {
                it->second.signed_in = false;
                return boost::make_tuple(bad_session_id, it->second);
            }
        }
    }
    if(phash.empty()) {
        return boost::make_tuple(send_salt, it->second);
    } else {
        if(check_password(it->second.salt, fixed_password, phash)) {
            it->second.signed_in = true;
            return boost::make_tuple(login_success, it->second);
        } else {
            it->second.signed_in = false;
            return boost::make_tuple(password_failed, it->second);
        }
    }
}
Ejemplo n.º 23
0
dbref
connect_player(const char *name, const char *password)
{
    dbref player;

    if (*name == NUMBER_TOKEN && number(name + 1) && atoi(name + 1)) {
        player = (dbref) atoi(name + 1);
        if ((player < 0) || (player >= db_top)
            || (Typeof(player) != TYPE_PLAYER))
            player = NOTHING;
    } else {
        player = lookup_player(name);
    }
    if (player == NOTHING)
        return NOTHING;
    if (!check_password(player, password))
        return NOTHING;

    return player;
}
Ejemplo n.º 24
0
bool ladmin_auth(struct login_session_data* sd, const char* ip)
{
	bool result = false;

	if( str2ip(ip) != host2ip(login_config.admin_allowed_host) )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - IP isn't authorised (ip: %s).\n", ip);
	else
	if( !login_config.admin_state )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (ip: %s)\n", ip);
	else
	if( !check_password(sd->md5key, sd->passwdenc, sd->passwd, login_config.admin_pass) )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - invalid password (ip: %s)\n", ip);
	else
	{
		ShowNotice("'ladmin'-login: Connection in administration mode accepted (ip: %s)\n", ip);
		session[sd->fd]->func_parse = parse_admin;
		result = true;
	}

	return result;
}
Ejemplo n.º 25
0
/**
 * The /ns release command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
int do_release(User * u)
{
    char *nick = strtok(NULL, " ");
    char *pass = strtok(NULL, " ");
    NickAlias *na;

    if (!nick) {
        syntax_error(s_NickServ, u, "RELEASE", NICK_RELEASE_SYNTAX);
    } else if (!(na = findnick(nick))) {
        notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
    } else if (na->status & NS_VERBOTEN) {
        notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
    } else if (na->nc->flags & NI_SUSPENDED) {
        notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
    } else if (!(na->status & NS_KILL_HELD)) {
        notice_lang(s_NickServ, u, NICK_RELEASE_NOT_HELD, nick);
    } else if (pass) {
        int res = check_password(pass, na->nc->pass);
        if (res == 1) {
            release(na, 0);
            notice_lang(s_NickServ, u, NICK_RELEASED);
        } else {
            notice_lang(s_NickServ, u, ACCESS_DENIED);
            if (res == 0) {
                alog("%s: RELEASE: invalid password for %s by %s!%s@%s",
                     s_NickServ, nick, u->nick, u->username, u->host);
                bad_password(u);
            }
        }
    } else {
        if (group_identified(u, na->nc)
            || (!(na->nc->flags & NI_SECURE) && is_on_access(u, na->nc))) {
            release(na, 0);
            notice_lang(s_NickServ, u, NICK_RELEASED);
        } else {
            notice_lang(s_NickServ, u, ACCESS_DENIED);
        }
    }
    return MOD_CONT;
}
Ejemplo n.º 26
0
// Authorize against the opened passwords file. Return 1 if authorized.
static int authorize(struct mg_connection *conn, FILE *fp) {
  struct ah ah;
  char line[256], f_user[256], ha1[256], f_domain[256], buf[MG_BUF_LEN];

  if (!parse_auth_header(conn, buf, sizeof(buf), &ah)) {
    return 0;
  }

  // Loop over passwords file
  while (fgets(line, sizeof(line), fp) != NULL) {
    if (sscanf(line, "%[^:]:%[^:]:%s", f_user, f_domain, ha1) != 3) {
      continue;
    }

    if (!strcmp(ah.user, f_user) &&
        !strcmp(conn->ctx->config[AUTHENTICATION_DOMAIN], f_domain))
      return check_password(conn->request_info.request_method, ha1, ah.uri,
                            ah.nonce, ah.nc, ah.cnonce, ah.qop, ah.response);
  }

  return 0;
}
Ejemplo n.º 27
0
int cgiMain() {
	int sensor_num;
	
	sensor_num = 0;
	cgiFormInteger("sensor_num", &sensor_num, 0);

	pdlc_load_light_sensor_from_xml();

	if(sensor_num > 50) sensor_num = 50;
	
	if(0 == sensor_num)
	{
		sensor_num = pwsw_h.sensor_num;
	}
	else
	{
		pwsw_h.sensor_num = sensor_num;
	}

	cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
	CookieSet();
	cgiHeaderContentType("text/html");

	OutHead();
	OutBodyStart();

	if(0 == check_password())
		return 0;

	//fprintf(cgiOut, "<p>&nbsp; sensor_num=%d -%d</p>\n",pwsw_h.sensor_num,sensor_num);
	
	OutBodyConfigForm(sensor_num);
	OutGroup(sensor_num);


	OutBodyEnd();

	return 0;
}
Ejemplo n.º 28
0
// A handler for the /authorize endpoint.
// Login page form sends user name and password to this endpoint.
struct session* authorize_ex(struct mg_connection *conn,
		const struct mg_request_info *request_info) {
	char user[MAX_USER_LEN], password[MAX_USER_LEN];
	struct session *session;

	if (session = if_authorized(conn, request_info))
		return session;

	// Fetch user name and password.
	get_qsvar(request_info, "user", user, sizeof(user));
	get_qsvar(request_info, "password", password, sizeof(password));

	if (check_password(user, password) && (session = new_session()) != NULL) {
		my_strlcpy(session->user, user, sizeof(session->user));
		snprintf(session->random, sizeof(session->random), "%d", rand());
		generate_session_id(session->session_id, session->random,
				session->user);
		return session;
	}

	return 0;
}
Ejemplo n.º 29
0
// A handler for the /authorize endpoint.
// Login page form sends user name and password to this endpoint.
int authorize(struct mg_connection *conn,
		const struct mg_request_info *request_info) {
	char user[MAX_USER_LEN], password[MAX_USER_LEN];
	struct session *session;

	// Fetch user name and password.
	get_qsvar(request_info, "user", user, sizeof(user));
	get_qsvar(request_info, "password", password, sizeof(password));

	if (check_password(user, password) && (session = new_session()) != NULL) {
		// Authentication success:
		//   1. create new session
		//   2. set session ID token in the cookie
		//   3. remove original_url from the cookie - not needed anymore
		//   4. redirect client back to the original URL
		//
		// The most secure way is to stay HTTPS all the time. However, just to
		// show the technique, we redirect to HTTP after the successful
		// authentication. The danger of doing this is that session cookie can
		// be stolen and an attacker may impersonate the user.
		// Secure application must use HTTPS all the time.
		my_strlcpy(session->user, user, sizeof(session->user));
		snprintf(session->random, sizeof(session->random), "%d", rand());
		generate_session_id(session->session_id, session->random,
				session->user);
		mg_printf(conn, "HTTP/1.1 302 Found\r\n"
				"Set-Cookie: session=%s; max-age=3600; http-only\r\n" // Session ID
				"Set-Cookie: user=%s\r\n"// Set user, needed by Javascript code
				"Set-Cookie: original_url=/; max-age=0\r\n"// Delete original_url
				"Location: /\r\n\r\n", session->session_id, session->user);
		return 1;
	} else {
		// Authentication failure, redirect to login.
		redirect_to_login(conn, request_info);
		return 0;
	}
}
Ejemplo n.º 30
0
int cgiMain() {
	int power_num,group_serial_num[5],group_num,group_idx;
	int i,j,k;
	char name[81];
	ctrl_group *p_group ;

	cgiFormInteger("power_num", &power_num, 0);
	cgiFormInteger("group_num", &group_num, 0);
	memset(name,0,sizeof(name));
	cgiFormStringNoNewlines("serial_num", name, 81);
	get_serial_num(name,&group_serial_num);
	
	if(power_num > 100) power_num = 100;
	if(group_num > 5) group_num = 5;
	if(group_serial_num[0] > 100) group_serial_num[0] = 100;
	if(group_serial_num[1] > 100) group_serial_num[1] = 100;
	if(group_serial_num[2] > 100) group_serial_num[2] = 100;
	if(group_serial_num[3] > 100) group_serial_num[3] = 100;
	if(group_serial_num[4] > 100) group_serial_num[4] = 100;


	cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
	cgiHeaderContentType("text/html");

	OutHead();
	OutBodyStart();

	if(0 == check_password())
		return 0;

	fprintf(cgiOut, "<p>power_num=%d group_num=%d [%d-%d-%d-%d-%d]</p>\n",
		power_num,group_num,group_serial_num[0],group_serial_num[1],
		group_serial_num[2],group_serial_num[3],group_serial_num[4]);

	if(0 == power_num)
	{
		fprintf(cgiOut, "<p>数据出错,退出!!</p>\n");
		OutBodyEnd();	
		return 0;
	}
	else
	{
		pwsw_h.power_num = power_num;
		pwsw_h.group_num = group_num;
		pwsw_h.group[0].ctrl_serial_num = group_serial_num[0];
		pwsw_h.group[1].ctrl_serial_num = group_serial_num[1];
		pwsw_h.group[2].ctrl_serial_num = group_serial_num[2];
		pwsw_h.group[3].ctrl_serial_num = group_serial_num[3];
		pwsw_h.group[4].ctrl_serial_num = group_serial_num[4];

		for(i=0;i<group_num;i++)
		{
			p_group = &pwsw_h.group[i];
			p_group->projector_on = 0;
			p_group->ctrl_serial_num = group_serial_num[i];
			get_start_time(i,&p_group->start_time);
			get_end_time(i,&p_group->end_time);
			for(j=0;j<p_group->ctrl_serial_num;j++)
			{
				p_group->serial_info[j].duration_ms = get_duration_ms(i,j);
				for(k=0;k<power_num;k++)
				{
					p_group->serial_info[j].power_status[k]= get_power_status(i,j,k);
				}
				
			}
		}
	}

	//Out_pwsw_xml();
	save_to_xml_file();
	fprintf(cgiOut, "<p>保存成功,请返回!</p>\n");
	fprintf(cgiOut, "&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" name=\"rest\" onclick=\"javascript:history.go(-1)\" value=\"重新载入\" />\n");

	OutBodyEnd();

	return 0;
}