-
Notifications
You must be signed in to change notification settings - Fork 121
/
shell.cpp
70 lines (55 loc) · 2.46 KB
/
shell.cpp
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
#include "Platforms/General/PFmain.h"
#include "Widget_Systems/widgets_mandatory.h"
static bool asked_if_idiot = false;
static bool confirmed_idiot = false;
static void ask_if_idiot() {
if (!asked_if_idiot) {
if (enigma_user::show_question("The following game runs shell functions that are almost always unnecessary\
and can potentionally cause irreparable harm to your system such as deleting you home folder.\
We advise only enabling these functions after careful inspection of the game's source code\
Would you like to enable these dangerous funtions?")) { confirmed_idiot = true; }
asked_if_idiot = true;
}
}
namespace enigma_insecure {
void execute_shell(std::string operation, std::string fname, std::string args, bool wait) {
if (system(NULL)) {
system(("\"" + fname + "\" " + args + (wait ? " &" : "")).c_str());
} else {
DEBUG_MESSAGE("execute_program cannot be used as there is no command processor!", MESSAGE_TYPE::M_ERROR);
return;
}
}
void execute_shell_for_output(const std::string &command, std::string& res) {
char buffer[BUFSIZ];
FILE *pf = popen(command.c_str(), "r");
while (!feof(pf)) {
res.append(buffer, fread(&buffer, sizeof(char), BUFSIZ, pf));
}
pclose(pf);
}
}
namespace enigma_user {
void execute_shell(std::string operation, std::string fname, std::string args) {
ask_if_idiot();
if (confirmed_idiot) enigma_insecure::execute_shell(operation, fname, args, false);
}
void execute_shell(std::string fname, std::string args) { execute_shell("", fname, args); }
void execute_program(std::string operation, std::string fname, std::string args, bool wait) {
ask_if_idiot();
if (confirmed_idiot) enigma_insecure::execute_shell(operation, fname, args, wait);
}
std::string execute_shell_for_output(const std::string &command) {
ask_if_idiot();
std::string res;
if (confirmed_idiot) enigma_insecure::execute_shell_for_output(command, res);
return res;
}
void execute_program(std::string fname, std::string args, bool wait) { execute_program("", fname, args, wait); }
void url_open(std::string url, std::string target, std::string options) {
execute_program("xdg-open", url, false);
}
void url_open_ext(std::string url, std::string target) { url_open(url, target); }
void url_open_full(std::string url, std::string target, std::string options) { url_open(url, target, options); }
void action_webpage(const std::string& url) { url_open(url); }
} // namespace enigma_user