remove deprecated cometvisu-php binding (#1594)

* remove deprecated cometvisu-php binding

closes #1592

Signed-off-by: Tobias Bräutigam <tbraeutigam@gmail.com>
pull/1616/head^2
Tobias Bräutigam 2022-12-30 19:50:10 +01:00 committed by GitHub
parent 2f5bb5c8ee
commit 87e1d78705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 30 additions and 853 deletions

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="annotationpath" value="target/dependency"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="annotationpath" value="target/dependency"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.ui.cometvisu.php</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -1,13 +0,0 @@
This content is produced and maintained by the openHAB project.
* Project home: https://www.openhab.org
== Declared Project Licenses
This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.
== Source Code
https://github.com/openhab/openhab2-addons

View File

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openhab.ui.bundles</groupId>
<artifactId>org.openhab.ui.reactor.bundles</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.ui.cometvisu.php</artifactId>
<name>openHAB UI :: Bundles :: CometVisu :: PHP Support</name>
<dependencies>
<dependency>
<groupId>org.openhab</groupId>
<artifactId>com.caucho.quercus</artifactId>
<version>4.0.45</version>
</dependency>
<dependency>
<groupId>org.openhab.ui.bundles</groupId>
<artifactId>org.openhab.ui.cometvisu</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.model.sitemap</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.ui</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.ui.icon</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.ui.cometvisu-php-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
<repository>mvn:org.openhab.ui.bundles/org.openhab.ui.cometvisu/${project.version}/xml/features</repository>
<feature name="openhab-ui-cometvisu-php" description="PHP support for CometVisu" version="${project.version}">
<feature>openhab-core-ui</feature>
<feature>openhab-ui-cometvisu</feature>
<bundle>mvn:org.openhab.ui.bundles/org.openhab.ui.cometvisu.php/${project.version}</bundle>
<bundle>mvn:org.openhab/com.caucho.quercus/4.0.45</bundle>
</feature>
</features>

View File

@ -1,342 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.ui.cometvisu.internal.servlet.quercus;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openhab.ui.cometvisu.php.PHProvider;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.caucho.java.WorkDir;
import com.caucho.quercus.QuercusContext;
import com.caucho.quercus.QuercusEngine;
import com.caucho.quercus.QuercusErrorException;
import com.caucho.quercus.QuercusExitException;
import com.caucho.quercus.QuercusLineRuntimeException;
import com.caucho.quercus.QuercusRequestAdapter;
import com.caucho.quercus.QuercusRuntimeException;
import com.caucho.quercus.env.Env;
import com.caucho.quercus.env.QuercusValueException;
import com.caucho.quercus.env.StringValue;
import com.caucho.quercus.page.QuercusPage;
import com.caucho.quercus.servlet.api.QuercusHttpServletRequest;
import com.caucho.quercus.servlet.api.QuercusHttpServletRequestImpl;
import com.caucho.quercus.servlet.api.QuercusHttpServletResponse;
import com.caucho.quercus.servlet.api.QuercusHttpServletResponseImpl;
import com.caucho.quercus.servlet.api.QuercusServletContextImpl;
import com.caucho.util.CurrentTime;
import com.caucho.util.L10N;
import com.caucho.vfs.FilePath;
import com.caucho.vfs.Path;
import com.caucho.vfs.Vfs;
import com.caucho.vfs.WriteStream;
/**
* Provides PHP5 execution service
*
* @author Tobias Bräutigam - initial contribution and API
* @author BalusC - code for static files (taken from FileServlet)
* @author Scott Ferguson - code for php files (taken from QuercusServletImpl)
*
* @link
* http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html
* @link http://quercus.caucho.com/
*
*/
@Component(immediate = true)
public class PHProviderImpl implements PHProvider {
private final Logger logger = LoggerFactory.getLogger(PHProviderImpl.class);
private static final L10N L = new L10N(PHProviderImpl.class);
protected QuercusEngine engine;
protected String defaultUserDir;
protected ServletContext servletContext;
@Override
public void createQuercusEngine() {
this.engine = new QuercusEngine();
}
/**
* Set an ini value
*
* @param name - name of the ini parameter
* @param value - value of the ini parameter
*/
@Override
public void setIni(String name, String value) {
engine.getQuercus().setIni(name, value);
}
/**
* Initialize the quercus engine
*
* @param path - base path
* @param userDir - default user directory
* @param context - servlet context
*/
@Override
public void init(String path, String userDir, ServletContext context) {
checkServletAPIVersion(context);
this.defaultUserDir = userDir;
this.servletContext = context;
Path pwd = new FilePath(path);
Path webInfDir = pwd;
logger.debug("initial pwd {}", pwd);
engine.getQuercus().setPwd(pwd);
engine.getQuercus().setWebInfDir(webInfDir);
// need to set these for non-Resin containers
if (!CurrentTime.isTest() && !engine.getQuercus().isResin()) {
Vfs.setPwd(pwd);
WorkDir.setLocalWorkDir(webInfDir.lookup("work"));
}
engine.getQuercus().init();
engine.getQuercus().start();
}
/**
* Executes a php file and sends the result back to the {@HttpServletResponse}
*
* @param file - the php file which should be processed
* @param request - the http request
* @param response - the http response
* @throws ServletException
* @throws IOException
*/
@Override
public final void phpService(File file, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Env env = null;
WriteStream ws = null;
QuercusHttpServletRequest req = new QuercusHttpServletRequestImpl(request);
QuercusHttpServletResponse res = new QuercusHttpServletResponseImpl(response);
try {
Path path = getPath(file, req);
logger.debug("phpService path: {}", path);
QuercusPage page;
try {
page = engine.getQuercus().parse(path);
} catch (FileNotFoundException e) {
// php/2001
logger.debug("{}", e.toString(), e);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
ws = openWrite(response);
// php/2002
// for non-Resin containers
// for servlet filters that do post-request work after Quercus
ws.setDisableCloseSource(true);
// php/6006
ws.setNewlineString("\n");
QuercusContext quercus = engine.getQuercus();
env = quercus.createEnv(page, ws, req, res);
// php/815d
env.setPwd(path.getParent());
logger.debug("setting user dir to {}", path.getParent().getNativePath());
System.setProperty("user.dir", path.getParent().getNativePath());
quercus.setServletContext(new QuercusServletContextImpl(servletContext));
try {
env.start();
// php/2030, php/2032, php/2033
// Jetty hides server classes from web-app
// http://docs.codehaus.org/display/JETTY/Classloading
//
// env.setGlobalValue("request", env.wrapJava(request));
// env.setGlobalValue("response", env.wrapJava(response));
// env.setGlobalValue("servletContext",
// env.wrapJava(_servletContext));
StringValue prepend = quercus.getIniValue("auto_prepend_file").toStringValue(env);
if (prepend.length() > 0) {
Path prependPath = env.lookup(prepend);
if (prependPath == null) {
env.error(L.l("auto_prepend_file '{0}' not found.", prepend));
} else {
QuercusPage prependPage = engine.getQuercus().parse(prependPath);
prependPage.executeTop(env);
}
}
env.executeTop();
StringValue append = quercus.getIniValue("auto_append_file").toStringValue(env);
if (append.length() > 0) {
Path appendPath = env.lookup(append);
if (appendPath == null) {
env.error(L.l("auto_append_file '{0}' not found.", append));
} else {
QuercusPage appendPage = engine.getQuercus().parse(appendPath);
appendPage.executeTop(env);
}
}
// return;
} catch (QuercusExitException e) {
throw e;
} catch (QuercusErrorException e) {
throw e;
} catch (QuercusLineRuntimeException e) {
logger.debug("{}", e.toString(), e);
ws.println(e.getMessage());
// return;
} catch (QuercusValueException e) {
logger.debug("{}", e.toString(), e);
ws.println(e.toString());
// return;
} catch (StackOverflowError e) {
RuntimeException myException = new RuntimeException(L.l("StackOverflowError at {0}", env.getLocation()),
e);
throw myException;
} catch (Exception e) {
if (response.isCommitted()) {
e.printStackTrace(ws.getPrintWriter());
}
ws = null;
throw e;
} finally {
if (env != null) {
env.close();
}
// don't want a flush for an exception
if (ws != null && env != null && env.getDuplex() == null) {
ws.close();
}
System.setProperty("user.dir", defaultUserDir);
}
} catch (com.caucho.quercus.QuercusDieException e) {
// normal exit
logger.trace("{}", e.getMessage(), e);
} catch (QuercusExitException e) {
// normal exit
logger.trace("{}", e.getMessage(), e);
} catch (QuercusErrorException e) {
// error exit
logger.error("{}", e.getMessage(), e);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
handleException(response, e);
}
}
protected Path getPath(File file, QuercusHttpServletRequest req) {
// php/8173
Path pwd = engine.getQuercus().getPwd().copy();
String servletPath = QuercusRequestAdapter.getPageServletPath(req);
if (servletPath.startsWith("/")) {
servletPath = servletPath.substring(1);
}
Path path = pwd.lookupChild(servletPath);
// php/2010, php/2011, php/2012
if (path.isFile()) {
return path;
}
StringBuilder sb = new StringBuilder();
if (path.exists()) {
sb.append(servletPath);
}
String pathInfo = QuercusRequestAdapter.getPagePathInfo(req);
if (pathInfo != null) {
if (pathInfo.startsWith("/")) {
pathInfo = pathInfo.substring(1);
}
if (sb.length() > 1) {
sb.append("/");
}
sb.append(pathInfo);
}
String scriptPath = sb.toString();
path = pwd.lookupChild(scriptPath);
if (file != null && !path.isFile()) {
path = path.lookupChild(file.getName());
}
logger.debug("ServletPath '{}', PathInfo: '{}', ScriptPath: '{}' => Path '{}'", servletPath, pathInfo,
scriptPath, path);
return path;
}
protected void handleException(HttpServletResponse response, Throwable e) throws IOException, ServletException {
throw new ServletException(e);
}
protected WriteStream openWrite(HttpServletResponse response) throws IOException {
WriteStream ws;
OutputStream out = response.getOutputStream();
ws = Vfs.openWrite(out);
return ws;
}
/**
* Makes sure the servlet container supports Servlet API 2.4+.
*/
protected void checkServletAPIVersion(ServletContext context) {
int major = context.getMajorVersion();
int minor = context.getMinorVersion();
if (major < 2 || major == 2 && minor < 4) {
throw new QuercusRuntimeException(L.l("Quercus requires Servlet API 2.4+."));
}
}
}

View File

@ -0,0 +1,8 @@
# Development Hints
Source files are automatically generated from CometVisu's visu_config.xsd and openapi.yaml files.
For a manual update of these files copy them to the src/main/resources folder and run
`mvn clean generated-sources`.
If the library version changes the value must be updated in `org.openhab.ui.cometvisu.internal.backend.model.config.LibVersion`.

View File

@ -12,17 +12,17 @@ to use the CometVisu with openHAB as backend. If you use an extra webserver to s
docker container of the CometVisu <https://hub.docker.com/r/cometvisu/cometvisu>) this binding is obsolete.
You only need this binding if you want to use openHABs internal webserver to serve the CometVisu.
**"PHP support for CometVisu"-binding is not needed anymore**
**"PHP support for CometVisu"-binding is not needed anymore and has been deleted**
If you want to use this binding to serve the CometVisu, you do not need the additional "PHP support for CometVisu" binding anymore.
That binding is deprecated and will be removed in future openHAB versions. This binding provides everything that is needed to
run CometVisus own file-manager and editors. The only things that are not supported are plugins that use PHP-Code.
The additional "PHP support for CometVisu" binding is not needed anymore. It has been removed in openHAB 4.0.
This binding provides everything that is needed to run CometVisu's own file-manager and editors.
The only things that are not supported are plugins, that use PHP-Code.
## Requirements
* openHAB 2.0 or greater
* CometVisu 0.8.6 or greater <https://github.com/CometVisu/CometVisu/releases>
* CometVisu 0.12.0 or greater <https://github.com/CometVisu/CometVisu/releases>
## Installation
@ -146,12 +146,6 @@ http://<openhab-server>:8080/<webAlias>/?config=<sitemap-name>
You can use the editor to change and store this config.
You can start with the demo-sitemap to get a quick overview about how the CometVisu looks like.
## New features (compared to the 1.x version)
* PHP support: Editor is working, rsslog-plugin can be used (see examples)
* Persistence support: Any persisted item can be used to create a chart
* GroupItem support: as known from the openHAB UI´s the group-functions like the number of open windows in a group of contacts can be shown in the visu
## Examples
@ -268,15 +262,13 @@ sendCommand(Logger,"Received call from 123456789")
</colorchooser>
```
Please note: You have to add the colorchooser plugin in the meta>plugins section of you config
## Known problems
Not all of the PHP-based functions in the CometVisu client have been tested so far. The untested features are:
Plugins that use custom PHP code, do not work when you use this binding to serve the CometVisu, currently these are:
* Automatic configuration upgrade, when the library version has changed
* calendarlist plugin
* upnpcontroller plugin
* Direct influxdb support in diagrams
* TR064 plugin (use openHABs TR064 binding instead)
* upnpcontroller plugin
The sitemap support can only be used as a starting point for own customizations, e.g. you open an automatic generated config and store it in by CometVisu by using the editor. Then you start to customize it to your own needs. New items must by added by hand from the moment you stored and changed the generated config.
@ -288,31 +280,6 @@ Please make sure that openHAB has the rights to read the configured \<webFolder\
If you get an 403 - Access Denied error, when you try to open the CometVisu in your browser you have not copied the correct release folder into the \<webFolder\> folder. Please check if there is a subfolder with the exact name "release/", which contains an index.html file and copy the content to the folder defined in the \<webFolder\>-property.
### Hints for development
Source file are automatically generated from CometVisu's visu_config.xsd and openapi.yaml files.
For a manual update of these files copy them to the src/main/resources folder and run
`mvn clean generated-sources`.
If the library version changes the value must be updated in `org.openhab.ui.cometvisu.internal.backend.model.config.LibVersion`.
## TODO
Maybe it is possible to define a general structure (in addition to a sitemap), that maps and groups items based on their context, e.g. which floor/room/subsection the belong to
```
<floor>
<room navbar="top">
<all-lights-items colspan="12">
<all-rollershutter-items colspan="6">
<all-contact-items colspan="6">
<all-other-items colspan="12">
</room>
</floor>
```
Something like that could help to improve the sitemap->config generation.
## Screenshots
some screenshots can be found here:
@ -322,5 +289,6 @@ some screenshots can be found here:
## Links
* German CometVisu Support Forum: <https://knx-user-forum.de/forum/supportforen/cometvisu>
* User documentation for the CometVisu: <https://www.cometvisu.org/>
* English User documentation for the CometVisu: <https://www.cometvisu.org/CometVisu/en/latest/manual/>
* German user documentation for the CometVisu: <https://www.cometvisu.org/CometVisu/de/latest/manual/>
* GitHub project page of the CometVisu: <https://github.com/CometVisu/CometVisu>

View File

@ -158,20 +158,18 @@ public class ConfigHelper {
defaultStatus.setValue(" - <a href=\".\">Default Config</a>");
statusbar.getStatus().add(defaultStatus);
if (this.app.getServlet().isPhpEnabled()) {
CDataStatus editStatus = new CDataStatus();
editStatus.setType("html");
editStatus.setCondition("!edit");
editStatus.setHrefextend("config");
editStatus.setValue(" - <a href=\"editor/\">Edit</a>");
statusbar.getStatus().add(editStatus);
CDataStatus editStatus = new CDataStatus();
editStatus.setType("html");
editStatus.setCondition("!edit");
editStatus.setHrefextend("config");
editStatus.setValue(" - <a cv-action=\"edit/\">Edit</a>");
statusbar.getStatus().add(editStatus);
CDataStatus checkStatus = new CDataStatus();
checkStatus.setType("html");
checkStatus.setHrefextend("config");
checkStatus.setValue("- <a href=\"check_config.php\">Check Config</a>");
statusbar.getStatus().add(checkStatus);
}
CDataStatus checkStatus = new CDataStatus();
checkStatus.setType("html");
checkStatus.setHrefextend("config");
checkStatus.setValue("- <a cv-action=\"validate\">Check Config</a>");
statusbar.getStatus().add(checkStatus);
// add download link
CDataStatus downloadConfig = new CDataStatus();

View File

@ -33,7 +33,6 @@ import org.openhab.core.ui.icon.IconProvider;
import org.openhab.core.ui.items.ItemUIRegistry;
import org.openhab.ui.cometvisu.internal.Config;
import org.openhab.ui.cometvisu.internal.util.ClientInstaller;
import org.openhab.ui.cometvisu.php.PHProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.service.cm.ConfigurationException;
@ -44,7 +43,6 @@ import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.slf4j.Logger;
@ -78,8 +76,6 @@ public class CometVisuApp {
private CometVisuServlet servlet;
private PHProvider phpProvider;
protected static Map<String, QueryablePersistenceService> persistenceServices = new HashMap<>();
private final ClientInstaller installer = ClientInstaller.getInstance();
@ -187,25 +183,6 @@ public class CometVisuApp {
this.httpService = null;
}
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
public void setPHProvider(PHProvider prov) {
this.phpProvider = prov;
if (servlet != null) {
servlet.setPHProvider(prov);
}
}
public PHProvider getPHProvider() {
return this.phpProvider;
}
public void unsetPHProvider(PHProvider prov) {
this.phpProvider = null;
if (servlet != null) {
servlet.unsetPHProvider();
}
}
private void readConfiguration(final Map<String, Object> properties) {
if (properties != null) {
setProperties(properties);

View File

@ -30,11 +30,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -47,18 +45,9 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.OpenHAB;
import org.openhab.core.items.GroupItem;
import org.openhab.core.items.Item;
import org.openhab.core.items.ItemNotFoundException;
import org.openhab.core.items.events.ItemEventFactory;
@ -71,19 +60,11 @@ import org.openhab.core.persistence.HistoricItem;
import org.openhab.core.persistence.QueryablePersistenceService;
import org.openhab.core.types.Command;
import org.openhab.ui.cometvisu.internal.Config;
import org.openhab.ui.cometvisu.internal.backend.model.editor.dataprovider.DataBean;
import org.openhab.ui.cometvisu.internal.backend.model.editor.dataprovider.ItemBean;
import org.openhab.ui.cometvisu.internal.backend.model.rss.Feed;
import org.openhab.ui.cometvisu.internal.backend.sitemap.ConfigHelper.Transform;
import org.openhab.ui.cometvisu.internal.backend.sitemap.VisuConfig;
import org.openhab.ui.cometvisu.internal.util.ClientInstaller;
import org.openhab.ui.cometvisu.php.PHProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.google.gson.Gson;
@ -111,7 +92,6 @@ public class CometVisuServlet extends HttpServlet {
protected File rootFolder;
protected File userFileFolder;
protected @Nullable String defaultUserDir;
protected @Nullable PHProvider engine;
protected @Nullable ServletContext servletContext;
protected @Nullable ServletConfig config;
@ -125,45 +105,6 @@ public class CometVisuServlet extends HttpServlet {
userFileFolder = new File(OpenHAB.getConfigFolder() + Config.COMETVISU_WEBAPP_USERFILE_FOLDER);
defaultUserDir = System.getProperty("user.dir");
this.cometVisuApp = cometVisuApp;
PHProvider prov = cometVisuApp.getPHProvider();
if (prov != null) {
this.setPHProvider(prov);
}
}
public void setPHProvider(PHProvider prov) {
this.engine = prov;
this.initQuercusEngine();
}
public void unsetPHProvider() {
this.engine = null;
this.phpEnabled = false;
}
private void initQuercusEngine() {
try {
if (this.engine != null) {
this.engine.createQuercusEngine();
this.engine.setIni("include_path", ".:" + rootFolder.getAbsolutePath());
if (servletContext != null) {
this.engine.init(rootFolder.getAbsolutePath(), defaultUserDir, servletContext);
phpEnabled = true;
}
}
} catch (Exception e) {
phpEnabled = false;
}
}
/**
* Returns true if the PHP feature is enabled
*
* @return {boolean}
*/
public boolean isPhpEnabled() {
return phpEnabled;
}
/**
@ -176,25 +117,6 @@ public class CometVisuServlet extends HttpServlet {
if (config != null) {
servletContext = config.getServletContext();
}
// init php service if available
if (this.engine != null) {
this.engine.init(rootFolder.getAbsolutePath(), defaultUserDir, servletContext);
phpEnabled = true;
}
}
/**
* {@inheritDoc}
*
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
@Deprecated
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
File requestedFile = getRequestedFile(req);
processPhpRequest(requestedFile, req, resp);
}
private @Nullable Sitemap getSitemap(String sitemapname) {
@ -250,32 +172,13 @@ public class CometVisuServlet extends HttpServlet {
if (requestedFile.getName().equalsIgnoreCase("hidden.php")) {
// do not deliver the hidden php
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
} else if (path.matches(".*editor/dataproviders/.+\\.(php|json)$")
|| path.matches(".*designs/get_designs\\.php$")) {
dataProviderService(requestedFile, req, resp);
} else if (path.endsWith(rssLogPath)) {
processRssLogRequest(requestedFile, req, resp);
} else if (requestedFile.getName().endsWith(".php")) {
processPhpRequest(requestedFile, req, resp);
} else {
processStaticRequest(requestedFile, req, resp, true);
}
}
@Deprecated
protected void processPhpRequest(File file, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (!this.phpEnabled) {
// try to initialize the php service
initQuercusEngine();
}
if (this.phpEnabled && this.engine != null) {
this.engine.phpService(file, request, response);
} else {
logger.debug("php service is not available please install com.caucho.quercus bundle");
}
}
protected File getRequestedFile(HttpServletRequest req) throws UnsupportedEncodingException {
String requestedFile = req.getPathInfo();
File file = null;
@ -845,175 +748,6 @@ public class CometVisuServlet extends HttpServlet {
}
}
/**
* replaces the dataproviders in
* <cometvisu-src>/editor/dataproviders/*.(php|json) +
*
* @param file
* @param request
* @param response
* @throws ServletException
* @throws IOException
* @deprecated replaced by the CV REST backend in CometVisu versions >=0.12.0
*/
@Deprecated
private final void dataProviderService(File file, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.debug("dataprovider '{}' requested", file.getPath());
List<Object> beans = new ArrayList<>();
String resultString = null;
File resourceFolder = rootFolder;
String rel = file.getPath().substring(rootFolder.getPath().length());
// is CometVisu version >= 0.11 (Qooxdoo based)
if (rel.startsWith("/source/") || rel.startsWith("/build/")) {
// Qooxdoo based CometVisu in source/build mode
// change the folder
String[] parts = rel.substring(1).split("/");
resourceFolder = new File(rootFolder, parts[0] + "/resource");
logger.debug("new resource folder is {}", resourceFolder.getPath());
}
if (file.getName().equals("dpt_list.json")) {
// return all transforms available for openhab
for (Transform transform : Transform.values()) {
DataBean bean = new DataBean();
bean.label = transform.toString().toLowerCase();
bean.value = "OH:" + bean.label;
beans.add(bean);
}
} else if (file.getName().equals("list_all_addresses.php")) {
// all item names
// collect all available transform types
List<String> transformTypes = new ArrayList<>();
for (Transform transform : Transform.values()) {
transformTypes.add(transform.toString().toLowerCase());
}
Map<String, List<Object>> groups = new HashMap<>();
for (Item item : this.cometVisuApp.getItemRegistry().getItems()) {
ItemBean bean = new ItemBean();
bean.value = item.getName();
String type = item.getType();
if ("Group".equals(item.getType())) {
Item baseItem = ((GroupItem) item).getBaseItem();
if (baseItem != null) {
type = baseItem.getType();
} else {
continue;
}
}
bean.label = item.getName();
String transform = type.toLowerCase().replace("Item", "");
if (transformTypes.contains(transform)) {
bean.hints.put("transform", "OH:" + transform);
} else {
logger.debug("no transform type found for item type {}, skipping this item", type);
continue;
}
List<Object> list = groups.get(type);
if (list == null) {
list = new ArrayList<>();
groups.put(type, list);
}
list.add(bean);
}
resultString = marshalJson(groups);
} else if (file.getName().equals("list_all_icons.php")) {
// all item names
File svgFile = new File(resourceFolder, "icon/knx-uf-iconset.svg");
if (svgFile.exists()) {
// extract names from SVG file
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(svgFile);
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//symbol/@id");
NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0, len = nl.getLength(); i < len; i++) {
Node node = nl.item(i);
DataBean bean = new DataBean();
String iconName = node.getTextContent();
if (iconName.startsWith("kuf-")) {
iconName = iconName.substring(4);
}
bean.label = iconName;
bean.value = iconName;
beans.add(bean);
}
} catch (SAXException e) {
logger.error("error parsing SVG file: {}", e.getMessage(), e);
} catch (ParserConfigurationException e) {
logger.error("error extracting items from SVG file: {}", e.getMessage(), e);
} catch (XPathExpressionException e) {
logger.error("error extracting items from SVG file: {}", e.getMessage(), e);
}
} else {
File iconDir = new File(resourceFolder, "icon/knx-uf-iconset/128x128_white/");
if (iconDir.exists() && iconDir.isDirectory()) {
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(@Nullable File dir, @Nullable String name) {
return name != null && name.endsWith(".png");
}
};
File[] icons = iconDir.listFiles(filter);
Arrays.sort(icons);
for (File iconFile : icons) {
if (iconFile.isFile()) {
String iconName = iconFile.getName().replace(".png", "");
DataBean bean = new DataBean();
bean.label = iconName;
bean.value = iconName;
beans.add(bean);
}
}
}
}
} else if (file.getName().equals("list_all_plugins.php")) {
// all plugins
// all item names
File pluginDir = new File(resourceFolder, "plugins/");
File[] plugins = pluginDir.listFiles();
Arrays.sort(plugins);
for (File icon : plugins) {
if (icon.isDirectory()) {
DataBean bean = new DataBean();
bean.label = icon.getName();
bean.value = icon.getName();
beans.add(bean);
}
}
} else if (file.getName().equals("get_designs.php")) {
// all designs
File designDir = new File(resourceFolder, "designs/");
File[] designs = designDir.listFiles();
if (designs != null) {
Arrays.sort(designs);
for (File design : designs) {
if (design.isDirectory()) {
beans.add(design.getName());
}
}
}
} else if (file.getName().equals("list_all_rrds.php")) {
// all item names
}
if (beans.isEmpty() && resultString == null) {
// nothing found try the PHP files
processPhpRequest(file, request, response);
} else {
response.setContentType(MediaType.APPLICATION_JSON);
if (resultString == null) {
resultString = marshalJson(beans);
}
response.getWriter().write(resultString);
response.flushBuffer();
}
}
private String marshalJson(Object bean) {
Gson gson = new Gson();
return gson.toJson(bean);

View File

@ -1,38 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.ui.cometvisu.php;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Tobias Bräutigam - Initial contribution
* @deprecated PHP support in CometVisu backend is deprecated and replaced by native REST API
*/
@Deprecated(since = "3.4", forRemoval = true)
public interface PHProvider {
public void createQuercusEngine();
public void setIni(String key, String value);
public void init(String absolutePath, String defaultUserDir, ServletContext _servletContext);
public void phpService(File file, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException;
}

View File

@ -20,7 +20,6 @@
<module>org.openhab.ui</module>
<module>org.openhab.ui.basic</module>
<module>org.openhab.ui.cometvisu</module>
<module>org.openhab.ui.cometvisu.php</module>
<module>org.openhab.ui.habot</module>
<module>org.openhab.ui.habpanel</module>
<module>org.openhab.ui.iconset.classic</module>