Webdar 1.0.1
Web user interface to libdar
html_entrepot.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2026 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef HTML_ENTREPOT_HPP
25#define HTML_ENTREPOT_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <memory>
36#include <string>
37#include <libthreadar/libthreadar.hpp>
38
39 // webdar headers
40#include "body_builder.hpp"
41#include "html_form.hpp"
42#include "html_form_input.hpp"
43#include "html_form_input_file.hpp"
44#include "html_form_fieldset.hpp"
45#include "html_form_select.hpp"
46#include "actor.hpp"
47#include "events.hpp"
48#include "html_web_user_interaction.hpp"
49#include "jsoner.hpp"
50
52
54 public actor,
55 public events,
56 public libthreadar::thread_signal,
57 public jsoner
58{
59public:
61
62 // the use case is for the caller to know when to call get_entrepot()
63 static const std::string changed;
64
66 html_entrepot(const html_entrepot & ref) = delete;
67 html_entrepot(html_entrepot && ref) noexcept = delete;
68 html_entrepot & operator = (const html_entrepot & ref) = delete;
69 html_entrepot & operator = (html_entrepot && ref) noexcept = delete;
70 ~html_entrepot() { cancel(); join(); };
71
73
79 std::shared_ptr<libdar::entrepot> & get_entrepot(std::shared_ptr<html_web_user_interaction> & webui) const;
80
82 virtual void on_event(const std::string & event_name) override;
83
85 void set_event_name(const std::string & name);
86
88 virtual void load_json(const json & source) override;
89
91 virtual json save_json() const override;
92
94 virtual void clear_json() override;
95
98
100 virtual void bind_to_anchor(const std::string & val) override { form.bind_to_anchor(val); };
101
102
103protected:
105 virtual std::string inherited_get_body_part(const chemin & path,
106 const request & req) override;
107
109 virtual void css_classes_have_changed() override;
110
112 virtual void new_css_library_available() override;
113
115 virtual void inherited_run() override;
116
118 virtual void signaled_inherited_cancel() override;
119
120private:
121 static constexpr const char* type_local = "local";
122 static constexpr const char* type_ftp = "ftp";
123 static constexpr const char* type_sftp = "sftp";
124 static constexpr const char* auth_pass = "password";
125 static constexpr const char* auth_key = "keyfile";
126
127 static const std::string repo_type_changed;
128
129 std::string custom_event_name;
130 bool ignore_events;
131 mutable std::shared_ptr<libdar::user_interaction> dialog;
132 mutable std::shared_ptr<libdar::entrepot> entrep;
133 mutable libthreadar::mutex entrep_ctrl;
134 mutable bool entrep_type_has_changed;
135 mutable bool entrep_need_update;
136
137 html_form form;
139 html_form_select repo_type; // local, ftp or sftp
140 html_form_input host; // ftp and sftp
141 html_form_input port; // ftp and sftp
142 html_form_input login; // ftp and sftp
143 html_form_select auth_type; // (sftp only) login or keyfile
144 html_form_input pass; // ftp and sftp
145 html_form_input auth_from_file; // ftp and sftp
146 html_form_input_file pub_keyfile; // sftp only
147 html_form_input_file prv_keyfile; // sftp only
148 html_form_input knownhosts_check; // sftp only
149 html_form_input_file known_hosts_file; // sftp only
150 html_form_input wait_time; // ftp and sftp
151 html_form_input verbose; // ftp and sftp
152
153 void update_visible();
154 void trigger_changed_event();
155 void clear_form();
156 void reset_ssh_files();
157
158 static constexpr const unsigned int format_version = 1;
159 static constexpr const char* myclass_id = "html_entrepot";
160
161 static constexpr const char* jlabel_type = "type";
162 static constexpr const char* jlabel_host = "host";
163 static constexpr const char* jlabel_port = "port";
164 static constexpr const char* jlabel_authtype = "authtype";
165 static constexpr const char* jlabel_login = "login";
166 static constexpr const char* jlabel_pass = "pass";
167 static constexpr const char* jlabel_auth_from_file = "auth_file";
168 static constexpr const char* jlabel_pubkey = "pubkey";
169 static constexpr const char* jlabel_prvkey = "prvkey";
170 static constexpr const char* jlabel_knownhosts = "knownhosts";
171 static constexpr const char* jlabel_knownhosts_file = "knownhosts_file";
172 static constexpr const char* jlabel_waittime = "wait";
173 static constexpr const char* jlabel_verbose = "verbose";
174
175 static constexpr const char* default_waittime = "30";
176 static constexpr const char* default_verbose = "";
177};
178
179#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class body_builder is the root class of object generating HTML body
Definition: body_builder.hpp:99
class chemin definition
Definition: chemin.hpp:51
class events
Definition: events.hpp:52
class html_entrepot let user define an entrepot parameters
Definition: html_entrepot.hpp:58
virtual void clear_json() override
inherited from jsoner
Definition: html_entrepot.cpp:338
virtual void signaled_inherited_cancel() override
inherited from libthreadar::thread
Definition: html_entrepot.cpp:482
virtual void bind_to_anchor(const std::string &val) override
inherited from body_builder
Definition: html_entrepot.hpp:100
virtual void inherited_run() override
inherited from libthreadar::thread
Definition: html_entrepot.cpp:426
virtual void css_classes_have_changed() override
inherited from body_builder
Definition: html_entrepot.cpp:406
virtual json save_json() const override
inherited from jsoner
Definition: html_entrepot.cpp:315
virtual void load_json(const json &source) override
inherited from jsoner
Definition: html_entrepot.cpp:248
virtual void on_event(const std::string &event_name) override
inherited from actor parent class
Definition: html_entrepot.cpp:194
void set_to_webdar_defaults()
set the object to webdar defaults
Definition: html_entrepot.cpp:368
void set_event_name(const std::string &name)
change the change event name
Definition: html_entrepot.cpp:242
static const std::string changed
event triggered when any entrepot parameters has changed
Definition: html_entrepot.hpp:63
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder
Definition: html_entrepot.cpp:373
virtual void new_css_library_available() override
inherited from body_builder
Definition: html_entrepot.cpp:417
std::shared_ptr< libdar::entrepot > & get_entrepot(std::shared_ptr< html_web_user_interaction > &webui) const
run the entrepot building in a dedicated thread and display/control this thread
Definition: html_entrepot.cpp:142
class html_form_fieldset implements HTML fieldset feature
Definition: html_form_fieldset.hpp:51
class html_form_input_file provides a mean to the user to navigate in a file system to select a file ...
Definition: html_form_input_file.hpp:60
class html_form_input implements HTML input feature
Definition: html_form_input.hpp:57
class html_form_select implements HTML input of type "select"
Definition: html_form_select.hpp:53
class html_form implements HTML form feature
Definition: html_form.hpp:51
virtual void bind_to_anchor(const std::string &value) override
inherited from body_builder
Definition: html_form.hpp:83
class jsoner
Definition: jsoner.hpp:73
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class
defines jsoner class and class exception_json