/************************************************************************* * 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 . **************************************************************************/ #include "Connector.h" #include "tcpstack.h" #include "../stringtools.h" #include "../urbackupcommon/escape.h" #include "../urbackupcommon/os_functions.h" #include "../socket_header.h" #ifdef _WIN32 #include #endif #include #include #include std::string Connector::pw; bool Connector::error=false; const size_t conn_retries=4; bool Connector::busy=false; std::string Connector::pwfile="pw.txt"; std::string Connector::pwfile_change="pw_change.txt"; std::string Connector::client="127.0.0.1"; std::string Connector::tokens; namespace { bool LookupBlocking(std::string pServer, in_addr *dest) { const char* host=pServer.c_str(); unsigned int addr = inet_addr(host); if (addr != INADDR_NONE) { dest->s_addr = addr; } else { hostent* hp = gethostbyname(host); if (hp != 0) { memcpy(dest, hp->h_addr, hp->h_length); } else { return false; } } return true; } void read_tokens(std::string token_path, std::string& tokens) { if(os_directory_exists(os_file_prefix(token_path))) { std::vector token_files = getFiles(token_path); for(size_t i=0;i Connector::getSharedPaths(void) { std::vector ret; std::string d=getResponse("GET BACKUP DIRS","",false); int lc=linecount(d); for(int i=0;i &res) { std::string args; for(size_t i=0;i toks; Tokenize(d, toks, "#"); SStatus ret; ret.pause=false; if(toks.size()>0) ret.lastbackupdate=toks[0]; if(toks.size()>1) ret.status=toks[1]; if(toks.size()>2) ret.pcdone=toks[2]; if(toks.size()>3) { if(toks[3]=="P") ret.pause=true; else if(toks[3]=="NP") ret.pause=false; } return ret; } int Connector::startBackup(bool full) { std::string s; if(full) s="START BACKUP FULL"; else s="START BACKUP INCR"; std::string d=getResponse(s,"",false); if(d=="RUNNING") return 2; else if(d=="NO SERVER") return 3; else if(d!="OK") return 0; else return 1; } int Connector::startImage(bool full) { std::string s; if(full) s="START IMAGE FULL"; else s="START IMAGE INCR"; std::string d=getResponse(s,"",false); if(d=="RUNNING") return 2; else if(d=="NO SERVER") return 3; else if(d!="OK") return 0; else return 1; } bool Connector::updateSettings(const std::string &ndata) { std::string data=ndata; escapeClientMessage(data); std::string d=getResponse("UPDATE SETTINGS "+data,"", true); if(d!="OK") return false; else return true; } std::vector Connector::getLogEntries(void) { std::string d=getResponse("GET LOGPOINTS","", true); int lc=linecount(d); std::vector ret; for(int i=0;i Connector::getLogdata(int logid, int loglevel) { std::string d=getResponse("GET LOGDATA","logid="+convert(logid)+"&loglevel="+convert(loglevel), true); std::vector lines; TokenizeMail(d, lines, "\n"); std::vector ret; for(size_t i=0;i& map_paths, bool& no_server ) { no_server=false; if(!readTokens()) { return std::string(); } std::string params = "tokens="+tokens; params+="&path="+EscapeParamString(path); params+="&backupid="+convert(backupid); for (size_t i = 0; i < map_paths.size(); ++i) { params += "&map_path_source"+convert(i)+"=" + EscapeParamString(map_paths[i].source); params += "&map_path_target" + convert(i) + "=" + EscapeParamString(map_paths[i].target); } std::string res = getResponse("DOWNLOAD FILES TOKENS", params, false); if(!res.empty()) { if(res[0]!='0') { if(res[0]=='1') { no_server=true; } return std::string(); } else { return res.substr(1); } } else { return std::string(); } }