CAI_Support
Senior Member
In the WebControl FW 3.02.16, there is a WEBSET feature to allow user set the VAR or OPx on another Webcontrol board. You can also use that feature to store certain value or information to an Apache or IIS server. Following is an example of CGI code written in C to demonstrate how to process this WEBSET request on the server side.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char *data, *remote_mac, *remote_host;
long m,n;
FILE *fp;
char buffer[18] = "\r\nnew get call\r\n";
printf("%s%c%c\n",
"Content-Type:text/plain;charset=iso-8859-1",13,10);
data = getenv("QUERY_STRING");
remote_mac = getenv("HTTP_USER_AGENT");
remote_host = getenv("REMOTE_ADDR");
fp = fopen("/tmp/webcontro.txt", "w+");
fwrite(buffer, 1, strlen(buffer), fp);
if(data != NULL) {
fwrite(data, 1, (unsigned int) strlen(data), fp);
fwrite(buffer, 1, strlen(buffer), fp);
}
if(remote_host != NULL) {
fwrite(remote_host, 1, (unsigned int) strlen(remote_host), fp);
fwrite(buffer, 1, strlen(buffer), fp);
}
if(remote_mac != NULL) {
fwrite(remote_mac, 1, (unsigned int) strlen(remote_mac), fp);
fwrite(buffer, 1, strlen(buffer), fp);
} else
fwrite(buffer, 1, strlen(buffer), fp);
/***************************************************
put your logic here if MAC address not match then do what
You can simply return with an error message
****************************************************/
/****************************************************
Now, you can process the data string send in by WebControl
****************************************************/
printf("close connection\n");
fclose(fp);
return 0;
}
cc example.c -o example
Then place it on your web server's CGI directory with execute permission.
Once the cgi triggered by WEBSET from WebControl, you can exam the file content to see what being sent.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char *data, *remote_mac, *remote_host;
long m,n;
FILE *fp;
char buffer[18] = "\r\nnew get call\r\n";
printf("%s%c%c\n",
"Content-Type:text/plain;charset=iso-8859-1",13,10);
data = getenv("QUERY_STRING");
remote_mac = getenv("HTTP_USER_AGENT");
remote_host = getenv("REMOTE_ADDR");
fp = fopen("/tmp/webcontro.txt", "w+");
fwrite(buffer, 1, strlen(buffer), fp);
if(data != NULL) {
fwrite(data, 1, (unsigned int) strlen(data), fp);
fwrite(buffer, 1, strlen(buffer), fp);
}
if(remote_host != NULL) {
fwrite(remote_host, 1, (unsigned int) strlen(remote_host), fp);
fwrite(buffer, 1, strlen(buffer), fp);
}
if(remote_mac != NULL) {
fwrite(remote_mac, 1, (unsigned int) strlen(remote_mac), fp);
fwrite(buffer, 1, strlen(buffer), fp);
} else
fwrite(buffer, 1, strlen(buffer), fp);
/***************************************************
put your logic here if MAC address not match then do what
You can simply return with an error message
****************************************************/
/****************************************************
Now, you can process the data string send in by WebControl
****************************************************/
printf("close connection\n");
fclose(fp);
return 0;
}
cc example.c -o example
Then place it on your web server's CGI directory with execute permission.
Once the cgi triggered by WEBSET from WebControl, you can exam the file content to see what being sent.