dslinux/user/pixil/apps/fltk/netconfig Makefile dns_setup.cxx dns_setup.h ip_input.cxx ip_input.h ip_setup.cxx ip_setup.h net_config.cxx net_config.h ppp_modem.cxx ppp_modem.h ppp_status.h
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:24:28 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/apps/fltk/netconfig
In directory antilope:/tmp/cvs-serv11916/apps/fltk/netconfig
Added Files:
Makefile dns_setup.cxx dns_setup.h ip_input.cxx ip_input.h
ip_setup.cxx ip_setup.h net_config.cxx net_config.h
ppp_modem.cxx ppp_modem.h ppp_status.h
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: ppp_modem.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef PPP_MODEM_H
#define PPP_MODEM_H
/////// Includes ////////
#include <FL/Fl_Group.H>
#include <FL/forms.H>
#include <FL/Fl_Tabs.H>
#include <nxapp.h>
#include <nxwindow.h>
#include <nxholdbrowser.h>
#include <nxbutton.h>
#include <nxmenubutton.h>
#include <nxradioroundbutton.h>
#include <nxcheckbutton.h>
#include <nxmultilineinput.h>
#include <nxinput.h>
#include "ip_input.h"
extern "C"
{
#include <pixlib/pixlib.h>
#include <pixlib/pix_comm_proto.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
}
//////// Defines ////////
#define SCRIPT_PREFIX "/tmp/ppp/chat-"
#define ACCOUNT_FILE "/tmp/ppp/accounts"
#define DEVICE_FILE "/tmp/ppp/devices"
#define DIALER_FILE "/etc/wvdial.conf"
#define CONFIG_FILE "/tmp/ppp/config"
#define PPP_TMP_DIR "/tmp/ppp"
#define PPP_PEER_DIR "/etc/ppp/peers"
#define MODE_RDWRX S_IRWXU|S_IRWXG|S_IRWXO
#define MODE_RDX S_IROTH|S_IXOTH|S_IRGRP|S_IXGRP|S_IRUSR|S_IXUSR|S_IWUSR
#define MODE_RDWR S_IROTH|S_IWOTH|S_IWGRP|S_IRGRP|S_IRUSR|S_IWUSR
//////// static const ////////
static const int MAX_PPP_DEVS = 10;
static const int MAX_ACCOUNTS = 512;
static const int MAX_LINE_LEN = 255;
static const int MAX_PATH_LEN = 30;
static const int MAX_STR_LEN = 40;
static const int MAX_ARGS = 100;
static const int MAX_SCRIPT_SIZE = 4096;
//////// Classes ////////
class PPP_Add_Account;
class PPP_Account;
class PPP_Modem;
class PPP_Add_Config;
///////////////////////////////////////////////////////////
//
// class: PPP_Add_Account
// description: This class defines the ui for adding an
// account.
//
///////////////////////////////////////////////////////////
class PPP_Add_Account
{
NxPimWindow *add_win;
NxInput *add_general_account;
NxInput *add_general_phone;
NxInput *add_general_username;
NxInput *add_general_password;
public:
NxButton * ok_button;
NxButton *cancel_button;
Fl_Group *add_general_group;
FL_EXPORT void set_max_values();
FL_EXPORT void set_account_value(const char *);
FL_EXPORT void set_phone_value(const char *);
FL_EXPORT void set_username_value(const char *);
FL_EXPORT void set_password_value(const char *);
FL_EXPORT const char *get_account_value();
FL_EXPORT const char *get_phone_value();
FL_EXPORT const char *get_username_value();
FL_EXPORT const char *get_password_value();
Fl_Window *get_parent_win()
{
return add_win->GetWindowPtr();
}
FL_EXPORT void set_secret();
FL_EXPORT PPP_Add_Account();
FL_EXPORT ~ PPP_Add_Account();
};
///////////////////////////////////////////////////////////
//
// Class: PPP_Account
// Description: This class defines the ui for viewong and
// and manipulating accounts
//
///////////////////////////////////////////////////////////
class PPP_Account
{
NxPimWindow *acct_win;
PPP_Modem *account_modem;
Fl_Group *ppp_account_group;
NxButton *ppp_add_account_button;
NxButton *ppp_edit_account_button;
NxButton *ppp_delete_account_button;
NxHoldBrowser *ppp_account_browser;
NxMenuButton *ppp_account_choice;
FL_EXPORT void edit_account_value(PPP_Add_Account *);
FL_EXPORT void change_account_value(PPP_Add_Account *);
FL_EXPORT const char *get_account_value(PPP_Add_Account *);
FL_EXPORT void write_account(PPP_Add_Account *);
FL_EXPORT void add_account(PPP_Add_Account *);
FL_EXPORT void edit_account(PPP_Add_Account *);
FL_EXPORT int get_account_names();
FL_EXPORT void fill_account_browser();
static FL_EXPORT void ppp_add_account_cb(Fl_Widget *, void *parent);
static FL_EXPORT void ppp_delete_account_cb(Fl_Widget *, void *parent);
FL_EXPORT int get_num_accounts();
FL_EXPORT char **get_account_names_array();
public:
FL_EXPORT void hide();
FL_EXPORT void show();
Fl_Window *get_parent_win()
{
return acct_win->GetWindowPtr();
}
PPP_Modem *get_ppp_modem()
{
return account_modem;
}
FL_EXPORT PPP_Account(PPP_Modem * this_modem);
FL_EXPORT ~ PPP_Account();
};
///////////////////////////////////////////////////////////
//
// Class PPP_Add_Config
// Descriptions This class defines the ui for adding a config
//
///////////////////////////////////////////////////////////
class PPP_Add_Config
{
NxPimWindow *config_win;
NxMenuButton *ppp_add_config_dev_choice;
NxMenuButton *ppp_add_config_speed_choice;
NxCheckButton *dhcp_button;
NxCheckButton *auto_button;
IP_Input *ppp_add_config_ip_dest;
IP_Input *ppp_add_config_ip_source;
IP_Input *ppp_add_config_gateway;
IP_Input *ppp_add_config_broadcast;
NxInput *ppp_add_config_input;
NxInput *add_dns_domain;
IP_Input *add_dns_ip;
NxMultilineInput *ppp_add_config_script;
static void device_cb(Fl_Widget * fl, void *o = 0)
{
fl->label(((NxMenuButton *) fl)->text());
fl->redraw();
}
static void speed_cb(Fl_Widget * fl, void *o = 0)
{
fl->label(((NxMenuButton *) fl)->text());
fl->redraw();
}
static void ppp_add_config_dhcp_cb(Fl_Widget *, void *parent);
static void ppp_add_config_auto_cb(Fl_Widget *, void *parent);
public:
NxButton * ok_button;
NxButton *cancel_button;
Fl_Group *ppp_add_config_group;
FL_EXPORT void set_max_values();
FL_EXPORT void set_config_value(char *);
FL_EXPORT void set_device_value(char *);
FL_EXPORT void set_device_value(int val)
{
ppp_add_config_dev_choice->value(val);
}
FL_EXPORT void set_speed_value(char *);
FL_EXPORT void set_speed_value(int val)
{
ppp_add_config_speed_choice->value(val);
}
FL_EXPORT void set_dest_value(char *);
FL_EXPORT void set_source_value(char *);
FL_EXPORT void set_broadcast_value(char *);
FL_EXPORT void set_gateway_value(char *);
FL_EXPORT void set_dhcp_value(char *);
FL_EXPORT void set_auto_value(char *);
FL_EXPORT void set_script_value(char *);
const char *get_auto_value();
const char *get_dhcp_value();
const char *get_config_value();
const char *get_device_value();
const char *get_speed_value();
const char *get_dest_value();
const char *get_source_value();
const char *get_broadcast_value();
const char *get_gateway_value();
const char *get_script_value();
FL_EXPORT void get_ttys();
FL_EXPORT void fill_dev_choice();
FL_EXPORT void fill_speed_choice();
FL_EXPORT void set_dns_domain_value(const char *);
FL_EXPORT void set_dns_ip_value(char *);
FL_EXPORT const char *get_dns_domain_value();
FL_EXPORT const char *get_dns_ip_value();
void set_ip_info();
Fl_Window *get_parent_window()
{
return config_win->GetWindowPtr();
}
FL_EXPORT void hide();
FL_EXPORT void show();
FL_EXPORT PPP_Add_Config();
FL_EXPORT ~ PPP_Add_Config();
};
///////////////////////////////////////////////////////////
//
// Class PPP_Modem_Setup
// Description This class defines the ui for manipulating
// the ui for configurations
//
///////////////////////////////////////////////////////////
class PPP_Modem_Setup
{
NxPimWindow *modem_setup_win;
PPP_Modem *account_modem;
Fl_Group *ppp_setup_group;
NxButton *save_button;
NxHoldBrowser *ppp_modem_setup_browser;
NxButton *ppp_modem_setup_add_button;
NxButton *ppp_modem_setup_edit_button;
NxButton *ppp_modem_setup_delete_button;
static void ppp_add_config_cb(Fl_Widget *, void *parent);
static void ppp_delete_config_cb(Fl_Widget *, void *parent);
public:
FL_EXPORT void get_devices();
FL_EXPORT void set_speed(int);
const char *get_config_value(PPP_Add_Config * config)
{
return config->get_config_value();
}
FL_EXPORT void edit_config_value(PPP_Add_Config *);
FL_EXPORT void edit_config(PPP_Add_Config *);
FL_EXPORT void add_config(PPP_Add_Config *);
FL_EXPORT void write_config(PPP_Add_Config *);
FL_EXPORT void change_config_value(PPP_Add_Config *);
FL_EXPORT void fill_config_browser();
FL_EXPORT void get_script_file(char *, PPP_Add_Config *);
FL_EXPORT void write_script_file(char *, PPP_Add_Config *);
PPP_Modem *get_ppp_modem()
{
return account_modem;
}
FL_EXPORT void hide();
FL_EXPORT void show();
Fl_Window *get_parent_win()
{
return modem_setup_win->GetWindowPtr();
}
FL_EXPORT PPP_Modem_Setup(PPP_Modem * this_modem);
FL_EXPORT ~ PPP_Modem_Setup();
};
///////////////////////////////////////////////////////////
//
// Class PPP_Modem
// descriptions This class defines the ui for manipulating
// accounts and configs for a modem.
//
///////////////////////////////////////////////////////////
class PPP_Modem
{
bool _active;
int _status;
pix_comm_ppp_options_t ppp_options;
pix_comm_ppp_info_t ppp_info;
pix_comm_interface_t ppp_list[MAX_PPP_DEVS];
int ppp_count;
NxPimWindow *modem_win;
Fl_Group *ppp_modem_group;
// NxMenuButton *ppp_config_choice;
NxMenuButton *ppp_config_choice;
NxMenuButton *ppp_modem_speed;
NxMenuButton *ppp_account_choice;
NxButton *ppp_connect_button;
NxButton *ppp_account_setup_button;
NxButton *ppp_device_setup_button;
NxOutput *ppp_status_box;
PPP_Modem_Setup *ppp_device_setup;
PPP_Account *modem_account;
PPP_Add_Account *modem_add_account;
static void config_cb(Fl_Widget * fl, void *o = 0)
{
fl->label(((NxMenuButton *) fl)->text());
fl->redraw();
}
static void account_cb(Fl_Widget * fl, void *o = 0)
{
fl->label(((NxMenuButton *) fl)->text());
fl->redraw();
}
static void ppp_connect_button_cb(Fl_Widget *, void *parent);
static void ppp_account_setup_cb(Fl_Widget *, void *parent);
static void ppp_device_setup_cb(Fl_Widget *, void *parent);
public:
NxButton * cancel_button;
NxButton *ok_button;
PPP_Account *_acct;
PPP_Add_Config *_add_config;
PPP_Add_Account *_add_account;
FL_EXPORT void get_accounts();
FL_EXPORT void get_configs();
FL_EXPORT void get_devices();
FL_EXPORT void add_account(char *account)
{
ppp_account_choice->add(account);
}
FL_EXPORT void add_config(char *config)
{
ppp_config_choice->add(config);
}
FL_EXPORT void hide();
FL_EXPORT void show();
FL_EXPORT void set_ppp_options();
pix_comm_ppp_options_t get_ppp_options()
{
return ppp_options;
}
bool get_active_status()
{
return _active;
}
void set_active_status(bool status)
{
_active = status;
}
void set_status_box(char *status)
{
ppp_status_box->value(status);
}
void set_status_box();
int get_status()
{
return _status;
}
void set_status(int status)
{
_status = status;
}
int get_num_accounts() const
{
return (ppp_account_choice->size() - 1);
}
int get_num_configs() const
{
return (ppp_config_choice->size() - 1);
}
const char *get_account_name(int i)
{
return ppp_account_choice->text(i);
}
const char *get_config_name(int i)
{
return ppp_config_choice->text(i);
}
FL_EXPORT void delete_account(int i)
{
fl_delete_menu_item(ppp_account_choice, i);
}
FL_EXPORT void delete_config(int i)
{
fl_delete_menu_item(ppp_config_choice, i);
}
void check_ppp_dirs();
void get_script(char *);
char **set_pppd_command(char *, int *);
Fl_Window *get_parent_win()
{
return modem_win->GetWindowPtr();
}
FL_EXPORT PPP_Modem(Fl_Window * win);
FL_EXPORT ~ PPP_Modem();
};
#endif
--- NEW FILE: ip_setup.cxx ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#include "ip_setup.h"
#include "net_config.h"
extern "C"
{
#include <pixlib/pixlib.h>
#include <pixlib/pix_comm_proto.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
}
#include <nxoutput.h>
Fl_Menu_Item ipMenuItems[] = {
{"TCP/IP Setup", 0, NetConfig::show_ip},
{"DNS Setup", 0, NetConfig::show_dns},
{"Modem Setup", 0, NetConfig::show_modem},
{0},
{0}
};
IP_Setup *
IP_Setup::_inst;
char *
IP_Setup::netconf;
char *
IP_Setup::get_ip_value()
{
ip_address_->get_ip_inputs(false);
return ip_address_->get_ip_inputs(false);
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::set_wireless_value()
// Description: This function set the value of the
// wireles button depending if the interface
// exists or not
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::set_have_wireless_value()
{
if (PIX_COMM_OK == pix_comm_wireless_get_name(DEV_ETH0, wireless_name)) {
if (0 == strcmp(wireless_name, WNAME)) {
have_wireless_lan_ = true;
}
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::get_dhcp_value()
// Description: This function returns the value of the
// dhcp button
// Parametets: none
// Returns: bool - true if button is pressed
// false if button is not pressed
//
//////////////////////////////////////////////////////////
bool IP_Setup::get_dhcp_value()
{
if (0 == dhcp_button_->value()) {
return false;
} else {
return true;
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::dhcp_button_cb()
// Description: This function is the callback when the
// dhcp button is pressed. It causes the input boxes
// to either be activated or deactivated depending
// on the state of the dhcp button.
// Parametets: Fl_Widget *widget - widget doing the calling
// void *parent - the widgets parent
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::dhcp_button_cb(Fl_Widget * widget, void *parent)
{
IP_Setup *ip_setup = (IP_Setup *) parent;
NxCheckButton *button = (NxCheckButton *) widget;
if (0 == button->value()) {
ip_setup->ip_address_->activate();
ip_setup->netmask_->activate();
ip_setup->broadcast_->activate();
ip_setup->gateway_->activate();
}
if (1 == button->value()) {
ip_setup->ip_address_->deactivate();
ip_setup->netmask_->deactivate();
ip_setup->broadcast_->deactivate();
ip_setup->gateway_->deactivate();
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::start_stop_button_cb()
// Description: This function is the callback when the
// the start_stop_button is pressed. It either stops
// or starts the network depending on the status
// of the network.
// Parametets: Fl_Widget *widget - widget doing the calling
// void *parent - the widgets parent
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::start_stop_button_cb(Fl_Widget * widget, void *parent)
{
IP_Setup *ip_parent = (IP_Setup *) parent;
NetConfig::I()->write_net_values();
if (PIX_COMM_ACTIVE == ip_parent->get_eth0_active_status() ||
PIX_COMM_ACTIVE == ip_parent->get_wvlan_active_status()) {
IP_Setup::IP()->net_down();
ip_parent->start_stop_button_->label("Start");
ip_parent->start_stop_button_->redraw();
} else {
IP_Setup::IP()->net_up();
ip_parent->start_stop_button_->label("Stop");
ip_parent->start_stop_button_->redraw();
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::set_button_label
// Description: This function sets the label on the start_stop_button
// determined by if the network is active or not
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::set_button_label()
{
if (PIX_COMM_ACTIVE == eth0_active_ || PIX_COMM_ACTIVE == wvlan_active_) {
start_stop_button_->label("Stop");
} else {
start_stop_button_->label("Start");
}
start_stop_button_->redraw();
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::set_button_cb
// Description: This function is the call made when the
// set button is pressed. It saves the input box
// values, stops the network and brings the
// network back up
// Parametets: Fl_Widget *widget - widget that is doing the call
// void *parent - parent object of the widget
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::set_button_cb(Fl_Widget * widget, void *parent)
{
IP_Setup *ip_parent = (IP_Setup *) parent;
int err = 0;
char *keys[MAX_KEYS];
char *vals[MAX_KEYS];
for (int i = 0; i < MAX_KEYS; i++) {
keys[i] = new char[MAX_VALS];
vals[i] = new char[MAX_VALS];
keys[i][0] = '\0';
vals[i][0] = '\0';
}
strcpy(keys[DEVICE], KEY_DEVICE);
strcpy(keys[PROTO], KEY_PROTO);
strcpy(keys[IPADDR], KEY_IPADDR);
strcpy(keys[NETMASK], KEY_NETMASK);
strcpy(keys[BROADCAST], KEY_BROADCAST);
strcpy(keys[GATEWAY], KEY_GATEWAY);
strcpy(keys[ESSID], KEY_ESSID);
strcpy(keys[WEPID], KEY_WEPID);
// Set device
if (ip_parent->have_dev_eth0_)
strcpy(vals[DEVICE], DEV_ETH0);
// Get string values for ip, netmask, broadcast, essid, and wepid
strcpy(vals[IPADDR], ip_parent->get_ip_value());
strcpy(vals[NETMASK], ip_parent->get_netmask_value());
strcpy(vals[BROADCAST], ip_parent->get_broadcast_value());
strcpy(vals[GATEWAY], ip_parent->get_gateway_value());
if (ip_parent->wireless_check->value()) {
char essid_tmp[MAX_VALS];
essid_tmp[0] = '\0';
strcpy(essid_tmp, "\"");
strcat(essid_tmp, ip_parent->essid_input->value());
strcat(essid_tmp, "\"");
strcpy(vals[ESSID], essid_tmp);
if (ip_parent->wep_check->value())
strcpy(vals[WEPID], ip_parent->wep_input->value());
}
// Take the network down
err = IP_Setup::IP()->net_down();
NetConfig::I()->write_net_values();
if (0 == err) {
// Write new netscript values
if (ip_parent->have_wireless_lan_) {
pix_comm_set_netscript_values(netconf, (const char **) keys,
(const char **) vals, MAX_KEYS);
} else {
pix_comm_set_netscript_values(netconf, (const char **) keys, (const char **) vals, MAX_KEYS - 2); // no essid and no wepid
}
err = IP_Setup::IP()->net_up();
ip_parent->get_ip_info();
// Memory management
for (int i = 0; i < MAX_KEYS; i++) {
delete[]keys[i];
delete[]vals[i];
keys[i] = NULL;
vals[i] = NULL;
}
}
ip_parent->set_button_label();
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::reset_button_cb
// Description: This function is the call made when the
// reset button is pressed. It changes the values
// of the inputs boxes back to the last saved state
// Parametets: Fl_Widget *widget - widget that is doing the call
// void *parent - parent object of the widget
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::reset_button_cb(Fl_Widget * widget, void *parent)
{
IP_Setup *ip_parent = (IP_Setup *) parent;
ip_parent->get_ip_info();
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::set_have_if_flags
// Description: This function set the have_dev_eth0 and have_wvlan
// flags
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::set_have_if_flags()
{
int err = 0;
int count = MAX_ETH_DEVS;
int wcount = MAX_ETH_DEVS;
pix_comm_interface_t eth_list[MAX_ETH_DEVS];
pix_comm_interface_t wireless_list[MAX_ETH_DEVS];
err = pix_comm_wireless_get_if_list(wireless_list, &wcount);
if (0 <= err) {
err = -1;
for (int idx = 0; idx <= count; idx++) {
if (0 == strcmp(wireless_list[idx].name, WV_LAN)) {
have_dev_wvlan_ = true;
err = 0;
break;
}
}
}
err = pix_comm_get_if_list(PIX_COMM_TYPE_ETHERNET, eth_list, &count);
if (0 <= err) {
err = -1;
for (int idx = 0; idx <= count; idx++) {
if (0 == strcmp(eth_list[idx].name, DEV_ETH0)) {
have_dev_eth0_ = true;
err = 0;
break;
}
}
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::get_ip_info
// Description: This function loads the ipnut boxes of the
// user interface, it gets the values from
// reading values from current network settings
// or from a specified file, and then writes
// out the settings by calling write_net_values.
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::get_ip_info()
{
char dhcp;
pix_comm_ipaddr_t ip_info;
char essid_tmp[MAX_VALS];
char *keys[MAX_KEYS];
char *vals[MAX_KEYS];
for (int i = 0; i < MAX_KEYS; i++) {
keys[i] = new char[MAX_VALS];
vals[i] = new char[MAX_VALS];
keys[i][0] = '\0';
vals[i][0] = '\0';
}
strcpy(keys[DEVICE], KEY_DEVICE);
strcpy(keys[PROTO], KEY_PROTO);
strcpy(keys[IPADDR], KEY_IPADDR);
strcpy(keys[NETMASK], KEY_NETMASK);
strcpy(keys[BROADCAST], KEY_BROADCAST);
strcpy(keys[GATEWAY], KEY_GATEWAY);
strcpy(keys[ESSID], KEY_ESSID);
strcpy(keys[WEPID], KEY_WEPID);
// currently can only get config for one dev
// get wvlan first for wirelless because
// eth0 can also be wirelless
if (true == have_dev_wvlan_) {
pix_comm_get_ip_address(WV_LAN, &ip_info);
wvlan_active_ = pix_comm_if_active(WV_LAN);
}
if (true == have_dev_eth0_) {
pix_comm_get_ip_address(DEV_ETH0, &ip_info);
eth0_active_ = pix_comm_if_active(DEV_ETH0);
strcpy(vals[DEVICE], DEV_ETH0);
}
if (true == have_wireless_lan_) {
wireless_check->value(1);
wireless_check->do_callback();
essid_tmp[0] = '\0';
pix_comm_wireless_get_essid(DEV_ETH0, essid_tmp);
strcpy(vals[ESSID], "\"");
strcat(vals[ESSID], essid_tmp);
strcat(vals[ESSID], "\"");
pix_comm_wireless_get_encode(DEV_ETH0, vals[WEPID]);
if (vals[ESSID][0] != 0) {
essid_input->value(essid_tmp);
if (vals[WEPID][0] != 0) {
wep_check->value(1);
wep_check->do_callback();
wep_input->value(vals[WEPID]);
}
}
} else {
wireless_check->value(0);
essid_input->value("");
wep_check->value(0);
wep_input->value("");
wireless_check->do_callback();
wep_check->do_callback();
}
set_button_label();
set_status_box(TYPE_ETH);
set_status_box(TYPE_WVLAN);
// Set str values for ip, netmask, and broadcast
sprintf(vals[IPADDR], "%d.%d.%d.%d",
(unsigned char) (ip_info.addr >> 24) & 0xFF,
(unsigned char) (ip_info.addr >> 16) & 0xFF,
(unsigned char) (ip_info.addr >> 8) & 0xFF,
(unsigned char) ip_info.addr & 0xFF);
sprintf(vals[NETMASK], "%d.%d.%d.%d",
(unsigned char) (ip_info.netmask >> 24) & 0xFF,
(unsigned char) (ip_info.netmask >> 16) & 0xFF,
(unsigned char) (ip_info.netmask >> 8) & 0xFF,
(unsigned char) ip_info.netmask & 0xFF);
sprintf(vals[BROADCAST], "%d.%d.%d.%d",
(unsigned char) (ip_info.broadcast >> 24) & 0xFF,
(unsigned char) (ip_info.broadcast >> 16) & 0xFF,
(unsigned char) (ip_info.broadcast >> 8) & 0xFF,
(unsigned char) ip_info.broadcast & 0xFF);
ip_address_->set_ip_inputs(vals[IPADDR], true);
netmask_->set_ip_inputs(vals[NETMASK], true);
broadcast_->set_ip_inputs(vals[BROADCAST], true);
// Set gateway
char buf[255];
if (PIX_COMM_ACTIVE == eth0_active_ || PIX_COMM_ACTIVE == wvlan_active_) {
unsigned long gway;
pix_comm_get_default_gateway(&gway);
sprintf(vals[GATEWAY], "%d.%d.%d.%d",
(unsigned char) (gway >> 24) & 0xFF,
(unsigned char) (gway >> 16) & 0xFF,
(unsigned char) (gway >> 8) & 0xFF,
(unsigned char) gway & 0xFF);
} else {
FILE *fp = fopen(GATEWAY_FILE, "r");
if (NULL != fp) {
if (NULL != fgets(buf, sizeof(buf) - 1, fp)) {
fclose(fp);
strncpy(vals[GATEWAY], buf, sizeof(vals[GATEWAY]));
}
}
}
gateway_->set_ip_inputs(vals[GATEWAY], true);
pix_sys_get_net_value(DHCP, &dhcp);
if ('Y' == dhcp || 'y' == dhcp) {
dhcp_button_->value(1);
strcpy(vals[PROTO], "dynamic");
} else {
dhcp_button_->value(0);
strcpy(vals[PROTO], "static");
}
dhcp_button_->do_callback();
if (have_wireless_lan_)
pix_comm_set_netscript_values(netconf, (const char **) keys,
(const char **) vals, MAX_KEYS);
else
pix_comm_set_netscript_values(netconf, (const char **) keys, (const char **) vals, MAX_KEYS - 2); // don't include ESSID/WEPID keys
NetConfig::I()->write_net_values();
set_button_label();
for (int i = 0; i < MAX_KEYS; i++) {
delete[]keys[i];
delete[]vals[i];
keys[i] = NULL;
vals[i] = NULL;
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::set_status_box
// Description: This function sets the text in the status_box_
// Parametets: char *status - string containing status
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::set_status_box(int type, char *status)
{
if (TYPE_ETH == type) {
eth0_status_box_->value(status);
eth0_status_box_->redraw();
}
if (TYPE_WVLAN == type) {
wvlan_status_box_->value(status);
wvlan_status_box_->redraw();
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::set_status_box
// Description: This function sets the text in the status_box_
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Setup::set_status_box(int type)
{
char *status;
if (TYPE_ETH == type) {
if (PIX_COMM_ACTIVE == eth0_active_) {
status = " Interface eth0 is active";
} else {
status = " Interface eth0 is not active";
}
eth0_status_box_->value(status);
eth0_status_box_->redraw();
}
if (TYPE_WVLAN == type) {
if (PIX_COMM_ACTIVE == wvlan_active_) {
status = " Interface wvlan0 is active";
} else {
status = " Interface wvlan0 is not active";
}
wvlan_status_box_->value(status);
wvlan_status_box_->redraw();
}
}
///////////////////////////////////////////////////////////
//
// Method net_down()
// Description: This function brings the ethernet down
// Parametets: none
// Returns: int err
//
//////////////////////////////////////////////////////////
int
IP_Setup::net_down()
{
pid_t childpid;
int child_status;
int idx;
int err = 0;
// bool have_dev_wvlan0 = get_have_wvlan0_value();
bool dhcp_state = get_dhcp_value();
//bool have_dev_eth0 = get_have_dev_eth0_value();
if ((childpid = fork()) == -1) {
perror("net_down (FORK)");
return (PIX_COMM_ERROR);
} else if (childpid == 0) {
for (idx = 3; idx < 20; idx++)
close(idx);
err = execl("/bin/sh", "sh", ifdown, netconf, NULL);
exit(0);
} // in parent
else {
waitpid(childpid, &child_status, 0);
if (0 == child_status) {
set_eth0_active_status(PIX_COMM_INACTIVE);
set_dhcp_value(dhcp_state);
} else {
perror("net_down (EXECL)");
set_status_box(TYPE_ETH, " Error shutting down interface eth0");
}
return child_status;
}
}
//////////////////////////////////////////////////////////
//
// Function: net_up
// Description: this function brings the ethernet up
// Parameters: none
// Return: int err
//
//////////////////////////////////////////////////////////
int
IP_Setup::net_up()
{
int err = 0;
bool dhcp_state = get_dhcp_value();
//bool have_dev_wvlan0 = get_have_wvlan0_value();
//bool have_dev_eth0 = get_have_dev_eth0_value();
pid_t childpid;
int child_status;
int idx;
if ((childpid = fork()) == -1) {
perror("net_down (FORK)");
return (PIX_COMM_ERROR);
} else if (childpid == 0) {
for (idx = 3; idx < 20; idx++)
close(idx);
err = execl("/bin/sh", "sh", ifup, netconf, NULL);
exit(0);
} // in parent
else {
waitpid(childpid, &child_status, 0);
if (0 == child_status) {
set_eth0_active_status(PIX_COMM_ACTIVE);
set_dhcp_value(dhcp_state);
} else if (err < 0) {
perror("net_up (EXECL)");
set_status_box(TYPE_ETH, " Error starting interface eth0");
}
return child_status;
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::IP_Setup
// Description: This function is the constructor for the IP_Setup
// object. It determines the look of the UI.
// Parametets: Fl_Tabs *tabs - pointer to the tabs that this
// object belongs to
// Fl_Window *win - pointer to the parent window
// of the object
// Returns: none
//
//////////////////////////////////////////////////////////
#include <iostream.h>
IP_Setup::IP_Setup()
{
_inst = this;
ifup = new char[255];
ifdown = new char[255];
netconf = new char[255];
getGblParStr("scripts", "ifup", ifup, 255);
getGblParStr("scripts", "ifdown", ifdown, 255);
getGblParStr("scripts", "netconf", netconf, 255);
cout << "ifup = " << ifup << endl;
cout << "ifdown = " << ifdown << endl;
cout << "netconf = " << netconf << endl;
wireless_name = new char[255];
ip_setup_win_ = new NxPimWindow("TCP/IP Setup", ipMenuItems, MENU);
NxApp::Instance()->add_window((Fl_Window *) ip_setup_win_->
GetWindowPtr());
ip_setup_group_ = new Fl_Group(W_X, W_Y, W_W, W_H);
int oset = 12;
// DHCP
dhcp_button_ = new NxCheckButton(BUTTON_X, MB_Y + (2 * oset), "DHCP");
dhcp_button_->callback(dhcp_button_cb, this);
// IP
int i_oset = 65;
ip_address_ =
new IP_Input(BUTTON_X + i_oset, MB_Y + (4 * oset), 140, 20,
"IP Address:");
netmask_ =
new IP_Input(BUTTON_X + i_oset, MB_Y + (6 * oset), 140, 20,
"Netmask:");
broadcast_ =
new IP_Input(BUTTON_X + i_oset, MB_Y + (8 * oset), 140, 20,
"Broadcast:");
gateway_ =
new IP_Input(BUTTON_X + i_oset, MB_Y + (10 * oset), 140, 20,
"Gateway:");
///////////
// Wireless
///////////
// Wireless NxCheckButton & callback (If checked, activate ESSID & WEP NxCheckButton & deactivate WEP NxInput)
wireless_check =
new NxCheckButton(BUTTON_X, MB_Y + (12 * oset), "Wireless");
wireless_check->callback(wireless_check_cb, &inputs);
// ESSID
////////
// ESSID NxInput box
essid_input =
new NxInput(BUTTON_X + i_oset - 5, MB_Y + (14 * oset), 130, 20,
"ESS ID:");
essid_input->deactivate();
inputs.essid_input = essid_input;
// WEP
//////
// WEP NxCheckButton & callback (If checked, activate WEP NxInput)
wep_check =
new NxCheckButton(BUTTON_X + oset + 6, MB_Y + (16 * oset), "WEP");
wep_check->deactivate();
inputs.wep_check = wep_check;
wep_check->callback(wep_check_cb, &inputs);
// WEP NxInput box
wep_input =
new NxInput(BUTTON_X + i_oset + 25, MB_Y + (18 * oset), 100, 20,
"WEP ID::");
wep_input->deactivate();
inputs.wep_input = wep_input;
// Status Box
eth0_status_box_ = new NxOutput(0, MB_Y + (17 * oset), W_W, 50, "");
NxApp::Instance()->big_font(eth0_status_box_);
eth0_status_box_->hide();
// Status Box (We don't need this any more)
wvlan_status_box_ = new NxOutput(30, 175, 180, 20, "");
wvlan_status_box_->hide();
// Buttons
set_button_ =
new NxButton(BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "Set");
set_button_->callback(set_button_cb, this);
start_stop_button_ =
new NxButton(BUTTON_X + (1 * BUTTON_WIDTH) + 3, BUTTON_Y,
BUTTON_WIDTH, BUTTON_HEIGHT, "Stop");
start_stop_button_->callback(start_stop_button_cb, this);
reset_button_ =
new NxButton(BUTTON_X + (2 * BUTTON_WIDTH) + 6, BUTTON_Y,
BUTTON_WIDTH, BUTTON_HEIGHT, "Reset");
reset_button_->callback(reset_button_cb, this);
ip_setup_group_->end();
ip_setup_win_->add((Fl_Widget *) ip_setup_group_);
set_status_box(TYPE_ETH);
set_status_box(TYPE_WVLAN);
set_have_if_flags(); // Sets have lo, eth0
set_have_wireless_value(); // Sets have wireless
//get_ip_info();
}
///////////////////////////////////////////////////////////
//
// Function: IP_Setup::~IP_Setup
// Description: This function is the deconstructor for the IP_Setup
// object.
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
IP_Setup::~IP_Setup()
{
delete[]ifup;
delete[]ifdown;
delete[]netconf;
delete[]wireless_name;
wireless_name = ifup = ifdown = netconf = NULL;
}
--- NEW FILE: dns_setup.cxx ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#include "dns_setup.h"
#include "net_config.h"
extern "C"
{
#include <pixlib/pixlib.h>
#include <pixlib/pix_comm_proto.h>
#include <stdio.h>
}
Fl_Menu_Item dnsMenuItems[] = {
{"TCP/IP Setup", 0, NetConfig::show_ip},
{"DNS Setup", 0, NetConfig::show_dns},
{"Modem Setup", 0, NetConfig::show_modem},
{0},
{0}
};
///////////////////////////////////////////////////////////
//
// Function: DNS_Setup::set_button_cb()
// Description: This function write out net values and restart
// the network
// Parametets: Fl_Widget *widget - widget calling the function
// void *parent - Parent object of the widget
// Returns: none
//
//////////////////////////////////////////////////////////
void
DNS_Setup::set_button_cb(Fl_Widget * widget, void *parent)
{
//DNS_Setup *dns_parent = (DNS_Setup *)parent;
int err = 0;
NetConfig::I()->write_net_values();
err = IP_Setup::IP()->net_down();
if (0 == err) {
IP_Setup::IP()->net_up();
}
}
///////////////////////////////////////////////////////////
//
// Function: DNS_Setup::defaults_button_cb()
// Description: This function restores the inputs to the last saved
// settings.
// Parametets: Fl_Widget *widget - widget calling the function
// void *parent - Parent object of the widget
// Returns: none
//
//////////////////////////////////////////////////////////
void
DNS_Setup::defaults_button_cb(Fl_Widget * widget, void *parent)
{
DNS_Setup *dns_parent = (DNS_Setup *) parent;
dns_parent->get_values_from_file();
}
///////////////////////////////////////////////////////////
//
// Function: DNS_Setup::get_values_from_file()
// Description: This function fills in the input boxes with
// values loaded from the appropriate files
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
DNS_Setup::get_values_from_file()
{
char domain[61];
char search[61];
char dns_1[17];
char dns_2[17];
char dns_3[17];
domain[0] = '\0';
search[0] = '\0';
dns_1[0] = '\0';
dns_2[0] = '\0';
dns_3[0] = '\0';
pix_sys_get_net_value(DOMAIN, domain);
pix_sys_get_net_value(SEARCH, search);
pix_sys_get_net_value(DNS_1, dns_1);
pix_sys_get_net_value(DNS_2, dns_2);
pix_sys_get_net_value(DNS_3, dns_3);
domain_->value(domain);
search_domain_->value(search);
dns1_ip_->set_ip_inputs(dns_1, false);
dns2_ip_->set_ip_inputs(dns_2, false);
dns3_ip_->set_ip_inputs(dns_3, false);
}
///////////////////////////////////////////////////////////
//
// Function: DNS_Setup::DNS_Setup()
// Description: This function is the constructor for the DNS_Setup
// object wich describes the UI.
// Parametets: Fl_Tabs *tabs - pointer to the group of tabs
// that the object belongs to.
// Fl_Window *win - pointer to the parent window
// Returns: none
//
//////////////////////////////////////////////////////////
DNS_Setup::DNS_Setup()
{
dns_win_ = new NxPimWindow("DNS Setup", dnsMenuItems, MENU);
NxApp::Instance()->add_window((Fl_Window *) dns_win_->GetWindowPtr());
dns_setup_group_ = new Fl_Group(W_X, W_Y, W_W, W_H);
int oset = 20;
// Domain
domain_ =
new NxInput(BUTTON_X + 90, MB_Y + (1 * MB_H + oset), 140, 20,
"Default Domain:");
domain_->maximum_size(60);
// DNS
dns1_ip_ =
new IP_Input(BUTTON_X + 90, MB_Y + (3 * MB_H + oset), 140, 20,
"Nameserver 1:");
dns2_ip_ =
new IP_Input(BUTTON_X + 90, MB_Y + (5 * MB_H + oset), 140, 20,
"Nameserver 2:");
dns3_ip_ =
new IP_Input(BUTTON_X + 90, MB_Y + (7 * MB_H + oset), 140, 20,
"Nameserver 3:");
// Search Domain
search_domain_ =
new NxInput(BUTTON_X + 90, MB_Y + (9 * MB_H + oset), 140, 20,
"Search domain:");
search_domain_->maximum_size(60);
// Buttons
defaults_button_ =
new NxButton(BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT,
"Reset");
defaults_button_->callback(defaults_button_cb, this);
set_button_ =
new NxButton(BUTTON_X + BUTTON_WIDTH + 3, BUTTON_Y, BUTTON_WIDTH,
BUTTON_HEIGHT, "Set");
set_button_->callback(set_button_cb, this);
dns_setup_group_->end();
dns_win_->add((Fl_Widget *) dns_setup_group_);
dns1_ip_->set_ip_inputs("", false);
dns2_ip_->set_ip_inputs("", false);
dns3_ip_->set_ip_inputs("", false);
get_values_from_file();
}
///////////////////////////////////////////////////////////
//
// Function: DNS_Setup::~DNS_Setup()
// Description: This function is the deconstructor for the DNS_Setup
// object
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
DNS_Setup::~DNS_Setup()
{
}
--- NEW FILE: net_config.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef NET_CONFIG_H
#define NET_CONFIG_H
#include <nxapp.h>
#include "ip_input.h"
#include "ppp_modem.h"
#include "ip_setup.h"
#include "dns_setup.h"
//////////// Constants //////////////////////////
#define GATEWAY_FILE "/tmp/gateway"
#define WV_LAN "wvlan0"
#define DEV_ETH0 "eth0"
#define DEV_LO "lo"
#define DEV_LO_LONG 2130706432L
#define BOOTPROTO "BOOTPROTO"
#define DOMAIN "DOMAIN"
#define SEARCH "SEARCH"
#define DNS_1 "DNS_1"
#define DNS_2 "DNS_2"
#define DNS_3 "DNS_3"
//#define NETMASK "NETMASK"
#define DHCP "DHCP"
//#define DEVICE "DEVICE"
//#define IPADDR "IPADDR"
#define ONBOOT "ONBOOT"
#define BOOTP "BOOTP"
#define PUMP "PUMP"
#define SUBNET "SUBNET"
//#define BROADCAST "BROADCAST"
#define MAX_TRIES 10
#define MAX_LEN 100
#define APP "Network"
class NetConfig:public NxApp
{
static NetConfig *_inst;
static pid_t pid;
NxWindow *cWin;
PPP_Modem *this_modem;
IP_Setup *this_ip_setup;
DNS_Setup *this_dns_setup;
////////////////////////////////////////////////////////////////////////////////
// FLNX-Colosseum IPC
virtual void ClientIPCHandler(int fd, void *o, int ipc_id = -1);
protected:
void MakeIPWin()
{
this_ip_setup = new IP_Setup();
}
void MakePPPWin()
{
this_modem = new PPP_Modem(cWin);
}
void MakeDNSWin()
{
this_dns_setup = new DNS_Setup();
}
public:
NetConfig(int argc, char *argv[]);
// Access pt.
static NetConfig *I()
{
assert(_inst);
return _inst;
}
void write_net_values();
static void show_modem(Fl_Widget * fl, void *o)
{
Fl_Window *tWin = I()->this_modem->get_parent_win();
NxApp::Instance()->show_window(tWin);
}
static void show_ip(Fl_Widget * fl, void *o)
{
Fl_Window *tWin = I()->this_ip_setup->get_parent_win();
NxApp::Instance()->show_window(tWin);
}
static void show_dns(Fl_Widget * fl, void *o)
{
Fl_Window *tWin = I()->this_dns_setup->get_parent_win();
NxApp::Instance()->show_window(tWin);
}
};
#endif
--- NEW FILE: net_config.cxx ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#include "net_config.h"
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/forms.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Browser.H>
#include <FL/Fl_Radio_Button.H>
#include <nxapp.h>
#include <nxwindow.h>
#include <nxbrowser.h>
#include <nxradioroundbutton.h>
#include <assert.h>
extern "C"
{
#include <pixlib/pixlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/wait.h>
}
about about_net_conf = {
"About Network Config",
"(c) 2001, Century Software.",
"jeffm at censoft.com",
"09/04/01",
"1.0"
};
NetConfig *
NetConfig::_inst;
pid_t NetConfig::pid;
void
NetConfig::ClientIPCHandler(int fd, void *o, int ipc_id)
{
char *tokenMsg = new char[MAX_LENGTH];
char *passMsg = new char[MAX_LENGTH];
memset(tokenMsg, 0, MAX_LENGTH);
memset(passMsg, 0, MAX_LENGTH);
if (o == NULL) {
int length = MAX_LENGTH - 1;
ipc_id = NxApp::Instance()->Read_Fd(passMsg, &length);
if ((passMsg == NULL) || (passMsg[0] == 0))
return;
else
strcpy(tokenMsg, passMsg);
} else if (ipc_id == -1) {
strcpy(tokenMsg, (char *) o);
strcpy(passMsg, (char *) o);
ipc_id = NxApp::Instance()->Find_Fd("nxnet");
} else {
strcpy(tokenMsg, (char *) o);
strcpy(passMsg, (char *) o);
}
// Explode Message
char *service = new char[MAX_LENGTH];
char *msg_cmd = new char[MAX_LENGTH];
char *data_item = new char[MAX_LENGTH];
// SERVICE
char *tmp = strtok(tokenMsg, TOKEN);
strcpy(service, tmp);
// MSG_CMD
tmp = strtok(NULL, TOKEN);
strcpy(msg_cmd, tmp);
// DATA_ITEM
tmp = strtok(NULL, TOKEN);
strcpy(data_item, tmp);
// Memory Mangement
delete[]service;
delete[]msg_cmd;
delete[]data_item;
delete[]tokenMsg;
service = msg_cmd = data_item = tokenMsg = NULL;
NxApp::Instance()->ServerIPCHandler(fd, ipc_id, (char *) passMsg);
delete[]passMsg;
passMsg = NULL;
}
//////////////////////////////////////////////////////////
//
//
// function: write_net_values
// description: this function writes out ethernet values
// parameters: none
// return: none
//
//////////////////////////////////////////////////////////
void
NetConfig::write_net_values()
{
pix_sys_ipaddr_str_t ip_v;
pix_sys_dns_t dom_v;
ip_v.addr = IP_Setup::IP()->get_ip_value();
ip_v.netmask = IP_Setup::IP()->get_netmask_value();
ip_v.broadcast = IP_Setup::IP()->get_broadcast_value();
ip_v.dhcp = (int) IP_Setup::IP()->get_dhcp_value();
ip_v.subnet = "";
ip_v.gateway = IP_Setup::IP()->get_gateway_value();
dom_v.domain = this_dns_setup->get_domain_value();
dom_v.search = this_dns_setup->get_search_value();
dom_v.long_dns_1 = this_dns_setup->get_dns1_lvalue();
dom_v.long_dns_2 = this_dns_setup->get_dns2_lvalue();
dom_v.long_dns_3 = this_dns_setup->get_dns3_lvalue();
dom_v.str_dns_1 = this_dns_setup->get_dns1_value();
dom_v.str_dns_2 = this_dns_setup->get_dns2_value();
dom_v.str_dns_3 = this_dns_setup->get_dns3_value();
pix_sys_write_net_values(ip_v, dom_v);
}
//////////////////////////////////////////////////////////
//
// Constructor
// description: this function starts the net_config
// user interface
// parameters: none
// return: none
//
//////////////////////////////////////////////////////////
NetConfig::NetConfig(int argc, char *argv[])
:
NxApp(APP)
{
//////////////////////////////////////
// Access pt. initialization
_inst = this;
NxApp::Instance()->set_keyboard(argc, argv);
NxApp::Instance()->set_about(about_net_conf);
this_modem = NULL;
this_ip_setup = NULL;
this_dns_setup = NULL;
cWin = new NxWindow(W_X, W_Y, W_W, W_H, "Network Configuration");
MakePPPWin();
MakeDNSWin();
MakeIPWin();
cWin->end();
this_ip_setup->get_ip_info();
////////////////////////////////////////
// FLNX-Colosseum IPC
set_shown_window(this_ip_setup->get_parent_win());
Add_Fd("nxnet", _ClientIPCHandler);
}
//////////////////////////////////////////////////////////
//
// function: main
// description: main function
// parameters: int argc - argument count
// char **argv - argument array
// return: int - return value
//
//////////////////////////////////////////////////////////
int
main(int argc, char **argv)
{
NetConfig net_config(argc, argv);
return (Fl::run());
}
--- NEW FILE: dns_setup.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef _DNS_SETUP_H_
#define _DNS_SETUP_H_
/////// Includes ////////
#include <FL/Fl_Group.H>
#include <FL/forms.H>
#include <FL/Fl_Radio_Button.H>
#include <FL/Fl_Tabs.H>
#include <FL/Fl_Input.H>
#include "ip_input.h"
#include <nxapp.h>
#include <nxwindow.h>
#include <nxbutton.h>
#include <nxinput.h>
/////// Classes ///////
///////////////////////////////////////////////
//
// class: DNS_Setup
// description: The DNS_Setup class defines the
// user interface for setting up
// the DNS
///////////////////////////////////////////////
class DNS_Setup
{
Fl_Group *dns_setup_group_;
Fl_Input *domain_;
IP_Input *dns1_ip_;
IP_Input *dns2_ip_;
IP_Input *dns3_ip_;
Fl_Input *search_domain_;
NxButton *defaults_button_;
NxButton *set_button_;
NxPimWindow *dns_win_;
FL_EXPORT void get_values_from_file();
static FL_EXPORT void set_button_cb(Fl_Widget *, void *parent);
static FL_EXPORT void defaults_button_cb(Fl_Widget *, void *parent);
public:
Fl_Window * get_parent_win()
{
return dns_win_->GetWindowPtr();
}
const char *get_domain_value()
{
return domain_->value();
}
const char *get_search_value()
{
return search_domain_->value();
}
char *get_dns1_value()
{
return dns1_ip_->get_ip_inputs(true);
}
unsigned long get_dns1_lvalue()
{
return dns1_ip_->iptol();
}
char *get_dns2_value()
{
return dns2_ip_->get_ip_inputs(true);
}
unsigned long get_dns2_lvalue()
{
return dns2_ip_->iptol();
}
char *get_dns3_value()
{
return dns3_ip_->get_ip_inputs(true);
}
unsigned long get_dns3_lvalue()
{
return dns3_ip_->iptol();
}
FL_EXPORT DNS_Setup();
FL_EXPORT ~ DNS_Setup();
};
#endif
--- NEW FILE: Makefile ---
# apps/address/Makefile
TARGET_CXX=netconfig
SRC=${shell ls *.cxx}
OBJS=${SRC:.cxx=.o}
ifeq ($(CROSS_COMPILE),y)
CFLAGS ?=
CFLAGS += -fpermissive
endif
LIBS=-lpixil-pim -lpixil
ifeq ($(CONFIG_PAR),y)
LIBS+=-lpar
endif
ifeq ($(CONFIG_SYNC),y)
LIBS+=-lpixil-sync
endif
LIBS+=-lfltk -lflek
ifeq ($(CONFIG_NANOX),y)
LIBS+=-lwm -lnano-X
endif
ifeq ($(CONFIG_X11),y)
LIBS+=-lX11
endif
ifeq ($(CONFIG_COLOSSEUM),y)
LIBS+=-lipc
endif
include $(BASE_DIR)/Rules.make
--- NEW FILE: ppp_modem.cxx ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
[...2231 lines suppressed...]
set_status_box();
check_ppp_dirs();
ppp_device_setup = new PPP_Modem_Setup(this);
_add_config = new PPP_Add_Config();
_acct = new PPP_Account(this);
_add_account = new PPP_Add_Account();
}
///////////////////////////////////////////////////////////
//
// function: PPP_Momde::~PPP_Modem()
// description: PPP_Modem class destroyer
// parameters: none
// returns: none
//
///////////////////////////////////////////////////////////
PPP_Modem::~PPP_Modem()
{
}
--- NEW FILE: ip_input.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef IP_INPUT_H
#define IP_INPUT_H
////// Includes ////////
#include <FL/Fl_Input.H>
///// Defines //////////
#define MAX_IP_LEN 16
///// Const ////////////
const static int NUM_INPUTS = 4;
///// Classes /////////
class Single_IP_Input;
///////////////////////////////////////////////
//
// class: IP_Input
// description: The IP_Input class defines the
// user interface for setting up
// the ip input boxes
///////////////////////////////////////////////
class IP_Input:public Fl_Widget
{
char ip_addr[MAX_IP_LEN];
FL_EXPORT void draw();
FL_EXPORT void move_focus();
public:
FL_EXPORT unsigned long iptol();
FL_EXPORT char *get_ip_inputs();
FL_EXPORT char *get_ip_inputs(bool);
FL_EXPORT void set_ip_inputs(char *, bool);
Single_IP_Input *input[NUM_INPUTS];
FL_EXPORT void activate();
FL_EXPORT void deactivate();
FL_EXPORT void hide();
FL_EXPORT void show();
FL_EXPORT IP_Input(int, int, int, int, const char * = 0);
virtual void resize(int x, int y, int w, int h)
{
Fl_Widget::resize(x, y, this->w(), this->h());
}
};
///////////////////////////////////////////////
//
// class: Single_IP_Input
// description: The Single_IP_Input class defines the
// user interface for setting up
// the single ip input boxes
///////////////////////////////////////////////
class Single_IP_Input:public Fl_Input
{
FL_EXPORT int handle_key();
IP_Input *parent;
public:
FL_EXPORT void set_parent(IP_Input *);
FL_EXPORT int handle(int);
FL_EXPORT Single_IP_Input(int X, int Y, int W, int H,
const char *L):Fl_Input(X, Y, W, H, L)
{
}
};
#endif
--- NEW FILE: ip_input.cxx ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#include <FL/fl_draw.H>
#include <FL/Fl.H>
#include <nxapp.h>
extern "C"
{
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
}
#include "ip_input.h"
///////////////////////////////////////////////////////////
//
// Function: Single_IP_Input::set_paretn()
// Description: This function sets a Single_IP_INput parent
// Parametets: IP_Input *par - pointer to an IP_Input object
// Returns: none
//
//////////////////////////////////////////////////////////
void
Single_IP_Input::set_parent(IP_Input * par)
{
parent = par;
}
///////////////////////////////////////////////////////////
//
// Function: Single_IP_Input::handle()
// Description: This function handles the input into a Single_IP_Input object
// and limits the input to numbers between 0 and 255
// Parametets: int event - interger numver of the event being passed in
// Returns: int
//
//////////////////////////////////////////////////////////
int
Single_IP_Input::handle(int event)
{
int idx;
switch (event) {
case FL_KEYBOARD:
switch (Fl::event_key()) {
case FL_BackSpace:
for (idx = 0; idx < NUM_INPUTS; idx++) {
if (this == parent->input[idx]) {
break;
}
}
if (idx) {
idx--;
}
if (0 == position()) {
parent->input[idx]->take_focus();
int len = strlen(parent->input[idx]->value());
parent->input[idx]->position(len);
}
default:
int c = Fl::event_key();
if ((c > 47 && c < 58) || c > FL_Button) {
if ((2 == strlen(value())) && (c > 47 && c < 58)) {
char strbuf[NUM_INPUTS];
char tmpbuf[NUM_INPUTS];
int pos = position();
sprintf(tmpbuf, "%c", c);
sprintf(strbuf, "%s", value());
if (0 == pos) {
strbuf[2] = strbuf[1];
strbuf[1] = strbuf[0];
strbuf[0] = tmpbuf[0];
}
if (1 == pos) {
strbuf[2] = strbuf[1];
strbuf[1] = tmpbuf[0];
}
if (2 == pos) {
strbuf[2] = tmpbuf[0];
}
strbuf[3] = '\0';
int move_pos = 1;
//FIXME
// for some dumb reason strtol seg faults
// in fact a lot seg faults so if you can fix it
// please do this is why this is kludged togethor
if (strbuf[0] > '2') {
strbuf[0] = '2';
strbuf[1] = '5';
strbuf[2] = '5';
move_pos = 0;
}
if (strbuf[0] == '2') {
if (strbuf[1] > '5') {
strbuf[1] = '5';
strbuf[2] = '5';
move_pos = 0;
}
}
if (strbuf[0] == '2' && strbuf[1] == '5') {
if (strbuf[2] > '5') {
strbuf[2] = '5';
move_pos = 0;
}
}
value(strbuf);
return 0;
}
if ((3 == strlen(value())) && c < FL_Button) {
for (idx = 0; idx < NUM_INPUTS; idx++) {
if (this == parent->input[idx]) {
break;
}
}
if (idx != NUM_INPUTS - 1) {
idx++;
}
parent->input[idx]->take_focus();
return 0;
}
return Fl_Input::handle(event);
} else {
return 0;
}
}
default:
return Fl_Input::handle(event);
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::draw()
// Description: This function draws an IP_Input object
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Input::draw()
{
int x1 = x();
int y1 = y();
int w1 = w();
int h1 = h();
int xpos = 0;
if (damage() & (FL_DAMAGE_EXPOSE | FL_DAMAGE_ALL)) {
draw_box(FL_BOTTOM_BOX, x(), y(), w(), h(), FL_WHITE);
align(FL_ALIGN_LEFT);
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->resize(x1 + xpos + 2, y1 + 2, w1 / 4 - 5, h1 - 5);
input[idx]->box(FL_FLAT_BOX);
input[idx]->draw();
xpos += w1 / 4;
}
xpos = x1;
for (int jdx = 0; jdx < NUM_INPUTS; jdx++) {
if (jdx != 3) {
xpos += w1 / 4;
draw_box(FL_BLACK_BOX, xpos - 4, y1 + h1 - 7, 4, 4, FL_BLACK);
}
}
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::iptol()
// Description: This function converts the value of an IP_Input
// object from dot notation into an unsigned long
// Parametets: none
// Returns: unsigned long
//
//////////////////////////////////////////////////////////
unsigned long
IP_Input::iptol()
{
unsigned long val = 0L;
unsigned long tmp = 0L;
for (int idx = 0; idx < NUM_INPUTS; idx++) {
tmp = strtol(input[idx]->value(), NULL, 10);
if (0 == idx) {
tmp = (tmp & 0xFF) << 24;
val = val | tmp;
} else if (1 == idx) {
tmp = (tmp & 0xFF) << 16;
val = val | tmp;
} else if (2 == idx) {
tmp = (tmp & 0xFF) << 8;
val = val | tmp;
} else if (3 == idx) {
tmp = (tmp & 0xFF);
val = val | tmp;
} else {
fprintf(stderr, "Error! out of range\n");
val = 0L;
break;
}
}
return val;
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::get_ip_inputs()
// Description: This function returns the value of the IP_Input
// object
// Parametets: bool blanks - Determines if it returns 0.0.0.0 or ""
// Returns: char * - value of IP_Input object
//
//////////////////////////////////////////////////////////
char *
IP_Input::get_ip_inputs(bool blanks)
{
ip_addr[0] = 0;
if (false == blanks) {
for (int idx = 0; idx < NUM_INPUTS; idx++) {
if (0 == strcmp(input[idx]->value(), "")) {
input[idx]->value("");
}
}
sprintf(ip_addr, "%s.%s.%s.%s", input[0]->value(), input[1]->value(),
input[2]->value(), input[3]->value());
} else {
bool first = false;
for (int idx = 0; idx < NUM_INPUTS; idx++) {
if (0 != strcmp(input[idx]->value(), "")) {
if (first == false) {
first = true;
sprintf(ip_addr, "%s", input[idx]->value());
} else {
sprintf(ip_addr, "%s.%s", ip_addr, input[idx]->value());
}
}
}
}
return ip_addr;
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::get_ip_inputs()
// Description: This function returns the value of the IP_Input
// object
// Parametets: none
// Returns: char * - value of IP_Input object
//
//////////////////////////////////////////////////////////
char *
IP_Input::get_ip_inputs()
{
for (int idx = 0; idx < NUM_INPUTS; idx++) {
if (0 == strcmp(input[idx]->value(), "")) {
input[idx]->value("0");
}
}
sprintf(ip_addr, "%s.%s.%s.%s", input[0]->value(), input[1]->value(),
input[2]->value(), input[3]->value());
return ip_addr;
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::set_ip_inputs()
// Description: This function sets the value of the IP_Input
// object
// Parametets: chat *ip_addr - set object to this value
// bool blanks - determine if blanks meaning "" are permitted
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Input::set_ip_inputs(char *ip_addr, bool blanks)
{
int len = 0;
char buf[NUM_INPUTS];
char *strptr;
char *tmpptr;
if (0 == strcmp("", ip_addr) || (NULL == ip_addr)) {
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->value("");
}
return;
}
if (false == blanks) {
if (4 > strlen(ip_addr)) {
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->value("0");
}
} else {
tmpptr = ip_addr;
for (int idx = 0; idx < 3; idx++) {
strptr = strstr(ip_addr, ".");
if (NULL != strptr) {
len = strptr - ip_addr;
strncpy(buf, ip_addr, len);
buf[len] = '\0';
input[idx]->value(buf);
ip_addr += (len + 1);
}
}
len = strlen(ip_addr);
strncpy(buf, ip_addr, len);
buf[len] = '\0';
input[3]->value(buf);
}
} else {
int per_count = 0;
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->value("");
}
for (unsigned int idx = 0; idx <= strlen(ip_addr); idx++) {
if ('.' == ip_addr[idx]) {
per_count++;
}
}
for (int idx = 0; idx < per_count; idx++) {
strptr = strstr(ip_addr, ".");
if (NULL != strptr) {
len = strptr - ip_addr;
strncpy(buf, ip_addr, len);
buf[len] = '\0';
input[idx]->value(buf);
ip_addr += (len + 1);
}
}
len = strlen(ip_addr);
strncpy(buf, ip_addr, len);
buf[len] = '\0';
input[per_count]->value(buf);
if (per_count < 3) {
for (int idx = per_count + 1; idx < 3; idx++) {
input[idx]->value("");
}
}
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::activate()
// Description: This function allows the inputs area of the object to
// be changed
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Input::activate()
{
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->activate();
}
labelcolor(FL_BLACK);
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::deactivate()
// Description: This function disallows the inputs area of the object to
// be changed
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Input::deactivate()
{
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->deactivate();
}
labelcolor(inactive(labelcolor()));
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::hide()
// Description: This function hides the input boxes
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Input::hide()
{
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->hide();
input[idx]->redraw();
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::show()
// Description: This function shows the input boxes
// Parametets: none
// Returns: none
//
//////////////////////////////////////////////////////////
void
IP_Input::show()
{
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx]->show();
input[idx]->redraw();
}
}
///////////////////////////////////////////////////////////
//
// Function: IP_Input::IP_Input()
// Description: This function is the constructor of the IP_Input object
// Parametets: int X - x pos
// int Y - y pos
// int W - widdth
// int H - height
// const char *L - label
// Fl_Widget(X<Y<W<H<L) - class inheretance
// Returns: none
//
//////////////////////////////////////////////////////////
IP_Input::IP_Input(int X, int Y, int W, int H, const char *L)
:
Fl_Widget(X, Y, W, H, L)
{
box(FL_BOTTOM_BOX);
for (int idx = 0; idx < NUM_INPUTS; idx++) {
input[idx] = new Single_IP_Input(0, 0, 0, 0, "");
input[idx]->Single_IP_Input::set_parent(this);
input[idx]->maximum_size(3);
input[idx]->value("0");
input[idx]->labelfont(DEFAULT_LABEL_FONT);
input[idx]->labelsize(DEFAULT_LABEL_SIZE);
input[idx]->textfont(DEFAULT_LABEL_FONT);
input[idx]->textsize(DEFAULT_LABEL_SIZE);
}
/* Set the default fonts */
labelfont(DEFAULT_LABEL_FONT);
labelsize(DEFAULT_LABEL_SIZE);
}
--- NEW FILE: ip_setup.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef _IP_SETUP_H_
#define _IP_SETUP_H_
/////// Includes ////////
#include <assert.h>
#include <FL/forms.H>
#include <FL/Fl_Tabs.H>
#include "ip_input.h"
#include <nxapp.h>
#include <nxwindow.h>
#include <nxbutton.h>
#include <nxcheckbutton.h>
//////// Defines ////////
#define MAX_ETH_DEVS 3
#define TYPE_ETH 0
#define TYPE_WVLAN 1
#define WNAME "IEEE 802.11-DS"
#define MAX_VALS 34 // 32 + 2(FOR "")
#define DEVICE 0
#define PROTO 1
#define IPADDR 2
#define NETMASK 3
#define BROADCAST 4
#define GATEWAY 5
#define ESSID 6
#define WEPID 7
#define MAX_KEYS 8
#define KEY_DEVICE "DEVICE"
#define KEY_PROTO "PROTO"
#define KEY_IPADDR "IPADDR"
#define KEY_NETMASK "NETMASK"
#define KEY_BROADCAST "BROADCAST"
#define KEY_GATEWAY "GATEWAY"
#define KEY_ESSID "ESSID"
#define KEY_WEPID "WEPID"
//////// Structures /////
struct tmp_inputs
{
NxInput *essid_input;
NxCheckButton *wep_check;
NxInput *wep_input;
};
//////// Classes ////////
///////////////////////////////////////////////
//
// class: IP_Setup
// description: The IP_Setup class defines the
// user interface for setting up
// the TCP/IP network
///////////////////////////////////////////////
class IP_Setup
{
char *ifup, *ifdown;
static char *netconf;
static IP_Setup *_inst;
int eth0_active_;
int wvlan_active_;
bool have_dev_eth0_;
bool have_dev_wvlan_;
bool have_wireless_lan_;
NxPimWindow *ip_setup_win_;
Fl_Group *ip_setup_group_;
NxButton *start_stop_button_;
IP_Input *ip_address_;
IP_Input *netmask_;
IP_Input *broadcast_;
IP_Input *gateway_;
NxCheckButton *dhcp_button_;
NxButton *reset_button_;
NxButton *set_button_;
NxOutput *eth0_status_box_;
NxOutput *wvlan_status_box_;
///////////
// Wireless
///////////
char *wireless_name;
// Wireless NxCheckButton
NxCheckButton *wireless_check;
tmp_inputs inputs;
static void wireless_check_cb(Fl_Widget * fl, void *o)
{
tmp_inputs *inputs = (tmp_inputs *) o;
NxCheckButton *wireless_check = (NxCheckButton *) fl;
NxInput *essid_input = inputs->essid_input;
NxCheckButton *wep_check = inputs->wep_check;
NxInput *wep_input = inputs->wep_input;
if (wireless_check->value())
{
essid_input->activate();
wep_check->activate();
wep_input->deactivate();
} else
{
essid_input->deactivate();
wep_check->value(0);
wep_check->deactivate();
wep_input->deactivate();
}
}
// ESSID
////////
NxInput *essid_input;
// WEP
//////
NxCheckButton *wep_check;
NxInput *wep_input;
static void wep_check_cb(Fl_Widget * fl, void *o)
{
tmp_inputs *inputs = (tmp_inputs *) o;
NxCheckButton *wep_check = (NxCheckButton *) fl;
NxInput *wep_input = inputs->wep_input;
if (wep_check->value())
wep_input->activate();
else
wep_input->deactivate();
}
static FL_EXPORT void reset_button_cb(Fl_Widget *, void *parent);
static FL_EXPORT void start_stop_button_cb(Fl_Widget *, void *parent);
static FL_EXPORT void dhcp_button_cb(Fl_Widget *, void *parent);
static FL_EXPORT void set_button_cb(Fl_Widget *, void *parent);
void set_have_if_flags();
public:
Fl_Window * get_parent_win() {
return (ip_setup_win_->GetWindowPtr());
}
void set_ip_value(char *addr)
{
ip_address_->set_ip_inputs(addr, false);
}
char *get_ip_value(); // {return ip_address_->get_ip_inputs(false);}
unsigned long get_ip_lvalue()
{
return ip_address_->iptol();
}
void set_netmask_value(char *addr)
{
netmask_->set_ip_inputs(addr, false);
}
char *get_netmask_value()
{
return netmask_->get_ip_inputs(false);
}
unsigned long get_netmask_lvalue()
{
return netmask_->iptol();
}
void set_broadcast_value(char *addr)
{
broadcast_->set_ip_inputs(addr, false);
}
char *get_broadcast_value()
{
return broadcast_->get_ip_inputs(false);
}
unsigned long get_broadcast_lvalue()
{
return broadcast_->iptol();
}
char *get_gateway_value()
{
return gateway_->get_ip_inputs(false);
}
unsigned long get_gateway_lvalue()
{
return gateway_->iptol();
}
bool get_dhcp_value();
void set_dhcp_value(bool value)
{
dhcp_button_->value(value);
}
bool get_have_dev_eth0_value()
{
return (have_dev_eth0_ ? true : false);
}
void set_have_dev_eth0_value(bool value)
{
have_dev_eth0_ = value;
}
bool get_have_wvlan0_value()
{
return (have_dev_wvlan_ ? true : false);
}
void set_have_wvlan0_value(bool value)
{
have_dev_wvlan_ = value;
}
bool get_have_wireless_value()
{
return (have_wireless_lan_ ? true : false);
}
void set_have_wireless_value();
void set_button_label();
void set_eth0_active_status(int status)
{
eth0_active_ = status;
}
int get_eth0_active_status()
{
return eth0_active_;
}
void set_wvlan_active_status(int status)
{
wvlan_active_ = status;
}
int get_wvlan_active_status()
{
return wvlan_active_;
}
void set_status_box(int);
void set_status_box(int, char *);
void get_ip_info();
void set_ip_info();
void set_gateway_value(char *value)
{
gateway_->set_ip_inputs(value, false);
}
public:
int net_up();
int net_down();
static IP_Setup *IP()
{
assert(_inst);
return _inst;
}
FL_EXPORT IP_Setup();
FL_EXPORT ~ IP_Setup();
};
#endif
--- NEW FILE: ppp_status.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef PPP_STATUS_H
#define PPP_STATUS_H
#include <FL/Fl_Widget.H>
#ifndef PPP_MODEM_H
#include "ppp_modem.h"
#endif
extern "C"
{
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <pthread.h>
}
class PPP_Status:public Fl_Widget
{
friend class PPP_Modem;
Fl_Callback *connect_cb_;
Fl_Callback *disconnect_cb_;
Fl_Callback *setup_account_cb_;
Fl_Callback *setup_device_cb_;
Fl_Callback *cancel_cb_;
PPP_Modem *modem_;
bool dialing_, connected_, disconnect_wish_;
time_t connect_time_;
int hour_, minute_, second_;
int fd_;
char *speed_;
ulong value_;
ulong start_;
FL_EXPORT int handle(int);
protected:
FL_EXPORT void draw(int, int, int, int)
{
return;
}
FL_EXPORT void draw()
{
return;
}
public:
FL_EXPORT Fl_Callback_p get_connect_cb()const
{
return connect_cb_;
}
FL_EXPORT Fl_Callback_p get_disconnect_cb() const
{
return disconnect_cb_;
}
FL_EXPORT Fl_Callback_p get_setup_account_cb() const
{
return setup_account_cb_;
}
FL_EXPORT Fl_Callback_p get_setup_device_cb() const
{
return setup_device_cb_;
}
FL_EXPORT Fl_Callback_p get_cancel_cb() const
{
return cancel_cb_;
}
FL_EXPORT void set_connect_cb(Fl_Callback * c)
{
connect_cb_ = c;
}
FL_EXPORT void set_cancel_cb(Fl_Callback * c)
{
cancel_cb_ = c;
}
FL_EXPORT void set_disconnect_cb(Fl_Callback * c)
{
disconnect_cb_ = c;
}
FL_EXPORT void set_account_setup_cb(Fl_Callback * c)
{
setup_account_cb_ = c;
}
FL_EXPORT void set_device_setup_cb(Fl_Callback * c)
{
setup_device_cb_ = c;
}
FL_EXPORT void set_fd(int);
FL_EXPORT void set_modem(PPP_Modem *);
time_t get_connect_time() const
{
return connect_time_;
}
int get_fd() const
{
return fd_;
}
bool get_disconnect_wish() const
{
return disconnect_wish_;
}
bool get_dialing() const
{
return dialing_;
}
bool get_connected() const
{
return connected_;
}
FL_EXPORT void set_disconnect_wish(bool);
FL_EXPORT void set_dialing(bool);
FL_EXPORT void set_connected(bool);
FL_EXPORT void value(ulong v); // set to Unix time
FL_EXPORT void value(int, int, int); // set hour, minute, second
ulong value() const
{
return value_;
}
int hour() const
{
return hour_;
}
int minute() const
{
return minute_;
}
int second() const
{
return second_;
}
FL_EXPORT void update_status();
PPP_Modem *get_modem()
{
return modem_;
}
FL_EXPORT PPP_Status(int, int, int, int, const char *);
};
#endif
More information about the dslinux-commit
mailing list