Skip to content

Commit

Permalink
SSH Wizard: add toggle button password/pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
wizmer committed Sep 8, 2016
1 parent 5e242eb commit 44c034b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.ViewTreeObserver;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.Switch;

import com.matburt.mobileorg.Gui.Wizard.Wizards.SSHWizard;
import com.matburt.mobileorg.Gui.Wizard.Wizards.Wizard;
Expand Down Expand Up @@ -45,7 +47,7 @@ public void onCreate(Bundle savedInstanceState) {
syncSdCard = findViewById(R.id.sync_sdcard).getId();
syncNull = findViewById(R.id.sync_null).getId();
syncSSH = findViewById(R.id.sync_ssh).getId();

ViewTreeObserver observer = wizardView.getViewTreeObserver();
if (observer.isAlive()) {
observer.addOnGlobalLayoutListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;

import com.matburt.mobileorg.Gui.Wizard.WizardView;
Expand All @@ -30,6 +32,7 @@ public class SSHWizard extends Wizard {
private EditText sshPort;

private TextView sshPubFileActual;
Switch auth_selector;

public SSHWizard(WizardView wizardView, Context context) {
super(wizardView, context);
Expand All @@ -39,20 +42,26 @@ public SSHWizard(WizardView wizardView, Context context) {
@Override
public void setupFirstPage() {
createSSHConfig();


}

public View createSSHConfig() {
View view = LayoutInflater.from(context).inflate(
R.layout.wizard_ssh, null);


final TextView sshPasswordTitle = (TextView) view.findViewById(R.id.wizard_ssh_password_text);
final TextView sshPubkeyTitle = (TextView) view.findViewById(R.id.wizard_ssh_pubkey_prompt);

sshUser = (EditText) view.findViewById(R.id.wizard_ssh_username);
sshPass = (EditText) view.findViewById(R.id.wizard_ssh_password);
sshPath = (EditText) view.findViewById(R.id.wizard_ssh_path);
sshHost = (EditText) view.findViewById(R.id.wizard_ssh_host);
sshPort = (EditText) view.findViewById(R.id.wizard_ssh_port);
sshPubFileActual = (TextView) view
.findViewById(R.id.wizard_ssh_pub_file_actual);
Button sshPubFileSelect = (Button) view
final Button sshPubFileSelect = (Button) view
.findViewById(R.id.wizard_ssh_choose_pub_file);
sshPubFileSelect.setOnClickListener(new OnClickListener() {
@Override
Expand All @@ -66,8 +75,32 @@ public void onClick(View v) {
}
});



auth_selector = (Switch) view.findViewById(R.id.auth_selector);
auth_selector.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b){
sshPass.setVisibility(View.GONE);
sshPasswordTitle.setVisibility(View.GONE);
sshPubFileSelect.setVisibility(View.VISIBLE);
sshPubkeyTitle.setVisibility(View.VISIBLE);
sshPubFileActual.setVisibility(View.VISIBLE);
} else {
sshPass.setVisibility(View.VISIBLE);
sshPasswordTitle.setVisibility(View.VISIBLE);
sshPubFileSelect.setVisibility(View.GONE);
sshPubkeyTitle.setVisibility(View.GONE);
sshPubFileActual.setVisibility(View.GONE);
}
}
});

loadSettings();



setupDoneButton(view);
wizardView.addPage(view);
wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
Expand All @@ -87,13 +120,17 @@ private void loadSettings() {
sshPass.setText(appSettings.getString("scpPass", ""));
sshHost.setText(appSettings.getString("scpHost", ""));
sshPort.setText(appSettings.getString("scpPort", ""));
auth_selector.setChecked( appSettings.getBoolean("usePassword", true));
auth_selector.performClick();
auth_selector.performClick();
sshPubFileActual.setText(appSettings.getString("scpPubFile", ""));
}

public void saveSettings() {
final String pathActual = sshPath.getText().toString();
final String userActual = sshUser.getText().toString();
final String hostActual = sshHost.getText().toString();

String portActual = sshPort.getText().toString();
if(portActual.equals("")) portActual = "22";

Expand All @@ -109,6 +146,7 @@ public void saveSettings() {
editor.putString("scpUser", userActual);
editor.putString("scpHost", hostActual);
editor.putString("scpPort", portActual);
editor.putBoolean("usePassword", auth_selector.isChecked());
editor.putString("scpPubFile", sshPubFileActual.getText().toString());
editor.putString("scpPass", sshPass.getText().toString());
editor.apply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static AuthData getInstance(Context context) {
return mAuthData;
}

public boolean usePassword(){
return appSettings.getBoolean("usePassword", true);
}

public String getPath() {
return OrgUtils.rStrip(appSettings.getString("scpPath", ""));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static ConnectionType getConnectionType(Context context) {
final AuthData authData = AuthData.getInstance(context);
if (authData.getHost().startsWith("http")) return ConnectionType.kHttp;
else {
if (!authData.getPubFile().equals("")) return ConnectionType.kSshPubKey;
if (authData.usePassword()) return ConnectionType.kSshPubKey;
else return ConnectionType.kSshPassword;
}
}
Expand Down
14 changes: 10 additions & 4 deletions MobileOrg/src/main/res/layout/wizard_page1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="@string/wizard_webdav"
android:visibility="gone"
android:checked="true"/>
<RadioButton
android:textSize="18dp"
android:id="@+id/sync_dropbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"

android:layout_height="wrap_content"
android:text="@string/wizard_dropbox" />
<RadioButton
android:textSize="18dp"
android:id="@+id/sync_ubuntuone"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_ubuntuone" />
<RadioButton
Expand All @@ -49,13 +53,15 @@
<RadioButton
android:textSize="18dp"
android:id="@+id/sync_sdcard"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_sdcard" />
<RadioButton
android:id="@+id/sync_null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="@string/wizard_null"
android:checked="true"/>
Expand Down
19 changes: 19 additions & 0 deletions MobileOrg/src/main/res/layout/wizard_ssh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,25 @@
android:layout_height="wrap_content"
android:textSize="20dp"
android:singleLine="true" android:inputType="text|textEmailAddress"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:paddingTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/auth_type"
android:textSize="20dp"/>
<Switch
android:id="@+id/auth_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
android:id="@+id/wizard_ssh_password_text"
android:paddingTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -50,6 +68,7 @@
android:password="true"
android:singleLine="true"/>
<TextView
android:id="@+id/wizard_ssh_pubkey_prompt"
android:paddingTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
3 changes: 2 additions & 1 deletion MobileOrg/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<string name="conflict">Conflict</string>
<string name="date">Date</string>
<string name="time">Time</string>
<string name="auth_type">Authentifaction type:</string>

<!-- toasts -->
<string name="unselectable_item">You cannot select this item</string>
Expand Down Expand Up @@ -137,7 +138,7 @@
<string name="log_in_to_ubuntuone">Log in to Ubuntu One</string>
<string name="log_in_to_webdav">Log in to your WebDAV server</string>
<string name="log_in_to_ssh">Log in to your SSH server</string>
<string name="ssh_inform_choose_pub_file">OR select a file containing your *private* key (requires a file explorer program to be installed)</string>
<string name="ssh_inform_choose_pub_file">SSH private key</string>
<string name="ssh_choose_file_button">Select your *private* key file</string>
<string name="null_sync_description">This is a capture only synchronizerManager. It will not attempt to synchronize to any source.</string>
<string name="dropbox_login_info">This will redirect you to a login form. After logging in it will return you to this screen to continue.</string>
Expand Down

0 comments on commit 44c034b

Please sign in to comment.