前提・実現したいこと
お世話になります。
web経由(php)で、openOfficeBasicのMacroでファイルを作成したいです。
現在、ターミナルのコマンドラインのphpでは成功しています。
なので、コードの問題というよりは、apacheのセキュリティなどの問題で
web経由ではmacro実行はできないのかなと思っております。
もし回避できる方法がありましたら、ご教示ください。
centos7
apache 2.4.6
php 7.0.25
LibreOffice 5.0.6.2(soffice.bin)
発生している問題
ファイルを作成するテストプログラムにて、
・ターミナルのコマンドラインではphp実行でファイルが作成されます。
$ php test.php ⇒ ファイルが作成できる
・web経由では作成されません。
httpd://XXX/test.php ⇒ ファイルが作成できない
試したこと
SELinuxは無効です。
ファイルを作成するフォルダを0777にしてみてもダメでした。
「Module1.xba」を0755にしてみてもダメでした。
shellでは、管理者権限実行にしても変化無しでした。
openOfficeコマンドのpdfへの変換は、web経由でもファイルが作成されました。
該当のソースコード
※ shellをかましているのは、PHPから直接openOfficeコマンドが使えなかったためです。
test.php
PHP
1// 引数はshellへ渡っているかの確認用なので意味はないです 2$cmd='/usr/bin/bash openoffice_basic_macro_boot.sh calc.xls'; 3echo $cmd; 4 5$results = exec($cmd); 6echo "<pre>$results</pre>";
shell ( openoffice_basic_macro_boot.sh )
#!/bin/bash echo $1 pass="XXXXXXX" echo $pass | sudo -S /opt/libreoffice5.2/program/soffice.bin --headless "macro:///Standard.Module1.test" # ↓これはファイルが作成されます # export HOME=/tmp;/opt/libreoffice5.2/program/soffice.bin --headless --nologo --nofirststartwizard --convert-to pdf --outdir /var/www/html/test/tmp /var/www/html/test/calc.xls
openOfficeBasicのMacro ( Module1.xba )
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> <!-- * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * 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 . --> <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic"> REM ***** BASIC ***** Option VBASupport 1 ・・・ Sub test Dim objDoc As Object Dim objSheet As Object Dim objCell As Object Dim strMessage As String Dim inFile As String, outFile As String, tmpStr As String Dim filepath As String filepath= "/var/www/html/test/" inFile=ConvertToUrl( filepath+"calc1.xls") objDoc = StarDesktop.loadComponentFromURL(inFile, "_hidden", 0, Array()) objSheet = ThisComponent.Sheets.getByName("TEST_02") objSheet.getCellRangeByName("B6").Value=objSheet.getCellRangeByName("B6").Value objSheet.getCellRangeByName("A1").String= "セルへの書き込み" outFile=ConvertToUrl( filepath+"calc_to.xls" ) Dim lProperties(0) = New com.sun.star.beans.PropertyValue lProperties(0).Name = "Overwrite" lProperties(0).Value = true Dim lProperties(1)= New com.sun.star.beans.PropertyValue lProperties(1).Name = "FilterName" lProperties(1).Value = "MS Excel 97" objDoc.storeAsURL(outFile,lProperties()) 'ファイルを閉じる objDoc.close(True) End Sub ・・・ </script:module>