View | Details | Raw Unified | Return to bug 59004
Collapse All | Expand All

(-)a/properties/nm-openvpn-dialog.ui (+17 lines)
Lines 1753-1758 config: data-ciphers</property> Link Here
1753
                    <property name="top-attach">2</property>
1753
                    <property name="top-attach">2</property>
1754
                  </packing>
1754
                  </packing>
1755
                </child>
1755
                </child>
1756
                <child>
1757
                  <object class="GtkComboBox" id="data_ciphers_picker">
1758
                    <property name="visible">True</property>
1759
                    <property name="can-focus">False</property>
1760
                    <property name="tooltip-text" translatable="yes">Select a cipher to append it to the list.</property>
1761
                    <child>
1762
                      <object class="GtkCellRendererText" id="renderer_data_ciphers_picker"/>
1763
                      <attributes>
1764
                        <attribute name="text">0</attribute>
1765
                      </attributes>
1766
                    </child>
1767
                  </object>
1768
                  <packing>
1769
                    <property name="left-attach">2</property>
1770
                    <property name="top-attach">2</property>
1771
                  </packing>
1772
                </child>
1756
                <child>
1773
                <child>
1757
                  <object class="GtkLabel" id="label24">
1774
                  <object class="GtkLabel" id="label24">
1758
                    <property name="visible">True</property>
1775
                    <property name="visible">True</property>
(-)a/properties/nm-openvpn-editor.c (-3 / +130 lines)
Lines 1564-1569 ping_exit_restart_checkbox_toggled_cb (GtkWidget *check, gpointer user_data) Link Here
1564
	checkbox_toggled_update_widget_cb (check, spin);
1564
	checkbox_toggled_update_widget_cb (check, spin);
1565
}
1565
}
1566
1566
1567
static void
1568
data_ciphers_filter_cb (GtkEditable *editable, gpointer user_data)
1569
{
1570
	const char *text = gtk_editable_get_text (editable);
1571
	GString *filtered = g_string_new (NULL);
1572
	gboolean changed = FALSE;
1573
	const char *p;
1574
1575
	for (p = text; *p; p++) {
1576
		char c = *p;
1577
		if (g_ascii_isalnum (c) || c == '-' || c == ':')
1578
			g_string_append_c (filtered, c);
1579
		else
1580
			changed = TRUE;
1581
	}
1582
1583
	if (changed) {
1584
		g_signal_handlers_block_by_func (editable, data_ciphers_filter_cb, user_data);
1585
		gtk_editable_set_text (editable, filtered->str);
1586
		g_signal_handlers_unblock_by_func (editable, data_ciphers_filter_cb, user_data);
1587
	}
1588
1589
	g_string_free (filtered, TRUE);
1590
}
1591
1592
static void
1593
populate_data_ciphers_picker (GtkComboBox *box)
1594
{
1595
	gs_unref_object GtkListStore *store = NULL;
1596
	GtkTreeIter iter;
1597
	const char *openvpn_binary;
1598
	char *argv[3];
1599
1600
	store = gtk_list_store_new (1, G_TYPE_STRING);
1601
	gtk_combo_box_set_model (box, GTK_TREE_MODEL (store));
1602
1603
	gtk_list_store_append (store, &iter);
1604
	gtk_list_store_set (store, &iter, 0, _("— Add cipher —"), -1);
1605
1606
	openvpn_binary = nm_find_openvpn ();
1607
	if (openvpn_binary) {
1608
		gs_free gchar *tmp = NULL;
1609
		GError *error = NULL;
1610
		gboolean ignore = TRUE;
1611
1612
		argv[0] = (char *) openvpn_binary;
1613
		argv[1] = "--show-ciphers";
1614
		argv[2] = NULL;
1615
1616
		if (g_spawn_sync ("/", argv, NULL, 0, NULL, NULL, &tmp, NULL, NULL, &error)) {
1617
			gchar **lines = g_strsplit (tmp, "\n", 0);
1618
			gchar **line;
1619
1620
			for (line = lines; *line; line++) {
1621
				char *space;
1622
1623
				if (!strlen (*line)) {
1624
					ignore = !ignore;
1625
					continue;
1626
				}
1627
				if (ignore)
1628
					continue;
1629
1630
				space = strchr (*line, ' ');
1631
				if (space)
1632
					*space = '\0';
1633
1634
				if (!strcmp (*line, "none"))
1635
					continue;
1636
1637
				if (strlen (*line)) {
1638
					gtk_list_store_append (store, &iter);
1639
					gtk_list_store_set (store, &iter, 0, *line, -1);
1640
				}
1641
			}
1642
			g_strfreev (lines);
1643
		} else {
1644
			g_warning ("%s: couldn't determine ciphers: %s", __func__, error->message);
1645
			g_clear_error (&error);
1646
		}
1647
	}
1648
1649
	gtk_combo_box_set_active (box, 0);
1650
}
1651
1652
static void
1653
data_ciphers_picker_changed_cb (GtkComboBox *combo, gpointer user_data)
1654
{
1655
	GtkEditable *entry = GTK_EDITABLE (user_data);
1656
	GtkTreeModel *model;
1657
	GtkTreeIter iter;
1658
	char *cipher = NULL;
1659
	const char *current;
1660
1661
	if (gtk_combo_box_get_active (combo) == 0)
1662
		return;
1663
1664
	model = gtk_combo_box_get_model (combo);
1665
	if (!gtk_combo_box_get_active_iter (combo, &iter))
1666
		return;
1667
1668
	gtk_tree_model_get (model, &iter, 0, &cipher, -1);
1669
	if (!cipher || !*cipher) {
1670
		g_free (cipher);
1671
		gtk_combo_box_set_active (combo, 0);
1672
		return;
1673
	}
1674
1675
	current = gtk_editable_get_text (entry);
1676
	if (current && *current) {
1677
		gchar *new_text = g_strdup_printf ("%s:%s", current, cipher);
1678
		gtk_editable_set_text (entry, new_text);
1679
		g_free (new_text);
1680
	} else {
1681
		gtk_editable_set_text (entry, cipher);
1682
	}
1683
	g_free (cipher);
1684
1685
	gtk_combo_box_set_active (combo, 0);
1686
}
1687
1567
#define TA_DIR_COL_NAME 0
1688
#define TA_DIR_COL_NAME 0
1568
#define TA_DIR_COL_NUM 1
1689
#define TA_DIR_COL_NUM 1
1569
1690
Lines 1766-1776 advanced_dialog_new (GHashTable *hash, const char *contype) Link Here
1766
	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_CIPHER);
1887
	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_CIPHER);
1767
	populate_cipher_combo (GTK_COMBO_BOX (widget), value);
1888
	populate_cipher_combo (GTK_COMBO_BOX (widget), value);
1768
1889
1890
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "data_ciphers_entry"));
1891
	g_signal_connect (G_OBJECT (widget), "changed",
1892
	                  G_CALLBACK (data_ciphers_filter_cb), NULL);
1769
	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_DATA_CIPHERS);
1893
	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_DATA_CIPHERS);
1770
	if (value && *value) {
1894
	if (value && *value)
1771
		widget = GTK_WIDGET (gtk_builder_get_object (builder, "data_ciphers_entry"));
1772
		gtk_editable_set_text (GTK_EDITABLE (widget), value);
1895
		gtk_editable_set_text (GTK_EDITABLE (widget), value);
1773
	}
1896
1897
	combo = GTK_WIDGET (gtk_builder_get_object (builder, "data_ciphers_picker"));
1898
	populate_data_ciphers_picker (GTK_COMBO_BOX (combo));
1899
	g_signal_connect (G_OBJECT (combo), "changed",
1900
	                  G_CALLBACK (data_ciphers_picker_changed_cb), widget);
1774
1901
1775
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "data_ciphers_fallback_combo"));
1902
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "data_ciphers_fallback_combo"));
1776
	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_DATA_CIPHERS_FALLBACK);
1903
	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_DATA_CIPHERS_FALLBACK);

Return to bug 59004