Compare commits
44 Commits
0.5.0
...
plugin_rew
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7d40dc6e0 | ||
|
|
9ac1a378d0 | ||
|
|
de01486c0f | ||
|
|
c383a53105 | ||
|
|
f0b67ea4cd | ||
|
|
ac96ace7df | ||
|
|
7970f80114 | ||
|
|
62216a7afe | ||
|
|
99711a5c6e | ||
|
|
e43aea35cc | ||
|
|
d54d723c59 | ||
|
|
c813231c8d | ||
|
|
debbca572f | ||
|
|
a8ee6e7f60 | ||
|
|
f0e9b2ffd9 | ||
|
|
ba19048ebc | ||
|
|
fd05f13fe4 | ||
|
|
11538d6909 | ||
|
|
90d05c9a19 | ||
|
|
ed5a59b16c | ||
|
|
70f2a43f67 | ||
|
|
dc80644471 | ||
|
|
889807da1b | ||
|
|
5151badbeb | ||
|
|
96cc46117f | ||
|
|
5e63ab2ccd | ||
|
|
32b7e68f00 | ||
|
|
5c5918a89d | ||
|
|
3f2641595b | ||
|
|
0e27e4219d | ||
|
|
e32bb3ff7a | ||
|
|
32c65ada49 | ||
|
|
77704f6e67 | ||
|
|
77323fa98d | ||
|
|
7840e09884 | ||
|
|
6ad5efea6d | ||
|
|
076daec846 | ||
|
|
223e01937e | ||
|
|
19068de088 | ||
|
|
c15f201d70 | ||
|
|
7bda215ad4 | ||
|
|
d86ef503b3 | ||
|
|
7865277324 | ||
|
|
8a7e892aeb |
3
BUGS
3
BUGS
@@ -1,2 +1 @@
|
||||
Bugs are tracked on: http://bugs.extatic.org/
|
||||
|
||||
Bugs are tracked on: https://github.com/janvidar/uhub/issues
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
##
|
||||
## Makefile for uhub
|
||||
## Copyright (C) 2007-2013, Jan Vidar Krey <janvidar@extatic.org>
|
||||
## Copyright (C) 2007-2019, Jan Vidar Krey <janvidar@extatic.org>
|
||||
#
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.2)
|
||||
@@ -10,7 +10,7 @@ enable_language(C)
|
||||
|
||||
set (UHUB_VERSION_MAJOR 0)
|
||||
set (UHUB_VERSION_MINOR 5)
|
||||
set (UHUB_VERSION_PATCH 0)
|
||||
set (UHUB_VERSION_PATCH 1)
|
||||
|
||||
set (PROJECT_SOURCE_DIR "${CMAKE_SOURCE_DIR}/src")
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules)
|
||||
@@ -54,10 +54,13 @@ if (SSL_SUPPORT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT SQLITE3_FOUND)
|
||||
message(FATAL_ERROR "SQLite3 is not found!")
|
||||
endif()
|
||||
|
||||
if (SYSTEMD_SUPPORT)
|
||||
INCLUDE(FindPkgConfig)
|
||||
pkg_search_module(SD_DAEMON REQUIRED libsystemd-daemon)
|
||||
pkg_search_module(SD_JOURNAL REQUIRED libsystemd-journal)
|
||||
pkg_search_module(SD REQUIRED libsystemd)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
@@ -104,7 +107,7 @@ add_dependencies(adc utils)
|
||||
add_dependencies(network utils)
|
||||
|
||||
add_executable(uhub ${PROJECT_SOURCE_DIR}/core/main.c ${uhub_SOURCES} )
|
||||
add_executable(test ${CMAKE_SOURCE_DIR}/autotest/test.c ${uhub_SOURCES} )
|
||||
add_executable(autotest-bin ${CMAKE_SOURCE_DIR}/autotest/test.c ${uhub_SOURCES} )
|
||||
add_executable(uhub-passwd ${PROJECT_SOURCE_DIR}/tools/uhub-passwd.c)
|
||||
|
||||
add_library(mod_example MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_example.c)
|
||||
@@ -117,10 +120,11 @@ add_library(mod_chat_only MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_chat_only.c)
|
||||
add_library(mod_topic MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_topic.c)
|
||||
add_library(mod_no_guest_downloads MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_no_guest_downloads.c)
|
||||
add_library(mod_auth_sqlite MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_auth_sqlite.c)
|
||||
add_library(mod_require_tls MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_require_tls.c)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(uhub ws2_32)
|
||||
target_link_libraries(test ws2_32)
|
||||
target_link_libraries(autotest-bin ws2_32)
|
||||
target_link_libraries(mod_logging ws2_32)
|
||||
target_link_libraries(mod_welcome ws2_32)
|
||||
endif()
|
||||
@@ -136,11 +140,12 @@ set_target_properties(
|
||||
mod_chat_only
|
||||
mod_no_guest_downloads
|
||||
mod_topic
|
||||
mod_require_tls
|
||||
PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries(uhub ${CMAKE_DL_LIBS} adc network utils)
|
||||
target_link_libraries(uhub-passwd ${SQLITE3_LIBRARIES} utils)
|
||||
target_link_libraries(test ${CMAKE_DL_LIBS} adc network utils)
|
||||
target_link_libraries(autotest-bin ${CMAKE_DL_LIBS} adc network utils)
|
||||
target_link_libraries(mod_example utils)
|
||||
target_link_libraries(mod_welcome utils)
|
||||
target_link_libraries(mod_auth_simple utils)
|
||||
@@ -151,6 +156,7 @@ target_link_libraries(mod_no_guest_downloads utils)
|
||||
target_link_libraries(mod_chat_only utils)
|
||||
target_link_libraries(mod_logging utils)
|
||||
target_link_libraries(mod_topic utils)
|
||||
target_link_libraries(mod_require_tls utils)
|
||||
target_link_libraries(utils network)
|
||||
target_link_libraries(mod_welcome network)
|
||||
target_link_libraries(mod_logging network)
|
||||
@@ -161,7 +167,7 @@ if(UNIX)
|
||||
add_executable(uhub-admin ${PROJECT_SOURCE_DIR}/tools/admin.c)
|
||||
target_link_libraries(uhub-admin adcclient adc network utils pthread)
|
||||
target_link_libraries(uhub pthread)
|
||||
target_link_libraries(test pthread)
|
||||
target_link_libraries(autotest-bin pthread)
|
||||
|
||||
if (ADC_STRESS)
|
||||
add_executable(adcrush ${PROJECT_SOURCE_DIR}/tools/adcrush.c ${adcclient_SOURCES})
|
||||
@@ -200,7 +206,7 @@ endif()
|
||||
|
||||
if(SSL_SUPPORT)
|
||||
target_link_libraries(uhub ${SSL_LIBS})
|
||||
target_link_libraries(test ${SSL_LIBS})
|
||||
target_link_libraries(autotest-bin ${SSL_LIBS})
|
||||
if(UNIX)
|
||||
target_link_libraries(uhub-admin ${SSL_LIBS})
|
||||
endif()
|
||||
@@ -212,14 +218,11 @@ if(SSL_SUPPORT)
|
||||
endif()
|
||||
|
||||
if (SYSTEMD_SUPPORT)
|
||||
target_link_libraries(uhub ${SD_DAEMON_LIBRARIES})
|
||||
target_link_libraries(uhub ${SD_JOURNAL_LIBRARIES})
|
||||
target_link_libraries(test ${SD_DAEMON_LIBRARIES})
|
||||
target_link_libraries(test ${SD_JOURNAL_LIBRARIES})
|
||||
target_link_libraries(uhub-passwd ${SD_JOURNAL_LIBRARIES})
|
||||
target_link_libraries(uhub-admin ${SD_JOURNAL_LIBRARIES})
|
||||
include_directories(${SD_DAEMON_INCLUDE_DIRS})
|
||||
include_directories(${SD_JOURNAL_INCLUDE_DIRS})
|
||||
target_link_libraries(uhub ${SD_LIBRARIES})
|
||||
target_link_libraries(autotest-bin ${SD_LIBRARIES})
|
||||
target_link_libraries(uhub-passwd ${SD_LIBRARIES})
|
||||
target_link_libraries(uhub-admin ${SD_LIBRARIES})
|
||||
include_directories(${SD_INCLUDE_DIRS})
|
||||
add_definitions(-DSYSTEMD)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -706,6 +706,34 @@ int main(int argc, char** argv)
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_10, "utf8_valid_10");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_11, "utf8_valid_11");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_12, "utf8_valid_12");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_13, "utf8_valid_13");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_14, "utf8_valid_14");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_15, "utf8_valid_15");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_16, "utf8_valid_16");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_17, "utf8_valid_17");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_18, "utf8_valid_18");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_19, "utf8_valid_19");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_20, "utf8_valid_20");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_21, "utf8_valid_21");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_22, "utf8_valid_22");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_23, "utf8_valid_23");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_24, "utf8_valid_24");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_25, "utf8_valid_25");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_26, "utf8_valid_26");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_27, "utf8_valid_27");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_28, "utf8_valid_28");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_29, "utf8_valid_29");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_30, "utf8_valid_30");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_31, "utf8_valid_31");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_32, "utf8_valid_32");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_33, "utf8_valid_33");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_34, "utf8_valid_34");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_35, "utf8_valid_35");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_36, "utf8_valid_36");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_37, "utf8_valid_37");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_38, "utf8_valid_38");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_39, "utf8_valid_39");
|
||||
exotic_add_test(&handle, &exotic_test_utf8_valid_40, "utf8_valid_40");
|
||||
exotic_add_test(&handle, &exotic_test_rbtree_create_destroy, "rbtree_create_destroy");
|
||||
exotic_add_test(&handle, &exotic_test_rbtree_create_1, "rbtree_create_1");
|
||||
exotic_add_test(&handle, &exotic_test_rbtree_size_0, "rbtree_size_0");
|
||||
|
||||
@@ -107,6 +107,7 @@ static const char test_utf_seq_6[] = { 0xE2, 0x82, 0xAC, 0x00}; // valid
|
||||
static const char test_utf_seq_7[] = { 0xC2, 0x32, 0x00}; // invalid
|
||||
static const char test_utf_seq_8[] = { 0xE2, 0x82, 0x32, 0x00}; // invalid
|
||||
static const char test_utf_seq_9[] = { 0xE2, 0x32, 0x82, 0x00}; // invalid
|
||||
static const char test_utf_seq_10[] = { 0xF0, 0x9F, 0x98, 0x81, 0x00}; // valid
|
||||
|
||||
EXO_TEST(utf8_valid_4, { return is_valid_utf8(test_utf_seq_1); });
|
||||
EXO_TEST(utf8_valid_5, { return !is_valid_utf8(test_utf_seq_2); });
|
||||
@@ -117,5 +118,61 @@ EXO_TEST(utf8_valid_9, { return is_valid_utf8(test_utf_seq_6); });
|
||||
EXO_TEST(utf8_valid_10, { return !is_valid_utf8(test_utf_seq_7); });
|
||||
EXO_TEST(utf8_valid_11, { return !is_valid_utf8(test_utf_seq_8); });
|
||||
EXO_TEST(utf8_valid_12, { return !is_valid_utf8(test_utf_seq_9); });
|
||||
EXO_TEST(utf8_valid_13, { return is_valid_utf8(test_utf_seq_10); });
|
||||
|
||||
// Limits of utf-8
|
||||
static const char test_utf_seq_11[] = { 0x7F, 0x00 }; // valid last 7-bit character
|
||||
static const char test_utf_seq_12[] = { 0x80, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_13[] = { 0xBF, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_14[] = { 0xC0, 0x80, 0x00 }; // invalid out of 2 bytes range
|
||||
static const char test_utf_seq_15[] = { 0xC1, 0x7F, 0x00 }; // invalid out of 2 bytes range
|
||||
static const char test_utf_seq_16[] = { 0xC2, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_17[] = { 0xC2, 0x80, 0x00 }; // valid
|
||||
static const char test_utf_seq_18[] = { 0xDF, 0xBF, 0x00 }; // valid
|
||||
static const char test_utf_seq_19[] = { 0xE0, 0x80, 0x80, 0x00 }; // invalid out of 3 bytes range
|
||||
static const char test_utf_seq_20[] = { 0xE0, 0x9F, 0xBF, 0x00 }; // invalid out of 3 bytes range
|
||||
static const char test_utf_seq_21[] = { 0xE0, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_22[] = { 0xE0, 0xA0, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_23[] = { 0xE0, 0xA0, 0x80, 0x00 }; // valid
|
||||
static const char test_utf_seq_24[] = { 0xEC, 0x9F, 0xBF, 0x00 }; // valid
|
||||
static const char test_utf_seq_25[] = { 0xED, 0xA0, 0x80, 0x00 }; // invalid surrogate
|
||||
static const char test_utf_seq_26[] = { 0xED, 0xBF, 0xBF, 0x00 }; // invalid surrogate
|
||||
static const char test_utf_seq_27[] = { 0xEF, 0x80, 0x80, 0x00 }; // valid
|
||||
static const char test_utf_seq_28[] = { 0xEF, 0xBF, 0xBF, 0x00 }; // valid
|
||||
static const char test_utf_seq_29[] = { 0xF0, 0x80, 0x80, 0x80, 0x00 }; // invalid out of 4 bytes range
|
||||
static const char test_utf_seq_30[] = { 0xF0, 0x8F, 0xBF, 0xBF, 0x00 }; // invalid out of 4 bytes range
|
||||
static const char test_utf_seq_31[] = { 0xF0, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_32[] = { 0xF0, 0x90, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_33[] = { 0xF0, 0x90, 0x80, 0x00 }; // invalid truncated string
|
||||
static const char test_utf_seq_34[] = { 0xF0, 0x90, 0x80, 0x80, 0x00 }; // valid
|
||||
static const char test_utf_seq_35[] = { 0xF4, 0x8F, 0xBF, 0xBF, 0x00 }; // valid
|
||||
static const char test_utf_seq_36[] = { 0xF4, 0x90, 0x80, 0x80, 0x00 }; // invalid out of 4 bytes range
|
||||
static const char test_utf_seq_37[] = { 0xFF, 0xBF, 0xBF, 0xBF, 0x00 }; // invalid out of 4 bytes range
|
||||
|
||||
EXO_TEST(utf8_valid_14, { return is_valid_utf8(test_utf_seq_11); });
|
||||
EXO_TEST(utf8_valid_15, { return !is_valid_utf8(test_utf_seq_12); });
|
||||
EXO_TEST(utf8_valid_16, { return !is_valid_utf8(test_utf_seq_13); });
|
||||
EXO_TEST(utf8_valid_17, { return !is_valid_utf8(test_utf_seq_14); });
|
||||
EXO_TEST(utf8_valid_18, { return !is_valid_utf8(test_utf_seq_15); });
|
||||
EXO_TEST(utf8_valid_19, { return !is_valid_utf8(test_utf_seq_16); });
|
||||
EXO_TEST(utf8_valid_20, { return is_valid_utf8(test_utf_seq_17); });
|
||||
EXO_TEST(utf8_valid_21, { return is_valid_utf8(test_utf_seq_18); });
|
||||
EXO_TEST(utf8_valid_22, { return !is_valid_utf8(test_utf_seq_19); });
|
||||
EXO_TEST(utf8_valid_23, { return !is_valid_utf8(test_utf_seq_20); });
|
||||
EXO_TEST(utf8_valid_24, { return !is_valid_utf8(test_utf_seq_21); });
|
||||
EXO_TEST(utf8_valid_25, { return !is_valid_utf8(test_utf_seq_22); });
|
||||
EXO_TEST(utf8_valid_26, { return is_valid_utf8(test_utf_seq_23); });
|
||||
EXO_TEST(utf8_valid_27, { return is_valid_utf8(test_utf_seq_24); });
|
||||
EXO_TEST(utf8_valid_28, { return !is_valid_utf8(test_utf_seq_25); });
|
||||
EXO_TEST(utf8_valid_29, { return !is_valid_utf8(test_utf_seq_26); });
|
||||
EXO_TEST(utf8_valid_30, { return is_valid_utf8(test_utf_seq_27); });
|
||||
EXO_TEST(utf8_valid_31, { return is_valid_utf8(test_utf_seq_28); });
|
||||
EXO_TEST(utf8_valid_32, { return !is_valid_utf8(test_utf_seq_29); });
|
||||
EXO_TEST(utf8_valid_33, { return !is_valid_utf8(test_utf_seq_30); });
|
||||
EXO_TEST(utf8_valid_34, { return !is_valid_utf8(test_utf_seq_31); });
|
||||
EXO_TEST(utf8_valid_35, { return !is_valid_utf8(test_utf_seq_32); });
|
||||
EXO_TEST(utf8_valid_36, { return !is_valid_utf8(test_utf_seq_33); });
|
||||
EXO_TEST(utf8_valid_37, { return is_valid_utf8(test_utf_seq_34); });
|
||||
EXO_TEST(utf8_valid_38, { return is_valid_utf8(test_utf_seq_35); });
|
||||
EXO_TEST(utf8_valid_39, { return !is_valid_utf8(test_utf_seq_36); });
|
||||
EXO_TEST(utf8_valid_40, { return !is_valid_utf8(test_utf_seq_37); });
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
export CFLAGS="$(dpkg-buildflags --get CFLAGS) $(dpkg-buildflags --get CPPFLAGS)"
|
||||
export LDFLAGS="$(dpkg-buildflags --get LDFLAGS) -Wl,--as-needed"
|
||||
@@ -33,6 +34,10 @@ cmake ${CMAKEOPTS} \
|
||||
make VERBOSE=1
|
||||
|
||||
|
||||
make VERBOSE=1 autotest-bin
|
||||
./autotest-bin
|
||||
|
||||
|
||||
sudo make install
|
||||
du -shc /etc/uhub/ /usr/bin/uhub* /usr/lib/uhub/
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
Getting started guide
|
||||
---------------------
|
||||
|
||||
(This document is maintained at http://www.extatic.org/uhub/getstarted.html )
|
||||
|
||||
Unpack your binaries
|
||||
|
||||
Example:
|
||||
@@ -17,6 +15,7 @@ Create configuration files.
|
||||
If no configuration files are created, uhub will use the default parameters, so you can skip this step if you are in a hurry to see it run.
|
||||
|
||||
As root, or use sudo.
|
||||
|
||||
% mkdir /etc/uhub
|
||||
% cp doc/uhub.conf /etc/uhub
|
||||
% cp doc/users.conf /etc/uhub
|
||||
@@ -32,8 +31,11 @@ NOTE: It is important to use the "adc://" prefix, and the port number when using
|
||||
|
||||
If you modify the configuration files in /etc/uhub you will have to notify uhub by sending a HUP signal.
|
||||
|
||||
% ps aux | grep uhub
|
||||
% kill -HUP <pid of uhub>
|
||||
|
||||
Or, for the lazy people
|
||||
|
||||
% killall -HUP uhub
|
||||
|
||||
In order to run uhub as a daemon, start it with the -f switch which will make it fork into the background.
|
||||
@@ -41,8 +43,8 @@ In addition, use the -l to specify a log file instead of stdout. One can also sp
|
||||
if one wishes to run uhub as a specific user using the -u and -g switches.
|
||||
|
||||
Example:
|
||||
% uhub -f -l mylog.txt -u nobody -g nogroup
|
||||
|
||||
% uhub -f -l mylog.txt -u nobody -g nogroup
|
||||
|
||||
If you are planning to more than 1024 users on hub, you must increase the max number of file descriptors allowed.
|
||||
This limit needs to be higher than the configured max_users in uhub.conf.
|
||||
@@ -52,6 +54,14 @@ In linux can add the following lines to /etc/security/limits.conf (allows for ~4
|
||||
* hard nofile 4096
|
||||
|
||||
Or, you can use (as root):
|
||||
|
||||
% ulimit -n 4096
|
||||
|
||||
You can interact with uhub in your hub main chat using the `!` prefix, followed by a command:
|
||||
|
||||
Example :
|
||||
|
||||
* to display help and the command you can use:
|
||||
!help
|
||||
|
||||
Your mileage may vary -- Good luck!
|
||||
|
||||
@@ -41,7 +41,7 @@ plugin /usr/lib/uhub/mod_logging.so "file=/var/log/uhub.log"
|
||||
#
|
||||
# Parameters:
|
||||
# motd: path/filename for the welcome message (message of the day)
|
||||
# rules: path/filenam for the rules file
|
||||
# rules: path/filename for the rules file
|
||||
#
|
||||
# NOTE: The files MUST exist, however if you do not wish to provide one then these parameters can be omitted.
|
||||
#
|
||||
@@ -69,4 +69,3 @@ plugin /usr/lib/uhub/mod_welcome.so "motd=/etc/uhub/motd.txt rules=/etc/uhub/rul
|
||||
# history_default: when !history is provided without arguments, then this default number of messages are returned.
|
||||
# history_connect: the number of chat history messages to send when users connect (0 = do not send any history)
|
||||
plugin /usr/lib/uhub/mod_chat_history.so "history_max=200 history_default=10 history_connect=5"
|
||||
|
||||
|
||||
@@ -39,4 +39,4 @@ is one of 'admin', 'super', 'op', 'user'
|
||||
This program was written by Jan Vidar Krey <janvidar@extatic.org>
|
||||
.SH "BUG REPORTS"
|
||||
If you find a bug in uhub please report it to
|
||||
.B http://bugs.extatic.org/
|
||||
.B https://github.com/janvidar/uhub/issues
|
||||
|
||||
@@ -69,4 +69,4 @@ To run uhub as a daemon, and log to a file:
|
||||
This program was written by Jan Vidar Krey <janvidar@extatic.org>
|
||||
.SH "BUG REPORTS"
|
||||
If you find a bug in uhub please report it to
|
||||
.B http://bugs.extatic.org/
|
||||
.B https://github.com/janvidar/uhub/issues
|
||||
|
||||
@@ -156,9 +156,10 @@ typedef uint32_t fourcc_t;
|
||||
#define ADC_SUP_FLAG_ADD "AD"
|
||||
#define ADC_SUP_FLAG_REMOVE "RM"
|
||||
|
||||
#define ADC_CLIENT_TYPE_BOT "1"
|
||||
#define ADC_CLIENT_TYPE_REGISTERED_USER "2"
|
||||
#define ADC_CLIENT_TYPE_OPERATOR "4"
|
||||
#define ADC_CLIENT_TYPE_BOT "1"
|
||||
#define ADC_CLIENT_TYPE_REGISTERED_USER "2"
|
||||
#define ADC_CLIENT_TYPE_OPERATOR "4"
|
||||
#define ADC_CLIENT_TYPE_HUBBOT "5" /* 1 + 4 */
|
||||
#define ADC_CLIENT_TYPE_SUPER_USER "12" /* 8 + 4 */
|
||||
#define ADC_CLIENT_TYPE_ADMIN "20" /* 16 + 4 = hub owner */
|
||||
#define ADC_CLIENT_TYPE_HUB "32" /* the hub itself */
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
uhub_assert(X); \
|
||||
uhub_assert(X->cache); \
|
||||
uhub_assert(X->capacity); \
|
||||
uhub_assert(X->length); \
|
||||
uhub_assert(X->length <= X->capacity); \
|
||||
uhub_assert(X->references > 0); \
|
||||
uhub_assert(X->length == strlen(X->cache));
|
||||
@@ -311,7 +310,7 @@ struct adc_message* adc_msg_parse_verify(struct hub_user* u, const char* line, s
|
||||
if (!command)
|
||||
return 0;
|
||||
|
||||
if (command->source && (!u || command->source != u->id.sid))
|
||||
if (command->source && (!u || (command->source != u->id.sid && !auth_cred_is_unrestricted(u->credentials))))
|
||||
{
|
||||
LOG_DEBUG("Command does not match user's SID (command->source=%d, user->id.sid=%d)", command->source, (u ? u->id.sid : 0));
|
||||
adc_msg_free(command);
|
||||
|
||||
@@ -170,6 +170,9 @@ static int acl_parse_line(char* line, int line_count, void* ptr_data)
|
||||
LOG_DEBUG("acl_parse_line: '%s'", line);
|
||||
|
||||
ACL_ADD_USER("bot", handle->users, auth_cred_bot);
|
||||
ACL_ADD_USER("ubot", handle->users, auth_cred_ubot);
|
||||
ACL_ADD_USER("opbot", handle->users, auth_cred_opbot);
|
||||
ACL_ADD_USER("opubot", handle->users, auth_cred_opubot);
|
||||
ACL_ADD_USER("user_admin", handle->users, auth_cred_admin);
|
||||
ACL_ADD_USER("user_super", handle->users, auth_cred_super);
|
||||
ACL_ADD_USER("user_op", handle->users, auth_cred_operator);
|
||||
|
||||
@@ -84,7 +84,7 @@ class Option(object):
|
||||
|
||||
class SourceGenerator(object):
|
||||
def __init__(self, filename, cppStyle = True):
|
||||
print "Generating %s..." % filename
|
||||
print ("Generating %s..." % filename)
|
||||
self.f = open(filename, 'w');
|
||||
|
||||
def write_header(self, Comment = True):
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
<option name="register_self" type="boolean" default="0">
|
||||
<short>Allow users to register themselves on the hub.</short>
|
||||
<description><![CDATA[
|
||||
If this is enabled guests can register their nickname on the hub.
|
||||
If this is enabled guests can register their nickname on the hub using !register command.
|
||||
Otherwise only operators can register users.
|
||||
]]></description>
|
||||
<since>0.4.0</since>
|
||||
|
||||
@@ -23,7 +23,7 @@ struct hub_info* g_hub = 0;
|
||||
|
||||
/* FIXME: Flood control should be done in a plugin! */
|
||||
#define CHECK_FLOOD(TYPE, WARN) \
|
||||
if (flood_control_check(&u->flood_ ## TYPE , hub->config->flood_ctl_ ## TYPE, hub->config->flood_ctl_interval, net_get_time())) \
|
||||
if (flood_control_check(&u->flood_ ## TYPE , hub->config->flood_ctl_ ## TYPE, hub->config->flood_ctl_interval, net_get_time()) && !auth_cred_is_unrestricted(u->credentials)) \
|
||||
{ \
|
||||
if (WARN) \
|
||||
{ \
|
||||
|
||||
@@ -571,6 +571,10 @@ static int set_credentials(struct hub_info* hub, struct hub_user* user, struct a
|
||||
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_BOT);
|
||||
break;
|
||||
|
||||
case auth_cred_ubot:
|
||||
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_BOT);
|
||||
break;
|
||||
|
||||
case auth_cred_guest:
|
||||
/* Nothing to be added to the info message */
|
||||
break;
|
||||
@@ -583,6 +587,14 @@ static int set_credentials(struct hub_info* hub, struct hub_user* user, struct a
|
||||
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_OPERATOR);
|
||||
break;
|
||||
|
||||
case auth_cred_opbot:
|
||||
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_HUBBOT);
|
||||
break;
|
||||
|
||||
case auth_cred_opubot:
|
||||
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_HUBBOT);
|
||||
break;
|
||||
|
||||
case auth_cred_super:
|
||||
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_SUPER_USER);
|
||||
break;
|
||||
|
||||
@@ -96,6 +96,29 @@ static int cbfunc_user_disconnect(struct plugin_handle* plugin, struct plugin_us
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cbfunc_user_redirect(struct plugin_handle* plugin, struct plugin_user* user, const char* address)
|
||||
{
|
||||
char* buffer = adc_msg_escape(address);
|
||||
struct adc_message* command = adc_msg_construct(ADC_CMD_IQUI, strlen(buffer) + 10);
|
||||
adc_msg_add_named_argument(command, ADC_QUI_FLAG_REDIRECT, buffer);
|
||||
route_to_user(plugin_get_hub(plugin), convert_user_type(user), command);
|
||||
adc_msg_free(command);
|
||||
hub_free(buffer);
|
||||
hub_disconnect_user(plugin_get_hub(plugin), convert_user_type(user), quit_disconnected);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cbfunc_user_is_tls_connected(struct plugin_handle* plugin, struct plugin_user* user)
|
||||
{
|
||||
#ifdef SSL_SUPPORT
|
||||
struct hub_user* u = convert_user_type(user);
|
||||
return net_con_is_ssl(u->connection);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int cbfunc_command_add(struct plugin_handle* plugin, struct plugin_command_handle* cmdh)
|
||||
{
|
||||
struct plugin_callback_data* data = get_callback_data(plugin);
|
||||
@@ -203,6 +226,8 @@ void plugin_register_callback_functions(struct plugin_handle* handle)
|
||||
handle->hub.send_broadcast_message = cbfunc_send_broadcast;
|
||||
handle->hub.send_status_message = cbfunc_send_status;
|
||||
handle->hub.user_disconnect = cbfunc_user_disconnect;
|
||||
handle->hub.user_redirect = cbfunc_user_redirect;
|
||||
handle->hub.user_is_tls_connected = cbfunc_user_is_tls_connected;
|
||||
handle->hub.command_add = cbfunc_command_add;
|
||||
handle->hub.command_del = cbfunc_command_del;
|
||||
handle->hub.command_arg_reset = cbfunc_command_arg_reset;
|
||||
|
||||
@@ -102,7 +102,6 @@ struct plugin_handle* plugin_load(const char* filename, const char* config, stru
|
||||
int ret;
|
||||
struct plugin_handle* handle = (struct plugin_handle*) hub_malloc_zero(sizeof(struct plugin_handle));
|
||||
struct uhub_plugin* plugin = plugin_open(filename);
|
||||
struct plugin_hub_internals* internals = (struct plugin_hub_internals*) plugin->internals;
|
||||
|
||||
if (!plugin)
|
||||
return NULL;
|
||||
@@ -118,6 +117,7 @@ struct plugin_handle* plugin_load(const char* filename, const char* config, stru
|
||||
unregister_f = plugin_lookup_symbol(plugin, "plugin_unregister");
|
||||
|
||||
// register hub internals
|
||||
struct plugin_hub_internals* internals = (struct plugin_hub_internals*) plugin->internals;
|
||||
internals->unregister = unregister_f;
|
||||
internals->hub = hub;
|
||||
internals->callback_data = plugin_callback_data_create();
|
||||
|
||||
@@ -91,7 +91,9 @@ int net_ssl_library_init()
|
||||
int net_ssl_library_shutdown()
|
||||
{
|
||||
ERR_clear_error();
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
ERR_remove_state(0);
|
||||
#endif
|
||||
|
||||
ENGINE_cleanup();
|
||||
CONF_modules_unload(1);
|
||||
@@ -106,16 +108,24 @@ int net_ssl_library_shutdown()
|
||||
|
||||
static void add_io_stats(struct net_ssl_openssl* handle)
|
||||
{
|
||||
if (handle->bio->num_read > handle->bytes_rx)
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
unsigned long num_read = handle->bio->num_read;
|
||||
unsigned long num_write = handle->bio->num_write;
|
||||
#else
|
||||
unsigned long num_read = BIO_number_read(handle->bio);
|
||||
unsigned long num_write = BIO_number_written(handle->bio);
|
||||
#endif
|
||||
|
||||
if (num_read > handle->bytes_rx)
|
||||
{
|
||||
net_stats_add_rx(handle->bio->num_read - handle->bytes_rx);
|
||||
handle->bytes_rx = handle->bio->num_read;
|
||||
net_stats_add_rx(num_read - handle->bytes_rx);
|
||||
handle->bytes_rx = num_read;
|
||||
}
|
||||
|
||||
if (handle->bio->num_write > handle->bytes_tx)
|
||||
if (num_write > handle->bytes_tx)
|
||||
{
|
||||
net_stats_add_tx(handle->bio->num_write - handle->bytes_tx);
|
||||
handle->bytes_tx = handle->bio->num_write;
|
||||
net_stats_add_tx(num_write - handle->bytes_tx);
|
||||
handle->bytes_tx = num_write;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +137,7 @@ static const SSL_METHOD* get_ssl_method(const char* tls_version)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
if (!strcmp(tls_version, "1.0"))
|
||||
return TLSv1_method();
|
||||
if (!strcmp(tls_version, "1.1"))
|
||||
@@ -136,6 +147,10 @@ static const SSL_METHOD* get_ssl_method(const char* tls_version)
|
||||
|
||||
LOG_ERROR("Unable to recognize tls_version.");
|
||||
return 0;
|
||||
#else
|
||||
LOG_WARN("tls_version is obsolete, and should not be used.");
|
||||
return TLS_method();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,7 +348,7 @@ ssize_t net_ssl_send(struct net_connection* con, const void* buf, size_t len)
|
||||
{
|
||||
struct net_ssl_openssl* handle = get_handle(con);
|
||||
|
||||
LOG_ERROR("net_ssl_send(), state=%d", (int) handle->state);
|
||||
LOG_TRACE("net_ssl_send(), state=%d", (int) handle->state);
|
||||
|
||||
if (handle->state == tls_st_error)
|
||||
return -2;
|
||||
|
||||
@@ -35,6 +35,16 @@ struct plugin_command
|
||||
struct linked_list* args;
|
||||
};
|
||||
|
||||
enum plugin_command_arg_type
|
||||
{
|
||||
plugin_cmd_arg_type_integer,
|
||||
plugin_cmd_arg_type_string,
|
||||
plugin_cmd_arg_type_user,
|
||||
plugin_cmd_arg_type_address,
|
||||
plugin_cmd_arg_type_range,
|
||||
plugin_cmd_arg_type_credentials,
|
||||
};
|
||||
|
||||
struct plugin_command_arg_data
|
||||
{
|
||||
enum plugin_command_arg_type type;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "util/credentials.h"
|
||||
#include "network/ipcalc.h"
|
||||
#include "plugin_api/types.h"
|
||||
#include "plugin_api/command_api.h"
|
||||
|
||||
typedef void (*on_connection_accepted_t)(struct plugin_handle*, struct ip_addr_encap*);
|
||||
typedef void (*on_connection_refused_t)(struct plugin_handle*, struct ip_addr_encap*);
|
||||
@@ -113,6 +114,8 @@ typedef int (*hfunc_send_message)(struct plugin_handle*, struct plugin_user* use
|
||||
typedef int (*hfunc_send_broadcast_message)(struct plugin_handle*, const char* message);
|
||||
typedef int (*hfunc_send_status)(struct plugin_handle*, struct plugin_user* to, int code, const char* message);
|
||||
typedef int (*hfunc_user_disconnect)(struct plugin_handle*, struct plugin_user* user);
|
||||
typedef int (*hfunc_user_redirect)(struct plugin_handle*, struct plugin_user* user, const char* address);
|
||||
typedef int (*hfunc_user_is_tls_connected)(struct plugin_handle*, struct plugin_user* user);
|
||||
typedef int (*hfunc_command_add)(struct plugin_handle*, struct plugin_command_handle*);
|
||||
typedef int (*hfunc_command_del)(struct plugin_handle*, struct plugin_command_handle*);
|
||||
|
||||
@@ -136,6 +139,8 @@ struct plugin_hub_funcs
|
||||
hfunc_send_broadcast_message send_broadcast_message;
|
||||
hfunc_send_status send_status_message;
|
||||
hfunc_user_disconnect user_disconnect;
|
||||
hfunc_user_redirect user_redirect;
|
||||
hfunc_user_is_tls_connected user_is_tls_connected;
|
||||
hfunc_command_add command_add;
|
||||
hfunc_command_del command_del;
|
||||
hfunc_command_arg_reset command_arg_reset;
|
||||
|
||||
@@ -93,15 +93,6 @@ struct ban_info
|
||||
time_t expiry; /* Time when the ban record expires */
|
||||
};
|
||||
|
||||
enum plugin_command_arg_type
|
||||
{
|
||||
plugin_cmd_arg_type_integer,
|
||||
plugin_cmd_arg_type_string,
|
||||
plugin_cmd_arg_type_user,
|
||||
plugin_cmd_arg_type_address,
|
||||
plugin_cmd_arg_type_range,
|
||||
plugin_cmd_arg_type_credentials,
|
||||
};
|
||||
|
||||
|
||||
#endif /* HAVE_UHUB_PLUGIN_TYPES_H */
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "util/list.h"
|
||||
#include "util/cbuffer.h"
|
||||
|
||||
#define MAX_HISTORY_SIZE 16384
|
||||
#define MAX_HISTORY_SIZE 614400
|
||||
|
||||
struct chat_history_data
|
||||
{
|
||||
@@ -49,7 +49,7 @@ static int null_callback(void* ptr, int argc, char **argv, char **colName) { ret
|
||||
|
||||
static const char* sql_escape_string(const char* str)
|
||||
{
|
||||
static char out[1024];
|
||||
static char out[MAX_HISTORY_SIZE];
|
||||
size_t i = 0;
|
||||
size_t n = 0;
|
||||
for (; n < strlen(str); n++)
|
||||
@@ -65,7 +65,7 @@ static const char* sql_escape_string(const char* str)
|
||||
static int sql_execute(struct chat_history_data* sql, int (*callback)(void* ptr, int argc, char **argv, char **colName), void* ptr, const char* sql_fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char query[1024];
|
||||
char query[MAX_HISTORY_SIZE];
|
||||
char* errMsg;
|
||||
int rc;
|
||||
|
||||
@@ -142,7 +142,7 @@ void user_login(struct plugin_handle* plugin, struct plugin_user* user)
|
||||
struct cbuffer* buf = NULL;
|
||||
struct linked_list* found = (struct linked_list*) list_create();
|
||||
|
||||
sql_execute(data, get_messages_callback, found, "SELECT * FROM chat_history ORDER BY time DESC LIMIT 0,%d;", (int) data->history_connect);
|
||||
sql_execute(data, get_messages_callback, found, "SELECT from_nick,message, datetime(time, 'localtime') as time FROM chat_history ORDER BY time DESC LIMIT 0,%d;", (int) data->history_connect);
|
||||
|
||||
if (data->history_connect > 0 && list_size(found) > 0)
|
||||
{
|
||||
@@ -180,7 +180,7 @@ static int command_history(struct plugin_handle* plugin, struct plugin_user* use
|
||||
else
|
||||
maxlines = data->history_default;
|
||||
|
||||
sql_execute(data, get_messages_callback, found, "SELECT * FROM chat_history ORDER BY time DESC LIMIT 0,%d;", maxlines);
|
||||
sql_execute(data, get_messages_callback, found, "SELECT from_nick,message, datetime(time, 'localtime') as time FROM chat_history ORDER BY time DESC LIMIT 0,%d;", maxlines);
|
||||
|
||||
size_t linecount = list_size(found);
|
||||
|
||||
@@ -226,6 +226,8 @@ static int command_historycleanup(struct plugin_handle* plugin, struct plugin_us
|
||||
plugin->hub.send_message(plugin, user, cbuf_get(buf));
|
||||
cbuf_destroy(buf);
|
||||
|
||||
sql_execute(data, null_callback, NULL, "VACUUM;");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ static struct log_data* parse_config(const char* line, struct plugin_handle* plu
|
||||
else if (strcmp(cfg_settings_get_key(setting), "syslog") == 0)
|
||||
{
|
||||
int use_syslog = 0;
|
||||
if (!string_to_boolean(cfg_settings_get_value(setting), &use_syslog))
|
||||
if (string_to_boolean(cfg_settings_get_value(setting), &use_syslog))
|
||||
{
|
||||
data->logmode = (use_syslog) ? mode_syslog : mode_file;
|
||||
}
|
||||
|
||||
41
src/plugins/mod_require_tls.c
Normal file
41
src/plugins/mod_require_tls.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* uhub - A tiny ADC p2p connection hub
|
||||
* Copyright (C) 2007-2018, Jan Vidar Krey
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "plugin_api/handle.h"
|
||||
#include "plugin_api/command_api.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
struct example_plugin_data
|
||||
{
|
||||
struct plugin_command_handle* redirect;
|
||||
};
|
||||
|
||||
|
||||
|
||||
int plugin_register(struct plugin_handle* plugin, const char* config)
|
||||
{
|
||||
PLUGIN_INITIALIZE(plugin, "TLS redirect plugin", "1.0", "A simple redirect to TLS plug-in");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plugin_unregister(struct plugin_handle* plugin)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -197,6 +197,10 @@
|
||||
#define CPUINFO "ARM"
|
||||
#endif
|
||||
|
||||
#if defined(__aarch64__)
|
||||
#define CPUINFO "AArch64"
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__i386) || defined(i386) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__THW_INTEL__)
|
||||
#define CPUINFO "i386"
|
||||
#endif
|
||||
|
||||
@@ -101,7 +101,19 @@ static const char* validate_cred(const char* cred_str)
|
||||
if (!strcmp(cred_str, "user"))
|
||||
return "user";
|
||||
|
||||
fprintf(stderr, "Invalid user credentials. Must be one of: 'admin', 'super', 'op' or 'user'\n");
|
||||
if (!strcmp(cred_str, "bot"))
|
||||
return "bot";
|
||||
|
||||
if (!strcmp(cred_str, "ubot"))
|
||||
return "ubot";
|
||||
|
||||
if (!strcmp(cred_str, "opbot"))
|
||||
return "opbot";
|
||||
|
||||
if (!strcmp(cred_str, "opubot"))
|
||||
return "opubot";
|
||||
|
||||
fprintf(stderr, "Invalid user credentials. Must be one of: 'bot', 'ubot', 'opbot', 'opubot', 'admin', 'super', 'op' or 'user'\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -363,7 +375,7 @@ void main_usage(const char* binary)
|
||||
" 'filename' is a database file\n"
|
||||
" 'username' is a nickname (UTF-8, up to %i bytes)\n"
|
||||
" 'password' is a password (UTF-8, up to %i bytes)\n"
|
||||
" 'credentials' is one of 'admin', 'super', 'op', 'user'\n"
|
||||
" 'credentials' is one of 'bot', 'ubot', 'opbot', 'opubot', 'admin', 'super', 'op' or 'user'\n"
|
||||
"\n"
|
||||
, binary, MAX_NICK_LEN, MAX_PASS_LEN);
|
||||
}
|
||||
@@ -391,5 +403,3 @@ int main(int argc, char** argv)
|
||||
main_usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "uhub.h"
|
||||
|
||||
#define CBUF_FLAG_CONST_BUFFER 0x01
|
||||
#define MAX_MSG_LEN 16384
|
||||
|
||||
struct cbuffer
|
||||
{
|
||||
@@ -86,19 +87,19 @@ void cbuf_append(struct cbuffer* buf, const char* msg)
|
||||
|
||||
void cbuf_append_format(struct cbuffer* buf, const char* format, ...)
|
||||
{
|
||||
static char tmp[1024];
|
||||
static char tmp[MAX_MSG_LEN];
|
||||
va_list args;
|
||||
int bytes;
|
||||
uhub_assert(buf->flags == 0);
|
||||
va_start(args, format);
|
||||
bytes = vsnprintf(tmp, 1024, format, args);
|
||||
bytes = vsnprintf(tmp, sizeof(tmp), format, args);
|
||||
va_end(args);
|
||||
cbuf_append_bytes(buf, tmp, bytes);
|
||||
}
|
||||
|
||||
void cbuf_append_strftime(struct cbuffer* buf, const char* format, const struct tm* tm)
|
||||
{
|
||||
static char tmp[1024];
|
||||
static char tmp[MAX_MSG_LEN];
|
||||
int bytes;
|
||||
uhub_assert(buf->flags == 0);
|
||||
bytes = strftime(tmp, sizeof(tmp), format, tm);
|
||||
|
||||
@@ -19,11 +19,33 @@
|
||||
|
||||
#include "uhub.h"
|
||||
|
||||
/**
|
||||
* Returns 1 if a user is unrestricted.
|
||||
* Unrestricted users override the limits of flood and can send messages in
|
||||
* the name of other users.
|
||||
* This is useful for amongst other external chatrooms.
|
||||
*/
|
||||
int auth_cred_is_unrestricted(enum auth_credentials cred)
|
||||
{
|
||||
switch (cred)
|
||||
{
|
||||
case auth_cred_ubot:
|
||||
case auth_cred_opubot:
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int auth_cred_is_protected(enum auth_credentials cred)
|
||||
{
|
||||
switch (cred)
|
||||
{
|
||||
case auth_cred_bot:
|
||||
case auth_cred_ubot:
|
||||
case auth_cred_opbot:
|
||||
case auth_cred_opubot:
|
||||
case auth_cred_operator:
|
||||
case auth_cred_super:
|
||||
case auth_cred_admin:
|
||||
@@ -45,6 +67,9 @@ int auth_cred_is_registered(enum auth_credentials cred)
|
||||
switch (cred)
|
||||
{
|
||||
case auth_cred_bot:
|
||||
case auth_cred_ubot:
|
||||
case auth_cred_opbot:
|
||||
case auth_cred_opubot:
|
||||
case auth_cred_user:
|
||||
case auth_cred_operator:
|
||||
case auth_cred_super:
|
||||
@@ -64,6 +89,9 @@ const char* auth_cred_to_string(enum auth_credentials cred)
|
||||
{
|
||||
case auth_cred_none: return "none";
|
||||
case auth_cred_bot: return "bot";
|
||||
case auth_cred_ubot: return "ubot";
|
||||
case auth_cred_opbot: return "opbot";
|
||||
case auth_cred_opubot: return "opubot";
|
||||
case auth_cred_guest: return "guest";
|
||||
case auth_cred_user: return "user";
|
||||
case auth_cred_operator: return "operator";
|
||||
@@ -95,14 +123,20 @@ int auth_string_to_cred(const char* str, enum auth_credentials* out)
|
||||
if (!strcasecmp(str, "none")) { *out = auth_cred_none; return 1; }
|
||||
if (!strcasecmp(str, "user")) { *out = auth_cred_user; return 1; }
|
||||
if (!strcasecmp(str, "link")) { *out = auth_cred_link; return 1; }
|
||||
if (!strcasecmp(str, "ubot")) { *out = auth_cred_ubot; return 1; }
|
||||
return 0;
|
||||
|
||||
case 5:
|
||||
if (!strcasecmp(str, "admin")) { *out = auth_cred_admin; return 1; }
|
||||
if (!strcasecmp(str, "super")) { *out = auth_cred_super; return 1; }
|
||||
if (!strcasecmp(str, "opbot")) { *out = auth_cred_opbot; return 1; }
|
||||
if (!strcasecmp(str, "guest")) { *out = auth_cred_guest; return 1; }
|
||||
return 0;
|
||||
|
||||
case 6:
|
||||
if (!strcasecmp(str, "opubot")) { *out = auth_cred_opubot; return 1; }
|
||||
return 0;
|
||||
|
||||
case 8:
|
||||
if (!strcasecmp(str, "operator")) { *out = auth_cred_operator; return 1; }
|
||||
return 0;
|
||||
|
||||
@@ -23,15 +23,24 @@
|
||||
enum auth_credentials
|
||||
{
|
||||
auth_cred_none, /**<<< "User has no credentials (not yet logged in)" */
|
||||
auth_cred_bot, /**<<< "User is a robot" */
|
||||
auth_cred_guest, /**<<< "User is a guest (unregistered user)" */
|
||||
auth_cred_user, /**<<< "User is identified as a registered user" */
|
||||
auth_cred_bot, /**<<< "User is a robot" */
|
||||
auth_cred_ubot, /**<<< "User is an unrestricted robot" */
|
||||
auth_cred_operator, /**<<< "User is identified as a hub operator" */
|
||||
auth_cred_opbot, /**<<< "User is a operator robot" */
|
||||
auth_cred_opubot, /**<<< "User is an unrestricted operator robot" */
|
||||
auth_cred_super, /**<<< "User is a super user" (not used) */
|
||||
auth_cred_link, /**<<< "User is a link (not used currently)" */
|
||||
auth_cred_admin, /**<<< "User is identified as a hub administrator/owner" */
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns 1 if the credentials means that a user is unrestricted.
|
||||
* Returns 0 otherwise.
|
||||
*/
|
||||
int auth_cred_is_unrestricted(enum auth_credentials cred);
|
||||
|
||||
/**
|
||||
* Returns 1 if the credentials means that a user is protected.
|
||||
* Returns 0 otherwise.
|
||||
|
||||
@@ -63,7 +63,7 @@ char* strip_white_space(char* string)
|
||||
return string;
|
||||
}
|
||||
|
||||
static int is_valid_utf8_str(const char* string, size_t length)
|
||||
static int is_valid_utf8_str(const unsigned char* string, size_t length)
|
||||
{
|
||||
int expect = 0;
|
||||
char div = 0;
|
||||
@@ -82,12 +82,32 @@ static int is_valid_utf8_str(const char* string, size_t length)
|
||||
{
|
||||
if (string[pos] & 0x80)
|
||||
{
|
||||
for (div = 0x40; div > 0x10; div /= 2)
|
||||
for (div = 0x40; div > 0x08; div /= 2)
|
||||
{
|
||||
if (string[pos] & div) expect++;
|
||||
else break;
|
||||
}
|
||||
if ((string[pos] & div) || (pos+expect >= length)) return 0;
|
||||
switch (expect) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
/* Out of range */
|
||||
if (string[pos] < 0xC2) return 0;
|
||||
break;
|
||||
case 2:
|
||||
/* Out of range */
|
||||
if ((string[pos] == 0xE0) && (string[pos+1] < 0xA0 )) return 0;
|
||||
/* Surrogates */
|
||||
if ((string[pos] == 0xED) && (string[pos+1] > 0x9F )) return 0;
|
||||
break;
|
||||
case 3:
|
||||
/* Out of range */
|
||||
if ((string[pos] == 0xF0) && (string[pos+1] < 0x90 )) return 0;
|
||||
if (string[pos] > 0xF4) return 0;
|
||||
if ((string[pos] == 0xF4) && (string[pos+1] > 0x8F )) return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
114
tools/fh2uh_regimport.pl
Normal file
114
tools/fh2uh_regimport.pl
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# A simple tool for importing FlexHub users to uhub sqlite database
|
||||
#
|
||||
# Usage: ./fh2uh_regimport.pl <flexhub_userlist> <uhub_database>
|
||||
#
|
||||
# Note: uhub database has to be created before running this script.
|
||||
|
||||
use File::Slurp;
|
||||
use Data::Dumper;
|
||||
use DBI;
|
||||
|
||||
my @uhubaccounts;
|
||||
my $text = read_file $ARGV[0];
|
||||
my $dbfile = $ARGV[1];
|
||||
|
||||
sub convertprofile
|
||||
{
|
||||
$flexprofile = $_[0];
|
||||
if($flexprofile >= 0 && $flexprofile <= 3)
|
||||
{
|
||||
return 'user';
|
||||
}
|
||||
elsif($flexprofile >= 4 && $flexprofile <= 6)
|
||||
{
|
||||
return 'operator';
|
||||
}
|
||||
elsif($flexprofile >= 7 && $flexprofile <= 8)
|
||||
{
|
||||
return 'super';
|
||||
}
|
||||
elsif($flexprofile >= 9 && $flexprofile <= 10)
|
||||
{
|
||||
return 'admin';
|
||||
}
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
sub parseinfo
|
||||
{
|
||||
my @info = split('\n', $_[0]);
|
||||
|
||||
for my $line (@info)
|
||||
{
|
||||
chop $line;
|
||||
my %reginfo;
|
||||
if ($line =~ /\["sNick"\]\s*=\s*\S+/)
|
||||
{
|
||||
my @nick = split(/\["sNick"\]\s*=\s*"(\S+)"/, $line);
|
||||
$reginfo->{'nickname'} = $nick[1];
|
||||
}
|
||||
elsif ($line =~ /\["sPassword"\]\s*=\s*\S+/)
|
||||
{
|
||||
my @password = split(/\["sPassword"\]\s*=\s*"(\S+)"/, $line);
|
||||
$reginfo->{'password'} = $password[1];
|
||||
}
|
||||
elsif ($line =~ /\["iLevel"\]\s*=\s*\S+/)
|
||||
{
|
||||
my @level = split(/\["iLevel"\]\s*=\s*(\d+)/, $line);
|
||||
$reginfo->{'credentials'} = convertprofile $level[1];
|
||||
}
|
||||
elsif ($line =~ /\["iRegDate"\]\s*=\s*\S+/)
|
||||
{
|
||||
my @created = split(/\["iRegDate"\]\s*=\s*(\d+)/, $line);
|
||||
$reginfo->{'created'} = $created[1];
|
||||
}
|
||||
elsif ($line =~ /\["iLastLogin"\]\s*=\s*\S+/)
|
||||
{
|
||||
my @activity = split(/\["iLastLogin"\]\s*=\s*(\d+)/, $line);
|
||||
$reginfo->{'activity'} = $activity[1];
|
||||
}
|
||||
}
|
||||
|
||||
return %{$reginfo};
|
||||
}
|
||||
|
||||
sub dbimport
|
||||
{
|
||||
my @arr = @_;
|
||||
my $db = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "", {RaiseError => 1, AutoCommit => 1});
|
||||
|
||||
for my $import (@arr)
|
||||
{
|
||||
if ($import->{'credentials'} ne 'unknown')
|
||||
{
|
||||
$db->do("INSERT OR IGNORE INTO users (nickname,password,credentials,created,activity) VALUES('$import->{'nickname'}','$import->{'password'}','$import->{'credentials'}',datetime($import->{'created'}, 'unixepoch'),datetime($import->{'activity'}, 'unixepoch'));");
|
||||
}
|
||||
}
|
||||
|
||||
$db->disconnect();
|
||||
}
|
||||
|
||||
|
||||
if ($text =~ /tAccounts = {/)
|
||||
{
|
||||
$text =~ s/^(?:.*\n){1}/},\n/;
|
||||
my @flexaccounts = split('},.*\n.*\[".+"\] = {', $text);
|
||||
|
||||
shift(@flexaccounts);
|
||||
|
||||
for my $account (@flexaccounts)
|
||||
{
|
||||
my %info = parseinfo $account;
|
||||
push(@uhubaccounts, \%info);
|
||||
}
|
||||
|
||||
dbimport @uhubaccounts;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Provided file is not valid FlexHub userlist.\n";
|
||||
}
|
||||
62
tools/px2uh_regimport.pl
Normal file
62
tools/px2uh_regimport.pl
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# A simple tool for importing PtokaX (< 0.5.0.0) users to uhub sqlite database.
|
||||
# Userlist MUST be in xml format.
|
||||
#
|
||||
# Usage: ./px2uh_regimport.pl <ptokax_userlist.xml> <uhub_database.db>
|
||||
#
|
||||
# Note: uhub database has to be created before running this script.
|
||||
|
||||
use XML::Simple;
|
||||
use DBI;
|
||||
|
||||
# create xml object
|
||||
my $xml = new XML::Simple;
|
||||
|
||||
# read XML file
|
||||
my $regdata = $xml->XMLin($ARGV[0], ForceArray => [ 'RegisteredUser' ]);
|
||||
|
||||
my $dbfile = $ARGV[1];
|
||||
my @pxaccounts = @{$regdata->{'RegisteredUser'}};
|
||||
|
||||
sub convertprofile
|
||||
{
|
||||
$pxprofile = $_[0];
|
||||
if($pxprofile == 2 || $pxprofile == 3)
|
||||
{
|
||||
return 'user';
|
||||
}
|
||||
elsif($pxprofile == 1)
|
||||
{
|
||||
return 'operator';
|
||||
}
|
||||
elsif($pxprofile == 0)
|
||||
{
|
||||
return 'admin';
|
||||
}
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
sub dbimport
|
||||
{
|
||||
my @arr = @_;
|
||||
my $db = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "", {RaiseError => 1, AutoCommit => 1});
|
||||
|
||||
for my $import (@arr)
|
||||
{
|
||||
if ($import->{'credentials'} ne 'unknown')
|
||||
{
|
||||
$db->do("INSERT OR IGNORE INTO users (nickname,password,credentials) VALUES('$import->{'Nick'}','$import->{'Password'}','$import->{'credentials'}');");
|
||||
}
|
||||
}
|
||||
|
||||
$db->disconnect();
|
||||
}
|
||||
|
||||
for my $account (@pxaccounts)
|
||||
{
|
||||
$account->{'credentials'} = convertprofile $account->{'Profile'};
|
||||
}
|
||||
|
||||
dbimport @pxaccounts;
|
||||
Reference in New Issue
Block a user