Leosac  0.7.0
OpenSourceAccessControl
RemoteControl.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
24 #include <boost/property_tree/ptree_fwd.hpp>
25 #include <zmqpp/zmqpp.hpp>
26 
27 namespace Leosac
28 {
29 
30 class Kernel;
31 
41 {
42  public:
43  RemoteControl(zmqpp::context &ctx, Kernel &kernel,
44  const boost::property_tree::ptree &cfg);
45 
46  void update();
47 
48  private:
54  bool handle_module_config(zmqpp::message *msg_in, zmqpp::message *msg_out);
55 
61  bool handle_module_list(zmqpp::message *msg_in, zmqpp::message *msg_out);
62 
68  bool handle_sync_from(zmqpp::message *msg_in, zmqpp::message *msg_out);
69 
75  bool handle_save(zmqpp::message *msg_in, zmqpp::message *msg_out);
76 
82  bool handle_general_config(zmqpp::message *msg_in, zmqpp::message *msg_out);
83 
90  bool handle_config_version(zmqpp::message *msg_in, zmqpp::message *msg_out);
91 
97  void module_list(zmqpp::message *message_out);
98 
102  void module_config(const std::string &module,
103  ConfigManager::ConfigFormat cfg_format,
104  zmqpp::message *message_out);
105 
112  zmqpp::message *msg_out);
113 
117  void handle_msg();
118 
119  void process_config(const boost::property_tree::ptree &cfg);
120 
127  bool gather_remote_module_list(zmqpp::socket &s,
128  std::list<std::string> &remote_modules);
129 
138  bool receive_remote_config(zmqpp::socket &s, std::map<std::string, bool> &cfg);
139 
148  bool gather_remote_config(zmqpp::socket &s, std::list<std::string> &start_list,
149  std::list<std::string> &stop_list);
150 
152 
156  zmqpp::socket socket_;
157 
161  std::string public_key_;
162 
166  std::string secret_key_;
167 
168  zmqpp::auth auth_;
169  zmqpp::context &context_;
170 
171  // Function is not really void (), we use placeholder and bind.
172  using CommandHandlerMap =
173  std::map<std::string, std::function<bool(zmqpp::message *msg_in,
174  zmqpp::message *msg_out)>>;
175 
177 
182 
183  std::string current_client_idt_;
184 
185  // Allow kernel full access to this class.
186  friend class Kernel;
187 };
188 }
RemoteControlSecurity security_
Object to check remote user permission before processing their request.
std::map< std::string, std::function< bool(zmqpp::message *msg_in, zmqpp::message *msg_out)> > CommandHandlerMap
void general_config(ConfigManager::ConfigFormat cfg_format, zmqpp::message *msg_out)
Implements GLOBAL_CONFIG API call.
This is the header file for a generated source file, GitSHA1.cpp.
bool handle_general_config(zmqpp::message *msg_in, zmqpp::message *msg_out)
Command handler for GENERAL_CONFIG.
This class handle the remote control of leosac.
bool receive_remote_config(zmqpp::socket &s, std::map< std::string, bool > &cfg)
After sending a bunch of MODULE_CONFIG command, wait for reply.
RemoteControl(zmqpp::context &ctx, Kernel &kernel, const boost::property_tree::ptree &cfg)
Provide some kind of security framework to the Remote Control service.
void module_list(zmqpp::message *message_out)
Implements the module list command.
std::string current_client_idt_
void handle_msg()
Register by core and called when message arrives.
CommandHandlerMap command_handlers_
void process_config(const boost::property_tree::ptree &cfg)
bool handle_save(zmqpp::message *msg_in, zmqpp::message *msg_out)
Save the current configuration to disk.
bool handle_sync_from(zmqpp::message *msg_in, zmqpp::message *msg_out)
Extract and verify content from message and call sync_from()
Core of Leosac.
Definition: kernel.hpp:73
ConfigFormat
This enum is used internally, when core request module configuration.
zmqpp::socket socket_
Public ROUTER.
bool gather_remote_config(zmqpp::socket &s, std::list< std::string > &start_list, std::list< std::string > &stop_list)
Will retrieve the config for a remote leosac unit.
bool handle_module_config(zmqpp::message *msg_in, zmqpp::message *msg_out)
Extract and verify content from user-message and call implementation.
std::string secret_key_
z85 encoded private curve key
bool handle_module_list(zmqpp::message *msg_in, zmqpp::message *msg_out)
Extract and verify content from message and call implementation.
std::string public_key_
z85 encoded public curve key
bool gather_remote_module_list(zmqpp::socket &s, std::list< std::string > &remote_modules)
Build the list of modules (their name) running on the remote host.
zmqpp::context & context_
void module_config(const std::string &module, ConfigManager::ConfigFormat cfg_format, zmqpp::message *message_out)
Implements the MODULE_CONFIG command.
bool handle_config_version(zmqpp::message *msg_in, zmqpp::message *msg_out)
Command handler for CONFIG_VERSION command.