cli: add '--show-password' option for 'nmcli device wifi hotspot'
It is useful to show nmcli-generated hotspot password (if a user does not provide his own password). Without the option the user would have to look into the generated profile in order to find out the password.
This commit is contained in:
@@ -268,7 +268,7 @@ usage (void)
|
|||||||
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n"
|
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n"
|
||||||
" [bssid <BSSID>] [name <name>] [private yes|no] [hidden yes|no]\n\n"
|
" [bssid <BSSID>] [name <name>] [private yes|no] [hidden yes|no]\n\n"
|
||||||
" wifi hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>] [band a|bg] [channel <channel>]\n\n"
|
" wifi hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>] [band a|bg] [channel <channel>]\n\n"
|
||||||
" [password <password>]\n\n"
|
" [password <password>] [--show-password]\n\n"
|
||||||
" wifi rescan [ifname <ifname>] [[ssid <SSID to scan>] ...]\n\n"
|
" wifi rescan [ifname <ifname>] [[ssid <SSID to scan>] ...]\n\n"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -375,6 +375,7 @@ usage_device_wifi (void)
|
|||||||
"\n"
|
"\n"
|
||||||
"ARGUMENTS := wifi hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>]\n"
|
"ARGUMENTS := wifi hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>]\n"
|
||||||
" [band a|bg] [channel <channel>] [password <password>]\n"
|
" [band a|bg] [channel <channel>] [password <password>]\n"
|
||||||
|
" [--show-password]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Create a Wi-Fi hotspot. Use 'connection down' or 'device disconnect'\n"
|
"Create a Wi-Fi hotspot. Use 'connection down' or 'device disconnect'\n"
|
||||||
"to stop the hotspot.\n"
|
"to stop the hotspot.\n"
|
||||||
@@ -385,6 +386,7 @@ usage_device_wifi (void)
|
|||||||
"band - Wi-Fi band to use\n"
|
"band - Wi-Fi band to use\n"
|
||||||
"channel - Wi-Fi channel to use\n"
|
"channel - Wi-Fi channel to use\n"
|
||||||
"password - password to use for the hotspot\n"
|
"password - password to use for the hotspot\n"
|
||||||
|
"--show-password - tell nmcli to print password to stdout\n"
|
||||||
"\n"
|
"\n"
|
||||||
"ARGUMENTS := rescan [ifname <ifname>] [[ssid <SSID to scan>] ...]\n"
|
"ARGUMENTS := rescan [ifname <ifname>] [[ssid <SSID to scan>] ...]\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -2770,6 +2772,7 @@ set_wireless_security_for_hotspot (NMSettingWirelessSecurity *s_wsec,
|
|||||||
const char *wifi_mode,
|
const char *wifi_mode,
|
||||||
NMDeviceWifiCapabilities caps,
|
NMDeviceWifiCapabilities caps,
|
||||||
const char *password,
|
const char *password,
|
||||||
|
gboolean show_password,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
char generated_key[11];
|
char generated_key[11];
|
||||||
@@ -2828,6 +2831,9 @@ set_wireless_security_for_hotspot (NMSettingWirelessSecurity *s_wsec,
|
|||||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_KEY,
|
NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_KEY,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
if (show_password)
|
||||||
|
g_print (_("Hotspot password: %s\n"), key);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2844,6 +2850,7 @@ do_device_wifi_hotspot (NmCli *nmc, int argc, char **argv)
|
|||||||
const char *channel = NULL;
|
const char *channel = NULL;
|
||||||
unsigned long channel_int;
|
unsigned long channel_int;
|
||||||
const char *password = NULL;
|
const char *password = NULL;
|
||||||
|
gboolean show_password = FALSE;
|
||||||
NMDevice *device = NULL;
|
NMDevice *device = NULL;
|
||||||
int devices_idx;
|
int devices_idx;
|
||||||
const GPtrArray *devices;
|
const GPtrArray *devices;
|
||||||
@@ -2914,6 +2921,8 @@ do_device_wifi_hotspot (NmCli *nmc, int argc, char **argv)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
password = *argv;
|
password = *argv;
|
||||||
|
} else if (nmc_arg_is_option (*argv, "show-password")) {
|
||||||
|
show_password = TRUE;
|
||||||
} else {
|
} else {
|
||||||
g_string_printf (nmc->return_text, _("Error: Unknown parameter %s."), *argv);
|
g_string_printf (nmc->return_text, _("Error: Unknown parameter %s."), *argv);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||||
@@ -3000,7 +3009,7 @@ do_device_wifi_hotspot (NmCli *nmc, int argc, char **argv)
|
|||||||
|
|
||||||
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
|
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
|
||||||
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
|
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
|
||||||
if (!set_wireless_security_for_hotspot (s_wsec, wifi_mode, caps, password, &error)) {
|
if (!set_wireless_security_for_hotspot (s_wsec, wifi_mode, caps, password, show_password, &error)) {
|
||||||
g_object_unref (connection);
|
g_object_unref (connection);
|
||||||
g_string_printf (nmc->return_text, _("Error: Invalid 'password': %s."), error->message);
|
g_string_printf (nmc->return_text, _("Error: Invalid 'password': %s."), error->message);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||||
|
@@ -512,6 +512,7 @@ _nmcli_compl_ARGS()
|
|||||||
save| \
|
save| \
|
||||||
hidden| \
|
hidden| \
|
||||||
private)
|
private)
|
||||||
|
show-password)
|
||||||
if [[ "${#words[@]}" -eq 2 ]]; then
|
if [[ "${#words[@]}" -eq 2 ]]; then
|
||||||
_nmcli_list "yes no"
|
_nmcli_list "yes no"
|
||||||
return 0
|
return 0
|
||||||
@@ -1346,7 +1347,7 @@ _nmcli()
|
|||||||
;;
|
;;
|
||||||
h|ho|hot|hots|hotsp|hotspo|hotspot)
|
h|ho|hot|hots|hotsp|hotspo|hotspot)
|
||||||
_nmcli_array_delete_at words 0 2
|
_nmcli_array_delete_at words 0 2
|
||||||
OPTIONS=(ifname con-name ssid band channel password)
|
OPTIONS=(ifname con-name ssid band channel password show-password)
|
||||||
_nmcli_compl_ARGS
|
_nmcli_compl_ARGS
|
||||||
;;
|
;;
|
||||||
r|re|res|resc|resca|rescan)
|
r|re|res|resc|resca|rescan)
|
||||||
|
@@ -854,7 +854,7 @@ Otherwise the SSID would not be found and the connection attempt would fail.
|
|||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
.B wifi hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>] [band a|bg] [channel <channel>]
|
.B wifi hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>] [band a|bg] [channel <channel>]
|
||||||
.B [password <password>]
|
.B [password <password>] [--show-password]
|
||||||
.br
|
.br
|
||||||
Create a Wi-Fi hotspot. The command creates a hotspot connection profile according to
|
Create a Wi-Fi hotspot. The command creates a hotspot connection profile according to
|
||||||
Wi-Fi device capabilities and activates it on the device. The hotspot is secured with WPA
|
Wi-Fi device capabilities and activates it on the device. The hotspot is secured with WPA
|
||||||
@@ -864,20 +864,23 @@ Use \fIconnection down\fP or \fIdevice disconnect\fP to stop the hotspot.
|
|||||||
.RS
|
.RS
|
||||||
.PP
|
.PP
|
||||||
Parameters of the hotspot can be influenced by the optional parameters:
|
Parameters of the hotspot can be influenced by the optional parameters:
|
||||||
.IP \fIifname\fP 10
|
.IP \fIifname\fP 17
|
||||||
\(en what Wi-Fi device is used
|
\(en what Wi-Fi device is used
|
||||||
.IP \fIcon-name\fP 10
|
.IP \fIcon-name\fP 17
|
||||||
\(en name of the created hotspot connection profile
|
\(en name of the created hotspot connection profile
|
||||||
.IP \fIssid\fP 10
|
.IP \fIssid\fP 17
|
||||||
\(en SSID of the hotspot
|
\(en SSID of the hotspot
|
||||||
.IP \fIband\fP 10
|
.IP \fIband\fP 17
|
||||||
\(en Wi-Fi band to use
|
\(en Wi-Fi band to use
|
||||||
.IP \fIchannel\fP 10
|
.IP \fIchannel\fP 17
|
||||||
\(en Wi-Fi channel to use
|
\(en Wi-Fi channel to use
|
||||||
.IP \fIpassword\fP 10
|
.IP \fIpassword\fP 17
|
||||||
\(en password to use for the created hotspot. If not provided,
|
\(en password to use for the created hotspot. If not provided,
|
||||||
nmcli will generate a password. The password is either WPA
|
nmcli will generate a password. The password is either WPA
|
||||||
pre-shared key or WEP key.
|
pre-shared key or WEP key.
|
||||||
|
.IP \fI--show-password\fP 17
|
||||||
|
\(en tell nmcli to print the password to stdout. It is useful
|
||||||
|
when the user did not provide his own password.
|
||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
.B wifi rescan [ifname <ifname>] [[ssid <SSID>] ...]
|
.B wifi rescan [ifname <ifname>] [[ssid <SSID>] ...]
|
||||||
|
Reference in New Issue
Block a user