Commit 289650a0 authored by Frank Bergmann's avatar Frank Bergmann

- import

parent 72cc7ce0
Pipeline #1011 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PO-Timesheet</name>
<comment>
]project-open[ Time Sheet is a light weight desktop time sheet
logging application written in Java. ]po[ Time Sheet is designed
to work with the ]project-open[ project management on the server
side for managing the project hierarchy, advanced reporting,
billing and financials.
</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PO-Timesheet</name>
<comment>
]project-open[ Time Sheet is a light weight desktop time sheet
logging application written in Java. ]po[ Time Sheet is designed
to work with the ]project-open[ project management on the server
side for managing the project hierarchy, advanced reporting,
billing and financials.
</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
</natures>
</projectDescription>
This diff is collapsed.
#--- User account to access ]project-open[ server ---
#Fri May 21 16:01:37 CEST 2010
port=
password=ben
email=bbigboss@tigerpond.com
server=http\://po34demo.project-open.net
#--- Parameters to access a ]project-open[ server ---
#Tue Sep 20 22:53:24 CEST 2016
password=ben
email=bbigboss@tigerpond.com
server=http\://192.168.52.128
;NSIS Modern User Interface version 1.70
;PO-Timesheet Installer Script
;Autors: Stephen Strenn and Frank Bergmann
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;--------------------------------
;General
;Name and file
Name "PO-Timesheet"
OutFile "PO-Timesheet.exe"
;Default installation folder
InstallDir "$PROGRAMFILES\Project Open\PO-Timesheet"
;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\PO-Timesheet" ""
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
!define MUI_HEADERIMAGE "C:\eclipse\PO-Timesheet\images\project-open.149x49.bmp"
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
!define MUI_HEADERIMAGE_BITMAP "C:\eclipse\PO-Timesheet\images\project-open.149x49.bmp"
!define MUI_ICON "C:\eclipse\PO-Timesheet\images\setup.ico"
!define MUI_UNICON "C:\eclipse\PO-Timesheet\images\setup.ico"
;--------------------------------
;Pages
!insertmacro MUI_PAGE_LICENSE "C:\eclipse\PO-Timesheet\License.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section "PO-Timesheet (required)" SecDummy
SectionIn RO
SetOutPath "$INSTDIR"
File "C:\eclipse\PO-Timesheet.jar"
File "C:\eclipse\PO-Timesheet\images\po-timesheet.ico"
; File "C:\eclipse\PO-Timesheet\swt-win32-3138.dll"
SetOutPath "$INSTDIR\lib"
; File "C:\eclipse\PO-Timesheet\lib\org.eclipse.swt.win32.win32.x86_3.1.0.jar"
SetOutPath "$INSTDIR"
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\PO-Timesheet "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PO-Timesheet" "DisplayName" "PO-Timesheet"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PO-Timesheet" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PO-Timesheet" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PO-Timesheet" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\PO-Timesheet"
CreateShortCut "$SMPROGRAMS\PO-Timesheet\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe"
CreateShortCut "$SMPROGRAMS\PO-Timesheet\PO-Timesheet.lnk" "$INSTDIR\PO-Timesheet.jar" "" "$INSTDIR\po-timesheet.ico"
SectionEnd
;--------------------------------
;Uninstaller Section
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PO-Timesheet"
DeleteRegKey HKLM SOFTWARE\PO-Timesheet
DeleteRegKey /ifempty HKCU "Software\PO-Timesheet"
; Remove shortcuts
RMDir /r "$SMPROGRAMS\PO-Timesheet"
; Remove directories used
RMDir /r "$INSTDIR"
SectionEnd
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Manifest-Version: 1.0
Main-Class: org.projectopen.timesheet.TrayIconStarter
Class-Path: PO-Timesheet.jar
package org.projectopen.dynfield;
/**
* This class represents values of a ComboBox.
* In ]project-open[ we identify every object
* uniquely with an integer ID, while object
* names may include duplicates etc.
*
* @author fraber
*
*/
public class ComboBoxValue {
private int id = 0;
private Object object = null;
public ComboBoxValue(Object o, int id) {
this.id = id;
this.object = o;
}
public String toString() { return object.toString(); }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public Object getObject() { return object; }
public void setObject(Object object) { this.object = object; }
}
package org.projectopen.dynfield;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import org.projectopen.debug.DomPrinter;
import org.projectopen.debug.Logger;
import org.projectopen.rest.*;
@SuppressWarnings("unchecked")
public class ProjopDynfieldAttribute extends ProjopObject {
private static Hashtable objectTypeAttributes = new Hashtable();
public ProjopDynfieldAttribute() {
super("user");
}
/**
* Returns an ordered list of ProjopDynfieldAttribute objects
* for the given object type.
*
* @param objectType The ]po[ object type to look for
* @return A list of ProjopDynfieldAttribute objects.
*/
public static List getAttributesFromObjectType(String objectType) {
RESTClient rest = RESTClient.defaultInstance();
List attributes = (List)objectTypeAttributes.get(objectType);
if (null == attributes) {
String query = "object_type = '"+objectType+"'";
attributes = rest.fromQuery("im_dynfield_attribute", query);
objectTypeAttributes.put(objectType, attributes);
}
return attributes;
}
public String toString() {
String name = get("username");
if (name == null) { name = super.toString(); }
return name;
}
}
package org.projectopen.dynfield;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import org.projectopen.debug.DomPrinter;
import org.projectopen.debug.Logger;
import org.projectopen.rest.ProjopObject;
import org.projectopen.rest.ProjopObjectType;
import org.projectopen.rest.RESTClient;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
public class ProjopDynfieldWidget extends ProjopObject {
public ProjopDynfieldWidget() {
super("user");
}
public String toString() {
String name = get("username");
if (name == null) { name = super.toString(); }
return name;
}
@SuppressWarnings("unchecked")
public static ProjopObject getWidgetFromName(String widgetName) {
// the object type "responsible" for Dynfield Widget
ProjopObjectType dynfieldWidgetType = ProjopObjectType.getObjectType("im_dynfield_widget");
TreeMap instances = dynfieldWidgetType.getInstances();
Iterator iter = instances.values().iterator();
while (iter.hasNext()) {
ProjopObject o = (ProjopObject)iter.next();
String name = o.get("widget_name");
if (widgetName.equals(name)) { return o; }
}
return null;
}
/**
* Retreive the values of a DynField widget.
*
* @param widgetName The name of a DynField Widget
* @return A List of ComboBoxValues representing
* the options for the widget.
*/
public static List<String> restListDynfieldWidgetValues(String widgetName) {
RESTClient rest = RESTClient.defaultInstance();
TreeMap widgets = ProjopObjectType.getObjectType("im_dynfield_widget").getInstances();
Iterator iter = widgets.values().iterator();
ProjopObject widget = null;
while (iter.hasNext()) {
ProjopObject attr = (ProjopObject)iter.next();
if (widgetName.equals(attr.get("widget_name"))) {
widget = attr;
}
}
if (null == widget) {
rest.logMessage(Logger.ERROR, "Dynfield Widgets", "Didn't find widget with name "+widgetName, "");
return null;
}
int widgetId = Integer.parseInt(widget.get("widget_id"));
Document dom = null;
List groups = new ArrayList();
try {
String urlPath = "/intranet-rest/dynfield-widget-values?widget_id="+widgetId+"&format=json";
dom = rest.httpRequest("GET", urlPath, null);
} catch (Exception e) {
e.printStackTrace();
}
// Get the root element
Element docEle = dom.getDocumentElement();
// Iterate through the list of <row> entries,
// adding the data to the list of projects.
NodeList nl = docEle.getElementsByTagName("value");
if(nl != null && nl.getLength() > 0) {
for(int i = 0 ; i < nl.getLength();i++) {
Element el = (Element)nl.item(i);
int type = el.getNodeType();
DomPrinter.walk(el);
// skip everything except for element nodes ("real" nodes).
if (type != Node.ELEMENT_NODE) { continue; }
String value = el.getTextContent();
String key = el.getAttribute("key");
int keyInt = Integer.parseInt(key);
// System.out.println("v="+value+", n="+name+", k="+key);
ComboBoxValue v = new ComboBoxValue(value, keyInt);
groups.add(v);
}
}
rest.logMessage(Logger.INFO, "RESTClient.restListGroups()", "List all groups in the ]po[ system", groups.toString());
return groups;
}
}
package org.projectopen.rest;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.net.URLEncoder;
import java.util.*;
import org.json.simple.JSONObject;
import org.projectopen.debug.DomPrinter;
import org.projectopen.debug.Logger;
import org.w3c.dom.*;
@SuppressWarnings("unchecked")
public class ProjopCategory extends ProjopObject {
private static Hashtable<String,List<ProjopObject>> categoriesPerType = new Hashtable<String,List<ProjopObject>>();
public ProjopCategory() {
super("im_category");
}
/**
* Converts a list of ProjopCategory objects into an
* array of category strings suitable for a combo box.
*
* @return An array of formatted categories, suitable
* to be used in the JComboBox constructor.
*/
public static Object[] comboBoxCategories(String categoryType) {
List<ProjopObject> categories = ProjopCategory.getCategoryObjectsFromType(categoryType);
Iterator<ProjopObject> iter = categories.iterator();
ArrayList<String> categoryStrings = new ArrayList<String>();
while (iter.hasNext()) {
ProjopCategory cat = (ProjopCategory)iter.next();
String s = cat.get("category");
int level = cat.get("tree_sortkey").length() / 8 - 1;
for (int i = 0; i < level; i++) { s = " "+s; }
categoryStrings.add(s);
}
return categoryStrings.toArray();
}
/**
* Get the list of categories for a given category type.
* Example: "Intranet Project Status" returns "Open", "Closed", ...
* @param categoryType The ]po[ category type.
* @return A List of ProjopCategory objects.
*/
public static List<ProjopObject> getCategoryObjectsFromType(String categoryType) {
RESTClient rest = RESTClient.defaultInstance();
// Check the cache
List<ProjopObject> categories = categoriesPerType.get(categoryType);
if (null == categories) {
// Nothing found in the cache - load from REST
List<ProjopObject> categoryObjectList = new ArrayList<ProjopObject>();
String categoryTypeEncoded = null;
try {
categoryTypeEncoded = URLEncoder.encode("'"+categoryType+"'", "UTF-8");
} catch (Exception e) { }
String urlPath = "/intranet-reporting/view?format=json&report_code=rest_category_type&category_type="+categoryTypeEncoded;
categories = rest.fromURL("im_category", urlPath);
rest.logMessage(Logger.INFO, "RESTClient.restListCategories()", "List a category type", categories.toString());
// Write into cache
categoriesPerType.put(categoryType, categories);
}
return categories;
}
/**
* Return the category_id of the input variable.
* The input can either be a
* @param o
* @return
*/
public static int categoryIdFromCategory(String categoryType, Object o) {
RESTClient rest = RESTClient.defaultInstance();
if (null == o || null == categoryType) { return 0; }
if (String.class != o.getClass()) {
rest.logMessage(Logger.ERROR, "GUI", "Calling categoryIdFromCategory with a non-string object", o.toString());
return 0;
}
String searchString = o.toString().trim();
if (null == searchString) { return 0; }
List<ProjopObject> categories = getCategoryObjectsFromType(categoryType);
Iterator<ProjopObject> iter = categories.iterator();
while (iter.hasNext()) {
ProjopObject cat = (ProjopObject)iter.next();
String type = cat.get("category_type");
if (!categoryType.equals(type)) { continue; }
if (!searchString.equals(cat.get("category"))) { continue; }
return cat.getObjectId();
}
return 0;
}
}
package org.projectopen.rest;
import java.util.List;
import org.projectopen.debug.Logger;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
/**
* Represents a ]project-open[ group object.
*/
public class ProjopGroup extends ProjopObject {
public ProjopGroup() {
super("group");
}
public String toString() {
String name = get("group_name");
if (name == null) { name = super.toString(); }
return name;
}
/**
* Query the REST server for the list of available groups in the system.
*
* @return List of ProjopObjects representing the current ]po[ groups.
*/
public List<ProjopObject> fromAll() {
RESTClient rest = RESTClient.defaultInstance();
List<ProjopObject> groups = rest.fromQuery("group", "");
rest.logMessage(Logger.INFO, "RESTClient.restListGroups()", "List all groups in the ]po[ system", groups.toString());
return groups;
}
}
package org.projectopen.rest;
import java.util.List;
import org.json.simple.JSONObject;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
public class ProjopHour extends ProjopObject {
public ProjopHour() {
super("im_hour");
}
public ProjopHour(JSONObject el) {
super("im_hour", el); // ]po[ name of this object type
}
/**
* Query the REST server the hours logged by the current user today.
* @return A list of ProjectHour objects
*/
public static List<ProjopObject> fromToday() {
RESTClient rest = RESTClient.defaultInstance();
String urlPath = "/intranet-reporting/view?format=json&report_code=rest_my_hours";
return rest.fromURL("im_hour", urlPath);
}
}
This diff is collapsed.
package org.projectopen.rest;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.util.*;
public class ProjopObjectType extends ProjopObject {
// A cache for object types, so that every object type
// only exists once in the system.
private static Hashtable<String,ProjopObjectType> objectTypes = new Hashtable<String,ProjopObjectType>();
// Parent object type. "acs_object" is the root of all object
// types. Only acs_objects has NULL as parentObjectType.
private ProjopObjectType parentObjectType = null;
// List of object types that are inheriting from this one.
private Vector<ProjopObjectType> childObjectTypes = new Vector<ProjopObjectType>();
// Sorted list of objects of this object type.
private TreeMap<Integer,ProjopObject> instances = null;
// A sorted vector of children, so that the ObjectBrowser
// can show them as a sorted list.
private Vector<ProjopObjectType> childrenForObjectBrowser = null;
// A list of variables available in the an arbitrary
// first element of this object type.
private ArrayList<String> varList = null;
public ProjopObjectType() {
super("acs_object_type");
}
/**
* Returns an ordered list of all variable names
* available for this object type. The order of the
* variables is arbitrary at the moment. In the future
* this should be replaced by data from DynFields.
* @return
*/
public ArrayList<String> getVarList() {
if (null == varList) {
varList = new ArrayList<String>();
Object firstKey = this.getInstances().firstKey();
Object first = this.instances.get(firstKey);
ProjopObject o = (ProjopObject)first;
Hashtable<String,String> vars = o.getVars();
Enumeration<String> keys = vars.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
varList.add(key);
}
}
return varList;
}
public static Hashtable<String,ProjopObjectType> getObjectTypes() { return objectTypes; }
public static ProjopObjectType getObjectType(String objectType) {
if (null == objectTypes.get(objectType)) {
ProjopObjectType t = new ProjopObjectType();
t.set("object_type",objectType);
objectTypes.put(objectType, t);
}
return (ProjopObjectType)objectTypes.get(objectType);
}
public ProjopObjectType getParentObjectType() { return parentObjectType; }
public void setParentType(ProjopObjectType parentType) { this.parentObjectType = parentType; }
public void setChildTypes(Vector<ProjopObjectType> childTypes) { this.childObjectTypes = childTypes; }
public Vector<ProjopObjectType> getChildObjectTypes() { Collections.sort(childObjectTypes); return childObjectTypes; }
public void set(String varName, String value) {
super.set(varName, value);
// Add this object to the list of object types
// to maintain a global cache
if ("object_type" == varName) {
objectTypes.put(value, this);
}
}
public TreeMap<Integer,ProjopObject> getInstances() {
RESTClient rest = RESTClient.defaultInstance();
if (null == instances) {
// Get the list of instances
List<ProjopObject> is = null;
String objectTypeString = this.get("object_type");
if ("acs_object_type" != objectTypeString) {
is = rest.fromQuery(objectTypeString, "");
}
// Setup the new instanceHash
instances = new TreeMap<Integer,ProjopObject>();
if (null != is) {
Iterator<ProjopObject> e = is.iterator();
while(e.hasNext()) {
ProjopObject o = (ProjopObject)e.next();
Integer i = new Integer(o.getObjectId());
instances.put(i, o);
}
}
}
return instances;
}
/**
* Return an ordered list of children suitable for
* being displayed in the ObjectBrowserTreeModel.
* @return A list of 1) sub-object types and 2)
* of instance objects.
*/
public List<ProjopObjectType> getChildrenForObjectBrowser() {
if (null == childrenForObjectBrowser) {
// clone the child object types
childrenForObjectBrowser = new Vector<ProjopObjectType>(getChildObjectTypes());
}
return childrenForObjectBrowser;
}
public String toString() {
String name = this.get("pretty_name");
if (null == name || "" == name) { name = this.get("object_type"); }
return name;
}
}
package org.projectopen.rest;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.util.*;
import org.json.simple.*;
// @SuppressWarnings("unchecked")
/**
* Class representing a ]po[ Project.
* Values are stored in a key-value list, so the object adapts
* to whatever attributes the REST interface returns.
* Values are stored as strings using TCL string representation,
* independent from the actual type. Convenient...
*/
public class ProjopProject extends ProjopObject {
public ProjopProject() {
super("im_project"); // ]po[ name of this object type
}
public ProjopProject(JSONObject el) {
super("im_project", el); // ]po[ name of this object type
}
public String toString() {
String name = get("project_name");
if (name == null) { name = super.toString(); }
return name;
}
/**
* Query the REST server for a list projects available for
* timesheet logging
*
* @return A list of ProjopHour objects representing the hours
* logged today.
*/
public static List<ProjopObject> myTimesheetProjects() {
RESTClient rest = RESTClient.defaultInstance();
String urlPath = "/intranet-reporting/view?format=json&report_code=rest_my_timesheet_projects";
return rest.fromURL("im_project", urlPath);
}
}
package org.projectopen.rest;
import java.util.List;
import org.projectopen.debug.Logger;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program 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 General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
/**
* Represents a ]project-open[ user object.
*/
public class ProjopUser extends ProjopObject {
public ProjopUser() {
super("user");
}
public String toString() {
String name = get("username");
if (name == null) { name = super.toString(); }
return name;
}
/**
* What is the ]po[ userId of the user that is logged in?
* This function asks the REST server, based on the email
* of the login credentials.
* However, the RESTClient contains a cached version of this
* ID which it gets during intialization, so you probably
* never have to call this function.
*
* @return userId of the user currently logged into the REST interface.
*/
public static int getMyUserIdFromServer() {
int userId = -1;
RESTClient client = RESTClient.defaultInstance();
String email = client.getProperties().getProperty("email");
ProjopObject user = ProjopUser.fromEmail(email);
if (null != user) {
userId = Integer.parseInt(user.get("user_id"));
}
return userId;
}
/**
* Retrieve all information about a ]po[ specific user, identified
* by the user's email (which is unique in ]po[).
*
* @param email The email of a ]po[ user
* @return a ProjopObject of type "user" with everything about the user.
*/
public static ProjopObject fromEmail(String email) {
RESTClient client = RESTClient.defaultInstance();
client.logMessage(Logger.INFO, "RESTClient.restReadUserFromEmail("+email+")", "Query the REST server for a user with the specified email", "");
List<ProjopObject> objects = client.fromQuery("user", "email = '"+email+"'");
if (objects == null) { return null; }
if (objects.isEmpty()) { return null; }
ProjopObject o = objects.get(0);
client.logMessage(Logger.INFO, "RESTClient.restReadUserFromEmail("+email+")", "Query the REST server for a user with the specified email", o.toString());
return o;
}
}
This diff is collapsed.
/**
*
*/
package org.projectopen.serverstatus;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import org.projectopen.debug.*;
/**
* @author fraber
*
*/
public class ServicePanel extends JPanel implements Logger {
/**
*
*/
private static final long serialVersionUID = 6360295344991781929L;
private static Logger logger = null;
public ServicePanel(Map map) {
// Setup the panel
super();
this.setLayout(new FlowLayout(FlowLayout.CENTER, 7, 7)); // alignment, horizontal gap and vertical gap
// Set transparent background
this.setOpaque(false);
// Extract the interesting values from the map
String serviceName = map.containsKey("service_name") ? (String)map.get("service_name") : "";
String toolTipText = map.containsKey("service_tooltip") ? (String)map.get("service_tooltip") : "";
String installStatus = map.containsKey("installed_status") ? (String)map.get("installed_status") : "clear";
String processStatus = map.containsKey("process_status") ? (String)map.get("process_status") : "clear";
String portStatus = map.containsKey("port_status") ? (String)map.get("port_status") : "clear";
String logStatus = map.containsKey("log_status") ? (String)map.get("log_status") : "clear";
// calculate service status as a summary of individual states
String serviceStatus = "green";
if ("orange" == installStatus | "orange" == processStatus | "orange" == portStatus | "orange" == logStatus) { serviceStatus = "orange"; }
if ("red" == installStatus | "red" == processStatus | "red" == portStatus | "red" == logStatus) { serviceStatus = "red"; }
// Status + Service Description
ImageIcon imageIcon = new ImageIcon(ServicesPanel.class.getResource("/org/projectopen/serverstatus/" + serviceStatus + ".100.gif"));
JLabel serivceLabel = new JLabel(imageIcon);
serivceLabel.setToolTipText(toolTipText);
serivceLabel.setText(serviceName);
serivceLabel.setHorizontalTextPosition(JLabel.CENTER);
serivceLabel.setVerticalTextPosition(JLabel.CENTER);
this.add(serivceLabel);
// Install Status
imageIcon = new ImageIcon(ServicesPanel.class.getResource("/org/projectopen/serverstatus/bb_" + installStatus + ".gif"));
JLabel installLabel = new JLabel(imageIcon);
this.add(installLabel);
// Process Status
imageIcon = new ImageIcon(ServicesPanel.class.getResource("/org/projectopen/serverstatus/bb_" + processStatus + ".gif"));
JLabel processLabel = new JLabel(imageIcon);
this.add(processLabel);
// Port Status
imageIcon = new ImageIcon(ServicesPanel.class.getResource("/org/projectopen/serverstatus/bb_" + portStatus + ".gif"));
JLabel portLabel = new JLabel(imageIcon);
this.add(portLabel);
// log Status
imageIcon = new ImageIcon(ServicesPanel.class.getResource("/org/projectopen/serverstatus/bb_" + logStatus + ".gif"));
JLabel logLabel = new JLabel(imageIcon);
this.add(logLabel);
}
/* (non-Javadoc)
* @see org.projectopen.debug.Logger#logMessage(int, java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void logMessage(int level, String domain, String message,
String details) {
// TODO Auto-generated method stub
}
/**
* @param args
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) {
HashMap map = new HashMap();
map.put("service_name", "AOLserver");
map.put("service_status", "green");
map.put("port_status", "yellow");
map.put("process_status", "green");
map.put("port_status", "yellow");
// Launch a frame with the panel
JFrame frame = new JFrame("Single Service Panel");
frame.setBounds(0, 0, 400, 300);
JPanel p = new ServicePanel(map);
frame.getContentPane().add(p);
frame.setVisible(true);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
*
*/
/**
* @author fraber
*
*/
package org.projectopen.serverstatus;
\ No newline at end of file
package org.projectopen.winservice;
import java.io.*;
import java.net.*;
public class WinClient {
private Socket socket = null;
private PrintWriter out = null;
private BufferedReader in = null;
private boolean connectionOpen = false;
private String serverResponse = null;
private String serverReturnCodeString = null;
private int serverReturnCode = 0;
public WinClient() {
try {
socket = new Socket("localhost", WinService.winServiceSocket);
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
connectionOpen = true;
} catch (UnknownHostException e) {
System.err.println("Unable to get name for 'localhost'");
} catch (IOException e) {
System.err.println("Unable to connect to 'localhost' with port " + WinService.winServiceSocket);
}
}
/**
* Destructor: Close the connection if still open.
*/
protected void finalize() throws Throwable {
this.close();
}
/**
* Close the connection if open
*/
public void close() {
if (connectionOpen) {
try {
out.close();
in.close();
socket.close();
} catch (Exception e) {
System.err.println("Error closing connection");
System.exit(1);
}
}
}
public boolean isOpen() { return connectionOpen; }
public PrintWriter getOut() { return out; }
public BufferedReader getIn() { return in; }
public String getServerResponse() { return serverResponse; }
public int getReturnCode() {
int colonPos = serverReturnCodeString.indexOf(":");
String returnCodeString = serverReturnCodeString.substring(colonPos+2);
return new Integer(returnCodeString).intValue();
}
/**
* Execute a command on the server side
*/
public String exec(String cmdLine) {
StringBuffer output = new StringBuffer();
String line = null;
// return an error indicator if not open
if (!connectionOpen) { return null; }
try {
// Send input server
this.getOut().println(cmdLine);
// Wait until the reply gets ready
do {
try {
Thread.sleep(10);
} catch(InterruptedException e) { }
} while (!"".equals(cmdLine) && !this.getIn().ready());
// Read until all text has been read
int ctr = 0;
while (this.getIn().ready()) {
line = in.readLine();
if (0 == ctr) {
serverReturnCodeString = line;
} else {
output.append(line).append("\n");
}
ctr++;
}
} catch (IOException e) { }
// Return the result
serverResponse = output.toString();
return serverResponse;
}
/**
* Testing function with manual client.
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
WinClient client = new WinClient();
String userInput;
do {
// Get one line of input
userInput = stdIn.readLine();
String output = client.exec(userInput);
int returnCode = client.getReturnCode();
System.out.println("Return Code = " + returnCode);
System.out.println("Output = " + output);
} while (userInput != null && !"".equals(userInput));
client.close();
stdIn.close();
}
}
package org.projectopen.winservice;
import java.net.*;
import java.io.*;
import java.security.*;
/**
* Windows service listening on port 7999 for command lines.
* The service executes these command lines if they comply
* with the patters of permissible lines.
*
* This service is designed to be run with "elevated" admin
* permission in order to start and stop the ]po[ services
* "aolserver-projop" and "postgresql-8.4". This way we can
* run the po-service-monitor.jar application with user
* permissions and interacting with the TrayIcon while executing
* certain admin actions for starting and stopping Win
* services.
*
* @author frank.bergmann@project-open.com
*
*/
public class WinService {
public static int winServiceSocket = 7999;
/**
* Main server routine:
*
* Listen for incoming connections and execute them
* in the same thread. We don't need to spawn new threads
* for occasionally executing a command string.
*/
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
boolean running = true;
try {
serverSocket = new ServerSocket(winServiceSocket);
Socket socket;
while(running) {
socket = serverSocket.accept();
ConnectionServer connection = new ConnectionServer(socket);
Thread t = new Thread(connection);
t.start();
}
} catch (IOException e) {
System.out.println("IOException on socket listen: " + e);
e.printStackTrace();
}
serverSocket.close();
}
}
class ConnectionServer implements Runnable {
private Socket connection;
WinServiceProtocol protocol = new WinServiceProtocol();
ConnectionServer(Socket serverConnection) {
this.connection = serverConnection;
}
public void run () {
String input = "";
String output = "";
try {
// Get input from the client
DataInputStream in = new DataInputStream (connection.getInputStream());
PrintStream out = new PrintStream(connection.getOutputStream());
// Read exactly one line
input = in.readLine();
while (input != null && !"".equals(input)) {
System.out.println("Overall message is:" + input);
// Process protocol
output = protocol.process(input);
// Now write to the client
out.println(output);
// read the next line
input = in.readLine();
}
// close the connection
connection.close();
} catch (IOException ioe) {
System.out.println("IOException on socket listen: " + ioe);
ioe.printStackTrace();
}
}
}
package org.projectopen.winservice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.projectopen.debug.Logger;
/**
* Simple protocol implementation for executing command lines
* with elevated Windows permissions.
*
* The ]po[ Service Manager needs this background services
* in order to start or stop ]po[ services while operating
* as a non-elevated TrayIcon program with user level permissions.
*
* @author frank.bergmann@project-open.com
*
*/
public class WinServiceProtocol {
/**
* Main and only action of the Protocol:
* Check if the command line adheres to security constraints,
* execute and send the command line output back to the client.
* @param cmdLine A command line to execute
* @return The output of the command line
*/
public String process(String cmdLine) {
if (cmdLine.isEmpty()) { return "Return Code: 0"; }
Pattern p = Pattern.compile("^sc .*");
Matcher m = p.matcher(cmdLine);
if (!m.find()) {
System.out.println("Security: Somebody tries to fiddle with system security: cmdLine=" + cmdLine);
return "Return Code: -1";
}
String line = null;
Process process = null;
int returnCode = -1;
StringBuffer errorMessageBuffer = new StringBuffer();
try {
process = Runtime.getRuntime().exec(cmdLine);
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()), 13107200);
while ((line = input.readLine()) != null) {
if (0 == line.length()) { continue; }
errorMessageBuffer.append(line).append("\n");
}
try {
returnCode = process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
return "Return Code: " + returnCode + "\n" + errorMessageBuffer;
}
}
/**
*
*/
/**
* @author fraber
*
*/
package org.projectopen.winservice;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment