mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-10-30 18:27:49 +00:00 
			
		
		
		
	Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
		| @@ -181,8 +181,6 @@ namespace OpenWifi { | |||||||
| 		MyHash_ = Utils::ComputeHash(MyPublicEndPoint_); | 		MyHash_ = Utils::ComputeHash(MyPublicEndPoint_); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void MicroServicePostInitialization(); |  | ||||||
|  |  | ||||||
| 	void MicroService::InitializeLoggingSystem() { | 	void MicroService::InitializeLoggingSystem() { | ||||||
| 		static auto initialized = false; | 		static auto initialized = false; | ||||||
|  |  | ||||||
| @@ -200,95 +198,136 @@ namespace OpenWifi { | |||||||
| 				Poco::AutoPtr<Poco::NullChannel> DevNull(new Poco::NullChannel); | 				Poco::AutoPtr<Poco::NullChannel> DevNull(new Poco::NullChannel); | ||||||
| 				Poco::Logger::root().setChannel(DevNull); | 				Poco::Logger::root().setChannel(DevNull); | ||||||
| 			} else if (LoggingDestination == "console") { | 			} else if (LoggingDestination == "console") { | ||||||
| 				Poco::AutoPtr<Poco::ConsoleChannel> Console(new Poco::ConsoleChannel); |                 SetConsoleLogs(UseAsyncLogs_, DisableWebSocketLogging, LoggingFormat); | ||||||
| 				if(UseAsyncLogs_) { |  | ||||||
| 					Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Console)); |  | ||||||
| 					Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); |  | ||||||
| 					Formatter->setProperty("pattern", LoggingFormat); |  | ||||||
| 					Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel( |  | ||||||
| 						new Poco::FormattingChannel(Formatter, Async)); |  | ||||||
| 					Poco::Logger::root().setChannel(FormattingChannel); |  | ||||||
| 				} else { |  | ||||||
| 					Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); |  | ||||||
| 					Formatter->setProperty("pattern", LoggingFormat); |  | ||||||
| 					Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel( |  | ||||||
| 						new Poco::FormattingChannel(Formatter, Console)); |  | ||||||
| 					Poco::Logger::root().setChannel(FormattingChannel); |  | ||||||
| 				} |  | ||||||
| 			} else if (LoggingDestination == "colorconsole") { | 			} else if (LoggingDestination == "colorconsole") { | ||||||
| 				Poco::AutoPtr<Poco::ColorConsoleChannel> ColorConsole(new Poco::ColorConsoleChannel); |                 SetColorConsoleLogs(UseAsyncLogs_, DisableWebSocketLogging, LoggingFormat); | ||||||
| 				if(UseAsyncLogs_) { | 			} else if (LoggingDestination == "sql") { | ||||||
| 					Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(ColorConsole)); |                 SetSQLLogs(UseAsyncLogs_, DisableWebSocketLogging, LoggingFormat); | ||||||
| 					Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); | 			} else if (LoggingDestination == "syslog") { | ||||||
| 					Formatter->setProperty("pattern", LoggingFormat); |                 SetSyslogLogs(UseAsyncLogs_, DisableWebSocketLogging, LoggingFormat); | ||||||
| 					Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel( |  | ||||||
| 						new Poco::FormattingChannel(Formatter, Async)); |  | ||||||
| 					Poco::Logger::root().setChannel(FormattingChannel); |  | ||||||
| 			} else { | 			} else { | ||||||
|  |                 SetFileLogs(UseAsyncLogs_, DisableWebSocketLogging, LoggingFormat, DAEMON_ROOT_ENV_VAR); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  | 			auto Level = Poco::Logger::parseLevel(MicroService::instance().ConfigGetString("logging.level", "debug")); | ||||||
|  | 			Poco::Logger::root().setLevel(Level); | ||||||
|  | 			if(!DisableWebSocketLogging) { | ||||||
|  | 				static const UI_WebSocketClientServer::NotificationTypeIdVec Notifications = { | ||||||
|  | 					{1, "log"}}; | ||||||
|  | 				UI_WebSocketClientServer()->RegisterNotifications(Notifications); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void MicroService::SetConsoleLogs(bool UseAsync, bool DisableWebSocketLogging, const std::string & FormatterPattern) { | ||||||
|  |  | ||||||
|  |         Poco::AutoPtr<Poco::ConsoleChannel> Console(new Poco::ConsoleChannel); | ||||||
|         Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); |         Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); | ||||||
| 					Formatter->setProperty("pattern", LoggingFormat); |         Formatter->setProperty("pattern", FormatterPattern); | ||||||
| 					Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel( |         Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(new Poco::FormattingChannel(Formatter, Console)); | ||||||
| 						new Poco::FormattingChannel(Formatter, ColorConsole)); |  | ||||||
|  |         if(DisableWebSocketLogging) { | ||||||
|  |             if(UseAsync) { | ||||||
|  |                 Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(FormattingChannel)); | ||||||
|  |                 Poco::Logger::root().setChannel(Async); | ||||||
|  |             } else { | ||||||
|                 Poco::Logger::root().setChannel(FormattingChannel); |                 Poco::Logger::root().setChannel(FormattingChannel); | ||||||
|             } |             } | ||||||
| 			} else if (LoggingDestination == "sql") { |  | ||||||
| 				//"CREATE TABLE T_POCO_LOG (Source VARCHAR, Name VARCHAR, ProcessId INTEGER, Thread VARCHAR, ThreadId INTEGER, Priority INTEGER, Text VARCHAR, DateTime DATE)" |  | ||||||
|  |  | ||||||
| 			} else if (LoggingDestination == "syslog") { |  | ||||||
|  |  | ||||||
|         } else { |         } else { | ||||||
| 				auto LoggingLocation = |             Poco::AutoPtr<WebSocketLogger>			WSLogger(new WebSocketLogger); | ||||||
| 					MicroService::instance().ConfigPath("logging.path", "$OWCERT_ROOT/logs") + "/log"; |             Poco::AutoPtr<Poco::SplitterChannel>	Splitter(new Poco::SplitterChannel); | ||||||
|  |             Splitter->addChannel(WSLogger); | ||||||
|  |             Splitter->addChannel(FormattingChannel); | ||||||
|  |             if(UseAsync) { | ||||||
|  |                 Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Splitter)); | ||||||
|  |                 Poco::Logger::root().setChannel(Async); | ||||||
|  |             } else { | ||||||
|  |                 Poco::Logger::root().setChannel(Splitter); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void MicroService::SetColorConsoleLogs(bool UseAsync, bool DisableWebSocketLogging, const std::string & FormatterPattern) { | ||||||
|  |  | ||||||
|  |         Poco::AutoPtr<Poco::ColorConsoleChannel> Console(new Poco::ColorConsoleChannel); | ||||||
|  |         Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); | ||||||
|  |         Formatter->setProperty("pattern", FormatterPattern); | ||||||
|  |         Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(new Poco::FormattingChannel(Formatter, Console)); | ||||||
|  |  | ||||||
|  |         if(DisableWebSocketLogging) { | ||||||
|  |             if(UseAsync) { | ||||||
|  |                 Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(FormattingChannel)); | ||||||
|  |                 Poco::Logger::root().setChannel(Async); | ||||||
|  |             } else { | ||||||
|  |                 Poco::Logger::root().setChannel(FormattingChannel); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             Poco::AutoPtr<WebSocketLogger>			WSLogger(new WebSocketLogger); | ||||||
|  |             Poco::AutoPtr<Poco::SplitterChannel>	Splitter(new Poco::SplitterChannel); | ||||||
|  |             Splitter->addChannel(WSLogger); | ||||||
|  |             Splitter->addChannel(FormattingChannel); | ||||||
|  |             if(UseAsync) { | ||||||
|  |                 Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Splitter)); | ||||||
|  |                 Poco::Logger::root().setChannel(Async); | ||||||
|  |             } else { | ||||||
|  |                 Poco::Logger::root().setChannel(Splitter); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void MicroService::SetSQLLogs([[maybe_unused]] bool UseAsync,[[maybe_unused]]  bool DisableWebSocketLogging,[[maybe_unused]]  const std::string & FormatterPattern) { | ||||||
|  |         //"CREATE TABLE T_POCO_LOG (Source VARCHAR, Name VARCHAR, ProcessId INTEGER, Thread VARCHAR, ThreadId INTEGER, Priority INTEGER, Text VARCHAR, DateTime DATE)" | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void MicroService::SetSyslogLogs([[maybe_unused]] bool UseAsync,[[maybe_unused]]  bool DisableWebSocketLogging,[[maybe_unused]]  const std::string & FormatterPattern) { | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void MicroService::SetFileLogs(bool UseAsync, bool DisableWebSocketLogging, const std::string & FormatterPattern, const std::string & root_env_var) { | ||||||
|  |         std::string DefaultLogPath = fmt::format("${}/logs",root_env_var); | ||||||
|  |         auto LoggingLocationDir = MicroService::instance().ConfigPath("logging.path", DefaultLogPath); | ||||||
|  |         Poco::File      LD(LoggingLocationDir); | ||||||
|  |         try { | ||||||
|  |             if(!LD.exists()) { | ||||||
|  |                 LD.createDirectory(); | ||||||
|  |             } | ||||||
|  |         } catch(const Poco::Exception &E) { | ||||||
|  |             std::cout << "Cannot create " << LD.path() << "  Error: " << E.message() << std::endl; | ||||||
|  |         } | ||||||
|  |         auto LoggingLocationDirFilePattern = LoggingLocationDir + "/log"; | ||||||
|  |  | ||||||
|         Poco::AutoPtr<Poco::FileChannel> FileChannel(new Poco::FileChannel); |         Poco::AutoPtr<Poco::FileChannel> FileChannel(new Poco::FileChannel); | ||||||
|         FileChannel->setProperty("rotation", "10 M"); |         FileChannel->setProperty("rotation", "10 M"); | ||||||
|         FileChannel->setProperty("archive", "timestamp"); |         FileChannel->setProperty("archive", "timestamp"); | ||||||
|         FileChannel->setProperty("purgeCount", "10"); |         FileChannel->setProperty("purgeCount", "10"); | ||||||
| 				FileChannel->setProperty("path", LoggingLocation); |         FileChannel->setProperty("path", LoggingLocationDirFilePattern); | ||||||
| 				if(UseAsyncLogs_) { |  | ||||||
| 					Poco::AutoPtr<Poco::AsyncChannel> Async_File( |  | ||||||
| 						new Poco::AsyncChannel(FileChannel)); |  | ||||||
|         Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); |         Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); | ||||||
| 					Formatter->setProperty("pattern", LoggingFormat); |         Formatter->setProperty("pattern", FormatterPattern); | ||||||
| 					Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel( |         Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(new Poco::FormattingChannel(Formatter, FileChannel)); | ||||||
| 						new Poco::FormattingChannel(Formatter, Async_File)); |  | ||||||
|         if(DisableWebSocketLogging) { |         if(DisableWebSocketLogging) { | ||||||
|  |             if(UseAsync) { | ||||||
|  |                 Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(FormattingChannel)); | ||||||
|  |                 Poco::Logger::root().setChannel(Async); | ||||||
|  |             } else { | ||||||
|                 Poco::Logger::root().setChannel(FormattingChannel); |                 Poco::Logger::root().setChannel(FormattingChannel); | ||||||
|  |             } | ||||||
|         } else { |         } else { | ||||||
|             Poco::AutoPtr<WebSocketLogger>			WSLogger(new WebSocketLogger); |             Poco::AutoPtr<WebSocketLogger>			WSLogger(new WebSocketLogger); | ||||||
|             Poco::AutoPtr<Poco::SplitterChannel>	Splitter(new Poco::SplitterChannel); |             Poco::AutoPtr<Poco::SplitterChannel>	Splitter(new Poco::SplitterChannel); | ||||||
|             Splitter->addChannel(WSLogger); |             Splitter->addChannel(WSLogger); | ||||||
|             Splitter->addChannel(FormattingChannel); |             Splitter->addChannel(FormattingChannel); | ||||||
| 						Poco::Logger::root().setChannel(Splitter); |             if(UseAsync) { | ||||||
| 					} |                 Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Splitter)); | ||||||
|  |                 Poco::Logger::root().setChannel(Async); | ||||||
|             } else { |             } else { | ||||||
| 					Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter); |  | ||||||
| 					Formatter->setProperty("pattern", LoggingFormat); |  | ||||||
| 					Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel( |  | ||||||
| 						new Poco::FormattingChannel(Formatter, FileChannel)); |  | ||||||
| 					if(DisableWebSocketLogging) { |  | ||||||
| 						Poco::Logger::root().setChannel(FormattingChannel); |  | ||||||
| 					} else { |  | ||||||
| 						Poco::AutoPtr<Poco::SplitterChannel>	Splitter(new Poco::SplitterChannel); |  | ||||||
| 						Poco::AutoPtr<WebSocketLogger>			WSLogger(new WebSocketLogger); |  | ||||||
| 						Splitter->addChannel(WSLogger); |  | ||||||
| 						Splitter->addChannel(FormattingChannel); |  | ||||||
|                 Poco::Logger::root().setChannel(Splitter); |                 Poco::Logger::root().setChannel(Splitter); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 			auto Level = Poco::Logger::parseLevel(MicroService::instance().ConfigGetString("logging.level", "debug")); |  | ||||||
| 			Poco::Logger::root().setLevel(Level); |  | ||||||
|  |  | ||||||
| 			if(!DisableWebSocketLogging) { |  | ||||||
| 				static const UI_WebSocketClientServer::NotificationTypeIdVec Notifications = { |  | ||||||
| 					{1, "log"}}; |  | ||||||
|  |  | ||||||
| 				UI_WebSocketClientServer()->RegisterNotifications(Notifications); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	void DaemonPostInitialization(Poco::Util::Application &self); | 	void DaemonPostInitialization(Poco::Util::Application &self); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -158,6 +158,12 @@ namespace OpenWifi { | |||||||
| 		[[nodiscard]] std::string Sign(Poco::JWT::Token &T, const std::string &Algo); | 		[[nodiscard]] std::string Sign(Poco::JWT::Token &T, const std::string &Algo); | ||||||
| 		void AddActivity(const std::string &Activity); | 		void AddActivity(const std::string &Activity); | ||||||
|  |  | ||||||
|  |         static void SetConsoleLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern); | ||||||
|  |         static void SetColorConsoleLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern); | ||||||
|  |         static void SetSQLLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern); | ||||||
|  |         static void SetSyslogLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern); | ||||||
|  |         static void SetFileLogs(bool UseAsync, bool AllowWebSocket, const std::string & FormatterPattern, const std::string & root_env_var); | ||||||
|  |  | ||||||
| 	  private: | 	  private: | ||||||
| 	    static MicroService         * instance_; | 	    static MicroService         * instance_; | ||||||
| 		bool                        HelpRequested_ = false; | 		bool                        HelpRequested_ = false; | ||||||
|   | |||||||
| @@ -550,6 +550,27 @@ namespace OpenWifi { | |||||||
| 			Poco::JSON::Stringifier::stringify(Object, Answer); | 			Poco::JSON::Stringifier::stringify(Object, Answer); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		inline void ReturnRawJSON(const std::string &json_doc) { | ||||||
|  | 			PrepareResponse(); | ||||||
|  | 			if(Request!= nullptr) { | ||||||
|  | 				//   can we compress ??? | ||||||
|  | 				auto AcceptedEncoding = Request->find("Accept-Encoding"); | ||||||
|  | 				if(AcceptedEncoding!=Request->end()) { | ||||||
|  | 					if( AcceptedEncoding->second.find("gzip")!=std::string::npos || | ||||||
|  | 						AcceptedEncoding->second.find("compress")!=std::string::npos) { | ||||||
|  | 						Response->set("Content-Encoding", "gzip"); | ||||||
|  | 						std::ostream &Answer = Response->send(); | ||||||
|  | 						Poco::DeflatingOutputStream deflater(Answer, Poco::DeflatingStreamBuf::STREAM_GZIP); | ||||||
|  |                         deflater << json_doc; | ||||||
|  | 						deflater.close(); | ||||||
|  | 						return; | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			std::ostream &Answer = Response->send(); | ||||||
|  |             Answer << json_doc; | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		inline void ReturnCountOnly(uint64_t Count) { | 		inline void ReturnCountOnly(uint64_t Count) { | ||||||
| 			Poco::JSON::Object  Answer; | 			Poco::JSON::Object  Answer; | ||||||
| 			Answer.set("count", Count); | 			Answer.set("count", Count); | ||||||
|   | |||||||
| @@ -228,6 +228,7 @@ namespace OpenWifi::RESTAPI::Errors { | |||||||
|     static const struct msg ApiKeyNameDoesNotExist{1150,"API Key name does not exist."}; |     static const struct msg ApiKeyNameDoesNotExist{1150,"API Key name does not exist."}; | ||||||
|     static const struct msg ApiKeyDoesNotExist{1150,"API Key does not exist."}; |     static const struct msg ApiKeyDoesNotExist{1150,"API Key does not exist."}; | ||||||
|  |  | ||||||
|  | 	static const struct msg DeviceIsRestricted{1151,"Device is protected by regulation. This function is not allowed."}; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 stephb9959
					stephb9959