Exemple #1
0
void main(void)
{
	/*
    * Get the compressed sizes of the files
    */
	xmem2root(&text_size, alice_html, 4);
	text_size &= ZIMPORT_MASK;
	xmem2root(&image_size, alice_jpg, 4);
	image_size &= ZIMPORT_MASK;

	/*
    * When compressed files are added via the sspec_addxmemfile() function,
    * they are automatically detected as such.  This is in distinction to
    * the static resource table setup (i.e. SSPEC_RESOURCE_* macros) which
    * require explicit specification at compile time.
    *
    * Note, that jpeg or gif files (as in the following) do not generally
    * compress well (or at all).  Hence, it is best to leave image files uncompressed.
    */
	sspec_addxmemfile("/alice.jpg", alice_jpg, SERVER_HTTP);
	sspec_addvariable("text_size", &text_size, INT32, "%ld", SERVER_HTTP);
   sspec_addvariable("image_size", &image_size, INT32, "%ld", SERVER_HTTP);

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

   while (1) {
   	http_handler();
   }
}
Exemple #2
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();
	}
}
Exemple #3
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();
	}
}
Exemple #4
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);
      }
   }
}
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();
	}
}
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;
	// Can't store this on the stack (auto) since the HTTP server library stores
	// a reference to it for use later.
	static far 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();

	_f_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);

	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");

	/*
	 * 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_HTTPS);
	user2 = sauth_adduser("foo2", "bar2", SERVER_HTTPS);
	user3 = sauth_adduser("foo3", "bar3", SERVER_HTTPS);

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

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

	/*
	 *  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).
    *  We reserve port 443 for HTTPS communication
	 */
	tcp_reserveport(HTTPS_PORT);

	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();
	}
}