Пример #1
0
main()
{
	/* Set both LED's initially ON.  When update_outputs() is called, the
	 * human will see it this way.
	 */
   strcpy(led2,led_on_gif);
   strcpy(led3,led_on_gif);

   sock_init();
   http_init();
   tcp_reserveport(80);

	/*  Configure the I/O ports.  Disable slave port which makes
	 *  Port A an output, and PORT E not have SCS signal.
	 *  Read shadow and set PE1 and PE7 as normal I/O.
	 *  LED's are controlled by PE1 and PE7, so make them outputs.
	 */
	WrPortI(SPCR, NULL, 0x84);
	WrPortI(PEFR,  & PEFRShadow,  ~((1<<7)|(1<<1)) & PEFRShadow);
	WrPortI(PEDDR, & PEDDRShadow, (1<<7)|(1<<1));

   while (1) {
   	update_outputs();
      http_handler();
   }
}
Пример #2
0
void main()
{
	SSL_Cert_t my_cert;

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();

	memset(&my_cert, 0, sizeof(my_cert));
	// When using HTTPS (i.e. HTTP over SSL or TLS), the certificates need
	// to be parsed and registered with the library.  For use with a
	// server, we need to know our own private key.
	if (SSL_new_cert(&my_cert, server_pub_cert, SSL_DCERT_XIM, 0) ||
	    SSL_set_private_key(&my_cert, server_priv_key, SSL_DCERT_XIM))
		exit(7);

	// Register certificate with HTTPS server.
	https_set_cert(&my_cert);

   tcp_reserveport(443);

/*
 *  http_handler needs to be called to handle the active http servers.
 */

   while (1) {
      http_handler();
   }
}
Пример #3
0
main()
{
   // Set Port A pins for LEDs low
   BitWrPortI(PADR, &PADRShadow, 1, DS1);
   BitWrPortI(PADR, &PADRShadow, 1, DS2);
   BitWrPortI(PADR, &PADRShadow, 1, DS3);
   BitWrPortI(PADR, &PADRShadow, 1, DS4);

   // Make Port A bit-wide output
   BitWrPortI(SPCR, &SPCRShadow, 1, 2);
   BitWrPortI(SPCR, &SPCRShadow, 0, 3);

   strcpy(led1,"ledon.gif");
   strcpy(led2,"ledoff.gif");
   strcpy(led3,"ledon.gif");
   strcpy(led4,"ledoff.gif");

   sock_init_or_exit(1);
   http_init();
   tcp_reserveport(80);

   while (1)
   {
   	update_outputs();
      http_handler();

	}
}
Пример #4
0
void main(void)
{
    auto int i;

    // Initialized the #web-registered variables.
    for (i = 0; i < 5; i++) {
        array1[i] = i + 1;
    }
    array2[0][0] = 2;
    array2[0][1] = 3;
    array2[1][0] = 4;
    array2[1][1] = 5;
    for (i = 0; i < 3; i++) {
        array3[i] = i + 5;
    }

    // Initialize the TCP/IP stack and HTTP server
    sock_init();
    http_init();

    // This yields a performance improvement for an HTTP server
    tcp_reserveport(80);

    while (1) {
        // Drive the HTTP server
        http_handler();
    }
}
Пример #5
0
           SSPEC_MIMETABLE_END

           void main()
{
    /*
     *  sock_init initializes the TCP/IP stack.
     *  http_init initializes the web server.
     */
    sock_init();
    http_init();

    /*
     *  tcp_reserveport causes the web server to ignore requests when there
     *  isn't an available socket (HTTP_MAXSERVERS are all serving index_html
     *  or rabbit1.gif).  This saves some memory, but can cause the client
     *  delays when retrieving pages.
     */
    tcp_reserveport(80);

    dlp_init();

    /*
     *  http_handler needs to be called to handle the active http servers.
     */
    for(;;)
    {
        tcp_tick(NULL);
        http_handler();
        dlp_handler();
    }
}
Пример #6
0
void main()
{
	SSL_Cert_t my_cert;


	/*
	 *  sock_init initializes the TCP/IP stack.
	 *  http_init initializes the web server.
	 */

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();

	memset(&my_cert, 0, sizeof(my_cert));
	// When using HTTPS (i.e. HTTP over SSL or TLS), the certificates need
	// to be parsed and registered with the library.  For use with a
	// server, we need to know our own private key.
	if (SSL_new_cert(&my_cert, server_pub_cert, SSL_DCERT_XIM, 0) ||
	    SSL_set_private_key(&my_cert, server_priv_key, SSL_DCERT_XIM))
		exit(7);

	// Register certificate with HTTPS server.
	https_set_cert(&my_cert);

	/*
	 *  tcp_reserveport causes the web server to ignore requests when there
	 *  isn't an available socket (HTTP_MAXSERVERS are all serving index_html
	 *  or rabbit1.gif).  This saves some memory, but can cause the client
	 *  delays when retrieving pages.
	 */

   tcp_reserveport(80);

   // Also reserve the HTTPS port
   tcp_reserveport(443);

	/*
	 *  http_handler needs to be called to handle the active http servers.
	 */

   while (1) {
      http_handler();
   }
}
Пример #7
0
void main(void)
{
	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();
	tcp_reserveport(80);

   while (1) {
   	http_handler();
   }
}
Пример #8
0
main(){
   int correct, i;

   brdInit();

   //  sock_init initializes the TCP/IP stack.
   //  http_init initializes the web server.
   sock_init();
   http_init();

   tcp_reserveport(80);

   mode = -1;  // -1 = uninitialized

   while(1){

      if(mode== -1){
         InitializeGame();
         mode = 0;
      }

      http_handler();

      if(numUsedGuesses == 6){   // guesses used up
         mode = 1;
         numUsedGuesses = 0;
         strcpy(hint,wrd->answer);
      }

      if(character)  {  // new character entered
         correct = 0;   // assume incorrect guess

         // see if character is in word
         for(i = 0 ; i < strlen(wrd->answer) ; i++)  {
            if(wrd->answer[i] == (char)character) {
               guess[i] = newGuess[2*i] = (char)character;
               correct = 1;
            }
         }
         // see if word is guessed correctly
         if( !strcmpi(guess, wrd->answer) ){
            prompt[0] = 0;
            numUsedGuesses = 7; // 7 signals win
         }
         else if(correct == 0) {
            numUsedGuesses++;
            currentGIF++;       // use next GIF
            sprintf(prompt,"You have %d guesses left!", 6-numUsedGuesses);
         }
         character = 0;
      }
   }
}
Пример #9
0
void main()
{
	/* FORM stuff */
	sspec_addxmemfile("register.html", reg_form, SERVER_HTTP);
	sspec_addfunction("submit.cgi", submit, SERVER_HTTP);

	/* normal SSI button stuff */
	sspec_addxmemfile("/", index_html, SERVER_HTTP);
	sspec_addxmemfile("index.shtml", index_html, SERVER_HTTP);
	sspec_addxmemfile("showsrc.shtml", showsrc_shtml, SERVER_HTTP);
	sspec_addxmemfile("rabbit1.gif", rabbit1_gif, SERVER_HTTP);
	sspec_addxmemfile("ledon.gif", ledon_gif, SERVER_HTTP);
	sspec_addxmemfile("ledoff.gif", ledoff_gif, SERVER_HTTP);
	sspec_addxmemfile("button.gif", button_gif, SERVER_HTTP);

	sspec_addxmemfile("ssi.c", ssi_c, SERVER_HTTP);

	sspec_addvariable("led1", led1, PTR16, "%s", SERVER_HTTP);
	sspec_addvariable("led2", led2, PTR16, "%s", SERVER_HTTP);
	sspec_addvariable("led3", led3, PTR16, "%s", SERVER_HTTP);
	sspec_addvariable("led4", led4, PTR16, "%s", SERVER_HTTP);

	sspec_addfunction("led1tog.cgi", led1toggle, SERVER_HTTP);
	sspec_addfunction("led2tog.cgi", led2toggle, SERVER_HTTP);
	sspec_addfunction("led3tog.cgi", led3toggle, SERVER_HTTP);
	sspec_addfunction("led4tog.cgi", led4toggle, SERVER_HTTP);
	sspec_addfunction("audit", audit_list_print, SERVER_HTTP);

	strcpy(led1,"ledon.gif");
	strcpy(led2,"ledon.gif");
	strcpy(led3,"ledoff.gif");
	strcpy(led4,"ledon.gif");

	/* Init the audit history */
   	AuditInit();

	/* init FORM searchable names - must init ALL FORMSpec structs! */
	FORMSpec[0].name = "user_name";
	FORMSpec[1].name = "user_email";

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
	http_init();
	tcp_reserveport(80);

	while (1) {
		http_handler();
	}
}
Пример #10
0
/**
 * Does network and HTTP setup
 */
void setupHttp() {
	// IP Buffer
	char buffer[16];
	// User ID
	int userid;

	// Initialize the board
   	brdInit();

	// Initialize the socket
   	sock_init();

	// Wait for IP address to be obtained
	while (ifpending(IF_DEFAULT) == IF_COMING_UP) {
		tcp_tick(NULL);
	}

	// Output the IP Address
	printf("My IP address is %s\n", inet_ntoa(buffer, gethostid()));

	//Set up the HTTP Server
   	http_init();
   	tcp_reserveport(80);

	// Set redirect
	http_set_path("/", "/index.zhtml");

	// Set up authentication
	sspec_addrule("/", "Admin", admin, admin, SERVER_ANY, SERVER_AUTH_BASIC, NULL);

   // Add our users
   // Ario
   userid = sauth_adduser("ario", "fish", SERVER_ANY);
   sauth_setusermask(userid, admin, NULL);
   // Chan
   userid = sauth_adduser("chan", "bar", SERVER_ANY);
   sauth_setusermask(userid, admin, NULL);
   // Jeff
   userid = sauth_adduser("jeff", "bar7", SERVER_ANY);
   sauth_setusermask(userid, admin, NULL);
   // Shea
   userid = sauth_adduser("shea", "bar2", SERVER_ANY);
   sauth_setusermask(userid, admin, NULL);
   // Toby
   userid = sauth_adduser("toby", "bar3", SERVER_ANY);
   sauth_setusermask(userid, admin, NULL);

   //Done
}
Пример #11
0
void main()
{
   brdInit();
	sock_init();
	http_init();
	init_dateform();
   init_log();

	tcp_reserveport(80);			// mark port 80 as a server port.

	for(;;) {
		update_date();
		http_handler();
	}
}
Пример #12
0
void main(void)
{
   brdInit();
   sock_init_or_exit(1);   // call debug function (provides handy information)
   http_init();
   init_dateform();
   init_log();

   tcp_reserveport(80); // mark port 80 as a server port.

   for (;;)
   {
      update_date();
      http_handler();
   }
}
Пример #13
0
SSPEC_RESOURCETABLE_END

void main()
{
	/* init FORM searchable names - must init ALL FORMSpec structs! */
	FORMSpec[0].name = "user_name";
	FORMSpec[1].name = "user_email";

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
	http_init();
	tcp_reserveport(80);

	while (1) {
		http_handler();
	}
}
Пример #14
0
SSPEC_RESOURCETABLE_END

void main()
{
	char buf[20];

   sock_init();
   http_init();
   tcp_reserveport(80);

   printf("Ready: point your browser to http://%s/\n\n", inet_ntoa(buf, MY_ADDR(IF_DEFAULT)));


   while (1) {
      http_handler();
   }
}
Пример #15
0
void main(void)
{
	// Initialize the temperature
	temperature = 72;

	// Initialize the TCP/IP stack and HTTP server
	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();

	// This yields a performance improvement for an HTTP server
	tcp_reserveport(80);

   while (1) {
		// Drive the HTTP server
      http_handler();
   }
}
Пример #16
0
void main(void)
{
	// Initialize the global, #web-registered variables.
	color = 3;
	city = 53549;

	// Initialize the TCP/IP stack and HTTP server
	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();

	// This yields a performance improvement for an HTTP server
	tcp_reserveport(80);

   while (1) {
		// Drive the HTTP server
      http_handler();
   }
}
Пример #17
0
main()
{

	brdInit();				//initialize board for this demo

   strcpy(led1,"ledon.gif");
   strcpy(led2,"ledoff.gif");

   sock_init_or_exit(1);
   http_init();
   tcp_reserveport(80);

   while (1)
   {
   	update_outputs();
      http_handler();

	}
}
Пример #18
0
void main(void)
{
	LogEntry loginfo;
	int status;
	char buf[200];

	/*
	 * This call is necessary to initialize target communications
	 * beween the DeviceMate and the target processor.
	 */
	targetproc_init();

	/*
	 * Initialize the TCP/IP stack and the web server.
	 */
	sock_init();
	http_init();

	/*
	 * The following improves interactive performance of the web server.
	 */
	tcp_reserveport(80);

	/*
	 * Log an initial entry.
	 */
#define LOG_TEST_STRING "~~~{ Started test run. }~~~"
	status = log_put(LOG_MAKEPRI(2,LOG_INFO), 0, LOG_TEST_STRING, strlen(LOG_TEST_STRING));
	if (status != 0) {
		printf("Failed to add 1st message: %d\n", status);
	}
	
	/*
	 * Drive the target communications and the web server continuously.
	 * This is all that is necessary as the main part of the program.
	 */
	for (;;) {
		targetproc_tick();
		http_handler();
	}
}
Пример #19
0
void main()
{
   // initialize the controller
   brdInit();
   sock_init();
   http_init();
   tcp_reserveport(80);

   // set the initial state of the LED's 
   strcpy(led_DS4,"ledon.gif");  ledOut(DS4, ON);
   strcpy(led_DS5,"ledon.gif");  ledOut(DS5, ON);
   strcpy(led_DS6,"ledoff.gif"); ledOut(DS6, OFF);
   strcpy(led_DS7,"ledon.gif");  ledOut(DS7, ON);
   strcpy(led_DS8,"ledon.gif");  ledOut(DS8, ON);

   // process WEB page requests and update the LED's
   while (1) {
      update_leds();
      http_handler();
   }
}
Пример #20
0
main()
{
   // initialize the controller
   initsystem();

   sock_init();
   http_init();
   tcp_reserveport(80);

   // set the initial state of the LED's 
   strcpy(led_LED0,"ledon.gif");  ledOut(LED0, ON);
   strcpy(led_LED1,"ledon.gif");  ledOut(LED1, ON);
   strcpy(led_LED2,"ledon.gif");  ledOut(LED2, ON);
   strcpy(led_LED3,"ledon.gif");  ledOut(LED3, ON);

   // process WEB page requests and update the LED's
   while (1) {
      update_leds();
      http_handler();
   }
}
Пример #21
0
SSPEC_RESOURCETABLE_END

void main()
{

	/*
	 *  sock_init initializes the TCP/IP stack.
	 *  http_init initializes the web server.
	 */

#ifdef USE_IDIGI
	// Start iDigi services
	if (idigi_init())
		exit(1);
#else
	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
#endif
   http_init();

	/*
	 *  tcp_reserveport causes the web server to ignore requests when there
	 *  isn't an available socket (HTTP_MAXSERVERS are all serving index_html
	 *  or rabbit1.gif).  This saves some memory, but can cause the client
	 *  delays when retrieving pages.
	 */

   tcp_reserveport(80);

	/*
	 *  http_handler needs to be called to handle the active http servers.
	 */

   while (1) {
#ifdef USE_IDIGI
		idigi_tick();
#endif
      http_handler();
   }
}
Пример #22
0
void main(void)
{
	// Give sane defaults to the global variables
	strcpy(my_string, "Hello, world!");
	inum = 150;
	lnum = 60000;
	uinum = 123;
	fpoint = 4.0;

	// Initialize the TCP/IP stack and HTTP server
	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();

	// This yields a performance improvement for an HTTP server
	tcp_reserveport(80);

   while (1) {
		// Drive the HTTP server
      http_handler();
   }
}
Пример #23
0
SSPEC_MIMETABLE_END


int main()
{
	int rc;
   char buf[20];

	printf("Initializing filesystem...\n");
	// Note: sspec_automount automatically initializes all known filesystems.  We assume
   // that the first partition on the device will be a valid FAT12 or FAT16 partition
   // which will be mounted on '/A'.
   rc = sspec_automount(SSPEC_MOUNT_ANY, NULL, NULL, NULL);
   if (rc)
   	printf("Failed to initialize, rc=%d\nProceeding anyway...\n", rc);

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();
   http_set_path("/A/", "static.htm");	// Set a root directory (the FAT first partition) and
   												// default resource name.
	tcp_reserveport(80);

   printf("Now try connecting via your web browser.\n");
   printf("Try a URL of http://%s/\n", inet_ntoa(buf, MY_ADDR(IF_DEFAULT)));
   printf("\nPress any key to bring down the server cleanly.\n");

   while (1) {
      http_handler();
      if (kbhit())
      {
		   // You should always unmount the device on exit to flush cache entries
			fat_UnmountDevice(sspec_fatregistered(0)->dev);
        	exit(0);
      }
   }
	return 0;
}
Пример #24
0
void main()
{
	int file;
	int user;
	faraddr_t  xdest;

	// Set up the first file and user
	file = sspec_addxmemfile("rabbitA.gif", rabbit1_gif, SERVER_FTP);
	user = sauth_adduser("anonymous", "", SERVER_FTP);
	ftp_set_anonymous(user);
	sspec_setuser(file, user);
	sspec_setuser(sspec_addxmemfile("test1", rabbit1_gif, SERVER_FTP), user);
	sspec_setuser(sspec_addxmemfile("test2", rabbit1_gif, SERVER_FTP), user);

	/*
	 *  Copy the string from one place in XMEMORY to another.  
	 */
	xdest = xmem_strdup( xtext );
	sspec_setuser( sspec_addxmemfile( "README", xdest, SERVER_FTP ), user );

	// Set up the second file and user
	file = sspec_addxmemfile("rabbitF.gif", rabbit1_gif, SERVER_FTP);
	user = sauth_adduser("foo", "bar", SERVER_FTP);
	sspec_setuser(file, user);
	sspec_setuser(sspec_addxmemfile("test3", rabbit1_gif, SERVER_FTP), user);
	sspec_setuser(sspec_addxmemfile("test4", rabbit1_gif, SERVER_FTP), user);
	
	sock_init();
	ftp_init(NULL); /* use default handlers */

	tcp_reserveport(FTP_CMDPORT);	// Port 21
	
	while(1) {
		ftp_tick();
	}
}
Пример #25
0
void main(void)
{
	// Declare the FormVar array to hold form variable information
	auto FormVar myform[5];
	auto int var;
	auto int form;
	// This array lists the options that are possible for the fail variable
	static const char* fail_options[] = {
		"Email",
		"Page",
		"Email and page",
		"Nothing"
	};

	// Initialize variables
	temphi = 80;
	tempnow = 72;
	templo = 65;
	humidity = 0.3;
	strcpy(fail, "Page");

	// Add the form (array of variables)
	form = sspec_addform("myform.html", myform, 5, SERVER_HTTP);

	// Set the title of the form
	sspec_setformtitle(form, "ACME Thermostat Settings");

	// Add the first variable, and set it up with the form
	var = sspec_addvariable("temphi", &temphi, INT16, "%d", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "High Temp");
	sspec_setfvdesc(form, var, "Maximum in temperature range (60 - 90 &deg;F)");
	sspec_setfvlen(form, var, 5);
	sspec_setfvrange(form, var, 60, 90);
	sspec_setfvcheck(form, var, checkHighTemp);

	// Add the second variable, and set it up with the form
	var = sspec_addvariable("tempnow", &tempnow, INT16, "%d", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Current Temp");
	sspec_setfvdesc(form, var, "Current temperature in &deg;F");
	sspec_setfvlen(form, var, 5);
	sspec_setfvreadonly(form, var, 1);

	// Add the third variable, and set it up with the form
	var = sspec_addvariable("templo", &templo, INT16, "%d", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Low Temp");
	sspec_setfvdesc(form, var, "Minimum in temperature range (50 - 80 &deg;F)");
	sspec_setfvlen(form, var, 5);
	sspec_setfvrange(form, var, 50, 80);
	sspec_setfvcheck(form, var, checkLowTemp);

	// Add the fourth variable, and set it up with the form
	var = sspec_addvariable("failure", fail, PTR16, "%s", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Failure Action");
	sspec_setfvdesc(form, var, "Action to take in case of air-conditioning failure");
	sspec_setfvlen(form, var, 20);
	sspec_setfvoptlist(form, var, fail_options, 4);
	sspec_setfventrytype(form, var, HTML_FORM_PULLDOWN);

	// Add the fifth variable, and set it up with the form
	var = sspec_addvariable("humidity", &humidity, FLOAT32, "%.2f", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Humidity");
	sspec_setfvdesc(form, var, "Target humidity (between 0.0 and 1.0)");
	sspec_setfvlen(form, var, 8);
	sspec_setfvfloatrange(form, var, 0.0, 1.0);

	// Create aliases for this form.  This allows the form to be accessed from
	// other locations.
	sspec_aliasspec(form, "index.html");
	sspec_aliasspec(form, "/");

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();
   tcp_reserveport(80);

   while (1) {
      http_handler();
   }
}
Пример #26
0
void main()
{
	auto char buf[128];
   auto int rc, i, uid, handle;

	text_size = 12345;
	image_size = xgetlong(alice_jpg) & ZIMPORT_MASK;

	printf("Initializing filesystems...\n");
	// Note: sspec_automount automatically initializes all known filesystems.
   rc = sspec_automount(SSPEC_MOUNT_ANY, NULL, NULL, NULL);
   if (rc)
   	printf("Failed to initialize, rc=%d\nProceeding anyway...\n", rc);

	sspec_addxmemfile("/alice.jpg", alice_jpg, SERVER_HTTP | SERVER_COMPRESSED);
	sspec_addvariable("text_size", &text_size, INT32, "%ld", SERVER_HTTP);
   sspec_addvariable("image_size", &image_size, INT32, "%ld", SERVER_HTTP);



   /*
    *  sock_init initializes the TCP/IP stack.
    *  http_init initializes the web server.
    *  ftp_init initializes the FTP server.
    */

   sock_init();
   http_init();
   ftp_init(NULL);

   // Create a permissions rule for fs2, FAT, and everything else
   sspec_addrule("/fs2", "fs2-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL);
   sspec_addrule("/fs2/file1", "another-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL);
   sspec_addrule("/A", "fat-A-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL);
   sspec_addrule("/E", "fat-E-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL);

   // Add users and ensure users are in the correct group(s).
   uid = sauth_adduser("root", "super", SERVER_ANY);
   sauth_setwriteaccess(uid, SERVER_ANY);
   sauth_setusermask(uid, ALL_GROUPS, NULL);

   uid = sauth_adduser("admin", "work", SERVER_HTTP | SERVER_FTP);
   sauth_setwriteaccess(uid, SERVER_HTTP | SERVER_FTP);
   sauth_setusermask(uid, ADMIN_GROUP, NULL);

   uid = sauth_adduser("anonymous", "", SERVER_FTP);
   sauth_setusermask(uid, USER_GROUP, NULL);
   ftp_set_anonymous(uid);	// This FTP user does not require password, but cannot write anything

   uid = sauth_adduser("foo", "bar", SERVER_HTTP);
   sauth_setusermask(uid, USER_GROUP, NULL);

	// First, let's list the current working directory as seen by the 1st HTTP server instance.
   // The CWD for HTTP is always the root directory.
   printf("Root directory listing for the HTTP server...\n");
   for (handle = 0; handle >= 0; handle >= 0 ? printf(buf) : 0)
      handle = sspec_dirlist(handle, buf, sizeof(buf),
                                    http_getcontext(0), SSPEC_LIST_LONG);

   printf("\n");


   /*
    *  tcp_reserveport causes the web server to ignore requests when there
    *  isn't an available socket (HTTP_MAXSERVERS are all serving index_html
    *  or rabbit1.gif).  This saves some memory, but can cause the client
    *  delays when retrieving pages.
    */

   tcp_reserveport(80);

   /*
    *  http_handler needs to be called to handle the active http servers.
    *  ftp_tick needs to be called to handle the active FTP servers.
    */

   printf("Press any key to safely shut-down server.\n");

   while (1) {
      http_handler();
      ftp_tick();
      if (kbhit())
      {
#ifdef DO_FAT
      	// Unmount all of the mounted FAT partitions & devices before exit
  	   	for (i = 0; i < num_fat_devices * FAT_MAX_PARTITIONS;
     	   											 i += FAT_MAX_PARTITIONS) {
	      	if (fat_part_mounted[i]) {
	      		fat_UnmountDevice(fat_part_mounted[i]->dev);
   	   	}
      	}
#endif
        	exit(rc);
      }
   }
}
Пример #27
0
void main(void)
{
	long lxsize;
	LogEntry loginfo;
	int status;
	char buf[200];

	/* File system setup and partitioning */
	fs_ext = fs_get_flash_lx();
	if (fs_ext == 0) {
		printf("No flash available!\n");
		exit(1);
	}

	/*
	 * Get the size of the entire flash with the given sector size
	 */
	lxsize = fs_get_lx_size(fs_ext, 1, MY_LS_SHIFT);
	/*
	 * Partition the filesystem - always give 1/8 to the backup partition, as we
	 * have room to spare.
	 */
	backup_ext = fs_setup(fs_ext, MY_LS_SHIFT, 0, NULL, FS_PARTITION_FRACTION,
	                      0x2000, MY_LS_SHIFT, 0, NULL);
	if (backup_ext == 0) {
		printf("Could not create backup extent!\n");
		exit(2);
	}

	lxsize = fs_get_lx_size(fs_ext, 1, MY_LS_SHIFT);
	lxsize = fs_get_lx_size(backup_ext, 1, MY_LS_SHIFT);

	if (fs_init(0, 0) != 0) {
		printf("Filesystem failed to initialize!\n");
		exit(3);
	}
#ifdef FORMAT
	if (lx_format(fs_ext, 0) != 0) {
		printf("Filesystem failed to format!\n");
		exit(4);
	}
	if (lx_format(backup_ext, 0) != 0) {
		printf("Backup area failed to format!\n");
		exit(5);
	}
#endif

	fs_set_lx(fs_ext, fs_ext);

	/*
	 * Reset all logs if requested.
	 */
#ifdef RESET_ALL_LOGS
	log_open(LOG_DEST_ALL, 1);
#endif

	/*
	 * This call is necessary to initialize target communications
	 * beween the DeviceMate and the target processor.
	 */
	targetproc_init();

	/*
	 * Initialize the TCP/IP stack and the web server.
	 */
	sock_init();
	http_init();

	/*
	 * The following improves interactive performance of the web server.
	 */
	tcp_reserveport(80);
	
	/*
	 * Print out previous log entries
	 */
	if (!log_seek(LOG_DEST_FS2, 0)) {
		printf("Scanning previous log entries, oldest first...\n");
		for (;;) {
			if (log_next(LOG_DEST_FS2, &loginfo) < 0)
				break;
			printf("%s\n", log_format(&loginfo, buf, sizeof(buf), 1));
		}
		printf("End of messages.\n");
	}

	/*
	 * Log an initial entry.
	 */
#define LOG_TEST_STRING "~~~{ Started test run. }~~~"
	status = log_put(LOG_MAKEPRI(2,LOG_INFO), 0, LOG_TEST_STRING, strlen(LOG_TEST_STRING));
	if (status != 0) {
		printf("Failed to add 1st message: %d\n", status);
	}

	/*
	 * Drive the target communications and the web server continuously.
	 * This is all that is necessary as the main part of the program.
	 */
	for (;;) {
		targetproc_tick();
		http_handler();
	}
}
Пример #28
0
SSPEC_MIMETABLE_END

void main(void)
{
	int user1;
	int user2;
	int user3;
	int user1_enabled;
	int user2_enabled;
	int user3_enabled;
	int page1;
	int ch;

	printf("Press '1', '2', or '3' to disable/enable the three users.\n");
	printf("Press 'b', 'd', or 'n' to set the authentication to basic, digest, or none.\n\n");

	/*
	 *  sock_init initializes the TCP/IP stack.
	 *  http_init initializes the web server.
	 */
	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
	http_init();

	/*
	 * HTTP_DIGEST_AUTH is the default authentication type when
	 * digest authentication has been enabled, so this line is not
	 * strictly necessary.  The other possible values are
	 * HTTP_BASIC_AUTH and HTTP_NO_AUTH.
	 */
	http_setauthentication(HTTP_DIGEST_AUTH);
	printf("Using digest authentication\n");

	/*
	 * The following lines add three users, a web page, and an image, and
	 * associates the users with the web page.  The userx_enabled
	 * variables are used to keep track of which users are current
	 * enabled.
	 */
	user1_enabled = 1;
	user2_enabled = 1;
	user3_enabled = 1;
	user1 = sauth_adduser("foo", "bar", SERVER_HTTP);
	user2 = sauth_adduser("foo2", "bar2", SERVER_HTTP);
	user3 = sauth_adduser("foo3", "bar3", SERVER_HTTP);

	page1 = sspec_addxmemfile("/", index_html, SERVER_HTTP);
	sspec_adduser(page1, user1);
	sspec_adduser(page1, user2);
	sspec_adduser(page1, user3);
	sspec_setrealm(page1, "Admin");

	sspec_addxmemfile("rabbit1.gif", rabbit1_gif, SERVER_HTTP);

	/*
	 *  tcp_reserveport causes the web server to ignore requests when there
	 *  isn't an available socket (HTTP_MAXSERVERS are all serving index_html
	 *  or rabbit1.gif).  This saves some memory, but can cause the client
	 *  delays when retrieving pages (versus increasing HTTP_MAXSERVERS).
	 */
	tcp_reserveport(80);

	while (1) {
		/*
		 * Watch for user keypresses
		 */
		if (kbhit()) {
			ch = getchar();
			switch (ch) {
			case '1':
				/*
				 * Handle the keypress for User 1
				 */
				user1_enabled = !user1_enabled;
				if (user1_enabled) {
					/*
					 * sspec_adduser() adds a user to a resource
					 */
					sspec_adduser(page1, user1);
					printf("User 1 enabled\n");
				}
				else {
					/*
					 * sspec_removeuser() removes a user from a resource
					 */
					sspec_removeuser(page1, user1);
					printf("User 1 disabled\n");
				}
				break;
			case '2':
				user2_enabled = !user2_enabled;
				if (user2_enabled) {
					sspec_adduser(page1, user2);
					printf("User 2 enabled\n");
				}
				else {
					sspec_removeuser(page1, user2);
					printf("User 2 disabled\n");
				}
				break;
			case '3':
				user3_enabled = !user3_enabled;
				if (user3_enabled) {
					sspec_adduser(page1, user3);
					printf("User 3 enabled\n");
				}
				else {
					sspec_removeuser(page1, user3);
					printf("User 3 disabled\n");
				}
				break;
			case 'b':
				http_setauthentication(HTTP_BASIC_AUTH);
				printf("Using basic authentication\n");
				break;
			case 'd':
				http_setauthentication(HTTP_DIGEST_AUTH);
				printf("Using digest authentication\n");
				break;
			case 'n':
				http_setauthentication(HTTP_NO_AUTH);
				printf("Using no authentication\n");
				break;
			}
		}

		/*
		 * http_handler needs to be called to handle the active http servers
		 */
		http_handler();
	}
}
Пример #29
0
main()
{
	auto unsigned wKey;
	auto int i;

	/* init FORM searchable names - must init ALL FORMSpec structs! */
	FORMSpec[0].name = "email_from";
	FORMSpec[0].value = emailTemp.from;
	FORMSpec[0].len = MAX_FROM_LEN;
	FORMSpec[1].name = "email_subject";
	FORMSpec[1].value = emailTemp.subject;
	FORMSpec[1].len = MAX_SUBJECT_LEN;
	FORMSpec[2].name = "email_body";
	FORMSpec[2].value = emailTemp.body;
	FORMSpec[2].len = MAX_BODY_LEN;

	initsystem();

	sock_init();
	http_init();
	tcp_reserveport(80);

	FlagInit();
	CreateEmailList();
	LogInit();
	DispBufferInit();
	DispNoEmail();

	while (1) {
		http_handler();

		costate
		{
			keyProcess();			//scans for keypress
			waitfor (DelayMs(10));
		}

		costate
		{
			waitfor (wKey = keyGet());		//get key from buffer
			switch (wKey)
			{
				case DELETE:
					if (emailList.ptr != -1) {
						LogAddEmailEntry("deleted", email.from, email.subject);
						DeleteEmail();
					}
					DispEmail();
					break;
				case READ:
					if ((emailList.ptr != -1) && (emailIndex[emailList.ptr].read != 1)) {
						LogAddEmailEntry("read", email.from, email.subject);
						emailIndex[emailList.ptr].read = 1;
						FlagCheck();
					}
					break;
				case EMAIL_UP:
				if (emailList.ptr != -1) {
					if (emailIndex[emailList.ptr].prev != -1) {
						emailList.ptr = emailIndex[emailList.ptr].prev;
					}
					DispEmail();
				}
				break;
				case EMAIL_DOWN:
					if (emailList.ptr != -1) {
						if (emailIndex[emailList.ptr].next != -1) {
							emailList.ptr = emailIndex[emailList.ptr].next;
						}
						DispEmail();
					}
					break;
				case SCROLL_UP:
					if ((emailList.ptr != -1) && (emailDispLine > 0)) {
						emailDispLine--;
						DispUpdateWindow();
					}
					break;
				case SCROLL_DOWN:
					if ((emailList.ptr != -1) && ((emailDispLine + 4) < emailLastLine)) {
						emailDispLine++;
						DispUpdateWindow();
					}
					break;

				default: // Do nothing
					break;

			} //end switch
		} //end costate
	}
}
Пример #30
0
void main()
{

	int channel;
	My_Socket_Type socket;
	My_InOuts_Type InOuts;
	char DispStrIn[100];
	long IOoutcnt,InCnt;
	// initializing
	InOuts.rtime	= REFRESH_RATE;
	brdInit();
	digOutConfig(0);
	glInit();
	glBlankScreen();
	glSetContrast(24);
	glBackLight(1);
	glXFontInit ( &fi10x12,10,12,0x20,0x7E,Terminal9 );
	glXFontInit ( &fi14x16,14,16,0x20,0x7E,Terminal12 );
	keyInit();
	IOoutcnt = InCnt = 0;
	xmemBtn = btnInit(20);
	for(channel=0;channel<DIGITAL_OUTPUTS;channel++)	// setting digital outputs to low state
		InOuts.dout[channel] = LOW_HIGH[0];
	memset(socket.buff,0x00,BUFF_SIZE);
	socket.nextstate 	= 0;

	sock_init();
	http_init();
	tcp_reserveport(80);

	while(1)
	{
		costate //TCP_HANDLES
		{
			My_Handler(&socket);
			http_handler();
		}

		costate //IO_Ctrl
		{
			waitfor(socket.nextstate == 2 && DelayMs(InOuts.rtime));
			My_IO_Ctrl(&InOuts);

		}

		costate //TCP_RX
		{	// THIS IS WHERE WE RECEIVE INFORMATION FROM THE XML SOCKET
			waitfor(socket.rxbytes || DelayMs(15000) );
			if (socket.rxbytes)
			{
				sprintf(DispStrIn,"Msg From Host\n%s",socket.buff);
				btnMsgBox(0,120,320,120,&fi14x16,DispStrIn,1,0);
					//printf("%sRcvd: %s\n",RED,socket.buff);
				socket.rxbytes = 0;
				My_XML_Parser(socket.buff,&InOuts);
			}
			else
			{
				btnClearRegion(0,120,320,120);
			}
		}

		costate //TCP_TX
		{	// THIS IS WHERE WE SEND INFORMATION TO THE XML SOCKET
			waitfor(socket.nextstate == 2 && DelayMs(InOuts.rtime));
			My_Load_Buffer(0,&socket,&InOuts);		// FILLING SOCKET BUFFER WITH ANALOG INPUTS DATA
			socket.nextstate = 3;						// SET STATEMACHINE TO THE SEND STATE
//			printf("%sSent: %s\n",RED,socket.buff);
			yield;

			My_Load_Buffer(1,&socket,&InOuts);		// FILLING SOCKET BUFFER WITH DIGITAL INPUTS
			socket.nextstate = 3;						// SET STATEMACHINE TO THE SEND STATE
//			printf("%sSent: %s\n",RED,socket.buff);
			yield;

			My_Load_Buffer(2,&socket,&InOuts);		// FILLING SOCKET BUFFER WITH DIGITAL OUTPUT STATUS
			socket.nextstate = 3;						// SET STATEMACHINE TO THE SEND STATE
//			printf("%sSent: %s",RED,socket.buff);
//			printf("\n\n");


		}
	}
}