Leosac  0.8.0
Open Source Access Control
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 }
Leosac::RemoteControl::gather_remote_module_list
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.
Leosac::RemoteControl::context_
zmqpp::context & context_
Definition: RemoteControl.hpp:169
Leosac::RemoteControl::receive_remote_config
bool receive_remote_config(zmqpp::socket &s, std::map< std::string, bool > &cfg)
After sending a bunch of MODULE_CONFIG command, wait for reply.
Leosac::RemoteControl::module_config
void module_config(const std::string &module, ConfigManager::ConfigFormat cfg_format, zmqpp::message *message_out)
Implements the MODULE_CONFIG command.
Definition: RemoteControl.cpp:163
Leosac::RemoteControl::process_config
void process_config(const boost::property_tree::ptree &cfg)
Definition: RemoteControl.cpp:51
Leosac::RemoteControl::handle_config_version
bool handle_config_version(zmqpp::message *msg_in, zmqpp::message *msg_out)
Command handler for CONFIG_VERSION command.
Definition: RemoteControl.cpp:361
Leosac::RemoteControlSecurity
Provide some kind of security framework to the Remote Control service.
Definition: RemoteControlSecurity.hpp:48
Leosac::ConfigManager::ConfigFormat
ConfigFormat
This enum is used internally, when core request module configuration.
Definition: ConfigManager.hpp:118
Leosac::RemoteControl::CommandHandlerMap
std::map< std::string, std::function< bool(zmqpp::message *msg_in, zmqpp::message *msg_out)> > CommandHandlerMap
Definition: RemoteControl.hpp:174
Leosac::RemoteControl::current_client_idt_
std::string current_client_idt_
Definition: RemoteControl.hpp:183
Leosac::RemoteControl::handle_msg
void handle_msg()
Register by core and called when message arrives.
Definition: RemoteControl.cpp:94
Leosac::RemoteControl::handle_sync_from
bool handle_sync_from(zmqpp::message *msg_in, zmqpp::message *msg_out)
Extract and verify content from message and call sync_from()
Definition: RemoteControl.cpp:260
Leosac::RemoteControl::handle_save
bool handle_save(zmqpp::message *msg_in, zmqpp::message *msg_out)
Save the current configuration to disk.
Definition: RemoteControl.cpp:327
Leosac::RemoteControl::handle_general_config
bool handle_general_config(zmqpp::message *msg_in, zmqpp::message *msg_out)
Command handler for GENERAL_CONFIG.
Definition: RemoteControl.cpp:345
Leosac::RemoteControl::socket_
zmqpp::socket socket_
Public ROUTER.
Definition: RemoteControl.hpp:156
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::RemoteControl::secret_key_
std::string secret_key_
z85 encoded private curve key
Definition: RemoteControl.hpp:166
Leosac::RemoteControl::RemoteControl
RemoteControl(zmqpp::context &ctx, Kernel &kernel, const boost::property_tree::ptree &cfg)
Definition: RemoteControl.cpp:39
Leosac::RemoteControl::module_list
void module_list(zmqpp::message *message_out)
Implements the module list command.
Definition: RemoteControl.cpp:154
Leosac::RemoteControl::gather_remote_config
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.
Leosac::RemoteControl::public_key_
std::string public_key_
z85 encoded public curve key
Definition: RemoteControl.hpp:161
Leosac::RemoteControl::update
void update()
Definition: RemoteControl.cpp:375
RemoteControlSecurity.hpp
Leosac::Kernel
Core of Leosac.
Definition: kernel.hpp:73
Leosac::RemoteControl::auth_
zmqpp::auth auth_
Definition: RemoteControl.hpp:168
Leosac::RemoteControl::command_handlers_
CommandHandlerMap command_handlers_
Definition: RemoteControl.hpp:176
Leosac::RemoteControl::security_
RemoteControlSecurity security_
Object to check remote user permission before processing their request.
Definition: RemoteControl.hpp:181
Leosac::RemoteControl::handle_module_config
bool handle_module_config(zmqpp::message *msg_in, zmqpp::message *msg_out)
Extract and verify content from user-message and call implementation.
Definition: RemoteControl.cpp:229
Leosac::RemoteControl::general_config
void general_config(ConfigManager::ConfigFormat cfg_format, zmqpp::message *msg_out)
Implements GLOBAL_CONFIG API call.
Definition: RemoteControl.cpp:207
ConfigManager.hpp
Leosac::RemoteControl::kernel_
Kernel & kernel_
Definition: RemoteControl.hpp:151
Leosac::RemoteControl::handle_module_list
bool handle_module_list(zmqpp::message *msg_in, zmqpp::message *msg_out)
Extract and verify content from message and call implementation.
Definition: RemoteControl.cpp:246
Leosac::RemoteControl
This class handle the remote control of leosac.
Definition: RemoteControl.hpp:40