Skip to content

Commit

Permalink
♾ fixing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFTN committed Dec 13, 2022
1 parent 8950671 commit 07b88be
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
26 changes: 15 additions & 11 deletions client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

int main() {
char *handshake = "MySecurity - HandShake";
char message[256];
char message[1024] = { 0 };
int client, error, sock = 0;
bool mysecurity, connected;
bool connected;
char *command;

// Start Client
Expand All @@ -21,16 +21,20 @@ int main() {
if (error < 0)
return -1;

// Receive from server
error = receive_socket(sock, message);
if (error < 0)
return -1;
while (connected)
{
// Receive from server
error = receive_socket(sock, message);
if (error < 0)
return -1;

printf("< ");
scanf("%s", command);
error = send_socket(sock, command);
if (error < 0)
return -1;
// Send to server
printf("< ");
scanf("%s", command);
error = send_socket(sock, command);
if (error < 0)
return -1;
}

return 0;
}
1 change: 0 additions & 1 deletion client/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ int send_socket(int sock, char *buffer)
return -1;
}

printf("> %s\n", buffer);
return 0;
}

Expand Down
27 changes: 16 additions & 11 deletions server/handler/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,21 @@ int get_instance_info(char* name, char* ip)
}

// Get option and execute a command
int run_command(char *option, int client, bool *mysecurity)
int run_command(char *option, bool *mysecurity, bool *connected)
{
printf("[!] run command: %s", option);
if (option[0] == '1') { *mysecurity = false; return -1; }
if (option[0] == '2') { close(client); return -1; }
#ifdef __unix__
if (option[0] == '0') { system("sudo shutdown -P now"); return 0; }
#endif
#ifdef _WIN32
if (option[0] == '0') { system("shutdown -s -c 'mySecurity'"); return 0; }
#endif
return -1;
printf("[!] run command: %s\n", option);
if (option[0] == '0')
{
printf("shutting down computer");
system("sudo shutdown -P");
return 0;

} else if (option[0] == '1')
{
*connected = false;
*mysecurity = false;
return 0;
}

return -1;
}
2 changes: 1 addition & 1 deletion server/handler/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ char *get_commands();
int get_instance_info(char *name, char* ip);

// Get option and execute a command
int run_command(char *option, int client, bool *mysecurity);
int run_command(char *option, bool *mysecurity, bool *connected);
9 changes: 2 additions & 7 deletions server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
int main()
{
bool connected, handshaked;
char option[1024] = { 0 };
bool mysecurity = true;
char handshake[64];
char *option;
int client;
int sock;
int error;
Expand Down Expand Up @@ -53,19 +53,14 @@ int main()
close_socket(client, sock);

// Handle user option
error = run_command(option, client, &mysecurity);
error = run_command(option, &mysecurity, &connected);
if (error < 0)
{
error = send_socket(client, "[!] Invalid option");
if (error < 0)
close_socket(client, sock);
}
}

// Close socket server
error = close_socket(client, sock);
if (error < 0)
return -1;
}
return 0;
}
1 change: 0 additions & 1 deletion server/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ int send_socket(int client, char *buffer)
return -1;
}

printf("> %s\n", buffer);
return 0;
}

Expand Down

0 comments on commit 07b88be

Please sign in to comment.