/************************************************************************* * UrBackup - Client/Server backup system * Copyright (C) 2011-2014 Martin Raiber * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . **************************************************************************/ #ifndef CLIENT_ONLY #include "action_header.h" #include "../../urbackupcommon/os_functions.h" #include "../../urlplugin/IUrlFactory.h" extern IUrlFactory *url_fak; std::string constructFilter(const std::vector &clientid, std::string key); ACTION_IMPL(logs) { Helper helper(tid, &GET, &PARAMS); JSON::Object ret; SUser *session=helper.getSession(); if(session!=NULL && session->id==-1) return; std::wstring filter=GET[L"filter"]; std::wstring s_logid=GET[L"logid"]; int logid=watoi(s_logid); std::string rights=helper.getRights("logs"); std::vector clientid; if(rights!="all" && rights!="none" ) { std::vector s_clientid; Tokenize(rights, s_clientid, ","); for(size_t i=0;i0 && filter.empty() ) { for(size_t i=0;i v_filter; if(!filter.empty()) { std::vector s_filter; Tokenize(filter, s_filter, L","); for(size_t i=0;iPrepare(qstr); db_results res=q_clients->Read(); q_clients->Reset(); JSON::Array clients; for(size_t i=0;iPrepare("SELECT id, name FROM clients"+(clientid.empty()?"" :" WHERE "+constructFilter(clientid, "id"))+" ORDER BY name"); res=q_log_right_clients->Read(); q_log_right_clients->Reset(); JSON::Array log_right_clients; for(size_t i=0;iPrepare(qstr); res=q->Read(); q->Reset(); JSON::Array logs; for(size_t i=0;iPrepare("UPDATE settings_db.si_users SET report_mail=?, report_loglevel=? WHERE id=?"); q->Bind(GET[L"report_mail"]); q->Bind(watoi(GET[L"report_loglevel"])); q->Bind(session->id); q->Write(); q->Reset(); } if(GET.find(L"report_mail")!=GET.end()) { IQuery *q=db->Prepare("UPDATE settings_db.si_users SET report_mail=?, report_loglevel=?, report_sendonly=? WHERE id=?"); q->Bind(GET[L"report_mail"]); q->Bind(watoi(GET[L"report_loglevel"])); q->Bind(watoi(GET[L"report_sendonly"])); q->Bind(session->id); q->Write(); ret.set("saved_ok", true); } IQuery *mq=db->Prepare("SELECT report_mail, report_loglevel, report_sendonly FROM settings_db.si_users WHERE id=? AND report_mail IS NOT NULL"); mq->Bind(session->id); res=mq->Read(); mq->Reset(); if(!res.empty()) { ret.set("report_mail", res[0][L"report_mail"]); ret.set("report_loglevel", watoi(res[0][L"report_loglevel"])); ret.set("report_sendonly", watoi(res[0][L"report_sendonly"])); } else { ret.set("report_mail", ""); ret.set("report_sendonly", ""); ret.set("report_loglevel", ""); } if(url_fak!=NULL) { ret.set("HAS_MAIL_START", ""); ret.set("HAS_MAIL_STOP", ""); } else { ret.set("HAS_MAIL_START", ""); } } else { IQuery *q=db->Prepare("SELECT l.clientid AS clientid, l.logdata AS logdata, strftime('"+helper.getTimeFormatString()+"', l.created, 'localtime') AS time, c.name AS name FROM logs l INNER JOIN clients c ON l.clientid=c.id WHERE l.id=?"); q->Bind(logid); db_results res=q->Read(); q->Reset(); if(!res.empty()) { bool ok=true; if(!clientid.empty()) { ok=false; int t_clientid=watoi(res[0][L"clientid"]); for(size_t i=0;i