diff --git a/archlinux/PKGBUILD b/archlinux/PKGBUILD index 6d61a07..8022832 100644 --- a/archlinux/PKGBUILD +++ b/archlinux/PKGBUILD @@ -5,7 +5,7 @@ arch=(x86_64) pkgdesc=$(grep "Summary:" ./rpm_spec/qpdf-converter.spec.in | sed 's/Summary://' | xargs) url=$(git remote get-url origin) license=(GPL) -depends=(unoconv graphicsmagick zenity poppler python-nautilus) +depends=(libreoffice graphicsmagick zenity poppler python-nautilus file net-tools) build() { ln -s "$srcdir"/../ "$srcdir/src" diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +10 diff --git a/debian/control b/debian/control index 33756ce..0a317bf 100644 --- a/debian/control +++ b/debian/control @@ -2,12 +2,14 @@ Source: qubes-pdf-converter Section: admin Priority: optional Maintainer: Jason Mehring -Build-Depends: pandoc, debhelper-compat (= 10) +Build-Depends: pandoc, debhelper (>= 9) +# For the futures version of debian, delete the "compat" file, and add the line below in "Build-Depends" +# debhelper-compat (= 12) Standards-Version: 4.5.0 Homepage: https://github.com/QubesOS/qubes-app-linux-pdf-converter Package: qubes-pdf-converter Section: admin Architecture: any -Depends: poppler-utils, unoconv, graphicsmagick, python-nautilus, ${misc:Depends} +Depends: poppler-utils, net-tools, file, libreoffice, graphicsmagick, python-nautilus, ${misc:Depends} Description: The Qubes service for converting untrusted PDF files into trusted ones diff --git a/qpdf-convert-server b/qpdf-convert-server index 77f3dc1..a9ff478 100755 --- a/qpdf-convert-server +++ b/qpdf-convert-server @@ -71,12 +71,51 @@ application/pdf) done ;; *) + # Start libreoffice server + libreoffice --accept='socket,host=localhost,port=2202;urp;' --norestore --nologo --nodefault >/dev/null 2>/dev/null & + listener_notready=1 + + # Wait until libreoffice server is started + while [ $listener_notready -ne 0 ]; + do + sleep 1 + netstat -anop 2> /dev/null | grep '127.0.0.1:2202' | grep LISTEN >/dev/null 2>/dev/null + listener_notready=$? + done + + # Remove password from file using libreoffice API while [ $PASSWORD_SUCCESS -eq 0 ] ; do - unoconv --password="$PASSWORD" -o "$INPUT_FILE""unoconv" "$INPUT_FILE" >&2 + python3 -c ' +import os +import uno +from com.sun.star.beans import PropertyValue +import sys + +src="file://'"$INPUT_FILE"'" +dst="file://'"$INPUT_FILE.nopassword"'" +password="'"$PASSWORD"'" + +localContext = uno.getComponentContext() +resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext) +ctx = resolver.resolve("uno:socket,host=localhost,port=2202;urp;StarOffice.ComponentContext") +smgr = ctx.ServiceManager +desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx) + +hidden_property = PropertyValue() +hidden_property.Name = "Hidden" +hidden_property.Value = True + +password_property = PropertyValue() +password_property.Name = "Password" +password_property.Value = password + +document = desktop.loadComponentFromURL(src, "_blank", 0, (password_property, hidden_property,)) +document.storeAsURL(dst, ())' >&2 ERROR_CODE=$? - read_password $(( ERROR_CODE != 5 && ERROR_CODE != 6 )) + read_password $(( ERROR_CODE == 0 )) done - mv "$INPUT_FILE""unoconv.pdf" "$INPUT_FILE" + libreoffice --convert-to pdf "$INPUT_FILE.nopassword" --outdir /tmp/ >&2 + mv "$INPUT_FILE"".pdf" "$INPUT_FILE" ;; esac # now, let's convert it into a simple representation, diff --git a/rpm_spec/qpdf-converter.spec.in b/rpm_spec/qpdf-converter.spec.in index 2252eb4..35f2331 100644 --- a/rpm_spec/qpdf-converter.spec.in +++ b/rpm_spec/qpdf-converter.spec.in @@ -35,7 +35,7 @@ URL: https://github.com/QubesOS/qubes-app-linux-pdf-converter BuildRequires: pandoc -Requires: poppler-utils GraphicsMagick unoconv +Requires: poppler-utils GraphicsMagick libreoffice file net-tools Requires: nautilus-python Source0: %{name}-%{version}.tar.gz