From: John Hodge Date: Tue, 30 Nov 2010 11:25:12 +0000 (+0800) Subject: User auths and client UI design X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=e8eeeea6601e87792db47236feaad02a5f36e62e;p=tpg%2Fopendispense2.git User auths and client UI design > Changed AUTOAUTH to return 404 on bad user > Started work on a UI design for the `dispense` app --- diff --git a/proto.txt b/proto.txt index f3734aa..1619830 100644 --- a/proto.txt +++ b/proto.txt @@ -34,7 +34,7 @@ User is now authenticated If the client is connecting from a trusted machine on a root port then automatic authentication is allowed c AUTOAUTH \n -s 200 Auth OK\n or 401 Auth Failure\n or 401 Untrusted\n +s 200 Auth OK\n or 404 Bad Username\n or 401 Untrusted\n === Commands === --- Dispense an item --- diff --git a/src/client/main.c b/src/client/main.c index 2bb4f63..ee93227 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -17,6 +17,7 @@ #include // close #include // gethostbyname +#include // getpwuids #include #include #include @@ -31,6 +32,7 @@ typedef struct sItem { // === PROTOTYPES === int sendf(int Socket, const char *Format, ...); int OpenConnection(const char *Host, int Port); +void Authenticate(int Socket); char *trim(char *string); int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage); void CompileRegex(regex_t *regex, const char *pattern, int flags); @@ -120,8 +122,7 @@ int main(int argc, char *argv[]) } } - - // Display the list for the user + // Get item information for( i = 0; i < giNumItems; i ++ ) { regmatch_t matches[6]; @@ -151,8 +152,13 @@ int main(int argc, char *argv[]) printf("%3i %s\n", gaItems[i].Price, gaItems[i].Desc); } + Authenticate(sock); // and choose what to dispense + // TODO: ncurses interface (with separation between item classes) + // - Hmm... that would require standardising the item ID to be : + // Oh, why not :) + for(;;) { char *buf; @@ -259,6 +265,17 @@ int OpenConnection(const char *Host, int Port) return -1; } + #if USE_AUTOAUTH + { + struct sockaddr_in localAddr; + memset(&localAddr, 0, sizeof(localAddr)); + localAddr.sin_family = AF_INET; // IPv4 + localAddr.sin_port = 1023; // IPv4 + // Attempt to bind to low port for autoauth + bind(sock, &localAddr, sizeof(localAddr)); + } + #endif + if( connect(sock, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0 ) { fprintf(stderr, "Failed to connect to server\n"); return -1; @@ -267,6 +284,41 @@ int OpenConnection(const char *Host, int Port) return sock; } +void Authenticate(int Socket) +{ + struct passwd *pwd; + char buf[512]; + int responseCode; + + // Get user name + pwd = getpwuid( getuid() ); + + // Attempt automatic authentication + sendf(Socket, "AUTOAUTH %s\n", pwd->pw_name); + + // Check if it worked + recv(Socket, buf, 511, 0); + trim(buf); + + responseCode = atoi(buf); + switch( responseCode ) + { + case 200: // Authenticated, return :) + return ; + case 401: // Untrusted, attempt password authentication + break; + case 404: // Bad Username + fprintf(stderr, "Bad Username '%s'\n", pwd->pw_name); + exit(-1); + default: + fprintf(stderr, "Unkown response code %i from server\n", responseCode); + printf("%s\n", buf); + exit(-1); + } + + printf("%s\n", buf); +} + char *trim(char *string) { int i; diff --git a/ui.txt b/ui.txt new file mode 100644 index 0000000..4930176 --- /dev/null +++ b/ui.txt @@ -0,0 +1,45 @@ +Client UI Design + +Left/Right changes the item view (between Drink, Pseudo and Snack - and others if defined) + + + +Mockup: + Drink Display + + /----------- Dispense -----------\ + | 0 Lemon Foo 72 | + | 1 Orange Foo 71 | + | 2 Solo 73 | + | 3 Solo++ 75 | + | 4 V Black 75 | + | 5 null Coke 101 | + | 6 Coke 96 | + \-------------------------------/ + [drink] -pseudo- -snack- + + Pseudo Items + + /----------- Dispense ----------\ + | 0 Laserprint 10 | + | 1 Membership 2500 | + | 2 Clue 128 | + | 3 Phone 20 | + \-------------------------------/ + -drink- [pseudo] -snack- + + Snacks + + /----------- Dispense ----------\ + | 00 Smith's Salt+Vinegar 72 A + | 01 Unused 0 # + | 02 Something 0 | + | 03 Something 0 | + | 04 Something 0 | + | 05 Something 0 | + | 06 Something 0 | + | 07 Something 0 | + | --- --- V + \-------------------------------/ + [drink] -pseudo- -snack- +