/** * 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 }
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); } } }