예제 #1
0
function get_app_db_headers($controller_dblink, $app_data, $environment)
{
    # Fetching a valid token
    $query = "\tSELECT\n\t\t\t\t\t`api_key`\n\t\t\t\tFROM\n\t\t\t\t\t" . NQ_APP_TOKENS_TABLE . "\n\t\t\t\tWHERE\n\t\t\t\t\t`app_id`\t\t= " . (int) $app_data['id'] . " AND\n\t\t\t\t\t`environment`\t= '" . mysqli_escape_string($controller_dblink, $environment) . "' AND\n\t\t\t\t\t`db_fetch` \t= b'1'\n\t\t\t\tLIMIT 1";
    $token_data = mysqli_single_result_query($controller_dblink, $query);
    # Adding our headers
    $headers = ['Referring-Host: ' . explode(',', $app_data['domain'])[0], 'Content-Type: ' . NQ_DEFAULT_CONTENT_TYPE];
    # Post object
    $post = (object) ['app_secret' => hash('sha256', $app_data['secret']), 'token' => $token_data['api_key'], 'user_agent' => 'nuQuery/1.0 (Emailbot)'];
    # Performing our curl
    $s = curl_init();
    curl_setopt($s, CURLOPT_URL, NQ_AUTH_HOST . $app_data['id'] . '/create');
    curl_setopt($s, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($s, CURLOPT_USERAGENT, 'nuQuery/1.0 (Emailbot)');
    curl_setopt($s, CURLOPT_POST, true);
    curl_setopt($s, CURLOPT_POSTFIELDS, PostParser::encode($post));
    # Our return data type
    $token_data = PostParser::decode(curl_exec($s), NQ_DEFAULT_CONTENT_TYPE);
    curl_close($s);
    # Updating our headers
    $headers[] = 'Access-Token: ' . $token_data->id;
    # Sending our headers back
    return $headers;
}
예제 #2
0
     if (NQ_WHITELIST_COLUMNS) {
         $whitelist = get_whitelist_columns($G_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_TABLE_DETAILS['id'], $G_TOKEN_PRIVILEGE_DATA['id']);
         if (NQ_WHITELIST_EXISTENTIAL ? count($whitelist) > 0 : true) {
             $query->whitelist_columns($whitelist);
         }
     }
     # Blacklisting the locked and partitioned fields
     $query->blacklist_columns(explode(',', NQ_LOCKED_FIELDS));
     $query->blacklist_columns(explode(',', $partition_data['partition_column']));
     # Order by
     if (isset($_CGET['order'])) {
         $order_sort = isset($_CGET['ordersort']) ? explode(',', $_CGET['ordersort']) : [];
         $query->add_order_by(explode(',', $_CGET['order']), $order_sort);
     }
     # Adding our update columns
     $query->add_update_columns(PostParser::decode());
     # Where columns
     $query->add_where_columns($_CGET);
 }
 # Updating our partition
 $query->set_table($partition_data['table_name'], false, false, $partition_data['database']);
 $update_query = $query->get_update_query($limit, false, false);
 mysqli_sub_query($partition_dblink, $update_query);
 # Getting our updated info
 $info = mysqli_info_array($partition_dblink);
 $limit -= (int) $info['Rows matched'];
 # Tracking our internal changed numbers
 $content->affected_rows += (int) $info['Changed'];
 $content->matched_rows += (int) $info['Rows matched'];
 # We are done updating
 if ($limit !== false && $limit <= 0) {
예제 #3
0
		furnished to do so, subject to the following conditions:
	The above copyright notice and this permission notice shall be included in
		all copies or substantial portions of the Software.
	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
		IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
		THE SOFTWARE.
*/
# Including our configuration and validate app
require_once __DIR__ . '/_includes/config.php';
require_once __DIR__ . '/_includes/validate-app.php';
# Handling our global json parsing
$_JPOST = PostParser::decode();
# Validating we have the constant
$query = "\tSELECT\n\t\t\t\t`id`\n\t\t\tFROM\n\t\t\t\t" . NQ_CONSTANT_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment` \tIN ('*','" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "') AND\n\t\t\t\t`tag`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $_JPOST->tag) . "'\n\t\t\t\tLIMIT 1";
$constant_data = mysqli_single_result_query($G_CONTROLLER_DBLINK, $query);
# Bailing if we have a bad constant
if (!isset($constant_data['id'])) {
    exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_CONSTANT);
}
# Archiving the constant
$query = "\tINSERT INTO\n\t\t\t\t" . NQ_CONSTANT_ARCHIVE_TABLE . "\n\t\t\t\t(\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_CONSTANT_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t=" . (int) $constant_data['id'] . "\n\t\t\t\t)";
mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
# Deleting the constant
$query = "\tDELETE FROM\n\t\t\t\t" . NQ_CONSTANT_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`id`\t=" . (int) $constant_data['id'] . "\n\t\t\tLIMIT 1";
mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query);
# The content to be returned
$content = new stdClass();
예제 #4
0
파일: post.php 프로젝트: nuQuery/v1m0-cron
 public static function decode($data = false, $content_type = false, $index = -1, $top = true)
 {
     # Defaulting
     $data = $data === false ? file_get_contents('php://input') : $data;
     $default_type = isset($_SERVER['HTTP_CONTENT_TYPE']) ? $_SERVER['HTTP_CONTENT_TYPE'] : NQ_DEFAULT_CONTENT_TYPE;
     $content_type = $content_type === false ? $default_type : $content_type;
     # Choosing our type
     $obj = false;
     switch ($content_type) {
         # JSON
         case 'json':
         case 'application/json':
             # Converting our object and making it an array if it isn't
             $obj = json_decode($data);
             if (json_last_error() != JSON_ERROR_NONE) {
                 exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_JSON);
             }
             break;
             # XML
         # XML
         case 'xml':
         case 'application/xml':
             # Converting our xml string into an object
             $xml = $data;
             if (is_string($data) && $top) {
                 $xml = false;
                 try {
                     $xml = new SimpleXMLElement($data);
                 } catch (Exception $e) {
                 }
                 if ($xml === false) {
                     try {
                         $xml = new SimpleXMLElement('<DEFAULT_BODY>' . $data . '</DEFAULT_BODY>');
                     } catch (Exception $e) {
                     }
                 }
             }
             # Return variable
             $obj = new stdClass();
             $name = $xml->getName();
             # Storing attributes
             foreach ($xml->attributes() as $key => $value) {
                 $value = (array) $value;
                 $obj->{$key} = $value[0];
             }
             # Adding children
             foreach ($xml->children() as $child) {
                 # We have some children/attributes
                 $c = false;
                 if (count($child->children()) + count($child->attributes()) > 0) {
                     $c = PostParser::decode($child, 'xml', -1, false);
                 }
                 # We have a string value
                 if (trim($child->__toString()) != '' || count($child->children()) + count($child->attributes()) == 0) {
                     $c = $c === false ? new stdClass() : $c;
                     $c->{PostParser::node_flag} = $child->__toString();
                 }
                 # We have a value to set
                 if ($c !== false) {
                     # If we are just a value, set it
                     if (is_object($c) && count(get_object_vars($c)) == 1 && isset($c->{PostParser::node_flag})) {
                         $c = $c->{PostParser::node_flag};
                     }
                     # If we already have the item set, we turn it into an array
                     if (isset($obj->{$child->getName()})) {
                         # If we aren't an array, create an array and store the first item
                         if (!is_array($obj->{$child->getName()})) {
                             $obj->{$child->getName()} = [$obj->{$child->getName()}];
                         }
                         # Adding the child to the array
                         $obj->{$child->getName()}[] = $c;
                     } else {
                         $obj->{$child->getName()} = $c;
                     }
                 }
             }
             break;
             # POST Body
         # POST Body
         case 'form':
         case 'application/x-www-form-urlencoded':
             # Parsing our data
             parse_str($data, $obj);
             # Convert to an array
             if (is_array($data)) {
                 $arr = [];
                 foreach ($obj as $key => $value) {
                     foreach ($obj[$key] as $first_key => $first_value) {
                         $arr[] = (object) [$key => $first_value];
                     }
                 }
                 $obj = $arr;
             }
             break;
     }
     # Returning our object
     return $index == -1 ? $obj : (!$obj || is_array($obj) && $index > -1 && $index < count($obj) ? $obj[$index] : false);
 }
예제 #5
0
파일: queue.php 프로젝트: nuQuery/v1m0-cron
 $G_APP_DATA = mysqli_single_result_query($G_CONTROLLER_DBLINK, $query);
 # Adding our headers
 $headers = get_app_db_headers($G_CONTROLLER_DBLINK, $G_APP_DATA, $db_queue['environment']);
 # Looping through our pages
 $nextpage = NQ_DATABASE_HOST . NQ_DATABASE_APP_ID . '_' . $db_queue['app_id'] . '/fetch/' . $db_queue['table_name'] . '?' . $db_queue['query_string'];
 while ($nextpage != '') {
     # Our records to be added
     $records = [];
     # Performing our curl
     $s = curl_init();
     curl_setopt($s, CURLOPT_URL, $nextpage);
     curl_setopt($s, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($s, CURLOPT_USERAGENT, 'nuQuery/1.0 (Emailbot)');
     # Our return data type
     $return_data = PostParser::decode(curl_exec($s), NQ_DEFAULT_CONTENT_TYPE);
     curl_close($s);
     # Looping through the results
     foreach ($return_data->results as $record) {
         # Setting up the variables
         $variables = json_decode($db_queue['variables']);
         foreach ($record as $key => $value) {
             $variables->{$key} = $value;
         }
         # Adding the email to the queue
         $result = queue_email($G_CONTROLLER_DBLINK, $record->{$db_queue['recipient_column']}, $db_queue['sender_email'], $db_queue['subject'], $email_data, $constants, $variables, $db_queue['app_id'], strtotime($db_queue['send_date']), false);
         # Tracking
         if ($result == 1) {
             $sent++;
         } elseif ($result == -1) {
             $blocked++;