Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cezary-marczak committed Jun 24, 2024
1 parent 7a24614 commit 35f2db3
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 84 deletions.
45 changes: 40 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ RUN apk add --no-cache \
openssl1.1-compat-dev \
pango-dev \
pulseaudio-dev \
util-linux-dev \
ffmpeg-dev \
krb5-libs \
krb5 \
krb5-dev \
libgss \
krb5-conf \
util-linux-dev

# Copy source to container for sake of build
ARG BUILD_DIR=/tmp/guacamole-server
COPY . ${BUILD_DIR}
# ARG BUILD_DIR=/tmp/guacamole-server
# COPY . ${BUILD_DIR}

#
# Base directory for installed build artifacts.
Expand Down Expand Up @@ -84,7 +91,7 @@ ARG FREERDP_OPTS="\
-DWITH_DIRECTFB=OFF \
-DWITH_FFMPEG=OFF \
-DWITH_GSM=OFF \
-DWITH_GSSAPI=OFF \
-DWITH_GSSAPI=ON \
-DWITH_IPP=OFF \
-DWITH_JPEG=ON \
-DWITH_LIBSYSTEMD=OFF \
Expand All @@ -110,7 +117,11 @@ ARG FREERDP_OPTS="\
-DWITH_XRENDER=OFF \
-DWITH_XTEST=OFF \
-DWITH_XV=OFF \
-DWITH_ZLIB=ON"
-DWITH_ZLIB=ON \
-DWITH_KRB5=ON \
-DKRB5_TRACE=/dev/stdout \
-DDEBUG_NLA=ON \
-DGSS_ROOT_FLAVOUR=MIT"

ARG GUACAMOLE_SERVER_OPTS="\
--disable-guaclog"
Expand All @@ -135,6 +146,17 @@ ARG LIBWEBSOCKETS_OPTS="\
-DLWS_WITHOUT_TEST_SERVER_EXTPOLL=ON \
-DLWS_WITH_STATIC=OFF"

# Build the dependencies for guacamole-server
ARG BUILD_DIR=/tmp/guacamole-server
RUN mkdir -p ${BUILD_DIR}/src/guacd-docker/bin

COPY ./src/guacd-docker/bin/build-deps.sh ${BUILD_DIR}/src/guacd-docker/bin
RUN ${BUILD_DIR}/src/guacd-docker/bin/build-deps.sh
RUN rm -f ${BUILD_DIR}/src/guacd-docker/bin/build-deps.sh

# Copy source to container for sake of build
COPY . ${BUILD_DIR}

# Build guacamole-server and its core protocol library dependencies
RUN ${BUILD_DIR}/src/guacd-docker/bin/build-all.sh

Expand Down Expand Up @@ -174,6 +196,12 @@ RUN apk add --no-cache \
terminus-font \
ttf-dejavu \
ttf-liberation \
ffmpeg-dev \
krb5-conf \
krb5-libs \
krb5-dev \
krb5 \
libgss \
util-linux-login && \
xargs apk add --no-cache < ${PREFIX_DIR}/DEPENDENCIES

Expand All @@ -186,6 +214,14 @@ ARG GID=10001
RUN groupadd --gid $GID guacd
RUN useradd --system --create-home --shell /sbin/nologin --uid $UID --gid $GID guacd

# Create symlinks to procyon krb5.conf and hosts
RUN mkdir -p /etc/procyon
RUN cp /etc/hosts /etc/procyon/hosts
COPY ./src/guacd-docker/krb5.conf /etc/procyon/krb5.conf

RUN ln -s /etc/procyon/krb5.conf /etc/krb5.conf
RUN ln -s /etc/procyon/hosts /etc/hosts

# Run with user guacd
USER guacd

Expand All @@ -198,4 +234,3 @@ EXPOSE 4822
# PREFIX_DIR build argument.
#
CMD /opt/guacamole/sbin/guacd -b 0.0.0.0 -L $GUACD_LOG_LEVEL -f

70 changes: 0 additions & 70 deletions src/guacd-docker/bin/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,76 +35,6 @@ export PKG_CONFIG_PATH="${PREFIX_DIR}/lib/pkgconfig"
# 128 KB (musl's default)
export LDFLAGS="$LDFLAGS -Wl,-z,stack-size=8388608"

##
## Builds and installs the source at the given git repository, automatically
## switching to the version of the source at the tag/commit that matches the
## given pattern.
##
## @param URL
## The URL of the git repository that the source should be downloaded from.
##
## @param PATTERN
## The Perl-compatible regular expression that the tag must match. If no
## tag matches the regular expression, the pattern is assumed to be an
## exact reference to a commit, branch, etc. acceptable by git checkout.
##
## @param ...
## Any additional command-line options that should be provided to CMake or
## the configure script.
##
install_from_git() {

URL="$1"
PATTERN="$2"
shift 2

# Calculate top-level directory name of resulting repository from the
# provided URL
REPO_DIR="$(basename "$URL" .git)"

# Allow dependencies to be manually omitted with the tag/commit pattern "NO"
if [ "$PATTERN" = "NO" ]; then
echo "NOT building $REPO_DIR (explicitly skipped)"
return
fi

# Clone repository and change to top-level directory of source
cd /tmp
git clone "$URL"
cd $REPO_DIR/

# Locate tag/commit based on provided pattern
VERSION="$(git tag -l --sort=-v:refname | grep -Px -m1 "$PATTERN" \
|| echo "$PATTERN")"

# Switch to desired version of source
echo "Building $REPO_DIR @ $VERSION ..."
git -c advice.detachedHead=false checkout "$VERSION"

# Configure build using CMake or GNU Autotools, whichever happens to be
# used by the library being built
if [ -e CMakeLists.txt ]; then
cmake -DCMAKE_INSTALL_PREFIX:PATH="$PREFIX_DIR" "$@" .
else
[ -e configure ] || autoreconf -fi
./configure --prefix="$PREFIX_DIR" "$@"
fi

# Build and install
make && make install

}

#
# Build and install core protocol library dependencies
#

install_from_git "https://github.com/FreeRDP/FreeRDP" "$WITH_FREERDP" $FREERDP_OPTS
install_from_git "https://github.com/libssh2/libssh2" "$WITH_LIBSSH2" $LIBSSH2_OPTS
install_from_git "https://github.com/seanmiddleditch/libtelnet" "$WITH_LIBTELNET" $LIBTELNET_OPTS
install_from_git "https://github.com/LibVNC/libvncserver" "$WITH_LIBVNCCLIENT" $LIBVNCCLIENT_OPTS
install_from_git "https://github.com/warmcat/libwebsockets" "$WITH_LIBWEBSOCKETS" $LIBWEBSOCKETS_OPTS

#
# Build guacamole-server
#
Expand Down
106 changes: 106 additions & 0 deletions src/guacd-docker/bin/build-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/sh -e
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

##
## @fn build-all.sh
##
## Builds the source of guacamole-server and its various core protocol library
## dependencies.
##

# Pre-populate build control variables such that the custom build prefix is
# used for C headers, locating libraries, etc.
export CFLAGS="-I${PREFIX_DIR}/include"
export LDFLAGS="-L${PREFIX_DIR}/lib"
export PKG_CONFIG_PATH="${PREFIX_DIR}/lib/pkgconfig"

# Ensure thread stack size will be 8 MB (glibc's default on Linux) rather than
# 128 KB (musl's default)
export LDFLAGS="$LDFLAGS -Wl,-z,stack-size=8388608"

##
## Builds and installs the source at the given git repository, automatically
## switching to the version of the source at the tag/commit that matches the
## given pattern.
##
## @param URL
## The URL of the git repository that the source should be downloaded from.
##
## @param PATTERN
## The Perl-compatible regular expression that the tag must match. If no
## tag matches the regular expression, the pattern is assumed to be an
## exact reference to a commit, branch, etc. acceptable by git checkout.
##
## @param ...
## Any additional command-line options that should be provided to CMake or
## the configure script.
##
install_from_git() {

URL="$1"
PATTERN="$2"
shift 2

# Calculate top-level directory name of resulting repository from the
# provided URL
REPO_DIR="$(basename "$URL" .git)"

# Allow dependencies to be manually omitted with the tag/commit pattern "NO"
if [ "$PATTERN" = "NO" ]; then
echo "NOT building $REPO_DIR (explicitly skipped)"
return
fi

# Clone repository and change to top-level directory of source
cd /tmp
git clone "$URL"
cd $REPO_DIR/

# Locate tag/commit based on provided pattern
VERSION="$(git tag -l --sort=-v:refname | grep -Px -m1 "$PATTERN" \
|| echo "$PATTERN")"

# Switch to desired version of source
echo "Building $REPO_DIR @ $VERSION ..."
git -c advice.detachedHead=false checkout "$VERSION"

# Configure build using CMake or GNU Autotools, whichever happens to be
# used by the library being built
if [ -e CMakeLists.txt ]; then
cmake -DCMAKE_INSTALL_PREFIX:PATH="$PREFIX_DIR" "$@" .
else
[ -e configure ] || autoreconf -fi
./configure --prefix="$PREFIX_DIR" "$@"
fi

# Build and install
make && make install

}

#
# Build and install core protocol library dependencies
#

install_from_git "https://github.com/FreeRDP/FreeRDP" "$WITH_FREERDP" $FREERDP_OPTS
install_from_git "https://github.com/libssh2/libssh2" "$WITH_LIBSSH2" $LIBSSH2_OPTS
install_from_git "https://github.com/seanmiddleditch/libtelnet" "$WITH_LIBTELNET" $LIBTELNET_OPTS
install_from_git "https://github.com/LibVNC/libvncserver" "$WITH_LIBVNCCLIENT" $LIBVNCCLIENT_OPTS
install_from_git "https://github.com/warmcat/libwebsockets" "$WITH_LIBWEBSOCKETS" $LIBWEBSOCKETS_OPTS
7 changes: 7 additions & 0 deletions src/guacd-docker/krb5.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[libdefaults]
dns_lookup_kdc = true
dns_lookup_realm = true

[realms]

[domain_realm]
2 changes: 1 addition & 1 deletion src/guacd/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* within this period of time, the associated process will be forcibly
* terminated.
*/
#define GUACD_CLIENT_FREE_TIMEOUT 5
#define GUACD_CLIENT_FREE_TIMEOUT 600

/**
* Process information of the internal remote desktop client.
Expand Down
4 changes: 2 additions & 2 deletions src/guacenc/ffmpeg-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ int guacenc_avcodec_encode_video(guacenc_video* video, AVFrame* frame) {
#endif
}

AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodec* codec,
AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, const AVCodec* codec,
int bitrate, int width, int height, int gop_size, int qmax, int qmin,
int pix_fmt, AVRational time_base) {

Expand Down Expand Up @@ -249,7 +249,7 @@ AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodec* codec,
}

int guacenc_open_avcodec(AVCodecContext *avcodec_context,
AVCodec *codec, AVDictionary **options,
const AVCodec *codec, AVDictionary **options,
AVStream* stream) {

int ret = avcodec_open2(avcodec_context, codec, options);
Expand Down
4 changes: 2 additions & 2 deletions src/guacenc/ffmpeg-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int guacenc_avcodec_encode_video(guacenc_video* video, AVFrame* frame);
* The pointer to the configured AVCodecContext.
*
*/
AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodec* codec,
AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, const AVCodec* codec,
int bitrate, int width, int height, int gop_size, int qmax, int qmin,
int pix_fmt, AVRational time_base);

Expand Down Expand Up @@ -158,7 +158,7 @@ AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodec* codec,
* Zero on success, a negative value on error.
*/
int guacenc_open_avcodec(AVCodecContext *avcodec_context,
AVCodec *codec, AVDictionary **options,
const AVCodec *codec, AVDictionary **options,
AVStream* stream);

#endif
Expand Down
4 changes: 2 additions & 2 deletions src/guacenc/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
guacenc_video* guacenc_video_alloc(const char* path, const char* codec_name,
int width, int height, int bitrate) {

AVOutputFormat *container_format;
const AVOutputFormat *container_format;
AVFormatContext *container_format_context;
AVStream *video_stream;
int ret;
Expand All @@ -63,7 +63,7 @@ guacenc_video* guacenc_video_alloc(const char* path, const char* codec_name,
container_format = container_format_context->oformat;

/* Pull codec based on name */
AVCodec* codec = avcodec_find_encoder_by_name(codec_name);
const AVCodec* codec = avcodec_find_encoder_by_name(codec_name);
if (codec == NULL) {
guacenc_log(GUAC_LOG_ERROR, "Failed to locate codec \"%s\".",
codec_name);
Expand Down
19 changes: 18 additions & 1 deletion src/libguac/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,24 @@ void guac_client_free(guac_client* client) {
guac_client_log(client, GUAC_LOG_ERROR, "Unable to close plugin: %s", dlerror());
}

pthread_rwlock_destroy(&(client->__users_lock));
if (client->recording_path != NULL) {
// sleep(1);
char command[3000];
snprintf(command, sizeof(command), "touch %s.m4v.lock", client->recording_path);
guac_client_log(client, GUAC_LOG_INFO, "Running command \"%s\"", command);
system(command);

snprintf(command, sizeof(command), "/opt/guacamole/bin/guacenc -s 1920x1080 -f %s", client->recording_path);
guac_client_log(client, GUAC_LOG_INFO, "Running command \"%s\"", command);
system(command);

snprintf(command, sizeof(command), "rm %s.m4v.lock", client->recording_path);
guac_client_log(client, GUAC_LOG_INFO, "Running command \"%s\"", command);
system(command);

free(client->recording_path);
}

free(client->connection_id);
free(client);
}
Expand Down
1 change: 1 addition & 0 deletions src/libguac/guacamole/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

struct guac_client {

char* recording_path;
/**
* The guac_socket structure to be used to communicate with all connected
* web-clients (users). Unlike the user-level guac_socket, this guac_socket
Expand Down
Loading

0 comments on commit 35f2db3

Please sign in to comment.