We have a Release Candidate !!! http://opensource.grisambre.net/fez/NetConfig.zip
If someone can test, this is welcome !
http://opensource.grisambre.net/fez/NetConfig.zip
If you have an idea of something to add to it, please let me know 8) !
/*
* This class allows the network configuration of the smaller devices (domino, panda)
* to be managed from an embedded webpage (http://mydevice/netconfig) : "home router configuration style".
*
* Right now, it supports:
* - Access with password (however, the security is kind of weak still)
* - Easy customization of the http config page (a template is provided, but it should be very simple to adapt it to any other design, using the provided tags).
* - static or DHCP IP addresses
* - change of Mac address
* - NETBIOS name resolution (very basic implementation)
* - NTP time update at startup
* - Basic Javascript error detection is made on the web page
* - Allowing to add more of your own pages easyly
* - An external button / jumper contact can be used at startup time to put the equipement back into default configuration (forgotten password...)
* - /netstatus tab for system status information
* - Customizable tabs for the user
* - Time stored and checked inside the RTC clock
* - Optional cable status monitoring (requiring an extra interrupt pin)
*
* It was designed to be small and simple (meaning : everything is basic)...
* It stores its configuration into InternalFlashStorage.
* You can initialy change the default parameters in your program, but after then, the end user manages it all by himself.
*
*
* ----------------------
* NetConfig Class Usage
* ----------------------
*
* Please add in your project 2 files as resources:
* - Template.html.bin : Template header for simple message to the user (password, error, you own tabs). Actualy covers CSS and html headers up to </head>
* - NetConfig.html.bin : Template for the main configuration page. It includes zero to several "tags" under the form:
* @ PARAMETERNAME which will be replaced by the actual value when the page is transmitted
* The HTML ressources have to be named as .bin to be considered as binary ressources by Visual C# express, to use
* half less memory inside the FEZ: a conversion from string to binary is not any more necessary.
*
*
* Constructor : (non blocking : returns immediatly, even if the configuration
* is not completed : DHCP, NTP can take take. User shall read the public fields
* Ready and NTPpending to check if things are ready)
*
* NetConfig(SPI.SPI_module SPI, // First 4 parameters same as
* Cpu.Pin CsPin, // for the function WIZnet_W5100.Enable
* Cpu.Pin ResetPin, // Number of pages served by the Http Server
* bool Reservesocket, // If set to false and user selects DHCP, this will forced to true
* Cpu.Pin Resetcfg = Cpu.Pin.GPIO_NONE, // Optional Pin that is checked at startup, shall be grounded by user to go back to default parameters
* uint Flashoffset = 0, // The configuration is written to Flash at this offset
* // Offset can be adjusted for the program to store other information there
* // User can know the number of necessary bytes for the config by checking NetConfig.FlashSize
* Cpu.Pin ledPin = Cpu.Pin.GPIO_NONE) // Optional Pin looped from the "Link Led" (Wiz5100 side) to monitor Link status in software
* // This allows for an example to renew DHCP when link is going up "again"
*
* Public Fields:
*
* public string Http404 { get; set; } //Customizable 404 Error
* public uint HttpPagesViewed { get; private set; // Number of pages served by the Http Server
* public DateTime HttpLastTime { get; private set; } // Time of the last page served by the Http Server
* public uint UsedSockets { get; private set; } // Provide user how many sockets are reserved by the class (from 1 to 3: DHCP/DNS(WIZ5100) ; NETBIOS; HTTPSERVER)
* public const int FlashSize // How many bytes (max) is necessary in FlashStorage to store the configuration
* public bool Ready { get; private set; } // True if the network is initialized
* public bool NTPpending { get; private set; } //True if the time is beeing adjusted : don't use a Time function in your program, it might change !
* public delegate void HttpProcess(HttpListenerContext ctx,NetConfig MyNet); // delegate you should use if creating a function to handle your own pages.
* public int LastResetCause { get; private set; } // Since the Watchdog reset cause can be read only once, it is kept here
* public bool CableConnected { get; private set; } //True if network cable is connected (if optional Pin LinkLED is used)
* public int CableChanges { get; private set; } // Number of times the cable connected went up (if optional Pin LinkLED is used)
* public bool HttpServerStatus { get; } // Return Http Server Status
* public bool NetBiosServerStatus { get; } // Return NetBios Server Status
*
* // Following the default configuration you can adjust to your needs (if flash empty or user ask for default config return
* // Make sure to respect the correct format, length and allowed characters !
* public const string DefaultCfg = "PSW=;" //Password string[10] [a-zA-Z0-9.-] (empty = no password): Max Length=4+10+1=15 bytes
* + "DN=DefaultConfig;" //Device Name string[15] [a-zA-Z0-9.-] :Max Length=3+15+1=19 bytes
* + "NETB=checked;" //NetBios enabled if value "checked" disabled if empty: Max Length=5+7+1=13 bytes
* + "MAC=AA-AA-AA-AA-AA-AA;" //Mac address : Length=4+17+1=22 bytes
* + "DHCP=;" //DHCP enabled if value "checked" disabled if empty: Max Length=5+7+1=13 bytes
* + "IP=192.168.0.10;" //Max Length=3+15+1=19 bytes
* + "MSK=255.255.255.0;" //Max Length=4+15+1=20 bytes
* + "GTW=192.168.0.1;" //Max Length=4+15+1=20 bytes
* + "DNS=8.8.8.8;" //Max Length=4+15+1=20 bytes
* + "NTP=pool.ntp.org;" //NTP server string[30] [a-zA-Z0-9.-] : Max Length=4+30+1=35 bytes
* + "NTPO=-300;" //NTP time offset from GMT is minutes : Max Length=5+5+1=11 bytes
* + "TCP=80;"; //TCP port for the webserver : Max Length=4+5+1=10 bytes
*
*
* Public methods:
*
* public void NetworkInitialize() // ReIntialize network or tries again every 10s (please use in separate thread since this is blocking)
* public void AutoReinitialize(DateTime StartTime, TimeSpan Frequency) // Optionaly Set up a timer to reinitialize the network part automaticaly
* public void StopHttpServer() // Stops http server. Can be used to temporary disabled the server to free sockets
* public void StartHttpServer() // Starts an http server thread.
* public bool StopNetBiosServer() // Stops NetBios server (if enabled. Can be used to temporary disabled the server to free sockets (if enabled returns true, if disabled false)
* public bool StartNetBiosServer() // Starts a NetBios server thread (if enabled returns true, if disabled false).
*
* public void HttpAddDispatcher(string Request, HttpProcess Function, string tabname="") // Add your own function to handle "Request" urls. If Tabname is specified, a tab will be added in the netconfig menu
* public string MyLanUrl() // returns the LAN Url of this Weberver, with ending "/" (valid for LAN only since using netbios name if available)
* public string GetParam(string param) // Returns a string giving the current parameter value or empty if not set
* public string GetUrlPassword(string RawUrl) // Returns the password as specified in URL
* public string HtmlTabs(string ActiveTab,string Password) // returns an html tab structure to be sent before the <div class='n'> tag
* public void PasswordScreen(HttpListenerContext ctx, string callingpage) // Send the html password page
*
* // a few utilities hardly related to NetConfig
* public string IpToString(byte[] Adress) // Convert a byte[] IP address into a string ex "192.168.0.1"
* public string MacToString(byte[] Mac) // Convert a byte[] Mac address into a string ex "AA-AA-AA-AA-AA-AA"
* public string Replace(string s, string olds, string news) // Quick function to replace some text by another in a string; made to work only for the first needle occurence
*/