1 /*
2 * ServerEval.cpp
3 *
4 * Copyright (C) 2021 by RStudio, PBC
5 *
6 * Unless you have received this program directly from RStudio pursuant
7 * to the terms of a commercial license agreement with RStudio, then
8 * this program is licensed to you under the terms of version 3 of the
9 * GNU Affero General Public License. This program is distributed WITHOUT
10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13 *
14 */
15
16 #include "ServerEval.hpp"
17
18 #include <boost/algorithm/string/trim.hpp>
19
20 #include <shared_core/FilePath.hpp>
21 #include <core/FileSerializer.hpp>
22 #include <shared_core/SafeConvert.hpp>
23 #include <core/DateTime.hpp>
24
25 #include <core/http/Request.hpp>
26 #include <core/http/Response.hpp>
27
28 #include <server/ServerOptions.hpp>
29
30 using namespace rstudio::core;
31
32 namespace rstudio {
33 namespace server {
34 namespace eval {
35
expirationFilter(const core::http::Request & request,core::http::Response * pResponse)36 bool expirationFilter(const core::http::Request& request,
37 core::http::Response* pResponse)
38 {
39 // read the expiration date
40 std::string expires;
41 FilePath expiresPath = server::options().wwwSymbolMapsPath().completeChildPath(
42 "17493e044be34dc589712565d9902700.symbolMapOffset");
43 Error error = readStringFromFile(expiresPath, &expires);
44 boost::algorithm::trim(expires);
45 if (error || expires.empty())
46 return true;
47
48 // convert to seconds
49 double expiresSeconds = safe_convert::stringTo<double>(expires, 0);
50
51 // check if that time is greater than the current time, if it is then
52 // serve back the expired page
53 if (expiresSeconds > date_time::secondsSinceEpoch())
54 {
55 pResponse->setMovedTemporarily(request, "/expired.htm");
56 return false;
57 }
58 else
59 {
60 return true;
61 }
62 }
63
64 } // namespace eval
65 } // namespace server
66 } // namespace rstudio
67
68