summaryrefslogtreecommitdiff
path: root/hscript/network.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-26 03:38:02 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-26 03:38:02 -0500
commit1efbbaf0145dd785b2cefcf1f51703372efed2f3 (patch)
tree08d0052a0c621f04b0bae00a9cbc11da02601ca8 /hscript/network.cc
parent1cd72d82372a9e89bdf406f58ae8609e344a1bd1 (diff)
downloadhorizon-1efbbaf0145dd785b2cefcf1f51703372efed2f3.tar.gz
horizon-1efbbaf0145dd785b2cefcf1f51703372efed2f3.tar.bz2
horizon-1efbbaf0145dd785b2cefcf1f51703372efed2f3.tar.xz
horizon-1efbbaf0145dd785b2cefcf1f51703372efed2f3.zip
hscript: Implement NetSSID::execute
Diffstat (limited to 'hscript/network.cc')
-rw-r--r--hscript/network.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/hscript/network.cc b/hscript/network.cc
index 14e33b4..e375385 100644
--- a/hscript/network.cc
+++ b/hscript/network.cc
@@ -13,6 +13,7 @@
#include <algorithm>
#include <arpa/inet.h> /* inet_pton */
#include <cstring> /* memcpy */
+#include <fstream> /* ofstream for Net write */
#ifdef HAS_INSTALL_ENV
# include <linux/wireless.h> /* struct iwreq */
# include <string.h> /* strerror */
@@ -395,5 +396,22 @@ bool NetSSID::validate(ScriptOptions options) const {
}
bool NetSSID::execute(ScriptOptions) const {
- return false;
+ std::ofstream conf("/tmp/horizon/wpa_supplicant.conf",
+ std::ios_base::app);
+ if(!conf) {
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "netssid: failed to write configuration");
+ return false;
+ }
+
+ conf << std::endl;
+ conf << "network={" << std::endl;
+ conf << "\tssid=\"" << this->ssid() << "\"" << std::endl;
+ if(this->type() != SecurityType::None) {
+ conf << "\tpsk=\"" << this->passphrase() << "\"" << std::endl;
+ }
+ conf << "\tpriority=5" << std::endl;
+ conf << "}" << std::endl;
+
+ return !conf.fail();
}