from karesansui.lib.rest import Rest, auth
from karesansui.lib.log.config import LogViewConfigParam
from karesansui.lib.const import LOG_VIEW_XML_FILE,DEFAULT_LANGS
-from karesansui.lib.utils import json_dumps, is_param, str2datetime
+from karesansui.lib.utils import json_dumps, is_param, str2datetime, create_epochsec
from karesansui.lib.log.viewer import read_all_log
-class HostBy1LogBy1(Rest):
+from karesansui.lib.checker import Checker, CHECK_EMPTY, CHECK_VALID
+
+def validates_log(obj):
+ checker = Checker()
+ check = True
+
+ _ = obj._
+ checker.errors = []
+
+ if is_param(obj.input, 's'):
+ check = checker.check_datetime_string(_('Log Start Day'),
+ obj.input.s,
+ CHECK_EMPTY | CHECK_VALID,
+ obj.me.languages,
+ ) and check
+
+ if is_param(obj.input, 'e'):
+ check = checker.check_datetime_string(_('Log End Day'),
+ obj.input.e,
+ CHECK_EMPTY | CHECK_VALID,
+ obj.me.languages,
+ ) and check
+
+ if is_param(obj.input, 'st'):
+ check = checker.check_time_string(_('Log Start Time'),
+ obj.input.st,
+ CHECK_EMPTY | CHECK_VALID,
+ ) and check
+
+ if is_param(obj.input, 'et'):
+ check = checker.check_time_string(_('Log End Time'),
+ obj.input.et,
+ CHECK_EMPTY | CHECK_VALID,
+ ) and check
+
+ obj.view.alert = checker.errors
+ return check
+
+class HostBy1LogBy1(Rest):
@auth
def _GET(self, *param, **params):
self.__template__.dir = "hostby1logby1appby1"
appname = param[1]
log_config = None
+ if not validates_log(self):
+ self.logger.debug("Get log failed. Did not validate.")
+ return web.badrequest(self.view.alert)
+
config = LogViewConfigParam(LOG_VIEW_XML_FILE)
config.load_xml_config()
app = config.findby1application(appname)
DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
end_day = str2datetime(self.input.e,
DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
+
+ (start_hour, start_minute) = self.input.st.split(':', 2)
+ (end_hour, end_minute) = self.input.et.split(':', 2)
+
+ start_time = create_epochsec(start_day.year,
+ start_day.month,
+ start_day.day,
+ int(start_hour),
+ int(start_minute),
+ )
+
+ end_time = create_epochsec(end_day.year,
+ end_day.month,
+ end_day.day,
+ int(end_hour),
+ int(end_minute),
+ )
+ if int(start_time) > int(end_time):
+ self.logger.debug("Get report failed. Start time from end time is the future.")
+ # TRANSLATORS:
+ # 開始時刻が終了時刻より未来です
+ return web.badrequest(_('Get report failed. Start time from end time is the future.'))
+
param_value["start_datetime"] = "%s %s" % (start_day.strftime("%Y/%m/%d"), self.input.st)
param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et)
-
+
lines = read_all_log(app,
int(self.input.m),
param_value["start_datetime"],
from karesansui.lib.rest import Rest, auth
from karesansui.lib.log.config import LogViewConfigParam
from karesansui.lib.const import LOG_VIEW_XML_FILE, DEFAULT_LANGS
-from karesansui.lib.utils import json_dumps, is_param, str2datetime
+from karesansui.lib.utils import json_dumps, is_param, str2datetime, create_epochsec
from karesansui.lib.log.viewer import read_log, read_log_with_lotate
+from karesansui.lib.checker import Checker, CHECK_EMPTY, CHECK_VALID
+
+def validates_log(obj):
+ checker = Checker()
+ check = True
+
+ _ = obj._
+ checker.errors = []
+
+ if is_param(obj.input, 's'):
+ check = checker.check_datetime_string(_('Log Start Day'),
+ obj.input.s,
+ CHECK_EMPTY | CHECK_VALID,
+ obj.me.languages,
+ ) and check
+
+ if is_param(obj.input, 'e'):
+ check = checker.check_datetime_string(_('Log End Day'),
+ obj.input.e,
+ CHECK_EMPTY | CHECK_VALID,
+ obj.me.languages,
+ ) and check
+
+ if is_param(obj.input, 'st'):
+ check = checker.check_time_string(_('Log Start Time'),
+ obj.input.st,
+ CHECK_EMPTY | CHECK_VALID,
+ ) and check
+
+ if is_param(obj.input, 'et'):
+ check = checker.check_time_string(_('Log End Time'),
+ obj.input.et,
+ CHECK_EMPTY | CHECK_VALID,
+ ) and check
+
+ obj.view.alert = checker.errors
+ return check
+
class HostBy1LogBy1AppBy1(Rest):
@auth
def _GET(self, *param, **params):
filename = param[2]
log_config = None
+ if not validates_log(self):
+ self.logger.debug("Get log failed. Did not validate.")
+ return web.badrequest(self.view.alert)
+
config = LogViewConfigParam(LOG_VIEW_XML_FILE)
config.load_xml_config()
app = config.findby1application(appname)
lines = []
param_value = {}
- if self.input.has_key("k"):
+ if is_param(self.input, 'k'):
param_value["k"] = self.input.k
else:
param_value["k"] = ""
DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
end_day = str2datetime(self.input.e,
DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
+
+ (start_hour, start_minute) = self.input.st.split(':', 2)
+ (end_hour, end_minute) = self.input.et.split(':', 2)
+
+ start_time = create_epochsec(start_day.year,
+ start_day.month,
+ start_day.day,
+ int(start_hour),
+ int(start_minute),
+ )
+
+ end_time = create_epochsec(end_day.year,
+ end_day.month,
+ end_day.day,
+ int(end_hour),
+ int(end_minute),
+ )
+ if int(start_time) > int(end_time):
+ self.logger.debug("Get report failed. Start time from end time is the future.")
+ # TRANSLATORS:
+ # 開始時刻が終了時刻より未来です
+ return web.badrequest(_('Get report failed. Start time from end time is the future.'))
+
param_value["start_datetime"] = "%s %s" % (start_day.strftime("%Y/%m/%d"), self.input.st)
param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et)
-
+
if log_config['view_lotatelog']:
try:
lines = read_log_with_lotate(filename,
else:
end_hour = today.hour
+ end_minute = today.minute
start_time = create_epochsec(start_day.year,
start_day.month,
<script type="text/javascript">
<!--
+function get_form_value(form){
+ var ret;
+ if(form.jquery != undefined){
+ ret = form[0].value;
+ } else {
+ ret = form.value();
+ }
+ return ret;
+}
+
function validates_log(){
var check = true;
ERROR_MSG = "";