$SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_min_amount bigint(20) not null default '40000'";
$SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_id bigint(20) not null default '0'";
$SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_md5 varchar(32) not null default ''";
+ $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_url varchar(255) not null default 'http://www.wds66.com/api/'";
$SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', '', '{!POINTS!}-Management', 'Konfiguration zur WDS66-API einstellen, Auszahlungen auflisten usw..', 15)";
$SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', 'config_wernis', 'WDS66-API-Einstellungen', 'Konfiguration zur WDS66-API einstellen.', 1)";
$SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', 'list_wernis', '{!POINTS!}-Anfragen auflisten', 'Listet alle {!POINTS!}-Auszahlungsanfragen Ihrer Mitglieder auf.', 2)";
$CONFIG['wernis_min_amount'] = $DUMMY['wernis_min_amount'];
$CONFIG['wernis_api_id'] = $DUMMY['wernis_api_id'];
$CONFIG['wernis_api_md5'] = $DUMMY['wernis_api_md5'];
+ $CONFIG['wernis_api_url'] = $DUMMY['wernis_api_url'];
unset($DUMMY);
break;
}
//
function MXCHANGE_OPEN($script) {
+ // Compile the script name
+ $script = COMPILE_CODE($script);
+
+ // Use default SERVER_URL by default... ;) So?
+ $url = SERVER_URL;
+ if (substr($script, 0, 7) == "http://") {
+ // Use the hostname from script URL as new hostname
+ $url = substr($script, 7);
+ $extract = explode("/", $url);
+ $url = $extract[0];
+ // Done extracting the URL :)
+ }
+
// Extract host name
- $host = str_replace("http://", "", SERVER_URL);
+ $host = str_replace("http://", "", $url);
if (ereg("/", $host)) $host = substr($host, 0, strpos($host, "/"));
// Generate relative URL
- $script = substr(SERVER_URL, (strpos(SERVER_URL, $host) + strlen($host)))."/".basename($script);
+ $script = substr($script, (strlen($url) + 7));
if (substr($script, 0, 1) == "/") $script = substr($script, 1);
// Open connection
************************************************************************/
// Some security stuff...
-if (basename($_SERVER['PHP_SELF']) == basename(__FILE__))
-{
+if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
$INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
require($INC);
}
define('WERNIS_ADMIN_MIN_AMOUNT', "Minimumguthaben von {!POINTS!} für Auszahlungen.");
define('WERNIS_ADMIN_API_ID', "WDS66-API-ID (api_id=x)");
define('WERNIS_ADMIN_API_MD5', "WDS66-API-Key (api_md5=xxxxx; 32-stellig)");
+define('WERNIS_ADMIN_API_URL', "Basis-URL der API-Skripte");
define('WERNIS_ADMIN_CONFIG_NOTE', "<A href=\"http://www.wds66.com/ref.php?refid=10437\" target=\"_blank\">Hier</A> können Sie schon für <strong>5,00€</strong>=<strong>25.000 Abfragen</strong> ein API-Account beantragen (dazu ist ein <strong>kostenloses</strong> {!POINTS!}-Account dennoch nötig!)");
define('MEMBER_WERNIS_MODE_CHOOSE', "Möchten Sie {!POINTS!} zu Ihrem WDS66-Hauptaccount ausbezahlt bekommen oder {!POINTS!} hier einzahlen?");
define('MEMBER_WERNIS_MODE_WITHDRAW', "{!POINTS!} einzahlen");
define('MEMBER_WERNIS_MODE_PAYOUT', "{!POINTS!} auszahlen");
+// API messages
+define('WERNIS_API_REQUEST_DATA_INVALID', "Interner Fehler: Abfragedaten sind defekt!");
+define('WERNIS_API_REQUEST_DATA_MISSING', "Interner Fehler: Abfragedaten sind nicht komplett!");
+define('WERNIS_API_REQUEST_ERROR', "Abfragefehler: <u>%s</u>");
+define('WERNIS_API_REQUEST_FAILED', "Unbekannter Fehler <u>%s</u> von API erhalten! Bitte im [<A href=\"http://forum.mxchange.org\" target=\"_blank\" title=\"Direktlink zum Forum\">Forum melden</A>], den Fehlercode nennen und wie es dazu gekommen ist.");
+define('WERNIS_API_REQUEST_FAILED_AUTH', "Authorisierung an API fehlgeschlagen! Bitte API-ID und Key überprüfen. [<A href=\"http://www.wds66.com/modules.php?module=export\" target=\"_blank\" title=\"Direkt zum WDS66-Exportaccount\">Hier</A>] direkt zum Export-Account. Sie benötigen Ihren Usernamen und Passwort!");
+
//
?>
************************************************************************/
// Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
+if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
$INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
require($INC);
}
+// Sends out a request to the API and returns it's result
+function WERNIS_SEND_REQUEST ($scriptName, $requestData = array()) {
+ global $CONFIG;
+
+ // Is the requestData an array?
+ if (!is_array($requestData)) {
+ // Then abort here!
+ return array(
+ 'status' => "failed_general",
+ 'message' => WERNIS_API_REQUEST_DATA_INVALID
+ );
+ }
+
+ // Is the API id and MD5 hash there?
+ if ((empty($CONFIG['wernis_api_id'])) || (empty($CONFIG['wernis_api_md5']))) {
+ // Abort here...
+ return array(
+ 'status' => "failed_general",
+ 'message' => WERNIS_API_REQUEST_DATA_MISSING
+ );
+ }
+
+ // Construct the request string
+ $requestString = $CONFIG['wernis_api_url'] . $scriptName."?api_id=".$CONFIG['wernis_api_id']."&api_key=".$CONFIG['wernis_api_md5'];
+ foreach ($requestData as $key=>$value) {
+ $requestString .= "&".$key."=".$value;
+ }
+
+ // Get the raw response from the lower function
+ $response = MXCHANGE_OPEN($requestString);
+
+ // Check the response header if all is fine
+ if (strpos($response[0], "200") === false) {
+ // Something bad happend... :(
+ return array(
+ 'status' => "request_eror",
+ 'message' => sprintf(WERNIS_API_REQUEST_ERROR, $response[0])
+ );
+ }
+
+ // All (maybe) fine so remove the response header from server
+ $response = $response[(count($response) - 1)];
+
+ // Prepare the returning result for higher functions
+ if (substr($response, 0, 1) == "&") {
+ // Remove the leading & (which can be used in Flash)
+ $response = substr($response, 1);
+ }
+
+ // Bring back the response
+ $data = explode("=", $response);
+
+ // Default return array (should not stay empty)
+ $return = array();
+
+ // We use only the first two entries (which shall be fine)
+ if ($data[0] == "error") {
+ // The request has failed... :(
+ switch ($data[1]) {
+ case "AUTH": // Authorization has failed
+ $return = array(
+ 'status' => "auth_failed",
+ 'message' => WERNIS_API_REQUEST_FAILED_AUTH
+ );
+ break;
+
+ default: // Unknown error (maybe new?)
+ $return = array(
+ 'status' => "request_failed",
+ 'message' => sprintf(WERNIS_API_REQUEST_FAILED, $data[1])
+ );
+ break;
+ }
+ } else {
+ // All fine here
+ $return = array(
+ 'status' => "OK",
+ 'response' => $response
+ );
+ }
+
+ // Return the result
+ return $return;
+}
+
+// Tests the function by calling balance.php on the API
+function WERNIS_TEST_API () {
+ // Get config first
+ global $CONFIG;
+
+ // Prepare the request to the API
+ $return = WERNIS_SEND_REQUEST("balance.php");
+
+ die("<pre>".print_r($return, true)."</pre>");
+}
+
//
?>
ADD_DESCR("admin", basename(__FILE__));
if (isset($_POST['ok'])) {
- // Save settings
- ADMIN_SAVE_SETTINGS($_POST, "_config", "config='0'");
+ // First merge temporary the new API data into config
+ $CONFIG = array_merge($CONFIG, $_POST);
+
+ // Let's test the API first (hold your horses here, cowboy! Thanks. :) )
+ if (WERNIS_TEST_API()) {
+ // Save settings
+ ADMIN_SAVE_SETTINGS($_POST, "_config", "config='0'");
+ } else {
+ // Failed to test the API!
+ LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_ERROR_MESSAGE());
+ }
} else {
// Prepare data for template output
$content = array(
'min_amount' => $CONFIG['wernis_min_amount'],
'api_id' => $CONFIG['wernis_api_id'],
- 'api_md5' => $CONFIG['wernis_api_md5']
+ 'api_md5' => $CONFIG['wernis_api_md5'],
+ 'api_url' => $CONFIG['wernis_api_url']
);
// Load template
<TD width="300" align="right">{--WERNIS_ADMIN_API_ID--}:</TD>
<TD class="seperator" width="10"> </TD>
<TD width="270"><INPUT type="text" name="wernis_api_id"
- class="admin_normal" value="$content[api_id]" size="2" maxlength="20"></TD>
+ class="admin_normal" value="$content[api_id]" size="2"
+ maxlength="20" /></TD>
</TR>
<TR>
<TD colspan="3" class="seperator" height="5"> </TD>
<TD class="seperator" width="10"> </TD>
<TD width="270"><INPUT type="text" name="wernis_api_md5"
class="admin_normal" value="$content[api_md5]" size="33"
- maxlength="32"></TD>
+ maxlength="32" /></TD>
</TR>
<TR>
<TD colspan="3" class="seperator bottom2" height="5"> </TD>
<TD class="seperator" width="10"> </TD>
<TD width="270"><INPUT type="text" name="wernis_min_amount"
class="admin_normal" value="$content[min_amount]" size="5"
- maxlength="20"></TD>
+ maxlength="20" /></TD>
+ </TR>
+ <TR>
+ <TD colspan="3" class="seperator" height="5"> </TD>
+ </TR>
+ <TR>
+ <TD width="300" align="right">{--WERNIS_ADMIN_API_URL--}:</TD>
+ <TD class="seperator" width="10"> </TD>
+ <TD width="270"><INPUT type="text" name="wernis_api_url"
+ class="admin_normal" value="$content[api_url]" size="25"
+ maxlength="255" /></TD>
</TR>
<TR>
<TD colspan="3" class="bottom2 seperator" height="5"> </TD>