Script for Agent
authorAndrey Zabolotnyi <a.zabolotnyi@samsung.com>
Wed, 24 May 2017 10:00:44 +0000 (13:00 +0300)
committerAndrey Zabolotnyi <a.zabolotnyi@samsung.com>
Wed, 24 May 2017 10:00:44 +0000 (13:00 +0300)
agent/CMakeLists.txt
agent/packaging/agent.spec
agent/run.sh [new file with mode: 0755]
agent/src/main.cpp

index a0e0e9b..6b1251e 100644 (file)
@@ -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})
index f1d7cd5..ae1532e 100644 (file)
@@ -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 (executable)
index 0000000..ac8bc27
--- /dev/null
@@ -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
+
+
index b1b156b..31c369f 100644 (file)
@@ -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<string> split(const string& str, const char delim)
 {
     vector<string> 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('-');