summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthlo <smarttv640@gmail.com>2016-11-14 18:56:38 +0100
committerthlo <smarttv640@gmail.com>2016-11-14 18:56:38 +0100
commit9864d6a98c83408046a4d69c39fb5c788c346b18 (patch)
tree9c692d2a6727558dac003c962a81e3576bbef1c6
parent4b82aa28d30ea4935d2099d371ddd3970e713c79 (diff)
downloadvdr-plugin-smarttvweb-9864d6a98c83408046a4d69c39fb5c788c346b18.tar.gz
vdr-plugin-smarttvweb-9864d6a98c83408046a4d69c39fb5c788c346b18.tar.bz2
BlackList support for parental control
-rwxr-xr-xhttpresource.c22
-rwxr-xr-xresponsememblk.c57
-rwxr-xr-xresponsememblk.h4
-rwxr-xr-xsmarttvfactory.c34
-rwxr-xr-xsmarttvfactory.h8
5 files changed, 123 insertions, 2 deletions
diff --git a/httpresource.c b/httpresource.c
index 375460f..367a897 100755
--- a/httpresource.c
+++ b/httpresource.c
@@ -284,6 +284,11 @@ int cHttpResource::processRequest() {
struct stat statbuf;
bool ok_to_serve = false;
+ if (mFactory->isBlackListed (mRemoteAddr)) {
+ mResponse = new cResponseError(this, 400, "Bad Request", NULL, "00x Blacklisted.");
+ return OKAY;
+ }
+
if (mMethod.compare("POST")==0) {
return handlePost();
}
@@ -392,6 +397,12 @@ int cHttpResource::processRequest() {
return OKAY;
}
+ if (mPath.compare("/getBlacklist") == 0) {
+ mResponse = new cResponseMemBlk(this);
+ ((cResponseMemBlk*)mResponse)->get_blacklist();
+ return OKAY;
+ }
+
#endif
if (mPath.compare("/deleteFile") == 0) {
@@ -733,6 +744,17 @@ int cHttpResource::handlePost() {
return OKAY;
}
+ if (mPath.compare("/addToBlacklist") == 0) {
+ mResponse = new cResponseMemBlk(this);
+ ((cResponseMemBlk*)mResponse)->post_addToBlacklist();
+ return OKAY;
+ }
+ if (mPath.compare("/removeFromBlacklist") == 0) {
+ mResponse = new cResponseMemBlk(this);
+ ((cResponseMemBlk*)mResponse)->post_removeFromBlacklist();
+ return OKAY;
+ }
+
// Should not reach the end of the function
return ERROR;
diff --git a/responsememblk.c b/responsememblk.c
index c0d1054..7a72b67 100755
--- a/responsememblk.c
+++ b/responsememblk.c
@@ -1692,10 +1692,65 @@ uint64_t cResponseMemBlk::getVdrFileSize() {
}
return total_file_size;
}
+
+ void cResponseMemBlk::post_addToBlacklist() {
+ if (isHeadRequest())
+ return;
+
+ vector<sQueryAVP> avps;
+ string ip_addr;
+ mRequest->parseQueryLine(&avps);
-// - Manifest End
+ if (mRequest->getQueryAttributeValue(&avps, "ip_addr", ip_addr) != OKAY) {
+ sendError(400, "Bad Request", NULL, "00x ip_addr attrib is mandatory.");
+ return ;
+ }
+ *(mLog->log())<< DEBUGPREFIX
+ << " post_addToBlacklist ip= " << ip_addr << endl;
+ mRequest->mFactory->addToBlackList(ip_addr);
+ sendHeaders(200, "OK", NULL, NULL, 0, -1);
+ return;
+}
+
+void cResponseMemBlk::get_blacklist() {
+ mResponseMessage = new string();
+ mResponseMessagePos = 0;
+ *mResponseMessage = "";
+
+ list<string> * l = mRequest->mFactory->getBlackList();
+ for (list<string>::iterator it=l->begin(); it != l->end(); ++it) {
+ *mResponseMessage += *it;
+ *mResponseMessage += "\n";
+ }
+
+ sendHeaders(200, "OK", NULL, "text/plain", mResponseMessage->size(), -1);
+ return;
+}
+
+void cResponseMemBlk::post_removeFromBlacklist(){
+ if (isHeadRequest())
+ return;
+
+ vector<sQueryAVP> avps;
+ string ip_addr;
+ mRequest->parseQueryLine(&avps);
+
+ if (mRequest->getQueryAttributeValue(&avps, "ip_addr", ip_addr) != OKAY){
+ sendError(400, "Bad Request", NULL, "00x ip_addr attrib is mandatory.");
+ return;
+ }
+
+ *(mLog->log())<< DEBUGPREFIX
+ << " post_removeFromBlacklist ip= " << ip_addr << endl;
+
+ mRequest->mFactory->removeFromBlackList(ip_addr);
+ sendHeaders(200, "OK", NULL, NULL, 0, -1);
+ return;
+}
+
+// - Manifest End
// --------------------
// GET Resources
diff --git a/responsememblk.h b/responsememblk.h
index 2cdfae9..b119b8f 100755
--- a/responsememblk.h
+++ b/responsememblk.h
@@ -117,6 +117,10 @@ class cResponseMemBlk : public cResponseBase {
int no, time_t start, int dur, double fps, int is_pes, int is_new, string mime);
uint64_t getVdrFileSize();
+ void post_addToBlacklist();
+ void post_removeFromBlacklist();
+ void get_blacklist();
+
private:
string *mResponseMessage;
int mResponseMessagePos;
diff --git a/smarttvfactory.c b/smarttvfactory.c
index 7c29e8c..dc425a5 100755
--- a/smarttvfactory.c
+++ b/smarttvfactory.c
@@ -365,7 +365,7 @@ SmartTvServer::SmartTvServer(): cStatus(), mRequestCount(0), isInited(false), se
mSegmentDuration(10), mHasMinBufferTime(40), mLiveChannels(20),
clientList(), mConTvClients(), mRecCmds(), mCmdCmds(), mRecMsg(), mCmdMsg(), mActiveSessions(0), mHttpClientId(0),
mConfig(NULL), mMaxFd(0),
- mManagedUrls(NULL), mActRecordings(), mRecordings(NULL), mRecState(0) {
+ mManagedUrls(NULL), mActRecordings(), mRecordings(NULL), mRecState(0), mClientBlackList() {
}
@@ -1167,3 +1167,35 @@ void SmartTvServer::initServer(string dir, cSmartTvConfig* cfg) {
}
+void SmartTvServer::addToBlackList(string c) {
+ if (isBlackListed(c))
+ return;
+ mClientBlackList.push_back(c);
+ *(mLog.log()) << mLog.getTimeString() << " addToBlackList IpAddr= " << c << endl;
+}
+
+void SmartTvServer::removeFromBlackList(string c) {
+ for (list<string>::iterator it=mClientBlackList.begin(); it != mClientBlackList.end(); ++it) {
+ if (*it == c) {
+ mClientBlackList.erase(it);
+ *(mLog.log()) << mLog.getTimeString() << " removeFromBlackList IpAddr= " << c << endl;
+ break;
+ }
+ }
+ *(mLog.log()) << mLog.getTimeString() << " removeFromBlackList IpAddr= " << c << " Failed" << endl;
+}
+
+bool SmartTvServer::isBlackListed(string c) {
+ for (list<string>::iterator it=mClientBlackList.begin(); it != mClientBlackList.end(); ++it) {
+ if (*it == c) {
+ return true;
+ }
+ }
+ return false;
+}
+
+list<string> *SmartTvServer::getBlackList() {
+ return &mClientBlackList;
+}
+
+
diff --git a/smarttvfactory.h b/smarttvfactory.h
index 1762967..3e5b95b 100755
--- a/smarttvfactory.h
+++ b/smarttvfactory.h
@@ -192,6 +192,12 @@ class SmartTvServer : public cStatus {
cRecFolder* GetRecDb();
+ void addToBlackList(string);
+ void removeFromBlackList(string);
+
+ bool isBlackListed(string);
+ list<string> *getBlackList();
+
private:
void addHttpResource(int fd, cHttpResourceBase* resource);
void pushToClients(cHttpResourceBase* resource);
@@ -256,6 +262,8 @@ class SmartTvServer : public cStatus {
cRecFolder* mRecordings;
int mRecState;
void CreateRecDb();
+
+ list<string> mClientBlackList;
};