Skip to content

Commit

Permalink
Merge pull request #2 from max0y/dev
Browse files Browse the repository at this point in the history
merge branch dev
  • Loading branch information
max0y authored Apr 18, 2018
2 parents 650f5e3 + 44fc23b commit 76ec108
Show file tree
Hide file tree
Showing 13 changed files with 719 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-cd8021x
PKG_VERSION=1.2.1
PKG_VERSION=1.2.2
PKG_RELEASE:=1

PKG_LICENSE:=GPLv3
Expand All @@ -18,13 +18,16 @@ define Package/luci-app-cd8021x
SUBMENU:=3. Applications
TITLE:=a wired IEEE 802.1x client for Luci
PKGARCH:=all
DEPENDS:=+wpad
endef

define Package/luci-app-cd8021x/description
This package contains LuCI configuration pages for wired IEEE 802.1x authentication.
endef

define Build/Prepare
$(foreach po,$(wildcard ${CURDIR}/files/root/usr/lib/lua/luci/i18n/*.po), \
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
endef

define Build/Configure
Expand All @@ -38,11 +41,13 @@ define Package/luci-app-cd8021x/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n

$(INSTALL_CONF) ./files/root/etc/config/cd8021x $(1)/etc/config/cd8021x
$(INSTALL_BIN) ./files/root/etc/init.d/cd8021x $(1)/etc/init.d/cd8021x
$(INSTALL_DATA) ./files/root/usr/lib/lua/luci/model/cbi/cd8021x.lua $(1)/usr/lib/lua/luci/model/cbi/cd8021x.lua
$(INSTALL_DATA) ./files/root/usr/lib/lua/luci/controller/cd8021x.lua $(1)/usr/lib/lua/luci/controller/cd8021x.lua
$(INSTALL_DATA) $(PKG_BUILD_DIR)/cd8021x.*.lmo $(1)/usr/lib/lua/luci/i18n/
endef

$(eval $(call BuildPackage,luci-app-cd8021x))
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Configure 802.1x wired authentication on OpenWrt/LEDE<br/>

![screenshot](https://raw.githubusercontent.com/max0y/luci-app-cd8021x/master/screenshot.png)<br/>
![screenshot](https://raw.githubusercontent.com/max0y/luci-app-cd8021x/master/screenshot_en.png)<br/>
## Install<br/>
1. This package depends on *wpad*, you need to remove *wpad-mini* first
1. This package depends on *wpad*, you need to remove *wpad-mini* first, or you can manually download the *wpad* package from [OpenWrt packages site](https://downloads.openwrt.org/releases/17.01.4/packages/).
```bash
opkg update
opkg remove wpad-mini
Expand All @@ -29,6 +29,11 @@ cd openwrt-sdk-ar71xx-*
# clone this repo
git clone https://github.com/max0y/luci-app-cd8021x.git package/luci-app-cd8021x

# complie po2lmo (if you don't have po2lmo)
pushd package/luci-app-cd8021x/tool/po2lmo
make && sudo make install
popd

# run make menuconfig, and choose LuCI -> 3. Applications
make menuconfig

Expand Down
7 changes: 6 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ OpenWrt 802.1x 有线认证拨号界面<br/>

![screenshot](https://raw.githubusercontent.com/max0y/luci-app-cd8021x/master/screenshot_zh.png)<br/>
## 安装<br/>
1. 这个包的功能实现依赖于*wpad*,需要先卸载*wpad-mini*,再安装*wpad*
1. 这个包的功能实现依赖于*wpad*,需要先卸载*wpad-mini*,再安装*wpad*,也可以手动到OpenWrt[官方源](https://downloads.openwrt.org/releases/17.01.4/packages/)处下载*wpad*安装包
```bash
opkg update
opkg remove wpad-mini
Expand All @@ -29,6 +29,11 @@ cd openwrt-sdk-ar71xx-*
# Clone 项目
git clone https://github.com/max0y/luci-app-cd8021x.git package/luci-app-cd8021x

# 编译 po2lmo (如果已安装po2lmo可跳过)
pushd package/luci-app-cd8021x/tool/po2lmo
make && sudo make install
popd

# 运行make menuconfig,选择要编译的包 LuCI -> 3. Applications
make menuconfig

Expand Down
2 changes: 1 addition & 1 deletion files/root/usr/lib/lua/luci/controller/cd8021x.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
module("luci.controller.cd8021x", package.seeall)

function index()
entry({"admin", "network", "cd8021x"}, cbi("cd8021x"), _("cd802.1x client"), 100).dependent = true
entry({"admin", "network", "cd8021x"}, cbi("cd8021x"), _("802.1x Client"), 100).dependent = true
end
14 changes: 14 additions & 0 deletions files/root/usr/lib/lua/luci/i18n/cd8021x.zh-cn.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"

msgid "802.1x Client"
msgstr "802.1x 客户端"

msgid ""
"Configure IEEE 802.1x wired authentication, you may need to edit your WAN interface "
"protocol as <i>DHCP</i> client <a href=\"network\">here</a>"
msgstr ""
"IEEE 802.1x 有线拨号客户端, 使用前需要将WAN口"
"协议修改为<i>DHCP客户端</i>. <a href=\"network\">点击这里</a>"

4 changes: 2 additions & 2 deletions files/root/usr/lib/lua/luci/model/cbi/cd8021x.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ local eap_list = {
"MSCHAPV2",
}

m = Map("cd8021x", translate("cd802.1x client"),
translate("Configure IEEE 802.1x wired authentication, you may need to edit your WAN interface protocol as <i>DHCP client</i> <a href=\"network\">here</a>."))
m = Map("cd8021x", translate("802.1x Client"),
translate("Configure IEEE 802.1x wired authentication, you may need to edit your WAN interface protocol as <i>DHCP</i> client <a href=\"network\">here</a>"))

s = m:section(TypedSection, "login", "")
s.addremove = false
Expand Down
Binary file removed screenshot.png
Binary file not shown.
Binary file added screenshot_en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshot_zh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tool/po2lmo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

INSTALL = install
PREFIX = /usr/local/bin

po2lmo: src/po2lmo.o src/template_lmo.o
$(CC) $(LDFLAGS) -o src/po2lmo src/po2lmo.o src/template_lmo.o

install:
$(INSTALL) -m 755 src/po2lmo $(PREFIX)

clean:
$(RM) src/po2lmo src/*.o

248 changes: 248 additions & 0 deletions tool/po2lmo/src/po2lmo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/*
* lmo - Lua Machine Objects - PO to LMO conversion tool
*
* Copyright (C) 2009-2012 Jo-Philipp Wich <jow@openwrt.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "template_lmo.h"

static void die(const char *msg)
{
fprintf(stderr, "Error: %s\n", msg);
exit(1);
}

static void usage(const char *name)
{
fprintf(stderr, "Usage: %s input.po output.lmo\n", name);
exit(1);
}

static void print(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
if( fwrite(ptr, size, nmemb, stream) == 0 )
die("Failed to write stdout");
}

static int extract_string(const char *src, char *dest, int len)
{
int pos = 0;
int esc = 0;
int off = -1;

for( pos = 0; (pos < strlen(src)) && (pos < len); pos++ )
{
if( (off == -1) && (src[pos] == '"') )
{
off = pos + 1;
}
else if( off >= 0 )
{
if( esc == 1 )
{
switch (src[pos])
{
case '"':
case '\\':
off++;
break;
}
dest[pos-off] = src[pos];
esc = 0;
}
else if( src[pos] == '\\' )
{
dest[pos-off] = src[pos];
esc = 1;
}
else if( src[pos] != '"' )
{
dest[pos-off] = src[pos];
}
else
{
dest[pos-off] = '\0';
break;
}
}
}

return (off > -1) ? strlen(dest) : -1;
}

static int cmp_index(const void *a, const void *b)
{
uint32_t x = ((const lmo_entry_t *)a)->key_id;
uint32_t y = ((const lmo_entry_t *)b)->key_id;

if (x < y)
return -1;
else if (x > y)
return 1;

return 0;
}

static void print_uint32(uint32_t x, FILE *out)
{
uint32_t y = htonl(x);
print(&y, sizeof(uint32_t), 1, out);
}

static void print_index(void *array, int n, FILE *out)
{
lmo_entry_t *e;

qsort(array, n, sizeof(*e), cmp_index);

for (e = array; n > 0; n--, e++)
{
print_uint32(e->key_id, out);
print_uint32(e->val_id, out);
print_uint32(e->offset, out);
print_uint32(e->length, out);
}
}

int main(int argc, char *argv[])
{
char line[4096];
char key[4096];
char val[4096];
char tmp[4096];
int state = 0;
int offset = 0;
int length = 0;
int n_entries = 0;
void *array = NULL;
lmo_entry_t *entry = NULL;
uint32_t key_id, val_id;

FILE *in;
FILE *out;

if( (argc != 3) || ((in = fopen(argv[1], "r")) == NULL) || ((out = fopen(argv[2], "w")) == NULL) )
usage(argv[0]);

memset(line, 0, sizeof(key));
memset(key, 0, sizeof(val));
memset(val, 0, sizeof(val));

while( (NULL != fgets(line, sizeof(line), in)) || (state >= 2 && feof(in)) )
{
if( state == 0 && strstr(line, "msgid \"") == line )
{
switch(extract_string(line, key, sizeof(key)))
{
case -1:
die("Syntax error in msgid");
case 0:
state = 1;
break;
default:
state = 2;
}
}
else if( state == 1 || state == 2 )
{
if( strstr(line, "msgstr \"") == line || state == 2 )
{
switch(extract_string(line, val, sizeof(val)))
{
case -1:
state = 4;
break;
default:
state = 3;
}
}
else
{
switch(extract_string(line, tmp, sizeof(tmp)))
{
case -1:
state = 2;
break;
default:
strcat(key, tmp);
}
}
}
else if( state == 3 )
{
switch(extract_string(line, tmp, sizeof(tmp)))
{
case -1:
state = 4;
break;
default:
strcat(val, tmp);
}
}

if( state == 4 )
{
if( strlen(key) > 0 && strlen(val) > 0 )
{
key_id = sfh_hash(key, strlen(key));
val_id = sfh_hash(val, strlen(val));

if( key_id != val_id )
{
n_entries++;
array = realloc(array, n_entries * sizeof(lmo_entry_t));
entry = (lmo_entry_t *)array + n_entries - 1;

if (!array)
die("Out of memory");

entry->key_id = key_id;
entry->val_id = val_id;
entry->offset = offset;
entry->length = strlen(val);

length = strlen(val) + ((4 - (strlen(val) % 4)) % 4);

print(val, length, 1, out);
offset += length;
}
}

state = 0;
memset(key, 0, sizeof(key));
memset(val, 0, sizeof(val));
}

memset(line, 0, sizeof(line));
}

print_index(array, n_entries, out);

if( offset > 0 )
{
print_uint32(offset, out);
fsync(fileno(out));
fclose(out);
}
else
{
fclose(out);
unlink(argv[2]);
}

fclose(in);
return(0);
}

Loading

0 comments on commit 76ec108

Please sign in to comment.