Add VTOY_SHOW_PASSWORD_ASTERISK option in global control plugon. (#1931)

This commit is contained in:
longpanda 2022-10-26 15:27:51 +08:00
parent c2336f555a
commit 7d90912a09
5 changed files with 91 additions and 18 deletions

View File

@ -2212,6 +2212,21 @@ ventoy_password_get (char buf[], unsigned buf_size)
return (key != GRUB_TERM_ESC); return (key != GRUB_TERM_ESC);
} }
static int ventoy_get_password(char buf[], unsigned buf_size)
{
const char *env = NULL;
env = grub_env_get("VTOY_SHOW_PASSWORD_ASTERISK");
if (env && env[0] == '0' && env[1] == 0)
{
return grub_password_get(buf, buf_size);
}
else
{
return ventoy_password_get(buf, buf_size);
}
}
int ventoy_check_password(const vtoy_password *pwd, int retry) int ventoy_check_password(const vtoy_password *pwd, int retry)
{ {
int offset; int offset;
@ -2227,7 +2242,7 @@ int ventoy_check_password(const vtoy_password *pwd, int retry)
if (pwd->type == VTOY_PASSWORD_TXT) if (pwd->type == VTOY_PASSWORD_TXT)
{ {
ventoy_password_get(input, 128); ventoy_get_password(input, 128);
if (grub_strcmp(pwd->text, input) == 0) if (grub_strcmp(pwd->text, input) == 0)
{ {
return 0; return 0;
@ -2235,7 +2250,7 @@ int ventoy_check_password(const vtoy_password *pwd, int retry)
} }
else if (pwd->type == VTOY_PASSWORD_MD5) else if (pwd->type == VTOY_PASSWORD_MD5)
{ {
ventoy_password_get(input, 128); ventoy_get_password(input, 128);
grub_crypto_hash(GRUB_MD_MD5, md5, input, grub_strlen(input)); grub_crypto_hash(GRUB_MD_MD5, md5, input, grub_strlen(input));
if (grub_memcmp(pwd->md5, md5, 16) == 0) if (grub_memcmp(pwd->md5, md5, 16) == 0)
{ {
@ -2245,7 +2260,7 @@ int ventoy_check_password(const vtoy_password *pwd, int retry)
else if (pwd->type == VTOY_PASSWORD_SALT_MD5) else if (pwd->type == VTOY_PASSWORD_SALT_MD5)
{ {
offset = (int)grub_snprintf(input, 128, "%s", pwd->salt); offset = (int)grub_snprintf(input, 128, "%s", pwd->salt);
ventoy_password_get(input + offset, 128); ventoy_get_password(input + offset, 128);
grub_crypto_hash(GRUB_MD_MD5, md5, input, grub_strlen(input)); grub_crypto_hash(GRUB_MD_MD5, md5, input, grub_strlen(input));
if (grub_memcmp(pwd->md5, md5, 16) == 0) if (grub_memcmp(pwd->md5, md5, 16) == 0)

View File

@ -513,6 +513,7 @@ void ventoy_data_default_control(data_control *data)
{ {
memset(data, 0, sizeof(data_control)); memset(data, 0, sizeof(data_control));
data->password_asterisk = 1;
data->secondary_menu = 1; data->secondary_menu = 1;
data->filter_dot_underscore = 1; data->filter_dot_underscore = 1;
data->max_search_level = -1; data->max_search_level = -1;
@ -539,6 +540,7 @@ int ventoy_data_cmp_control(data_control *data1, data_control *data2)
data1->filter_vtoy != data2->filter_vtoy || data1->filter_vtoy != data2->filter_vtoy ||
data1->win11_bypass_check != data2->win11_bypass_check || data1->win11_bypass_check != data2->win11_bypass_check ||
data1->linux_remount != data2->linux_remount || data1->linux_remount != data2->linux_remount ||
data1->password_asterisk != data2->password_asterisk ||
data1->secondary_menu != data2->secondary_menu || data1->secondary_menu != data2->secondary_menu ||
data1->menu_timeout != data2->menu_timeout || data1->menu_timeout != data2->menu_timeout ||
data1->secondary_menu_timeout != data2->secondary_menu_timeout) data1->secondary_menu_timeout != data2->secondary_menu_timeout)
@ -587,6 +589,7 @@ int ventoy_data_save_control(data_control *data, const char *title, char *buf, i
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_WIN11_BYPASS_CHECK", win11_bypass_check); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_WIN11_BYPASS_CHECK", win11_bypass_check);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_LINUX_REMOUNT", linux_remount); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_LINUX_REMOUNT", linux_remount);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_SECONDARY_BOOT_MENU", secondary_menu); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_SECONDARY_BOOT_MENU", secondary_menu);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_SHOW_PASSWORD_ASTERISK", password_asterisk);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_MENU_TIMEOUT", menu_timeout); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_MENU_TIMEOUT", menu_timeout);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_SECONDARY_TIMEOUT", secondary_menu_timeout); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_SECONDARY_TIMEOUT", secondary_menu_timeout);
@ -634,6 +637,7 @@ int ventoy_data_json_control(data_control *ctrl, char *buf, int buflen)
VTOY_JSON_FMT_SINT("win11_bypass_check", ctrl->win11_bypass_check); VTOY_JSON_FMT_SINT("win11_bypass_check", ctrl->win11_bypass_check);
VTOY_JSON_FMT_SINT("linux_remount", ctrl->linux_remount); VTOY_JSON_FMT_SINT("linux_remount", ctrl->linux_remount);
VTOY_JSON_FMT_SINT("secondary_menu", ctrl->secondary_menu); VTOY_JSON_FMT_SINT("secondary_menu", ctrl->secondary_menu);
VTOY_JSON_FMT_SINT("password_asterisk", ctrl->password_asterisk);
VTOY_JSON_FMT_SINT("menu_timeout", ctrl->menu_timeout); VTOY_JSON_FMT_SINT("menu_timeout", ctrl->menu_timeout);
VTOY_JSON_FMT_SINT("secondary_menu_timeout", ctrl->secondary_menu_timeout); VTOY_JSON_FMT_SINT("secondary_menu_timeout", ctrl->secondary_menu_timeout);
VTOY_JSON_FMT_STRN("default_kbd_layout", ctrl->default_kbd_layout); VTOY_JSON_FMT_STRN("default_kbd_layout", ctrl->default_kbd_layout);
@ -702,6 +706,7 @@ static int ventoy_api_save_control(struct mg_connection *conn, VTOY_JSON *json)
VTOY_JSON_INT("win11_bypass_check", ctrl->win11_bypass_check); VTOY_JSON_INT("win11_bypass_check", ctrl->win11_bypass_check);
VTOY_JSON_INT("linux_remount", ctrl->linux_remount); VTOY_JSON_INT("linux_remount", ctrl->linux_remount);
VTOY_JSON_INT("secondary_menu", ctrl->secondary_menu); VTOY_JSON_INT("secondary_menu", ctrl->secondary_menu);
VTOY_JSON_INT("password_asterisk", ctrl->password_asterisk);
VTOY_JSON_INT("menu_timeout", ctrl->menu_timeout); VTOY_JSON_INT("menu_timeout", ctrl->menu_timeout);
VTOY_JSON_INT("secondary_menu_timeout", ctrl->secondary_menu_timeout); VTOY_JSON_INT("secondary_menu_timeout", ctrl->secondary_menu_timeout);
@ -3981,31 +3986,35 @@ static int ventoy_parse_control(VTOY_JSON *json, void *p)
if (strcmp(child->pcName, "VTOY_DEFAULT_MENU_MODE") == 0) if (strcmp(child->pcName, "VTOY_DEFAULT_MENU_MODE") == 0)
{ {
CONTROL_PARSE_INT(child, data->default_menu_mode); CONTROL_PARSE_INT_DEF_0(child, data->default_menu_mode);
} }
else if (strcmp(child->pcName, "VTOY_WIN11_BYPASS_CHECK") == 0) else if (strcmp(child->pcName, "VTOY_WIN11_BYPASS_CHECK") == 0)
{ {
CONTROL_PARSE_INT(child, data->win11_bypass_check); CONTROL_PARSE_INT_DEF_0(child, data->win11_bypass_check);
} }
else if (strcmp(child->pcName, "VTOY_LINUX_REMOUNT") == 0) else if (strcmp(child->pcName, "VTOY_LINUX_REMOUNT") == 0)
{ {
CONTROL_PARSE_INT(child, data->linux_remount); CONTROL_PARSE_INT_DEF_0(child, data->linux_remount);
} }
else if (strcmp(child->pcName, "VTOY_SECONDARY_BOOT_MENU") == 0) else if (strcmp(child->pcName, "VTOY_SECONDARY_BOOT_MENU") == 0)
{ {
CONTROL_PARSE_INT(child, data->secondary_menu); CONTROL_PARSE_INT_DEF_1(child, data->secondary_menu);
}
else if (strcmp(child->pcName, "VTOY_SHOW_PASSWORD_ASTERISK") == 0)
{
CONTROL_PARSE_INT_DEF_1(child, data->password_asterisk);
} }
else if (strcmp(child->pcName, "VTOY_TREE_VIEW_MENU_STYLE") == 0) else if (strcmp(child->pcName, "VTOY_TREE_VIEW_MENU_STYLE") == 0)
{ {
CONTROL_PARSE_INT(child, data->treeview_style); CONTROL_PARSE_INT_DEF_0(child, data->treeview_style);
} }
else if (strcmp(child->pcName, "VTOY_FILT_DOT_UNDERSCORE_FILE") == 0) else if (strcmp(child->pcName, "VTOY_FILT_DOT_UNDERSCORE_FILE") == 0)
{ {
CONTROL_PARSE_INT(child, data->filter_dot_underscore); CONTROL_PARSE_INT_DEF_1(child, data->filter_dot_underscore);
} }
else if (strcmp(child->pcName, "VTOY_SORT_CASE_SENSITIVE") == 0) else if (strcmp(child->pcName, "VTOY_SORT_CASE_SENSITIVE") == 0)
{ {
CONTROL_PARSE_INT(child, data->sort_casesensitive); CONTROL_PARSE_INT_DEF_0(child, data->sort_casesensitive);
} }
else if (strcmp(child->pcName, "VTOY_MAX_SEARCH_LEVEL") == 0) else if (strcmp(child->pcName, "VTOY_MAX_SEARCH_LEVEL") == 0)
{ {
@ -4058,31 +4067,31 @@ static int ventoy_parse_control(VTOY_JSON *json, void *p)
} }
else if (strcmp(child->pcName, "VTOY_VHD_NO_WARNING") == 0) else if (strcmp(child->pcName, "VTOY_VHD_NO_WARNING") == 0)
{ {
CONTROL_PARSE_INT(child, data->vhd_no_warning); CONTROL_PARSE_INT_DEF_0(child, data->vhd_no_warning);
} }
else if (strcmp(child->pcName, "VTOY_FILE_FLT_ISO") == 0) else if (strcmp(child->pcName, "VTOY_FILE_FLT_ISO") == 0)
{ {
CONTROL_PARSE_INT(child, data->filter_iso); CONTROL_PARSE_INT_DEF_0(child, data->filter_iso);
} }
else if (strcmp(child->pcName, "VTOY_FILE_FLT_IMG") == 0) else if (strcmp(child->pcName, "VTOY_FILE_FLT_IMG") == 0)
{ {
CONTROL_PARSE_INT(child, data->filter_img); CONTROL_PARSE_INT_DEF_0(child, data->filter_img);
} }
else if (strcmp(child->pcName, "VTOY_FILE_FLT_EFI") == 0) else if (strcmp(child->pcName, "VTOY_FILE_FLT_EFI") == 0)
{ {
CONTROL_PARSE_INT(child, data->filter_efi); CONTROL_PARSE_INT_DEF_0(child, data->filter_efi);
} }
else if (strcmp(child->pcName, "VTOY_FILE_FLT_WIM") == 0) else if (strcmp(child->pcName, "VTOY_FILE_FLT_WIM") == 0)
{ {
CONTROL_PARSE_INT(child, data->filter_wim); CONTROL_PARSE_INT_DEF_0(child, data->filter_wim);
} }
else if (strcmp(child->pcName, "VTOY_FILE_FLT_VHD") == 0) else if (strcmp(child->pcName, "VTOY_FILE_FLT_VHD") == 0)
{ {
CONTROL_PARSE_INT(child, data->filter_vhd); CONTROL_PARSE_INT_DEF_0(child, data->filter_vhd);
} }
else if (strcmp(child->pcName, "VTOY_FILE_FLT_VTOY") == 0) else if (strcmp(child->pcName, "VTOY_FILE_FLT_VTOY") == 0)
{ {
CONTROL_PARSE_INT(child, data->filter_vtoy); CONTROL_PARSE_INT_DEF_0(child, data->filter_vtoy);
} }
} }

View File

@ -79,6 +79,7 @@ typedef struct data_control
int secondary_menu_timeout; int secondary_menu_timeout;
int linux_remount; int linux_remount;
int secondary_menu; int secondary_menu;
int password_asterisk;
char default_search_root[MAX_PATH]; char default_search_root[MAX_PATH];
char default_image[MAX_PATH]; char default_image[MAX_PATH];
char default_kbd_layout[32]; char default_kbd_layout[32];
@ -402,9 +403,11 @@ else\
} \ } \
} }
#define CONTROL_PARSE_INT(node, val) \ #define CONTROL_PARSE_INT_DEF_0(node, val) \
if (node->unData.pcStrVal[0] == '1') val = 1 if (node->unData.pcStrVal[0] == '1') val = 1
#define CONTROL_PARSE_INT_DEF_1(node, val) \
if (node->unData.pcStrVal[0] == '0') val = 0
#define VTOY_JSON_INT(key, val) vtoy_json_get_int(json, key, &val) #define VTOY_JSON_INT(key, val) vtoy_json_get_int(json, key, &val)
#define VTOY_JSON_STR(key, buf) vtoy_json_get_string(json, key, sizeof(buf), buf) #define VTOY_JSON_STR(key, buf) vtoy_json_get_string(json, key, sizeof(buf), buf)

View File

@ -435,6 +435,49 @@
</div><!-- /.box-body --> </div><!-- /.box-body -->
</div><!-- /.box --> </div><!-- /.box -->
<div class="box box-primary box-solid">
<div class="box-header with-border">
<h3 class="box-title" style="font-size: 14px;font-weight: bold;">VTOY_SHOW_PASSWORD_ASTERISK
<span id="id_span_desc_cn"> —— 输入密码时显示星号</span></h3>
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div><!-- /.box-header -->
<div class="box-body no-padding">
<table class="table table-bordered no-padding">
<tr style="font-weight:bold;">
<td class="td_ctrl_col" id="td_title_setting">选项设置</td>
<td>
<label class="radio-inline">
<input type="radio" id="id_ctrl_asterisk_radio0" name="id_ctrl_asterisk_radio" data-type="0" value="0"> <span style="font-weight:bold;">0</span>
</label>&nbsp;&nbsp;&nbsp;&nbsp;
<label class="radio-inline">
<input type="radio" id="id_ctrl_asterisk_radio1" name="id_ctrl_asterisk_radio" data-type="1" value="1"> <span style="font-weight:bold;">1</span>
</label>
</td>
</tr>
<tr id="tr_title_desc_cn">
<td class="td_ctrl_col" id="td_title_desc">选项说明</td>
<td>输入密码时是否显示星号
<code style="font-weight: bold;">0</code> 不显示 &nbsp;&nbsp;
<code style="font-weight: bold;">1</code> 显示
</td>
</tr>
<tr id="tr_title_desc_en">
<td class="td_ctrl_col" id="td_title_desc">Option Description</td>
<td>
Display asterisk when typing password
<code style="font-weight: bold;">0</code> Don't display &nbsp;&nbsp;&nbsp;
<code style="font-weight: bold;">1</code> Display
</td>
</tr>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
<div class="box box-primary box-solid"> <div class="box box-primary box-solid">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title" style="font-size: 14px;font-weight: bold;">VTOY_SECONDARY_TIMEOUT <h3 class="box-title" style="font-size: 14px;font-weight: bold;">VTOY_SECONDARY_TIMEOUT
@ -1020,6 +1063,7 @@
data.win11_bypass_check = parseInt($('input:radio[name=id_ctrl_bypass_win11_radio]:checked').val()); data.win11_bypass_check = parseInt($('input:radio[name=id_ctrl_bypass_win11_radio]:checked').val());
data.linux_remount = parseInt($('input:radio[name=id_ctrl_linux_remount_radio]:checked').val()); data.linux_remount = parseInt($('input:radio[name=id_ctrl_linux_remount_radio]:checked').val());
data.secondary_menu = parseInt($('input:radio[name=id_ctrl_secondary_radio]:checked').val()); data.secondary_menu = parseInt($('input:radio[name=id_ctrl_secondary_radio]:checked').val());
data.password_asterisk = parseInt($('input:radio[name=id_ctrl_asterisk_radio]:checked').val());
data.default_search_root = $('input:text[id=id_ctrl_text_search_root]').val(); data.default_search_root = $('input:text[id=id_ctrl_text_search_root]').val();
data.menu_timeout = parseInt($('input:text[id=id_ctrl_text_timeout]').val()); data.menu_timeout = parseInt($('input:text[id=id_ctrl_text_timeout]').val());
data.secondary_menu_timeout = parseInt($('input:text[id=id_ctrl_text_secondary_timeout]').val()); data.secondary_menu_timeout = parseInt($('input:text[id=id_ctrl_text_secondary_timeout]').val());
@ -1055,6 +1099,7 @@
$('input:radio[name=id_ctrl_bypass_win11_radio]')[data.win11_bypass_check].checked = true; $('input:radio[name=id_ctrl_bypass_win11_radio]')[data.win11_bypass_check].checked = true;
$('input:radio[name=id_ctrl_linux_remount_radio]')[data.linux_remount].checked = true; $('input:radio[name=id_ctrl_linux_remount_radio]')[data.linux_remount].checked = true;
$('input:radio[name=id_ctrl_secondary_radio]')[data.secondary_menu].checked = true; $('input:radio[name=id_ctrl_secondary_radio]')[data.secondary_menu].checked = true;
$('input:radio[name=id_ctrl_asterisk_radio]')[data.password_asterisk].checked = true;
//VTOY_DEFAULT_SEARCH_ROOT //VTOY_DEFAULT_SEARCH_ROOT
$('input:text[id=id_ctrl_text_search_root]').val(data.default_search_root); $('input:text[id=id_ctrl_text_search_root]').val(data.default_search_root);
@ -1161,6 +1206,7 @@
win11_bypass_check: data.win11_bypass_check, win11_bypass_check: data.win11_bypass_check,
linux_remount:data.linux_remount, linux_remount:data.linux_remount,
secondary_menu:data.secondary_menu, secondary_menu:data.secondary_menu,
password_asterisk:data.password_asterisk,
default_search_root: data.default_search_root, default_search_root: data.default_search_root,
menu_timeout: data.menu_timeout, menu_timeout: data.menu_timeout,
secondary_menu_timeout: data.secondary_menu_timeout, secondary_menu_timeout: data.secondary_menu_timeout,