-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a shell and login menu (username: root, password: prad)
- Loading branch information
1 parent
e009669
commit cd4c76b
Showing
12 changed files
with
307 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @file sh_util.h | ||
* @author Pradosh ([email protected]) | ||
* @brief Utils for fw shell. | ||
* @version 0.1 | ||
* @date 2025-01-14 | ||
* | ||
* @copyright Copyright (c) 2025 | ||
* | ||
*/ | ||
#include <basics.h> | ||
#include <memory2.h> | ||
#include <graphics.h> | ||
|
||
#define BUFFER_SIZE 1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @file login.c | ||
* @author your name ([email protected]) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2025-01-14 | ||
* | ||
* @copyright Copyright (c) 2025 | ||
* | ||
*/ | ||
|
||
#include <basics.h> | ||
|
||
char* login_request(){ | ||
char username[21]; // +1 for null terminator | ||
char password[21]; | ||
|
||
char temp; | ||
int i; | ||
|
||
for(int i = 0; i < 30; i++) | ||
__putc('='); | ||
__putc('\n'); | ||
|
||
warn("DON'T USE BACKSPACE!!", __FILE__); | ||
|
||
print("Username: "); | ||
i = 0; | ||
while ((temp = getc()) != 0x1c && i < 20) { | ||
username[i++] = temp; | ||
__putc(temp); | ||
} | ||
username[i] = '\0'; | ||
|
||
print("\nPassword: "); | ||
i = 0; | ||
while ((temp = getc()) != 0x1c && i < 20) { | ||
password[i++] = temp; | ||
__putc('*'); | ||
} | ||
password[i] = '\0'; | ||
|
||
__putc('\n'); | ||
|
||
if (strcmp(username, "root") == 0 && strcmp(password, "prad") == 0) { | ||
memset(username, 0, 21); | ||
memset(password, 0, 21); | ||
return username; // I know this won't give the username.. need to fix! | ||
} else { | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* @file sh.c | ||
* @author your name ([email protected]) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2025-01-14 | ||
* | ||
* @copyright Copyright (c) 2025 | ||
* | ||
*/ | ||
|
||
#include <sh_util.h> | ||
|
||
bool running = true; | ||
|
||
void welcome_message(){ | ||
print("\e[0;34m ______ _ _ _____ _ _ _ \n"); | ||
printf("| ____| | | | |/ ____| | | | |"); | ||
printf("| |__ _ __ ___ ___| |_ ___ __| | (___ | |__ ___| | |"); | ||
printf("| __| '__/ _ \\/ __| __/ _ \\/ _` |\\___ \\| '_ \\ / _ \\ | |"); | ||
printf("| | | | | (_) \\__ \\ || __/ (_| |____) | | | | __/ | |"); | ||
print("|_| |_| \\___/|___/\\__\\___|\\__,_|_____/|_| |_|\\___|_|_|\e[0m\n\n"); | ||
|
||
print("\033[1;32mWelcome to frosted shell!\033[0m This is an implementation of \033[1;34msh\033[0m.\n"); | ||
print("We as the developers try to make this shell as similar as \033[1;34msh\033[0m.\n"); | ||
|
||
display_time(); | ||
} | ||
|
||
int shell_main(int argc, char** argv){ | ||
char* buffer = (char*)malloc(BUFFER_SIZE * sizeof(char)); | ||
int16 bufptr = 0; | ||
|
||
print("\x1b[2J\x1b[H"); | ||
welcome_message(); | ||
|
||
__putc('\n'); | ||
print(argv[0]); | ||
__putc(' '); | ||
__putc('%'); | ||
__putc(' '); | ||
int c; | ||
|
||
while (running) { | ||
c = getc(); | ||
|
||
if (c == 0x1c) { // Enter key | ||
buffer[bufptr] = '\0'; // Null-terminate the string | ||
__putc('\n'); | ||
execute(buffer); | ||
bufptr = 0; // Reset buffer pointer | ||
for (int i = 0; i < BUFFER_SIZE; i++) { | ||
buffer[i] = 0; | ||
} | ||
|
||
if(running){ | ||
print(argv[0]); | ||
__putc(' '); | ||
__putc('%'); | ||
__putc(' '); | ||
} | ||
} else if (c == 0xe) { // Backspace key | ||
if (bufptr > 0) { | ||
bufptr--; | ||
buffer[bufptr] = '\0'; // Adjust null-terminator | ||
__putc('\b'); // Move cursor back | ||
__putc(' '); // Overwrite previous character | ||
__putc('\b'); // Move cursor back again | ||
} | ||
} else { | ||
if (bufptr < BUFFER_SIZE - 1) { | ||
buffer[bufptr++] = (char)c; | ||
} | ||
} | ||
|
||
__putc(c); | ||
} | ||
|
||
free(buffer); | ||
return 0; | ||
} | ||
|
||
void execute(const char* buffer){ | ||
if(strcmp(buffer, "exit") == 0){ | ||
print("\x1b[2J\x1b[H"); | ||
running = false; | ||
} else if(strcmp(buffer, "shutdown") == 0){ | ||
info("Goodbye from Frosted Shell...", __FILE__); | ||
shutdown(); | ||
} else if(strcmp(buffer, "reboot") == 0){ | ||
info("Goodbye from Frosted Shell...", __FILE__); | ||
acpi_reboot(); | ||
} else { | ||
printf("fsh: :%s: not found (length : %d)", buffer, strlen_(buffer)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.