Skip to content

Commit

Permalink
initial removal of phantomjs
Browse files Browse the repository at this point in the history
  • Loading branch information
plessbd committed Aug 10, 2020
1 parent 967e0f6 commit 962978d
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 159 deletions.
10 changes: 5 additions & 5 deletions bin/xdmod-check-config
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ try {
'Javac executable configured'
);

$phantomJsPath
= xd_utilities\getConfiguration('reporting', 'phantomjs_path');
_debug('Checking for phantomjs executable');
$result = file_exists($phantomJsPath) && is_executable($phantomJsPath);
$chromiumPath
= xd_utilities\getConfiguration('reporting', 'chromium_path');
_debug('Checking for chromium executable');
$result = file_exists($chromiumPath) && is_executable($chromiumPath);
displayResult(
$result,
'PhantomJS configured'
'Chromium configured'
);

_debug('Checking for sendmail');
Expand Down
16 changes: 8 additions & 8 deletions classes/OpenXdmod/Setup/GeneralSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function handle()

$this->console->displayBlankLine();
$this->console->displayMessage(<<<"EOT"
Java and PhantomJS are required by the report generator for constructing
Java and Chromium are required by the report generator for constructing
reports. Setup will attempt to detect the presence of java, and
phantomjs on your system.
chromium-headless on your system.
EOT
);
$this->console->displayBlankLine();
Expand All @@ -95,14 +95,14 @@ public function handle()
$settings['reporting_javac_path']
);

if ($settings['reporting_phantomjs_path'] == '') {
$settings['reporting_phantomjs_path']
= exec('which phantomjs 2>/dev/null');
if ($settings['reporting_chromium_path'] == '') {
$settings['reporting_chromium_path']
= exec('ls /usr/lib64/chromium-browser/headless_shell 2>/dev/null');
}

$settings['reporting_phantomjs_path'] = $this->console->prompt(
'PhantomJS Path:',
$settings['reporting_phantomjs_path']
$settings['reporting_chromium_path'] = $this->console->prompt(
'Chromium Path:',
$settings['reporting_chromium_path']
);

$this->console->displayBlankLine();
Expand Down
2 changes: 1 addition & 1 deletion configuration/portal_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ captcha_private_key = ""
base_path = "/usr/share/xdmod/reporting/jasper_builder"
java_path = ""
javac_path = ""
phantomjs_path = ""
chromium_path = ""

[logger]
db_engine = "MySQLDB"
Expand Down
10 changes: 3 additions & 7 deletions docs/software-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Open XDMoD requires the following software:
- [mbstring][php-mbstring]
- [APCu][php-pecl-apcu]
- [Java][] 1.8 including the [JDK][]
- [PhantomJS][] 2.1+
- [Chromium][]
- [ghostscript][] 9+
- [cron][]
- [logrotate][]
Expand All @@ -49,8 +49,8 @@ Open XDMoD requires the following software:
[php-mbstring]: https://secure.php.net/manual/en/book.mbstring.php
[php-pecl-apcu]: https://www.php.net/manual/en/book.apcu.php
[java]: https://java.com/
[jdk]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
[phantomjs]: http://phantomjs.org/
[jdk]: https://www.oracle.com/java/technologies/javase-downloads.html
[chromium]: https://www.chromium.org/Home
[ghostscript]: https://www.ghostscript.com/
[cron]: https://en.wikipedia.org/wiki/Cron
[logrotate]: https://linux.die.net/man/8/logrotate
Expand Down Expand Up @@ -84,10 +84,6 @@ added with this command for CentOS 7:
mariadb-server mariadb cronie logrotate \
ghostscript php-mbstring php-pecl-apcu jq

**NOTE**: Neither the CentOS repositories nor EPEL include PhantomJS,
so that must be installed manually. Packages are available for
[download](http://phantomjs.org/download.html) from the PhantomJS
website.

**NOTE**: After installing Apache and MySQL you must make sure that they
are running. CentOS may not start these services and they will not
Expand Down
108 changes: 97 additions & 11 deletions libraries/charting.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,114 @@ function exportHighchart(
file_put_contents($tmp_html_filename,$template);

if ($format == 'png') {
\xd_phantomjs\phantomExecute(dirname(__FILE__)."/phantomjs/generate_highchart.js png $tmp_html_filename $output_image_filename $effectiveWidth $effectiveHeight");
executeChromiumScreenshot($tmp_html_filename, $output_image_filename, $effectiveWidth, $effectiveHeight);
$data = file_get_contents($output_image_filename);
@unlink($output_image_filename);
@unlink($tmp_html_filename);
return $data;
}

if ($format == 'svg') {
$svgContent = \xd_phantomjs\phantomExecute(dirname(__FILE__)."/phantomjs/generate_highchart.js svg $tmp_html_filename null ".$effectiveWidth." ".$effectiveHeight);
@unlink($tmp_html_filename);
return $svgContent;
$data = executeChromiumRepl($tmp_html_filename, 'chart.getSVG(inputChartOptions);', '.result.value', $effectiveWidth, $effectiveHeight);
}

if ($format == 'pdf') {
\xd_phantomjs\phantomExecute(dirname(__FILE__)."/phantomjs/generate_highchart.js png $tmp_html_filename $output_image_filename $effectiveWidth $effectiveHeight");
executeChromiumScreenshot($tmp_html_filename, $output_image_filename, $effectiveWidth, $effectiveHeight);
$svgData = executeChromiumRepl($tmp_html_filename, 'chart.getSVG(inputChartOptions);', '.result.value', $effectiveWidth, $effectiveHeight);
$svgFilename = $base_filename . '.svg';
file_put_contents($svgFilename, $svgData);
svg2pdf($svgFilename, $output_image_filename);
@unlink($svgFilename);
$data = getPdfWithMetadata($output_image_filename, round($width / 90.0 * 72.0), round($height / 90.0 * 72.0), $fileMetadata);
@unlink($output_image_filename);
@unlink($tmp_html_filename);
return $data;
}
@unlink($output_image_filename);
@unlink($tmp_html_filename);
return $data;
}
function executeChromiumRepl($uri, $repl, $result, $width, $height){
$command = 'echo -e "'. $repl .'" | /usr/lib64/chromium-browser/headless_shell --no-sandbox --disable-gpu --disable-software-rasterizer -repl --window-size=' . $width . ',' . $height . ' ' . $uri . ' 2>&1 | grep \'^>>> {"result":\' | cut -c4- | jq -r ' . $result;
$pipes = array();
$descriptor_spec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$process = proc_open($command, $descriptor_spec, $pipes);
if (!is_resource($process)) {
throw new \Exception('Unable execute command: "'. $command . '". Details: ' . print_r(error_get_last(), true));
}

$out = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);

fclose($pipes[1]);
fclose($pipes[2]);

$return_value = proc_close($process);

if ($return_value != 0) {
throw new \Exception("$command returned $return_value, stdout: $out stderr: $err");
}
if ($return_value != 0) {
throw new \Exception("$command returned $return_value, stdout: $out stderr: $err");
}
return $out;
}
function executeChromiumScreenshot($uri, $outputFileName, $width, $height)
{
$command = '/usr/lib64/chromium-browser/headless_shell --no-sandbox --disable-gpu --disable-software-rasterizer --screenshot=' . $outputFileName . ' --window-size=' . $width . ',' . $height . ' ' . $uri;

$pipes = array();

$descriptor_spec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);

$process = proc_open($command, $descriptor_spec, $pipes);

if (!is_resource($process)) {
throw new \Exception('Unable execute command: "'. $command . '". Details: ' . print_r(error_get_last(), true));
}

$out = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);

fclose($pipes[1]);
fclose($pipes[2]);

$return_value = proc_close($process);

if ($return_value != 0) {
throw new \Exception("$command returned $return_value, stdout: $out stderr: $err");
}

return $out;
}
function svg2pdf($inputFilename, $outputFilename){
$command = 'rsvg-convert -f pdf -o ' . $outputFilename . ' ' . $inputFilename;
$pipes = array();
$descriptor_spec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$process = proc_open($command, $descriptor_spec, $pipes);
if (!is_resource($process)) {
throw new \Exception('Unable execute command: "'. $command . '". Details: ' . print_r(error_get_last(), true));
}

$out = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);

fclose($pipes[1]);
fclose($pipes[2]);

$return_value = proc_close($process);

if ($return_value != 0) {
throw new \Exception("$command returned $return_value, stdout: $out stderr: $err");
}
return $out;
}
/**
* @param array $docmenta array with optional author, subject and title elements
* @return string valid pdfmark postscript for use by ghostscript
Expand Down
62 changes: 0 additions & 62 deletions libraries/phantomjs.php

This file was deleted.

12 changes: 0 additions & 12 deletions libraries/phantomjs/.eslintrc.json

This file was deleted.

51 changes: 0 additions & 51 deletions libraries/phantomjs/generate_highchart.js

This file was deleted.

2 changes: 2 additions & 0 deletions open_xdmod/modules/xdmod/xdmod.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Requires: mariadb >= 5.5.3
Requires: php >= 5.4 php-cli php-mysql php-pdo php-gd php-xml php-mbstring
Requires: php-pear-MDB2 php-pear-MDB2-Driver-mysql php-pecl-apcu
Requires: java-1.8.0-openjdk java-1.8.0-openjdk-devel
Requires: chromium-headless
Requires: librsvg2-tools
Requires: crontabs
Requires: logrotate
Requires: ghostscript
Expand Down
2 changes: 1 addition & 1 deletion templates/portal_settings.template
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ captcha_private_key = "[:mailer_captcha_private_key:]"
base_path = "/usr/share/xdmod/reporting/jasper_builder"
java_path = "[:reporting_java_path:]"
javac_path = "[:reporting_javac_path:]"
phantomjs_path = "[:reporting_phantomjs_path:]"
chromium_path = "[:reporting_chromium_path:]"

[logger]
db_engine = "MySQLDB"
Expand Down
2 changes: 1 addition & 1 deletion tests/ci/scripts/xdmod-setup-start.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ answerQuestion {Site Address} https://localhost/
provideInput {Email Address:} [email protected]
answerQuestion {Java Path} /usr/bin/java
answerQuestion {Javac Path} /usr/bin/javac
provideInput {PhantomJS Path:} /usr/local/bin/phantomjs
provideInput {Chromium Path:} /usr/lib64/chromium-browser/headless_shell
provideInput {Center Logo Path:} {}
provideInput {Enable Dashboard Tab*} {off}
confirmFileWrite yes
Expand Down

0 comments on commit 962978d

Please sign in to comment.