fix: Récupérer l'opération active depuis la table operations

- Corrige l'erreur SQL 'Unknown column fk_operation in users'
- L'opération active est récupérée depuis operations.chk_active = 1
- Jointure avec users pour filtrer par entité de l'admin créateur
- Query: SELECT o.id FROM operations o INNER JOIN users u ON u.fk_entite = o.fk_entite WHERE u.id = ? AND o.chk_active = 1
This commit is contained in:
2026-01-26 16:57:08 +01:00
parent c24a3afe6a
commit 0687900564
3040 changed files with 77204 additions and 1578 deletions

View File

@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.15)
set(PROJECT_NAME "connectivity_plus")
project(${PROJECT_NAME} LANGUAGES CXX)
# This value is used when generating builds using this plugin, so it must
# not be changed
set(PLUGIN_NAME "connectivity_plus_plugin")
add_library(${PLUGIN_NAME} SHARED
"connectivity_plus_plugin.cpp"
"network_manager.cpp"
)
apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE
flutter
flutter_wrapper_plugin
iphlpapi
)
# List of absolute paths to libraries that should be bundled with the plugin
set(connectivity_plus_bundled_libraries
""
PARENT_SCOPE
)

View File

@@ -0,0 +1,189 @@
// clang-format off
#include "include/connectivity_plus/network_manager.h"
// clang-format on
#include "include/connectivity_plus/connectivity_plus_windows_plugin.h"
#include <flutter/event_channel.h>
#include <flutter/event_sink.h>
#include <flutter/event_stream_handler.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
#include <functional>
#include <memory>
namespace {
typedef flutter::EventChannel<flutter::EncodableValue> FlEventChannel;
typedef flutter::EventSink<flutter::EncodableValue> FlEventSink;
typedef flutter::MethodCall<flutter::EncodableValue> FlMethodCall;
typedef flutter::MethodResult<flutter::EncodableValue> FlMethodResult;
typedef flutter::MethodChannel<flutter::EncodableValue> FlMethodChannel;
typedef flutter::StreamHandler<flutter::EncodableValue> FlStreamHandler;
typedef flutter::StreamHandlerError<flutter::EncodableValue>
FlStreamHandlerError;
class ConnectivityPlusWindowsPlugin : public flutter::Plugin {
public:
ConnectivityPlusWindowsPlugin();
virtual ~ConnectivityPlusWindowsPlugin();
std::shared_ptr<NetworkManager> GetManager() const;
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
private:
void HandleMethodCall(const FlMethodCall &method_call,
std::unique_ptr<FlMethodResult> result);
std::shared_ptr<NetworkManager> manager;
};
class ConnectivityStreamHandler : public FlStreamHandler {
public:
ConnectivityStreamHandler(std::shared_ptr<NetworkManager> manager);
virtual ~ConnectivityStreamHandler();
protected:
void AddConnectivityEvent();
std::unique_ptr<FlStreamHandlerError>
OnListenInternal(const flutter::EncodableValue *arguments,
std::unique_ptr<FlEventSink> &&sink) override;
std::unique_ptr<FlStreamHandlerError>
OnCancelInternal(const flutter::EncodableValue *arguments) override;
private:
std::shared_ptr<NetworkManager> manager;
std::unique_ptr<FlEventSink> sink;
};
ConnectivityPlusWindowsPlugin::ConnectivityPlusWindowsPlugin() {
manager = std::make_shared<NetworkManager>();
manager->Init();
}
ConnectivityPlusWindowsPlugin::~ConnectivityPlusWindowsPlugin() {
manager->Cleanup();
}
std::shared_ptr<NetworkManager>
ConnectivityPlusWindowsPlugin::GetManager() const {
return manager;
}
void ConnectivityPlusWindowsPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarWindows *registrar) {
auto plugin = std::make_unique<ConnectivityPlusWindowsPlugin>();
auto methodChannel =
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), "dev.fluttercommunity.plus/connectivity",
&flutter::StandardMethodCodec::GetInstance());
methodChannel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto &call, auto result) {
plugin_pointer->HandleMethodCall(call, std::move(result));
});
auto eventChannel = std::make_unique<FlEventChannel>(
registrar->messenger(), "dev.fluttercommunity.plus/connectivity_status",
&flutter::StandardMethodCodec::GetInstance());
eventChannel->SetStreamHandler(
std::make_unique<ConnectivityStreamHandler>(plugin->GetManager()));
registrar->AddPlugin(std::move(plugin));
}
static std::string ConnectivityToString(ConnectivityType connectivityType) {
switch (connectivityType) {
case ConnectivityType::WiFi:
return "wifi";
case ConnectivityType::Ethernet:
return "ethernet";
case ConnectivityType::VPN:
return "vpn";
case ConnectivityType::Other:
return "other";
case ConnectivityType::None:
default:
return "none";
}
}
static flutter::EncodableList
EncodeConnectivityTypes(std::set<ConnectivityType> connectivityTypes) {
flutter::EncodableList encodedList;
if (connectivityTypes.empty()) {
encodedList.push_back(
flutter::EncodableValue(ConnectivityToString(ConnectivityType::None)));
return encodedList;
}
for (const auto &type : connectivityTypes) {
std::string connectivityString = ConnectivityToString(type);
encodedList.push_back(flutter::EncodableValue(connectivityString));
}
return encodedList;
}
void ConnectivityPlusWindowsPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
if (method_call.method_name().compare("check") == 0) {
result->Success(EncodeConnectivityTypes(manager->GetConnectivityTypes()));
} else {
result->NotImplemented();
}
}
ConnectivityStreamHandler::ConnectivityStreamHandler(
std::shared_ptr<NetworkManager> manager)
: manager(manager) {}
ConnectivityStreamHandler::~ConnectivityStreamHandler() {}
void ConnectivityStreamHandler::AddConnectivityEvent() {
sink->Success(EncodeConnectivityTypes(manager->GetConnectivityTypes()));
}
std::unique_ptr<FlStreamHandlerError>
ConnectivityStreamHandler::OnListenInternal(
const flutter::EncodableValue *arguments,
std::unique_ptr<FlEventSink> &&events) {
sink = std::move(events);
auto callback =
std::bind(&ConnectivityStreamHandler::AddConnectivityEvent, this);
if (!manager->StartListen(callback)) {
return std::make_unique<FlStreamHandlerError>(
std::to_string(manager->GetError()), "NetworkManager::StartListen",
nullptr);
}
AddConnectivityEvent();
return nullptr;
}
std::unique_ptr<FlStreamHandlerError>
ConnectivityStreamHandler::OnCancelInternal(
const flutter::EncodableValue *arguments) {
manager->StopListen();
sink.reset();
return nullptr;
}
} // namespace
void ConnectivityPlusWindowsPluginRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
ConnectivityPlusWindowsPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}

View File

@@ -0,0 +1,23 @@
#ifndef FLUTTER_PLUGIN_CONNECTIVITY_WINDOWS_PLUS_PLUGIN_H_
#define FLUTTER_PLUGIN_CONNECTIVITY_WINDOWS_PLUS_PLUGIN_H_
#include <flutter_plugin_registrar.h>
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
#else
#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
#endif
#if defined(__cplusplus)
extern "C" {
#endif
FLUTTER_PLUGIN_EXPORT void ConnectivityPlusWindowsPluginRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_PLUGIN_CONNECTIVITY_PLUS_WINDOWS_PLUGIN_H_

View File

@@ -0,0 +1,50 @@
#ifndef NETWORK_MANAGER_H
#define NETWORK_MANAGER_H
// clang-format off
#include <winsock2.h>
// clang-format on
#include <windows.h>
#include <functional>
#include <set>
#include <string>
enum class ConnectivityType { None, Ethernet, WiFi, Other, VPN };
class NetworkListener;
struct IConnectionPoint;
struct IConnectionPointContainer;
struct INetworkListManager;
struct IUnknown;
typedef std::function<void()> NetworkCallback;
class NetworkManager {
public:
NetworkManager();
~NetworkManager();
bool Init();
void Cleanup();
std::set<ConnectivityType> GetConnectivityTypes() const;
bool StartListen(NetworkCallback pCallback);
void StopListen();
bool HasError() const;
int GetError() const;
private:
std::vector<GUID> GetConnectedAdapterIds() const;
DWORD dwCookie = 0;
IUnknown *pUnknown = NULL;
INetworkListManager *pNetworkListManager = NULL;
IConnectionPointContainer *pCPContainer = NULL;
IConnectionPoint *pConnectPoint = NULL;
NetworkListener *pListener = NULL;
};
#endif // NETWORK_MANAGER_H

View File

@@ -0,0 +1,252 @@
// based on
// https://github.com/PurpleI2P/i2pd/blob/master/Win32/Win32NetState.cpp
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/
#include "include/connectivity_plus/network_manager.h"
#include <iphlpapi.h>
#include <netlistmgr.h>
#include <ocidl.h>
#include <cassert>
#include <set>
class NetworkListener final : public INetworkEvents {
public:
NetworkListener(NetworkCallback pCb) : pCallback(pCb) {}
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) {
AddRef();
HRESULT hr = S_OK;
if (IsEqualIID(riid, IID_IUnknown)) {
*ppvObject = (IUnknown *)this;
} else if (IsEqualIID(riid, IID_INetworkEvents)) {
*ppvObject = (INetworkEvents *)this;
} else {
hr = E_NOINTERFACE;
}
return hr;
}
ULONG STDMETHODCALLTYPE AddRef() { return InterlockedIncrement(&lRef); }
ULONG STDMETHODCALLTYPE Release() {
LONG lAddend = InterlockedDecrement(&lRef);
if (lRef == 0) {
delete this;
}
return lAddend;
}
HRESULT STDMETHODCALLTYPE NetworkAdded(GUID networkId) { return S_OK; }
HRESULT STDMETHODCALLTYPE
NetworkConnectivityChanged(GUID networkId, NLM_CONNECTIVITY newConnectivity) {
Callback();
return S_OK;
}
HRESULT STDMETHODCALLTYPE NetworkDeleted(GUID networkId) { return S_OK; }
HRESULT STDMETHODCALLTYPE
NetworkPropertyChanged(GUID networkId, NLM_NETWORK_PROPERTY_CHANGE flags) {
if (flags & NLM_NETWORK_PROPERTY_CHANGE_CONNECTION) {
Callback();
}
return S_OK;
}
void Callback() {
assert(pCallback);
pCallback();
}
private:
volatile LONG lRef = 1;
NetworkCallback pCallback = nullptr;
};
NetworkManager::NetworkManager() {}
NetworkManager::~NetworkManager() {
StopListen();
Cleanup();
}
bool NetworkManager::Init() {
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_NetworkListManager, NULL, CLSCTX_ALL,
IID_IUnknown, (void **)&pUnknown);
if (SUCCEEDED(hr)) {
hr = pUnknown->QueryInterface(IID_INetworkListManager,
(void **)&pNetworkListManager);
}
return SUCCEEDED(hr);
}
void NetworkManager::Cleanup() {
if (pNetworkListManager) {
pNetworkListManager->Release();
pNetworkListManager = NULL;
}
if (pUnknown) {
pUnknown->Release();
pUnknown = NULL;
}
CoUninitialize();
}
std::vector<GUID> NetworkManager::GetConnectedAdapterIds() const {
std::vector<GUID> adapterIds;
IEnumNetworkConnections *connections = NULL;
HRESULT hr = pNetworkListManager->GetNetworkConnections(&connections);
if (hr == S_OK) {
while (true) {
INetworkConnection *connection = NULL;
hr = connections->Next(1, &connection, NULL);
if (hr != S_OK) {
break;
}
VARIANT_BOOL isConnected = VARIANT_FALSE;
hr = connection->get_IsConnectedToInternet(&isConnected);
if (hr == S_OK && isConnected == VARIANT_TRUE) {
GUID guid;
hr = connection->GetAdapterId(&guid);
if (hr == S_OK) {
adapterIds.push_back(std::move(guid));
}
}
connection->Release();
}
connections->Release();
}
return adapterIds;
}
std::set<ConnectivityType> NetworkManager::GetConnectivityTypes() const {
ULONG bufferSize = 15 * 1024;
ULONG flags = GAA_FLAG_SKIP_UNICAST | GAA_FLAG_SKIP_ANYCAST |
GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER |
GAA_FLAG_SKIP_FRIENDLY_NAME;
std::vector<unsigned char> buffer(bufferSize);
PIP_ADAPTER_ADDRESSES addresses =
reinterpret_cast<PIP_ADAPTER_ADDRESSES>(&buffer.front());
DWORD rc = GetAdaptersAddresses(AF_UNSPEC, flags, 0, addresses, &bufferSize);
if (rc == ERROR_BUFFER_OVERFLOW) {
buffer.resize(bufferSize);
addresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(&buffer.front());
rc = GetAdaptersAddresses(AF_UNSPEC, flags, 0, addresses, &bufferSize);
}
if (rc != NO_ERROR) {
return {ConnectivityType::None};
}
std::vector<GUID> adapterIds = GetConnectedAdapterIds();
if (adapterIds.empty()) {
return {ConnectivityType::None};
}
std::set<ConnectivityType> connectivities;
for (; addresses != NULL; addresses = addresses->Next) {
NET_LUID luid;
rc = ConvertInterfaceIndexToLuid(addresses->IfIndex, &luid);
if (rc != NO_ERROR) {
continue;
}
GUID guid;
rc = ConvertInterfaceLuidToGuid(&luid, &guid);
if (rc != NO_ERROR) {
continue;
}
if (std::find(adapterIds.begin(), adapterIds.end(), guid) !=
adapterIds.end()) {
// Read more at
// https://learn.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh
switch (addresses->IfType) {
case IF_TYPE_ETHERNET_CSMACD:
case IF_TYPE_IEEE1394:
connectivities.insert(ConnectivityType::Ethernet);
break;
case IF_TYPE_IEEE80211:
connectivities.insert(ConnectivityType::WiFi);
break;
case IF_TYPE_TUNNEL:
case IF_TYPE_PPP:
connectivities.insert(ConnectivityType::VPN);
break;
default:
connectivities.insert(ConnectivityType::Other);
break;
}
}
}
if (connectivities.empty()) {
// If no specific connectivity types were found, return a set containing
// only None
return {ConnectivityType::None};
}
// Return the set of detected connectivity types
return connectivities;
}
bool NetworkManager::StartListen(NetworkCallback pCallback) {
if (!pCallback || pListener) {
return false;
}
HRESULT hr = pNetworkListManager->QueryInterface(
IID_IConnectionPointContainer, (void **)&pCPContainer);
if (SUCCEEDED(hr)) {
hr = pCPContainer->FindConnectionPoint(IID_INetworkEvents, &pConnectPoint);
if (SUCCEEDED(hr)) {
pListener = new NetworkListener(pCallback);
hr = pConnectPoint->Advise((IUnknown *)pListener, &dwCookie);
if (SUCCEEDED(hr)) {
return true;
}
}
}
return false;
}
void NetworkManager::StopListen() {
if (pConnectPoint) {
pConnectPoint->Unadvise(dwCookie);
pConnectPoint->Release();
pConnectPoint = NULL;
dwCookie = 0;
}
if (pCPContainer) {
pCPContainer->Release();
pCPContainer = NULL;
}
if (pListener) {
pListener->Release();
pListener = NULL;
}
}
bool NetworkManager::HasError() const { return GetLastError() != 0; }
int NetworkManager::GetError() const { return GetLastError(); }