Example #1
0
function firstRun()
{
    global $bundle;
    $HOME = exec('echo $HOME');
    $data = "{$HOME}/Library/Application Support/Alfred 2/Workflow Data/{$bundle}";
    $cache = "{$HOME}/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/{$bundle}";
    $config = "{$data}/config";
    $endpoints = "{$data}/endpoints";
    $backups = "{$data}/backups";
    $directories = array($data, $cache, $config, $endpoints, $backups);
    foreach ($directories as $d) {
        if (!file_exists($d) && is_dir($d)) {
            mkdir($d);
        }
    }
    unset($config);
    // Generate Default Config File
    if (!file_exists("{$data}/config/config.xml")) {
        $d = '<?xml version="1.0" encoding="UTF-8"?><config></config>';
        $config = new SimpleXMLElement($d);
        $config->packalAccount = 0;
        $config->forcePackal = 0;
        $config->backups = 3;
        $config->username = '';
        $config->authorName = '';
        $config->notifications = '2';
        $config->workflowReporting = '1';
        $config->apiKey = '';
        $config->asXML("{$data}/config/config.xml");
        unset($config);
    }
    // Generate Empty Blacklist File
    if (!file_exists("{$data}/config/blacklist.json")) {
        file_put_contents("{$data}/config/blacklist.json", utf8_encode(json_encode(array())));
    }
    if (!file_exists("{$data}/manifest.xml")) {
        // Get the manifest with error handling.
        if (getManifest() == FALSE) {
            // So, we're getting the manifest, but
            // there was a problem, so we're going
            // to communicate that.
            return FALSE;
        }
    }
    return TRUE;
}
function showPage($configItems, $typeOfDemo)
{
    global $manifest;
    global $paths;
    // paths related to the environment
    global $typeOfDemo;
    $paths["webDefault"] = $paths["webHome"] . "/default/templates/" . $typeOfDemo;
    include $paths["templates"] . "/manifest.php";
    $manifest = getManifest($typeOfDemo);
    $basicHTMLstrings = getHTMLstrings($configItems);
    // grab any simple HTML
    //strings from the list of configurations
    $thesePaths = setPaths();
    // paths to all of the needed files
    $finalPaths = evaluatePaths($thesePaths);
    // files opened, html tags added
    $basicHTMLstrings["navigation"] = getNav();
    $finalHTML = getFinalHTML($finalPaths, $basicHTMLstrings);
    $htmlTemplate = getHTMLtemplate($configItems);
    $htmlString = buildPage($htmlTemplate, $finalHTML);
    echo $htmlString;
}
Example #3
0
    }
}
// Update the manifest if past cache.
// This is a potential failure spot.
if ($connection !== FALSE) {
    exec("'" . __DIR__ . "/cli/packal.sh' update");
}
// Do the workflow reporting script as long as the config option is set.
if ($config->workflowReporting == '1') {
    exec("nohup php '" . __DIR__ . "/report-usage-data.php'  > /dev/null 2>&1 &");
}
$blacklist = json_decode(file_get_contents("{$data}/config/blacklist.json"), TRUE);
$manifest = @simplexml_load_file("{$data}/manifest.xml");
// The manifest is not valid. Let's try to get it before we fail.
if (empty($manifest)) {
    if (getManifest() === FALSE) {
        $w->result('', '', 'Error: Packal Updater', 'The workflow manifest is not valid, and there is no valid Internet connection to retrieve a new one.', 'assets/icons/task-reject.png', 'no', '');
        echo $w->toxml();
        die;
    }
    // So, the we didn't get an error, but let's try to make sure it is valid XML.
    $manifest = @simplexml_load_file("{$data}/manifest.xml");
    if (empty($manifest)) {
        $w->result('', '', 'Error: Packal Updater', 'The workflow manifest is not valid, and there is no valid Internet connection to retrieve a new one.', 'assets/icons/task-reject.png', 'no', '');
        echo $w->toxml();
        die;
    }
}
// Okay, we're good. Or, at least we should be.
$json = json_decode(file_get_contents("{$data}/endpoints/endpoints.json"), TRUE);
$mine = array_keys($json);
function get_required_upgrades($session, $client_upgrade_history, $client_version)
{
    // files might be big
    global $sugar_config;
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('upgrade_history_list' => array(), 'error' => $error->get_soap_array());
    }
    global $current_user;
    $upgrade_history = new UpgradeHistory();
    $installeds = $upgrade_history->getAllOrderBy('date_entered ASC');
    $history = array();
    $client_ver = explode('.', $client_version);
    foreach ($installeds as $installed) {
        $installed_ver = explode('.', $installed->version);
        if (count($installed_ver) >= 3) {
            if (is_server_version_greater($client_ver, $installed_ver) == true) {
                $found = false;
                foreach ($client_upgrade_history as $client_history) {
                    if ($client_history['md5'] == $installed->md5sum) {
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    //now check to be sure that this is available as an offline client upgrade
                    $manifest_file = getManifest($installed->filename);
                    if (is_file($manifest_file)) {
                        require_once $manifest_file;
                        if (!isset($manifest['offline_client_applicable']) || $manifest['offline_client_applicable'] == true || $manifest['offline_client_applicable'] == 'true') {
                            $history[] = array('id' => $installed->id, 'filename' => $installed->filename, 'md5' => $installed->md5sum, 'type' => $installed->type, 'status' => $installed->status, 'version' => $installed->version, 'date_entered' => $installed->date_entered, 'error' => $error->get_soap_array());
                        }
                    }
                }
            }
        }
    }
    return array('upgrade_history_list' => $history, 'error' => $error->get_soap_array());
}
Example #5
0
function updateManifest()
{
    global $data;
    if (getManifest() == FALSE) {
        $time = getManifestModTime();
        echo "The manifest was last updated <strong>{$time}</strong> However it couldn't be updated because of no viable Internet connection.";
        die;
    }
    $time = getManifestModTime();
    echo "The manifest was last updated <strong>{$time}</strong>";
    die;
}