16
16
#include < limits.h>
17
17
18
18
class SecShell {
19
- std::unordered_map<pid_t , std::string> jobs;
19
+ std::unordered_map<pid_t , std::string> jobs;
20
20
bool running = true ;
21
21
22
22
// Security whitelists
@@ -125,7 +125,7 @@ class SecShell {
125
125
}
126
126
127
127
void display_history () {
128
- std::string drawbox_command = " drawbox \" Command History \" bold_white" ;
128
+ std::string drawbox_command = " drawbox \" Command History \" bold_white" ;
129
129
int result = system (drawbox_command.c_str ());
130
130
131
131
if (result != 0 ) {
@@ -166,19 +166,31 @@ class SecShell {
166
166
}
167
167
168
168
void list_env_variables () {
169
+ std::string drawbox_command = " drawbox \" Environment Variable \" bold_white" ;
170
+ int result = system (drawbox_command.c_str ());
171
+
172
+ if (result != 0 ) {
173
+ print_error (" Failed to execute drawbox command." );
174
+ return ;
175
+ }
169
176
extern char ** environ;
170
177
for (char ** env = environ; *env; env++) {
171
178
std::cout << *env << " \n " ;
172
179
}
173
180
}
174
181
175
182
void unset_env_variable (const std::vector<std::string>& args) {
183
+ std::string var_value = args[1 ];
184
+
185
+
176
186
if (args.size () < 2 ) {
177
187
print_error (" Usage: unset VAR" );
178
188
return ;
179
189
}
180
190
if (unsetenv (args[1 ].c_str ()) != 0 ) {
181
191
print_error (" Failed to unset environment variable: " + std::string (strerror (errno)));
192
+ } else {
193
+ print_alert (" Unset: " + var_value);
182
194
}
183
195
}
184
196
@@ -670,6 +682,16 @@ class SecShell {
670
682
} else {
671
683
arg += c;
672
684
}
685
+ } else if (c == ' $' && !in_quotes) {
686
+ // Handle environment variable expansion
687
+ std::string var_name;
688
+ while (i + 1 < input.length () && (isalnum (input[i + 1 ]) || input[i + 1 ] == ' _' )) {
689
+ var_name += input[++i];
690
+ }
691
+ const char * var_value = getenv (var_name.c_str ());
692
+ if (var_value) {
693
+ arg += var_value;
694
+ }
673
695
} else if (c == ' ' && !in_quotes) {
674
696
if (!arg.empty ()) {
675
697
args.push_back (arg);
@@ -688,7 +710,7 @@ class SecShell {
688
710
}
689
711
690
712
static void signal_handler (int signum) {
691
- std::cout << " \n Received signal " << signum << " . Use 'exit' to quit.\n " ;
713
+ std::cout << " \n Received signal " << signum << " . Use 'exit' to quit. Press ENTER to continue... \n " ;
692
714
}
693
715
};
694
716
@@ -725,6 +747,11 @@ std::string get_executable_directory() {
725
747
}
726
748
727
749
int main (int argc, char * argv[]) {
750
+ #ifdef _WIN32
751
+ system (" cls" );
752
+ #elif defined(unix) || defined(__unix__) || defined(__unix)
753
+ system (" clear" );
754
+ #endif
728
755
729
756
// Get the directory of the executable
730
757
std::string exe_dir = get_executable_directory ();
0 commit comments