{"id":34138,"date":"2024-01-17T13:20:50","date_gmt":"2024-01-17T18:20:50","guid":{"rendered":"http:\/\/www.allyngibson.com\/?p=34138"},"modified":"2025-01-30T17:44:41","modified_gmt":"2025-01-30T22:44:41","slug":"coding-myself-a-vpn-toggle","status":"publish","type":"post","link":"http:\/\/www.allyngibson.com\/?p=34138","title":{"rendered":"Coding Myself a VPN Toggle"},"content":{"rendered":"<p>At fifty, I am becoming the Linux nerd I feel I should have been at twenty-five.<\/p>\n<p>I had a problem.  I wanted an easy way to connect and disconnect from Diamond&#8217;s VPN.  Yes, I could use the Network Connections interface in Linux Mint, but sometimes it expands while I was navigating to the VPN toggle and I accidentally attempt to connect to another WiFi network.  Or, I could have set my VPN to autoconnect, as my WiFi does, except I don&#8217;t always need to be connected to the VPN.  So, I wanted some sort of simple toggle&#8211;if the VPN is on, turn it off; if off, turn it on.<\/p>\n<p>Could it be done with a script?  I knew how &#8212; or, at least I had the commands in a documentation file I wrote for myself last year &#8212; to turn the VPN on or off from the command line.  What I needed was a way to test the VPN&#8217;s status, then execute the right command based on that status.<\/p>\n<p>First, with thanks to the Googles, I figured out how to determine if the VPN was active from the command line with the ifconfig command.  Then I wrote an if statement off that command, plugged in the nmcli commands that activate\/deactivate the VPN, and tested it.<\/p>\n<p>It worked!  On!  Off!  On!  Off!<\/p>\n<p>One little thing annoyed me.  Activating the VPN popped up a notification that the VPN was active.  Deactivating the VPN did not have a similar result.  I discovered the notify-send command and created a deactivation notification.<\/p>\n<p>I created a desktop file so I could call the script from my taskbar.  I felt quite good.  I had a problem, and I had solved it.<\/p>\n<p>This morning, I decided I wanted to be able to activate and deactivate the VPN from my notifications instead.  It makes sense; that&#8217;s where I look for my network status.  So I would need a Cinnamon Applet.<\/p>\n<p>I didn&#8217;t need anything fancy, just an icon I could click on and it executes the script.  The Linux Mint website has some basic documentation for creating an applet, and I started from there.  I took their samples, made a few edits, and gave it a try.<\/p>\n<p>It didn&#8217;t work.<\/p>\n<p>The problem was, I didn&#8217;t know how to execute a shell command from a javascript file.  Google again was my friend, and I found a blog post that had exactly the information I needed.  I needed to add this const, I needed to use that js command.  I made my edits, restarted Cinnamon, and&#8230;<\/p>\n<p>It worked!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"400\" src=\"http:\/\/www.allyngibson.com\/wp-content\/uploads\/2024\/01\/Screenshot_20240117_125032.jpg\" alt=\"\" class=\"aligncenter size-full wp-image-34137\" \/><\/p>\n<p>I have been careful not to turn on and turn off the VPN too rapidly, lest I lock myself out of the network.<\/p>\n<p>The problem I had &#8212; a simple toggle to control my connection status with the work VPN &#8212; was solved.<\/p>\n<p>No wonder I am &#8220;the problem project person&#8221; at work.  See the problem, solve the problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At fifty, I am becoming the Linux nerd I feel I should have been at twenty-five. I had a problem. I wanted an easy way to connect and disconnect from Diamond&#8217;s VPN. Yes, I could use the Network Connections interface in Linux Mint, but sometimes it expands while I was navigating to the VPN toggle<a class=\"more-link\" href=\"http:\/\/www.allyngibson.com\/?p=34138\">Continue reading <span class=\"screen-reader-text\">&#8220;Coding Myself a VPN Toggle&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[763],"tags":[4846,5140,4860],"class_list":["post-34138","post","type-post","status-publish","format-standard","hentry","category-linux","tag-diamond-comic-distributors","tag-linux","tag-linux-mint","entry"],"_links":{"self":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/34138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=34138"}],"version-history":[{"count":0,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/34138\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=34138"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=34138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}