@@ -22,10 +22,13 @@
|
|||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
#include <GroupLayout.h>
|
#include <GroupLayout.h>
|
||||||
#include <GroupLayoutBuilder.h>
|
#include <GroupLayoutBuilder.h>
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
|
#include <Path.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -99,7 +102,34 @@ InterfacesAddOn::Save()
|
|||||||
InterfaceView* settingsView = _SettingsView();
|
InterfaceView* settingsView = _SettingsView();
|
||||||
if (settingsView != NULL)
|
if (settingsView != NULL)
|
||||||
settingsView->Apply();
|
settingsView->Apply();
|
||||||
return fListView->SaveItems();
|
|
||||||
|
BString settingsData;
|
||||||
|
|
||||||
|
status_t result = fListView->SaveItems(settingsData);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (settingsData.IsEmpty()) {
|
||||||
|
// Nothing to save, all interfaces are auto-configured
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BPath path;
|
||||||
|
result = find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path, true);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
path.Append("network");
|
||||||
|
create_directory(path.Path(), 0755);
|
||||||
|
|
||||||
|
path.Append("interfaces");
|
||||||
|
|
||||||
|
BFile settingsFile(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
|
result = settingsFile.Write(settingsData.String(),settingsData.Length());
|
||||||
|
if (result != settingsData.Length())
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ InterfacesListView::FindItem(BPoint where)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
InterfacesListView::SaveItems()
|
InterfacesListView::SaveItems(BString& settingsData)
|
||||||
{
|
{
|
||||||
// Grab each fSettings instance and write it's settings
|
// Grab each fSettings instance and write it's settings
|
||||||
for (int32 i = CountItems(); i-- > 0;) {
|
for (int32 i = CountItems(); i-- > 0;) {
|
||||||
@@ -504,8 +504,8 @@ InterfacesListView::SaveItems()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
NetworkSettings* ns = item->GetSettings();
|
NetworkSettings* ns = item->GetSettings();
|
||||||
// TODO : SetConfiguration doesn't use the interface settings file
|
|
||||||
ns->SetConfiguration();
|
ns->SetConfiguration();
|
||||||
|
settingsData << ns->GenerateConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
|
|
||||||
InterfaceListItem* FindItem(const char* name);
|
InterfaceListItem* FindItem(const char* name);
|
||||||
InterfaceListItem* FindItem(BPoint where);
|
InterfaceListItem* FindItem(BPoint where);
|
||||||
status_t SaveItems();
|
status_t SaveItems(BString& settingsData);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
|
|||||||
@@ -339,13 +339,76 @@ NetworkSettings::LoadConfiguration()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! WriteConfiguration reads this classes settings and write them to
|
/*! GenerateConfiguration reads this classes settings and write them to
|
||||||
the current interface configuration file that NetServer watches for.
|
a BString. This can then be put in the interfaces settings file to make
|
||||||
|
the settings persistant.
|
||||||
*/
|
*/
|
||||||
void
|
BString
|
||||||
NetworkSettings::WriteConfiguration()
|
NetworkSettings::GenerateConfiguration()
|
||||||
{
|
{
|
||||||
|
// TODO should use ProtocolVersions to know which protocols are there
|
||||||
|
bool autoConfigure = true;
|
||||||
|
if (!IsDisabled()) {
|
||||||
|
for (int i = 0; i < MAX_PROTOCOLS; i++) {
|
||||||
|
if (fProtocols[i].present && strlen(IP(fProtocols[i].inet_id)) != 0
|
||||||
|
&& !AutoConfigure(fProtocols[i].inet_id)) {
|
||||||
|
autoConfigure = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the interface is fully autoconfigured, don't include it in the
|
||||||
|
// settings file.
|
||||||
|
if (autoConfigure)
|
||||||
|
return BString();
|
||||||
|
|
||||||
|
BString result;
|
||||||
|
|
||||||
|
result.SetToFormat("interface %s {\n", Name());
|
||||||
|
|
||||||
|
if (IsDisabled())
|
||||||
|
result << "\tdisabled\ttrue\n";
|
||||||
|
else {
|
||||||
|
for (int i = 0; i < MAX_PROTOCOLS; i++) {
|
||||||
|
if (fProtocols[i].present && strlen(IP(fProtocols[i].inet_id)) != 0
|
||||||
|
&& !AutoConfigure(fProtocols[i].inet_id)) {
|
||||||
|
result << "\taddress {\n";
|
||||||
|
|
||||||
|
result << "\t\tfamily\t";
|
||||||
|
if (fProtocols[i].inet_id == AF_INET)
|
||||||
|
result << "inet\n";
|
||||||
|
else if (fProtocols[i].inet_id == AF_INET6)
|
||||||
|
result << "inet6\n";
|
||||||
|
else {
|
||||||
|
// FIXME the struct protocols should know the name to use.
|
||||||
|
debugger("Unknown protocol found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
result << "\t\taddress\t" << IP(fProtocols[i].inet_id) << "\n";
|
||||||
|
result << "\t\tgateway\t" << Gateway(fProtocols[i].inet_id)
|
||||||
|
<< "\n";
|
||||||
|
result << "\t\tmask\t" << Netmask(fProtocols[i].inet_id)
|
||||||
|
<< "\n";
|
||||||
|
result << "\t}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (!networks.empty()) {
|
||||||
|
for (size_t index = 0; index < networks.size(); index++) {
|
||||||
|
wireless_network& network = networks[index];
|
||||||
|
fprintf(fp, "\tnetwork %s {\n", network.name);
|
||||||
|
fprintf(fp, "\t\tmac\t%s\n",
|
||||||
|
network.address.ToString().String());
|
||||||
|
fprintf(fp, "\t}\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
result << "}\n\n";
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,10 +109,10 @@ public:
|
|||||||
void ReadConfiguration();
|
void ReadConfiguration();
|
||||||
void SetConfiguration();
|
void SetConfiguration();
|
||||||
|
|
||||||
/* Grab and write interface settings from interface configuration
|
/* Grab interface settings from interface configuration file */
|
||||||
file and let NetServer sort it out */
|
|
||||||
void LoadConfiguration();
|
void LoadConfiguration();
|
||||||
void WriteConfiguration();
|
/* Generate settings file entry suitable for interfaces settings */
|
||||||
|
BString GenerateConfiguration();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _DetectProtocols();
|
status_t _DetectProtocols();
|
||||||
|
|||||||
Reference in New Issue
Block a user