Esempio n. 1
0
function processRequest()
{
    @header('Content-type: application/json');
    $action = getRequestParameter("action");
    $token = getRequestParameter("token");
    if ($action == 'getAllDemos') {
        $maxItems = getRequestParameter("maxItems");
        $userEmail = getRequestParameter("userEmail");
        logUsage($action, "", $maxItems, $userEmail);
        echo json_encode(getAllConfigsFromDatabase($userEmail, $maxItems));
    } else {
        if ($action == 'getStandardDemos') {
            logUsage($action, "", "", "");
            echo json_encode(getDefaultConfigsFromDatabase());
        } else {
            if ($action == 'saveConfig') {
                $config = getRequestParameter("config");
                $savedConfig = saveConfig(json_decode($config));
                logUsage($action, "", $savedConfig->token, $config);
                echo json_encode($savedConfig);
            } else {
                if ($action == 'copyConfig') {
                    // copy token config to a new token
                    // copy website...
                    $newToken = copyConfig($token);
                    logUsage($action, "", $newToken, "");
                    echo json_encode($newToken);
                } else {
                    if ($action == 'getConfig') {
                        logUsage($action, "", $token, "");
                        echo json_encode(getConfig($token));
                    } else {
                        // display how to use service.
                        $endpointVariables = array("Name" => "token", "Type" => "String", "Mandatory" => false);
                        $serviceEndpoints = array(array("Name" => "Reset Demo", "Description" => "....", "Endpoint" => "/api?action=resetDemo&token=...", "Variables" => $endpointVariables), array("Name" => "Get Configuration", "Description" => "....", "Endpoint" => "/api?action=getConfig[&token=...]"), array("Name" => "Save Configuration", "Description" => "....", "Endpoint" => "/api?action=saveConfig&config=..."), array("Name" => "Get Offers", "Description" => "....", "Endpoint" => "/api?action=getOffers&customer=...&maxOffer=...&token=..."), array("Name" => "Respond to Offer", "Description" => "....", "Endpoint" => "/api?action=respondToOffer&offer=...&customer=...&token=..."), array("Name" => "Get History", "Description" => "....", "Endpoint" => "/api?action=getHistory&customer=...&token=..."));
                        $serviceEndpointDesc = array("Service Endpoints" => $serviceEndpoints);
                        echo json_encode($serviceEndpointDesc);
                    }
                }
            }
        }
    }
    // log usage
    return;
}
Esempio n. 2
0
function processRequest()
{
    @header('Content-type: application/json');
    $action = getRequestParameter("action");
    $token = getRequestParameter("token");
    if ($action == 'getAllDemos') {
        $maxItems = getRequestParameter("maxItems");
        $userEmail = getRequestParameter("userEmail");
        logUsage($action, "", $maxItems, $userEmail);
        echo json_encode(getAllConfigsFromDatabase($userEmail, $maxItems));
    } else {
        if ($action == 'getStandardDemos') {
            logUsage($action, "", "", "");
            echo json_encode(getDefaultConfigsFromDatabase());
        } else {
            if ($action == 'resetDemo') {
                resetDemo($token);
                logUsage($action, "", $token, "");
            } else {
                if ($action == 'saveConfig') {
                    $config = getRequestParameter("config");
                    $savedConfig = saveConfig(json_decode($config));
                    logUsage($action, "", $savedConfig->token, $config);
                    echo json_encode($savedConfig);
                } else {
                    if ($action == 'copyConfig') {
                        // copy token config to a new token
                        // copy website...
                        $newToken = copyConfig($token);
                        logUsage($action, "", $newToken, "");
                        echo json_encode($newToken);
                    } else {
                        if ($action == 'getOffers') {
                            $customer = getRequestParameter("customer");
                            $channel = getRequestParameter("channel");
                            $list_size = getRequestParameter("maxOffers");
                            $do_not_track = getRequestParameter("DoNotTrack");
                            logUsage($action, "", $token, $channel);
                            echo json_encode(getOffers($token, $customer, $channel, $list_size, $do_not_track));
                        } else {
                            if ($action == 'changeAnalyticsScore') {
                                $customer = getRequestParameter("customer");
                                $scoreIndex = getRequestParameter("scoreIndex");
                                $scoreValue = getRequestParameter("scoreValue");
                                echo json_encode(changeAnalyticsScore($token, $customer, $scoreIndex, $scoreValue));
                            } else {
                                if ($action == 'respondToOffer') {
                                    $customer = getRequestParameter("customer");
                                    $offerCd = getRequestParameter("offer");
                                    $responseCd = getRequestParameter("response");
                                    $channelCd = getRequestParameter("channel");
                                    $details = getRequestParameter("details");
                                    logUsage($action, "", $token, $channelCd);
                                    echo json_encode(respondToOffer($token, $customer, $offerCd, $responseCd, $channelCd, $details));
                                } else {
                                    if ($action == 'getHistory') {
                                        $customer = getRequestParameter("customer");
                                        logUsage($action, "", $token, $customer);
                                        echo json_encode(getCustomerHistory($token, $customer));
                                    } else {
                                        if ($action == 'getConfig') {
                                            logUsage($action, "", $token, "");
                                            echo json_encode(getConfig($token));
                                        } else {
                                            // display how to use service.
                                            $endpointVariables = array("Name" => "token", "Type" => "String", "Mandatory" => false);
                                            $serviceEndpoints = array(array("Name" => "Reset Demo", "Description" => "....", "Endpoint" => "/api?action=resetDemo&token=...", "Variables" => $endpointVariables), array("Name" => "Get Configuration", "Description" => "....", "Endpoint" => "/api?action=getConfig[&token=...]"), array("Name" => "Save Configuration", "Description" => "....", "Endpoint" => "/api?action=saveConfig&config=..."), array("Name" => "Get Offers", "Description" => "....", "Endpoint" => "/api?action=getOffers&customer=...&maxOffer=...&token=..."), array("Name" => "Respond to Offer", "Description" => "....", "Endpoint" => "/api?action=respondToOffer&offer=...&customer=...&token=..."), array("Name" => "Get History", "Description" => "....", "Endpoint" => "/api?action=getHistory&customer=...&token=..."));
                                            $serviceEndpointDesc = array("Service Endpoints" => $serviceEndpoints);
                                            echo json_encode($serviceEndpointDesc);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // log usage
    return;
}
Esempio n. 3
0
/**
 * @param array $json_a content of composer.json
 * @param array $skipDir contains list of directories already scanned for dependency
 */
function customInstall($downloadUrl, $installDir, $skipDir)
{
    /**
     *  download zip from github
     */
    $fileZip = "tempZip.zip";
    $dest = 'vendor/' . $installDir . '/';
    $tempSourceDir = 'sdk-core-php-composer';
    $fp = fopen("{$fileZip}", "w");
    curlExec($downloadUrl, $fp);
    $zip = new ZipArchive();
    if ($zip->open($fileZip) != "true") {
        echo PHP_EOL . "Could not open {$fileZip}";
        exit;
    }
    /**
     * extract the downloaded zip
     **/
    $zip->extractTo($dest);
    $zip->close();
    fclose($fp);
    unlink($fileZip);
    /**
     * scan extracted directory for nested dependency
     */
    $results = scandir($dest);
    foreach ($results as $result) {
        if ($result === '.' or $result === '..') {
            continue;
        }
        if (is_dir($dest . '/' . $result)) {
            /**
             *  skip the directories already scanned
             */
            if (!in_array($result, $skipDir)) {
                $scannedFiles = scandir($dest . '/' . $result);
                foreach ($scannedFiles as $file) {
                    /**
                     * copy the config file to root directory
                     */
                    if ($file == 'config') {
                        if (!is_dir("config")) {
                            mkdir("config");
                        }
                        copyConfig($dest . '/' . $result . '/' . $file . '/', 'config/');
                        rmdir($dest . '/' . $result . '/' . $file);
                    }
                    if ($file == COMPOSER_FILE) {
                        $json = file_get_contents($dest . '/' . $result . '/' . COMPOSER_FILE);
                        $json_a = json_decode($json, true);
                        $skipDir[] = $result;
                        $dependencies = getDependency($json_a);
                        if (!empty($dependencies)) {
                            foreach ($dependencies as $dependency) {
                                $downloadUrl = 'https://api.github.com/repos/' . $dependency['group'] . '/' . $dependency['artifact'] . '/zipball/' . $dependency['branch'];
                                echo "downloading dependency " . $dependency['artifact'] . '...' . PHP_EOL;
                                customInstall($downloadUrl, $dependency['group'], $skipDir);
                            }
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 4
0
     showConfigUser($id[0], true);
     break;
 case "deleteConfig":
     deleteConfig($id);
     break;
 case "newConfig":
     newConfig();
     break;
 case "saveConfig":
     saveConfig();
     break;
 case "saveMainConfig":
     saveMainConfig();
     break;
 case "copyConfig":
     copyConfig($id);
     break;
 case "addUser":
     addUser();
     break;
 case "deleteUser":
     deleteUser($id);
     break;
 case "cancel":
     cancel();
     break;
 case "register":
     register();
     break;
 case "dellic":
     deleteLicense();