Skip to content

Commit 4ca34e1

Browse files
Merge pull request #57 from lglglglgy/main
fix bug :1 send msg to your self 2 .. in path
2 parents c0f1067 + f525d90 commit 4ca34e1

File tree

2 files changed

+54
-46
lines changed

2 files changed

+54
-46
lines changed

file_controller.cc

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -85,57 +85,65 @@ void commandsCtrl(const HttpRequestPtr &req, std::function<void(const HttpRespon
8585
command = static_cast<Command>(stoi(req->getJsonObject()->get("command", "").asString()));
8686
std::string params1 = req->getJsonObject()->get("params", "")[0].asString();
8787
std::string params2 = req->getJsonObject()->get("params", "")[1].asString();
88-
switch (command)
88+
if ((params1.find("..") != std::string::npos) || (params2.find("..") != std::string::npos))
8989
{
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)
10496
{
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());
10799
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);
124103

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";
128144
res_json["code"] = 400;
145+
break;
129146
}
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;
139147
}
140148
}
141149
else

mysql.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ Json::Value sql_find_my_msg(const std::string& me, const std::string& connect_ty
459459
updateStmt->executeUpdate();
460460
delete updateStmt;
461461
}
462-
else
462+
if(res->getString("receiver")==me)
463463
{
464464
sql::PreparedStatement *updateStmt = con->prepareStatement(sql0To1_rec);
465465
updateStmt->setInt(1, id);

0 commit comments

Comments
 (0)