-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Mobsya/main
documentation
- Loading branch information
Showing
4,157 changed files
with
1,243,064 additions
and
153 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
299 changes: 299 additions & 0 deletions
299
...nwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/GettingStarded.stories.mdx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ard/src/hooks/useLuciRCPjsonClient/fetchCalls/getAllDevicesIP:Names.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Meta, Description } from '@storybook/addon-docs' | ||
|
||
<Meta | ||
title="HTTP CAlls/get all devices" | ||
parameters={{ | ||
viewMode: 'docs', | ||
previewTabs: { | ||
canvas: { hidden: true } | ||
}, | ||
}} | ||
/> | ||
|
||
# Get All Devices | ||
|
||
### API CALL: `getDevices` | ||
|
||
This function retrieves the devices connected to the Thymio2+ router, particularly tablets. | ||
|
||
#### Parameters: | ||
|
||
- `sid`: A `Sid` object containing the session ID required for authentication. | ||
|
||
#### Returns: | ||
|
||
- A Promise resolving to an array of devices connected to the router. Each device object contains the following properties: | ||
- `ip`: The IP address of the device. | ||
- `id`: The unique identifier of the device. | ||
- `mac`: The MAC address of the device. | ||
- `active`: A boolean indicating whether the device is currently active or not. | ||
|
||
#### Example Usage: | ||
|
||
```javascript | ||
import { Sid } from '..'; | ||
|
||
// Sample session ID | ||
const sid: Sid = 'sampleSessionID'; | ||
|
||
async function fetchDevices() { | ||
try { | ||
const devices = await getDevices({ sid }); | ||
console.log(devices); | ||
} catch (error) { | ||
console.error('Error fetching devices:', error.message); | ||
} | ||
} | ||
|
||
fetchDevices(); | ||
``` | ||
|
||
#### Details: | ||
|
||
1. **Function**: `matchesThymioPattern` | ||
|
||
- Description: Checks if the input string matches the pattern 'Thymio-XXXXXX.lan'. | ||
- Parameters: `str` - The input string to be tested. | ||
- Returns: A boolean indicating whether the input string matches the pattern or not. | ||
|
||
2. **Function**: `getDevices` | ||
|
||
- Description: Retrieves the devices connected to the Thymio2+ router, particularly tablets. | ||
- Parameters: An object containing the session ID (`sid`). | ||
- Returns: A Promise resolving to an array of device objects. | ||
- Steps: | ||
1. Constructs the necessary HTTP request headers. | ||
2. Fetches IP address hints from the router. | ||
3. Fetches MAC address hints from the router. | ||
4. Merges IP and MAC address data to form device objects. | ||
5. Filters out devices that do not match the Thymio pattern. | ||
- Throws: An error if fetching devices fails. | ||
|
||
#### Important Note: | ||
|
||
- Ensure that the `Sid` object passed to the function contains a valid session ID for authentication with the router. | ||
|
||
#### Dependencies: | ||
|
||
- This function relies on the `fetch` API for making HTTP requests. | ||
|
||
#### Security Considerations: | ||
|
||
- Ensure that the session ID (`sid`) used for authentication is obtained securely and is not exposed to unauthorized users. | ||
- Implement proper error handling and validation to handle unexpected responses from the router. | ||
- Use HTTPS instead of HTTP for secure communication with the router whenever possible. |
93 changes: 93 additions & 0 deletions
93
...fig-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getIfstatus.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Meta, Description } from '@storybook/addon-docs' | ||
|
||
<Meta | ||
title="HTTP CAlls/get if status" | ||
parameters={{ | ||
viewMode: 'docs', | ||
previewTabs: { | ||
canvas: { hidden: true } | ||
}, | ||
}} | ||
/> | ||
|
||
# Get Network Status | ||
|
||
### API CALL: : `getIfStatus` | ||
|
||
This function retrieves the status of the network interface from the router. | ||
|
||
#### Parameters: | ||
|
||
- `sid`: A `Sid` object containing the session ID required for authentication. | ||
|
||
#### Returns: | ||
|
||
- A Promise resolving to an object representing the status of the network interface. | ||
|
||
#### Example Usage: | ||
|
||
```javascript | ||
import { Sid } from '..'; | ||
|
||
// Sample session ID | ||
const sid: Sid = 'sampleSessionID'; | ||
|
||
async function fetchIfStatus() { | ||
try { | ||
const ifStatus = await getIfStatus({ sid }); | ||
console.log(ifStatus); | ||
} catch (error) { | ||
console.error('Error fetching interface status:', error.message); | ||
} | ||
} | ||
|
||
fetchIfStatus(); | ||
``` | ||
|
||
#### Details: | ||
|
||
1. **Function**: `getIfStatus` | ||
|
||
- Description: Retrieves the status of the network interface from the router. | ||
- Parameters: An object containing the session ID (`sid`). | ||
- Returns: A Promise resolving to an object representing the status of the network interface. | ||
- Throws: An error if fetching the interface status fails. | ||
|
||
2. **Default Status Object**: | ||
|
||
- Description: A default status object returned when the interface status is not found. | ||
- Fields: | ||
- `up`: Indicates if the interface is up. | ||
- `pending`: Indicates if there are pending changes. | ||
- `available`: Indicates if the interface is available. | ||
- `autostart`: Indicates if the interface starts automatically. | ||
- `dynamic`: Indicates if the interface is dynamic. | ||
- `uptime`: Uptime of the interface. | ||
- `l3_device`: Layer 3 device. | ||
- `proto`: Protocol used. | ||
- `device`: Device name. | ||
- `updated`: Updated fields. | ||
- `metric`: Metric value. | ||
- `dns_metric`: DNS metric value. | ||
- `delegation`: Indicates if delegation is enabled. | ||
- `ipv4-address`: Array of IPv4 addresses. | ||
- `ipv6-address`: Array of IPv6 addresses. | ||
- `ipv6-prefix`: Array of IPv6 prefixes. | ||
- `ipv6-prefix-assignment`: Array of IPv6 prefix assignments. | ||
- `route`: Array of routes. | ||
- `dns-server`: Array of DNS servers. | ||
- `dns-search`: Array of DNS search domains. | ||
- `neighbors`: Array of neighbors. | ||
- `inactive`: Inactive status fields. | ||
- `data`: Additional data. | ||
- Note: This default status object is returned when the interface status is not found. | ||
|
||
#### Dependencies: | ||
|
||
- This function relies on the `fetch` API for making HTTP requests. | ||
|
||
#### Security Considerations: | ||
|
||
- Ensure that the session ID (`sid`) used for authentication is obtained securely and is not exposed to unauthorized users. | ||
- Implement proper error handling and validation to handle unexpected responses from the router. | ||
- Use HTTPS instead of HTTP for secure communication with the router whenever possible. |
3 changes: 0 additions & 3 deletions
3
apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getIfstatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...shboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getInternetStatus.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Meta, Description } from '@storybook/addon-docs' | ||
|
||
<Meta | ||
title="HTTP CAlls/get internet status" | ||
parameters={{ | ||
viewMode: 'docs', | ||
previewTabs: { | ||
canvas: { hidden: true } | ||
}, | ||
}} | ||
/> | ||
|
||
# Get Internet Status | ||
|
||
### API CALL: getInternetStatus | ||
|
||
#### Overview | ||
The `getInternetStatus` function checks if the device has an active internet connection by attempting to reach Google's homepage. It returns a boolean value indicating whether the internet is accessible. | ||
|
||
#### Imports | ||
```javascript | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
import { Sid } from '..'; | ||
``` | ||
- **axios**: Used for making HTTP requests. | ||
- **AxiosRequestConfig**: Type used for configuring the axios request. | ||
- **Sid**: A type imported from the parent directory, presumably representing session ID or similar credentials. | ||
|
||
#### Parameters | ||
- `sid`: A session identifier of type `Sid`, required to authenticate or manage the session context for the request. | ||
|
||
#### Returns | ||
- **Promise of boolean**: ```Promise<boolean>``` A promise that resolves to `true` if the internet is reachable, otherwise `false`. | ||
|
||
#### Function Logic | ||
1. **Prepare the Request:** | ||
- The function constructs a JSON string that includes the command to check internet connectivity by using `wget` to quietly fetch Google's homepage. | ||
- The command will print 'true' if the fetch is successful, and 'false' otherwise. | ||
|
||
```javascript | ||
const data = JSON.stringify({ | ||
method: 'exec', | ||
params: ["wget -q --spider http://www.google.com 2>/dev/null && echo 'true' || echo 'false'"], | ||
}); | ||
``` | ||
|
||
2. **Configure the Request:** | ||
- An axios configuration object is set up, specifying the HTTP method, URL endpoint, headers, data, and timeout for the request. | ||
|
||
```javascript | ||
const config: AxiosRequestConfig = { | ||
method: 'post', | ||
url: '/cgi-bin/luci/rpc/sys', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
data: data, | ||
timeout: 4000, | ||
}; | ||
``` | ||
|
||
3. **Execute the Request and Handle Response:** | ||
- The axios library is used to send the configured request asynchronously. | ||
- If the HTTP response status is not 200, an error is thrown. | ||
- The function checks if the response contains 'true' within the result field to determine internet connectivity. | ||
|
||
```javascript | ||
const response = await axios(config); | ||
if (response.status !== 200) { | ||
throw new Error('Error fetching getWifiConfigFile'); | ||
} | ||
return response.data.result.includes('true'); | ||
``` | ||
|
||
4. **Error Handling:** | ||
- The catch block handles various errors such as axios cancellation due to timeout, server responses indicating failure, no response received, or other axios errors. | ||
- In any error scenario, the function returns `false`, indicating no internet connectivity. | ||
|
||
```javascript | ||
catch (error: any) { | ||
if (axios.isCancel(error)) { | ||
// Request was cancelled due to timeout | ||
return false; | ||
} else if (error.response) { | ||
// Server responded with an error | ||
return false; | ||
} else if (error.request) { | ||
// No response was received | ||
return false; | ||
} else { | ||
// Other errors | ||
console.log('Error:', error.message); | ||
} | ||
return false; | ||
} | ||
``` | ||
|
||
#### Usage Example | ||
```javascript | ||
const isConnected = await getInternetStatus({ sid: yourSessionId }) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getUptime.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getWifiStatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
.../openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/updateRootPassword.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BUNDLE_PATH: "vendor/bundle" | ||
BUNDLE_FORCE_RUBY_PLATFORM: 1 |
Oops, something went wrong.