Skip to content

Commit

Permalink
Merge pull request lludo#8 from pcans/master
Browse files Browse the repository at this point in the history
moved name from application object to version object, add uncrush png icons
  • Loading branch information
Ludovic Landry committed Jul 17, 2011
2 parents 981107b + b593dbd commit 5434f4b
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 349 deletions.
20 changes: 16 additions & 4 deletions back/application_list.php
Expand Up @@ -25,6 +25,7 @@
Entities\Tester,
Entities\Version;

require_once __DIR__ . '/../constants.php';
require_once __DIR__ . '/../core/index.php';
require_once __DIR__ . '/../tools.php';

Expand Down Expand Up @@ -62,10 +63,21 @@

echo '<ul>';
foreach ($applications AS $application) {
echo '<li>Application: <br/>->name: ' . $application->getName() . '<br />' .
'->bundle: ' . $application->getBundleId() . '<br />' .
'->app link: <a href="' . Tools::rel2abs('../app/' . $application->getToken() . '/app_bundle.ipa', Tools::current_url()) . '">' . $application->getName() . '.ipa</a><br />' .
'->install on device: <a href="itms-services://?action=download-manifest&url=' . Tools::rel2abs('../app/' . $application->getToken() . '.plist', Tools::current_url()) . '">Install on device</a></li>' . PHP_EOL;
echo '<li>Application: <br/>'
.'->bundle name: ' . $application->getBundleName() . '<br />'
.'->bundle id: ' . $application->getBundleId() . '<br />'
.'->icon: <img src="'.'../'.UPLOAD_PATH. $application->getBundleId().'.png"><br />';

echo '<ul>';
foreach ($application->getVersions() AS $version) {
echo '<li>Version:<br/>'
.'->version: '.$version->getVersion().'<br />'
.'->date upload: '.$version->getDateUpload()->format(DEFAULT_DATETIME_FORMAT).'<br />'
.'->app link: <a href="' . Tools::rel2abs('../app/' . $version->getToken() . '/app_bundle.ipa', Tools::current_url()) . '">' . $version->getName() . '.ipa</a><br />'
.'->install on device: <a href="itms-services://?action=download-manifest&url=' . Tools::rel2abs('../app/' . $version->getToken() . '.plist', Tools::current_url()) . '">Install on device</a></li>' . PHP_EOL;

}
echo '</ul>' . PHP_EOL;
}
echo '</ul>' . PHP_EOL;

Expand Down
282 changes: 139 additions & 143 deletions back/application_upload.php
Expand Up @@ -24,15 +24,18 @@
require_once __DIR__ . '/../lib/cfpropertylist/CFPropertyList.php';
require_once __DIR__ . '/../tools.php';
require_once __DIR__ . '/../core/index.php';
require_once __DIR__ . '/../constants.php';
require_once __DIR__ . '/../lib/PngCompote/PngCompote.php';


function unzipApplication($upload_path, $filename) {

$zip = new ZipArchive;
$res = $zip->open($upload_path . $filename);
if ($res === TRUE) {

$appName = substr($filename, 0, strpos($filename,'.'));
$zip->extractTo('../app/' . $upload_path . $appName . '/');
$appName = substr($filename, 0, -4);
$zip->extractTo($upload_path . $appName . '/');
$zip->close();

return true;
Expand All @@ -42,38 +45,6 @@ function unzipApplication($upload_path, $filename) {
}
}

function fillAppInfoWithPlist($plistfile, $application) {

$plistValue = file_get_contents($plistfile);
if (empty($plistValue)) {
return NULL;
} else {
$plist = new CFPropertyList();
$plist->parse( $plistValue, CFPropertyList::FORMAT_AUTO);
$plistData = $plist->toArray();

//TODO if '${PRODUCT_NAME}' use <app_ame>
$application->setName($plistData['CFBundleDisplayName']);

//Get icon, if empty use 'Icon.png'
if ( isset($plistData['CFBundleIconFile']) && $plistData['CFBundleIconFile'] != 0 ) {
$iconFile = $plistData['CFBundleIconFile'];
} else {
$iconFile = 'Icon.png';
}
$application->setIconFile($iconFile);

//TODO if contains('${PRODUCT_NAME:rfc1034identifier}') replace by <app_ame>
$application->setBundleId($plistData['CFBundleIdentifier']);

$version = new Version();
$version->setVersion($plistData['CFBundleVersion']);
$version->setDateUpload(new \DateTime("now"));

return $version;
}
}

?>

<!doctype html>
Expand All @@ -95,116 +66,141 @@ function fillAppInfoWithPlist($plistfile, $application) {
</div>
<div>

<?php
<?php

// If we have uploaded a file we process it else we ask for it
if (!empty($_FILES['app_file'])) {

if ($_FILES['app_file']['error'] > 0) {
if ($_FILES['app_file']['error'] == 1) {
echo 'Error: The uploaded file exceeds the upload_max_filesize directive in php.ini.<br />';
} else if ($_FILES['app_file']['error'] == 4) {
echo 'Error: No file was uploaded.<br />';
} else {
echo 'Error: code #' . $_FILES['app_file']['error'] . '<br />';
}
} else {

//echo 'Upload: ' . $_FILES['app_file']['name'] . '<br />';
echo 'Type: ' . $_FILES['app_file']['type'] . '<br />';
echo 'Size: ' . ($_FILES['app_file']['size'] / 1024) . ' Kb<br />';

$error = '';

// Configuration options
$allowed_filetypes = array('jpg', 'png', 'ipa'); // Types of file allowed
$max_filesize = 20971520; // Maximum filesize in BYTES (currently 20MB)

$folder_token = Tools::randomAppleRequestId();

$filename = $_FILES['app_file']['name']; // Get the name of the file (including file extension).
$ext = pathinfo($filename, PATHINFO_EXTENSION); // Get the extension from the filename.
// Check if the filetype is allowed
if (!in_array($ext, $allowed_filetypes)) {
$error = 'Error: The file you attempted to upload is not allowed: ' . $ext . '<br />';
}
// Now check the filesize
if (filesize($_FILES['app_file']['tmp_name']) > $max_filesize) {
$error = 'Error: The file you attempted to upload is too large.<br />';
}
$upload_path = '../' . UPLOAD_PATH;
// Check if we can upload to the specified path
if (!is_writable($upload_path)) {
$error = 'Error: You cannot upload to the directory ' . $upload_path . ', please CHMOD it to 777.<br />';
}
if ($error == '') {
// Upload the file to your specified path.
mkdir($upload_path . $folder_token, 0700);
$file_path = $upload_path . $folder_token . '/app_bundle.ipa';
if (move_uploaded_file($_FILES['app_file']['tmp_name'], $file_path)) {
echo 'Your file upload was successful at: ' . $file_path . '<br />';

$zip = new ZipArchive;
//$res = $zip->open($file_path . $folder_token . '/');
if (unzipApplication($upload_path . $folder_token . '/', 'app_bundle.ipa')) {
echo 'Unzip ok.<br>';

// We get the Info.plist of the app if it exists else <app_name>-Info.plist
$plistfile = Tools::getInfoPlistPath($folder_token);
echo 'Plist file: ' . $plistfile . '<br />';
$plistValue = file_get_contents($plistfile);

if (!empty($plistValue)) {
$plist = new CFPropertyList();
$plist->parse($plistValue, CFPropertyList::FORMAT_AUTO);
$plistData = $plist->toArray();

//TODO connect to apple and be sure a profile exists for this app.
//Create an application object and set basic data here
$entityManager = initDoctrine();

// Retrieve the developer connected (unique)
$developer = $entityManager->getRepository('Entities\Developer')->find($_SESSION['developerId']);

//verify if the application does not already exist (Ask to create an new version if it exists)
$application = $entityManager->getRepository('Entities\Application')->findOneBy(array('bundleId' => $plistData['CFBundleIdentifier']));
if ($application == NULL) {

$application = new Application();
$application->setDeveloper($developer);
$application->setBundleId($plistData['CFBundleIdentifier']);
$application->setBundleName($plistData['CFBundleName']);
}

//ensure version doesn't already exists.
//TODO version can be unspefied, handle this case.
$version = $entityManager->getRepository('Entities\Version')->findOneBy(array('version' => $plistData['CFBundleVersion']));
if ($version == NULL) {
$version = new Version();
$version->setVersion($plistData['CFBundleVersion']);
$version->setApplication($application);
} else {
// old version will be linked with new data folder using new token,
// but delete old data folder before
$versionToken = $version->getToken();
Tools::deleteVersionDataFiles($versionToken);
}
$version->setName($plistData['CFBundleDisplayName']);
$version->setToken($folder_token);
$version->setDateUpload(new \DateTime('now'));
$entityManager->persist($application);
$entityManager->persist($version);
$entityManager->flush();

//even if application already exists, update icon with last version uploaded.
//Get icon, if empty use 'Icon.png'
if (isset($plistData['CFBundleIconFile']) && $plistData['CFBundleIconFile'] != 0) {
$iconFile = $plistData['CFBundleIconFile'];
} else {
$iconFile = 'Icon.png';
}
//uncrush icon
$pngPath = '../' . UPLOAD_PATH . $folder_token . '/app_bundle/Payload/'.$version->getName().'.app/'.$iconFile;
if (file_exists($pngPath)){
$png = new PngFile($pngPath);
$newPngPath = '../' . UPLOAD_PATH . $application->getBundleId().'.png';
$png->revertIphone($newPngPath);
}

echo '<a href="application_list.php">Go back to Application list</a>';
} else {
echo 'Error: Unable to read application plist file.<br />';
}
} else {
echo 'Error: Unzip failed.<br />';
}
} else {
echo 'Error: There was an error during the file upload. Please try again.<br />';
}
} else {
echo $error;
}
}
} else {
echo '<p>Error: you can\'t call this page directly.</p>';
}

// If we have uploaded a file we process it else we ask for it
if ( !empty($_FILES['app_file']) ) {

if ($_FILES['app_file']['error'] > 0) {
if ($_FILES['app_file']['error'] == 1) {
echo 'Error: The uploaded file exceeds the upload_max_filesize directive in php.ini.<br />';
} else if ($_FILES['app_file']['error'] == 4) {
echo 'Error: No file was uploaded.<br />';
} else {
echo 'Error: code #' . $_FILES['app_file']['error'] . '<br />';
}
} else {

//echo 'Upload: ' . $_FILES['app_file']['name'] . '<br />';
echo 'Type: ' . $_FILES['app_file']['type'] . '<br />';
echo 'Size: ' . ($_FILES['app_file']['size'] / 1024) . ' Kb<br />';

$error = '';

// Configuration options
$allowed_filetypes = array('jpg','png','ipa'); // Types of file allowed
$max_filesize = 20971520; // Maximum filesize in BYTES (currently 20MB)

$upload_path = '../app/'; // The place where files will be uploaded
$folder_token = Tools::randomAppleRequestId();

$filename = $_FILES['app_file']['name']; // Get the name of the file (including file extension).
$ext = pathinfo($filename, PATHINFO_EXTENSION); // Get the extension from the filename.

// Check if the filetype is allowed
if(!in_array($ext, $allowed_filetypes)) {
$error = 'Error: The file you attempted to upload is not allowed: ' . $ext . '<br />';
}
// Now check the filesize
if(filesize($_FILES['app_file']['tmp_name']) > $max_filesize) {
$error = 'Error: The file you attempted to upload is too large.<br />';
}
// Check if we can upload to the specified path
if(!is_writable($upload_path)) {
$error = 'Error: You cannot upload to the specified directory, please CHMOD it to 777.<br />';
}
if ( $error == '' ) {
// Upload the file to your specified path.
mkdir($upload_path . $folder_token, 0700);
$file_path = $upload_path . $folder_token . '/app_bundle.ipa';
if(move_uploaded_file($_FILES['app_file']['tmp_name'], $file_path)) {
echo 'Your file upload was successful at: ' . $file_path . '<br />';

$zip = new ZipArchive;
//$res = $zip->open($file_path . $folder_token . '/');
if (unzipApplication($upload_path . $folder_token . '/', 'app_bundle.ipa')) {
echo 'Unzip ok.<br>';

// We get the Info.plist of the app if it exists else <app_name>-Info.plist
$plistfile = Tools::getInfoPlistPath($folder_token);
echo 'Plist file: ' . $plistfile . '<br />';

//TODO connect to apple and be sure a profile exists for this app.

//Create an application object and set basic data here
$entityManager = initDoctrine();
date_default_timezone_set('Europe/Paris');

// Retrieve the developer connected (unique)
//TODO replace '1' by the user connected in session
$developer = $entityManager->getRepository('Entities\Developer')->findOneBy(array('id' => 1));

//TODO: verify if the application does not already exist (Ask to create an new version if it exists)

$application = new Application();
$application->setDeveloper($developer);
$application->setToken($folder_token);

$version = fillAppInfoWithPlist($plistfile, $application);
if ( $version != NULL ) {

$entityManager->persist($application);
$entityManager->flush();

$version->setApplication($application);
$entityManager->persist($version);
$entityManager->flush();

echo '<a href="application_list.php">Go back to Application list</a>';

} else {
echo 'Error: Unable to read application plist file.<br />';
}


} else {
echo 'Error: Unzip failed.<br />';
}

} else {
echo 'Error: There was an error during the file upload. Please try again.<br />';
}

} else {
echo $error;
}
}

} else {
echo '<p>Error: you can\'t call this page directly.</p>';
}

?>
?>

</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion back/invitation_list.php
Expand Up @@ -18,6 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

require_once __DIR__ . '/../constants.php';

?><!doctype html>
<html>
<head>
Expand Down Expand Up @@ -57,7 +59,7 @@

echo '<ul>';
foreach ($invitations AS $invitation) {
echo '<li>Invitation: ' . $invitation->getTester()->getEmail() . ' - ' . $invitation->getDateSent()->format('d/m/Y H:i:s') . ' - ' . $invitation->getStatus() . '</li>' . PHP_EOL;
echo '<li>Invitation: ' . $invitation->getTester()->getEmail() . ' - ' . $invitation->getDateSent()->format(DEFAULT_DATETIME_FORMAT) . ' - ' . $invitation->getStatus() . '</li>' . PHP_EOL;
}
echo '</ul>' . PHP_EOL;

Expand Down
2 changes: 1 addition & 1 deletion back/invitation_new.php
Expand Up @@ -61,7 +61,7 @@
foreach ($applications as $application) {
$versions = $application->getVersions();
foreach ($versions as $version) {
echo '<option value="' . $version->getId() . '">' . $application->getName() . ' v' . $version->getVersion() . '</option>' . PHP_EOL;
echo '<option value="' . $version->getId() . '">' . $version->getName() . ' v' . $version->getVersion() . '</option>' . PHP_EOL;
}
}
?>
Expand Down
2 changes: 1 addition & 1 deletion back/invitation_send.php
Expand Up @@ -56,7 +56,7 @@ function sendInvitationForDevice($device, $mailer, $url, $version, $msg, $entity
$mail = $device->getTester()->getEmail();
$token = Tools::randomAppleRequestId();

$app = $version->getApplication()->getName();
$app = $version->getName();
$ver = $version->getVersion();

if (empty($udid)) {
Expand Down
12 changes: 12 additions & 0 deletions constants.php
@@ -0,0 +1,12 @@
<?php


date_default_timezone_set('Europe/Paris');

define('UPLOAD_PATH', 'app/'); // The place where files will be uploaded
define('DEFAULT_DATETIME_FORMAT', 'd/m/Y H:i:s'); // The place where files will be uploaded




?>

0 comments on commit 5434f4b

Please sign in to comment.