diff --git a/openrouter/src/settings/dns/enabled.cpp b/openrouter/src/settings/dns/enabled.cpp index 465008b..dbaf147 100644 --- a/openrouter/src/settings/dns/enabled.cpp +++ b/openrouter/src/settings/dns/enabled.cpp @@ -77,12 +77,12 @@ void set_dns(const httplib::Request &request, httplib::Response &response) { std::ofstream dnsfileout("/etc/openrouter/dns"); std::string new_dns_enabled = json_body["enabled"]; if (new_dns_enabled == "0") { - system("/etc/init.d/dnsmasq stop"); - system("rm-rc.d 60dnsmasq"); + system("rc stop dnsmasq"); + system("rc del dnsmasq"); syslog(LOG_INFO, "DNS is disabled"); } else { - system("/etc/init.d/dnsmasq restart"); - system("add-rc.d dnsmasq 60"); + system("rc restart dnsmasq"); + system("rc add dnsmasq"); syslog(LOG_INFO, "DNS is enabled"); } dnsfileout << stoi(new_dns_enabled); diff --git a/openrouter/src/settings/dns/local_domains.cpp b/openrouter/src/settings/dns/local_domains.cpp index 8c71681..4f76866 100644 --- a/openrouter/src/settings/dns/local_domains.cpp +++ b/openrouter/src/settings/dns/local_domains.cpp @@ -92,7 +92,7 @@ void set_local_domains(const httplib::Request &request, httplib::Response &respo domainsfile << ip << " " << dom << "\n"; } domainsfile.close(); - system("/etc/init.d/dnsmasq restart"); + system("rc restart dnsmasq"); syslog(LOG_INFO, "DNS local domains changed"); std::string responsedata = R"({"success":"true"})"; response.set_content(responsedata, JSON_TYPE); diff --git a/openrouter/src/settings/dns/servers.cpp b/openrouter/src/settings/dns/servers.cpp index 0f1dbc7..17581d2 100644 --- a/openrouter/src/settings/dns/servers.cpp +++ b/openrouter/src/settings/dns/servers.cpp @@ -90,7 +90,7 @@ void set_dns_servers(const httplib::Request &request, httplib::Response &respons dnsserversfile << "nameserver " << srv << "\n"; } dnsserversfile.close(); - system("/etc/init.d/dnsmasq restart"); + system("rc restart dnsmasq"); syslog(LOG_INFO, "DNS servers changed"); std::string responsedata = R"({"success":"true"})"; response.set_content(responsedata, JSON_TYPE); diff --git a/openrouter/src/settings/ftp/ftp.cpp b/openrouter/src/settings/ftp/ftp.cpp index 8690a78..fac8e3a 100644 --- a/openrouter/src/settings/ftp/ftp.cpp +++ b/openrouter/src/settings/ftp/ftp.cpp @@ -77,12 +77,12 @@ void set_ftp(const httplib::Request &request, httplib::Response &response) { std::ofstream ftpfileout("/etc/openrouter/ftp"); std::string new_ftp_enabled = json_body["enabled"]; if (new_ftp_enabled == "0") { - system("/etc/init.d/ftp stop"); - system("rm-rc 90ftp"); + system("rc stop ftp"); + system("rc del ftp"); syslog(LOG_INFO, "Ftp is disabled"); } else { - system("/etc/init.d/ftp start"); - system("add-rc ftp 90"); + system("rc start ftp"); + system("rc add ftp"); syslog(LOG_INFO, "Ftp is enabled"); } ftpfileout << stoi(new_ftp_enabled); diff --git a/openrouter/src/settings/ssh/keys.cpp b/openrouter/src/settings/ssh/keys.cpp index 2335ef5..b95dbfd 100644 --- a/openrouter/src/settings/ssh/keys.cpp +++ b/openrouter/src/settings/ssh/keys.cpp @@ -87,7 +87,7 @@ void set_ssh_keys(const httplib::Request &request, httplib::Response &response) keysfile << key << "\n"; } keysfile.close(); - system("/etc/init.d/ssh restart"); + system("rc restart ssh"); syslog(LOG_INFO, "SSH keys changed"); std::string responsedata = R"({"success":"true"})"; response.set_content(responsedata, JSON_TYPE); diff --git a/openrouter/src/settings/ssh/port.cpp b/openrouter/src/settings/ssh/port.cpp index 8ebe46b..c55e844 100644 --- a/openrouter/src/settings/ssh/port.cpp +++ b/openrouter/src/settings/ssh/port.cpp @@ -90,7 +90,7 @@ void set_ssh_port(const httplib::Request &request, httplib::Response &response) systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config"; std::cout << systemrequest.str() << std::endl; system(systemrequest.str().c_str()); - system("/etc/init.d/ssh restart"); + system("rc restart ssh"); std::string syslogstring = "SSH port changed to " + new_ssh_port; syslog(LOG_INFO, syslogstring.c_str()); std::ifstream sshportfile(SSH_PORT_PATH); diff --git a/openrouter/src/settings/ssh/status.cpp b/openrouter/src/settings/ssh/status.cpp index 3eb6858..185f32d 100644 --- a/openrouter/src/settings/ssh/status.cpp +++ b/openrouter/src/settings/ssh/status.cpp @@ -76,12 +76,12 @@ void set_ssh_status(const httplib::Request &request, httplib::Response &response std::ofstream sshfileout("/etc/openrouter/ssh/status"); std::string new_ssh_status = json_body["status"]; if (new_ssh_status == "0") { - system("/etc/init.d/ssh stop"); - system("rm-rc.d 75ssh"); + system("rc stop ssh"); + system("rc del ssh"); syslog(LOG_INFO, "SSH is disabled"); } else { - system("/etc/init.d/ssh start"); - system("add-rc.d ssh 75"); + system("rc start ssh"); + system("rc add ssh"); syslog(LOG_INFO, "SSH is enabled"); } sshfileout << stoi(new_ssh_status); diff --git a/openrouter/src/settings/telnet/enabled.cpp b/openrouter/src/settings/telnet/enabled.cpp index 73d7f0e..6e727fd 100644 --- a/openrouter/src/settings/telnet/enabled.cpp +++ b/openrouter/src/settings/telnet/enabled.cpp @@ -81,12 +81,12 @@ void set_telnet(const httplib::Request &request, httplib::Response &response) { std::ofstream telnetfileout("/etc/openrouter/telnet/enabled"); std::string new_telnet_enabled = json_body["enabled"]; if (new_telnet_enabled == "0") { - system("/etc/init.d/telnet stop"); - system("rm-rc.d 70telnet"); + system("rc stop telnet"); + system("rc del telnet"); syslog(LOG_INFO, "Telnet is disabled"); } else { - system("/etc/init.d/telnet start"); - system("add-rc.d telnet 70"); + system("rc start telnet"); + system("rc add telnet"); syslog(LOG_INFO, "Telnet is enabled"); } telnetfileout << stoi(new_telnet_enabled); diff --git a/openrouter/src/settings/telnet/port.cpp b/openrouter/src/settings/telnet/port.cpp index 86411d1..80a0605 100644 --- a/openrouter/src/settings/telnet/port.cpp +++ b/openrouter/src/settings/telnet/port.cpp @@ -82,7 +82,7 @@ void set_telnet_port(const httplib::Request &request, httplib::Response &respons std::string new_telnet_port = json_body["port"]; telnetportfileout << stoi(new_telnet_port); telnetportfileout.close(); - system("/etc/init.d/telnet restart"); + system("rc restart telnet"); std::string syslogstring = "Telnet port changed to " + new_telnet_port; syslog(LOG_INFO, syslogstring.c_str()); std::ifstream telnetportfile("/etc/openrouter/telnet/port"); diff --git a/rootfs/etc/dnsmasq.conf b/rootfs/etc/dnsmasq.conf index 5bc99ac..8e035b2 100644 --- a/rootfs/etc/dnsmasq.conf +++ b/rootfs/etc/dnsmasq.conf @@ -1,5 +1,5 @@ interface=eth1 -dhcp-range=interface:eth0,192.168.100.2,192.168.100.100,12h +dhcp-range=interface:eth1,192.168.100.2,192.168.100.100,12h dhcp-range=interface:wlan0,192.168.101.2,192.168.101.100,12h resolv-file=/etc/dnsmasq.conf.d/resolv.conf addn-hosts=/etc/dnsmasq.conf.d/hosts diff --git a/rootfs/etc/group b/rootfs/etc/group index 3a78d7e..03741b8 100644 --- a/rootfs/etc/group +++ b/rootfs/etc/group @@ -1,3 +1,4 @@ root:x:0:root dnsmasq:x:963: sshd:x:33:sshd +nobody:x:65534: diff --git a/rootfs/etc/group- b/rootfs/etc/group- index daccfcc..0cda185 100644 --- a/rootfs/etc/group- +++ b/rootfs/etc/group- @@ -1,3 +1,4 @@ root:x:0:root dnsmasq:x:963: sshd:x:33: +nobody:x:65534:65534:Kernel Overflow User:/:/usr/bin/nologin diff --git a/rootfs/etc/hosts b/rootfs/etc/hosts index 062c92c..07fcdab 100644 --- a/rootfs/etc/hosts +++ b/rootfs/etc/hosts @@ -1,3 +1,3 @@ 127.0.0.1 localhost ::1 localhost -127.0.1.1 Simple.localdomain +127.0.1.1 Simple.localdomain Simple diff --git a/rootfs/etc/init.d/dnsd b/rootfs/etc/init.d/dnsd index 9e1286e..06a1629 100755 --- a/rootfs/etc/init.d/dnsd +++ b/rootfs/etc/init.d/dnsd @@ -3,29 +3,21 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting dnsd " + notify "Starting dnsd " # sleep 10 /usr/bin/dnsd -d -c /etc/dnsd.conf echo "nameserver 0.0.0.0" > /etc/resolv.conf - if [[ "$?" == "0" ]]; then - echo "nameserver 0.0.0.0" > /etc/resolv.conf - echo $(pgrep dnsd) > /var/run/dnsd.pid - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "Stopping dnsd " + notify "Stopping dnsd " kill $(cat /var/run/dnsd.pid) &> /dev/null rm /var/run/dnsd.pid - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/dnsmasq b/rootfs/etc/init.d/dnsmasq index d26a3f4..e4da823 100755 --- a/rootfs/etc/init.d/dnsmasq +++ b/rootfs/etc/init.d/dnsmasq @@ -3,31 +3,24 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting dnsmasq " + notify "Starting dnsmasq " sleep 1 /usr/bin/dnsmasq --user=dnsmasq --pid-file=/var/run/dnsmasq.pid echo "nameserver 0.0.0.0" > /etc/resolv.conf - if [[ "$?" == "0" ]]; then - echo "nameserver 0.0.0.0" > /etc/resolv.conf - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "\nStopping dnsmasq " + notify "\nStopping dnsmasq " if [ -f /var/run/dnsmasq.pid ]; then kill $(cat /var/run/dnsmasq.pid) &> /dev/null - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? rm /var/run/dnsmasq &> /dev/null else - printf "[$Red Dnsmasq is not running $Color_off]\n" + notify "[$Red Dnsmasq is not running $Color_off]\n" fi ;; restart|reload) diff --git a/rootfs/etc/init.d/ftp b/rootfs/etc/init.d/ftp index f83a3be..008845c 100755 --- a/rootfs/etc/init.d/ftp +++ b/rootfs/etc/init.d/ftp @@ -3,27 +3,21 @@ Green='\033[0;32m' Color_Off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting fptd " + notify "Starting fptd " tcpsvd -vE 0.0.0.0 21 ftpd -w -S -A $(cat /etc/openrouter/ftppath) &>/dev/null & echo $! > /var/run/ftpd.pid - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Cpolor_Off]\n" - fi + check $? ;; stop) - printf "Stopping ftpd " + notify "Stopping ftpd " kill $(cat /var/run/ftpd.pid) killall ftpd rm /var/run/ftpd.pid - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Color_Off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/hostname b/rootfs/etc/init.d/hostname index 6c7375b..bd271b4 100755 --- a/rootfs/etc/init.d/hostname +++ b/rootfs/etc/init.d/hostname @@ -4,15 +4,13 @@ Green='\033[0;32m' Color_Off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Setting up hostname " + notify "Setting up hostname " /bin/hostname -F /etc/hostname - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Color_Off]\n" - fi + check $? ;; stop) ;; diff --git a/rootfs/etc/init.d/http_d b/rootfs/etc/init.d/http_d index dbc7534..c4093aa 100755 --- a/rootfs/etc/init.d/http_d +++ b/rootfs/etc/init.d/http_d @@ -3,26 +3,20 @@ Green='\033[0;32m' Color_Off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting httpd " + notify "Starting httpd " httpd -h /srv/www &> /dev/null - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Cpolor_Off]\n" - fi + check $? ;; stop) - printf "Stopping httpd " + notify "Stopping httpd " killall httpd #kill $(cat /var/run/httpd.pid) #rm /var/run/httpd.pid - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Color_Off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/init-functions b/rootfs/etc/init.d/init-functions index 67b0d5d..37889e8 100755 --- a/rootfs/etc/init.d/init-functions +++ b/rootfs/etc/init.d/init-functions @@ -1,4 +1,7 @@ #!/bin/sh +Green='\033[0;32m' +Color_Off='\033[0m' +Red='\033[0;31m' init () { test -f $DAEMON || exit 0 @@ -58,3 +61,15 @@ sleep 1 return 1 } + +check() { + if [[ "$1" == "0" ]];then + printf "[$Green OK $Color_Off]\n" + else + printf "[$Red ERR $Cpolor_Off]\n" + fi +} + +notify() { + printf "$*" +} diff --git a/rootfs/etc/init.d/iptables b/rootfs/etc/init.d/iptables index dd47884..3c73ef3 100755 --- a/rootfs/etc/init.d/iptables +++ b/rootfs/etc/init.d/iptables @@ -8,27 +8,21 @@ DAEMON="iptables" IPTABLES_ARGS="" +. /etc/init.d/init-functions + start() { - printf 'Starting %s: ' "$DAEMON" + notify "Starting $DAEMON" iptables-restore /etc/iptables.conf status=$? - if [ "$status" -eq 0 ]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? return "$status" } stop() { - printf 'Stopping %s: ' "$DAEMON" + notify "Stopping $DAEMON" iptables -F status=$? - if [ "$status" -eq 0 ]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? return "$status" } @@ -39,11 +33,11 @@ restart() { } save() { - printf 'Saving %s: ' "$DAEMON" + notify 'Saving %s: ' "$DAEMON" iptables-save -f /etc/iptables.conf status=$? if [ "$status" -eq 0 ]; then - printf "[$Green OK $Color_off]\n" + notify "[$Green OK $Color_off]\n" else echo "SKIP (read-only file system detected)" fi diff --git a/rootfs/etc/init.d/klogd b/rootfs/etc/init.d/klogd index 03b67b5..72f980f 100755 --- a/rootfs/etc/init.d/klogd +++ b/rootfs/etc/init.d/klogd @@ -3,28 +3,22 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting klogd " + notify "Starting klogd " klogd - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "Stopping klogd " + notify "Stopping klogd " if [ -f /var/run/klogd.pid ]; then kill $(cat /var/run/klogd.pid) - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? rm /var/run/klogd.pid &> /dev/null else - printf "[$Red Klogd is not running $Color_off]\n" + notify "[$Red Klogd is not running $Color_off]\n" fi ;; restart|reload) diff --git a/rootfs/etc/init.d/networking b/rootfs/etc/init.d/networking index 72b3f44..9721b73 100755 --- a/rootfs/etc/init.d/networking +++ b/rootfs/etc/init.d/networking @@ -3,26 +3,20 @@ Green='\033[0;32m' Color_Off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting networking " + notify "Starting networking " /usr/bin/ifup -a &>/dev/null & echo $! > /var/run/networking.pid - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Cpolor_Off]\n" - fi + check $? ;; stop) - printf "Stopping networking " + notify "Stopping networking " /usr/bin/ifdown -a rm /var/run/networking.pid - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Color_Off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/nginx b/rootfs/etc/init.d/nginx index 12b0f43..6cae7bc 100755 --- a/rootfs/etc/init.d/nginx +++ b/rootfs/etc/init.d/nginx @@ -3,24 +3,18 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting nginx " + notify "Starting nginx " nginx - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "Stopping nginx " + notify "Stopping nginx " nginx -s stop - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/openrouterinit b/rootfs/etc/init.d/openrouterinit index 7119359..00bee7a 100755 --- a/rootfs/etc/init.d/openrouterinit +++ b/rootfs/etc/init.d/openrouterinit @@ -3,26 +3,20 @@ Green='\033[0;32m' Color_Off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting openrouter software " + notify "Starting openrouter software " cd /srv/ftpd/auth_service_router/bin && ./auth_service &> /dev/null & cd /srv/ftpd/openrouter_adminpanel/bin && ./openrouter &> /dev/null & - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Cpolor_Off]\n" - fi + check $? ;; stop) - printf "Stopping openrouter software " + notify "Stopping openrouter software " killall openrouter killall auth_service - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Color_Off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/ssh b/rootfs/etc/init.d/ssh index 0748851..679e588 100755 --- a/rootfs/etc/init.d/ssh +++ b/rootfs/etc/init.d/ssh @@ -3,24 +3,18 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting sshd " + notify "Starting sshd " /usr/bin/sshd -D & - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "Stopping sshd " + notify "Stopping sshd " killall sshd - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/swap b/rootfs/etc/init.d/swap index 2718e63..261e924 100755 --- a/rootfs/etc/init.d/swap +++ b/rootfs/etc/init.d/swap @@ -3,24 +3,18 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Configuring swap " + notify "Configuring swap " swapon -a - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "Stopping use swap " + notify "Stopping use swap " swapoff -a - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/init.d/sysctl b/rootfs/etc/init.d/sysctl index d2ca561..7553d05 100755 --- a/rootfs/etc/init.d/sysctl +++ b/rootfs/etc/init.d/sysctl @@ -4,15 +4,13 @@ Green='\033[0;32m' Color_Off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Setting up sysctl " + notify "Setting up sysctl " sysctl -p &> /dev/null - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_Off]\n" - else - printf "[$Red ERR $Color_Off]\n" - fi + check $? ;; stop) ;; diff --git a/rootfs/etc/init.d/syslogd b/rootfs/etc/init.d/syslogd index a17c5c7..e036d84 100755 --- a/rootfs/etc/init.d/syslogd +++ b/rootfs/etc/init.d/syslogd @@ -3,28 +3,22 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting syslogd " + notify "Starting syslogd " syslogd - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "Stopping syslogd " + notify "Stopping syslogd " if [ -f /var/run/syslogd.pid ]; then kill $(cat /var/run/syslogd.pid) - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? rm /var/run/syslogd.pid &> /dev/null else - printf "[$Red Syslogd is not running $Color_off]\n" + notify "[$Red Syslogd is not running $Color_off]\n" fi ;; restart|reload) diff --git a/rootfs/etc/init.d/telnet b/rootfs/etc/init.d/telnet index 3fa807e..95456ad 100755 --- a/rootfs/etc/init.d/telnet +++ b/rootfs/etc/init.d/telnet @@ -3,24 +3,18 @@ Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' +. /etc/init.d/init-functions + case "$1" in start) - printf "Starting telnet " + notify "Starting telnet " telnetd -p $(cat /etc/openrouter/telnet/port) - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; stop) - printf "Stopping telnet " + notify "Stopping telnet " killall telnetd - if [[ "$?" == "0" ]]; then - printf "[$Green OK $Color_off]\n" - else - printf "[$Red ERR $Color_off]\n" - fi + check $? ;; restart|reload) "$0" stop diff --git a/rootfs/etc/issue b/rootfs/etc/issue index 5420779..209cfd0 100644 --- a/rootfs/etc/issue +++ b/rootfs/etc/issue @@ -1 +1,11 @@ -Simple \r (\l) +\h \r (\l) +########## ## #### #### ########## ## ########## +########## ## #### #### ########## ## ########## +## ## ## ## ## ## ## ## ## +## ## ## ## ## ## ## ## ## ## +########## ## ## ## ## ########## ## ########## +########## ## ## ## ## ########## ## ########## + ## ## ## ## ## ## ## + ## ## ## ## ## ## ## +########## ## ## ## ## ########## ########## +########## ## ## ## ## ########## ########## diff --git a/rootfs/etc/passwd b/rootfs/etc/passwd index e3c2c84..d52076a 100644 --- a/rootfs/etc/passwd +++ b/rootfs/etc/passwd @@ -1,3 +1,4 @@ root:x:0:0:root:/root:/bin/sh dnsmasq:x:963:963:dnsmasq daemon:/:/usr/bin/nologin sshd:x:33:33:SSH daemon:/var/lib/sshd:/bin/sh +nobody:x:65534:65534:Kernel Overflow User:/:/usr/bin/nologin diff --git a/rootfs/etc/pm/repo b/rootfs/etc/pm/repo new file mode 100644 index 0000000..1a4f002 --- /dev/null +++ b/rootfs/etc/pm/repo @@ -0,0 +1 @@ +http://localhost/ diff --git a/rootfs/etc/shadow b/rootfs/etc/shadow index 8268705..0e17c93 100644 --- a/rootfs/etc/shadow +++ b/rootfs/etc/shadow @@ -1,3 +1,4 @@ root:F.fHA5x2Q.xNY:19797:::::: dnsmasq:!*:19889:::::: sshd:!:19906:0:99999:7::: +nobody:!*:19889:::::: diff --git a/rootfs/usr/bin/add-rc.d b/rootfs/usr/bin/add-rc.d deleted file mode 100755 index de02caf..0000000 --- a/rootfs/usr/bin/add-rc.d +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -if [ -f /etc/init.d/$1 ] && [ "$2" -gt 0 ]; then - cd /etc/rc.d - ln -sv ../init.d/$1 "$2$1" - echo "added $1 to init." -else - echo " - ** add-rc.d usage: - add-rc.d [init.d script name] [order number] - - examples: - add-rc.d httpd 40 - add-rc.d ftpd 40 - add-rc.d telnetd 50 - " -fi diff --git a/rootfs/usr/bin/pm b/rootfs/usr/bin/pm new file mode 100755 index 0000000..4da6c01 --- /dev/null +++ b/rootfs/usr/bin/pm @@ -0,0 +1,284 @@ +#!/bin/sh + +########## #### #### +########## #### #### +## ## ## ## ## ## +## ## ## ## ## ## +########## ## ## ## - PACKAGE MANAGER FOR SIMPLE LINUX +########## ## ## ## - AUTHOR -- TOLA MIRONCENKO +## ## ## +## ## ## +## ## ## +## ## ## + +#----- colors ------- +Green='\033[0;32m' +Color_off='\033[0m' +Red='\033[0;31m' +Bred='\033[1;31m' +Yellow='\033[1;33m' +White='\033[0;37m' +Bwhite='\033[1;37m' +#-------------------- + +#---------------- variables -------------------------- +rootdir=/ +repofile=$rootdir/etc/pm/repo +packagesqueryfile=$rootdir/usr/share/pm/query +reposquerydir=$rootdir/usr/share/pm/repos +cachedpkgdir=$rootdir/var/cache/pm/pkg +installedpackagesdir=$rootdir/usr/share/pm/packages +#----------------------------------------------------- + +#---------------- check root priveleges function ------------------------ +checkroot() { + if [[ $(id -u) != 0 ]]; then + printf "$Yellow**$Bred error:$Color_off you must be root\n" + exit 1 + fi +} + +checkroot +#------------------------------------------------------------------------ + +#----------------- add(install) package function ------------------------ +add() { + if [[ ! $1 ]]; then + help + exit 0 + fi + for i in $*; do + if [[ "$i" == "add" ]]; then + continue + fi + + done + for i in $*; do + if [[ "$i" == "add" ]]; then + continue + fi + down $i + done + for i in $*; do + if [[ "$i" == "add" ]]; then + continue + fi + unpack $cachedpkgdir/$i.pkg.gz + done +} +#------------------------------------------------------------------------ + +#-------------------- download package without install function --------- +down() { + if [[ ! $1 ]]; then + help + exit 0 + fi + servers=$(cat $repofile) + for i in $servers; do + serverdir=$(echo $i | sed -e "/http:\/\//s///") + repoquery=$(cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///') + for j in $repoquery; do + if [[ $j == $1 ]]; then + if [ ! -f $cachedpkgdir/$1.pkg.gz ]; then + printf "$Yellow**$Color_off Downloading $Yellow$serverdir: $Bwhite$j\n$Color_off" + wget $i/$1.pkg.gz -P $cachedpkgdir + if [[ "$?" == "0" ]]; then + printf "$Yellow**$Green successful downloaded $1\n$Color_off" + return + else + printf "$Yellow**$Red error:$Color_off can't download package\n" + exit 1 + fi + else + printf "$Yellow**$Green successful downloaded $1\n$Color_off" + return + fi + # exit 0 + fi + done + done + printf "$Yellow**$Red error:$Color_off can't find package $1\n" + exit 1 +} +#------------------------------------------------------------------------ + +#-------------------- unpack local package archive ---------------------- +unpack() { + packagename=$(echo $1 | sed -e "/.gz/s///") + packagename=${packagename#*pkg/} + printf "$Yellow**$Green Installing ${packagename%.pkg*}\n$Color_off" + if [[ "$(cat $packagesqueryfile | grep ${packagename%.pkg*})" != "" ]]; then + printf "$Yellow**$Color_off Package already installed:$Yellow reinstalling\n" + fi + tar -xvf $1 -C $rootdir/tmp &> /dev/null + cd $rootdir/tmp/$packagename + mkdir $installedpackagesdir/$packagename &> /dev/null + mv -v list $installedpackagesdir/$packagename &> /dev/null + cp -rv ./* $rootdir &> /dev/null + if [[ "$(cat $packagesqueryfile | grep ${packagename%.pkg*})" == "" ]]; then + echo ${packagename%.pkg*} >> $packagesqueryfile + fi + rm -rv $rootdir/tmp/$packagename &> /dev/null + printf "$Yellow**$Green Installed ${packagename%.pkg*} successful\n$Color_off" +} +#------------------------------------------------------------------------ + +#------------------ delete package function ----------------------------- +del() { + printf "$Yellow**$Green deleting\n$Color_off" + for i in $*; do + if [[ "$i" == "del" ]]; then + continue + fi + printf "$Yellow**$Green deleting $i\n$Color_off" + if [ ! -f $installedpackagesdir/$i.pkg/list ]; then + printf "$Yellow**$Bred error:$Color_off package not installed\n" + exit 0 + fi + rm -v $rootdir/$(cat $installedpackagesdir/$i.pkg/list) &> /dev/null + rm -rv $installedpackagesdir/$i.pkg &> /dev/null + sed -i "/$i/d" $packagesqueryfile + printf "$Yellow**$Green delete $i successful\n$Color_off" + done +} +#------------------------------------------------------------------------ + +#------------------- list files in package function --------------------- +list() { + if [[ "$1" == "" ]]; then + help + exit 0 + fi + if [[ "$(cat $packagesqueryfile | grep $1)" == "" ]]; then + printf "$Yellow**$Bred error:$Color_off package is not installed\n" + exit 1 + fi + filelist=$(cat $installedpackagesdir/$1.pkg/list) + for i in $filelist; do + printf "$Yellow$1: $Bwhite$i$Color_off\n" + done +} +#------------------------------------------------------------------------ + +#------------------- show installed packages function ------------------- +query() { + packagesquery=$(cat $packagesqueryfile) + if [[ "$packagesquery" == "" ]]; then + printf "$Yellow**$Bwhite No installed packages\n" + exit 0 + fi + printf "$Bwhite$packagesquery$Color_off\n" +} +#------------------------------------------------------------------------ + +#--------------------- show help function ------------------------------- +help() { + printf " + $Yellow**$Green pm usage$Color_off : + $Bwhite pm add [package name] - download and install from repository + pm unpack [/path/to/package/archive] - unpack(install) from local package archive + pm down [package name] - download package from repository without install + pm del [package name] - delete package + pm list [package name] - list files in package + pm search [package name] - search package in repository + pm query - show installed packages + pm help - this help message + pm clear - clear all package archives from cached packages directory + pm sync - synchronize repository + + $Yellow**$Green examples$Color_off : + $Bwhite pm add dnsmasq + pm unpack ./dnsmasq.pkg.gz + pm down dnsmasq + pm search dnsmasq + pm help + pm clear + pm sync + pm del dnsmasq + pm list dnsmasq + pm query + \n$Color_off" +} +#------------------------------------------------------------------------ + +#------------------- sync repo function --------------------------------- +sync() { + servers=$(cat $repofile) + for i in $servers; do + serverdir=$(echo $i | sed -e "/http:\//s///") + mkdir $reposquerydir/$serverdir &> /dev/null + wget $i/query -O $reposquerydir/$serverdir/query &> /dev/null + done +} +#------------------------------------------------------------------------ + +#----------------- search package in repo function ---------------------- +search() { + servers=$(cat $repofile) + if [[ ! $1 ]]; then + for i in $servers; do + serverdir=$(echo $i | sed -e "/http:\/\//s///") + repoquery=$(cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///') + for j in $repoquery; do + printf "$Yellow$serverdir: $Bwhite$j\n$Color_off" + done + done + exit 0 + fi + + for i in $servers; do + serverdir=$(echo $i | sed -e "/http:\/\//s///") + repoquery=$(cat $reposquerydir/$serverdir/query | sed -e '/.pkg.gz/s///') + for j in $repoquery; do + if [[ $j == $1 ]]; then + printf "$Yellow$serverdir: $Bwhite$j\n$Color_off" + exit 0 + fi + done + done + printf "$Yellow**$Red error:$Color_off can't find package ($1)\n" +} +#------------------------------------------------------------------------ + +#------------------- clear cached packages directory -------------------- +clear() { + rm -v $cachedpkgdir/* +} +#------------------------------------------------------------------------ + +case "$1" in + add) + add $* + ;; + down) + down $2 + ;; + unpack) + unpack $2 + ;; + del) + del $* + ;; + list) + list $2 + ;; + query) + query + ;; + help) + help + ;; + sync) + sync + ;; + search) + search $2 + ;; + clear) + clear + ;; + *) + help + ;; +esac diff --git a/rootfs/usr/bin/rc b/rootfs/usr/bin/rc new file mode 100755 index 0000000..b04996c --- /dev/null +++ b/rootfs/usr/bin/rc @@ -0,0 +1,124 @@ +#!/bin/sh + +########## ########## +########## ########## +## ## ## +## ## +## ## - RC BOOT SCRIPTS MANAGER FOR SIMPLE LINUX +## ## - AUTHOR -- TOLA MIRONCENKO +## ## +## ## +## ########## +## ########## + +#------------------------ add to boot function -------------- +add() { + resultlink=$(cat /usr/share/rc/ordernumbers | grep $1) + if [ -f /etc/init.d/$1 ] && [ $resultlink ]; then + cd /etc/rc.d + ln -sv ../init.d/$1 "$resultlink" &> /dev/null + echo "added $1 to init." + else + help + fi +} +#------------------------------------------------------------ + +#--------------------- del from boot function --------------- +del() { + filetoremove=$(find /etc/rc.d/ | grep $1 ) + if [ $filetoremove ]; then + rm -v $filetoremove &> /dev/null + echo "removed $1 from init." + else + help + fi +} +#------------------------------------------------------------ + +#---------------------- start daemon function --------------- +start() { + if [ -f /etc/init.d/$1 ]; then + /etc/init.d/$1 start + else + help + fi +} +#------------------------------------------------------------ + +#---------------- stop daemon function ---------------------- +stop() { + if [ -f /etc/init.d/$1 ]; then + /etc/init.d/$1 stop + else + help + fi +} +#------------------------------------------------------------ + +#------------- restart daemon function ---------------------- +restart() { + if [ -f /etc/init.d/$1 ]; then + /etc/init.d/$1 restart + else + help + fi +} +#------------------------------------------------------------ + +#-------------- print help function ------------------------- +help() { + echo " + ** rc usage: + rc add [init.d script name] + rc del [init.d script name] + rc start [init.d script name] + rc stop [init.d script name] + rc restart [init.d script name] + + examples: + rc add httpd + rc add ftpd + rc add telnetd + + rc del httpd + rc del ftpd + rc del telnetd + + rc start httpd + rc start ftpd + rc start telnetd + + rc stop httpd + rc stop ftpd + rc stop telnetd + + rc restart httpd + rc restart ftpd + rc restart telnetd + " +} +#------------------------------------------------------------ + +command="$1" + +case ${command} in + add) + add $2 $3 + ;; + del) + del $2 + ;; + start) + start $2 + ;; + stop) + stop $2 + ;; + restart) + restart $2 + ;; + *) + help + ;; +esac diff --git a/rootfs/usr/bin/rm-rc.d b/rootfs/usr/bin/rm-rc.d deleted file mode 100755 index adeb53d..0000000 --- a/rootfs/usr/bin/rm-rc.d +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -if [ -f /etc/rc.d/$1 ]; then - rm -v /etc/rc.d/$1 - echo "removed $1 from init." -else - echo " - ** rm-rc.d usage: - rm-rc.d [rc.d link name] - - examples: - rm-rc.d 40httpd - rm-rc.d 40ftpd - rm-rc.d 50telnetd - " -fi diff --git a/rootfs/usr/share/pm/query b/rootfs/usr/share/pm/query new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/usr/share/pm/repos/localhost/query b/rootfs/usr/share/pm/repos/localhost/query new file mode 100644 index 0000000..d5b52db --- /dev/null +++ b/rootfs/usr/share/pm/repos/localhost/query @@ -0,0 +1,2 @@ +fet.sh.pkg.gz +pfetch.pkg.gz diff --git a/rootfs/usr/share/rc/ordernumbers b/rootfs/usr/share/rc/ordernumbers new file mode 100644 index 0000000..be7ddbb --- /dev/null +++ b/rootfs/usr/share/rc/ordernumbers @@ -0,0 +1,14 @@ +15hostname +20klogd +30syslogd +40swap +50networking +55sysctl +60dnsmasq +65dnsd +70telnet +75ssh +80iptables +85openrouterinit +90ftp +95nginx \ No newline at end of file