/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 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 "../server_settings.h"
#include "../os_functions.h"
ACTION_IMPL(status)
{
Helper helper(tid, &GET, &PARAMS);
JSON::Object ret;
std::string rights=helper.getRights("status");
std::vector clientids;
IDatabase *db=helper.getDatabase();
if(rights!="all" && rights!="none" )
{
std::vector s_clientid;
Tokenize(rights, s_clientid, ",");
for(size_t i=0;iid==-1) return;
if(session!=NULL && (rights=="all" || !clientids.empty()) )
{
{
ServerSettings settings(db);
if(!os_directory_exists(settings.getSettings()->backupfolder) || !os_directory_exists(settings.getSettings()->backupfolder_uncompr) || settings.getSettings()->backupfolder.empty())
{
ret.set("dir_error", true);
}
else if(!os_directory_exists(settings.getSettings()->backupfolder+os_file_sep()+L"clients") && !os_create_dir(settings.getSettings()->backupfolder+os_file_sep()+L"clients") )
{
ret.set("dir_error" ,true);
}
}
JSON::Array status;
IDatabase *db=helper.getDatabase();
std::string filter;
if(!clientids.empty())
{
filter=" WHERE ";
for(size_t i=0;iRead("SELECT id, name, strftime('"+helper.getTimeFormatString()+"', lastbackup, 'localtime') AS lastbackup, strftime('"+time_format_str+"', lastseen, 'localtime') AS lastseen,"
"strftime('"+helper.getTimeFormatString()+"', lastbackup_image, 'localtime') AS lastbackup_image FROM clients"+filter);
int backup_ok_mod=3;
db_results res_t=db->Read("SELECT value FROM settings WHERE key='backup_ok_mod' AND clientid=0");
if(res_t.size()>0)
{
backup_ok_mod=watoi(res_t[0][L"value"]);
}
for(size_t i=0;iPrepare("SELECT id FROM clients WHERE lastbackup IS NOT NULL AND datetime('now','-"+nconvert(settings.getSettings()->update_freq_incr*backup_ok_mod)+" seconds')Bind(clientid);
db_results res_file_ok=q->Read();
q->Reset();
stat.set("file_ok", !res_file_ok.empty());
q=db->Prepare("SELECT id FROM clients WHERE lastbackup_image IS NOT NULL AND datetime('now','-"+nconvert(settings.getSettings()->update_freq_image_incr*backup_ok_mod)+" seconds')Bind(clientid);
res_file_ok=q->Read();
q->Reset();
stat.set("image_ok", !res_file_ok.empty());
status.add(stat);
}
ret.set("status", status);
}
else
{
ret.set("error", 1);
}
helper.Write(ret.get(false));
}
#endif //CLIENT_ONLY