From f34899d430101505842ae442792ac66db07c6e9b Mon Sep 17 00:00:00 2001 From: TangoCash Date: Thu, 15 Jun 2017 16:34:19 +0200 Subject: [PATCH] [RemoteTimers] add possibility to transfer all timers at once via webif Use: http://boxip/control/sendalltimers?ip=10.1.1.xxx&force=1 http://boxip/control/sendalltimers?name=record%20box&force=true if parameter name is given, it has to be in timerlist as remote box. if parameter ip and name is given, ip is used. if parameter force is set, all checks are disabled, and the local timer will be deleted even the transfer was not successful. Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/7031e99573959206d0cd887f04c2ebe8d0b8d408 Author: TangoCash Date: 2017-06-15 (Thu, 15 Jun 2017) ------------------ This commit was generated by Migit --- src/nhttpd/tuxboxapi/controlapi.cpp | 28 +++++++++++++++ src/nhttpd/tuxboxapi/controlapi.h | 1 + src/nhttpd/tuxboxapi/neutrinoapi.cpp | 52 ++++++++++++++++++++++++++++ src/nhttpd/tuxboxapi/neutrinoapi.h | 2 ++ 4 files changed, 83 insertions(+) diff --git a/src/nhttpd/tuxboxapi/controlapi.cpp b/src/nhttpd/tuxboxapi/controlapi.cpp index 38e47231d..296c83ae7 100644 --- a/src/nhttpd/tuxboxapi/controlapi.cpp +++ b/src/nhttpd/tuxboxapi/controlapi.cpp @@ -209,6 +209,7 @@ const CControlAPI::TyCgiCall CControlAPI::yCgiCallList[]= {"crypt", &CControlAPI::CryptCGI, "text/plain"}, // timer {"timer", &CControlAPI::TimerCGI, "text/plain"}, + {"sendalltimers", &CControlAPI::TimerSendCGI, "text/plain"}, // bouquet editing {"setbouquet", &CControlAPI::setBouquetCGI, "text/plain"}, {"savebouquet", &CControlAPI::saveBouquetCGI, "text/plain"}, @@ -335,7 +336,34 @@ void CControlAPI::TimerCGI(CyhookHandler *hh) hh->SendError(); } +void CControlAPI::TimerSendCGI(CyhookHandler *hh) +{ + hh->outStart(); + + if (NeutrinoAPI->Timerd->isTimerdAvailable()) + { + if (!hh->ParamList.empty()) + { + bool force = (hh->ParamList["force"] == "1") || (hh->ParamList["force"] == "true"); + if(!hh->ParamList["ip"].empty()) + { + NeutrinoAPI->SendAllTimers(hh->ParamList["ip"],force); + hh->SendOk(); + } + else if(!hh->ParamList["name"].empty()) + { + NeutrinoAPI->SendAllTimers(NeutrinoAPI->GetRemoteBoxIP(decodeString(hh->ParamList["name"])),force); + hh->SendOk(); + } + else + hh->SendError(); + } + } + else + hh->SendError(); +} //----------------------------------------------------------------------------- + void CControlAPI::SetModeCGI(CyhookHandler *hh) { if (!(hh->ParamList.empty())) diff --git a/src/nhttpd/tuxboxapi/controlapi.h b/src/nhttpd/tuxboxapi/controlapi.h index 36873b8fc..b266e85d4 100644 --- a/src/nhttpd/tuxboxapi/controlapi.h +++ b/src/nhttpd/tuxboxapi/controlapi.h @@ -73,6 +73,7 @@ private: // CGI functions for ExecuteCGI void TimerCGI(CyhookHandler *hh); + void TimerSendCGI(CyhookHandler *hh); void SetModeCGI(CyhookHandler *hh); void GetModeCGI(CyhookHandler *hh); void ExecCGI(CyhookHandler *hh); diff --git a/src/nhttpd/tuxboxapi/neutrinoapi.cpp b/src/nhttpd/tuxboxapi/neutrinoapi.cpp index bfd6b216c..46f819145 100644 --- a/src/nhttpd/tuxboxapi/neutrinoapi.cpp +++ b/src/nhttpd/tuxboxapi/neutrinoapi.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -530,3 +531,54 @@ std::string CNeutrinoAPI::getLogoFile(t_channel_id channelId) return logoString; return ""; } + +std::string CNeutrinoAPI::GetRemoteBoxIP(std::string _rbname) +{ + std::string c_url = ""; + for (std::vector::iterator it = g_settings.timer_remotebox_ip.begin(); it != g_settings.timer_remotebox_ip.end(); ++it) + { + if (it->rbname == _rbname) + { + if (!it->user.empty() && !it->pass.empty()) + c_url += it->user + ":" + it->pass +"@"; + c_url += it->rbaddress; + c_url += ":" + to_string(it->port); + break; + } + } + return c_url; +} + +void CNeutrinoAPI::SendAllTimers(std::string url, bool force) +{ + CTimerd::TimerList timerlist; + timerlist.clear(); + Timerd->getTimerList(timerlist); + sort(timerlist.begin(), timerlist.end()); + CTimerd::TimerList::iterator timer = timerlist.begin(); + + int pre,post; + Timerd->getRecordingSafety(pre,post); + CHTTPTool httpTool; + std::string r_url; + + for(int i = 0; timer != timerlist.end(); ++timer) + { + if (timer->eventType == CTimerd::TIMER_RECORD) { + r_url = "http://"; + r_url += url; + r_url += "/control/timer?action=new"; + r_url += "&alarm=" + to_string((int)timer->alarmTime + pre); + r_url += "&stop=" + to_string((int)timer->stopTime - post); + r_url += "&announce=" + to_string((int)timer->announceTime + pre); + r_url += "&channel_id=" + string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, timer->channel_id); + r_url += "&aj=on"; + r_url += "&rs=on"; + + r_url = httpTool.downloadString(r_url, -1, 300); + + if ((r_url=="ok") || force) + Timerd->removeTimerEvent(timer->eventID); + } + } +} diff --git a/src/nhttpd/tuxboxapi/neutrinoapi.h b/src/nhttpd/tuxboxapi/neutrinoapi.h index 5936e194b..77e51baa0 100644 --- a/src/nhttpd/tuxboxapi/neutrinoapi.h +++ b/src/nhttpd/tuxboxapi/neutrinoapi.h @@ -84,6 +84,8 @@ public: std::string getAudioInfoAsString(void); std::string getCryptInfoAsString(void); std::string getLogoFile(t_channel_id channelId); + std::string GetRemoteBoxIP(std::string _rbname); + void SendAllTimers(std::string url, bool force = false); public: CNeutrinoAPI(); ~CNeutrinoAPI(void);