![]() |
Network Component
Version 7.2
MDK Middleware for IPv4 and IPv6 Networking
|
Functions to filter access to the HTTP server and to work with user accounts. More...
Functions | |
bool | netHTTPs_AcceptClient (const NET_ADDR *addr) |
Accept or deny a connection from a remote HTTP client. [user-provided]. | |
uint8_t | netHTTPs_CheckAccount (const char *username, const char *password) |
Check if an user account exist in the user database. [user-provided]. | |
bool | netHTTPs_FileAccess (uint8_t user_id, const char *fname) |
Check if remote user is allowed to access a file on HTTP server. [user-provided]. | |
uint8_t | netHTTPs_GetUserId (void) |
Retrieve the user identification. [thread-safe]. | |
Functions to filter access to the HTTP server and to work with user accounts.
To filter the access to the HTTP server based on the IP address and port of the connecting client, the optional function netHTTPs_AcceptClient is used. It is part of the template file HTTP_Server_Access.c. If this template file is missing in the µVision project, the function will not be available and thus connections from all remote clients will be accepted. You need to adapt the function to the application's needs by specifying the rules for allowed/blocked clients. The HTTP server will use the information in this function to filter the access.
The multi-user login allows you to create different profiles for different users or groups of users. The profiles define the access rights to different files on the HTTP server. The users which are allowed to access the HTTP server are stored in an user database.
If you want to use multi-user authentication, you need to check the Enable User Authentication in the configuration file (Net_Config_HTTP_Server.h). The default account is a system administrator account, which has no restrictions. All other accounts are created in a separate HTTP_Server_Multiuser.c module. To enable a list of users, you need to adapt the following functions that are included in this module:
bool netHTTPs_AcceptClient | ( | const NET_ADDR * | addr | ) |
Accept or deny a connection from a remote HTTP client. [user-provided].
[in] | addr | structure containing IP address and port of remote HTTP client. |
The function netHTTPs_AcceptClient checks if a connection from a remote client is allowed or not. This enables remote client filtering. You can selectively decide which clients are allowed to connect to the web server.
The argument addr points to a buffer containing the IP address and port of the remote machine.
Code Example
The following example is available in the user code template file HTTP_Server_Access.c. Customize it to the application's needs.
uint8_t netHTTPs_CheckAccount | ( | const char * | username, |
const char * | password | ||
) |
Check if an user account exist in the user database. [user-provided].
[in] | username | pointer to username. |
[in] | password | pointer to password. |
The function netHTTPs_CheckAccount checks if an user account exist in the user database for the provided credentials. It is called from the Network Component's HTTP server to check if the user with provided credentials is allowed to access the web pages or not.
The argument username points to a null-terminated string representing the user name that was typed in from the browser.
The argument password points to a null-terminated string representing the password.
Code Example
The following example is available in the user code template file HTTP_Server_Multiuser.c. Customize it to the application's needs.
bool netHTTPs_FileAccess | ( | uint8_t | user_id, |
const char * | fname | ||
) |
Check if remote user is allowed to access a file on HTTP server. [user-provided].
[in] | user_id | user identification number. |
[in] | fname | name of a file to access. |
The function netHTTPs_FileAccess checks if a file access is allowed for a specified user. This enables access protection of sensitive web pages. Protected web pages will not be displayed for unprivileged users. Instead, the Web server shows "Error Page 403 - Forbidden".
The argument user_id is an user identification number as returned by netHTTPs_CheckAccount. It identifies the user who is trying to access the specified file.
The argument fname points to a buffer containing the file name of a file, which the user is trying to access. The file name is a null-terminated string.
Code Example
The following example is available in the user code template file HTTP_Server_Multiuser.c. Customize it to the application's needs.
uint8_t netHTTPs_GetUserId | ( | void | ) |
Retrieve the user identification. [thread-safe].
The function netHTTPs_GetUserId retrieves the user identification number when the web pages are protected with user authentication. It can be used to generate a web page, whose content is based on the connected user. This function is normally called from the netCGI_Script function.
netHTTPs_GetUserId is a system function that is in the Network Component library.
Code Example