From 43a99d468725e99c1d6fad952c9b98e90343ff79 Mon Sep 17 00:00:00 2001 From: Andrey Zabolotnyi Date: Wed, 24 May 2017 13:00:44 +0300 Subject: [PATCH] Script for Agent --- agent/CMakeLists.txt | 1 + agent/packaging/agent.spec | 3 +++ agent/run.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++ agent/src/main.cpp | 20 ++-------------- 4 files changed, 63 insertions(+), 18 deletions(-) create mode 100755 agent/run.sh diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index a0e0e9b..6b1251e 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -54,6 +54,7 @@ target_link_libraries (${PROJECT_NAME} jsoncpp agent_policy pthread) install(TARGETS ${PROJECT_NAME} DESTINATION ${TESTS_DIR}) install(FILES agent.manifest DESTINATION ${MANIFESTDIR}) +install(FILES run.sh DESTINATION ${TESTS_DIR}) message(STATUS "Configuring: " ${ProjectId}) message(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS}) diff --git a/agent/packaging/agent.spec b/agent/packaging/agent.spec index f1d7cd5..ae1532e 100644 --- a/agent/packaging/agent.spec +++ b/agent/packaging/agent.spec @@ -85,3 +85,6 @@ Reference agent %files agent %manifest %{_manifestdir}/agent.manifest %attr(0755,root,root) %{_tests_dir}/agent +%attr(0755,root,root) %{_tests_dir}/run.sh + + diff --git a/agent/run.sh b/agent/run.sh new file mode 100755 index 0000000..ac8bc27 --- /dev/null +++ b/agent/run.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# run agent 1 +rm -f .fifo1 +mkfifo .fifo1 +tail -f .fifo1 | ./agent & + +# run agent 2 +rm -f .fifo2 +mkfifo .fifo2 +tail -f .fifo2 | ./agent & + +# run agent 3 +rm -f .fifo3 +mkfifo .fifo3 +tail -f .fifo3 | ./agent & + +sleep 0.1 +echo -e "agent1\n" > .fifo1 +sleep 0.1 +echo -e "agent2\n" > .fifo2 +sleep 0.1 +echo -e "agent3\n" > .fifo3 +sleep 0.1 + +# agent 1 +# usb disable +echo -e "1\n" > .fifo1 +echo -e "2\n" > .fifo1 +echo -e "q\n" > .fifo1 +sleep 0.1 + +# agent 2 +# screen capture disable +echo -e "2\n" > .fifo2 +echo -e "2\n" > .fifo2 +echo -e "q\n" > .fifo2 +sleep 0.1 + +# agent 3 +# bluetooth disable +echo -e "3\n" > .fifo3 +echo -e "2\n" > .fifo3 +echo -e "0\n" > .fifo3 +sleep 0.1 +# Iptables enable +echo -e "4\n" > .fifo3 +echo -e "1\n" > .fifo3 +sleep 0.1 +# Iptables add to block list +echo -e "3\n" > .fifo3 +echo -e "192.168.131.1\n" > .fifo3 +echo -e "2\n" > .fifo3 +echo -e "1234\n" > .fifo3 +echo -e "q\n" > .fifo3 + + diff --git a/agent/src/main.cpp b/agent/src/main.cpp index b1b156b..31c369f 100644 --- a/agent/src/main.cpp +++ b/agent/src/main.cpp @@ -24,10 +24,9 @@ enum class State void applyPolicy(const string& agend_id, const TvPolicy& policy) { - static AgentPolicyAdapter adapter; - try { + static AgentPolicyAdapter adapter; string policy_json = policy.makePolicy(); int result = adapter.enforcePolicy(agend_id, policy_json); @@ -43,21 +42,6 @@ void applyPolicy(const string& agend_id, const TvPolicy& policy) } } -void read_line(istream& is, string& out) -{ - char c; - out.clear(); - is.get(c); - if (c != 'r' && c != '\n') out.push_back(c); - - for (;;) - { - is.get(c); - if (c == '\r' || c == '\n') break; - out.push_back(c); - } -} - vector split(const string& str, const char delim) { vector v; @@ -318,7 +302,7 @@ int main(int argc, char* argv[]) cout << " Enter ports (one value, coma separated list, or range as start-end)" << endl; cout << " Examples:" << endl << " 1234" << endl << " 80,8080,8000" << endl << " 22-1000" << endl; - read_line(cin, ports); + cin >> ports; auto pos = ports.find('-'); -- 2.7.4