Skip to content

Update README.md #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 1 addition & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1 @@
## Adding a Custom Tab to a Web Page in OpenWrt

![opnwrt1](https://github.com/rahulelex/adding-a-custom-tab-to-a-webpage-in-openwrt/assets/46785940/ce748252-181a-4b4f-9cd2-341fa8a74862)

To add a custom tab to a web page in OpenWrt, which is hosted at http://192.168.1.1/cgi-bin/luci/
### Step 1: Creating the .lua file:
Make sure the ***nano*** command is installed in your OpenWrt, if not install it using the command 'opkg update' and then 'opkg install nano'.
```sh
nano /usr/lib/lua/luci/controller/my_page.lua
```

### Step 2: Writing code in my_page.lua
```ruby
module("luci.controller.my_page", package.seeall)
function index()
entry({"admin", "my_page"}, template("my_page"), "My Webpage", 70)
end
```
- ***"admin", "my_page"***: This defines the URL path where the tab will appear. In this case, it will appear under the "admin" section with the label "my_page".
- ***template("my_page")***: Refers to the template file to be used for rendering the content of the tab. The template file is named ***my_page.htm*** in your instructions.
- ***"My Webpage"***: This is the label that will be displayed for the tab in the navigation menu.
- ***70***: This is the priority of the tab. It determines the order in which the tabs appear in the menu. Lower numbers will appear first.

### Step 3: Generating the .htm file
```sh
nano /usr/lib/lua/luci/view/my_webpage.htm
```
### Step 4: Writing content in my_webpage.htm
```ruby
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- <meta http-equiv="refresh" content="0; URL=http://localhost:8090/my-page"> -->
<title>Redirect to Your Domain</title>
</head>
<%#
Copyright 2008 Steven Barth <[email protected]>
Copyright 2008-2019 Jo-Philipp Wich <[email protected]>
Licensed to the public under the Apache License 2.0.
-%>

<script type="text/javascript">
var host = document.location.hostname;
var redirectUrl = `http://${host}:8080/`;
document.location.replace(redirectUrl);
</script>

<body>
<h1>Redirecting to Your Domain...</h1>
</body>
</html>
```
By just following above mentioned 4 steps you will be able to add a custom tab in the existing web page of openwrt hosted at http://192.168.1.1/cgi-bin/luci/

## License
**Free Software, Hell Yeah!**

## Authors
- [Rahul Gupta](https://github.com/rahulelex)
"private"