add "BinaryPathEditor" for passenger-/fcgi-interpreter selection

This commit is contained in:
Peter Hormanns 2024-01-23 18:43:58 +01:00
parent f539c87aea
commit 8e8d2f17b8
5 changed files with 169 additions and 7 deletions

View File

@ -0,0 +1,137 @@
package de.hsadmin.web;
import java.util.List;
import java.util.Map;
import com.vaadin.ui.CustomComponent;
import com.vaadin.v7.data.Validator;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
import com.vaadin.v7.ui.HorizontalLayout;
import com.vaadin.v7.ui.NativeSelect;
import com.vaadin.v7.ui.TextField;
import com.vaadin.v7.ui.VerticalLayout;
import de.hsadmin.rpc.PropertyInfo;
public class BinaryPathEditor extends CustomComponent implements IHSEditor {
private static final long serialVersionUID = 1L;
public static final String[] PYTHON3_PATH =
new String[] {
"/usr/bin/python3"
};
public static final String[] RUBY_PATH =
new String[] {
"/usr/bin/ruby"
};
public static final String[] NODEJS_PATH =
new String[] {
"/usr/bin/node"
};
public static final String[] PHP_CGI_PATH =
new String[] {
"/usr/lib/cgi-bin/php7.4",
"/usr/lib/cgi-bin/php8.0",
"/usr/lib/cgi-bin/php8.1",
"/usr/lib/cgi-bin/php8.2",
"/usr/lib/cgi-bin/php"
};
private PropertyInfo propertyInfo;
private I18N i18n;
private HorizontalLayout layout;
private NativeSelect isManagedInstallationSelect;
private NativeSelect managedPathSelect;
private TextField pathField;
public BinaryPathEditor(final I18N i18n, final PropertyInfo propertyInfo, final String[] values) {
this.propertyInfo = propertyInfo;
this.i18n = i18n;
this.setCaption(i18n.getText(propertyInfo.getName()));
layout = new HorizontalLayout();
layout.setSpacing(true);
isManagedInstallationSelect = new NativeSelect();
isManagedInstallationSelect.setMultiSelect(false);
isManagedInstallationSelect.setNullSelectionAllowed(false);
isManagedInstallationSelect.addItem(i18n.getText("patheditor.managed"));
isManagedInstallationSelect.addItem(i18n.getText("patheditor.userspace"));
isManagedInstallationSelect.setValue(i18n.getText("patheditor.managed"));
isManagedInstallationSelect.setVisible(true);
isManagedInstallationSelect.setWidth("200px");
layout.addComponent(isManagedInstallationSelect);
managedPathSelect = new NativeSelect();
managedPathSelect.setMultiSelect(false);
managedPathSelect.setNullSelectionAllowed(false);
String defaultPath = "";
for (String path : values) {
managedPathSelect.addItem(path);
defaultPath = path;
}
managedPathSelect.setValue(defaultPath);
managedPathSelect.setWidth("400px");
layout.addComponent(managedPathSelect);
pathField = new TextField();
pathField.setWidth("400px");
pathField.setVisible(false);
layout.addComponent(pathField);
isManagedInstallationSelect.setImmediate(true);
isManagedInstallationSelect.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
final Object selectedValue = event.getProperty().getValue();
if (i18n.getText("patheditor.managed").equals(selectedValue)) {
managedPathSelect.setVisible(true);
pathField.setVisible(false);
} else {
managedPathSelect.setVisible(false);
pathField.setVisible(true);
}
}
});
setCompositionRoot(layout);
}
@Override
public void setValues(Map<String, Object> valuesMap) {
Object value = valuesMap.get(propertyInfo.getName());
if (value == null) value = "";
if (!(value instanceof String)) value = "";
String text = (String) value;
if (text.isEmpty() || text.startsWith("/usr/bin/") || text.startsWith("/usr/lib/")) {
isManagedInstallationSelect.setValue(i18n.getText("patheditor.managed"));
managedPathSelect.setValue(text);
} else {
isManagedInstallationSelect.setValue(i18n.getText("patheditor.userspace"));
pathField.setValue(text);
}
}
@Override
public Object getValue() {
if (i18n.getText("patheditor.managed").equals(isManagedInstallationSelect.getValue())) {
return managedPathSelect.getValue();
}
return pathField.getValue();
}
@Override
public void addValidator(Validator validator) {
pathField.addValidator(validator);
}
@Override
public boolean isValid() {
Object value = getValue();
if (value instanceof String) {
String text = (String) value;
return text.startsWith("/usr/") || text.startsWith("/home/");
}
return false;
}
}

View File

@ -44,8 +44,17 @@ public class GenericEditorFactory implements IEditorFactory, Serializable {
if ("domainoptions".equals(inputName)) { if ("domainoptions".equals(inputName)) {
return getDomainOptionsEditor(action, propertyInfo, session, whereContext); return getDomainOptionsEditor(action, propertyInfo, session, whereContext);
} }
if ("passengerpython".equals(inputName)|"passengernodejs".equals(inputName)|"passengerruby".equals(inputName)|"fcgiphpbin".equals(inputName)) { if ("passengernodejs".equals(inputName)) {
return getScriptingPathEditor(action, propertyInfo); return getScriptingPathEditor(action, propertyInfo, BinaryPathEditor.NODEJS_PATH);
}
if ("passengerpython".equals(inputName)) {
return getScriptingPathEditor(action, propertyInfo, BinaryPathEditor.PYTHON3_PATH);
}
if ("passengerruby".equals(inputName)) {
return getScriptingPathEditor(action, propertyInfo, BinaryPathEditor.RUBY_PATH);
}
if ("fcgiphpbin".equals(inputName)) {
return getScriptingPathEditor(action, propertyInfo, BinaryPathEditor.PHP_CGI_PATH);
} }
} }
if ("emailaddress".equals(module) || "emailalias".equals(module)) { if ("emailaddress".equals(module) || "emailalias".equals(module)) {
@ -80,8 +89,12 @@ public class GenericEditorFactory implements IEditorFactory, Serializable {
return PanelToolbar.ACTION_EDIT.equals(action) ? getEditor(action, propertyInfo) : new NullEditor(); return PanelToolbar.ACTION_EDIT.equals(action) ? getEditor(action, propertyInfo) : new NullEditor();
} }
private IHSEditor getScriptingPathEditor(final String action, final PropertyInfo propertyInfo) { private IHSEditor getScriptingPathEditor(final String action, final PropertyInfo propertyInfo, final String[] selectableValues) {
return PanelToolbar.ACTION_EDIT.equals(action) ? getEditor(action, propertyInfo) : new NullEditor(); if (PanelToolbar.ACTION_EDIT.equals(action)) {
final IHSEditor editor = new BinaryPathEditor(i18n, propertyInfo, selectableValues);
return editor;
}
return new NullEditor();
} }
private IHSEditor getDomainOptionsEditor(final String action, final PropertyInfo propertyInfo, final HSAdminSession session, final Map<String, String> whereContext) { private IHSEditor getDomainOptionsEditor(final String action, final PropertyInfo propertyInfo, final HSAdminSession session, final Map<String, String> whereContext) {
@ -158,7 +171,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable {
{ {
final HSPacPrefixedField field = new HSPacPrefixedField(i18n, propertyInfo, delimiter); final HSPacPrefixedField field = new HSPacPrefixedField(i18n, propertyInfo, delimiter);
field.setWidth("100%"); field.setWidth("100%");
field.setValue("xyz00-"); field.setValue("xyz00" + delimiter);
enableAndValidate(action, propertyInfo, field); enableAndValidate(action, propertyInfo, field);
return field; return field;
} }
@ -166,7 +179,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable {
private IHSEditor getShellSelect(final String action, final PropertyInfo propertyInfo) private IHSEditor getShellSelect(final String action, final PropertyInfo propertyInfo)
{ {
final String[] items = new String[] { "/bin/false", "/bin/bash", "/bin/csh", "/bin/dash", "/usr/bin/tcsh", "/usr/bin/zsh", "/usr/bin/passwd" }; final String[] items = new String[] { "/bin/false", "/bin/bash", "/bin/csh", "/bin/dash", "/usr/bin/tcsh", "/usr/bin/zsh", "/usr/bin/passwd" };
final HSSelect field = new HSSelect(i18n, propertyInfo, 7, Arrays.asList(items)); final HSSelect field = new HSSelect(i18n, propertyInfo, 1, Arrays.asList(items));
field.setWidth("100%"); field.setWidth("100%");
field.setEnabled(isWriteAble(propertyInfo, action)); field.setEnabled(isWriteAble(propertyInfo, action));
return field; return field;

View File

@ -29,7 +29,7 @@ public class GenericFormWindow extends Window implements IHSWindow {
this.parent = parent; this.parent = parent;
center(); center();
setModal(true); setModal(true);
setWidth("640px"); setWidth("960px");
inputFields = new HashMap<String, IHSEditor>(); inputFields = new HashMap<String, IHSEditor>();
contentForm = new FormLayout(); contentForm = new FormLayout();
contentForm.setMargin(true); contentForm.setMargin(true);

View File

@ -193,3 +193,9 @@ pac.name=Packet name
pac.basepac=Packet type pac.basepac=Packet type
pac.hive=Packet server pac.hive=Packet server
pac.curinetaddr=IPv4 address pac.curinetaddr=IPv4 address
patheditor.managed=provided (/usr/bin/..)
patheditor.userspace=Userspace (/home/..)
passengerpython=passenger python binary
passengernodejs=passenger node binary
passengerruby=passenger ruby binary
fcgiphpbin=fcgi php binary

View File

@ -188,3 +188,9 @@ pac.name=Paket-Name
pac.basepac=Paket-Typ pac.basepac=Paket-Typ
pac.hive=Server/Hive pac.hive=Server/Hive
pac.curinetaddr=Netzwerk-Adresse (IPv4) pac.curinetaddr=Netzwerk-Adresse (IPv4)
patheditor.managed=vorinstalliert (/usr/bin/..)
patheditor.userspace=Userspace (/home/..)
passengerpython=Passenger Python-Interpreter
passengernodejs=Passenger Node-Interpreter
passengerruby=Passenger Ruby-Interpreter
fcgiphpbin=FCGI-PHP-Interpreter