From 84adefa331c4159d432d22840663c38f155cd4c1 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Fri, 20 Nov 2009 14:54:40 +0000 Subject: The R13B03 release. --- lib/webtool/AUTHORS | 4 + lib/webtool/Makefile | 38 + lib/webtool/doc/html/.gitignore | 0 lib/webtool/doc/man1/.gitignore | 0 lib/webtool/doc/man3/.gitignore | 0 lib/webtool/doc/pdf/.gitignore | 0 lib/webtool/doc/src/Makefile | 127 +++ lib/webtool/doc/src/book.xml | 47 + lib/webtool/doc/src/fascicules.xml | 18 + lib/webtool/doc/src/make.dep | 20 + lib/webtool/doc/src/notes.xml | 112 +++ lib/webtool/doc/src/notes_history.xml | 73 ++ lib/webtool/doc/src/part.xml | 37 + lib/webtool/doc/src/part_notes.xml | 39 + lib/webtool/doc/src/part_notes_history.xml | 39 + lib/webtool/doc/src/ref_man.xml | 38 + lib/webtool/doc/src/start_webtool.xml | 103 ++ lib/webtool/doc/src/webtool.xml | 156 +++ lib/webtool/doc/src/webtool_chapter.xml | 248 +++++ lib/webtool/ebin/.gitignore | 0 lib/webtool/info | 2 + lib/webtool/priv/Makefile | 77 ++ lib/webtool/priv/bin/start_webtool | 3 + lib/webtool/priv/bin/start_webtool.bat | 2 + lib/webtool/priv/root/conf/mime.types | 99 ++ lib/webtool/priv/root/doc/index.html | 11 + lib/webtool/priv/root/doc/start_info.html | 28 + lib/webtool/priv/root/doc/tool_management.html | 9 + lib/webtool/src/Makefile | 97 ++ lib/webtool/src/webtool.app.src | 25 + lib/webtool/src/webtool.appup.src | 19 + lib/webtool/src/webtool.erl | 1205 ++++++++++++++++++++++++ lib/webtool/src/webtool_sup.erl | 74 ++ lib/webtool/vsn.mk | 2 + 34 files changed, 2752 insertions(+) create mode 100644 lib/webtool/AUTHORS create mode 100644 lib/webtool/Makefile create mode 100644 lib/webtool/doc/html/.gitignore create mode 100644 lib/webtool/doc/man1/.gitignore create mode 100644 lib/webtool/doc/man3/.gitignore create mode 100644 lib/webtool/doc/pdf/.gitignore create mode 100644 lib/webtool/doc/src/Makefile create mode 100644 lib/webtool/doc/src/book.xml create mode 100644 lib/webtool/doc/src/fascicules.xml create mode 100644 lib/webtool/doc/src/make.dep create mode 100644 lib/webtool/doc/src/notes.xml create mode 100644 lib/webtool/doc/src/notes_history.xml create mode 100644 lib/webtool/doc/src/part.xml create mode 100644 lib/webtool/doc/src/part_notes.xml create mode 100644 lib/webtool/doc/src/part_notes_history.xml create mode 100644 lib/webtool/doc/src/ref_man.xml create mode 100644 lib/webtool/doc/src/start_webtool.xml create mode 100644 lib/webtool/doc/src/webtool.xml create mode 100644 lib/webtool/doc/src/webtool_chapter.xml create mode 100644 lib/webtool/ebin/.gitignore create mode 100644 lib/webtool/info create mode 100644 lib/webtool/priv/Makefile create mode 100755 lib/webtool/priv/bin/start_webtool create mode 100644 lib/webtool/priv/bin/start_webtool.bat create mode 100644 lib/webtool/priv/root/conf/mime.types create mode 100644 lib/webtool/priv/root/doc/index.html create mode 100644 lib/webtool/priv/root/doc/start_info.html create mode 100644 lib/webtool/priv/root/doc/tool_management.html create mode 100644 lib/webtool/src/Makefile create mode 100644 lib/webtool/src/webtool.app.src create mode 100644 lib/webtool/src/webtool.appup.src create mode 100644 lib/webtool/src/webtool.erl create mode 100644 lib/webtool/src/webtool_sup.erl create mode 100644 lib/webtool/vsn.mk (limited to 'lib/webtool') diff --git a/lib/webtool/AUTHORS b/lib/webtool/AUTHORS new file mode 100644 index 0000000000..5f173dd264 --- /dev/null +++ b/lib/webtool/AUTHORS @@ -0,0 +1,4 @@ +Original Authors and Contributors: + +Siri Hansen +Martin Gustafsson diff --git a/lib/webtool/Makefile b/lib/webtool/Makefile new file mode 100644 index 0000000000..27c1986213 --- /dev/null +++ b/lib/webtool/Makefile @@ -0,0 +1,38 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2001-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Common Macros +# ---------------------------------------------------- + +SUB_DIRECTORIES = src priv doc/src + +include vsn.mk +VSN = $(WEBTOOL_VSN) + +SPECIAL_TARGETS = + +# ---------------------------------------------------- +# Default Subdir Targets +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_subdir.mk + + diff --git a/lib/webtool/doc/html/.gitignore b/lib/webtool/doc/html/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/webtool/doc/man1/.gitignore b/lib/webtool/doc/man1/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/webtool/doc/man3/.gitignore b/lib/webtool/doc/man3/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/webtool/doc/pdf/.gitignore b/lib/webtool/doc/pdf/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/webtool/doc/src/Makefile b/lib/webtool/doc/src/Makefile new file mode 100644 index 0000000000..7b86752738 --- /dev/null +++ b/lib/webtool/doc/src/Makefile @@ -0,0 +1,127 @@ +# ``The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved via the world wide web at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# The Initial Developer of the Original Code is Ericsson Utvecklings AB. +# Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings +# AB. All Rights Reserved.'' +# +# $Id$ +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../../vsn.mk +VSN=$(WEBTOOL_VSN) +APPLICATION=webtool + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/$(APPLICATION)-$(VSN) + +# ---------------------------------------------------- +# Target Specs +# ---------------------------------------------------- +XML_APPLICATION_FILES = ref_man.xml + +XML_REF1_FILES = start_webtool.xml + +XML_REF3_FILES = webtool.xml + +XML_PART_FILES = \ + part.xml \ + part_notes.xml \ + part_notes_history.xml + +XML_CHAPTER_FILES = \ + webtool_chapter.xml \ + notes.xml \ + notes_history.xml + +BOOK_FILES = book.xml + +XML_FILES = \ + $(BOOK_FILES) $(XML_CHAPTER_FILES) \ + $(XML_PART_FILES) $(XML_REF3_FILES) \ + $(XML_REF1_FILES) $(XML_APPLICATION_FILES) + +GIF_FILES = + +# ---------------------------------------------------- + +HTML_FILES = $(XML_APPLICATION_FILES:%.xml=$(HTMLDIR)/%.html) \ + $(XML_PART_FILES:%.xml=$(HTMLDIR)/%.html) + +INFO_FILE = ../../info + +MAN1_FILES = $(XML_REF1_FILES:%.xml=$(MAN1DIR)/%.1) +MAN3_FILES = $(XML_REF3_FILES:%.xml=$(MAN3DIR)/%.3) + +HTML_REF_MAN_FILE = $(HTMLDIR)/index.html + +TOP_PDF_FILE = $(PDFDIR)/$(APPLICATION)-$(VSN).pdf + +# ---------------------------------------------------- +# FLAGS +# ---------------------------------------------------- +XML_FLAGS += +DVIPS_FLAGS += + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- +$(HTMLDIR)/%.gif: %.gif + $(INSTALL_DATA) $< $@ + +docs: pdf html man + +$(TOP_PDF_FILE): $(XML_FILES) + +pdf: $(TOP_PDF_FILE) + +html: gifs $(HTML_REF_MAN_FILE) + + +clean clean_docs: + rm -rf $(HTMLDIR)/* + rm -f $(MAN1DIR)/* + rm -f $(MAN3DIR)/* + rm -f $(TOP_PDF_FILE) $(TOP_PDF_FILE:%.pdf=%.fo) + rm -f errs core *~ + +man: $(MAN1_FILES) $(MAN3_FILES) + +gifs: $(GIF_FILES:%=$(HTMLDIR)/%) + +debug opt: + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + +release_docs_spec: docs + $(INSTALL_DIR) $(RELSYSDIR)/doc/pdf + $(INSTALL_DATA) $(TOP_PDF_FILE) $(RELSYSDIR)/doc/pdf + $(INSTALL_DIR) $(RELSYSDIR)/doc/html + $(INSTALL_DATA) $(HTMLDIR)/* \ + $(RELSYSDIR)/doc/html + $(INSTALL_DATA) $(INFO_FILE) $(RELSYSDIR) + $(INSTALL_DIR) $(RELEASE_PATH)/man/man1 + $(INSTALL_DATA) $(MAN1_FILES) $(RELEASE_PATH)/man/man1 + $(INSTALL_DIR) $(RELEASE_PATH)/man/man3 + $(INSTALL_DATA) $(MAN3_FILES) $(RELEASE_PATH)/man/man3 + +release_spec: + diff --git a/lib/webtool/doc/src/book.xml b/lib/webtool/doc/src/book.xml new file mode 100644 index 0000000000..ace70b5726 --- /dev/null +++ b/lib/webtool/doc/src/book.xml @@ -0,0 +1,47 @@ + + + + +
+ + 20012009 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + WebTool + + + + 1.0 +
+ + + WebTool + + + + + + + + + + + + + +
+ diff --git a/lib/webtool/doc/src/fascicules.xml b/lib/webtool/doc/src/fascicules.xml new file mode 100644 index 0000000000..0678195e07 --- /dev/null +++ b/lib/webtool/doc/src/fascicules.xml @@ -0,0 +1,18 @@ + + + + + + User's Guide + + + Reference Manual + + + Release Notes + + + Off-Print + + + diff --git a/lib/webtool/doc/src/make.dep b/lib/webtool/doc/src/make.dep new file mode 100644 index 0000000000..87526b3f73 --- /dev/null +++ b/lib/webtool/doc/src/make.dep @@ -0,0 +1,20 @@ +# ---------------------------------------------------- +# >>>> Do not edit this file <<<< +# This file was automaticly generated by +# /home/otp/bin/docdepend +# ---------------------------------------------------- + + +# ---------------------------------------------------- +# TeX files that the DVI file depend on +# ---------------------------------------------------- + +book.dvi: book.tex part.tex ref_man.tex start_webtool.tex \ + webtool.tex webtool_chapter.tex + +# ---------------------------------------------------- +# Source inlined when transforming from source to LaTeX +# ---------------------------------------------------- + +book.tex: ref_man.xml + diff --git a/lib/webtool/doc/src/notes.xml b/lib/webtool/doc/src/notes.xml new file mode 100644 index 0000000000..644cf7f7a8 --- /dev/null +++ b/lib/webtool/doc/src/notes.xml @@ -0,0 +1,112 @@ + + + + +
+ + 20042009 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + Webtool Release Notes + otp_appnotes + nil + nil + nil + notes.xml +
+

This document describes the changes made to the Webtool + application.

+ +
WebTool 0.8.5 + +
Improvements and New Features + + +

+ The documentation is now built with open source tools + (xsltproc and fop) that exists on most platforms. One + visible change is that the frames are removed.

+

+ Own Id: OTP-8201

+
+
+
+ +
+ +
WebTool 0.8.4 + +
Improvements and New Features + + +

The copyright notices have been updated.

+

+ Own Id: OTP-7851

+
+
+
+ +
+
WebTool 0.8.3.2 + +
Improvements and New Features + + +

+ Minor updates.

+

+ Own Id: OTP-6998

+
+
+
+ +
+ +
+ WebTool 0.8.3.1 + +
+ Improvements and New Features + + +

Minor Makefile changes.

+

Own Id: OTP-6689

+
+ +

Obsolete guard tests (such as list()) have been replaced + with the modern guard tests (such as is_list()).

+

Own Id: OTP-6725

+
+
+
+
+ +
+ WebTool 0.8.3 + +
+ Improvements and New Features + + +

Removed some dead code discovered by Dialyzer.

+

Own Id: OTP-6041

+
+
+
+
+
+ diff --git a/lib/webtool/doc/src/notes_history.xml b/lib/webtool/doc/src/notes_history.xml new file mode 100644 index 0000000000..edab54d61f --- /dev/null +++ b/lib/webtool/doc/src/notes_history.xml @@ -0,0 +1,73 @@ + + + + +
+ + 2006 + 2007 + Ericsson AB, All Rights Reserved + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + The Initial Developer of the Original Code is Ericsson AB. + + + Webtool Release Notes History + otp_appnotes + nil + nil + nil +
+ +
+ Webtool 0.8.2 + +
+ Fixed Bugs and Malfunctions + + +

Bugfix: webtool crashed when trying to find a free + port number if connection failed with other reason than + econnrefused.

+

Own Id: OTP-5166

+
+
+
+ +
+ Improvements and New Features + + +

Misc improvements:

+ + The function debug_app/1 and some error + printouts are added to simplify debugging of own + application. + Multiple webtool instances can now be started on + the same host. If the default port (8888) is in use, port + 8889 is tried. If 8889 is also used, 8890 is tried and so + on. Max number of ports tried is 256. + Incompatible: If Data is set to + PortNumber in start(Path,Data), the default + data will be used for ip-number (127.0.0.1) and + server name (localhost). + +

*** POTENTIAL INCOMPATIBILITY ***

+

Own Id: OTP-4724

+
+
+
+
+
+ diff --git a/lib/webtool/doc/src/part.xml b/lib/webtool/doc/src/part.xml new file mode 100644 index 0000000000..9306ea020e --- /dev/null +++ b/lib/webtool/doc/src/part.xml @@ -0,0 +1,37 @@ + + + + +
+ + 20012009 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + WebTool User's Guide + + + + +
+ +

WebTool provides a easy way to use web based tools with + Erlang/OTP. It configures and starts a webserver as well as all + available tools.

+
+ +
+ diff --git a/lib/webtool/doc/src/part_notes.xml b/lib/webtool/doc/src/part_notes.xml new file mode 100644 index 0000000000..7d5592d3aa --- /dev/null +++ b/lib/webtool/doc/src/part_notes.xml @@ -0,0 +1,39 @@ + + + + +
+ + 20042009 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + WebTool Release Notes + + + + +
+ +

WebTool provides an easy way to use web based tools with + Erlang/OTP. It configures and starts a webserver as well as all + available tools.

+

For information about older versions, see + Release Notes History.

+
+ +
+ diff --git a/lib/webtool/doc/src/part_notes_history.xml b/lib/webtool/doc/src/part_notes_history.xml new file mode 100644 index 0000000000..c1f6f846f5 --- /dev/null +++ b/lib/webtool/doc/src/part_notes_history.xml @@ -0,0 +1,39 @@ + + + + +
+ + 2006 + 2007 + Ericsson AB, All Rights Reserved + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + The Initial Developer of the Original Code is Ericsson AB. + + + WebTool Release Notes History + + + + +
+ +

WebTool provides a easy way to use web based tools with + Erlang/OTP. It configures and starts a webserver as well as all + available tools.

+
+ +
+ diff --git a/lib/webtool/doc/src/ref_man.xml b/lib/webtool/doc/src/ref_man.xml new file mode 100644 index 0000000000..537e8697c9 --- /dev/null +++ b/lib/webtool/doc/src/ref_man.xml @@ -0,0 +1,38 @@ + + + + +
+ + 20012009 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + WebTool Reference Manual + + + + +
+ +

WebTool provides an easy way to use web based tools with + Erlang/OTP. It configures and starts a webserver as well as all + available tools.

+
+ + +
+ diff --git a/lib/webtool/doc/src/start_webtool.xml b/lib/webtool/doc/src/start_webtool.xml new file mode 100644 index 0000000000..184285c631 --- /dev/null +++ b/lib/webtool/doc/src/start_webtool.xml @@ -0,0 +1,103 @@ + + + + +
+ + 20032009 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + start_webtool + + + 1 + + + 2003-06-18 + + start_webtool.sgml +
+ start_webtool + WebTool Start Script + +

The start_webtool script starts WebTool, a WebTool + application and a web browser pointing to this application.

+
+ + + start_webtool application [ browser ] + Start a WebTool Application + +

Starts WebTool, the given WebTool Application and a web + browser pointing to this application. +

+

If no argument is given, a list of available applications + is displayed, e.g.

+
+>start_webtool
+Starting webtool...
+WebTool is available at http://localhost:8888/
+Or  http://127.0.0.1:8888/
+
+Usage: start_webtool application [ browser ]
+
+Available applications are: [orber,appmon,crashdump_viewer,webcover]
+Default browser is 'iexplore' (Internet Explorer) on Windows or else 'netscape'        
+

To start any of the listed applications, give the + application name as the first argument, e.g.

+
+>start_webtool webcover
+Starting webtool...
+WebTool is available at http://localhost:8888/
+Or  http://127.0.0.1:8888/
+Starting webcover...
+Sending URL to netscape...done        
+

The WebTool application WebCover is then started and the + default browser is used. The default browser is Internet + Explorer on Windows or else Netscape. +

+

To use another browser, give the browser's start command + as the second argument, e.g.

+
+>start_webtool webcover mozilla
+Starting webtool...
+WebTool is available at http://localhost:8888/
+Or  http://127.0.0.1:8888/
+Starting webcover...
+Sending URL to mozilla...done        
+

If the given browser name is not known to WebTool, WebTool + will run it as a command with the start URL as the only + argument, e.g.

+
+>start_webtool webcover mybrowser
+Starting webtool...
+WebTool is available at http://localhost:8888/
+Or  http://127.0.0.1:8888/
+Starting webcover...
+Starting mybrowser...        
+

Here the command "mybrowser http://localhost:8888/webcover" is executed. +

+
+
+
+ +
+ See Also +

webtool(3)

+
+
+ diff --git a/lib/webtool/doc/src/webtool.xml b/lib/webtool/doc/src/webtool.xml new file mode 100644 index 0000000000..55bac8bd34 --- /dev/null +++ b/lib/webtool/doc/src/webtool.xml @@ -0,0 +1,156 @@ + + + + +
+ + 2001 + 2007 + Ericsson AB, All Rights Reserved + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + The Initial Developer of the Original Code is Ericsson AB. + + + webtool + + + + +
+ webtool + WebTool is a tool used to simplify the implementation of web based tools with Erlang/OTP. + +

WebTool makes it easy to use web based tools with Erlang/OTP. WebTool + configures and starts the webserver httpd.

+
+ + + start()-> {ok,Pid}| {stop,Reason} + Start WebTool. + +

Start WebTool with default data, i.e. port 8888, ip-number + 127.0.0.1, and server-name localhost. If port 8888 is + in use, port 8889 is tried instead. If 8889 is also in use, + 8890 is tried and so on. Max number of ports tried is 256. +

+

The mime.types file and WebTool's own HTML files + are assumed to be in the directory + /priv/root/conf]]>.

+
+
+ + start(Path,Data)->{ok,Pid}|{stop,Reason} + Start WebTool with default configuration. + + Path = string() | standard_path + Data = [Port,Address,Name] | PortNumber | standard_data + Port = {port,PortNumber} + Address = {bind_address,IpNumber} + Name = {server_name,ServerName} + PortNumber = integer() + IpNumber = tuple(), e.g. {127,0,0,1} + ServerName = string() + Pid = pid() + + +

Use this function to start WebTool if the default port, + ip-number,servername or path can not be used.

+

Path is the directory where the mime.types + file and WebTool's own HTML files are located. By default + this is /priv]]>, and in most cases there + is no need to change this. If Path is set to + standard_path the default will be used.

+

If Data is set to PortNumber, the default data + will be used for ip-number (127.0.0.1) and server + name (localhost).

+
+
+ + stop()->void + Stop WebTool. + +

Stop WebTool and the tools started by WebTool.

+
+
+ + debug_app(Module)->void + Debug a WebTool application. + + Module = atom() + + +

Debug a WebTool application by tracing all functions in the + given module which are called from WebTool.

+
+
+ + stop_debug()->void + Stop debugging an application and format the trace log. + +

Stop the tracing started by debug_app/1, and format + the trace log.

+
+
+
+ +
+ CALLBACK FUNCTIONS +

The following callback function must be implemented by each web + based tool that will be used via WebTool. When started, WebTool + searches the Erlang code path for *.tool files to locate all web + based tools and their callback functions. See the WebTool User's Guide for more + information about the *.tool files.

+
+ + + Module:Func(Data)-> {Name,WebData}|error + Returns configuration data needed by WebTool to configure and start a tool. + + Data = term() + Name = atom() + WebData = [WebOptions] + WebOptions = LinkData | Alias | Start + LinkData = {web_data,{ToolName,Url}} + Alias = {alias,{VirtualPath,RealPath}} | {alias,{erl_alias,Path,[Modules]} + Start = {start,StartData} + ToolName = Url = VirtualPath = RealPath = Path = string() + Modules = atom() + StartData = AppData | ChildSpec | Func + AppData = {app,AppName} + ChildSpec = {child,child_spec()} + See the Reference Manual for the module supervisor in the STDLIB application for details about child_spec(). + Func = {func,{StartMod,StartFunc,StartArg}, {StopMod,StopFunc,StopArg}} + AppName = StartMod = StartFunc = StopMod = StopFunc =atom() + StartArg = StopArg = [term()] + + +

This is the configuration function (config_func) + which must be stated in the *.tool file.

+

The function is called by WebTool at startup to retrieve the + data needed to start and configure the tool. LinkData is + used by WebTool to create the link to the tool. Alias is + used to create the aliases needed by the webserver. Start + is used to start and stop the tool.

+
+
+
+ +
+ See Also +

start_webtool(1), + WebTool User's Guide

+
+
+ diff --git a/lib/webtool/doc/src/webtool_chapter.xml b/lib/webtool/doc/src/webtool_chapter.xml new file mode 100644 index 0000000000..ceadce382d --- /dev/null +++ b/lib/webtool/doc/src/webtool_chapter.xml @@ -0,0 +1,248 @@ + + + + +
+ + 20012009 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + WebTool User Guide + + + + + webtool_chapter.xml +
+ +
+ Introduction +

WebTool provides an easy and efficient way to implement web + based tools with Erlang/OTP. WebTool configures and starts the + webserver and the various web based tools.

+

All tools that shall run under WebTool must have a *.tool + file in the code path or in its priv directory. When WebTool + starts it searches the code path for such files. For each + ebin directory in the path, the priv directory is + also searched. The *.tool files contain the configuration data + for each web based tool.

+
+ +
+ Starting WebTool +

Start WebTool by calling the function webtool:start/0 or + webtool:start/2. If webtool:start/0 is used the + start page of WebTool is available at + http://localhost:8888/ or + http://127.0.0.1:8888/, and the directory containing + the root directory for the webserver, is assumed to be + /priv]]>.

+

Use webtool:start/2 if the default path for the root + directory, port, ip-number or server name can not be used. See + the Reference Manual for webtool for more information.

+

WebTool, with the default configuration as in start/0, + can also be started with the start_webtool script which + is available in the priv directory of the WebTool + application. See the Reference Manual for start_webtool for further + information about this script. For Windows users, the batch file + start_webtool.bat can be used for the same purpose.

+
+ +
+ Using WebTool +

Start WebTool and point the browser to the corresponding URL. + At the top of the page there is a frame with a link named + WebTool. Click that link and a page where it is + possible to start the available tools will appear in the main + frame.

+
+ +
+ Start a web based tool +

Click on the link labeled WebTool in the topmost frame, + select the checkbox for each tool to start and + click on the button labeled Start. A link to each tool + that WebTool succeeded to start will appear in the topmost frame.

+
+ +
+ Stop a web based tool +

Click on the link labeled WebTool in the topmost + frame. Select Stop Tools in the left frame. Select the + checkbox for each tool to stop and click on the button labeled + Stop.

+
+ +
+ Develop new web based tools +

WebTool can be used as a framework when developing new web based + tools.

+

A web based tool running under WebTool will typically consist of + three parts.

+ + A *.tool file which defines how WebTool can find the tool's + configuration data + The Erlang code generating the web interface to the tool (HTML + code) + The tool itself. + +

In most cases it is a good idea to separate the code for + creation of the html-pages and the code for the logic. This + increases the readability of the code and the logic might be + possible to reuse.

+ +
+ The *.tool file +

When WebTool starts it searches the current path for + *.tool files to find all available tools. The *.tool + file contains a version identifier and a list of tuples which + is the configuration data. The version identifier specifies + the *.tool file version, i.e. not the version of + webtool. Currently the only valid version is "1.2" and the + only valid configuration tag is + config_func. config_func specifies which + function WebTool must call to get further configuration data + for the tool. This means that a *.tool file generally must + look like this:

+ + {version,"1.2"}. + [{config_func,{Module,Function,Arguments}}]. +

Module is the name of the module where the callback + function is defined. Function is the name of the + callback function, and Arguments is the list of + arguments to the callback function.

+
+ +
+ The configuration function +

The *.tool file points out a configuration function. This + function must return a list of configuration parameters (see + the Reference Manual for webtool).

+

The web_data parameter is mandatory and it specifies + the name of the tool and the link to the tool's start + page. All other parameters are optional.

+

If the tool requires any processes to run, the start + parameter specifies the function that WebTool must call in + order to start the process(es).

+

The alias parameters are passed directly on to the + webserver (INETS). The webserver has three ways to create + dynamic web pages CGI, Eval Scheme and Erl Scheme. All tools + running under WebTool must use Erl Scheme.

+

Erl Scheme tries to resemble plain CGI. The big difference is + that Erl Scheme can only execute Erlang code. The code will + furthermore be executed on the same instance as the webserver.

+

An URL which calls an Erlang function with Erl Scheme can have + the following syntax:

+ ]]> +

An alias parameter in the configuration function can be + an ErlScriptAlias as used in the above URL. The definition of + an ErlScripAlias shall be like this:

+

{alias,{erl_alias,Path,[Modules]}}, e.g.

+

{alias,{erl_alias,"/testtool",[helloworld]}}

+

The following URL will then cause a call to the function + helloworld:helloworld/2 (if WebTool is started with default + settings i.e. servername "localhost" and port 8888):

+

http://localhost:8888/testtool/helloworld/helloworld

+

Note that the module helloworld must be in the code + path of the node running WebTool.

+

Functions that are called via the Erl Scheme must take two + arguments, Environment and Input. +

+ + Environment is a list of key/value tuples. + Input is the part of the URL after the "?", i.e. the + part of the URL containing name-value pairs. If the page was + called with the URL: +

+

+Input will be the string + . In the module + httpd in the INETS application there is a function + parse_query which will parse such a string and return + a list of key-value tuples.
+
+

An alias parameter in the configuration function can + also be a normal path alias. This can e.g. be used to point + out a directory where HTML files are stored. The following + definition states that the URL + http://localhost:8888/mytool_home/ really points to the + directory /usr/local/otp/lib/myapp-1.0/priv:

+

{alias,{"/mytool_home","/usr/local/otp/lib/myapp-1.0/priv"}}

+

See the INETS documentation, especially the module + mod_esi, for a more in depht coverage of Erl Scheme.

+
+ +
+ A small example +

A Hello World example that uses Erl Scheme would look like + this. Note that this example does not have a process running + and thus does not need a start parameter in the + configuration function. +

+

helloworld.erl:

+
+        -module(helloworld).
+        -export([config_data/0]).
+        -export([helloworld/2]).
+        
+        config_data()->
+            {testtool,
+             [{web_data,{"TestTool","/testtool/helloworld/helloworld"}},
+              {alias,{erl_alias,"/testtool",[helloworld]}}]}.
+        
+        helloworld(_Env,_Input)->
+            [header(),html_header(),helloworld_body(),html_end()].
+
+        header() ->
+            header("text/html").
+
+        header(MimeType) ->
+            "Content-type: " ++ MimeType ++ "\\r\
+\\r\
+".
+
+        html_header() ->    
+            "<HTML>
+               <HEAD>
+                  <TITLE>Hello world Example </TITLE>
+               </HEAD>\
+".
+
+        helloworld_body()->
+            "<BODY>Hello World</BODY>".
+
+        html_end()->
+            "</HTML>".
+      
+

To use this example with WebTool a *.tool file must be created + and added to a directory in the current path, e.g. the same + directory as the compiled helloworld.beam.

+

testtool.tool:

+ + {version,"1.2"}. + [{config_func, {helloworld,config_data,[]}}]. + +

When helloworld.erl is compiled, start WebTool by + calling the function webtool:start() and point your + browser to http://localhost:8888/. Select WebTool in + the topmost frame and start TestTool from the web page. Click + on the link labeled TestTool in the topmost frame.

+
+
+
+ diff --git a/lib/webtool/ebin/.gitignore b/lib/webtool/ebin/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/webtool/info b/lib/webtool/info new file mode 100644 index 0000000000..4d8dc6f2cb --- /dev/null +++ b/lib/webtool/info @@ -0,0 +1,2 @@ +group: tools +short: A tool that simplifying the use of web based Erlang tools diff --git a/lib/webtool/priv/Makefile b/lib/webtool/priv/Makefile new file mode 100644 index 0000000000..56ab772c45 --- /dev/null +++ b/lib/webtool/priv/Makefile @@ -0,0 +1,77 @@ +# ``The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved via the world wide web at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# The Initial Developer of the Original Code is Ericsson Utvecklings AB. +# Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings +# AB. All Rights Reserved.'' +# +# $Id$ +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../vsn.mk +VSN=$(WEBTOOL_VSN) + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/webtool-$(VSN) + +# ---------------------------------------------------- +# Target Specs +# ---------------------------------------------------- + +WEBSERVER_CONFIG_FILES = root/conf/mime.types + +HTDOCS_FILES = root/doc/index.html \ + root/doc/tool_management.html \ + root/doc/start_info.html + +SCRIPTS = bin/start_webtool \ + bin/start_webtool.bat + +# ---------------------------------------------------- +# FLAGS +# ---------------------------------------------------- +ERL_COMPILE_FLAGS += + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- + +debug opt: + +clean: + +docs: + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/priv + $(INSTALL_DIR) $(RELSYSDIR)/priv/root + $(INSTALL_DIR) $(RELSYSDIR)/priv/root/conf + $(INSTALL_DIR) $(RELSYSDIR)/priv/root/doc + $(INSTALL_DATA) $(HTDOCS_FILES) $(RELSYSDIR)/priv/root/doc + $(INSTALL_DATA) $(WEBSERVER_CONFIG_FILES) $(RELSYSDIR)/priv/root/conf + $(INSTALL_DIR) $(RELSYSDIR)/priv/bin + $(INSTALL_SCRIPT) $(SCRIPTS) $(RELSYSDIR)/priv/bin + +release_docs_spec: + + diff --git a/lib/webtool/priv/bin/start_webtool b/lib/webtool/priv/bin/start_webtool new file mode 100755 index 0000000000..e552fb5af0 --- /dev/null +++ b/lib/webtool/priv/bin/start_webtool @@ -0,0 +1,3 @@ +#!/bin/sh + +erl -sname webtool -s webtool script_start $@ diff --git a/lib/webtool/priv/bin/start_webtool.bat b/lib/webtool/priv/bin/start_webtool.bat new file mode 100644 index 0000000000..cd16aa6200 --- /dev/null +++ b/lib/webtool/priv/bin/start_webtool.bat @@ -0,0 +1,2 @@ +@ECHO OFF +CALL erl -sname webtool -s webtool script_start %* -s erlang halt \ No newline at end of file diff --git a/lib/webtool/priv/root/conf/mime.types b/lib/webtool/priv/root/conf/mime.types new file mode 100644 index 0000000000..32f7cd853c --- /dev/null +++ b/lib/webtool/priv/root/conf/mime.types @@ -0,0 +1,99 @@ +# This is a comment. I love comments. + +application/activemessage +application/andrew-inset +application/applefile +application/atomicmail +application/dca-rft +application/dec-dx +application/mac-binhex40 hqx +application/mac-compactpro cpt +application/macwriteii +application/msword doc +application/news-message-id +application/news-transmission +application/octet-stream bin dms lha lzh exe class +application/oda oda +application/pdf pdf +application/postscript ai eps ps +application/powerpoint ppt +application/remote-printing +application/rtf rtf +application/slate +application/wita +application/wordperfect5.1 +application/x-bcpio bcpio +application/x-cdlink vcd +application/x-compress Z +application/x-cpio cpio +application/x-csh csh +application/x-director dcr dir dxr +application/x-dvi dvi +application/x-gtar gtar +application/x-gzip gz +application/x-hdf hdf +application/x-httpd-cgi cgi +application/x-koan skp skd skt skm +application/x-latex latex +application/x-mif mif +application/x-netcdf nc cdf +application/x-sh sh +application/x-shar shar +application/x-stuffit sit +application/x-sv4cpio sv4cpio +application/x-sv4crc sv4crc +application/x-tar tar +application/x-tcl tcl +application/x-tex tex +application/x-texinfo texinfo texi +application/x-troff t tr roff +application/x-troff-man man +application/x-troff-me me +application/x-troff-ms ms +application/x-ustar ustar +application/x-wais-source src +application/zip zip +audio/basic au snd +audio/mpeg mpga mp2 +audio/x-aiff aif aiff aifc +audio/x-pn-realaudio ram +audio/x-pn-realaudio-plugin rpm +audio/x-realaudio ra +audio/x-wav wav +chemical/x-pdb pdb xyz +image/gif gif +image/ief ief +image/jpeg jpeg jpg jpe +image/png png +image/tiff tiff tif +image/x-cmu-raster ras +image/x-portable-anymap pnm +image/x-portable-bitmap pbm +image/x-portable-graymap pgm +image/x-portable-pixmap ppm +image/x-rgb rgb +image/x-xbitmap xbm +image/x-xpixmap xpm +image/x-xwindowdump xwd +message/external-body +message/news +message/partial +message/rfc822 +multipart/alternative +multipart/appledouble +multipart/digest +multipart/mixed +multipart/parallel +text/html html htm +text/x-server-parsed-html shtml +text/plain txt +text/richtext rtx +text/tab-separated-values tsv +text/x-setext etx +text/x-sgml sgml sgm +video/mpeg mpeg mpg mpe +video/quicktime qt mov +video/x-msvideo avi +video/x-sgi-movie movie +x-conference/x-cooltalk ice +x-world/x-vrml wrl vrml diff --git a/lib/webtool/priv/root/doc/index.html b/lib/webtool/priv/root/doc/index.html new file mode 100644 index 0000000000..9fbb143cc7 --- /dev/null +++ b/lib/webtool/priv/root/doc/index.html @@ -0,0 +1,11 @@ + + +Erlang WebTool + + + + + + + + diff --git a/lib/webtool/priv/root/doc/start_info.html b/lib/webtool/priv/root/doc/start_info.html new file mode 100644 index 0000000000..fcf44433f1 --- /dev/null +++ b/lib/webtool/priv/root/doc/start_info.html @@ -0,0 +1,28 @@ + + + + + + + + +
+ + + + + + + + + + + + + +
Welcome
to
WebTool




+
Click on the link WebTool on the top of the page, or here to start the Web based tools.
+ +
+ + \ No newline at end of file diff --git a/lib/webtool/priv/root/doc/tool_management.html b/lib/webtool/priv/root/doc/tool_management.html new file mode 100644 index 0000000000..19d9dbcb9e --- /dev/null +++ b/lib/webtool/priv/root/doc/tool_management.html @@ -0,0 +1,9 @@ + + +Erlang WebTool + + + + + + diff --git a/lib/webtool/src/Makefile b/lib/webtool/src/Makefile new file mode 100644 index 0000000000..62845cd370 --- /dev/null +++ b/lib/webtool/src/Makefile @@ -0,0 +1,97 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2001-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../vsn.mk +VSN=$(WEBTOOL_VSN) + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/webtool-$(VSN) + +# ---------------------------------------------------- +# Target Specs +# ---------------------------------------------------- + +MODULES= webtool \ + webtool_sup + + + +ERL_FILES= $(MODULES:%=%.erl) + +TARGET_FILES = $(MODULES:%=$(EBIN)/%.$(EMULATOR)) + +APP_FILE= webtool.app +APPUP_FILE= webtool.appup + +APP_SRC= $(APP_FILE).src +APPUP_SRC= $(APPUP_FILE).src + + +APP_TARGET= $(EBIN)/$(APP_FILE) +APPUP_TARGET= $(EBIN)/$(APPUP_FILE) + +# ---------------------------------------------------- +# FLAGS +# ---------------------------------------------------- +ERL_COMPILE_FLAGS += +warn_obsolete_guard + + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- + +debug opt: $(TARGET_FILES) $(APP_TARGET) $(APPUP_TARGET) + +clean: + rm -f $(TARGET_FILES) $(APP_TARGET) $(APP_TARGET) + rm -f core + +docs: + +# ---------------------------------------------------- +# Special Build Targets +# ---------------------------------------------------- + +$(APP_TARGET): $(APP_SRC) ../vsn.mk + sed -e 's;%VSN%;$(VSN);' $< > $@ + +$(APPUP_TARGET): $(APPUP_SRC) ../vsn.mk + sed -e 's;%VSN%;$(VSN);' $< > $@ + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/src + $(INSTALL_DATA) $(ERL_FILES) $(HRL_FILES) $(RELSYSDIR)/src + $(INSTALL_DIR) $(RELSYSDIR)/ebin + $(INSTALL_DATA) $(TARGET_FILES) $(APP_TARGET) $(APPUP_TARGET) \ + $(RELSYSDIR)/ebin + +release_docs_spec: + diff --git a/lib/webtool/src/webtool.app.src b/lib/webtool/src/webtool.app.src new file mode 100644 index 0000000000..8c6774c533 --- /dev/null +++ b/lib/webtool/src/webtool.app.src @@ -0,0 +1,25 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2001-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +{application,webtool, + [{description,"Toolbar lookalike for the web"}, + {vsn,"%VSN%"}, + {modules,[webtool,webtool_sup]}, + {registered,[web_tool,websup]}, + {applications,[kernel,stdlib]}]}. + diff --git a/lib/webtool/src/webtool.appup.src b/lib/webtool/src/webtool.appup.src new file mode 100644 index 0000000000..7a435e9b22 --- /dev/null +++ b/lib/webtool/src/webtool.appup.src @@ -0,0 +1,19 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2001-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +{"%VSN%",[],[]}. diff --git a/lib/webtool/src/webtool.erl b/lib/webtool/src/webtool.erl new file mode 100644 index 0000000000..51d821751c --- /dev/null +++ b/lib/webtool/src/webtool.erl @@ -0,0 +1,1205 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2001-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +-module(webtool). +-behaviour(gen_server). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% The general idea is: %% +%% %% +%% %% +%% 1. Scan through the path for *.tool files and find all the web %% +%% based tools. Query each tool for configuration data. %% +%% 2. Add Alias for Erlscript and html for each tool to %% +%% the webserver configuration data. %% +%% 3. Start the webserver. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%% API functions +-export([start/0, start/2, stop/0]). + +%% Starting Webtool from a shell script +-export([script_start/0, script_start/1]). + +%% Web api +-export([started_tools/2, toolbar/2, start_tools/2, stop_tools/2]). + +%% API against other tools +-export([is_localhost/0]). + +%% Debug export s +-export([get_tools1/1]). +-export([debug/1, stop_debug/0, debug_app/1]). + +%% gen_server callbacks +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +-include_lib("kernel/include/file.hrl"). +-include_lib("stdlib/include/ms_transform.hrl"). + +-record(state,{priv_dir,app_data,supvis,web_data,started=[]}). + +-define(MAX_NUMBER_OF_WEBTOOLS,256). +-define(DEFAULT_PORT,8888).% must be >1024 or the user must be root on unix +-define(DEFAULT_ADDR,{127,0,0,1}). + +-define(WEBTOOL_ALIAS,{webtool,[{alias,{erl_alias,"/webtool",[webtool]}}]}). +-define(HEADER,"Pragma:no-cache\r\n Content-type: text/html\r\n\r\n"). +-define(HTML_HEADER,"\r\n\r\nWebTool\r\n\r\n\r\n"). +-define(HTML_HEADER_RELOAD,"\r\n\r\nWebTool + \r\n\r\n + \r\n"). + +-define(HTML_END,""). + +-define(SEND_URL_TIMEOUT,5000). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% For debugging only. %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Start tracing with +%% debug(Functions). +%% Functions = local | global | FunctionList +%% FunctionList = [Function] +%% Function = {FunctionName,Arity} | FunctionName | +%% {Module, FunctionName, Arity} | {Module,FunctionName} +debug(F) -> + ttb:tracer(all,[{file,"webtool.trc"}]), % tracing all nodes + ttb:p(all,[call,timestamp]), + MS = [{'_',[],[{return_trace},{message,{caller}}]}], + tp(F,MS), + ttb:ctp(?MODULE,stop_debug), % don't want tracing of the stop_debug func + ok. +tp(local,MS) -> % all functions + ttb:tpl(?MODULE,MS); +tp(global,MS) -> % all exported functions + ttb:tp(?MODULE,MS); +tp([{M,F,A}|T],MS) -> % Other module + ttb:tpl(M,F,A,MS), + tp(T,MS); +tp([{M,F}|T],MS) when is_atom(F) -> % Other module + ttb:tpl(M,F,MS), + tp(T,MS); +tp([{F,A}|T],MS) -> % function/arity + ttb:tpl(?MODULE,F,A,MS), + tp(T,MS); +tp([F|T],MS) -> % function + ttb:tpl(?MODULE,F,MS), + tp(T,MS); +tp([],_MS) -> + ok. +stop_debug() -> + ttb:stop([format]). + +debug_app(Mod) -> + ttb:tracer(all,[{file,"webtool_app.trc"},{handler,{fun out/4,true}}]), + ttb:p(all,[call,timestamp]), + MS = [{'_',[],[{return_trace},{message,{caller}}]}], + ttb:tp(Mod,MS), + ok. + +out(_,{trace_ts,Pid,call,MFA={M,F,A},{W,_,_},TS},_,S) + when W==webtool;W==mod_esi-> + io:format("~w: (~p)~ncall ~s~n", [TS,Pid,ffunc(MFA)]), + [{M,F,length(A)}|S]; +out(_,{trace_ts,Pid,return_from,MFA,R,TS},_,[MFA|S]) -> + io:format("~w: (~p)~nreturned from ~s -> ~p~n", [TS,Pid,ffunc(MFA),R]), + S; +out(_,_,_,_) -> + ok. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% Functions called via script. %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +script_start() -> + usage(), + halt(). +script_start([App]) -> + DefaultBrowser = + case os:type() of + {win32,_} -> iexplore; + _ -> netscape + end, + script_start([App,DefaultBrowser]); +script_start([App,Browser]) -> + io:format("Starting webtool...\n"), + start(), + AvailableApps = get_applications(), + {OSType,_} = os:type(), + case lists:keysearch(App,1,AvailableApps) of + {value,{App,StartPage}} -> + io:format("Starting ~w...\n",[App]), + start_tools([],"app=" ++ atom_to_list(App)), + PortStr = integer_to_list(get_port()), + Url = case StartPage of + "/" ++ Page -> + "http://localhost:" ++ PortStr ++ "/" ++ Page; + _ -> + "http://localhost:" ++ PortStr ++ "/" ++ StartPage + end, + case Browser of + iexplore when OSType == win32-> + io:format("Starting internet explorer...\n"), + {ok,R} = win32reg:open(""), + Key="\\local_machine\\SOFTWARE\\Microsoft\\IE Setup\\Setup", + win32reg:change_key(R,Key), + {ok,Val} = win32reg:value(R,"Path"), + IExplore=filename:join(win32reg:expand(Val),"iexplore.exe"), + os:cmd("\"" ++ IExplore ++ "\" " ++ Url); + _ when OSType == win32 -> + io:format("Starting ~w...\n",[Browser]), + os:cmd("\"" ++ atom_to_list(Browser) ++ "\" " ++ Url); + B when B==netscape; B==mozilla -> + io:format("Sending URL to ~w...",[Browser]), + BStr = atom_to_list(Browser), + SendCmd = BStr ++ " -raise -remote \'openUrl(" ++ + Url ++ ")\'", + Port = open_port({spawn,SendCmd},[exit_status]), + receive + {Port,{exit_status,0}} -> + io:format("done\n"), + ok; + {Port,{exit_status,_Error}} -> + io:format(" not running, starting ~w...\n", + [Browser]), + os:cmd(BStr ++ " " ++ Url), + ok + after ?SEND_URL_TIMEOUT -> + io:format(" failed, starting ~w...\n",[Browser]), + erlang:port_close(Port), + os:cmd(BStr ++ " " ++ Url) + end; + _ -> + io:format("Starting ~w...\n",[Browser]), + os:cmd(atom_to_list(Browser) ++ " " ++ Url) + end, + ok; + false -> + stop(), + io:format("\n{error,{unknown_app,~p}}\n",[App]), + halt() + end. + +usage() -> + io:format("Starting webtool...\n"), + start(), + Apps = lists:map(fun({A,_}) -> A end,get_applications()), + io:format( + "\nUsage: start_webtool application [ browser ]\n" + "\nAvailable applications are: ~p\n" + "Default browser is \'iexplore\' (Internet Explorer) on Windows " + "or else \'netscape\'\n", + [Apps]), + stop(). + + +get_applications() -> + gen_server:call(web_tool,get_applications). + +get_port() -> + gen_server:call(web_tool,get_port). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% Api functions to the genserver. %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------------- +% +%---------------------------------------------------------------------- + +start()-> + start(standard_path,standard_data). + +start(Path,standard_data)-> + case get_standard_data() of + {error,Reason} -> + {error,Reason}; + Data -> + start(Path,Data) + end; + +start(standard_path,Data)-> + Path=get_path(), + start(Path,Data); + +start(Path,Port) when is_integer(Port)-> + Data = get_standard_data(Port), + start(Path,Data); + +start(Path,Data0)-> + Data = Data0 ++ rest_of_standard_data(), + gen_server:start({local,web_tool},webtool,{Path,Data},[]). + +stop()-> + gen_server:call(web_tool,stoppit). + +%---------------------------------------------------------------------- +%Web Api functions called by the web +%---------------------------------------------------------------------- +started_tools(Env,Input)-> + gen_server:call(web_tool,{started_tools,Env,Input}). + +toolbar(Env,Input)-> + gen_server:call(web_tool,{toolbar,Env,Input}). + +start_tools(Env,Input)-> + gen_server:call(web_tool,{start_tools,Env,Input}). + +stop_tools(Env,Input)-> + gen_server:call(web_tool,{stop_tools,Env,Input}). +%---------------------------------------------------------------------- +%Support API for other tools +%---------------------------------------------------------------------- + +is_localhost()-> + gen_server:call(web_tool,is_localhost). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%%The gen_server callback functions that builds the webbpages %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +handle_call(get_applications,_,State)-> + MS = ets:fun2ms(fun({Tool,{web_data,{_,Start}}}) -> {Tool,Start} end), + Tools = ets:select(State#state.app_data,MS), + {reply,Tools,State}; + +handle_call(get_port,_,State)-> + {value,{port,Port}}=lists:keysearch(port,1,State#state.web_data), + {reply,Port,State}; + +handle_call({started_tools,_Env,_Input},_,State)-> + {reply,started_tools_page(State),State}; + +handle_call({toolbar,_Env,_Input},_,State)-> + {reply,toolbar(),State}; + +handle_call({start_tools,Env,Input},_,State)-> + {NewState,Page}=start_tools_page(Env,Input,State), + {reply,Page,NewState}; + +handle_call({stop_tools,Env,Input},_,State)-> + {NewState,Page}=stop_tools_page(Env,Input,State), + {reply,Page,NewState}; + +handle_call(stoppit,_From,Data)-> + {stop,normal,ok,Data}; + +handle_call(is_localhost,_From,Data)-> + Result=case proplists:get_value(bind_address, Data#state.web_data) of + ?DEFAULT_ADDR -> + true; + _IpNumber -> + false + end, + {reply,Result,Data}. + + +handle_info(_Message,State)-> + {noreply,State}. + +handle_cast(_Request,State)-> + {noreply,State}. + +code_change(_,State,_)-> + {ok,State}. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% The other functions needed by the gen_server behaviour +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------------- +% Start the gen_server +%---------------------------------------------------------------------- +init({Path,Config})-> + case filelib:is_dir(Path) of + true -> + {ok, Table} = get_tool_files_data(), + insert_app(?WEBTOOL_ALIAS, Table), + case webtool_sup:start_link() of + {ok, Pid} -> + case start_webserver(Table, Path, Config) of + {ok, _} -> + print_url(Config), + {ok,#state{priv_dir=Path, + app_data=Table, + supvis=Pid, + web_data=Config}}; + {error, Error} -> + {stop, {error, Error}} + end; + Error -> + {stop,Error} + end; + false -> + {stop, {error, error_dir}} + end. + +terminate(_Reason,Data)-> + %%shut down the webbserver + shutdown_server(Data), + %%Shutdown the different tools that are started with application:start + shutdown_apps(Data), + %%Shutdown the supervisor and its children will die + shutdown_supervisor(Data), + ok. + +print_url(ConfigData)-> + Server=proplists:get_value(server_name,ConfigData,"undefined"), + Port=proplists:get_value(port,ConfigData,"undefined"), + {A,B,C,D}=proplists:get_value(bind_address,ConfigData,"undefined"), + io:format("WebTool is available at http://~s:~w/~n",[Server,Port]), + io:format("Or http://~w.~w.~w.~w:~w/~n",[A,B,C,D,Port]). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% begin build the pages +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%---------------------------------------------------------------------- +%The page that shows the started tools +%---------------------------------------------------------------------- +started_tools_page(State)-> + [?HEADER,?HTML_HEADER,started_tools(State),?HTML_END]. + +toolbar()-> + [?HEADER,?HTML_HEADER,toolbar_page(),?HTML_END]. + + +start_tools_page(_Env,Input,State)-> + %%io:format("~n======= ~n ~p ~n============~n",[Input]), + case get_tools(Input) of + {tools,Tools}-> + %%io:format("~n======= ~n ~p ~n============~n",[Tools]), + {ok,NewState}=handle_apps(Tools,State,start), + {NewState,[?HEADER,?HTML_HEADER_RELOAD,reload_started_apps(), + show_unstarted_apps(NewState),?HTML_END]}; + _ -> + {State,[?HEADER,?HTML_HEADER,show_unstarted_apps(State),?HTML_END]} + end. + +stop_tools_page(_Env,Input,State)-> + case get_tools(Input) of + {tools,Tools}-> + {ok,NewState}=handle_apps(Tools,State,stop), + {NewState,[?HEADER,?HTML_HEADER_RELOAD,reload_started_apps(), + show_started_apps(NewState),?HTML_END]}; + _ -> + {State,[?HEADER,?HTML_HEADER,show_started_apps(State),?HTML_END]} + end. + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%% Functions that start and config the webserver +%% 1. Collect the config data +%% 2. Start webserver +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%---------------------------------------------------------------------- +% Start the webserver +%---------------------------------------------------------------------- +start_webserver(Data,Path,Config)-> + case get_conf_data(Data,Path,Config) of + {ok,Conf_data}-> + %%io:format("Conf_data: ~p~n",[Conf_data]), + start_server(Conf_data); + {error,Error} -> + {error,{error_server_conf_file,Error}} + end. + +start_server(Conf_data)-> + case inets:start(httpd, Conf_data, stand_alone) of + {ok,Pid}-> + {ok,Pid}; + Error-> + {error,{server_error,Error}} + end. + +%---------------------------------------------------------------------- +% Create config data for the webserver +%---------------------------------------------------------------------- +get_conf_data(Data,Path,Config)-> + Aliases=get_aliases(Data), + ServerRoot = filename:join([Path,"root"]), + MimeTypesFile = filename:join([ServerRoot,"conf","mime.types"]), + case httpd_conf:load_mime_types(MimeTypesFile) of + {ok,MimeTypes} -> + Config1 = Config ++ Aliases, + Config2 = [{server_root,ServerRoot}, + {document_root,filename:join([Path,"root/doc"])}, + {mime_types,MimeTypes} | + Config1], + {ok,Config2}; + Error -> + Error + end. + +%---------------------------------------------------------------------- +% Control the path for *.tools files +%---------------------------------------------------------------------- +get_tool_files_data()-> + Tools=get_tools1(code:get_path()), + %%io:format("Data : ~p ~n",[Tools]), + get_file_content(Tools). + +%---------------------------------------------------------------------- +%Control that the data in the file really is erlang terms +%---------------------------------------------------------------------- +get_file_content(Tools)-> + Get_data=fun({tool,ToolData}) -> + %%io:format("Data : ~p ~n",[ToolData]), + case proplists:get_value(config_func,ToolData) of + {M,F,A}-> + case catch apply(M,F,A) of + {'EXIT',_} -> + bad_data; + Data when is_tuple(Data) -> + Data; + _-> + bad_data + end; + _ -> + bad_data + end + end, + insert_file_content([X ||X<-lists:map(Get_data,Tools),X/=bad_data]). + +%---------------------------------------------------------------------- +%Insert the data from the file in to the ets:table +%---------------------------------------------------------------------- +insert_file_content(Content)-> + Table=ets:new(app_data,[bag]), + lists:foreach(fun(X)-> + insert_app(X,Table) + end,Content), + {ok,Table}. + +%---------------------------------------------------------------------- +%Control that we got a a tuple of a atom and a list if so add the +%elements in the list to the ets:table +%---------------------------------------------------------------------- +insert_app({Name,Key_val_list},Table) when is_list(Key_val_list),is_atom(Name)-> + %%io:format("ToolData: ~p: ~p~n",[Name,Key_val_list]), + lists:foreach( + fun({alias,{erl_alias,Alias,Mods}}) -> + Key_val = {erl_script_alias,{Alias,Mods}}, + %%io:format("Insert: ~p~n",[Key_val]), + ets:insert(Table,{Name,Key_val}); + (Key_val_pair)-> + %%io:format("Insert: ~p~n",[Key_val_pair]), + ets:insert(Table,{Name,Key_val_pair}) + end, + Key_val_list); + +insert_app(_,_)-> + ok. + +%---------------------------------------------------------------------- +% Select all the alias in the database +%---------------------------------------------------------------------- +get_aliases(Data)-> + MS = ets:fun2ms(fun({_,{erl_script_alias,Alias}}) -> + {erl_script_alias,Alias}; + ({_,{alias,Alias}}) -> + {alias,Alias} + end), + ets:select(Data,MS). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% Helper functions %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +get_standard_data(Port)-> + [ + {port,Port}, + {bind_address,?DEFAULT_ADDR}, + {server_name,"localhost"} + ]. + +get_standard_data()-> + case get_free_port(?DEFAULT_PORT,?MAX_NUMBER_OF_WEBTOOLS) of + {error,Reason} -> {error,Reason}; + Port -> + [ + {port,Port}, + {bind_address,?DEFAULT_ADDR}, + {server_name,"localhost"} + ] + end. + +get_free_port(_Port,0) -> + {error,no_free_port_found}; +get_free_port(Port,N) -> + case gen_tcp:connect("localhost",Port,[]) of + {error, _Reason} -> + Port; + {ok,Sock} -> + gen_tcp:close(Sock), + get_free_port(Port+1,N-1) + end. + +rest_of_standard_data() -> + [ + %% Do not allow the server to be crashed by malformed http-request + {max_header_siz,1024}, + {max_header_action,reply414}, + %% Go on a straight ip-socket + {com_type,ip_comm}, + %% Do not change the order of these module names!! + {modules,[mod_alias, + mod_auth, + mod_esi, + mod_actions, + mod_cgi, + mod_include, + mod_dir, + mod_get, + mod_head, + mod_log, + mod_disk_log]}, + {directory_index,["index.html"]}, + {default_type,"text/plain"} + ]. + + +get_path()-> + code:priv_dir(webtool). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% These functions is used to shutdown the webserver +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%---------------------------------------------------------------------- +% Shut down the webbserver +%---------------------------------------------------------------------- +shutdown_server(State)-> + {Addr,Port} = get_addr_and_port(State#state.web_data), + inets:stop(httpd,{Addr,Port}). + +get_addr_and_port(Config) -> + Addr = proplists:get_value(bind_address,Config,?DEFAULT_ADDR), + Port = proplists:get_value(port,Config,?DEFAULT_PORT), + {Addr,Port}. + +%---------------------------------------------------------------------- +% Select all apps in the table and close them +%---------------------------------------------------------------------- +shutdown_apps(State)-> + Data=State#state.app_data, + MS = ets:fun2ms(fun({_,{start,HowToStart}}) -> HowToStart end), + lists:foreach(fun(Start_app)-> + stop_app(Start_app) + end, + ets:select(Data,MS)). + +%---------------------------------------------------------------------- +%Shuts down the supervisor that supervises tools that is not +%Designed as applications +%---------------------------------------------------------------------- +shutdown_supervisor(State)-> + %io:format("~n==================~n"), + webtool_sup:stop(State#state.supvis). + %io:format("~n==================~n"). + +%---------------------------------------------------------------------- +%close the individual apps. +%---------------------------------------------------------------------- +stop_app({child,_Real_name})-> + ok; + +stop_app({app,Real_name})-> + application:stop(Real_name); + +stop_app({func,_Start,Stop})-> + case Stop of + {M,F,A} -> + catch apply(M,F,A); + _NoStop -> + ok + end. + + + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%% These functions creates the webpage where the user can select if +%% to start apps or to stop apps +%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +toolbar_page()-> + " + + + + + + + + + +
+ Select Action +
+ Start Tools +
+ Stop Tools +
". +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%% These functions creates the webbpage that shows the started apps +%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%---------------------------------------------------------------------- +% started_tools(State)->String (html table) +% State is a record of type state +%---------------------------------------------------------------------- +started_tools(State)-> + Names=get_started_apps(State#state.app_data,State#state.started), + " + "++ make_rows(Names,[],0) ++" +
". +%---------------------------------------------------------------------- +%get_started_apps(Data,Started)-> [{web_name,link}] +%selects the started apps from the ets table of apps. +%---------------------------------------------------------------------- + +get_started_apps(Data,Started)-> + SelectData=fun({Name,Link}) -> + {Name,Link} + end, + MS = lists:map(fun(A) -> {{A,{web_data,'$1'}},[],['$1']} end,Started), + + [{"WebTool","/tool_management.html"} | + [SelectData(X) || X <- ets:select(Data,MS)]]. + +%---------------------------------------------------------------------- +% make_rows(List,Result,Fields)-> String (The rows of a htmltable +% List a list of tupler discibed above +% Result an accumulator for the result +% Field, counter that counts the number of cols in each row. +%---------------------------------------------------------------------- +make_rows([],Result,Fields)-> + Result ++ fill_out(Fields); +make_rows([Data|Paths],Result,Field)when Field==0-> + make_rows(Paths,Result ++ "" ++ make_field(Data),Field+1); + +make_rows([Path|Paths],Result,Field)when Field==4-> + make_rows(Paths,Result ++ make_field(Path) ++ "",0); + +make_rows([Path|Paths],Result,Field)-> + make_rows(Paths,Result ++ make_field(Path),Field+1). + +%---------------------------------------------------------------------- +% make_fields(Path)-> String that is a field i a html table +% Path is a name url tuple {Name,url} +%---------------------------------------------------------------------- +make_field(Path)-> + "" ++ get_name(Path) ++ "". + + +%---------------------------------------------------------------------- +%get_name({Nae,Url})->String that represents a tag in html. +%---------------------------------------------------------------------- +get_name({Name,Url})-> + "" ++ Name ++ "". + + +%---------------------------------------------------------------------- +% fill_out(Nr)-> String, that represent Nr fields in a html-table. +%---------------------------------------------------------------------- +fill_out(Nr)when Nr==0-> + []; +fill_out(Nr)when Nr==4-> + " "; + +fill_out(Nr)-> + " " ++ fill_out(Nr+1). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%%These functions starts applicatons and builds the page showing tools +%%to start +%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------------------------------------- +%Controls whether the user selected a tool to start +%---------------------------------------------------------------------- +get_tools(Input)-> + case httpd:parse_query(Input) of + []-> + no_tools; + Tools-> + FormatData=fun({_Name,Data}) -> list_to_atom(Data) end, + SelectData= + fun({Name,_Data}) -> string:equal(Name,"app") end, + {tools,[FormatData(X)||X<-Tools,SelectData(X)]} + end. + +%---------------------------------------------------------------------- +% Selects the data to start the applications the user has ordered +% starting of +%---------------------------------------------------------------------- +handle_apps([],State,_Cmd)-> + {ok,State}; + +handle_apps([Tool|Tools],State,Cmd)-> + case ets:match_object(State#state.app_data,{Tool,{start,'_'}}) of + []-> + Started = case Cmd of + start -> + [Tool|State#state.started]; + stop -> + lists:delete(Tool,State#state.started) + end, + {ok,#state{priv_dir=State#state.priv_dir, + app_data=State#state.app_data, + supvis=State#state.supvis, + web_data=State#state.web_data, + started=Started}}; + ToStart -> + case handle_apps2(ToStart,State,Cmd) of + {ok,NewState}-> + handle_apps(Tools,NewState,Cmd); + _-> + handle_apps(Tools,State,Cmd) + end + end. + +%---------------------------------------------------------------------- +%execute every start or stop data about a tool. +%---------------------------------------------------------------------- +handle_apps2([{Name,Start_data}],State,Cmd)-> + case handle_app({Name,Start_data},State#state.app_data,State#state.supvis,Cmd) of + ok-> + Started = case Cmd of + start -> + [Name|State#state.started]; + stop -> + + lists:delete(Name,State#state.started) + end, + {ok,#state{priv_dir=State#state.priv_dir, + app_data=State#state.app_data, + supvis=State#state.supvis, + web_data=State#state.web_data, + started=Started}}; + _-> + error + end; + +handle_apps2([{Name,Start_data}|Rest],State,Cmd)-> + case handle_app({Name,Start_data},State#state.app_data,State#state.supvis,Cmd)of + ok-> + handle_apps2(Rest,State,Cmd); + _-> + error + end. + + +%---------------------------------------------------------------------- +% Handle start and stop of applications +%---------------------------------------------------------------------- + +handle_app({Name,{start,{func,Start,Stop}}},Data,_Pid,Cmd)-> + Action = case Cmd of + start -> + Start; + _ -> + Stop + end, + case Action of + {M,F,A} -> + case catch apply(M,F,A) of + {'EXIT',_} = Exit-> + %%! Here the tool disappears from the webtool interface!! + io:format("\n=======ERROR (webtool, line ~w) =======\n" + "Could not start application \'~p\'\n\n" + "~w:~w(~s) ->\n" + "~p\n\n", + [?LINE,Name,M,F,format_args(A),Exit]), + ets:delete(Data,Name); + _OK-> + ok + end; + _NoStart -> + ok + end; + + +handle_app({Name,{start,{child,ChildSpec}}},Data,Pid,Cmd)-> + case Cmd of + start -> + case catch supervisor:start_child(Pid,ChildSpec) of + {ok,_}-> + ok; + {ok,_,_}-> + ok; + {error,Reason}-> + %%! Here the tool disappears from the webtool interface!! + io:format("\n=======ERROR (webtool, line ~w) =======\n" + "Could not start application \'~p\'\n\n" + "supervisor:start_child(~p,~p) ->\n" + "~p\n\n", + [?LINE,Name,Pid,ChildSpec,{error,Reason}]), + ets:delete(Data,Name); + Error -> + %%! Here the tool disappears from the webtool interface!! + io:format("\n=======ERROR (webtool, line ~w) =======\n" + "Could not start application \'~p\'\n\n" + "supervisor:start_child(~p,~p) ->\n" + "~p\n\n", + [?LINE,Name,Pid,ChildSpec,Error]), + ets:delete(Data,Name) + end; + stop -> + case catch supervisor:terminate_child(websup,element(1,ChildSpec)) of + ok -> + supervisor:delete_child(websup,element(1,ChildSpec)); + _ -> + error + end + end; + + + +handle_app({Name,{start,{app,Real_name}}},Data,_Pid,Cmd)-> + case Cmd of + start -> + case application:start(Real_name,temporary) of + ok-> + io:write(Name), + ok; + {error,{already_started,_}}-> + %% Remove it from the database so we dont start + %% anything already started + ets:match_delete(Data,{Name,{start,{app,Real_name}}}), + ok; + {error,_Reason}=Error-> + %%! Here the tool disappears from the webtool interface!! + io:format("\n=======ERROR (webtool, line ~w) =======\n" + "Could not start application \'~p\'\n\n" + "application:start(~p,~p) ->\n" + "~p\n\n", + [?LINE,Name,Real_name,temporary,Error]), + ets:delete(Data,Name) + end; + + stop -> + application:stop(Real_name) + end; + +%---------------------------------------------------------------------- +% If the data is incorrect delete the app +%---------------------------------------------------------------------- +handle_app({Name,Incorrect},Data,_Pid,Cmd)-> + %%! Here the tool disappears from the webtool interface!! + io:format("\n=======ERROR (webtool, line ~w) =======\n" + "Could not ~w application \'~p\'\n\n" + "Incorrect data: ~p\n\n", + [?LINE,Cmd,Name,Incorrect]), + ets:delete(Data,Name). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% this functions creates the page that shows the unstarted tools %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +reload_started_apps()-> + "". + +show_unstarted_apps(State)-> + " + + +
+
+ + + + + + + + +
Available Tools
+ + "++ list_available_apps(State)++" + + + + +
 
+ +
+
+ To Start a Tool: +
    +
  • Select the + checkbox for each tool to + start.
  • +
  • Click on the + button marked Start.
+
+
+
 
". + + + +list_available_apps(State)-> + MS = ets:fun2ms(fun({Tool,{web_data,{Name,_}}}) -> {Tool,Name} end), + Unstarted_apps= + lists:filter( + fun({Tool,_})-> + false==lists:member(Tool,State#state.started) + end, + ets:select(State#state.app_data,MS)), + case Unstarted_apps of + []-> + "All tools are started"; + _-> + list_apps(Unstarted_apps) + end. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% these functions creates the page that shows the started apps %% +%% the user can select to shutdown %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +show_started_apps(State)-> + " + + +
+
+ + + + + + + + +
Started Tools
+ + "++ list_started_apps(State)++" + + + + +
 
+ +
+
+ Stop a Tool: +
    +
  • Select the + checkbox for each tool to + stop.
  • +
  • Click on the + button marked Stop.
+
+
+
 
". + +list_started_apps(State)-> + MS = lists:map(fun(A) -> {{A,{web_data,{'$1','_'}}},[],[{{A,'$1'}}]} end, + State#state.started), + Started_apps= ets:select(State#state.app_data,MS), + case Started_apps of + []-> + "No tool is started yet."; + _-> + list_apps(Started_apps) + end. + + +list_apps(Apps) -> + lists:map(fun({Tool,Name})-> + " + + " ++ Name ++ " + " + end, + Apps). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% %% +%% Collecting the data from the *.tool files %% +%% %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%---------------------------------------- +% get_tools(Dirs) => [{M,F,A},{M,F,A}...{M,F,A}] +% Dirs - [string()] Directory names +% Calls get_tools2/2 recursively for a number of directories +% to retireve the configuration data for the web based tools. +%---------------------------------------- +get_tools1(Dirs)-> + get_tools1(Dirs,[]). + +get_tools1([Dir|Rest],Data) when is_list(Dir) -> + Tools=case filename:basename(Dir) of + %% Dir is an 'ebin' directory, check in '../priv' as well + "ebin" -> + [get_tools2(filename:join(filename:dirname(Dir),"priv")) | + get_tools2(Dir)]; + _ -> + get_tools2(Dir) + end, + get_tools1(Rest,[Tools|Data]); + +get_tools1([],Data) -> + lists:flatten(Data). + +%---------------------------------------- +% get_tools2(Directory) => DataList +% DataList : [WebTuple]|[] +% WebTuple: {tool,[{web,M,F,A}]} +% +%---------------------------------------- +get_tools2(Dir)-> + get_tools2(tool_files(Dir),[]). + +get_tools2([ToolFile|Rest],Data) -> + case get_tools3(ToolFile) of + {tool,WebData} -> + get_tools2(Rest,[{tool,WebData}|Data]); + {error,_Reason} -> + get_tools2(Rest,Data); + nodata -> + get_tools2(Rest,Data) + end; + +get_tools2([],Data) -> + Data. + +%---------------------------------------- +% get_tools3(ToolFile) => {ok,Tool}|{error,Reason}|nodata +% Tool: {tool,[KeyValTuple]} +% ToolFile - string() A .tool file +% Now we have the file get the data and sort it out +%---------------------------------------- +get_tools3(ToolFile) -> + case file:consult(ToolFile) of + {error,open} -> + {error,nofile}; + {error,read} -> + {error,format}; + {ok,[{version,"1.2"},ToolInfo]} when is_list(ToolInfo)-> + webdata(ToolInfo); + {ok,[{version,_Vsn},_Info]} -> + {error,old_version}; + {ok,_Other} -> + {error,format} + end. + + +%---------------------------------------------------------------------- +% webdata(TupleList)-> ToolTuple| nodata +% ToolTuple: {tool,[{config_func,{M,F,A}}]} +% +% There are a little unneccesary work in this format but it is extendable +%---------------------------------------------------------------------- +webdata(TupleList)-> + case proplists:get_value(config_func,TupleList,nodata) of + {M,F,A} -> + {tool,[{config_func,{M,F,A}}]}; + _ -> + nodata + end. + + +%============================================================================= +% Functions for getting *.tool configuration files +%============================================================================= + +%---------------------------------------- +% tool_files(Dir) => ToolFiles +% Dir - string() Directory name +% ToolFiles - [string()] +% Return the list of all files in Dir ending with .tool (appended to Dir) +%---------------------------------------- +tool_files(Dir) -> + case file:list_dir(Dir) of + {ok,Files} -> + filter_tool_files(Dir,Files); + {error,_Reason} -> + [] + end. + +%---------------------------------------- +% filter_tool_files(Dir,Files) => ToolFiles +% Dir - string() Directory name +% Files, ToolFiles - [string()] File names +% Filters out the files in Files ending with .tool and append them to Dir +%---------------------------------------- +filter_tool_files(_Dir,[]) -> + []; +filter_tool_files(Dir,[File|Rest]) -> + case filename:extension(File) of + ".tool" -> + [filename:join(Dir,File)|filter_tool_files(Dir,Rest)]; + _ -> + filter_tool_files(Dir,Rest) + end. + + +%%%----------------------------------------------------------------- +%%% format functions +ffunc({M,F,A}) when is_list(A) -> + io_lib:format("~w:~w(~s)\n",[M,F,format_args(A)]); +ffunc({M,F,A}) when is_integer(A) -> + io_lib:format("~w:~w/~w\n",[M,F,A]). + +format_args([]) -> + ""; +format_args(Args) -> + Str = lists:append(["~p"|lists:duplicate(length(Args)-1,",~p")]), + io_lib:format(Str,Args). diff --git a/lib/webtool/src/webtool_sup.erl b/lib/webtool/src/webtool_sup.erl new file mode 100644 index 0000000000..e299272c20 --- /dev/null +++ b/lib/webtool/src/webtool_sup.erl @@ -0,0 +1,74 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2001-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +-module(webtool_sup). + +-behaviour(supervisor). + +%% External exports +-export([start_link/0,stop/1]). + +%% supervisor callbacks +-export([init/1]). + +%%%---------------------------------------------------------------------- +%%% API +%%%---------------------------------------------------------------------- +start_link() -> + supervisor:start_link({local,websup},webtool_sup, []). + +stop(Pid)-> + exit(Pid,normal). +%%%---------------------------------------------------------------------- +%%% Callback functions from supervisor +%%%---------------------------------------------------------------------- + +%%---------------------------------------------------------------------- +%% Func: init/1 +%% Returns: {ok, {SupFlags, [ChildSpec]}} | +%% ignore | +%% {error, Reason} +%%---------------------------------------------------------------------- +init(_StartArgs) -> + %%Child1 = + %%Child2 ={webcover_backend,{webcover_backend,start_link,[]},permanent,2000,worker,[webcover_backend]}, + %%{ok,{{simple_one_for_one,5,10},[Child1]}}. + {ok,{{one_for_one,100,10},[]}}. + +%%%---------------------------------------------------------------------- +%%% Internal functions +%%%---------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + diff --git a/lib/webtool/vsn.mk b/lib/webtool/vsn.mk new file mode 100644 index 0000000000..8124b16816 --- /dev/null +++ b/lib/webtool/vsn.mk @@ -0,0 +1,2 @@ +WEBTOOL_VSN=0.8.5 + -- cgit v1.2.3