Use PHP exec shell (codesign) resign IPA on Mac - php

I wrote some code to package channel IPA and resign IPA with shell. When I run this shell in command line it works ok.
Main shell code:
#!/bin/bash
name=$1
needchannel=$2
appName="$name.app"
ipa="$name.ipa"
plistName="${name}_${needchannel}.plist"
# echo "${1} ${2} $ipa"
if [ ! -f "./Payload" ];then
# echo "not exit Payload"
unzip $ipa
chmod -R 0777 Payload
else
echo "exit Payload"
fi
cd Payload
cd $appName
ipaPath="${name}_${needchannel}.ipa"
/usr/libexec/PlistBuddy -c "set Channel $needchannel" "Channel.plist"
cd ../..
/usr/bin/codesign -f -s "iPhone Distribution: xxxx, ooo" --entitlements entitlements.plist "Payload/${appName}"
zip -rq "./app/${ipaPath}" "Payload"
PHP code:
<?php
$webid = $_GET["webid"];
$appfinder = "./app/";
$filename = "Channel_".$webid.".ipa";
if (!file_exists($appfinder.$filename))
{
$shell = "sh produceApp.sh Channel $webid";
system($shell, $status);
if( $status ){
echo "produceApp error";
var_dump($status);
return;
}
}
?>
I don't know why the shell run success in command line and fail in PHP.
Can anybody help me.
Everything works except codesign.
ps:i write the shell code in php,run directly,system() return 1;like this:
<?php
$shell = "/usr/bin/codesign -f -s \"iPhone Distribution: xxx, ooo\" --entitlements entitlements.plist \"Payload/Channel.app\"";
echo "$shell";
echo "<br>";
system($shell, $status);
print_r($status);
?>
the chrome show shell is:
/usr/bin/codesign -f -s "iPhone Distribution: xxx, ooo" --entitlements entitlementds.plist "Payload/Channel.app"
and function system() return $status is 1..
web show result of system run codesign...

The problem is in path! Log the path when you run php and correct it.

Related

Can't Use ImageMagick (convert) command in PHP

I want to edit images using ImageMagick and PHP on my website.
I'm on Linux (Raspbian OS) and have PHP and ImageMagick installed.
I'm trying to do something similar to: `convert test.png test.webp` using PHP. All work in the Terminal.
What I've tried:
putenv("PATH=/usr/local/bin:/usr/bin:/bin");
Full command path "/usr/bin/convert test.png test.webp" (Work in Terminal)
All of the PHP CMD commands including: exec() shell_exec() system() passthru()
(All of the output of those were empty, but simple commands like echo $PWD worked)
Images Full Path "convert /home/pi/www/test.png /home/pi/www/test.webp" (And all of the above variations)
Any help in hugely appreciated!
Use 2>&1 in php shell_exec command and try this code;
$file = "/home/pi/www/test.png";
$dest = "/home/pi/www/test.webp";
$result = '';
$file_extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if(extension_loaded("cwebp") || extension_loaded('gif2webp')) {
if($file_extension=="png" or $file_extension=="jpg" or $file_extension=="jpeg"){
$result = shell_exec("cwebp -q 80 ".escapeshellarg($file)." -o ".escapeshellarg($dest) . " 2>&1");
}
if($file_extension=="gif"){
$result = shell_exec("gif2webp -q 80 ".escapeshellarg($file)." -o ".escapeshellarg($dest) . " 2>&1");
}
} else if(extension_loaded("gmagick") || extension_loaded('imagick')) {
if($file_extension=="png" or $file_extension=="jpg" or $file_extension=="jpeg" or $file_extension=="gif"){
$result = shell_exec("convert ".escapeshellarg($file)." -quality 80 -define webp:lossless=true ".escapeshellarg($dest) . " 2>&1");
}
} else {
die("Does not have any webp library!");
}
echo $result;
I don't know your version of Imagick, some arguments may vary by version, but it might give some idea for your code.
You have also an imagick extension in PHP: https://www.php.net/manual/fr/book.imagick.php

php exec command with azure cli always return null

On a server Apache which runs PHP, I have a command which always return null.
exec("az storage container exists --account-name $accountName
--account-key $key --name $containeurName", $output);
I modified the sudoers file but it didn't change anything:
www-data ALL=(ALL) NOPASSWD: /usr/bin/az
Thanks for your help.
Use exec($your_command, $output, $error_code) and see what $error_code contains. It may just be because az isn't in the PATH env variable in PHP.
Try to put the full path to your executable, typically something like this:
<?php
// A default path in case "which az" doesn't work.
define('AZ_DEFAULT_PATH', '/usr/bin/az');
// Find the path to az with the "which" command.
$az_path = exec('which az');
if ($az_path === false) {
$az_path = AZ_DEFAULT_PATH;
}
// Sanitize your variables to avoid shell injection and build the command.
$cmd = $az_path .
"storage container exists --account-name $accountName " .
"--account-key $key --name $containeurName";
$last_line = exec($cmd, $full_output, $error_code);
// Then check if $last_line !== false and check $error_code to see
// what happened.
var_export([
'$cmd' => $cmd,
'$last_line' => $last_line,
'$full_output' => $full_output,
'$error_code' => $error_code,
]);

Php exec command pdftoimage not work

I have problem with my code.
My Code look like this:
$destinationFolder = $destinationRootFolder . '/';
// mkdir($destinationFolder,777);
$options = $this->buildOptions($saveAsJpeg, $inputPdf, $destinationFolder);
print_r($options);
// exit;
try {
$command = "/usr/bin/pdfimages ".$options[0]." ".$options[1]." ".$options[2];
echo $command;
// exit;
shell_exec($command);
exec($command);
// $command;
// echo $r;
} catch (ExecutionFailureException $e) {
throw new RuntimeException('PdfImages was unable to extract images', $e->getCode(), $e);
}
code entered first command before it executes it. When the copy command to the console everything works well but does not create php files png.
edit
root#mat-K50AB:~# php -a
Interactive mode enabled
php > ls
php > exec("/usr/bin/pdfimages -png /path/pdf/file.pdf /tmp/savefile/")
php > shell_exec("/usr/bin/pdfimages -png /path/pdf/file.pdf /tmp/savefile/")
php >
It also does not work
It sounds like the apache does not have permissions to run it, A few things to check
1) ( if CentOS/RHEL ) Is selinux stoping it, TO temporarly disable it
setenforce 0
Perminetly allow it ( Replace /usr/bin/pdfimages with all files that need access )
chcon -v --type=httpd_sys_content_t /usr/bin/pdfimages
2) Not executible by apache, Try
chmod +x /usr/bin/pdfimages
If nether of thoughs work, What os is your server running?

exec pdfimages in PHP

I have full root access through VPS (CentOS).
In Unix shell I am able to extract images with following command:
pdfimages -j xyz.pdf images
But I am unable to execute the command through PHP
exec ("pdfimages -j xyz.pdf images");
xpdf is installed. Also I have checked that // Exec function exists; // Exec is not disabled; // Safe Mode is not on.. by using following code:
$exec_enabled =
function_exists('exec') &&
!in_array('exec', array_map('trim', explode(', ', ini_get('disable_functions')))) &&
strtolower(ini_get('safe_mode')) != 1;
if($exec_enabled) { echo "enabled"; }
The following is however getting executed properly:
exec("ls -1 *.php", $output);
foreach ($output as &$tmp){
echo "$tmp<br>";
}
What am I doing wrong? Where is the issue?
You need to specify the path like below , this will save each image in the folder of your PDF.
'image' is just the file name ..
$path = 'path/to/your/folder/';
$pdf = $path.'xyz.pdf';
$command = 'pdfimages -j '.$pdf.' '.$path.'image';
exec($command);

shell script works fully in terminal but not when run by php

I have a shell script that uses unoconv and then pdftk. when i run the script through the command line it works exactly how i want it to. When i use shell_exec($cmd) in php with the same exact command it runs the script (i know because of the echo's in the script) but it looks like it does not use unoconv (and therefore cannot use pdftk). Any idea on how to troubleshoot this problem? here some code:
if(isset($_FILES["file"]["name"]) && !empty($_FILES["file"]["name"])){
$fname = $_FILES["file"]["name"];
$tmp_name = $_FILES["file"]["tmp_name"];
$dir = "powerpoints/".$name."/";
$ispdf = "1";
$output = shell_exec('mkdir '.$dir);
chmod($dir, 0777);
echo $output;
if(move_uploaded_file($tmp_name, $dir.$fname)){
chmod($dir.$fname, 0777);
$cmd = 'importppt.sh '.$name.' '.str_replace(".ppt", "", $fname);
echo "\n".$cmd;
$output = shell_exec($cmd);
echo $output;
}else{
$message = "move_uploaded_file() Failed";
}
and here is the shell script
#!/bin/bash
echo $1 ' is the argument:' $2 ' is the second '
STRING="/var/www/html/devclassroomproject/powerpoints/"
echo $STRING$1/$2'.ppt '
unoconv $STRING$1/$2'.ppt'
pdftk $STRING$1/$2'.pdf' burst output $STRING$1/$1'_%2d.pdf'
This is what is printed from echos:
importppt.sh pptest pptestpptest is the argument: pptest is the second
/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt
edit:
to decipher my debugging
the command: "importppt.sh pptest pptest"
importppt.sh being the shell script; pptest is the first and second argument
printed by the first echo in the shell script: "pptest is the argument: pptest is the second"
printed by the second echo in the script verifying the complete path of the pdf which does exist: "/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt"
sorry for the confusion
Found out what was wrong. the answer is here
http://johnparsons.net/index.php/2013/08/05/how-to-keep-unoconv-apache-from-making-you-sad/
basically you have to set up a home directory for the user for apache2 as www-data and change the path to the shell in the passwd file
he doesnt mention it but the changes will not work unless you restart apache

Categories