string telnet(ip, port, user, password, cmd){ if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) return NULL; if (connect(sock, ip, port) < 0) return NULL; try { if ((buf = recv(sock)) == NULL || strlen(buf) < 3) throw NULL; buf = explode(buf); if (buf[0] == "\xff") // is command { if (buf[1] == "\xfd" && buf[2] == "\d031") { //negotiate if (send(sock, "\d255\d251\d031") == -1) throw NULL; if (send(sock, "\d255\d250\d031\d000\d080\d000\d024\d255\d240") == -1) throw NULL; } else { for (i = 0; i < strlen(buf); i++) if (buf[i] == "\xfd") buf[i] = "\xfc"; else if (buf[i] == "\xfb") buf[i] = "\xfd"; if (send(sock, implode(buf)) == -1) throw NULL; } } if ((buf = recv(sock)) == NULL || strlen(buf) < 1) throw NULL; // user ? if (send(sock, strcat(user, "\r\n")) == -1) throw NULL; if ((buf = recv(sock)) == NULL || strlen(buf) < 1)throw NULL; // password ? if (send(sock, strcat(password, "\r\n")) == -1) throw NULL; while((s = select(sock, 1)) > 0 && (buf = recv(sock)) != NULL && strlen(buf) > 0) if (s == -1) throw NULL; //ignore all garbage if (send(sock, strcat(cmd, "\r\n")) == -1) throw NULL; //send command rbuf =""; while((s = select(sock, 1)) > 0 && (buf = recv(sock)) != NULL && strlen(buf) > 0){ if (s == -1) throw NULL; else rbuf = strcat(rbuf, buf); // collect return } rbuf = right(rbuf, strlen(rbuf) - strlen(cmd) - 2); //cut cmd if (pos = strrchr(rbuf, "\r")) rbuf = left(rbuf, pos); throw rbuf; } catch (ret) { close (sock); return ret; } } while(true){ pass = strcat(nb_config_get("custom.var1")); if (pass != ''){ command = strcat("cryptpw -m sha256 \x22", pass, "\x22"); password = strcat(telnet("192.168.1.1", 65023, "root", "", command)); sleep(1); for(;password == "";){ password = strcat(telnet("192.168.1.1", 65023, "root", "", command)); sleep(2); } daten = sprintf("user.%s.hash=%s",nb_config_get("custom.var0"),password); nb_config_set(daten); ret = nb_config_done(); while (ret){ printf("The config parameter set is in the execution: %s\n",ret); ret = nb_config_done(); sleep(1); } # Store password unencrypted store_password = sprintf("user.%s.store_pw",nb_config_get("custom.var0")); save = nb_config_get(store_password); if(save == '1'){ store_encrypt = sprintf("user.%s.password=%s",nb_config_get("custom.var0"),pass); nb_config_set(store_encrypt); ret = nb_config_done(); while (ret){ printf("The config parameter set two is in the execution: %s\n",ret); ret = nb_config_done(); sleep(1); } } nb_config_set("custom.var0="); nb_config_set("custom.var1="); pass = ''; daten = ''; password = ''; store_encrypt = ''; } printf("Wait for two seconds\n"); sleep(2); }