summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/changedns111
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetupimp.cpp8
-rw-r--r--noncore/settings/networksettings/interfaces/changedns111
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp8
4 files changed, 230 insertions, 8 deletions
diff --git a/noncore/net/networksetup/interfaces/changedns b/noncore/net/networksetup/interfaces/changedns
new file mode 100644
index 0000000..4760a67
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/changedns
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+SN="`basename $0`" # base portion of our filename
+AE="-a" # switch to add an entry
+RE="-r" # swithc to remove an entry
+EL="/tmp/resolv.conf" # expected location of the system nameserver config file
+ARGS="$@" # friendly variable name for all args
+
+usage(){
+ echo "usage:
+$SN -a {ip} [{ip}...]
+$SN -r {ip} [{ip}...]"
+}
+
+#if are there at least two arguments?
+if [ "$#" -gt 1 ]
+then
+
+ #remove any old resolv.conf file
+ rm .resolve.conf .resolve.old .resolve.new 2> /dev/null
+
+ #cast current nameserver file into OLD
+ cat "$EL" > .resolve.old
+
+ #build IP list
+ for ARG in $ARGS
+ do
+ if [ "$ARG" != "$1" ]
+ then
+ IP_LIST=`echo "$IP_LIST $ARG"`
+ fi
+ done
+
+ #select case on first switch
+ case "$1" in
+
+ #case '-a'
+ "$AE" )
+
+ #for each IP in IP_LIST
+ for IP in $IP_LIST
+ do
+ #add nameserver entery to .newfile
+ echo "nameserver $IP" >> .resolve.conf
+
+ #cat OLD into grep excluding IP lines,
+ #storing results into NEW
+ cat .resolve.old | grep -v "$IP" > .resolve.new
+
+ #set OLD to NEW
+ cat .resolve.new > .resolve.old
+
+ done
+
+ #cat OLD onto end of .newfile
+ cat .resolve.new >> .resolve.conf
+
+ #clean up work files
+ rm .resolve.new .resolve.old
+
+ #move old conf file to old conf file.bak
+ mv "$EL" "$EL.bak"
+
+ #move .newfile to resolve.conf file
+ mv .resolve.conf "$EL"
+
+ echo "Added $IP_LIST to $EL"
+ ;;
+
+ #case '-r'
+ "$RE" )
+
+ #for each IP in IP_LIST
+ for IP in $IP_LIST
+ do
+ #cat OLD into grep excluding IP lines,
+ #storing results into NEW
+ cat .resolve.old | grep -v "$IP" > .resolve.new
+
+ #set OLD to NEW
+ cat .resolve.new > .resolve.old
+
+ done
+
+ #move old conf file to old conf file.bak
+ mv "$EL" "$EL.bak"
+
+ #move .newfile to resolve.conf file
+ mv .resolve.new "$EL"
+
+ echo "Removed $IP_LIST from $EL"
+
+ ;;
+
+ #case else
+ * )
+
+ usage
+ ;;
+
+
+ #end switch
+ esac
+
+#else
+else
+
+ usage
+
+#end
+fi
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
index e717d6f..97c05cc 100644
--- a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
+++ b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
@@ -1,33 +1,33 @@
#include "interfacesetupimp.h"
#include "interface.h"
#include "interfaces.h"
#include <qdialog.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qmessagebox.h>
#include <assert.h>
-#define DNSSCRIPT "interfacednsscript"
+#define DNSSCRIPT "changedns"
/**
* Constuctor. Set up the connection and load the first profile.
*/
InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){
assert(parent);
assert(i);
interface = i;
interfaces = new Interfaces();
bool error = false;
if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
staticGroupBox->hide();
dhcpCheckBox->hide();
leaseTime->hide();
leaseHoursLabel->hide();
}
@@ -63,34 +63,34 @@ bool InterfaceSetupImp::saveSettings(){
return false;
}
interfaces->removeAllInterfaceOptions();
// DHCP
if(dhcpCheckBox->isChecked()){
interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
}
else{
interfaces->setInterfaceMethod("static");
interfaces->setInterfaceOption("address", ipAddressEdit->text());
interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
interfaces->setInterfaceOption("gateway", gatewayEdit->text());
QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
- interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
- interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
+ interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns);
+ interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns);
}
// IP Information
interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
/**
* The Profile has changed.
* @profile the new profile.
*/
void InterfaceSetupImp::setProfile(const QString &profile){
QString newInterfaceName = interface->getInterfaceName();
if(profile.length() > 0)
newInterfaceName += "_" + profile;
// See if we have to make a interface.
@@ -120,29 +120,29 @@ void InterfaceSetupImp::setProfile(const QString &profile){
// We must have a valid interface to get this far so read some settings.
// DHCP
bool error = false;
if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
dhcpCheckBox->setChecked(true);
else
dhcpCheckBox->setChecked(false);
leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
if(error)
leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
if(error)
leaseTime->setValue(24);
// IP Information
autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
- QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
+ QString dns = interfaces->getInterfaceOption("up interfacednsscript -a", error);
if(dns.contains(" ")){
firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
}
ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
}
// interfacesetup.cpp
diff --git a/noncore/settings/networksettings/interfaces/changedns b/noncore/settings/networksettings/interfaces/changedns
new file mode 100644
index 0000000..4760a67
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/changedns
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+SN="`basename $0`" # base portion of our filename
+AE="-a" # switch to add an entry
+RE="-r" # swithc to remove an entry
+EL="/tmp/resolv.conf" # expected location of the system nameserver config file
+ARGS="$@" # friendly variable name for all args
+
+usage(){
+ echo "usage:
+$SN -a {ip} [{ip}...]
+$SN -r {ip} [{ip}...]"
+}
+
+#if are there at least two arguments?
+if [ "$#" -gt 1 ]
+then
+
+ #remove any old resolv.conf file
+ rm .resolve.conf .resolve.old .resolve.new 2> /dev/null
+
+ #cast current nameserver file into OLD
+ cat "$EL" > .resolve.old
+
+ #build IP list
+ for ARG in $ARGS
+ do
+ if [ "$ARG" != "$1" ]
+ then
+ IP_LIST=`echo "$IP_LIST $ARG"`
+ fi
+ done
+
+ #select case on first switch
+ case "$1" in
+
+ #case '-a'
+ "$AE" )
+
+ #for each IP in IP_LIST
+ for IP in $IP_LIST
+ do
+ #add nameserver entery to .newfile
+ echo "nameserver $IP" >> .resolve.conf
+
+ #cat OLD into grep excluding IP lines,
+ #storing results into NEW
+ cat .resolve.old | grep -v "$IP" > .resolve.new
+
+ #set OLD to NEW
+ cat .resolve.new > .resolve.old
+
+ done
+
+ #cat OLD onto end of .newfile
+ cat .resolve.new >> .resolve.conf
+
+ #clean up work files
+ rm .resolve.new .resolve.old
+
+ #move old conf file to old conf file.bak
+ mv "$EL" "$EL.bak"
+
+ #move .newfile to resolve.conf file
+ mv .resolve.conf "$EL"
+
+ echo "Added $IP_LIST to $EL"
+ ;;
+
+ #case '-r'
+ "$RE" )
+
+ #for each IP in IP_LIST
+ for IP in $IP_LIST
+ do
+ #cat OLD into grep excluding IP lines,
+ #storing results into NEW
+ cat .resolve.old | grep -v "$IP" > .resolve.new
+
+ #set OLD to NEW
+ cat .resolve.new > .resolve.old
+
+ done
+
+ #move old conf file to old conf file.bak
+ mv "$EL" "$EL.bak"
+
+ #move .newfile to resolve.conf file
+ mv .resolve.new "$EL"
+
+ echo "Removed $IP_LIST from $EL"
+
+ ;;
+
+ #case else
+ * )
+
+ usage
+ ;;
+
+
+ #end switch
+ esac
+
+#else
+else
+
+ usage
+
+#end
+fi
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
index e717d6f..97c05cc 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -1,33 +1,33 @@
#include "interfacesetupimp.h"
#include "interface.h"
#include "interfaces.h"
#include <qdialog.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qmessagebox.h>
#include <assert.h>
-#define DNSSCRIPT "interfacednsscript"
+#define DNSSCRIPT "changedns"
/**
* Constuctor. Set up the connection and load the first profile.
*/
InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){
assert(parent);
assert(i);
interface = i;
interfaces = new Interfaces();
bool error = false;
if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
staticGroupBox->hide();
dhcpCheckBox->hide();
leaseTime->hide();
leaseHoursLabel->hide();
}
@@ -63,34 +63,34 @@ bool InterfaceSetupImp::saveSettings(){
return false;
}
interfaces->removeAllInterfaceOptions();
// DHCP
if(dhcpCheckBox->isChecked()){
interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
}
else{
interfaces->setInterfaceMethod("static");
interfaces->setInterfaceOption("address", ipAddressEdit->text());
interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
interfaces->setInterfaceOption("gateway", gatewayEdit->text());
QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
- interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
- interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
+ interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns);
+ interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns);
}
// IP Information
interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
/**
* The Profile has changed.
* @profile the new profile.
*/
void InterfaceSetupImp::setProfile(const QString &profile){
QString newInterfaceName = interface->getInterfaceName();
if(profile.length() > 0)
newInterfaceName += "_" + profile;
// See if we have to make a interface.
@@ -120,29 +120,29 @@ void InterfaceSetupImp::setProfile(const QString &profile){
// We must have a valid interface to get this far so read some settings.
// DHCP
bool error = false;
if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
dhcpCheckBox->setChecked(true);
else
dhcpCheckBox->setChecked(false);
leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
if(error)
leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
if(error)
leaseTime->setValue(24);
// IP Information
autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
- QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
+ QString dns = interfaces->getInterfaceOption("up interfacednsscript -a", error);
if(dns.contains(" ")){
firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
}
ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
}
// interfacesetup.cpp