2015-03-04 17:14:04 -06:00
|
|
|
LibreOffice On-Line WebSocket server
|
2015-04-21 05:48:17 -05:00
|
|
|
====================================
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-04-23 07:53:41 -05:00
|
|
|
Dependencies
|
2015-04-21 05:48:17 -05:00
|
|
|
------------
|
|
|
|
|
|
|
|
LibreOffice On-Line WebSocket server has the following dependencies:
|
|
|
|
|
|
|
|
* libpng
|
|
|
|
* Poco library: http://pocoproject.org/index.html.
|
2015-04-23 07:53:41 -05:00
|
|
|
* libcap-progs
|
2015-04-21 05:48:17 -05:00
|
|
|
|
|
|
|
Poco can be built with ./configure --prefix=/opt/poco && make install, but
|
|
|
|
distro packages exist too.
|
|
|
|
|
|
|
|
On openSUSE, you can use:
|
|
|
|
|
|
|
|
zypper ar http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_13.2/devel:libraries:c_c++.repo
|
2015-04-23 07:53:41 -05:00
|
|
|
zypper in poco-devel libcap-progs
|
2015-04-21 05:48:17 -05:00
|
|
|
|
2016-03-23 08:23:41 -05:00
|
|
|
On Debian 8 (Linux x86_64) you can use in /etc/apt/sources.list:
|
|
|
|
|
|
|
|
deb https://www.collaboraoffice.com/apt-poco/ /
|
|
|
|
|
2015-04-21 05:48:17 -05:00
|
|
|
Building
|
|
|
|
--------
|
|
|
|
|
|
|
|
loolwsd uses autoconf/automake, so build using the usual:
|
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
MASTER=/path/to/built/core.git # configure for your system
|
|
|
|
|
2015-04-21 05:48:17 -05:00
|
|
|
autoreconf
|
|
|
|
automake --add-missing
|
2015-04-27 03:44:59 -05:00
|
|
|
./configure --enable-silent-rules --with-lokit-path=${MASTER}/include
|
2015-04-21 05:48:17 -05:00
|
|
|
make
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
where ${MASTER} is the location of the LibreOffice source tree.
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2016-02-17 04:43:03 -06:00
|
|
|
Run 'make check' after each commit. Requires loolwsd to be running.
|
|
|
|
|
2015-04-22 07:50:09 -05:00
|
|
|
Note that the loolwsd program needs the CAP_SYS_CHROOT capability,
|
|
|
|
thus you will be asked the root password when running make as it
|
|
|
|
invokes sudo to run /sbin/setcap.
|
|
|
|
|
2015-04-21 05:48:17 -05:00
|
|
|
If you have self-built Poco, add the following to ./configure:
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-04-23 06:44:41 -05:00
|
|
|
--with-poco-includes=<POCOINST>/include --with-poco-libs=<POCOINST>/lib
|
|
|
|
|
|
|
|
where <POCOINST> means the Poco installation location.
|
2015-03-18 08:36:27 -05:00
|
|
|
|
2015-04-21 07:24:28 -05:00
|
|
|
If you have the Poco debugging libraries (eg. you have a self-built
|
|
|
|
Poco), you can add --enable-debug to the configure options for
|
|
|
|
additional debugging.
|
2015-03-09 04:30:56 -05:00
|
|
|
|
|
|
|
For Windows, a proper VS2013 project is needed.
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-04-21 07:24:28 -05:00
|
|
|
There is still unconditional debugging output etc. This is a work in
|
|
|
|
progress.
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-04-21 05:48:17 -05:00
|
|
|
Running
|
|
|
|
-------
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-04-24 09:45:57 -05:00
|
|
|
First create the directory used for caching tiles. It is set as
|
|
|
|
"${localstatedir}/cache/${PACKAGE}" in the configure.ac, so if you did
|
|
|
|
not pass any switch to the configure script that affects
|
|
|
|
"localstatedir, it will be /usr/local/var/cache/loolwsd . If you did
|
|
|
|
pass such a switch, like --prefix, check config.h for the exact value.
|
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
If you're using the defaults you'll need to:
|
|
|
|
|
|
|
|
sudo mkdir -p /usr/local/var/cache/loolwsd
|
|
|
|
sudo chown `whoami` /usr/local/var/cache/loolwsd
|
|
|
|
|
2015-04-23 10:24:22 -05:00
|
|
|
Now you need to set up a minimal chroot system, and directory for the jails:
|
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
SYSTEMPLATE=`pwd`/systemplate # or tweak for your system
|
|
|
|
ROOTFORJAILS=`pwd`/jails # or tweak for your system
|
|
|
|
|
2015-04-27 04:00:31 -05:00
|
|
|
rm -Rf ${SYSTEMPLATE} # clean
|
2015-05-19 05:20:16 -05:00
|
|
|
./loolwsd-systemplate-setup ${SYSTEMPLATE} ${MASTER}/instdir # build template
|
2015-04-27 04:00:31 -05:00
|
|
|
mkdir -p ${ROOTFORJAILS} # create location for transient jails.
|
2015-04-23 10:24:22 -05:00
|
|
|
|
|
|
|
To run loolwsd the way it is supposed to eventually be run "for real", you can
|
|
|
|
now do:
|
2015-04-21 05:48:17 -05:00
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
./loolwsd --systemplate=${SYSTEMPLATE} --lotemplate=${MASTER}/instdir --childroot=${ROOTFORJAILS}
|
2015-04-21 05:48:17 -05:00
|
|
|
|
|
|
|
and connect loleaflet to that (see loleaflet/README for more info).
|
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
Again, ${MASTER} is location of the LibreOffice source tree with a built
|
2015-04-21 05:48:17 -05:00
|
|
|
LibreOffice. This is work in progress, and consequently needs the latest
|
|
|
|
LibreOffice master.
|
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
The ${SYSTEMPLATE} is a directory tree set up using the
|
2015-05-19 06:17:46 -05:00
|
|
|
loolwsd-systemplate-setup script here. (It should not exist before
|
|
|
|
running the script.) It will contain the runtime environment needed by
|
|
|
|
the LibreOffice dynamic libraries used through LibreOfficeKit.
|
|
|
|
Improvements to that script are very likely needed on various distros.
|
2015-04-14 10:30:23 -05:00
|
|
|
|
2015-04-27 03:44:59 -05:00
|
|
|
The ${ROOTFORJAILS} directory above is a presumably initially empty
|
2015-04-21 07:24:28 -05:00
|
|
|
directory under which loolwsd will create chroot jails for editing
|
|
|
|
each specific document.
|
2015-04-14 10:30:23 -05:00
|
|
|
|
2015-04-27 03:27:22 -05:00
|
|
|
As loolwsd uses hardlinks to "copy" the contents of both
|
2015-04-27 03:44:59 -05:00
|
|
|
${SYSTEMPLATE} and the ${MASTER}/instdir directories into each chroot
|
|
|
|
jail, ${SYSTEMPLATE} and ${MASTER}/instdir need to be on the same file
|
|
|
|
system as ${ROOTFORJAILS}.
|
2015-04-14 10:30:23 -05:00
|
|
|
|
2016-03-22 05:39:22 -05:00
|
|
|
Leaflet files are served itself by loolwsd internal file server. You can specify the
|
|
|
|
root of this fileserver using the --fileserverroot flag in loolwsd commandline.
|
|
|
|
By default, if you do not specify this flag, the parent directory of loolwsd/
|
|
|
|
is assumed to be the fileserverroot. So, for development purposes, you can access
|
|
|
|
the leaflet files (using /loleaflet/), but it is advised to explicitly set the
|
|
|
|
fileserverroot to prevent any unwanted files from reading, especially when lool
|
|
|
|
is deployed for normal public usage on servers.
|
|
|
|
|
|
|
|
Please note that it is necessary that all the leaflet files that are meant to be
|
|
|
|
served is under a directory named 'loleaflet'. Since, the loleaflet files, in
|
|
|
|
lool git repo, are itself in a directory named 'loleaflet', this would work out of
|
|
|
|
the box for development purposes.
|
|
|
|
|
|
|
|
loolwsd only runs on HTTPS which means you would have to set up your own private
|
|
|
|
key and certificate (in PEM format only). Currently, loolwsd assumes files with
|
|
|
|
name cert.pem, and key.pem to be certificate and private key respectively.
|
|
|
|
Dummy self-signed cert.pem and key.pem are already included, but it is better
|
|
|
|
to replace those with your own files.
|
|
|
|
|
2015-04-21 07:24:28 -05:00
|
|
|
If you plan to hack on loolwsd, you probably want to familiarize
|
|
|
|
yourself with loolwsd's --test and --numprespawns switches, and the
|
2015-04-14 10:30:23 -05:00
|
|
|
'connect' test program.
|
|
|
|
|
|
|
|
For interactive testing, you can use the loolwsd --test switch, or you
|
|
|
|
can use the 'connect' program. Both accept "commands" from the
|
2015-04-21 07:24:28 -05:00
|
|
|
protocol on standard input. You can either used them tuly
|
|
|
|
interactively, or edit input lines into a file, or use shell
|
|
|
|
scripting, etc. For instance:
|
2015-04-21 05:48:17 -05:00
|
|
|
|
2015-04-30 07:19:29 -05:00
|
|
|
(echo load /some/where/foo.odt; echo tile part=0 width=500 height=500 tileposx=0 tileposy=0 tilewidth=10000 tileheight=10000; sleep 10) |
|
2015-04-23 07:51:10 -05:00
|
|
|
./loolwsd --test --systemplate=/home/tml/lo/master/lool-sys-template --lotemplate=/home/tml/lo/master/instdir --childroot=/home/tml/lo/master/lool-child-root
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2016-03-22 05:39:22 -05:00
|
|
|
Admin Panel
|
|
|
|
-----------
|
|
|
|
|
|
|
|
You can access the admin panel by directly acessing the admin.html file from loleaflet directory.
|
|
|
|
See loleaflet/README for more details.
|
|
|
|
|
2015-04-23 10:24:22 -05:00
|
|
|
Debugging
|
|
|
|
---------
|
|
|
|
|
|
|
|
When debugging, you want to add --numprespawns=1 to the loolwsd parameters to
|
|
|
|
limit the amount of concurrently running processes.
|
|
|
|
|
|
|
|
When the crash happens too early, you also want to
|
|
|
|
|
|
|
|
export SLEEPFORDEBUGGER=<number of seconds>
|
|
|
|
|
|
|
|
so that you have time to attach to the process.
|
|
|
|
|
2015-04-28 03:14:46 -05:00
|
|
|
Then run loolwsd, and attach your debugger to the process you are
|
2015-07-20 14:19:20 -05:00
|
|
|
interested in. Note that as the loolwsd executable file has
|
|
|
|
capabilities set, you need to run the debugger with super-user
|
|
|
|
privilege.
|
2015-04-28 03:14:46 -05:00
|
|
|
|
|
|
|
Also, note that as the child processes run in a chroot environment,
|
|
|
|
they see the LibreOffice shared libraries as being in a directory tree
|
|
|
|
/lo , but your debugger does not. So in order to be able to
|
|
|
|
effectively debug the LibreOffice code as used through LibreOfficeKit
|
|
|
|
by a child loolwsd process, you need to symlink the "lo" subdirectory
|
|
|
|
of a running child loolwsd process's chroot jail as /lo. Something like:
|
|
|
|
|
|
|
|
sudo ln -s ~/libreoffice/master/lool-child-roots/1046829984599121011/lo /lo
|
|
|
|
|
|
|
|
Use the ps command to find out exactly the path to use.
|
2015-04-21 05:48:17 -05:00
|
|
|
|
2016-01-10 21:13:32 -06:00
|
|
|
Set LOOL_DEBUG=1 to trap SIGSEGV and SEGBUS and prompt for debugger.
|
|
|
|
|
2015-04-21 05:48:17 -05:00
|
|
|
Protocol description
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
See protocol.txt for a description of the protocol to be used over the
|
|
|
|
websocket.
|
2015-04-24 06:34:43 -05:00
|
|
|
|
2016-01-06 23:41:32 -06:00
|
|
|
Architecture
|
|
|
|
------------
|
|
|
|
|
|
|
|
There are three processes: LoolWSD, LoolBroker, and LoolKit.
|
|
|
|
|
|
|
|
WSD is the top-level server and is intended to run as a service.
|
|
|
|
It is responsible for spawning Broker and listening on public
|
|
|
|
port for Client connections.
|
|
|
|
|
|
|
|
The Broker is only responsible for spawning (or forking) Kit
|
|
|
|
instances. There is only one Broker per WSD instance and
|
|
|
|
there is one Kit instance per document.
|
|
|
|
|
|
|
|
WSD listens on a public port and using internal pipes requests
|
|
|
|
the Broker to fire a child (Kit) instance to host documents.
|
|
|
|
The Broker then has to find an existing Kit that hosts that
|
|
|
|
document, based on the public URI as unique key, and forward
|
|
|
|
the request to this existing Kit, which then loads a new
|
|
|
|
view to the document.
|
|
|
|
|
2016-03-21 14:32:45 -05:00
|
|
|
There is an additional pipe that kit processes and broker have
|
|
|
|
write access to. This pipe is 'notify' pipe. All the important
|
|
|
|
changes are notified on this pipe. The pipe is read by the admin
|
|
|
|
manager continously and it keeps updating the AdminModel object.
|
|
|
|
AdminModel object has subscribers which corresponds to admin
|
|
|
|
panel sessions. Subscriber can subscribe to specific commands
|
|
|
|
to get live notifications about, and to update the UI accordingly.
|
|
|
|
|
2016-01-06 23:41:32 -06:00
|
|
|
Whether a document is loaded for the first time, or this is
|
|
|
|
a new view on an existing one, the Kit connects via a socket
|
|
|
|
to WSD on an internal port. WSD acts as a bridge between
|
|
|
|
the Client and Kit by tunnelling the traffic between the two
|
|
|
|
sockets (that which is between the Client and WSD and the one
|
|
|
|
between WSD and Kit).
|
|
|
|
|
|
|
|
File System
|
|
|
|
-----------
|
|
|
|
|
|
|
|
WSD is given childroot argument on the command line. This is
|
|
|
|
the root directory of jailed FS. This path can be anywhere, but
|
|
|
|
here we'll designate it as:
|
|
|
|
|
|
|
|
/childroot
|
|
|
|
|
|
|
|
Before spawning a Broker instance, WSD needs to generate a random
|
|
|
|
Jail-ID to use as the jail directory name. This JailID is then
|
|
|
|
passed to Broker as argument jailid.
|
|
|
|
|
|
|
|
Note: for security reasons, this directory name is randomly generated
|
|
|
|
and should not be given out to the Client. Since there is only one
|
|
|
|
Broker per WSD instance, there is also one JailID between them.
|
|
|
|
|
|
|
|
The Broker creates a chroot in this directory (the jail directory):
|
|
|
|
|
|
|
|
/childroot/jailid/
|
|
|
|
|
|
|
|
Broker copies the LO instdir (essentially installs LO in the chroot),
|
|
|
|
then copies the Kit binary into the jail directory upon startup.
|
|
|
|
Once done, it chroot-s and drops caps.
|
|
|
|
|
|
|
|
Broker then waits on a read pipe to which WSD writes when a new
|
|
|
|
request from a Client is received. Broker is responsible for spawning
|
|
|
|
(or forking) Kit instances. For our purposes, it doesn't matter
|
|
|
|
whether Kit is spawned or forked.
|
|
|
|
|
|
|
|
Every document is hosted by a Kit instance. Each document is stored
|
|
|
|
in a dedicated directory within the jail directory. The document
|
|
|
|
root within the jail is /user/docs. The absolute path on the system
|
|
|
|
(which isn't accessible to the Kit process as it's jailed) is:
|
|
|
|
|
|
|
|
/childroot/jailid/user/docs
|
|
|
|
|
|
|
|
Within this path, each document gets its own sub-directory based on
|
|
|
|
another random Child-ID (which could be the Process ID of the Kit).
|
|
|
|
This ChildId will be given out to Clients to facilitate the insertion
|
|
|
|
and downloading of documents. (Although strictly speaking the Client
|
|
|
|
can use the main document URI as key, this is the current design.)
|
|
|
|
|
|
|
|
/childroot/jailid/user/docs/childid
|
|
|
|
|
|
|
|
|
|
|
|
A request from a Client to load a document will trigger the following
|
|
|
|
chain of events.
|
|
|
|
|
|
|
|
- WSD public socket will receive the connection request followed
|
|
|
|
by a "load" command.
|
|
|
|
- WSD creates MasterProcessSession (ToClient) to handle the client traffic.
|
|
|
|
- MasterProcessSession requests Broker to find or spawn Kit for
|
|
|
|
the given URI.
|
|
|
|
- Broker sends Kit request to host URI via pipe.
|
|
|
|
- Kit connects to WSD on an internal port.
|
|
|
|
- WSD creates another MasterProcessSession (ToPrisoner) to service Kit.
|
|
|
|
- MasterProcessSession (ToClient) is linked to the ToPrisoner instance,
|
|
|
|
copies the document into jail (first load only) and sends
|
|
|
|
(via ToPrisoner) the load request to Kit.
|
|
|
|
- Kit loads the document and sets up callbacks with LOKit.
|
|
|
|
- MasterProcessSession (ToClient) and MasterProcessSession (ToPrisoner)
|
|
|
|
tunnel the traffic between Client and Kit both ways.
|
|
|
|
|
|
|
|
|
2015-04-24 06:34:43 -05:00
|
|
|
Coding style
|
|
|
|
------------
|
|
|
|
|
|
|
|
There is not really any serious rationale why the code ended up being
|
|
|
|
written in the style it is... but unless you plan to change some style
|
|
|
|
detail completely and consistenly all over, please keep to the style
|
|
|
|
of the existing code when editing.
|
|
|
|
|
|
|
|
The style is roughly as follows, in rough order of importance:
|
|
|
|
|
|
|
|
- As in LO, no hard TABs in source files. Only spaces. Indentation
|
|
|
|
step is four columns.
|
|
|
|
|
|
|
|
- As in LO, the braces { and } of the block of if, switch, and while
|
|
|
|
statements go on separate lines.
|
|
|
|
|
2016-01-15 00:40:51 -06:00
|
|
|
- Following Poco conventions, non-static member variables are prefixed
|
|
|
|
with an underscore. Static members have a CamelCase name.
|
2015-04-24 06:34:43 -05:00
|
|
|
|
|
|
|
- Do use C++11. I admit in some places (out of laziness or ignorance)
|
|
|
|
I use Poco API even if there probably is an equivalent std::
|
|
|
|
API. (Like for threads.) Feel free to change those, if the std:: API
|
|
|
|
is not much more verbose or ugly, and you are sure it is equivalent.
|
|
|
|
|
|
|
|
- Always prefer the C++ wrapped version of a C library
|
|
|
|
API. I.e. include <cstring> instead of <string.h>, use std::memcpy()
|
|
|
|
instead of memcpy(), etc.
|
|
|
|
|
|
|
|
- Use std:: prefix for all std API, i.e. don't ever do "using
|
|
|
|
std;". But it's OK to use "using Poco::Foo;" all over. Maybe that is
|
2016-01-06 23:41:32 -06:00
|
|
|
not a good idea? But please no "using" in headers.
|
2015-04-24 06:34:43 -05:00
|
|
|
|
|
|
|
- Member functions use camelCaseWithInitialLowerCase. I don't like
|
|
|
|
CamelCaseWithInitialUpperCase.
|
|
|
|
|
2016-02-18 04:10:48 -06:00
|
|
|
- [ No kind of Hungarian prefixes. ] This rule seems to have been
|
|
|
|
totally ignored lately. So now the codebase is inconsistent in
|
|
|
|
naming conventions. Oh well.
|