@@ -85,57 +85,65 @@ void commandsCtrl(const HttpRequestPtr &req, std::function<void(const HttpRespon
85
85
command = static_cast <Command>(stoi (req->getJsonObject ()->get (" command" , " " ).asString ()));
86
86
std::string params1 = req->getJsonObject ()->get (" params" , " " )[0 ].asString ();
87
87
std::string params2 = req->getJsonObject ()->get (" params" , " " )[1 ].asString ();
88
- switch (command )
88
+ if ((params1. find ( " .. " ) != std::string::npos) || (params2. find ( " .. " ) != std::string::npos) )
89
89
{
90
- case tree:
91
- result = shell_commands ((" cd " + std::string (pathvar) + " /.. " + " &&" + " tree -J root" ).c_str ());
92
- break ;
93
- case cp:
94
- result = shell_commands ((" cp -v " + std::string (pathvar) + " /../root/" + params1 + " " + std::string (pathvar) + " /../root/" + params2).c_str ());
95
- result = return_status (result, " cp" ,res_json);
96
-
97
- break ;
98
- case mv:
99
- result = shell_commands ((" mv -v " + std::string (pathvar) + " /../root/" + params1 + " " + std::string (pathvar) + " /../root/" + params2).c_str ());
100
- result = return_status (result, " mv" ,res_json);
101
- break ;
102
- case rm:
103
- if (params1.find (" .." ) != std::string::npos)
90
+ result = " error:result in wrong directory" ;
91
+ res_json[" code" ] = 400 ;
92
+ }
93
+ else
94
+ {
95
+ switch (command)
104
96
{
105
- result = " error:result in wrong directory " ;
106
- res_json[ " code " ] = 400 ;
97
+ case tree:
98
+ result = shell_commands (( " cd " + std::string (pathvar) + " /.. " + " && " + " tree -J root " ). c_str ()) ;
107
99
break ;
108
- }
109
- result = shell_commands ((" rm -rf -v " + std::string (pathvar) + " /../root/" + params1).c_str ());
110
- result = return_status (result, " rm" ,res_json);
111
- break ;
112
- case mkdir:
113
- result = shell_commands ((" mkdir -v " + std::string (pathvar) + " /../root/" + params1).c_str ());
114
- result = return_status (result, " mkdir" ,res_json);
115
- break ;
116
- case touch:
117
- if (shell_commands ((" ls -l " + std::string (pathvar) + " /../root/" + params1 + " grep ^- " ).c_str ()).empty ())
118
- {
119
- shell_commands ((" touch " + std::string (pathvar) + " /../root/" + params1).c_str ());
120
- // result = shell_commands(("touch " + std::string(pathvar) + "/../root/" + params1).c_str());
121
- result = " success" ;
122
- res_json[" code" ] = 200 ;
123
- }
100
+ case cp:
101
+ result = shell_commands ((" cp -v " + std::string (pathvar) + " /../root/" + params1 + " " + std::string (pathvar) + " /../root/" + params2).c_str ());
102
+ result = return_status (result, " cp" ,res_json);
124
103
125
- else
126
- {
127
- result = " error:file already exists" ;
104
+ break ;
105
+ case mv:
106
+ result = shell_commands ((" mv -v " + std::string (pathvar) + " /../root/" + params1 + " " + std::string (pathvar) + " /../root/" + params2).c_str ());
107
+ result = return_status (result, " mv" ,res_json);
108
+ break ;
109
+ case rm:
110
+ if (params1.find (" .." ) != std::string::npos)
111
+ {
112
+ result = " error:result in wrong directory" ;
113
+ res_json[" code" ] = 400 ;
114
+ break ;
115
+ }
116
+ result = shell_commands ((" rm -rf -v " + std::string (pathvar) + " /../root/" + params1).c_str ());
117
+ result = return_status (result, " rm" ,res_json);
118
+ break ;
119
+ case mkdir:
120
+ result = shell_commands ((" mkdir -v " + std::string (pathvar) + " /../root/" + params1).c_str ());
121
+ result = return_status (result, " mkdir" ,res_json);
122
+ break ;
123
+ case touch:
124
+ if (shell_commands ((" ls -l " + std::string (pathvar) + " /../root/" + params1 + " grep ^- " ).c_str ()).empty ())
125
+ {
126
+ shell_commands ((" touch " + std::string (pathvar) + " /../root/" + params1).c_str ());
127
+ // result = shell_commands(("touch " + std::string(pathvar) + "/../root/" + params1).c_str());
128
+ result = " success" ;
129
+ res_json[" code" ] = 200 ;
130
+ }
131
+
132
+ else
133
+ {
134
+ result = " error:file already exists" ;
135
+ res_json[" code" ] = 400 ;
136
+ }
137
+ break ;
138
+ case cat:
139
+ result = shell_commands ((" cat " + std::string (pathvar) + " /../root/" + params1).c_str ());
140
+ res_json[" code" ] = 200 ;
141
+ break ;
142
+ default :
143
+ result = " error:command not found" ;
128
144
res_json[" code" ] = 400 ;
145
+ break ;
129
146
}
130
- break ;
131
- case cat:
132
- result = shell_commands ((" cat " + std::string (pathvar) + " /../root/" + params1).c_str ());
133
- res_json[" code" ] = 200 ;
134
- break ;
135
- default :
136
- result = " error:command not found" ;
137
- res_json[" code" ] = 400 ;
138
- break ;
139
147
}
140
148
}
141
149
else
0 commit comments