Commit 838f6cdc authored by chenhaowen's avatar chenhaowen

first commit for version 1.4

parents
test
log
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/package.mk
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_NAME:=gdut-drcom
# Version: 1.0-1
PKG_VERSION:=1.4
PKG_RELEASE:=1
PKG_MAINTAINER:=CHW
# PKG_SOURCE_URL:=
define Package/gdut-drcom
SECTION:=utils
CATEGORY:=Utilities
DEFAULT:=y
TITLE:=xdh3c -- a h3c client for linux
# DEPENDS:=+libgcrypt
DEPENDS:=+libopenssl
endef
define Build/Prepare
@echo "############## Build/Prepare"
$(Build/Prepare/Default)
$(CP) ./src/* $(PKG_BUILD_DIR)
endef
define Build/Compile
@echo "############## Build/Compile"
export CFLAGS="$CFLAGS -DDEBUG"
$(call Build/Compile/Default, cryptlib=openssl)
endef
define Package/gdut-drcom/postinst
#!/bin/sh
echo "post install: patching ppp.sh"
sed -i '/proto_run_command/i username=$$(echo -e "\\r\\n$$username") #added by gdut-drcom!' /lib/netifd/proto/ppp.sh
echo "patched!"
endef
define Package/gdut-drcom/prerm
#!/bin/sh
echo "pre remove: unpatching ppp.sh!"
sed -i '/#added by gdut-drcom/d' /lib/netifd/proto/ppp.sh
echo "unpatched!"
endef
define Package/gdut-drcom/install
@echo "############## Package/gdut-drcom/install"
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/gdut-drcom $(1)/usr/bin
$(INSTALL_DIR) $(1)/etc
$(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/gdut-drcom.conf $(1)/etc
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) $(PKG_BUILD_DIR)/etc/init.d/gdut-drcom $(1)/etc/init.d
endef
$(eval $(call BuildPackage,gdut-drcom))
#CC:=gcc
CFLAGS+=-DDEBUG
#cryptlib=openssl
#ifeq ($(lib), openssl)
# CFLAGS+=-D_WITH_OPENSSL_
# LIBS:=-lcrypto
#else
# LIBS:=-lpolarssl
#endif
ifeq ($(cryptlib), polarssl)
CFLAGS+=-D__WITH_POLARSSL__
LIBS:=-lpolarssl
else ifeq ($(cryptlib), gcrypt)
CFLAGS+=-D__WITH_GCRYPT__
LIBS:=-lgcrypt
else
LIBS:=-lcrypto
endif
all: gdut-drcom
@echo gdut-drcom
gdut-drcom: gdut-drcom.o config.o auth.o
$(CC) gdut-drcom.o config.o auth.o -o gdut-drcom $(CFLAGS) $(LIBS)
gdut-drcom.o: gdut-drcom.c
$(CC) $(CFLAGS) -c $<
config.o: config.c config.h
$(CC) $(CFLAGS) -c $<
auth.o: auth.c config.h
$(CC) $(CFLAGS) -c $<
clean:
rm -f gdut-drcom *.o
This diff is collapsed.
#ifdef __AUTH_H__
#define __AUTH_H__
int auth(void);
#endif //__AUTH_H__
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
struct option_s {
char key[256];
char value[256];
};
/* extern variables */
struct config_s drcom_config = {
.remote_port = 61440,
};
/* extern variables */
/* locale functions */
static int parse_line(char *buf, int size);
static void strstrip(char *s, char *chars);
/* locale functions */
int parse_config(char *conf_file_name)
{
// char conf_file_name[256] = "/etc/gdut-drcom.conf";
char line_buf[1024];
#ifdef DEBUG
fprintf(stdout, "conf_file_name = %s\n", conf_file_name);
fflush(stdout);
#endif
FILE *fp = fopen(conf_file_name, "r");
if (fp == NULL)
{
fprintf(stderr, "open %s failed!\n", conf_file_name);
fflush(stderr);
exit(-1);
}
while(!feof(fp))
{
memset(line_buf, 0, sizeof(line_buf));
fgets(line_buf, sizeof(line_buf)-1, fp);
if (strlen(line_buf) > 0)
{
parse_line(line_buf, sizeof(line_buf));
}
}
fclose(fp);
return 0;
}
static int parse_line(char *buf, int size)
{
char *p;
struct option_s opt = {0};
//comment
p = strchr(buf, '#');
if (p)
*p = '\0';
p = strchr(buf, '=');
if (p == NULL)
return 1;
strncpy(opt.key, buf, p - buf);
strstrip(opt.key, " \n\r\t");
if ((opt.key[0]=='"' && opt.key[strlen(opt.key)-1]=='"') ||
(opt.key[0]=='\'' && opt.key[strlen(opt.key)-1]=='\''))
strstrip(opt.key, "\"'");
strncpy(opt.value, p+1, strlen(p));
strstrip(opt.value, " \r\t\n");
if ((opt.value[0]=='"' && opt.value[strlen(opt.value)-1]=='"') ||
(opt.value[0]=='\'' && opt.value[strlen(opt.value)-1]=='\''))
strstrip(opt.value, "\"'");
if (strcmp(opt.key, "remote_ip") == 0)
{
strcpy(drcom_config.remote_ip, opt.value);
}
else if (strcmp(opt.key, "remote_port") == 0)
{
drcom_config.remote_port = atoi(opt.value);
}
else if(strcmp(opt.key, "keep_alive1_flag") == 0)
{
sscanf(opt.value, "%02hhx", &drcom_config.keep_alive1_flag);
}
/* else if(strcmp(opt.key, "keep_alive2_flag") == 0)
{
sscanf(opt.value, "%02hhx", &drcom_config.keep_alive2_flag);
}*/
return 0;
}
static void strstrip(char *s, char *chars)
{
int i;
char *p;
p = s;
while (strchr(chars, *p)!=NULL && *p!='\0')
{
p++;
}
strcpy(s, p);
i = strlen(s) - 1;
while (strchr(chars, s[i])!=NULL && i>=0)
{
s[i] = '\0';
i--;
}
}
#ifndef __CONFIG_H__
#define __CONFIG_H__
struct config_s {
char remote_ip[20];
int remote_port;
unsigned char keep_alive1_flag;
};
extern struct config_s drcom_config;
int parse_config(char * conf_file_name);
#endif //__CONFIG_H__
remote_ip = 10.0.3.2
keep_alive1_flag = 2a
#!/bin/sh /etc/rc.common
#(c) 2010 ivan_wl
START=99
start() {
service_start /usr/bin/gdut-drcom -c /etc/gdut-drcom.conf 1> /tmp/gdut-drcom.log 2>/tmp/gdut-drcom_error.log&
}
stop()
{
service_stop /usr/bin/gdut-drcom
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "auth.h"
#include "config.h"
static void print_help(char * name);
int main(int argc, char *argv[])
{
char conf_file_name[256] = {0};
if (argc == 1)
{
print_help(argv[0]);
exit(-1);
}
int opt;
while (1)
{
int option_index = 0;
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"config-file", required_argument, 0, 'c'},
{"remote-ip", required_argument, 0, 0},
{"remote-port", required_argument, 0, 1},
{"keep-alive1-flag", required_argument, 0, 2},
{0, 0, 0, 0},
};
opt = getopt_long(argc, argv, "hc:", long_options, &option_index);
if (opt == -1)
{
break;
}
switch (opt)
{
case 0: //remote-ip
strcpy(drcom_config.remote_ip, optarg);
break;
case 1: //remote_port
drcom_config.remote_port = atoi(optarg);
break;
case 2: //keep_alive1_flag
sscanf(optarg, "%02hhx", &drcom_config.keep_alive1_flag);
break;
case 'c':
strcpy(conf_file_name, optarg);
parse_config(conf_file_name);
break;
case 'h':
print_help(argv[0]);
exit(0);
break;
case '?':
break;
default:
break;
}
}
// if (!conf_file_name[0] == '\0')
// {
// parse_config(conf_file_name);
// }
#ifdef DEBUG
fprintf(stdout, "drcom_config.remote_ip = %s\n", drcom_config.remote_ip);
fprintf(stdout, "drcom_config.remote_port = %d\n", drcom_config.remote_port);
fprintf(stdout, "drcom_config.keep_alive1_flag = %02hhx\n", drcom_config.keep_alive1_flag);
fflush(stdout);
#endif
auth();
return 0;
}
static void print_help(char *name)
{
fprintf(stdout, "gdut-drcom\n");
fprintf(stdout, " A third-partydrcom client for gdut.\n\n");
fprintf(stdout, "usage:\n");
fprintf(stdout, " %s\n", name);
fprintf(stdout, " --remote-ip <ip addr>\t\tThe server ip.\n");
fprintf(stdout, "\n");
fprintf(stdout, " [--remote-port <port>]\t\tThe server port, default as 61440.\n");
fprintf(stdout, " [--keep-alive1-flag <flag>]\t\tThe keep alive 1 packet's flag,"
"\t\t\t\t\t\t\t\t default as 00.\n");
fprintf(stdout, " [-c, --config-file <file>]\t\tThe path to config file. "
"\t\t\t\t\t\t\t\t default as /etc/gdut-drcom.conf\n");
fprintf(stdout, " [-h, --help]\t\t\tPrint this message.\n");
}
config gdut-drcom
option username '3114000294'
option password '166511'
option remote-ip '0.0.0.0'
option keep-alive1-flag '2a'
option enable '1'
module("luci.controller.gdut-drcom", package.seeall)
function index()
entry({"admin", "network", "gdut-drcom"}, cbi("gdut-drcom"), _("gdut-drcom client"), 100)
end
--[[
LuCI - Lua Configuration Interface
Copyright 2010 Jo-Philipp Wich <xm@subsignal.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
]]--
require("luci.sys")
m = Map("gdut-drcom", translate("gdut-drcom Client"), translate("Configure gdut-drcom client."))
s = m:section(TypedSection, "gdut-drcom", "")
s.addremove = false
s.anonymous = true
enable = s:option(Flag, "enable", translate("Enable"))
remote_ip = s:option(Value, "remote-ip", translate("Remote ip"))
keep_alive_flag = s:option(Value, "keep-alive1-flag", translate("Keep alive1 flag"))
local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("echo gdut-drcom apply >> /root/gdut-drcom.log")
end
return m
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment