Skip to content

Commit 2361862

Browse files
committed
[webgui] remove tmp html file after connection established
Temporary file required to start browser. Then connection established - information is not longer necessary. Also increase security.
1 parent 6f2c01e commit 2361862

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

gui/webdisplay/inc/ROOT/RWebDisplayHandle.hxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public:
109109
/// resize web window - if possible
110110
virtual bool Resize(int, int) { return false; }
111111

112+
/// remove file which was used to startup widget - if possible
113+
virtual void RemoveStartupFiles() {}
114+
112115
static bool NeedHttpServer(const RWebDisplayArgs &args);
113116

114117
static std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args);

gui/webdisplay/src/RWebDisplayHandle.cxx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ class RWebBrowserHandle : public RWebDisplayHandle {
125125
browser_process_id fPid;
126126

127127
public:
128-
RWebBrowserHandle(const std::string &url, const std::string &tmpdir, const std::string &tmpfile, const std::string &dump) :
129-
RWebDisplayHandle(url), fTmpDir(tmpdir), fTmpFile(tmpfile)
128+
RWebBrowserHandle(const std::string &url, const std::string &tmpdir, const std::string &tmpfile,
129+
const std::string &dump)
130+
: RWebDisplayHandle(url), fTmpDir(tmpdir), fTmpFile(tmpfile)
130131
{
131132
SetContent(dump);
132133
}
133134

134-
RWebBrowserHandle(const std::string &url, const std::string &tmpdir, const std::string &tmpfile, browser_process_id pid)
135+
RWebBrowserHandle(const std::string &url, const std::string &tmpdir, const std::string &tmpfile,
136+
browser_process_id pid)
135137
: RWebDisplayHandle(url), fTmpDir(tmpdir), fTmpFile(tmpfile), fHasPid(true), fPid(pid)
136138
{
137139
}
@@ -140,19 +142,30 @@ class RWebBrowserHandle : public RWebDisplayHandle {
140142
{
141143
#ifdef _MSC_VER
142144
if (fHasPid)
143-
gSystem->Exec(("taskkill /F /PID "s + std::to_string(fPid) + " >NUL 2>NUL").c_str());
144-
std::string rmdir = "rmdir /S /Q ", rmfile = "del /F ";
145+
gSystem->Exec(("taskkill /F /PID " s + std::to_string(fPid) + " >NUL 2>NUL").c_str());
146+
std::string rmdir = "rmdir /S /Q ";
145147
#else
146148
if (fHasPid)
147149
kill(fPid, SIGKILL);
148-
std::string rmdir = "rm -rf ", rmfile = "rm -f ";
150+
std::string rmdir = "rm -rf ";
149151
#endif
150152
if (!fTmpDir.empty())
151153
gSystem->Exec((rmdir + fTmpDir).c_str());
152-
if (!fTmpFile.empty())
153-
gSystem->Exec((rmfile + fTmpFile).c_str());
154+
RemoveStartupFiles();
154155
}
155156

157+
void RemoveStartupFiles() override
158+
{
159+
#ifdef _MSC_VER
160+
std::string rmfile = "del /F ";
161+
#else
162+
std::string rmfile = "rm -f ";
163+
#endif
164+
if (!fTmpFile.empty()) {
165+
gSystem->Exec((rmfile + fTmpFile).c_str());
166+
fTmpFile.clear();
167+
}
168+
}
156169
};
157170

158171
} // namespace ROOT

gui/webdisplay/src/RWebWindow.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ bool RWebWindow::ProcessWS(THttpCallArg &arg)
820820

821821
for (auto &conn : fPendingConn)
822822
if (_CanTrustIn(conn, key, ntry, is_remote, true /* test_first_time */))
823-
return true;
823+
return true;
824824

825825
return false;
826826
}
@@ -860,6 +860,9 @@ bool RWebWindow::ProcessWS(THttpCallArg &arg)
860860
// preserve key for longpoll or when with session key used for HMAC hash of messages
861861
// conn->fKey.clear();
862862
conn->ResetStamps();
863+
// remove files which are required for startup
864+
if (conn->fDisplayHandle)
865+
conn->fDisplayHandle->RemoveStartupFiles();
863866
if (conn->fWasFirst)
864867
fConn.emplace(fConn.begin(), conn);
865868
else

0 commit comments

Comments
 (0)