The pulse-cookie package looks pretty good and your packaging of it is pretty neat @erahhal. I started with no choices and now this thread has given me two choices and I am conflicted as I much prefer the Qt version over the selenium/Chromedriver version I got to work 2 days ago. Here is what I am using for reference,
The python scripts are part of my overlay called pulsevpn
#machines/framework/overlays/pulsevpn/src/openconnect.py
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import subprocess
host = "vpn.host.name"
user = "username"
driver = webdriver.Chrome("chromedriver")
wait = WebDriverWait(driver, 60)
driver.get("https://"+host)
dsid = wait.until(lambda driver: driver.get_cookie("DSID"))
driver.quit()
## Both pulse as well as nc work
subprocess.run(["sudo","openconnect", "-C", dsid["value"], "--protocol=pulse", "-u", user, host])
#machines/framework/overlays/pulsevpn/src/setup.py
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='pulsevpn',
version='1.0',
# Modules to import from other scripts:
packages=find_packages(),
# Executables
scripts=["openconnect.py"],
)
And the overlay
#machines/framework/overlays/pulsevpn/default.nix
{
config,
pkgs,
lib,
...
}: {
nixpkgs.overlays = [
(final: prev: {
pulsevpn = pkgs.python3Packages.buildPythonApplication rec {
pname = "pulsevpn";
version = "0.1";
src = ./src;
propagatedBuildInputs = with pkgs.python3Packages; [selenium pkgs.chromedriver];
installPhase = ''
mkdir -p $out/bin
cp ${src}/openconnect.py $out/bin/pulsevpn
chmod +x $out/bin/pulsevpn
'';
meta = with lib; {
description = "Poor Man's Pulse VPN";
platforms = platforms.linux;
};
};
})
];
}
I also tried out what you came up with and slightly polished it to add a wrapper instead to remove some of the annoying Qt5 related warnings and to force the use of Qt6. Here it is as an overlay in case you have the same warnings
#machines/framework/overlays/pulse-vpn/default.nix
{
config,
pkgs,
lib,
...
}: {
nixpkgs.overlays = [
(final: prev: {
pulse-vpn = let
pulse-cookie = pkgs.python3Packages.buildPythonApplication rec {
pname = "pulse-cookie";
version = "1.0";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "sha256-ZURSXfChq2k8ktKO6nc6AuVaAMS3eOcFkiKahpq4ebU=";
};
propagatedBuildInputs = with pkgs.python3Packages; [
pyqt6
pyqt6-webengine
setuptools
];
preBuild = ''
cat > setup.py << EOF
from setuptools import setup
setup(
name='pulse-cookie',
packages=['pulse_cookie'],
package_dir={"": 'src'},
version='1.0',
author='Raj Magesh Gauthaman',
description='wrapper around openconnect allowing user to log in through a webkit window for mfa',
install_requires=[
'PyQt6-WebEngine',
],
entry_points={
'console_scripts': ['get-pulse-cookie=pulse_cookie._cli:main']
},
)
EOF
'';
meta = with lib; {
homepage = "https://pypi.org/project/pulse-cookie/";
description = "wrapper around openconnect allowing user to log in through a webkit window for mfa";
license = licenses.gpl3;
};
};
pulse-cookie-wrapper = pkgs.runCommand "pulse-cookie-wrapper" {
buildInputs = [ pkgs.makeWrapper ];
} ''
makeWrapper ${pulse-cookie}/bin/get-pulse-cookie $out/bin/get-pulse-cookie \
--set QT_PLUGIN_PATH "${pkgs.lib.getLib pkgs.qt6.qtbase}/lib/qt-6.2/plugins" \
--set QML2_IMPORT_PATH "${pkgs.qt6.qtbase}/qml"
'';
pulse-vpn-shell-script = pkgs.writeShellScriptBin "pulse-vpn" ''
export QTWEBENGINE_CHROMIUM_FLAGS="--disable-logging"
HOST=https://your.vpn.host
DSID=$(${pulse-cookie-wrapper}/bin/get-pulse-cookie -n DSID $HOST)
sudo ${pkgs.openconnect}/bin/openconnect --protocol nc -C DSID=$DSID $HOST
'';
in
final.buildEnv {
name = "pulse-vpn";
paths = [pulse-cookie-wrapper pulse-vpn-shell-script];
};
})
];
}
And thanks everyone. This community is amazing.