From 54e33ef79af343260db44f368f6dab9e89ed1b2d Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Mon, 20 Aug 2012 00:05:19 -0700 Subject: [PATCH] Moving code to ethernet but not sure if this is the right way to do it --- Open_Access_Control_Ethernet.ino | 91 ++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/Open_Access_Control_Ethernet.ino b/Open_Access_Control_Ethernet.ino index f55ca7c..34aa0ae 100644 --- a/Open_Access_Control_Ethernet.ino +++ b/Open_Access_Control_Ethernet.ino @@ -292,14 +292,13 @@ void loop() // Main branch, runs over and ov if(readString.indexOf("?hi") > 0) { client.println("hi"); } - if(readString.indexOf("?s") > 0) { + if(readString.indexOf("?s") > 0) { // list user int offset = readString.indexOf("?s"); - char usernum[3] = {readString[offset+2],readString[offset+3],readString[offset+4]}; + char usernum[4] = {readString[offset+2],readString[offset+3],readString[offset+4],'\0'}; - client.print("m"); + client.print("s"); client.println(usernum); } - /* if(readString.indexOf("?m") > 0) { client.println("m"); // modify user } @@ -312,7 +311,6 @@ void loop() // Main branch, runs over and ov if(readString.indexOf("?o") > 0) { client.println("o"); // open } - */ if(readString.indexOf("?u") > 0) { unlockall(); client.println("u"); @@ -350,7 +348,9 @@ void loop() // Main branch, runs over and ov client.println(""); } if(readString.indexOf("?e") > 0) { - client.println("e"); + char pass[5] = {readString[offset+2],readString[offset+3],readString[offset+4],readString[offset+5],'\0'}; + + login(strtoul(pass,NULL,16)); } break; @@ -1443,6 +1443,45 @@ void dumpUser(byte usernum) // Return else Serial.println("Bad user number!"); } +void login(long input) { + logDate(); + if((consoleFail>=5) && (millis()-consolefailTimer<300000)) // Do not allow priv mode if more than 5 failed logins in 5 minute + { + PROGMEMprintln(privsAttemptsMessage); + } + else { + if (input == PRIVPASSWORD) + { + consoleFail=0; + PROGMEMprintln(privsenabledMessage); + privmodeEnabled=true; + } + else { + PROGMEMprintln(privsdisabledMessage); + privmodeEnabled=false; + if(consoleFail==0) { // Set the timeout for failed logins + consolefailTimer=millis(); + } + consoleFail++; // Increment the login failure counter + } + } +} + +void showUser(char* input) { + + if(privmodeEnabled==true) { + Serial.print("UserNum:"); + Serial.print(" "); + Serial.print("Usermask:"); + Serial.print(" "); + Serial.println("TagNum:"); + dumpUser(atoi(input)); + //Serial.println(); // commented out due to dumpUser always printing a line -WB 7-7-2011 + } + else{logprivFail();} + +} + /* Displays a serial terminal menu system for * user management and other tasks @@ -1494,29 +1533,8 @@ if(inCount==0) { case 'e': { // Enable "privileged" commands at console - logDate(); - - if((consoleFail>=5) && (millis()-consolefailTimer<300000)) // Do not allow priv mode if more than 5 failed logins in 5 minute - { - PROGMEMprintln(privsAttemptsMessage); - break; - } - if (strtoul(cmdString[1],NULL,16) == PRIVPASSWORD) - { - consoleFail=0; - PROGMEMprintln(privsenabledMessage); - privmodeEnabled=true; - } - else { - PROGMEMprintln(privsdisabledMessage); - privmodeEnabled=false; - if(consoleFail==0) { // Set the timeout for failed logins - consolefailTimer=millis(); - } - consoleFail++; // Increment the login failure counter - } - - break; + login(strtoul(cmdString[1],NULL,16)); + break; } @@ -1542,18 +1560,9 @@ if(inCount==0) { break; } - case 's': { // List user - if(privmodeEnabled==true) { - Serial.print("UserNum:"); - Serial.print(" "); - Serial.print("Usermask:"); - Serial.print(" "); - Serial.println("TagNum:"); - dumpUser(atoi(cmdString[1])); - //Serial.println(); // commented out due to dumpUser always printing a line -WB 7-7-2011 - } - else{logprivFail();} - break; + case 's': { // List user + showUser(cmdString[1]); + break; } case 'd': { // Display current time