Commit c867dc97 authored by Vladimir Bashkirtsev's avatar Vladimir Bashkirtsev

Initial commit

parents
all: easycwmp-service device-info easycwmp-config
tar xf easycwmp-1.5.3.tar.gz
patch -Np1 -d easycwmp-1.5.3 < easycwmp-1.5.3-blank-device.patch
cd easycwmp-1.5.3 && autoreconf -i
cd easycwmp-1.5.3 && ./configure --prefix=/usr --enable-jsonc=1
$(MAKE) -C easycwmp-1.5.3
$(MAKE) -C easycwmp-1.5.3 install
install -v -Dm755 -d /usr/share/easycwmp/functions
install -v -Dm755 -d /etc/easycwmp
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/easycwmp.sh /usr/sbin/easycwmp
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/defaults /usr/share/easycwmp/defaults
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/functions/common/common /usr/share/easycwmp/functions/common
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/functions/common/device_info /usr/share/easycwmp/functions/device_info
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/functions/common/management_server /usr/share/easycwmp/functions/management_server
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/functions/common/ipping_launch /usr/share/easycwmp/functions/ipping_launch
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/functions/tr181/root /usr/share/easycwmp/functions/root
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/functions/tr181/ip /usr/share/easycwmp/functions/ip
install -v -Dm755 easycwmp-1.5.3/ext/openwrt/scripts/functions/tr181/ipping_diagnostic /usr/share/easycwmp/functions/ipping_diagnostic
install -v -Dm755 ssh /usr/share/easycwmp/functions/ssh
install -v -Dm755 easycwmp-init-device-info /usr/sbin/easycwmp-init-device-info
@echo "$$DEVICE_INFO" > /etc/device_info
install -v -Dm755 -d /etc/config
@echo "$$EASYCWMP_CONFIG" > /etc/config/easycwmp
tar xf ../openwrt/openwrt.tar.xz -C /
@echo "$$EASYCWMP_SERVICE" > /lib/systemd/system/easycwmpd.service
ln -s /lib/systemd/system/easycwmpd.service /etc/systemd/system/multi-user.target.wants/easycwmpd.service
rm -rf easycwmp-1.5.3
easycwmp-service:
define EASYCWMP_SERVICE
[Unit]
Description=EasyCWMP TR-069 client service
After=network-online.target ubus.service
Wants=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStartPre=/usr/sbin/easycwmp-init-device-info
ExecStart=/usr/bin/easycwmpd -f --boot
Restart=on-failure
[Install]
WantedBy=multi-user.target
endef
export EASYCWMP_SERVICE
device-info:
define DEVICE_INFO
DEVICE_MANUFACTURER='$(DEVICE_MANUFACTURER)'
DEVICE_MANUFACTURER_URL='$(DEVICE_MANUFACTURER_URL)'
DEVICE_MANUFACTURER_OUI='$(DEVICE_MANUFACTURER_OUI)'
DEVICE_PRODUCT='$(DEVICE_TYPE)'
DEVICE_REVISION='$(ARTIFACT_NAME)-$(BUILD_ID)'
endef
export DEVICE_INFO
easycwmp-config:
define EASYCWMP_CONFIG
# easycwmp uci configuration
config local
option interface eth0
option port 7547
option ubus_socket /var/run/ubus.sock
option date_format %FT%T%z
option username easycwmp
option password easycwmp
option provisioning_code ''
#Logging levels: Critic=0, Warning=1, Notice=2, Info=3, Debug=4
option logging_level '0'
config acs
option url $(CWMP_SERVER)
option username easycwmp
option password easycwmp
option parameter_key ''
option periodic_enable '1'
option periodic_interval '100'
option periodic_time '0001-01-01T00:00:00Z'
config device
option manufacturer $(DEVICE_MANUFACTURER)
option oui $(DEVICE_MANUFACTURER_OUI)
option product_class $(DEVICE_TYPE)
option serial_number FFFFFF123456
option hardware_version example_hw_version
option software_version example_sw_version
endef
export EASYCWMP_CONFIG
diff -uNr easycwmp-1.5.3/ext/openwrt/scripts/easycwmp.sh easycwmp-1.5.3-blank-device/ext/openwrt/scripts/easycwmp.sh
--- easycwmp-1.5.3/ext/openwrt/scripts/easycwmp.sh 2017-06-01 18:25:35.000000000 +0930
+++ easycwmp-1.5.3-blank-device/ext/openwrt/scripts/easycwmp.sh 2018-08-29 20:14:07.261196306 +0930
@@ -354,11 +354,7 @@
return
fi
if [ "$action" = "factory_reset" ]; then
- if [ "`which jffs2_mark_erase`" != "" ]; then
- jffs2_mark_erase "rootfs_data"
- else
- /sbin/jffs2mark -y
- fi
+ touch /data/.factorydefault
sync
reboot
fi
diff -uNr easycwmp-1.5.3/ext/openwrt/scripts/functions/common/device_info easycwmp-1.5.3-blank-device/ext/openwrt/scripts/functions/common/device_info
--- easycwmp-1.5.3/ext/openwrt/scripts/functions/common/device_info 2017-06-01 18:25:35.000000000 +0930
+++ easycwmp-1.5.3-blank-device/ext/openwrt/scripts/functions/common/device_info 2018-08-29 20:14:07.262196310 +0930
@@ -25,11 +25,12 @@
common_execute_method_param "$DMROOT.DeviceInfo.SerialNumber" "0" "$UCI_GET easycwmp.@device[0].serial_number" "" "" "1"
common_execute_method_param "$DMROOT.DeviceInfo.HardwareVersion" "0" "$UCI_GET easycwmp.@device[0].hardware_version" "" "" "1"
common_execute_method_param "$DMROOT.DeviceInfo.SoftwareVersion" "0" "$UCI_GET easycwmp.@device[0].software_version" "" "" "1"
- common_execute_method_param "$DMROOT.DeviceInfo.UpTime" "0" "device_info_get_uptime" "" "xsd:unsignedInt"
+ common_execute_method_param "$DMROOT.DeviceInfo.UpTime" "0" "device_info_get_uptime" "" "xsd:unsignedInt" "1"
common_execute_method_param "$DMROOT.DeviceInfo.DeviceLog" "0" "dmesg | tail -n1"
common_execute_method_obj "$DMROOT.DeviceInfo.MemoryStatus." "0"
common_execute_method_param "$DMROOT.DeviceInfo.MemoryStatus.Total" "0" "device_info_get_total_memory"
common_execute_method_param "$DMROOT.DeviceInfo.MemoryStatus.Free" "0" "device_info_get_free_memory"
+ common_execute_method_param "$DMROOT.DeviceInfo.HostName" "1" "hostname" "device_info_set_hostname" "" "1"
return 0;
;;
esac
@@ -54,6 +55,14 @@
return 0
}
+device_info_set_hostname() {
+ local val="$1"
+ hostname $val
+ echo "127.0.0.1 localhost $val" > /etc/hosts
+ echo "$val" > /etc/hostname
+ return 0
+}
+
device_info_get_uptime() {
awk -F '.' '{ print $1 }' /proc/uptime
}
#!/bin/sh
UCI_SET="/sbin/uci -q set"
UCI_GET="/sbin/uci -q get"
UCI_COMMIT="/sbin/uci -q commit"
change=0
val=`cat "/etc/device_info" | grep "DEVICE_MANUFACTURER=" | cut -f 2 -d '=' | sed "s/['\"]//g"`
oval=`$UCI_GET easycwmp.@device[0].manufacturer`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].manufacturer="$val"; change=1; }
val=`cat /var/lib/mender/device_type | cut -f 2 -d '=' | sed "s/['\"]//g"`
oval=`$UCI_GET easycwmp.@device[0].product_class`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].product_class="$val"; change=1; }
if [ -f /proc/device-tree/model ] ; then
val=`cat /proc/device-tree/model | tr -d '\0'`
elif [ -f /sys/class/dmi/id/product_version ] ; then
val=`cat /sys/class/dmi/id/product_version | tr -d '\0'`
else
val="N/A"
fi
oval=`$UCI_GET easycwmp.@device[0].hardware_version`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].hardware_version="$val"; change=1; }
val=`cat /etc/mender/artifact_info | cut -f 2 -d '=' | sed "s/['\"]//g"`
oval=`$UCI_GET easycwmp.@device[0].software_version`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].software_version="$val"; change=1; }
val=`cat "/etc/device_info" | grep "DEVICE_MANUFACTURER_OUI=" | cut -f 2 -d '=' | sed "s/['\"]//g" | tr '[a-f]' '[A-F]'`
oval=`$UCI_GET easycwmp.@device[0].oui`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].oui="$val"; change=1; }
val=`deviceserial`
oval=`$UCI_GET easycwmp.@device[0].serial_number`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].serial_number="$val"; change=1; }
[ "$change" = "1" ] && $UCI_COMMIT easycwmp
exit 0
etc
/etc/.*
lib
/lib/config.*
/lib/functions.*
bin
/lib/systemd/system/.*
/usr/sbin/.*
/usr/share/easycwmp/.*
/usr/bin/.*
#!/bin/sh
#common_execute_method_param "$parameter" "$permission" "$get_cmd" "$set_cmd" "xsd:$type" "$forcedinform"
# $forcedinform should be set to 1 if the parameter is included in the inform message otherwise empty
# Default of $type = string
#############################
# Entry point functuons #
#############################
prefix_list="$prefix_list $DMROOT.SSH."
entry_execute_method_list="$entry_execute_method_list entry_execute_method_root_SSH"
entry_execute_method_list_forcedinform="$entry_execute_method_list_forcedinform entry_execute_method_root_SSH"
entry_execute_method_root_SSH() {
case "$1" in ""|"$DMROOT."|"$DMROOT.SSH."*)
common_execute_method_obj "$DMROOT.SSH." "0"
common_execute_method_param "$DMROOT.SSH.RootPassword" "1" "" "ssh_set_root_password"
common_execute_method_obj "$DMROOT.SSH.AuthorizedKey." "1" "add_ssh_key" "" "ssh_key_browse_instances $1"
return 0;
;;
esac
return $E_INVALID_PARAMETER_NAME;
}
ssh_key_browse_instances() {
if [ -f /root/.ssh/authorized_keys ]; then
local lines=$(wc -l /root/.ssh/authorized_keys | awk -F " " "{ print \$1 }")
local j=1
while [ $j -le $lines ]; do
local line=`sed -n "$j""p" /root/.ssh/authorized_keys`
if [ ! -z "$line" ]; then
sub_entry_SSH_AuthorizedKey "$1" "$j"
fi
$((++j))
done
fi
}
sub_entry_SSH_AuthorizedKey() {
local i="$1"
local j="$2"
case_param "$1" belongto "$DMROOT.SSH.AuthorizedKey.$j." && {
common_execute_method_obj "$DMROOT.SSH.AuthorizedKey.$j." "1" "" "del_ssh_key $j"
common_execute_method_param "$DMROOT.SSH.AuthorizedKey.$j.Type" "1" "ssh_key_get_Type $j" "ssh_key_set_Type $j"
common_execute_method_param "$DMROOT.SSH.AuthorizedKey.$j.Key" "1" "ssh_key_get_Key $j" "ssh_key_set_Key $j"
common_execute_method_param "$DMROOT.SSH.AuthorizedKey.$j.Identity" "1" "ssh_key_get_Identity $j" "ssh_key_set_Identity $j"
return 0
}
return $E_INVALID_PARAMETER_NAME;
}
#######################################
# Data model parameters functions #
#######################################
ssh_set_root_password() {
local val="$1"
local pass=`openssl passwd -1 $1`
sed -i --follow-symlinks -e "s,^root:[^:]*:,root:$pass:," /etc/shadow
}
add_ssh_key() {
mkdir -p /root/.ssh
echo " " >> /root/.ssh/authorized_keys
chmod g-w,o-wr /root/.ssh/authorized_keys
local lines=$(wc -l /root/.ssh/authorized_keys | awk -F " " "{ print \$1 }")
echo $lines
}
del_ssh_key() {
sed -i "$1""s|.*||g" /root/.ssh/authorized_keys
return 0
}
ssh_key_get_Type() {
local line=`sed -n $1p /root/.ssh/authorized_keys`
local type=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $1 }'`
echo $type
}
ssh_key_set_Type() {
local line=`sed -n $1p /root/.ssh/authorized_keys`
local type="$2"
local key=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $2 }'`
local identity=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $3 }'`
local pos="$1"
sed -i "$pos""s|.*|$type $key $identity|g" /root/.ssh/authorized_keys
}
ssh_key_get_Key() {
local line=`sed -n $1p /root/.ssh/authorized_keys`
local key=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $2 }'`
echo $key
}
ssh_key_set_Key() {
local line=`sed -n $1p /root/.ssh/authorized_keys`
local type=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $1 }'`
local key="$2"
local identity=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $3 }'`
local pos="$1"
sed -i "$pos""s|.*|$type $key $identity|g" /root/.ssh/authorized_keys
}
ssh_key_get_Identity() {
local line=`sed -n $1p /root/.ssh/authorized_keys`
local identity=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $3 }'`
echo $identity
}
ssh_key_set_Identity() {
local line=`sed -n $1p /root/.ssh/authorized_keys`
local type=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $1 }'`
local key=`echo "$line" | awk 'BEGIN { FS = "[ ]" } { print $2 }'`
local identity="$2"
local pos="$1"
sed -i "$pos""s|.*|$type $key $identity|g" /root/.ssh/authorized_keys
}
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