Skip to content

Commit 4bbd827

Browse files
committed
- Fixed control-c bug #518, #523
- Added www debug logging via preprocessor DEBUG_WWW - Changed: Custom Templates, now possible to have a space in the html file (My Custom Page) - Implemented: Custom Templates, now possible to directly call custom template pages (http://127.0.0.1:8080/#/Custom/mypage)
1 parent 73673a8 commit 4bbd827

File tree

12 files changed

+63
-32
lines changed

12 files changed

+63
-32
lines changed

History.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version 2.4xxx
33
- Implemented: Blockly, now possible to send a notification with a user variable/device as subject/body
44
- Implemented: Chinese language support, big thanks to wxws!!
55
- Implemented: CounterType 'Time'
6+
- Implemented: Custom Templates, now possible to directly call custom template pages (http://127.0.0.1:8080/#/Custom/mypage)
67
- Implemented: Day display in energy/gas/water/temp report
78
- Implemented: Dummy Hardware, Option to supply name, sensor is now also directly added to the system
89
- Implemented: Dummy Hardware, Wind+Temp+Chill

webserver/cWebem.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ int cWebem::CountSessions() {
952952
}
953953

954954
void cWebem::CleanSessions() {
955-
#ifdef _DEBUG
955+
#ifdef DEBUG_WWW
956956
_log.Log(LOG_STATUS, "[web:%s] cleaning sessions...", GetPort().c_str());
957957
#endif
958958
int before = CountSessions();
@@ -1241,7 +1241,7 @@ std::string cWebemRequestHandler::generateSessionID()
12411241

12421242
std::string sessionId = GenerateMD5Hash(base64_encode((const unsigned char*)randomValue.c_str(), randomValue.size()));
12431243

1244-
#ifdef _DEBUG
1244+
#ifdef DEBUG_WWW
12451245
_log.Log(LOG_STATUS, "[web:%s] generate new session id token %s", myWebem->GetPort().c_str(), sessionId.c_str());
12461246
#endif
12471247

@@ -1261,7 +1261,7 @@ std::string cWebemRequestHandler::generateAuthToken(const WebEmSession & session
12611261

12621262
std::string authToken = base64_encode((const unsigned char*)randomValue.c_str(), randomValue.size());
12631263

1264-
#ifdef _DEBUG
1264+
#ifdef DEBUG_WWW
12651265
_log.Log(LOG_STATUS, "[web:%s] generate new authentication token %s", myWebem->GetPort().c_str(), authToken.c_str());
12661266
#endif
12671267

@@ -1508,8 +1508,8 @@ bool cWebemRequestHandler::checkAuthToken(WebEmSession & session) {
15081508
return false;
15091509
}
15101510

1511-
#ifdef _DEBUG
1512-
// _log.Log(LOG_STATUS, "[web:%s] CheckAuthToken(%s_%s_%s) : user authenticated", myWebem->GetPort().c_str(), session.id.c_str(), session.auth_token.c_str(), session.username.c_str());
1511+
#ifdef DEBUG_WWW
1512+
_log.Log(LOG_STATUS, "[web:%s] CheckAuthToken(%s_%s_%s) : user authenticated", myWebem->GetPort().c_str(), session.id.c_str(), session.auth_token.c_str(), session.username.c_str());
15131513
#endif
15141514

15151515
if (session.username.empty()) {
@@ -1531,7 +1531,7 @@ bool cWebemRequestHandler::checkAuthToken(WebEmSession & session) {
15311531
sessionExpires = session.expires < now;
15321532

15331533
if (!userExists || sessionExpires) {
1534-
#ifdef _DEBUG
1534+
#ifdef DEBUG_WWW
15351535
_log.Log(LOG_ERROR, "[web:%s] CheckAuthToken(%s_%s) : cannot restore session, user not found or session expired", myWebem->GetPort().c_str(), session.id.c_str(), session.auth_token.c_str());
15361536
#endif
15371537
removeAuthToken(session.id);
@@ -1540,7 +1540,7 @@ bool cWebemRequestHandler::checkAuthToken(WebEmSession & session) {
15401540

15411541
WebEmSession* oldSession = myWebem->GetSession(session.id);
15421542
if (oldSession == NULL) {
1543-
#ifdef _DEBUG
1543+
#ifdef DEBUG_WWW
15441544
_log.Log(LOG_STATUS, "[web:%s] CheckAuthToken(%s_%s_%s) : restore session", myWebem->GetPort().c_str(), session.id.c_str(), session.auth_token.c_str(), session.username.c_str());
15451545
#endif
15461546
myWebem->AddSession(session);
@@ -1633,7 +1633,7 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
16331633
// Find and include any special cWebem strings
16341634
if (!myWebem->Include(rep.content)) {
16351635
if (mInfo.mtime_support && !mInfo.is_modified) {
1636-
#ifdef _DEBUG
1636+
#ifdef DEBUG_WWW
16371637
_log.Log(LOG_STATUS, "[web:%s] %s not modified (1).", myWebem->GetPort().c_str(), req.uri.c_str());
16381638
#endif
16391639
rep = reply::stock_reply(reply::not_modified);
@@ -1658,7 +1658,7 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
16581658
{
16591659
if (mInfo.mtime_support && !mInfo.is_modified) {
16601660
rep = reply::stock_reply(reply::not_modified);
1661-
#ifdef _DEBUG
1661+
#ifdef DEBUG_WWW
16621662
_log.Log(LOG_STATUS, "[web:%s] %s not modified (2).", myWebem->GetPort().c_str(), req.uri.c_str());
16631663
#endif
16641664
return;
@@ -1670,7 +1670,7 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
16701670
else {
16711671
if (mInfo.mtime_support && !mInfo.is_modified) {
16721672
rep = reply::stock_reply(reply::not_modified);
1673-
#ifdef _DEBUG
1673+
#ifdef DEBUG_WWW
16741674
_log.Log(LOG_STATUS, "[web:%s] %s not modified (3).", myWebem->GetPort().c_str(), req.uri.c_str());
16751675
#endif
16761676
return;
@@ -1701,7 +1701,9 @@ void cWebemRequestHandler::handle_request(const request& req, reply& rep)
17011701
send_cookie(rep, session);
17021702

17031703
} else if (session.forcelogin == true) {
1704+
#ifdef DEBUG_WWW
17041705
_log.Log(LOG_STATUS, "[web:%s] Logout : remove session %s", myWebem->GetPort().c_str(), session.id.c_str());
1706+
#endif
17051707
myWebem->RemoveSession(session.id);
17061708
removeAuthToken(session.id);
17071709
if (myWebem->m_authmethod == AUTH_BASIC) {

webserver/connection.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ connection::connection(boost::asio::io_service& io_service,
2929
request_handler_(handler),
3030
read_timeout_(read_timeout),
3131
read_timer_(io_service, boost::posix_time::seconds(read_timeout)),
32-
default_abandoned_timeout_(20*60), // 20mn before stopping abandoned connection
32+
default_abandoned_timeout_(20*60), // close abandoned connections after 20 minutes
3333
abandoned_timer_(io_service, boost::posix_time::seconds(default_abandoned_timeout_)),
3434
status("initializing"),
35-
stop_required(false)
35+
stop_required(false),
36+
reply_(reply::stock_reply(reply::internal_server_error))
3637
{
3738
secure_ = false;
3839
keepalive_ = false;
@@ -53,10 +54,11 @@ connection::connection(boost::asio::io_service& io_service,
5354
request_handler_(handler),
5455
read_timeout_(read_timeout),
5556
read_timer_(io_service, boost::posix_time::seconds(read_timeout)),
56-
default_abandoned_timeout_(20*60), // 20mn before stopping abandoned connection
57+
default_abandoned_timeout_(20*60), // close abandoned connections after 20 minutes
5758
abandoned_timer_(io_service, boost::posix_time::seconds(default_abandoned_timeout_)),
5859
status("initializing"),
59-
stop_required(false)
60+
stop_required(false),
61+
reply_(reply::stock_reply(reply::internal_server_error))
6062
{
6163
secure_ = true;
6264
keepalive_ = false;
@@ -320,7 +322,7 @@ void connection::reset_read_timeout() {
320322
/// stop connection on read timeout
321323
void connection::handle_read_timeout(const boost::system::error_code& error) {
322324
if (error != boost::asio::error::operation_aborted) {
323-
#ifdef _DEBUG
325+
#ifdef DEBUG_WWW
324326
_log.Log(LOG_STATUS, "%s -> handle read timeout", host_endpoint_.c_str());
325327
#endif
326328
connection_manager_.stop(shared_from_this());

webserver/connection_manager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ void connection_manager::stop(connection_ptr c)
5353
c->stop();
5454
}
5555

56-
void connection_manager::stop_all(bool graceful_stop)
56+
void connection_manager::stop_all(const bool graceful_stop)
5757
{
58-
#ifdef _DEBUG
58+
#ifdef DEBUG_WWW
5959
_log.Log(LOG_STATUS,"%stopping connections...", graceful_stop ? "Gracefully s" : "S");
6060
#endif
6161
if (graceful_stop) {
@@ -64,17 +64,17 @@ void connection_manager::stop_all(bool graceful_stop)
6464
int timeout = 10; // force stop after 10 seconds
6565
time_t start = mytime(NULL);
6666
while(true) {
67-
if (connections_.size() < 1) {
67+
if (connections_.empty()) {
6868
break;
6969
}
7070
if ((mytime(NULL) - start) > timeout) {
7171
// timeout occurred : force stop
72-
#ifdef _DEBUG
72+
#ifdef DEBUG_WWW
7373
_log.Log(LOG_STATUS,"Graceful stop timeout occurred : remaining connections will be closed now");
7474
#endif
7575
break;
7676
}
77-
#ifdef _DEBUG
77+
#ifdef DEBUG_WWW
7878
_log.Log(LOG_STATUS,"Graceful stopping : %d active connection(s)", (int) connections_.size());
7979
#endif
8080
sleep_milliseconds(500);

webserver/connection_manager.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class connection_manager
2525
{
2626
public:
2727
/// Add the specified connection to the manager and start it.
28-
void start(connection_ptr c);
28+
void start(const connection_ptr c);
2929

3030
/// Stop the specified connection.
31-
void stop(connection_ptr c);
31+
void stop(const connection_ptr c);
3232

3333
/// Stop all connections.
34-
void stop_all(bool graceful_stop);
34+
void stop_all(const bool graceful_stop);
3535

3636
private:
3737
/// The managed connections.

webserver/server.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void server_base::run() {
6262
is_running = false;
6363
handle_stop(); // dispatch or post call does NOT work because it is pushed in the event queue (executed only on next io service run)
6464
io_service_.reset(); // this call is needed before calling run() again
65-
throw e;
65+
throw;
6666
} catch (...) {
6767
_log.Log(LOG_ERROR, "[web:%s] unknown exception occurred (need to run again)", settings_.listening_port.c_str());
6868
is_running = false;
@@ -83,22 +83,19 @@ bool server_base::stopped() {
8383
}
8484

8585
void server_base::handle_stop() {
86-
// The server is stopped by cancelling all outstanding asynchronous
87-
// operations. Once all operations have finished the io_service::run() call
88-
// will exit.
8986
is_stopping = true;
90-
connection_manager_.stop_all(true);
9187
try {
9288
boost::system::error_code ignored_ec;
9389
acceptor_.close(ignored_ec);
9490
} catch (...) {
9591
_log.Log(LOG_ERROR, "[web:%s] exception occurred while closing acceptor", settings_.listening_port.c_str());
9692
}
93+
connection_manager_.stop_all(false);
9794
}
9895

9996
server::server(const server_settings & settings, request_handler & user_request_handler) :
10097
server_base(settings, user_request_handler) {
101-
#ifdef _DEBUG
98+
#ifdef DEBUG_WWW
10299
_log.Log(LOG_STATUS, "[web:%s] create server using settings : %s", settings.listening_port.c_str(), settings.to_string().c_str());
103100
#endif
104101
init(boost::bind(&server::init_connection, this),
@@ -133,7 +130,7 @@ ssl_server::ssl_server(const ssl_server_settings & ssl_settings, request_handler
133130
settings_(ssl_settings),
134131
context_(io_service_, ssl_settings.get_ssl_method())
135132
{
136-
#ifdef _DEBUG
133+
#ifdef DEBUG_WWW
137134
_log.Log(LOG_STATUS, "[web:%s] create ssl_server using ssl_server_settings : %s", ssl_settings.listening_port.c_str(), ssl_settings.to_string().c_str());
138135
#endif
139136
init(boost::bind(&ssl_server::init_connection, this),
@@ -145,7 +142,7 @@ ssl_server::ssl_server(const server_settings & settings, request_handler & user_
145142
server_base(settings, user_request_handler),
146143
settings_(dynamic_cast<ssl_server_settings const &>(settings)),
147144
context_(io_service_, dynamic_cast<ssl_server_settings const &>(settings).get_ssl_method()) {
148-
#ifdef _DEBUG
145+
#ifdef DEBUG_WWW
149146
_log.Log(LOG_STATUS, "[web:%s] create ssl_server using server_settings : %s", settings.listening_port.c_str(), settings.to_string().c_str());
150147
#endif
151148
init(boost::bind(&ssl_server::init_connection, this),
@@ -206,7 +203,7 @@ void ssl_server::init_connection() {
206203
(std::istreambuf_iterator<char>()));
207204
if (content.find("BEGIN DH PARAMETERS") != std::string::npos) {
208205
context_.use_tmp_dh_file(settings_.tmp_dh_file_path);
209-
#ifdef _DEBUG
206+
#ifdef DEBUG_WWW
210207
_log.Log(LOG_STATUS, "[web:%s] 'BEGIN DH PARAMETERS' found in file %s", settings_.listening_port.c_str(), settings_.tmp_dh_file_path.c_str());
211208
#endif
212209
} else {

www/app/CustomController.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
define(['app'], function (app) {
2+
app.controller('CustomController', [ '$scope', '$rootScope', '$location', '$http', '$interval', '$routeParams', function($scope,$rootScope,$location,$http,$interval,$routeParams) {
3+
init();
4+
5+
function init()
6+
{
7+
var custompage=$routeParams.custompage.replace(/ /g,"%20");
8+
$("#customcontent").load("templates/" + custompage + ".html", function (response, status, xhr) {
9+
if (status == "error") {
10+
var msg = "Sorry but there was an error: ";
11+
$("#customcontent").html(msg + xhr.status + " " + xhr.statusText);
12+
}
13+
});
14+
};
15+
} ]);
16+
});

www/app/app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ define(['angularAMD', 'angular-route', 'angular-animate', 'ng-grid', 'ng-grid-fl
315315
templateUrl: 'views/about.html',
316316
controller: 'AboutController'
317317
})).
318+
when('/Custom/:custompage', angularAMD.route({
319+
templateUrl: 'views/custom.html',
320+
controller: 'CustomController'
321+
})
322+
).
318323
otherwise({
319324
redirectTo: '/Dashboard'
320325
});

www/html5.appcache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ i18n/domoticz-zh.json
442442
app/AboutController.js
443443
app/app.js
444444
app/CamController.js
445+
app/CustomController.js
445446
app/CustomIconsController.js
446447
app/DashboardController.js
447448
app/DevicesController.js
@@ -542,6 +543,7 @@ ozwcp/cp.js
542543
# HTML pages
543544
views/about.html
544545
views/cam.html
546+
views/custom.html
545547
views/customicons.html
546548
views/dashboard.html
547549
views/devices.html

www/js/domoticz.js.gz

-46 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)