/************************************************************************* * UrBackup - Client/Server backup system * Copyright (C) 2011-2016 Martin Raiber * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero 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" #include "backups.h" extern IUrlFactory *url_fak; ACTION_IMPL(logs) { Helper helper(tid, &POST, &PARAMS); JSON::Object ret; SUser *session=helper.getSession(); if(session!=NULL && session->id==SESSION_ID_INVALID) return; std::string filter=POST["filter"]; std::string s_logid=POST["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, ","); for(size_t i=0;iPrepare(qstr); db_results res=q_clients->Read(); q_clients->Reset(); JSON::Array clients; for(size_t i=0;iid!=SESSION_ID_TOKEN_AUTH && session->id!=SESSION_ID_ADMIN); IQuery *q_log_right_clients=db->Prepare("SELECT id, name FROM clients"+(clientid.empty()?"" :" WHERE "+backupaccess::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(POST["report_mail"]); q->Bind(watoi(POST["report_loglevel"])); q->Bind(session->id); q->Write(); q->Reset(); } if(POST.find("report_mail")!=POST.end()) { IQuery *q=db->Prepare("UPDATE settings_db.si_users SET report_mail=?, report_loglevel=?, report_sendonly=? WHERE id=?"); q->Bind(POST["report_mail"]); q->Bind(watoi(POST["report_loglevel"])); q->Bind(watoi(POST["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]["report_mail"]); ret.set("report_loglevel", watoi(res[0]["report_loglevel"])); ret.set("report_sendonly", watoi(res[0]["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", ""); } if (helper.getRights(RIGHT_REPORT_SCRIPT) == RIGHT_ALL) { ret.set("can_report_script_edit", true); } } else { IQuery *q=db->Prepare("SELECT l.clientid AS clientid, ld.data AS logdata, strftime('"+helper.getTimeFormatString()+"', l.created) AS time, c.name AS name " "FROM ((logs l INNER JOIN log_data ld ON l.id=ld.logid) 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]["clientid"]); for(size_t i=0;i