|
|
|
@ -850,7 +850,7 @@ bool MainWindow::focus_ntp_text() {
|
|
|
|
bool flag_error = false;
|
|
|
|
bool flag_error = false;
|
|
|
|
bool flag_error_check_ntp = false;
|
|
|
|
bool flag_error_check_ntp = false;
|
|
|
|
string str_ntp = txtNtpServer->get_text();
|
|
|
|
string str_ntp = txtNtpServer->get_text();
|
|
|
|
flag_error_check_ntp = this->check_ntp(str_ntp);
|
|
|
|
flag_error_check_ntp = this->wrapper_check_ntp(str_ntp);
|
|
|
|
for (const auto &simvol: array_simvol) {
|
|
|
|
for (const auto &simvol: array_simvol) {
|
|
|
|
if (str_ntp.find(simvol) != std::string::npos) {
|
|
|
|
if (str_ntp.find(simvol) != std::string::npos) {
|
|
|
|
flag_error= true;
|
|
|
|
flag_error= true;
|
|
|
|
@ -893,7 +893,7 @@ vector<int> MainWindow::find_all(string &str_ntp, string substr) {
|
|
|
|
return sub_index;
|
|
|
|
return sub_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::check_num_ntp(string &str_ntp) {
|
|
|
|
bool MainWindow::check_is_num_ntp(string &str_ntp) {
|
|
|
|
int code_ascii = 0;
|
|
|
|
int code_ascii = 0;
|
|
|
|
bool flag_is_num = false;
|
|
|
|
bool flag_is_num = false;
|
|
|
|
for (size_t index = 0; index < str_ntp.length(); index++) {
|
|
|
|
for (size_t index = 0; index < str_ntp.length(); index++) {
|
|
|
|
@ -906,7 +906,7 @@ bool MainWindow::check_num_ntp(string &str_ntp) {
|
|
|
|
return flag_is_num;
|
|
|
|
return flag_is_num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::check_string_ntp(string &str_ntp) {
|
|
|
|
bool MainWindow::check_is_string_ntp(string &str_ntp) {
|
|
|
|
int code_ascii = 0;
|
|
|
|
int code_ascii = 0;
|
|
|
|
bool flag_is_str = false;
|
|
|
|
bool flag_is_str = false;
|
|
|
|
for (size_t index = 0; index < str_ntp.length(); index++) {
|
|
|
|
for (size_t index = 0; index < str_ntp.length(); index++) {
|
|
|
|
@ -919,21 +919,9 @@ bool MainWindow::check_string_ntp(string &str_ntp) {
|
|
|
|
return flag_is_str;
|
|
|
|
return flag_is_str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::check_ntp(string &str_ntp) {
|
|
|
|
bool MainWindow::validate_ip_address(string &str_ntp) {
|
|
|
|
bool flag_is_num = this->check_num_ntp(str_ntp);
|
|
|
|
|
|
|
|
bool flag_is_str = this->check_string_ntp(str_ntp);
|
|
|
|
|
|
|
|
vector<int> sub_index = this->find_all(str_ntp, ".");
|
|
|
|
vector<int> sub_index = this->find_all(str_ntp, ".");
|
|
|
|
if (sub_index.size() != 0 && flag_is_str) {
|
|
|
|
if (sub_index.size() == 3) {
|
|
|
|
int index_point = sub_index[sub_index.size()-1];
|
|
|
|
|
|
|
|
int len_str_ntp = str_ntp.length();
|
|
|
|
|
|
|
|
if (((len_str_ntp-index_point) >= 2) && (index_point > 2)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (sub_index.size() == 3 && (flag_is_num && flag_is_str == false)) {
|
|
|
|
|
|
|
|
int index_str_ntp = sub_index[0];
|
|
|
|
int index_str_ntp = sub_index[0];
|
|
|
|
int index_str_ntp_1 = sub_index[1];
|
|
|
|
int index_str_ntp_1 = sub_index[1];
|
|
|
|
int index_str_ntp_2 = sub_index[2];
|
|
|
|
int index_str_ntp_2 = sub_index[2];
|
|
|
|
@ -977,7 +965,60 @@ bool MainWindow::check_ntp(string &str_ntp) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::validate_domen(string &str_ntp) {
|
|
|
|
|
|
|
|
vector<int> sub_index = this->find_all(str_ntp, ".");
|
|
|
|
|
|
|
|
if (sub_index.size() != 0) {
|
|
|
|
|
|
|
|
int index_point = sub_index[sub_index.size()-1];
|
|
|
|
|
|
|
|
int len_str_ntp = str_ntp.length();
|
|
|
|
|
|
|
|
if (((len_str_ntp-index_point) >= 2) && (index_point > 2)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::check_ntp(string &str_ntp) {
|
|
|
|
|
|
|
|
bool flag_is_str = this->check_is_string_ntp(str_ntp);
|
|
|
|
|
|
|
|
bool flag_is_num = this->check_is_num_ntp(str_ntp);
|
|
|
|
|
|
|
|
if (flag_is_str) {
|
|
|
|
|
|
|
|
return this->validate_domen(str_ntp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (flag_is_str && flag_is_num == false) {
|
|
|
|
|
|
|
|
return this->validate_ip_address(str_ntp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::wrapper_check_ntp(string &str_ntp) {
|
|
|
|
|
|
|
|
bool flag_check_error_ntp = false;
|
|
|
|
|
|
|
|
if (str_ntp.find(",") != string::npos) {
|
|
|
|
|
|
|
|
vector<string> vec_ntp = split(str_ntp, ',');
|
|
|
|
|
|
|
|
for (string& str_split_ntp: vec_ntp) {
|
|
|
|
|
|
|
|
if (str_split_ntp.length() == 0) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
flag_check_error_ntp = this->check_ntp(str_split_ntp);
|
|
|
|
|
|
|
|
if (flag_check_error_ntp) {
|
|
|
|
|
|
|
|
return flag_check_error_ntp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return this->check_ntp(str_ntp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct MainWindow::Result<string> MainWindow::wrapper_call(string cmd) {
|
|
|
|
struct MainWindow::Result<string> MainWindow::wrapper_call(string cmd) {
|
|
|
|
|