summaryrefslogtreecommitdiff
path: root/cleopatre/application/spidgoahead/LINUX/spidcom_asp_functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/application/spidgoahead/LINUX/spidcom_asp_functions.c')
-rw-r--r--cleopatre/application/spidgoahead/LINUX/spidcom_asp_functions.c426
1 files changed, 0 insertions, 426 deletions
diff --git a/cleopatre/application/spidgoahead/LINUX/spidcom_asp_functions.c b/cleopatre/application/spidgoahead/LINUX/spidcom_asp_functions.c
deleted file mode 100644
index edac3d40a9..0000000000
--- a/cleopatre/application/spidgoahead/LINUX/spidcom_asp_functions.c
+++ /dev/null
@@ -1,426 +0,0 @@
-/*-----------------------------------------------------------------------------
-File: spidcom_functions.c
- Description: Asp functions definition used intenally by GoAhead web server.
- Project: HTTP server
- Target: SPiDCOM modem w/ SPC300
- Version: 0.1
- Revision list: -
- Company: SPiDCOM
- Author: Uros Gardasevic
- Date: September 2009.
------------------------------------------------------------------------------*/
-
-
-
-
-/**
- *
- * \brief Function naming:
- * \brief If it is data-function, it is in format : spidcom_asp_desc_h, where h stands for head, because function will be called in head section of html page.
- * \brief If it is action-function, it is in format : spidcom_asp_desc_b, where b stands for body, because function will be called in body section of html page.
- * \brief It is important because of error reporting to the end user.
- *
- */
-
-
-/**
- * For function called from head section, error will be reported during the load of body, and for function called from body section, error will be reported
- * wright away on the place from where it is actualy called.
- */
-
-
-
-
-#include "../uemf.h"
-#include "../wsIntrn.h"
-#ifdef WEBS_SSL_SUPPORT
-#include "../websSSL.h"
-#endif
-#ifdef USER_MANAGEMENT_SUPPORT
-#include "../um.h"
-void formDefineUserMgmt(void);
-#endif
-
-
-
-#include "spidlib.h"
-
-typedef char mac_t[6];
-
-
-
-char* human_readable(int return_value)
-{
- switch(return_value){
- case SPIDLIB_SUCCESS:
- return "Success";
- break;
- case SPIDLIB_ERROR_PARAM:
- return "Bad input parameters";
- break;
- case SPIDLIB_ERROR_NO_SPACE:
- return "Not enough aviable space";
- break;
- case SPIDLIB_ERROR_NOT_FOUND:
- return "Item / data not found";
- break;
- case SPIDLIB_ERROR_SYSTEM:
- return "System error.";
- default:
- /*
- * Not possible but ok...
- */
- return "Unknown error";
- break;
- }
-}
-
-
-
-/*
- *
- * MASTER-only functions
- *
- */
-
-
-/*
- *
- * MASTER AND SLAVE functions
- *
- */
-
-/**
- * Write the IP setting of a network interface.
-
- *
- * \param interface string containing network interface name (“br0”, “plc0” or “eth0”)
- * This argument is fetched by ejArgs() function.
- * \return ip_data separated by ':' on success, or string containing error description on error.
- */
-
-
-static int spidcom_asp_get_ip_data_h(int eid, webs_t wp, int argc, char_t **argv){
-
- spidlib_ip_t ip_data;
- spidlib_error_t return_value;
- char *interface;
-
- if ( ejArgs(argc, argv, T("%s"), &interface) < 1) {
- websError(wp, 400, T("Insufficient args\n"));
- return -1;
- }
-
- if ((return_value = spidlib_network_get_ip(interface, &ip_data)) == SPIDLIB_SUCCESS)
- websWrite(wp, "\"%s:%s:%s:%s:%s\"", ip_data.mode?"DHCP":"STATIC", ip_data.address, ip_data.netmask, ip_data.broadcast, ip_data.gateway);
- else
- websWrite(wp, "\"error: Ip data : %s\"", human_readable(return_value));
-
- return 0;
-}
-
-
-/**
- * Write the MAC address of a network interface.
-
- *
- * \param interface string containing network interface name (“br0”, “plc0” or “eth0”)
- * This argument is fetched by ejArgs() function.
- * \return mac string on success, or string containing error description on error.
- */
-
-
-static int spidcom_asp_get_mac_h(int eid, webs_t wp, int argc, char_t **argv)
-{
-
- spidlib_error_t return_value;
- char *interface;
- char mac[24];
-
- if ( ejArgs(argc, argv, T("%s"), &interface) < 1) {
- websError(wp, 400, T("Insufficient args\n"));
- return -1;
- }
-
- if ((return_value = spidlib_network_get_mac(interface, mac)) == SPIDLIB_SUCCESS)
- websWrite(wp, "\"%s\"", mac);
- else
- websWrite(wp, "\"error: MAC data : %s\"", human_readable(return_value));
-
- return 0;
-}
-
-
-
-/**
- * Write the local statistics values.
-
- *
- * \param mac_address string containing mac address of the device
- * This argument is fetched by ejArgs() function.
- * \return Eoc statistics values separated by ':' on success, or string containing error description on error.
- */
-
-static int spidcom_asp_get_stat_h(int eid, webs_t wp, int argc, char_t **argv)
-{
-
- FILE *fp;
- char *interface;
- char filename[16] = "/proc/net/dev";
- char word[80];
- char buffer[SPIDLIB_LINE_MAX_LEN];
- char *delimiter = NULL;
- int index = 0, range = 0;
- int stat[20];
- int found_intefrace = 0, found_delimiter=0; //flag
- int length = 0;
-
-
-
- interface = websGetVar(wp,"interface", "0"); // Get intrerface name from QUERY_STRING
- if ((fp = fopen(filename, "r")) == NULL) // open file for fething data
- {
- websWrite(wp, "\"error: Statistics. File not exist.\"");
- return 0;
- }
-
- fgets(buffer, SPIDLIB_LINE_MAX_LEN-1, fp ); //Eliminate first two lines
- fgets(buffer, SPIDLIB_LINE_MAX_LEN-1, fp );
-
-
- while (!feof(fp))
- {
- if (found_intefrace && (index<16)) // interface found and not all data is readed yet
- {
- fscanf(fp, "%d", &stat[index++] ); // so please read it then...
- if (index == 16) // dont circle anymore if there is no need...
- break;
- }
- else
- { // Search for paticular inteface
- fscanf(fp, "%s", &word);
- if ( (word[0] < '0') || (word[0] > '9')) // ignore integer values
- {
- if ( (delimiter = strchr(word, ':'))){ // extract the interface name
- length = strlen(word); // remeber size of readed word
- *(delimiter) = 0;
- }
- if (!strcmp(word, interface))
- {
- found_intefrace++; // interface found, raise the flag...
- if ( length > (strlen(word)+1) ) // if there is no white space between interface name and value read it over here
- stat[index++] = atoi(delimiter + 1);
- }
- }
- }
- }
- if(found_intefrace)
- {
- range = index;
- for (index = 0; index < (range/2); index++) // send the data to the browser
- websWrite(wp, T("%d:%d:"), stat[index], stat[index+8]);
- }
- else
- {
- websWrite(wp, "\"error: Statistics : Intreface not found\"");
- fclose(fp);
- return 0;
- }
- fclose(fp);
- return 0;
-}
-
-
-static int spidcom_asp_eoc_get_topo_h(int eid, webs_t wp, int argc, char_t **argv)
-{
-
- mac_t mac_address_list[SPIDLIB_EOC_ONLINE_INFO_LINE_MAX_NB];
- int mac_address_count = 0;
- spidlib_error_t return_value;
- int i = 0, end = 0;
- char mac[SPIDLIB_MAC_STR_LEN];
-
-
- if ((return_value = spidlib_eoc_get_topo(mac_address_list[0], &mac_address_count)) == SPIDLIB_SUCCESS)
- {
- for (i ; i < mac_address_count; i ++)
- {
- spidlib_mac_bin_to_str(mac_address_list[i], mac);
- websWrite(wp, "%s-", mac);
- }
- }
- else
- {
- websWrite(wp, "\"error: Online station : %s\"", human_readable(return_value));
- }
- return 0;
-}
-
-
-
-
-/**
- * Reboot the modem. ASP page which contain call to this function must have \param doit=yes in its QUERY_STRING.
- */
-
-static int spidcom_asp_reboot_b(int eid, webs_t wp, int argc, char_t **argv)
-{
- char *doit;
-
- doit = websGetVar(wp, T("doit"), T("no"));
- if(!(strcmp(doit,"yes")))
- {
- websWrite(wp, "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"20; URL=br0.asp\"></head>\n");
- websWrite(wp, "<h2> System is rebooting. Wait for page to be refreshed.</h2>");
- spidlib_system_reboot();
- }
- else
- websWrite(wp, "Not allowed. Please try again.");
-
- return 0;
-
-}
-
-
-
-
-static int spidcom_asp_eoc_action(int eid, webs_t wp, int argc, char_t **argv)
-{
- char *mac;
- char *action;
- spidlib_error_t return_value;
- spidlib_eoc_link_quality_t link_quality;
- spidlib_eoc_dev_info_t eoc_dev_info;
- spidlib_eoc_rt_stat_t eoc_rt_stat;
-
-
- mac = websGetVar(wp, "mac", "00:00:00:00:00:00");
- action = websGetVar(wp, "action", "none");
-
-
- memset(&link_quality, 0, sizeof(link_quality));
- memset(&eoc_dev_info, 0, sizeof(eoc_dev_info));
- memset(&eoc_rt_stat, 0, sizeof(eoc_rt_stat));
-
-
- if (!strcmp(action,"get_link"))
- {
- if ((return_value = spidlib_eoc_get_link(mac, &link_quality)) == SPIDLIB_SUCCESS)
- websWrite(wp, "\"%d:%d:%d:%d\"", link_quality.down_att, link_quality.up_att, link_quality.down_quality, link_quality.up_quality);
- else
- websWrite(wp, "\"error: EOC : %s\"", human_readable(return_value));
- }
- else
- if (!strcmp(action,"get_device_info"))
- {
- if ((return_value = spidlib_eoc_get_device_info(mac, &eoc_dev_info)) == SPIDLIB_SUCCESS)
- websWrite(wp, "\"%s:%d:%s\"", eoc_dev_info.model_no, eoc_dev_info.port_amount, eoc_dev_info.sw_version);
- else
- websWrite(wp, "\"error: EOC :%s\"", human_readable(return_value));
- }
- else
- if (!strcmp(action,"get_stat"))
- {
- if ((return_value = spidlib_eoc_get_stat(mac, &eoc_rt_stat)) == SPIDLIB_SUCCESS)
- websWrite(wp, "\"%d:%d:%d:%d:%d:%d:%d:%d:%d:%d\"", eoc_rt_stat.tx_pkt , eoc_rt_stat.tx_byte, eoc_rt_stat.tx_bcast, eoc_rt_stat.tx_mcast, eoc_rt_stat.tx_dropped, eoc_rt_stat.rx_pkt , eoc_rt_stat.rx_byte, eoc_rt_stat.rx_bcast, eoc_rt_stat.rx_mcast, eoc_rt_stat.rx_dropped);
- else
- websWrite(wp, "\"error: EOC : %s\"", human_readable(return_value));
- }
- else
- if (!strcmp(action,"reboot"))
- {
- if ((return_value = spidlib_eoc_reboot(mac)) == SPIDLIB_SUCCESS)
- websWrite(wp, "\"Station with %s address is rebooted\"", mac);
- else
- websWrite(wp, "\"error: EOC : %s\"", human_readable(return_value));
- }
- else
- if (!strcmp(action,"reset_stat"))
- {
- if ((return_value = spidlib_eoc_reboot(mac)) == SPIDLIB_SUCCESS)
- websWrite(wp, "\"Station with %s address reset statistics\"", mac);
- else
- websWrite(wp, "\"error: EOC : %s\"", human_readable(return_value));
- }
-
- return 0;
-}
-
-static void spidcom_form_action(webs_t wp, char_t *path, char_t *query)
-{
- char_t *reboot,
- *inter,
- *ipmode;
-
- spidlib_ip_mode_t ip_mode;
- spidlib_ip_t ip_data;
- spidlib_error_t return_value;
-
-
-
- ipmode = websGetVar(wp, T("dhcp"), T("static"));
- if (!(strcmp(ipmode,"static")))
- ip_data.mode = SPIDLIB_IP_MODE_STATIC;
- else
- if(!(strcmp(ipmode,"dhcp")))
- ip_data.mode = SPIDLIB_IP_MODE_DHCP;
-
-
- strcpy(ip_data.address, websGetVar(wp, T("ip"), T("0.0.0.0")));
- strcpy(ip_data.netmask, websGetVar(wp, T("nm"), T("0.0.0.0")));
- strcpy(ip_data.broadcast, websGetVar(wp, T("bc"), T("0.0.0.0")));
- strcpy(ip_data.gateway, websGetVar(wp, T("gw"), T("0.0.0.0")));
-
- inter = websGetVar(wp, T("inter"), T("none"));
- reboot = websGetVar(wp, T("reboot"), T("no"));
-
- if (!strcmp(reboot, "yes"))
- {
- websRedirect(wp, "count.asp?doit=yes");
- return;
- }
-
- websHeader(wp);
-
- websWrite(wp, T("<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"3; URL=../%s.asp\">\n"), inter);
- websWrite(wp, T("<link rel=\"stylesheet\" href=\"/../style/normal_ws.css\" type=\"text/css\">\n</head>\n<body>\n"), inter);
-
- websWrite(wp, T("<h3>"));
-
- if ((return_value = spidlib_network_set_ip (inter, &ip_data)) == SPIDLIB_SUCCESS)
- ;//websWrite(wp, "spidlib_network_set_ip : ok<br>");
- else
- websWrite(wp, "\"error: IP data : %s\" <br>", human_readable(return_value));
-
-
- if ((return_value = spidlib_system_save()) == SPIDLIB_SUCCESS)
- ;//websWrite(wp, "spidlib_system_save : ok <br>");
- else
- websWrite(wp, "\"error: Save problem : %s\"<br>", human_readable(return_value));
-
-
- websWrite(wp, T("</h3>"));
- websWrite(wp, T("</body>\n"));
- websFooter(wp);
- websDone(wp, 200);
-
-}
-
-
-/**
- *
- * Bind actual asp name used in HTML to the implemented C function.
- *
- */
-
-void spidcom_register_all()
-{
- websAspDefine(T("spidcomAspEocGetTopo"), spidcom_asp_eoc_get_topo_h);
- websAspDefine(T("spidcomAspGetStatistics"), spidcom_asp_get_stat_h); // We bind spidcomAspGetStatistic to my function
- websAspDefine(T("spidcomAspGetIpData"), spidcom_asp_get_ip_data_h);
- websAspDefine(T("spidcomAspGetMac"), spidcom_asp_get_mac_h);
- websAspDefine(T("spidcomAspReboot"), spidcom_asp_reboot_b);
-
- websAspDefine(T("spidcomAction"), spidcom_asp_eoc_action);
- websFormDefine(T("formAction"), spidcom_form_action);
-}