Merge pull request 'formated code' (#13) from formated-code into main
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/openrouter/pulls/13
This commit was merged in pull request #13.
This commit is contained in:
commit
c86d4d77ba
40 files changed
+23482
-22584
No files matched your search
@@ -0,0 +1,46 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
tab_width = 8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[DEVELOPERS]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[Config*.in*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[linux/Config.ext.in]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[Makefile*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[*.mk]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[*.patch]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[S{0..9}{0..9}*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[*.adoc]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
|
||||||
|
|
||||||
|
cpp_indent_case_contents_when_block = true
|
||||||
|
cpp_new_line_before_open_brace_namespace = new_line
|
||||||
|
cpp_new_line_before_open_brace_function = new_line
|
||||||
@@ -1,13 +1,37 @@
|
|||||||
CXX=g++
|
CXX=g++
|
||||||
STRIP=strip
|
STRIP=strip
|
||||||
CXXFLAGS=-Wall -I src/libs -I src -std=c++20
|
CXXFLAGS=-Wall -I src/libs -I src -std=c++20
|
||||||
SOURCES=src/openrouter.cpp src/security/cors.cpp src/settings/telnet/enabled.cpp src/settings/telnet/port.cpp src/settings/ssh/status.cpp src/settings/ssh/keys.cpp src/settings/ssh/port.cpp src/settings/ssh/server.cpp src/settings/dns/enabled.cpp src/settings/dns/servers.cpp src/settings/dns/local_domains.cpp src/settings/wifi/status.cpp src/settings/wifi/name.cpp src/settings/wifi/password.cpp src/settings/wifi/qr.cpp src/settings/wifi/channel.cpp src/settings/ftp/ftp.cpp src/system/reboot/reboot.cpp src/system/syslog/syslog.cpp src/system/uptime/uptime.cpp src/OpenRouter/OpenRouter.cpp src/auth/auth.cpp src/libs/QR-Code-generator/qrcodegen.cpp src/libs/QR-Code-generator/qrtosvg.cpp
|
SOURCES=src/openrouter.cpp \
|
||||||
TARGET=bin/openrouter
|
src/security/cors.cpp \
|
||||||
|
src/settings/telnet/enabled.cpp \
|
||||||
|
src/settings/telnet/port.cpp \
|
||||||
|
src/settings/ssh/status.cpp \
|
||||||
|
src/settings/ssh/keys.cpp \
|
||||||
|
src/settings/ssh/port.cpp \
|
||||||
|
src/settings/ssh/server.cpp \
|
||||||
|
src/settings/dns/enabled.cpp \
|
||||||
|
src/settings/dns/servers.cpp \
|
||||||
|
src/settings/dns/local_domains.cpp \
|
||||||
|
src/settings/wifi/status.cpp \
|
||||||
|
src/settings/wifi/name.cpp \
|
||||||
|
src/settings/wifi/password.cpp \
|
||||||
|
src/settings/wifi/qr.cpp \
|
||||||
|
src/settings/wifi/channel.cpp \
|
||||||
|
src/settings/ftp/ftp.cpp \
|
||||||
|
src/system/reboot/reboot.cpp \
|
||||||
|
src/system/syslog/syslog.cpp \
|
||||||
|
src/system/uptime/uptime.cpp \
|
||||||
|
src/OpenRouter/OpenRouter.cpp \
|
||||||
|
src/auth/auth.cpp \
|
||||||
|
src/libs/QR-Code-generator/qrcodegen.cpp \
|
||||||
|
src/libs/QR-Code-generator/qrtosvg.cpp
|
||||||
|
TARGET=build/openrouter
|
||||||
default: all
|
default: all
|
||||||
all: build
|
all: build
|
||||||
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
@if [ ! -d bin ]; then \
|
@if [ ! -d build ]; then \
|
||||||
mkdir bin; \
|
mkdir build; \
|
||||||
fi
|
fi
|
||||||
$(CXX) -o $(TARGET) $(SOURCES) $(CXXFLAGS)
|
$(CXX) -o $(TARGET) $(SOURCES) $(CXXFLAGS)
|
||||||
$(STRIP) $(TARGET)
|
$(STRIP) $(TARGET)
|
||||||
|
|||||||
+29
-34
@@ -1,44 +1,39 @@
|
|||||||
project('openrouter', 'cpp', default_options : ['cpp_std=c++20', 'cpp_args=-Wall'])
|
project('openrouter', 'cpp', default_options: ['cpp_std=c++20', 'cpp_args=-Wall'])
|
||||||
include_dirs = include_directories('src', 'src/libs')
|
include_dirs = include_directories('src', 'src/libs')
|
||||||
executable(
|
executable(
|
||||||
'openrouter',
|
'openrouter',
|
||||||
'src/openrouter.cpp',
|
'src/openrouter.cpp',
|
||||||
'src/security/cors.cpp',
|
'src/security/cors.cpp',
|
||||||
|
|
||||||
'src/settings/telnet/enabled.cpp',
|
'src/settings/telnet/enabled.cpp',
|
||||||
'src/settings/telnet/port.cpp',
|
'src/settings/telnet/port.cpp',
|
||||||
|
|
||||||
'src/settings/ssh/status.cpp',
|
'src/settings/ssh/status.cpp',
|
||||||
'src/settings/ssh/keys.cpp',
|
'src/settings/ssh/keys.cpp',
|
||||||
'src/settings/ssh/port.cpp',
|
'src/settings/ssh/port.cpp',
|
||||||
'src/settings/ssh/server.cpp',
|
'src/settings/ssh/server.cpp',
|
||||||
|
|
||||||
'src/settings/dns/enabled.cpp',
|
'src/settings/dns/enabled.cpp',
|
||||||
'src/settings/dns/servers.cpp',
|
'src/settings/dns/servers.cpp',
|
||||||
'src/settings/dns/local_domains.cpp',
|
'src/settings/dns/local_domains.cpp',
|
||||||
|
|
||||||
'src/settings/wifi/status.cpp',
|
'src/settings/wifi/status.cpp',
|
||||||
'src/settings/wifi/name.cpp',
|
'src/settings/wifi/name.cpp',
|
||||||
'src/settings/wifi/password.cpp',
|
'src/settings/wifi/password.cpp',
|
||||||
'src/settings/wifi/qr.cpp',
|
'src/settings/wifi/qr.cpp',
|
||||||
'src/settings/wifi/channel.cpp',
|
'src/settings/wifi/channel.cpp',
|
||||||
|
|
||||||
'src/settings/ftp/ftp.cpp',
|
'src/settings/ftp/ftp.cpp',
|
||||||
|
|
||||||
'src/system/reboot/reboot.cpp',
|
'src/system/reboot/reboot.cpp',
|
||||||
'src/system/syslog/syslog.cpp',
|
'src/system/syslog/syslog.cpp',
|
||||||
'src/system/uptime/uptime.cpp',
|
'src/system/uptime/uptime.cpp',
|
||||||
'src/OpenRouter/OpenRouter.cpp',
|
'src/OpenRouter/OpenRouter.cpp',
|
||||||
'src/auth/auth.cpp',
|
'src/auth/auth.cpp',
|
||||||
'src/libs/QR-Code-generator/qrcodegen.cpp',
|
'src/libs/QR-Code-generator/qrcodegen.cpp',
|
||||||
'src/libs/QR-Code-generator/qrtosvg.cpp',
|
'src/libs/QR-Code-generator/qrtosvg.cpp',
|
||||||
include_directories: include_dirs,
|
include_directories: include_dirs,
|
||||||
install: true
|
install: true,
|
||||||
)
|
)
|
||||||
|
|
||||||
install_subdir(
|
install_subdir('src/web', install_dir: 'share/openrouter')
|
||||||
'src/web',
|
|
||||||
install_dir: 'share/openrouter'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@@ -58,10 +58,10 @@ OpenRouter::OpenRouter()
|
|||||||
|
|
||||||
OpenRouter::~OpenRouter() = default;
|
OpenRouter::~OpenRouter() = default;
|
||||||
|
|
||||||
int OpenRouter::serve(const std::string &ip, int port, int socket_flags)
|
int OpenRouter::serve(const std::string& ip, int port, int socket_flags)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
||||||
<< "0.0.0.0" << RESET << ":" << CYAN << "43244" << RESET << " ]" << std::endl;
|
<< "0.0.0.0" << RESET << ":" << CYAN << "43244" << RESET << " ]" << std::endl;
|
||||||
|
|
||||||
syslog(LOG_INFO, "openrouter administration software started.");
|
syslog(LOG_INFO, "openrouter administration software started.");
|
||||||
this->srv.listen(ip, port, socket_flags);
|
this->srv.listen(ip, port, socket_flags);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
OpenRouter();
|
OpenRouter();
|
||||||
~OpenRouter();
|
~OpenRouter();
|
||||||
int serve(const std::string &ip, int port, int socket_flags = 0);
|
int serve(const std::string& ip, int port, int socket_flags = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OPENROUTER_HPP
|
#endif // OPENROUTER_HPP
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
|
|
||||||
static bool check_body(const httplib::Request &request)
|
static bool check_body(const httplib::Request& request)
|
||||||
{
|
{
|
||||||
if (request.body.empty())
|
if (request.body.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -30,520 +30,521 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace qrcodegen {
|
namespace qrcodegen
|
||||||
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A segment of character/binary/control data in a QR Code symbol.
|
* A segment of character/binary/control data in a QR Code symbol.
|
||||||
* Instances of this class are immutable.
|
* Instances of this class are immutable.
|
||||||
* The mid-level way to create a segment is to take the payload data
|
* The mid-level way to create a segment is to take the payload data
|
||||||
* and call a static factory function such as QrSegment::makeNumeric().
|
* and call a static factory function such as QrSegment::makeNumeric().
|
||||||
* The low-level way to create a segment is to custom-make the bit buffer
|
* The low-level way to create a segment is to custom-make the bit buffer
|
||||||
* and call the QrSegment() constructor with appropriate values.
|
* and call the QrSegment() constructor with appropriate values.
|
||||||
* This segment class imposes no length restrictions, but QR Codes have restrictions.
|
* This segment class imposes no length restrictions, but QR Codes have restrictions.
|
||||||
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
|
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
|
||||||
* Any segment longer than this is meaningless for the purpose of generating QR Codes.
|
* Any segment longer than this is meaningless for the purpose of generating QR Codes.
|
||||||
*/
|
*/
|
||||||
class QrSegment final {
|
class QrSegment final {
|
||||||
|
|
||||||
/*---- Public helper enumeration ----*/
|
/*---- Public helper enumeration ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Describes how a segment's data bits are interpreted. Immutable.
|
* Describes how a segment's data bits are interpreted. Immutable.
|
||||||
*/
|
*/
|
||||||
public: class Mode final {
|
public: class Mode final {
|
||||||
|
|
||||||
/*-- Constants --*/
|
/*-- Constants --*/
|
||||||
|
|
||||||
public: static const Mode NUMERIC;
|
public: static const Mode NUMERIC;
|
||||||
public: static const Mode ALPHANUMERIC;
|
public: static const Mode ALPHANUMERIC;
|
||||||
public: static const Mode BYTE;
|
public: static const Mode BYTE;
|
||||||
public: static const Mode KANJI;
|
public: static const Mode KANJI;
|
||||||
public: static const Mode ECI;
|
public: static const Mode ECI;
|
||||||
|
|
||||||
|
|
||||||
/*-- Fields --*/
|
/*-- Fields --*/
|
||||||
|
|
||||||
// The mode indicator bits, which is a uint4 value (range 0 to 15).
|
// The mode indicator bits, which is a uint4 value (range 0 to 15).
|
||||||
private: int modeBits;
|
private: int modeBits;
|
||||||
|
|
||||||
// Number of character count bits for three different version ranges.
|
// Number of character count bits for three different version ranges.
|
||||||
private: int numBitsCharCount[3];
|
private: int numBitsCharCount[3];
|
||||||
|
|
||||||
|
|
||||||
/*-- Constructor --*/
|
/*-- Constructor --*/
|
||||||
|
|
||||||
private: Mode(int mode, int cc0, int cc1, int cc2);
|
private: Mode(int mode, int cc0, int cc1, int cc2);
|
||||||
|
|
||||||
|
|
||||||
/*-- Methods --*/
|
/*-- Methods --*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (Package-private) Returns the mode indicator bits, which is an unsigned 4-bit value (range 0 to 15).
|
* (Package-private) Returns the mode indicator bits, which is an unsigned 4-bit value (range 0 to 15).
|
||||||
*/
|
*/
|
||||||
public: int getModeBits() const;
|
public: int getModeBits() const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (Package-private) Returns the bit width of the character count field for a segment in
|
* (Package-private) Returns the bit width of the character count field for a segment in
|
||||||
* this mode in a QR Code at the given version number. The result is in the range [0, 16].
|
* this mode in a QR Code at the given version number. The result is in the range [0, 16].
|
||||||
*/
|
*/
|
||||||
public: int numCharCountBits(int ver) const;
|
public: int numCharCountBits(int ver) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Static factory functions (mid level) ----*/
|
/*---- Static factory functions (mid level) ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a segment representing the given binary data encoded in
|
* Returns a segment representing the given binary data encoded in
|
||||||
* byte mode. All input byte vectors are acceptable. Any text string
|
* byte mode. All input byte vectors are acceptable. Any text string
|
||||||
* can be converted to UTF-8 bytes and encoded as a byte mode segment.
|
* can be converted to UTF-8 bytes and encoded as a byte mode segment.
|
||||||
*/
|
*/
|
||||||
public: static QrSegment makeBytes(const std::vector<std::uint8_t> &data);
|
public: static QrSegment makeBytes(const std::vector<std::uint8_t>& data);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
* Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
||||||
*/
|
*/
|
||||||
public: static QrSegment makeNumeric(const char *digits);
|
public: static QrSegment makeNumeric(const char* digits);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a segment representing the given text string encoded in alphanumeric mode.
|
* Returns a segment representing the given text string encoded in alphanumeric mode.
|
||||||
* The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
* The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
||||||
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
||||||
*/
|
*/
|
||||||
public: static QrSegment makeAlphanumeric(const char *text);
|
public: static QrSegment makeAlphanumeric(const char* text);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a list of zero or more segments to represent the given text string. The result
|
* Returns a list of zero or more segments to represent the given text string. The result
|
||||||
* may use various segment modes and switch modes to optimize the length of the bit stream.
|
* may use various segment modes and switch modes to optimize the length of the bit stream.
|
||||||
*/
|
*/
|
||||||
public: static std::vector<QrSegment> makeSegments(const char *text);
|
public: static std::vector<QrSegment> makeSegments(const char* text);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a segment representing an Extended Channel Interpretation
|
* Returns a segment representing an Extended Channel Interpretation
|
||||||
* (ECI) designator with the given assignment value.
|
* (ECI) designator with the given assignment value.
|
||||||
*/
|
*/
|
||||||
public: static QrSegment makeEci(long assignVal);
|
public: static QrSegment makeEci(long assignVal);
|
||||||
|
|
||||||
|
|
||||||
/*---- Public static helper functions ----*/
|
/*---- Public static helper functions ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tests whether the given string can be encoded as a segment in numeric mode.
|
* Tests whether the given string can be encoded as a segment in numeric mode.
|
||||||
* A string is encodable iff each character is in the range 0 to 9.
|
* A string is encodable iff each character is in the range 0 to 9.
|
||||||
*/
|
*/
|
||||||
public: static bool isNumeric(const char *text);
|
public: static bool isNumeric(const char* text);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
* Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
||||||
* A string is encodable iff each character is in the following set: 0 to 9, A to Z
|
* A string is encodable iff each character is in the following set: 0 to 9, A to Z
|
||||||
* (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
* (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
||||||
*/
|
*/
|
||||||
public: static bool isAlphanumeric(const char *text);
|
public: static bool isAlphanumeric(const char* text);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Instance fields ----*/
|
/*---- Instance fields ----*/
|
||||||
|
|
||||||
/* The mode indicator of this segment. Accessed through getMode(). */
|
/* The mode indicator of this segment. Accessed through getMode(). */
|
||||||
private: const Mode *mode;
|
private: const Mode* mode;
|
||||||
|
|
||||||
/* The length of this segment's unencoded data. Measured in characters for
|
/* The length of this segment's unencoded data. Measured in characters for
|
||||||
* numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
|
* numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
|
||||||
* Always zero or positive. Not the same as the data's bit length.
|
* Always zero or positive. Not the same as the data's bit length.
|
||||||
* Accessed through getNumChars(). */
|
* Accessed through getNumChars(). */
|
||||||
private: int numChars;
|
private: int numChars;
|
||||||
|
|
||||||
/* The data bits of this segment. Accessed through getData(). */
|
/* The data bits of this segment. Accessed through getData(). */
|
||||||
private: std::vector<bool> data;
|
private: std::vector<bool> data;
|
||||||
|
|
||||||
|
|
||||||
/*---- Constructors (low level) ----*/
|
/*---- Constructors (low level) ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a new QR Code segment with the given attributes and data.
|
* Creates a new QR Code segment with the given attributes and data.
|
||||||
* The character count (numCh) must agree with the mode and the bit buffer length,
|
* The character count (numCh) must agree with the mode and the bit buffer length,
|
||||||
* but the constraint isn't checked. The given bit buffer is copied and stored.
|
* but the constraint isn't checked. The given bit buffer is copied and stored.
|
||||||
*/
|
*/
|
||||||
public: QrSegment(const Mode &md, int numCh, const std::vector<bool> &dt);
|
public: QrSegment(const Mode& md, int numCh, const std::vector<bool>& dt);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a new QR Code segment with the given parameters and data.
|
* Creates a new QR Code segment with the given parameters and data.
|
||||||
* The character count (numCh) must agree with the mode and the bit buffer length,
|
* The character count (numCh) must agree with the mode and the bit buffer length,
|
||||||
* but the constraint isn't checked. The given bit buffer is moved and stored.
|
* but the constraint isn't checked. The given bit buffer is moved and stored.
|
||||||
*/
|
*/
|
||||||
public: QrSegment(const Mode &md, int numCh, std::vector<bool> &&dt);
|
public: QrSegment(const Mode& md, int numCh, std::vector<bool>&& dt);
|
||||||
|
|
||||||
|
|
||||||
/*---- Methods ----*/
|
/*---- Methods ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the mode field of this segment.
|
* Returns the mode field of this segment.
|
||||||
*/
|
*/
|
||||||
public: const Mode &getMode() const;
|
public: const Mode& getMode() const;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the character count field of this segment.
|
* Returns the character count field of this segment.
|
||||||
*/
|
*/
|
||||||
public: int getNumChars() const;
|
public: int getNumChars() const;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the data bits of this segment.
|
* Returns the data bits of this segment.
|
||||||
*/
|
*/
|
||||||
public: const std::vector<bool> &getData() const;
|
public: const std::vector<bool>& getData() const;
|
||||||
|
|
||||||
|
|
||||||
// (Package-private) Calculates the number of bits needed to encode the given segments at
|
// (Package-private) Calculates the number of bits needed to encode the given segments at
|
||||||
// the given version. Returns a non-negative number if successful. Otherwise returns -1 if a
|
// the given version. Returns a non-negative number if successful. Otherwise returns -1 if a
|
||||||
// segment has too many characters to fit its length field, or the total bits exceeds INT_MAX.
|
// segment has too many characters to fit its length field, or the total bits exceeds INT_MAX.
|
||||||
public: static int getTotalBits(const std::vector<QrSegment> &segs, int version);
|
public: static int getTotalBits(const std::vector<QrSegment>& segs, int version);
|
||||||
|
|
||||||
|
|
||||||
/*---- Private constant ----*/
|
/*---- Private constant ----*/
|
||||||
|
|
||||||
/* The set of all legal characters in alphanumeric mode, where
|
/* The set of all legal characters in alphanumeric mode, where
|
||||||
* each character value maps to the index in the string. */
|
* each character value maps to the index in the string. */
|
||||||
private: static const char *ALPHANUMERIC_CHARSET;
|
private: static const char* ALPHANUMERIC_CHARSET;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A QR Code symbol, which is a type of two-dimension barcode.
|
* A QR Code symbol, which is a type of two-dimension barcode.
|
||||||
* Invented by Denso Wave and described in the ISO/IEC 18004 standard.
|
* Invented by Denso Wave and described in the ISO/IEC 18004 standard.
|
||||||
* Instances of this class represent an immutable square grid of dark and light cells.
|
* Instances of this class represent an immutable square grid of dark and light cells.
|
||||||
* The class provides static factory functions to create a QR Code from text or binary data.
|
* The class provides static factory functions to create a QR Code from text or binary data.
|
||||||
* The class covers the QR Code Model 2 specification, supporting all versions (sizes)
|
* The class covers the QR Code Model 2 specification, supporting all versions (sizes)
|
||||||
* from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
|
* from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
|
||||||
*
|
*
|
||||||
* Ways to create a QR Code object:
|
* Ways to create a QR Code object:
|
||||||
* - High level: Take the payload data and call QrCode::encodeText() or QrCode::encodeBinary().
|
* - High level: Take the payload data and call QrCode::encodeText() or QrCode::encodeBinary().
|
||||||
* - Mid level: Custom-make the list of segments and call QrCode::encodeSegments().
|
* - Mid level: Custom-make the list of segments and call QrCode::encodeSegments().
|
||||||
* - Low level: Custom-make the array of data codeword bytes (including
|
* - Low level: Custom-make the array of data codeword bytes (including
|
||||||
* segment headers and final padding, excluding error correction codewords),
|
* segment headers and final padding, excluding error correction codewords),
|
||||||
* supply the appropriate version number, and call the QrCode() constructor.
|
* supply the appropriate version number, and call the QrCode() constructor.
|
||||||
* (Note that all ways require supplying the desired error correction level.)
|
* (Note that all ways require supplying the desired error correction level.)
|
||||||
*/
|
*/
|
||||||
class QrCode final {
|
class QrCode final {
|
||||||
|
|
||||||
/*---- Public helper enumeration ----*/
|
/*---- Public helper enumeration ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The error correction level in a QR Code symbol.
|
* The error correction level in a QR Code symbol.
|
||||||
*/
|
*/
|
||||||
public: enum class Ecc {
|
public: enum class Ecc {
|
||||||
LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords
|
LOW = 0, // The QR Code can tolerate about 7% erroneous codewords
|
||||||
MEDIUM , // The QR Code can tolerate about 15% erroneous codewords
|
MEDIUM, // The QR Code can tolerate about 15% erroneous codewords
|
||||||
QUARTILE, // The QR Code can tolerate about 25% erroneous codewords
|
QUARTILE, // The QR Code can tolerate about 25% erroneous codewords
|
||||||
HIGH , // The QR Code can tolerate about 30% erroneous codewords
|
HIGH, // The QR Code can tolerate about 30% erroneous codewords
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Returns a value in the range 0 to 3 (unsigned 2-bit integer).
|
// Returns a value in the range 0 to 3 (unsigned 2-bit integer).
|
||||||
private: static int getFormatBits(Ecc ecl);
|
private: static int getFormatBits(Ecc ecl);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Static factory functions (high level) ----*/
|
/*---- Static factory functions (high level) ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a QR Code representing the given Unicode text string at the given error correction level.
|
* Returns a QR Code representing the given Unicode text string at the given error correction level.
|
||||||
* As a conservative upper bound, this function is guaranteed to succeed for strings that have 2953 or fewer
|
* As a conservative upper bound, this function is guaranteed to succeed for strings that have 2953 or fewer
|
||||||
* UTF-8 code units (not Unicode code points) if the low error correction level is used. The smallest possible
|
* UTF-8 code units (not Unicode code points) if the low error correction level is used. The smallest possible
|
||||||
* QR Code version is automatically chosen for the output. The ECC level of the result may be higher than
|
* QR Code version is automatically chosen for the output. The ECC level of the result may be higher than
|
||||||
* the ecl argument if it can be done without increasing the version.
|
* the ecl argument if it can be done without increasing the version.
|
||||||
*/
|
*/
|
||||||
public: static QrCode encodeText(const char *text, Ecc ecl);
|
public: static QrCode encodeText(const char* text, Ecc ecl);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a QR Code representing the given binary data at the given error correction level.
|
* Returns a QR Code representing the given binary data at the given error correction level.
|
||||||
* This function always encodes using the binary segment mode, not any text mode. The maximum number of
|
* This function always encodes using the binary segment mode, not any text mode. The maximum number of
|
||||||
* bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
|
* bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
|
||||||
* The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
|
* The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
|
||||||
*/
|
*/
|
||||||
public: static QrCode encodeBinary(const std::vector<std::uint8_t> &data, Ecc ecl);
|
public: static QrCode encodeBinary(const std::vector<std::uint8_t>& data, Ecc ecl);
|
||||||
|
|
||||||
|
|
||||||
/*---- Static factory functions (mid level) ----*/
|
/*---- Static factory functions (mid level) ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a QR Code representing the given segments with the given encoding parameters.
|
* Returns a QR Code representing the given segments with the given encoding parameters.
|
||||||
* The smallest possible QR Code version within the given range is automatically
|
* The smallest possible QR Code version within the given range is automatically
|
||||||
* chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
* chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
||||||
* may be higher than the ecl argument if it can be done without increasing the
|
* may be higher than the ecl argument if it can be done without increasing the
|
||||||
* version. The mask number is either between 0 to 7 (inclusive) to force that
|
* version. The mask number is either between 0 to 7 (inclusive) to force that
|
||||||
* mask, or -1 to automatically choose an appropriate mask (which may be slow).
|
* mask, or -1 to automatically choose an appropriate mask (which may be slow).
|
||||||
* This function allows the user to create a custom sequence of segments that switches
|
* This function allows the user to create a custom sequence of segments that switches
|
||||||
* between modes (such as alphanumeric and byte) to encode text in less space.
|
* between modes (such as alphanumeric and byte) to encode text in less space.
|
||||||
* This is a mid-level API; the high-level API is encodeText() and encodeBinary().
|
* This is a mid-level API; the high-level API is encodeText() and encodeBinary().
|
||||||
*/
|
*/
|
||||||
public: static QrCode encodeSegments(const std::vector<QrSegment> &segs, Ecc ecl,
|
public: static QrCode encodeSegments(const std::vector<QrSegment>& segs, Ecc ecl,
|
||||||
int minVersion=1, int maxVersion=40, int mask=-1, bool boostEcl=true); // All optional parameters
|
int minVersion = 1, int maxVersion = 40, int mask = -1, bool boostEcl = true); // All optional parameters
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Instance fields ----*/
|
/*---- Instance fields ----*/
|
||||||
|
|
||||||
// Immutable scalar parameters:
|
// Immutable scalar parameters:
|
||||||
|
|
||||||
/* The version number of this QR Code, which is between 1 and 40 (inclusive).
|
/* The version number of this QR Code, which is between 1 and 40 (inclusive).
|
||||||
* This determines the size of this barcode. */
|
* This determines the size of this barcode. */
|
||||||
private: int version;
|
private: int version;
|
||||||
|
|
||||||
/* The width and height of this QR Code, measured in modules, between
|
/* The width and height of this QR Code, measured in modules, between
|
||||||
* 21 and 177 (inclusive). This is equal to version * 4 + 17. */
|
* 21 and 177 (inclusive). This is equal to version * 4 + 17. */
|
||||||
private: int size;
|
private: int size;
|
||||||
|
|
||||||
/* The error correction level used in this QR Code. */
|
/* The error correction level used in this QR Code. */
|
||||||
private: Ecc errorCorrectionLevel;
|
private: Ecc errorCorrectionLevel;
|
||||||
|
|
||||||
/* The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
|
/* The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
|
||||||
* Even if a QR Code is created with automatic masking requested (mask = -1),
|
* Even if a QR Code is created with automatic masking requested (mask = -1),
|
||||||
* the resulting object still has a mask value between 0 and 7. */
|
* the resulting object still has a mask value between 0 and 7. */
|
||||||
private: int mask;
|
private: int mask;
|
||||||
|
|
||||||
// Private grids of modules/pixels, with dimensions of size*size:
|
// Private grids of modules/pixels, with dimensions of size*size:
|
||||||
|
|
||||||
// The modules of this QR Code (false = light, true = dark).
|
// The modules of this QR Code (false = light, true = dark).
|
||||||
// Immutable after constructor finishes. Accessed through getModule().
|
// Immutable after constructor finishes. Accessed through getModule().
|
||||||
private: std::vector<std::vector<bool> > modules;
|
private: std::vector<std::vector<bool> > modules;
|
||||||
|
|
||||||
// Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
|
// Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
|
||||||
private: std::vector<std::vector<bool> > isFunction;
|
private: std::vector<std::vector<bool> > isFunction;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Constructor (low level) ----*/
|
/*---- Constructor (low level) ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a new QR Code with the given version number,
|
* Creates a new QR Code with the given version number,
|
||||||
* error correction level, data codeword bytes, and mask number.
|
* error correction level, data codeword bytes, and mask number.
|
||||||
* This is a low-level API that most users should not use directly.
|
* This is a low-level API that most users should not use directly.
|
||||||
* A mid-level API is the encodeSegments() function.
|
* A mid-level API is the encodeSegments() function.
|
||||||
*/
|
*/
|
||||||
public: QrCode(int ver, Ecc ecl, const std::vector<std::uint8_t> &dataCodewords, int msk);
|
public: QrCode(int ver, Ecc ecl, const std::vector<std::uint8_t>& dataCodewords, int msk);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Public instance methods ----*/
|
/*---- Public instance methods ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns this QR Code's version, in the range [1, 40].
|
* Returns this QR Code's version, in the range [1, 40].
|
||||||
*/
|
*/
|
||||||
public: int getVersion() const;
|
public: int getVersion() const;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns this QR Code's size, in the range [21, 177].
|
* Returns this QR Code's size, in the range [21, 177].
|
||||||
*/
|
*/
|
||||||
public: int getSize() const;
|
public: int getSize() const;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns this QR Code's error correction level.
|
* Returns this QR Code's error correction level.
|
||||||
*/
|
*/
|
||||||
public: Ecc getErrorCorrectionLevel() const;
|
public: Ecc getErrorCorrectionLevel() const;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns this QR Code's mask, in the range [0, 7].
|
* Returns this QR Code's mask, in the range [0, 7].
|
||||||
*/
|
*/
|
||||||
public: int getMask() const;
|
public: int getMask() const;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the color of the module (pixel) at the given coordinates, which is false
|
* Returns the color of the module (pixel) at the given coordinates, which is false
|
||||||
* for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
* for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
||||||
* If the given coordinates are out of bounds, then false (light) is returned.
|
* If the given coordinates are out of bounds, then false (light) is returned.
|
||||||
*/
|
*/
|
||||||
public: bool getModule(int x, int y) const;
|
public: bool getModule(int x, int y) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Private helper methods for constructor: Drawing function modules ----*/
|
/*---- Private helper methods for constructor: Drawing function modules ----*/
|
||||||
|
|
||||||
// Reads this object's version field, and draws and marks all function modules.
|
// Reads this object's version field, and draws and marks all function modules.
|
||||||
private: void drawFunctionPatterns();
|
private: void drawFunctionPatterns();
|
||||||
|
|
||||||
|
|
||||||
// Draws two copies of the format bits (with its own error correction code)
|
// Draws two copies of the format bits (with its own error correction code)
|
||||||
// based on the given mask and this object's error correction level field.
|
// based on the given mask and this object's error correction level field.
|
||||||
private: void drawFormatBits(int msk);
|
private: void drawFormatBits(int msk);
|
||||||
|
|
||||||
|
|
||||||
// Draws two copies of the version bits (with its own error correction code),
|
// Draws two copies of the version bits (with its own error correction code),
|
||||||
// based on this object's version field, iff 7 <= version <= 40.
|
// based on this object's version field, iff 7 <= version <= 40.
|
||||||
private: void drawVersion();
|
private: void drawVersion();
|
||||||
|
|
||||||
|
|
||||||
// Draws a 9*9 finder pattern including the border separator,
|
// Draws a 9*9 finder pattern including the border separator,
|
||||||
// with the center module at (x, y). Modules can be out of bounds.
|
// with the center module at (x, y). Modules can be out of bounds.
|
||||||
private: void drawFinderPattern(int x, int y);
|
private: void drawFinderPattern(int x, int y);
|
||||||
|
|
||||||
|
|
||||||
// Draws a 5*5 alignment pattern, with the center module
|
// Draws a 5*5 alignment pattern, with the center module
|
||||||
// at (x, y). All modules must be in bounds.
|
// at (x, y). All modules must be in bounds.
|
||||||
private: void drawAlignmentPattern(int x, int y);
|
private: void drawAlignmentPattern(int x, int y);
|
||||||
|
|
||||||
|
|
||||||
// Sets the color of a module and marks it as a function module.
|
// Sets the color of a module and marks it as a function module.
|
||||||
// Only used by the constructor. Coordinates must be in bounds.
|
// Only used by the constructor. Coordinates must be in bounds.
|
||||||
private: void setFunctionModule(int x, int y, bool isDark);
|
private: void setFunctionModule(int x, int y, bool isDark);
|
||||||
|
|
||||||
|
|
||||||
// Returns the color of the module at the given coordinates, which must be in range.
|
// Returns the color of the module at the given coordinates, which must be in range.
|
||||||
private: bool module(int x, int y) const;
|
private: bool module(int x, int y) const;
|
||||||
|
|
||||||
|
|
||||||
/*---- Private helper methods for constructor: Codewords and masking ----*/
|
/*---- Private helper methods for constructor: Codewords and masking ----*/
|
||||||
|
|
||||||
// Returns a new byte string representing the given data with the appropriate error correction
|
// Returns a new byte string representing the given data with the appropriate error correction
|
||||||
// codewords appended to it, based on this object's version and error correction level.
|
// codewords appended to it, based on this object's version and error correction level.
|
||||||
private: std::vector<std::uint8_t> addEccAndInterleave(const std::vector<std::uint8_t> &data) const;
|
private: std::vector<std::uint8_t> addEccAndInterleave(const std::vector<std::uint8_t>& data) const;
|
||||||
|
|
||||||
|
|
||||||
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
||||||
// data area of this QR Code. Function modules need to be marked off before this is called.
|
// data area of this QR Code. Function modules need to be marked off before this is called.
|
||||||
private: void drawCodewords(const std::vector<std::uint8_t> &data);
|
private: void drawCodewords(const std::vector<std::uint8_t>& data);
|
||||||
|
|
||||||
|
|
||||||
// XORs the codeword modules in this QR Code with the given mask pattern.
|
// XORs the codeword modules in this QR Code with the given mask pattern.
|
||||||
// The function modules must be marked and the codeword bits must be drawn
|
// The function modules must be marked and the codeword bits must be drawn
|
||||||
// before masking. Due to the arithmetic of XOR, calling applyMask() with
|
// before masking. Due to the arithmetic of XOR, calling applyMask() with
|
||||||
// the same mask value a second time will undo the mask. A final well-formed
|
// the same mask value a second time will undo the mask. A final well-formed
|
||||||
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
||||||
private: void applyMask(int msk);
|
private: void applyMask(int msk);
|
||||||
|
|
||||||
|
|
||||||
// Calculates and returns the penalty score based on state of this QR Code's current modules.
|
// Calculates and returns the penalty score based on state of this QR Code's current modules.
|
||||||
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
|
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
|
||||||
private: long getPenaltyScore() const;
|
private: long getPenaltyScore() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Private helper functions ----*/
|
/*---- Private helper functions ----*/
|
||||||
|
|
||||||
// Returns an ascending list of positions of alignment patterns for this version number.
|
// Returns an ascending list of positions of alignment patterns for this version number.
|
||||||
// Each position is in the range [0,177), and are used on both the x and y axes.
|
// Each position is in the range [0,177), and are used on both the x and y axes.
|
||||||
// This could be implemented as lookup table of 40 variable-length lists of unsigned bytes.
|
// This could be implemented as lookup table of 40 variable-length lists of unsigned bytes.
|
||||||
private: std::vector<int> getAlignmentPatternPositions() const;
|
private: std::vector<int> getAlignmentPatternPositions() const;
|
||||||
|
|
||||||
|
|
||||||
// Returns the number of data bits that can be stored in a QR Code of the given version number, after
|
// Returns the number of data bits that can be stored in a QR Code of the given version number, after
|
||||||
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
||||||
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
||||||
private: static int getNumRawDataModules(int ver);
|
private: static int getNumRawDataModules(int ver);
|
||||||
|
|
||||||
|
|
||||||
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
|
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
|
||||||
// QR Code of the given version number and error correction level, with remainder bits discarded.
|
// QR Code of the given version number and error correction level, with remainder bits discarded.
|
||||||
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
|
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
|
||||||
private: static int getNumDataCodewords(int ver, Ecc ecl);
|
private: static int getNumDataCodewords(int ver, Ecc ecl);
|
||||||
|
|
||||||
|
|
||||||
// Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
|
// Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
|
||||||
// implemented as a lookup table over all possible parameter values, instead of as an algorithm.
|
// implemented as a lookup table over all possible parameter values, instead of as an algorithm.
|
||||||
private: static std::vector<std::uint8_t> reedSolomonComputeDivisor(int degree);
|
private: static std::vector<std::uint8_t> reedSolomonComputeDivisor(int degree);
|
||||||
|
|
||||||
|
|
||||||
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
|
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
|
||||||
private: static std::vector<std::uint8_t> reedSolomonComputeRemainder(const std::vector<std::uint8_t> &data, const std::vector<std::uint8_t> &divisor);
|
private: static std::vector<std::uint8_t> reedSolomonComputeRemainder(const std::vector<std::uint8_t>& data, const std::vector<std::uint8_t>& divisor);
|
||||||
|
|
||||||
|
|
||||||
// Returns the product of the two given field elements modulo GF(2^8/0x11D).
|
// Returns the product of the two given field elements modulo GF(2^8/0x11D).
|
||||||
// All inputs are valid. This could be implemented as a 256*256 lookup table.
|
// All inputs are valid. This could be implemented as a 256*256 lookup table.
|
||||||
private: static std::uint8_t reedSolomonMultiply(std::uint8_t x, std::uint8_t y);
|
private: static std::uint8_t reedSolomonMultiply(std::uint8_t x, std::uint8_t y);
|
||||||
|
|
||||||
|
|
||||||
// Can only be called immediately after a light run is added, and
|
// Can only be called immediately after a light run is added, and
|
||||||
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
|
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
|
||||||
private: int finderPenaltyCountPatterns(const std::array<int,7> &runHistory) const;
|
private: int finderPenaltyCountPatterns(const std::array<int, 7>& runHistory) const;
|
||||||
|
|
||||||
|
|
||||||
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
|
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
|
||||||
private: int finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunLength, std::array<int,7> &runHistory) const;
|
private: int finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunLength, std::array<int, 7>& runHistory) const;
|
||||||
|
|
||||||
|
|
||||||
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
|
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
|
||||||
private: void finderPenaltyAddHistory(int currentRunLength, std::array<int,7> &runHistory) const;
|
private: void finderPenaltyAddHistory(int currentRunLength, std::array<int, 7>& runHistory) const;
|
||||||
|
|
||||||
|
|
||||||
// Returns true iff the i'th bit of x is set to 1.
|
// Returns true iff the i'th bit of x is set to 1.
|
||||||
private: static bool getBit(long x, int i);
|
private: static bool getBit(long x, int i);
|
||||||
|
|
||||||
|
|
||||||
/*---- Constants and tables ----*/
|
/*---- Constants and tables ----*/
|
||||||
|
|
||||||
// The minimum version number supported in the QR Code Model 2 standard.
|
// The minimum version number supported in the QR Code Model 2 standard.
|
||||||
public: static constexpr int MIN_VERSION = 1;
|
public: static constexpr int MIN_VERSION = 1;
|
||||||
|
|
||||||
// The maximum version number supported in the QR Code Model 2 standard.
|
// The maximum version number supported in the QR Code Model 2 standard.
|
||||||
public: static constexpr int MAX_VERSION = 40;
|
public: static constexpr int MAX_VERSION = 40;
|
||||||
|
|
||||||
|
|
||||||
// For use in getPenaltyScore(), when evaluating which mask is best.
|
// For use in getPenaltyScore(), when evaluating which mask is best.
|
||||||
private: static const int PENALTY_N1;
|
private: static const int PENALTY_N1;
|
||||||
private: static const int PENALTY_N2;
|
private: static const int PENALTY_N2;
|
||||||
private: static const int PENALTY_N3;
|
private: static const int PENALTY_N3;
|
||||||
private: static const int PENALTY_N4;
|
private: static const int PENALTY_N4;
|
||||||
|
|
||||||
|
|
||||||
private: static const std::int8_t ECC_CODEWORDS_PER_BLOCK[4][41];
|
private: static const std::int8_t ECC_CODEWORDS_PER_BLOCK[4][41];
|
||||||
private: static const std::int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41];
|
private: static const std::int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Public exception class ----*/
|
/*---- Public exception class ----*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Thrown when the supplied data does not fit any QR Code version. Ways to handle this exception include:
|
* Thrown when the supplied data does not fit any QR Code version. Ways to handle this exception include:
|
||||||
* - Decrease the error correction level if it was greater than Ecc::LOW.
|
* - Decrease the error correction level if it was greater than Ecc::LOW.
|
||||||
* - If the encodeSegments() function was called with a maxVersion argument, then increase
|
* - If the encodeSegments() function was called with a maxVersion argument, then increase
|
||||||
* it if it was less than QrCode::MAX_VERSION. (This advice does not apply to the other
|
* it if it was less than QrCode::MAX_VERSION. (This advice does not apply to the other
|
||||||
* factory functions because they search all versions up to QrCode::MAX_VERSION.)
|
* factory functions because they search all versions up to QrCode::MAX_VERSION.)
|
||||||
* - Split the text data into better or optimal segments in order to reduce the number of bits required.
|
* - Split the text data into better or optimal segments in order to reduce the number of bits required.
|
||||||
* - Change the text or binary data to be shorter.
|
* - Change the text or binary data to be shorter.
|
||||||
* - Change the text to fit the character set of a particular segment mode (e.g. alphanumeric).
|
* - Change the text to fit the character set of a particular segment mode (e.g. alphanumeric).
|
||||||
* - Propagate the error upward to the caller/user.
|
* - Propagate the error upward to the caller/user.
|
||||||
*/
|
*/
|
||||||
class data_too_long : public std::length_error {
|
class data_too_long : public std::length_error {
|
||||||
|
|
||||||
public: explicit data_too_long(const std::string &msg);
|
public: explicit data_too_long(const std::string& msg);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* An appendable sequence of bits (0s and 1s). Mainly used by QrSegment.
|
* An appendable sequence of bits (0s and 1s). Mainly used by QrSegment.
|
||||||
*/
|
*/
|
||||||
class BitBuffer final : public std::vector<bool> {
|
class BitBuffer final : public std::vector<bool> {
|
||||||
|
|
||||||
/*---- Constructor ----*/
|
/*---- Constructor ----*/
|
||||||
|
|
||||||
// Creates an empty bit buffer (length 0).
|
// Creates an empty bit buffer (length 0).
|
||||||
public: BitBuffer();
|
public: BitBuffer();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Method ----*/
|
/*---- Method ----*/
|
||||||
|
|
||||||
// Appends the given number of low-order bits of the given value
|
// Appends the given number of low-order bits of the given value
|
||||||
// to this buffer. Requires 0 <= len <= 31 and val < 2^len.
|
// to this buffer. Requires 0 <= len <= 31 and val < 2^len.
|
||||||
public: void appendBits(std::uint32_t val, int len);
|
public: void appendBits(std::uint32_t val, int len);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,29 +2,30 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
std::string toSvgString(const qrcodegen::QrCode &qr, int border) {
|
std::string toSvgString(const qrcodegen::QrCode& qr, int border)
|
||||||
if (border < 0)
|
{
|
||||||
throw std::domain_error("Border must be non-negative");
|
if (border < 0)
|
||||||
if (border > INT_MAX / 2 || border * 2 > INT_MAX - qr.getSize())
|
throw std::domain_error("Border must be non-negative");
|
||||||
throw std::overflow_error("Border too large");
|
if (border > INT_MAX / 2 || border * 2 > INT_MAX - qr.getSize())
|
||||||
|
throw std::overflow_error("Border too large");
|
||||||
|
|
||||||
std::ostringstream sb;
|
std::ostringstream sb;
|
||||||
sb << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
sb << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||||
sb << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
sb << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||||
sb << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 ";
|
sb << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 ";
|
||||||
sb << (qr.getSize() + border * 2) << " " << (qr.getSize() + border * 2) << "\" stroke=\"none\">\n";
|
sb << (qr.getSize() + border * 2) << " " << (qr.getSize() + border * 2) << "\" stroke=\"none\">\n";
|
||||||
sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
|
sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
|
||||||
sb << "\t<path d=\"";
|
sb << "\t<path d=\"";
|
||||||
for (int y = 0; y < qr.getSize(); y++) {
|
for (int y = 0; y < qr.getSize(); y++) {
|
||||||
for (int x = 0; x < qr.getSize(); x++) {
|
for (int x = 0; x < qr.getSize(); x++) {
|
||||||
if (qr.getModule(x, y)) {
|
if (qr.getModule(x, y)) {
|
||||||
if (x != 0 || y != 0)
|
if (x != 0 || y != 0)
|
||||||
sb << " ";
|
sb << " ";
|
||||||
sb << "M" << (x + border) << "," << (y + border) << "h1v1h-1z";
|
sb << "M" << (x + border) << "," << (y + border) << "h1v1h-1z";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb << "\" fill=\"#000000\"/>\n";
|
sb << "\" fill=\"#000000\"/>\n";
|
||||||
sb << "</svg>\n";
|
sb << "</svg>\n";
|
||||||
return sb.str();
|
return sb.str();
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "qrcodegen.hpp"
|
#include "qrcodegen.hpp"
|
||||||
|
|
||||||
std::string toSvgString(const qrcodegen::QrCode &qr, int border);
|
std::string toSvgString(const qrcodegen::QrCode& qr, int border);
|
||||||
|
|
||||||
#endif // RTOSVG_HPP
|
#endif // RTOSVG_HPP
|
||||||
+9567
-8854
File diff suppressed because it is too large.
Load diff
+12512
-12452
File diff suppressed because it is too large.
Load diff
@@ -5,7 +5,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace security
|
namespace security
|
||||||
{
|
{
|
||||||
void set_cors_headers(const httplib::Request &request, httplib::Response &response)
|
void set_cors_headers(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << " " << std::endl;
|
std::cout << GREEN << request.path << " " << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace api
|
|||||||
namespace security
|
namespace security
|
||||||
{
|
{
|
||||||
// function to set cors headers
|
// function to set cors headers
|
||||||
void set_cors_headers(const httplib::Request &request, httplib::Response &response);
|
void set_cors_headers(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace dns
|
namespace dns
|
||||||
{
|
{
|
||||||
void get_dns(const httplib::Request &request, httplib::Response &response);
|
void get_dns(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_dns(const httplib::Request &request, httplib::Response &response);
|
void set_dns(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_dns_servers(const httplib::Request &request, httplib::Response &response);
|
void get_dns_servers(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_dns_servers(const httplib::Request &request, httplib::Response &response);
|
void set_dns_servers(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_local_domains(const httplib::Request &request, httplib::Response &response);
|
void get_local_domains(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_local_domains(const httplib::Request &request, httplib::Response &response);
|
void set_local_domains(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace dns
|
namespace dns
|
||||||
{
|
{
|
||||||
void get_dns(const httplib::Request &request, httplib::Response &response)
|
void get_dns(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -37,7 +37,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_dns(const httplib::Request &request, httplib::Response &response)
|
void set_dns(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace dns
|
namespace dns
|
||||||
{
|
{
|
||||||
void get_local_domains(const httplib::Request &request, httplib::Response &response)
|
void get_local_domains(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -36,7 +36,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_local_domains(const httplib::Request &request, httplib::Response &response)
|
void set_local_domains(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace dns
|
namespace dns
|
||||||
{
|
{
|
||||||
void get_dns_servers(const httplib::Request &request, httplib::Response &response)
|
void get_dns_servers(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -36,7 +36,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_dns_servers(const httplib::Request &request, httplib::Response &response)
|
void set_dns_servers(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -54,7 +54,7 @@ namespace api
|
|||||||
}
|
}
|
||||||
std::ofstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
std::ofstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
||||||
nlohmann::json servers = json_body["servers"];
|
nlohmann::json servers = json_body["servers"];
|
||||||
for (const nlohmann::json_abi_v3_11_3::json &server : servers)
|
for (const nlohmann::json_abi_v3_11_3::json& server : servers)
|
||||||
{
|
{
|
||||||
std::string srv = server;
|
std::string srv = server;
|
||||||
if (server == "")
|
if (server == "")
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace ftp
|
namespace ftp
|
||||||
{
|
{
|
||||||
void get_ftp(const httplib::Request &request, httplib::Response &response)
|
void get_ftp(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -37,7 +37,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_ftp(const httplib::Request &request, httplib::Response &response)
|
void set_ftp(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace ftp
|
namespace ftp
|
||||||
{
|
{
|
||||||
void get_ftp(const httplib::Request &request, httplib::Response &response);
|
void get_ftp(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_ftp(const httplib::Request &request, httplib::Response &response);
|
void set_ftp(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace ssh
|
namespace ssh
|
||||||
{
|
{
|
||||||
void get_ssh_keys(const httplib::Request &request, httplib::Response &response)
|
void get_ssh_keys(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -38,7 +38,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_ssh_keys(const httplib::Request &request, httplib::Response &response)
|
void set_ssh_keys(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace ssh
|
namespace ssh
|
||||||
{
|
{
|
||||||
void get_ssh_port(const httplib::Request &request, httplib::Response &response)
|
void get_ssh_port(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -42,7 +42,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_ssh_port(const httplib::Request &request, httplib::Response &response)
|
void set_ssh_port(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -76,7 +76,8 @@ namespace api
|
|||||||
if (get_ssh_server() == DROPBEAR_SSH)
|
if (get_ssh_server() == DROPBEAR_SSH)
|
||||||
{
|
{
|
||||||
systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" /etc/default/dropbear";
|
systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" /etc/default/dropbear";
|
||||||
} else if (get_ssh_server() == OPENSSH_SSH)
|
}
|
||||||
|
else if (get_ssh_server() == OPENSSH_SSH)
|
||||||
{
|
{
|
||||||
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
|
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,8 @@ namespace api
|
|||||||
if (get_ssh_server() == OPENSSH_SSH)
|
if (get_ssh_server() == OPENSSH_SSH)
|
||||||
{
|
{
|
||||||
system("rc restart ssh");
|
system("rc restart ssh");
|
||||||
} else if (get_ssh_server() == DROPBEAR_SSH)
|
}
|
||||||
|
else if (get_ssh_server() == DROPBEAR_SSH)
|
||||||
{
|
{
|
||||||
system("rc restart dropbear");
|
system("rc restart dropbear");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace api
|
|||||||
return config::config.getConfig()["settings"]["ssh"]["server"];
|
return config::config.getConfig()["settings"]["ssh"]["server"];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string set_ssh_server(std::string &server)
|
std::string set_ssh_server(std::string& server)
|
||||||
{
|
{
|
||||||
config::config.setConfig(std::string("../config.json"));
|
config::config.setConfig(std::string("../config.json"));
|
||||||
nlohmann::json new_config = config::config.getConfig();
|
nlohmann::json new_config = config::config.getConfig();
|
||||||
@@ -30,7 +30,7 @@ namespace api
|
|||||||
return config::config.getConfig()["settings"]["ssh"]["server"];
|
return config::config.getConfig()["settings"]["ssh"]["server"];
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_ssh_server_http(const httplib::Request &request, httplib::Response &response)
|
void get_ssh_server_http(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -50,7 +50,7 @@ namespace api
|
|||||||
responsedata << R"({"server":")" << get_ssh_server() << R"("})";
|
responsedata << R"({"server":")" << get_ssh_server() << R"("})";
|
||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
void set_ssh_server_http(const httplib::Request &request, httplib::Response &response)
|
void set_ssh_server_http(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -81,7 +81,8 @@ namespace api
|
|||||||
system("rc del ssh");
|
system("rc del ssh");
|
||||||
system("rc start dropbear");
|
system("rc start dropbear");
|
||||||
system("rc add dropbear");
|
system("rc add dropbear");
|
||||||
} else if (new_server == OPENSSH_SSH) {
|
}
|
||||||
|
else if (new_server == OPENSSH_SSH) {
|
||||||
system("rc stop dropbear");
|
system("rc stop dropbear");
|
||||||
system("rc del dropbear");
|
system("rc del dropbear");
|
||||||
system("rc start ssh");
|
system("rc start ssh");
|
||||||
|
|||||||
@@ -13,19 +13,19 @@ namespace api
|
|||||||
namespace ssh
|
namespace ssh
|
||||||
{
|
{
|
||||||
std::string get_ssh_server();
|
std::string get_ssh_server();
|
||||||
std::string set_ssh_server(std::string &server);
|
std::string set_ssh_server(std::string& server);
|
||||||
|
|
||||||
void get_ssh_server_http(const httplib::Request &request, httplib::Response &response);
|
void get_ssh_server_http(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_ssh_server_http(const httplib::Request &request, httplib::Response &response);
|
void set_ssh_server_http(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_ssh_status(const httplib::Request &request, httplib::Response &response);
|
void get_ssh_status(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_ssh_status(const httplib::Request &request, httplib::Response &response);
|
void set_ssh_status(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_ssh_keys(const httplib::Request &request, httplib::Response &response);
|
void get_ssh_keys(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_ssh_keys(const httplib::Request &request, httplib::Response &response);
|
void set_ssh_keys(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_ssh_port(const httplib::Request &request, httplib::Response &response);
|
void get_ssh_port(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_ssh_port(const httplib::Request &request, httplib::Response &response);
|
void set_ssh_port(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace ssh
|
namespace ssh
|
||||||
{
|
{
|
||||||
void get_ssh_status(const httplib::Request &request, httplib::Response &response)
|
void get_ssh_status(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -37,7 +37,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_ssh_status(const httplib::Request &request, httplib::Response &response)
|
void set_ssh_status(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -66,7 +66,8 @@ namespace api
|
|||||||
{
|
{
|
||||||
system("rc stop dropbear");
|
system("rc stop dropbear");
|
||||||
system("rc del dropbear");
|
system("rc del dropbear");
|
||||||
} else if (get_ssh_server() == OPENSSH_SSH) {
|
}
|
||||||
|
else if (get_ssh_server() == OPENSSH_SSH) {
|
||||||
system("rc stop ssh");
|
system("rc stop ssh");
|
||||||
system("rc del ssh");
|
system("rc del ssh");
|
||||||
}
|
}
|
||||||
@@ -78,7 +79,8 @@ namespace api
|
|||||||
{
|
{
|
||||||
system("rc start dropbear");
|
system("rc start dropbear");
|
||||||
system("rc add dropbear");
|
system("rc add dropbear");
|
||||||
} else if (get_ssh_server() == OPENSSH_SSH) {
|
}
|
||||||
|
else if (get_ssh_server() == OPENSSH_SSH) {
|
||||||
system("rc start ssh");
|
system("rc start ssh");
|
||||||
system("rc add ssh");
|
system("rc add ssh");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace telnet
|
namespace telnet
|
||||||
{
|
{
|
||||||
void get_telnet(const httplib::Request &request, httplib::Response &response)
|
void get_telnet(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -41,7 +41,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_telnet(const httplib::Request &request, httplib::Response &response)
|
void set_telnet(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace telnet
|
namespace telnet
|
||||||
{
|
{
|
||||||
void get_telnet_port(const httplib::Request &request, httplib::Response &response)
|
void get_telnet_port(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -41,7 +41,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_telnet_port(const httplib::Request &request, httplib::Response &response)
|
void set_telnet_port(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace telnet
|
namespace telnet
|
||||||
{
|
{
|
||||||
void get_telnet(const httplib::Request &request, httplib::Response &response);
|
void get_telnet(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_telnet(const httplib::Request &request, httplib::Response &response);
|
void set_telnet(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_telnet_port(const httplib::Request &request, httplib::Response &response);
|
void get_telnet_port(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_telnet_port(const httplib::Request &request, httplib::Response &response);
|
void set_telnet_port(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace wifi
|
namespace wifi
|
||||||
{
|
{
|
||||||
void get_wifi_channel(const httplib::Request &request, httplib::Response &response)
|
void get_wifi_channel(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -41,7 +41,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_wifi_channel(const httplib::Request &request, httplib::Response &response)
|
void set_wifi_channel(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace wifi
|
namespace wifi
|
||||||
{
|
{
|
||||||
void get_wifi_name(const httplib::Request &request, httplib::Response &response)
|
void get_wifi_name(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -41,7 +41,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_wifi_name(const httplib::Request &request, httplib::Response &response)
|
void set_wifi_name(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace wifi
|
namespace wifi
|
||||||
{
|
{
|
||||||
void get_wifi_password(const httplib::Request &request, httplib::Response &response)
|
void get_wifi_password(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -41,7 +41,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_wifi_password(const httplib::Request &request, httplib::Response &response)
|
void set_wifi_password(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace wifi
|
namespace wifi
|
||||||
{
|
{
|
||||||
void get_wifi_qr(const httplib::Request &request, httplib::Response &response)
|
void get_wifi_qr(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace wifi
|
namespace wifi
|
||||||
{
|
{
|
||||||
void get_wifi_status(const httplib::Request &request, httplib::Response &response)
|
void get_wifi_status(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -37,7 +37,7 @@ namespace api
|
|||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_wifi_status(const httplib::Request &request, httplib::Response &response)
|
void set_wifi_status(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -11,19 +11,19 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace wifi
|
namespace wifi
|
||||||
{
|
{
|
||||||
void get_wifi_status(const httplib::Request &request, httplib::Response &response);
|
void get_wifi_status(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_wifi_status(const httplib::Request &request, httplib::Response &response);
|
void set_wifi_status(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_wifi_name(const httplib::Request &request, httplib::Response &response);
|
void get_wifi_name(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_wifi_name(const httplib::Request &request, httplib::Response &response);
|
void set_wifi_name(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_wifi_password(const httplib::Request &request, httplib::Response &response);
|
void get_wifi_password(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_wifi_password(const httplib::Request &request, httplib::Response &response);
|
void set_wifi_password(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_wifi_qr(const httplib::Request &request, httplib::Response &response);
|
void get_wifi_qr(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
void get_wifi_channel(const httplib::Request &request, httplib::Response &response);
|
void get_wifi_channel(const httplib::Request& request, httplib::Response& response);
|
||||||
void set_wifi_channel(const httplib::Request &request, httplib::Response &response);
|
void set_wifi_channel(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace system
|
namespace system
|
||||||
{
|
{
|
||||||
void reboot(const httplib::Request &request, httplib::Response &response)
|
void reboot(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace system
|
namespace system
|
||||||
{
|
{
|
||||||
void reboot(const httplib::Request &request, httplib::Response &response);
|
void reboot(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace system
|
namespace system
|
||||||
{
|
{
|
||||||
void get_syslog(const httplib::Request &request, httplib::Response &response)
|
void get_syslog(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
std::stringstream responsedata;
|
std::stringstream responsedata;
|
||||||
std::ifstream syslogfile(SYSLOG_FILE);
|
std::ifstream syslogfile(SYSLOG_FILE);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace system
|
namespace system
|
||||||
{
|
{
|
||||||
void get_syslog(const httplib::Request &request, httplib::Response &response);
|
void get_syslog(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace system
|
namespace system
|
||||||
{
|
{
|
||||||
void get_uptime(const httplib::Request &request, httplib::Response &response)
|
void get_uptime(const httplib::Request& request, httplib::Response& response)
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
struct sysinfo x;
|
struct sysinfo x;
|
||||||
@@ -21,12 +21,12 @@ namespace api
|
|||||||
// << std::endl;
|
// << std::endl;
|
||||||
std::stringstream responsedata;
|
std::stringstream responsedata;
|
||||||
responsedata << R"({"uptime":{"hour":")"
|
responsedata << R"({"uptime":{"hour":")"
|
||||||
<< static_cast<unsigned long long>(x.uptime) / 3600ULL
|
<< static_cast<unsigned long long>(x.uptime) / 3600ULL
|
||||||
<< R"(","minute":")"
|
<< R"(","minute":")"
|
||||||
<< static_cast<unsigned long long>(x.uptime) / 60ULL % 60ULL
|
<< static_cast<unsigned long long>(x.uptime) / 60ULL % 60ULL
|
||||||
<< R"(","second":")"
|
<< R"(","second":")"
|
||||||
<< static_cast<unsigned long long>(x.uptime) % 60ULL
|
<< static_cast<unsigned long long>(x.uptime) % 60ULL
|
||||||
<< R"("}})";
|
<< R"("}})";
|
||||||
response.set_content(responsedata.str(), JSON_TYPE);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace system
|
namespace system
|
||||||
{
|
{
|
||||||
void get_uptime(const httplib::Request &request, httplib::Response &response);
|
void get_uptime(const httplib::Request& request, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user