-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpumaMenu.c
283 lines (230 loc) · 7 KB
/
pumaMenu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/***************************************************************
*
* Mark Foudy
* August 15, 2022
* pumaMenu.c
*
* This is my menu for my Penguin User Management Assistant (PUMA).
*
************************************************************ */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "list.c"
#define MAXIPLENGTH 15
void printMenu();
int getUserChoice();
int executeMenu();
void showListADT();
node **headPtr;
/* ***************************************************************** *
* function mainMenu prints the menu choices for available for Users
* ***************************************************************** */
void mainMenu() {
system("clear");
printf("----------------------------------- \n");
printf("Welcome to the PENGUIN USER MANAGEMENT ASSISTANT (PUMA): \n");
printf("Please select one of the choices below: \n");
printf("----------------------------------- \n");
printf(" 1 -- INPUT RAW DATA FILE \n");
printf(" 2 -- PRINT USER DATA\n");
printf(" 3 -- SEARCH BY USERNAME \n");
printf(" 4 -- SEARCH ON IP ADDRESS \n");
printf(" 5 -- SEARCH ON MAC ADDRESS \n");
printf(" 6 -- SORT BY USERNAME\n");
printf(" 7 -- DELETE USER CREDENTIALS LIST\n");
printf(" 8 -- Quit \n");
printf("----------------------------------- \n");
}
/* ******************************************************************
* function printMenu is the function called
* whenever a system administrator wants to retrieve a list of users.
* ******************************************************************/
void printMenu() {
int tempChoice = 0;
while(tempChoice != 6){
system("clear");
printf("----------------------------------- \n");
printf("PRINT USER DATA MENU: \n");
printf("Please select one of the choices below: \n");
printf("----------------------------------- \n");
printf(" 1 -- Print Raw Data File TO CONSOLE\n");
printf(" 2 -- Print authorized user list TO CONSOLE\n");
printf(" 3 -- Print unauthorized user list TO CONSOLE\n");
printf(" 4 -- Print authorized user list TO FILE\n");
printf(" 5 -- Print unauthorized user list TO FILE\n");
printf(" 6 -- Back to Main Menu \n");
printf("----------------------------------- \n");
printf("Enter choice (1-6): ");
fflush(stdin);
scanf("%d", &tempChoice);
printf("\n");
switch (tempChoice) {
case (1):
printf("Print Raw Data File TO CONSOLE\n");
printListAllToConsole(*headPtr);
break;
case (2):
printf("Print authorized user list TO CONSOLE\n");
printAuthListToConsole(*headPtr);
break;
case (3):
printf("Print unauthorized user list TO CONSOLE\n");
printUnauthListToConsole(*headPtr);
break;
case (4):
printf("Print authorized user list TO EXPORT FILE\n");
printAuthListToFile(*headPtr);
break;
case (5):
printf("Print unauthorized user list TO EXPORT FILE\n");
printUnauthListToFile(*headPtr);
break;
case (6):
printf("Back to Main Menu \n");
mainMenu();
break;
default:
printf("Back to Main Menu \n");
mainMenu();
break;
}
if(tempChoice != 6){
printf("Press any key to continue\n");
getchar();
fflush(stdin);
getchar();
fflush(stdout);
}
}
}
/* ************************************************************************
* function GETUSERCHOICE gets input from user and returns integer
* ***********************************************************************/
int getUserChoice() {
int tempChoice = 0;
mainMenu();
printf("Enter choice (1-8): ");
fflush(stdin);
scanf("%d", &tempChoice);
printf("\n");
return tempChoice;
}
/***************************************************************
* function EXECUTE_MENU displays menu and implements user choice.
*
* **************************************************************/
int executeMenu() {
int tempChoice = 0;
char uname[30];
char ip[16];
char mac[18];
node *returnNode = (node *)malloc(sizeof(node));
clock_t t;
long double time_taken;
tempChoice = getUserChoice();
switch (tempChoice) {
case (1):
printf("THIS SELECTION WILL INPUT ALL USER DATA.\n");
populateList(headPtr);
break;
case (2):
printf("THIS SELECTION WILL PRINT ALL USER DATA\n");
printMenu();
break;
case(3):
printf("THIS SELECTION WILL SEARCH BY USERNAME.\n");
printf("Enter a username to search on: ");
scanf("%s", uname);
// initialize clock
t = clock();
returnNode = findItem(*headPtr, 0, uname);
// prompt System Admin if User isn't located
if (returnNode == NULL)
printf("User not found.\n");
else
printNode(returnNode);
// stop clock
t = clock() - t;
// calculate time_taken
time_taken = ((double) t)/CLOCKS_PER_SEC;
printf("Search by UserName took %.25Lf seconds to execute\n", time_taken);
break;
case (4):
printf("THIS SELECTION WILL SEARCH BY IP ADDRESS.\n");
printf("Enter a IP Address to search on: ");
scanf("%s", ip);
// initialize clock
t = clock();
returnNode = findItem(*headPtr, 1, ip);
// prompt system admin if IP isn't located
if (returnNode == NULL)
printf("IP ADDRESS not found.\n");
else
printNode(returnNode);
// stop clock
t = clock() - t;
// calculate time_taken
time_taken = ((double) t)/CLOCKS_PER_SEC;
printf("Search by IP Address took %.25Lf seconds to execute\n", time_taken);
break;
case (5):
printf("THIS SELECTION WILL SEARCH BY MAC ADDRESS.\n");
printf("Enter a MAC Address to search on: ");
scanf("%s", mac);
// initialize clock
t = clock();
returnNode = findItem(*headPtr, 2, mac);
// prompt System Admin if MAC Address is not located
if (returnNode == NULL)
printf("MAC ADDRESS not found.\n");
else
printNode(returnNode);
// stop the clock
t = clock() - t;
// calculate time taken
time_taken = ((double) t)/CLOCKS_PER_SEC;
printf("Search by MAC Address took %.25Lf seconds to execute\n", time_taken);
break;
break;
case (6):
printf("THIS SELECTION WILL SORT BY USERNAME. \n");
sortList(headPtr);
break;
case (7):
printf("THIS SELECTION WILL DELETE USER CREDENTIAL LIST. \n");
deleteList(headPtr);
break;
case (8):
printf("Quitting now. Bye. \n");
break;
default:
printf("invalid choice ... choose again \n");
break;
} //SWITCH
printf("Press any key to continue\n");
getchar();
fflush(stdin);
getchar();
fflush(stdout);
return tempChoice;
}
/* ***************************************************************** *
* FUNCTION showListADT
* ***************************************************************** */
void showListADT(){
int userChoice = -1;
do {
userChoice = executeMenu();
} while (userChoice != 8);
}
/******************************************/
int main(){
srand(time(0));
headPtr = (node **) malloc (sizeof(node **));
// creation of the list
*headPtr = createList();
showListADT();
return 0;
}