forked from xwikisas/application-admintools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download important files xwikisas#8 - DRAFT
- Loading branch information
1 parent
e9bc0f4
commit 7439f99
Showing
7 changed files
with
427 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
application-admintools-api/src/main/java/com/xwiki/admintools/FilesDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package com.xwiki.admintools; | ||
|
||
import java.util.Map; | ||
|
||
import org.xwiki.component.annotation.Role; | ||
|
||
/** | ||
* Allows data gathering. CREATE AN ABSTRACT CLASS CONTAINING THE SAME FEATURES (adminToolsCfgProvider, templateManager, | ||
* logger)? | ||
* | ||
* @version $Id$ | ||
* @since 1.0 | ||
*/ | ||
@Role | ||
public interface FilesDownloader | ||
{ | ||
/** | ||
* TBC. | ||
* | ||
* @param filter | ||
* @param path | ||
* @return TBC | ||
*/ | ||
Object getLogs(Map<String, String> filter, String path); | ||
|
||
/** | ||
* Extract the hint of a component. | ||
* | ||
* @return component hint | ||
*/ | ||
String getIdentifier(); | ||
} |
64 changes: 64 additions & 0 deletions
64
application-admintools-api/src/main/java/com/xwiki/admintools/rest/AdminToolsRestApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package com.xwiki.admintools.rest; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.xwiki.rest.XWikiRestComponent; | ||
import org.xwiki.rest.XWikiRestException; | ||
|
||
/** | ||
* Provides the APIs needed by the collabora server in order to access a file and it's content, but also to save it. | ||
* | ||
* @version $Id$ | ||
* @since 1.0 | ||
*/ | ||
@Path("/admintools/download") | ||
public interface AdminToolsRestApi extends XWikiRestComponent | ||
{ | ||
/** | ||
* TBC. | ||
* @param type | ||
* @param token | ||
* @return TBC | ||
* @throws XWikiRestException | ||
*/ | ||
@GET | ||
@Path("/configs/{fileType}") | ||
Response getConfigs(@PathParam("fileType") String type, @QueryParam("access_token") String token) | ||
throws XWikiRestException; | ||
|
||
/** | ||
* TBC. | ||
* | ||
* @param type | ||
* @param token | ||
* @return TBC | ||
* @throws XWikiRestException | ||
*/ | ||
@GET | ||
@Path("/logs") | ||
Response getLogs(@PathParam("fileType") String type, @QueryParam("access_token") String token) | ||
throws XWikiRestException; | ||
} |
150 changes: 150 additions & 0 deletions
150
...tools-default/src/main/java/com/xwiki/admintools/internal/downloads/DownloadsManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package com.xwiki.admintools.internal.downloads; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.component.phase.Initializable; | ||
import org.xwiki.component.phase.InitializationException; | ||
|
||
import com.xwiki.admintools.FilesDownloader; | ||
import com.xwiki.admintools.internal.data.identifiers.CurrentServer; | ||
|
||
/** | ||
* Encapsulates functions used for downloading configuration files. | ||
* | ||
* @version $Id$ | ||
* @since 1.0 | ||
*/ | ||
@Component(roles = DownloadsManager.class) | ||
@Singleton | ||
public class DownloadsManager implements Initializable | ||
{ | ||
/** | ||
* TBC. | ||
*/ | ||
@Inject | ||
private CurrentServer currentServer; | ||
|
||
/** | ||
* A list of all the data providers for Admin Tools. | ||
*/ | ||
@Inject | ||
private Provider<List<FilesDownloader>> filesDownloader; | ||
|
||
private String serverPath; | ||
|
||
private String serverType; | ||
|
||
/** | ||
* TBC. | ||
* | ||
* @throws InitializationException | ||
*/ | ||
@Override | ||
public void initialize() throws InitializationException | ||
{ | ||
Map<String, String> identifiers = currentServer.getServerIdentifiers(); | ||
serverPath = identifiers.get("serverPath"); | ||
serverType = identifiers.get("serverType"); | ||
} | ||
|
||
/** | ||
* TBC. | ||
* | ||
* @param fileType TBC. | ||
* @return TBC. | ||
* @throws IOException | ||
*/ | ||
public byte[] downloadXWikiFile(String fileType) throws IOException | ||
{ | ||
return prepareFile(fileType); | ||
} | ||
|
||
/** | ||
* TBC. | ||
* | ||
* @param filters TBC | ||
* @return TBC | ||
*/ | ||
public Object downloadLogs(Map<String, String> filters) | ||
{ | ||
return callLogsDownloader(serverType + "Logs", filters); | ||
} | ||
|
||
/** | ||
* As all servers have the same path to the xwiki properties and configuration files, it is not needed to call this | ||
* function in a server specific class. | ||
* | ||
* @param type | ||
* @return | ||
* @throws IOException | ||
*/ | ||
private byte[] prepareFile(String type) throws IOException | ||
{ | ||
String filePath = serverPath; | ||
if (Objects.equals(type, "properties")) { | ||
filePath += "/webapps/xwiki/WEB-INF/xwiki.properties"; | ||
} else { | ||
filePath += "/webapps/xwiki/WEB-INF/xwiki.cfg"; | ||
} | ||
File inputFile = new File(filePath); | ||
|
||
BufferedReader reader = new BufferedReader(new FileReader(inputFile)); | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
|
||
String currentLine; | ||
List<String> wordsList = new ArrayList<>( | ||
Arrays.asList("xwiki.authentication.validationKey", "xwiki.authentication.encryptionKey", | ||
"xwiki.superadminpassword", "extension.repositories.privatemavenid.auth", "mail.sender.password")); | ||
while ((currentLine = reader.readLine()) != null) { | ||
String trimmedLine = currentLine.trim(); | ||
if (wordsList.stream().anyMatch(trimmedLine::contains)) { | ||
continue; | ||
} | ||
stringBuilder.append(currentLine).append(System.getProperty("line.separator")); | ||
} | ||
reader.close(); | ||
return stringBuilder.toString().getBytes(); | ||
} | ||
|
||
private Object callLogsDownloader(String hint, Map<String, String> filter) | ||
{ | ||
for (FilesDownloader specificFilesDownloader : this.filesDownloader.get()) { | ||
if (specificFilesDownloader.getIdentifier().equals(hint)) { | ||
return specificFilesDownloader.getLogs(filter, serverPath); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...-default/src/main/java/com/xwiki/admintools/internal/downloads/TomcatFilesDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package com.xwiki.admintools.internal.downloads; | ||
|
||
import java.util.Map; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
|
||
import com.xwiki.admintools.FilesDownloader; | ||
|
||
/** | ||
* Encapsulates functions used for downloading configuration files. | ||
* | ||
* @version $Id$ | ||
* @since 1.0 | ||
*/ | ||
@Component(roles = TomcatFilesDownloader.class) | ||
@Named(TomcatFilesDownloader.HINT) | ||
@Singleton | ||
public class TomcatFilesDownloader implements FilesDownloader | ||
{ | ||
/** | ||
* The hint for the component. | ||
*/ | ||
public static final String HINT = "tomcatLogs"; | ||
|
||
/** | ||
* @param filter | ||
* @return | ||
*/ | ||
@Override | ||
public Object getLogs(Map<String, String> filter, String path) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getIdentifier() | ||
{ | ||
return HINT; | ||
} | ||
} |
Oops, something went wrong.