ThemeAvenue /
Remote-Dashboard-Notifications
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Get requester user agent |
||
| 4 | */ |
||
| 5 | $user_agent = $_SERVER['HTTP_USER_AGENT']; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Validate user agent. |
||
| 9 | * |
||
| 10 | * If the request is not from WordPress we return a 403 header. |
||
| 11 | * This will also avoid search engines to index the page. |
||
| 12 | */ |
||
| 13 | if( stristr( $user_agent, 'WordPress' ) == false ) { |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 14 | |||
| 15 | header('HTTP/1.0 403 Forbidden'); |
||
| 16 | _e( 'Sorry, you are not allowed to access this page', 'remote-notifications' ); |
||
| 17 | exit; |
||
| 18 | |||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Check if channel info is available |
||
| 23 | */ |
||
| 24 | if( !isset( $_GET['payload'] ) ) { |
||
| 25 | echo json_encode( array( 'error' => __( 'Unable to find channel information.', 'remote-notifications' ) ) ); |
||
| 26 | exit; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Decode the payload from base64 |
||
| 31 | */ |
||
| 32 | $payload = base64_decode( $_GET['payload'] ); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Check if payload have been decoded |
||
| 36 | */ |
||
| 37 | if( !$payload ) { |
||
| 38 | echo json_encode( array( 'error' => __( 'The payload was not properly encoded in base64.', 'remote-notifications' ) ) ); |
||
| 39 | exit; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Decode the channel JSON string |
||
| 44 | */ |
||
| 45 | $payload = json_decode( $payload ); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Check if the payload is in a usable JSON format |
||
| 49 | */ |
||
| 50 | if( json_last_error() != JSON_ERROR_NONE ) { |
||
| 51 | echo json_encode( array( 'error' => __( 'The payload is not in a correct JSON format.', 'remote-notifications' ) ) ); |
||
| 52 | exit; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Check if all variables are provided |
||
| 57 | */ |
||
| 58 | if( !isset( $payload->channel ) || !isset( $payload->key ) ) { |
||
| 59 | echo json_encode( array( 'error' => __( 'All required variable were not provided.', 'remote-notifications' ) ) ); |
||
| 60 | exit; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Prepare and sanitize the vars. Get the channel ready for verification. |
||
| 65 | */ |
||
| 66 | $channel_id = intval( $payload->channel ); |
||
| 67 | $channel_key = sanitize_key( $payload->key ); |
||
| 68 | $channel = new WP_Query( array( 'post_type' => 'notification', 'p' => $channel_id, 'post_status' => 'publish' ) ); |
||
| 69 | $channel_pid = $channel->post->ID; |
||
| 70 | $key = get_option( "_rn_channel_key_$channel_id", false ); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Check if taxonomy exists |
||
| 74 | */ |
||
| 75 | if( !taxonomy_exists( 'rn-channel' ) ) { |
||
| 76 | |||
| 77 | echo json_encode( array( 'error' => __( 'No channels.', 'remote-notifications' ) ) ); |
||
| 78 | exit; |
||
| 79 | |||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Check if the channel has a key set |
||
| 84 | */ |
||
| 85 | if( false === $key ) { |
||
| 86 | |||
| 87 | echo json_encode( array( 'error' => __( 'Key hasn\'t been set for this channel.', 'remote-notifications' ) ) ); |
||
| 88 | exit; |
||
| 89 | |||
| 90 | } else { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Check the validity of the key |
||
| 94 | */ |
||
| 95 | if( $key !== $channel_key ) { |
||
| 96 | echo json_encode( array( 'error' => __( 'The key you provided for this channel is incorrect.', 'remote-notifications' ) ) ); |
||
| 97 | exit; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Now we know the channel exists and the request is authenticated |
||
| 103 | */ |
||
| 104 | $args = array( |
||
| 105 | 'post_type' => 'notification', |
||
| 106 | 'post_status' => 'publish', |
||
| 107 | 'posts_per_page' => 1, |
||
| 108 | 'orderby' => 'date', |
||
| 109 | 'order' => 'DESC', |
||
| 110 | 'update_post_meta_cache' => false, |
||
| 111 | 'update_post_term_cache' => false, |
||
| 112 | 'tax_query' => array( |
||
| 113 | array( |
||
| 114 | 'taxonomy' => 'rn-channel', |
||
| 115 | 'field' => 'id', |
||
| 116 | 'terms' => $channel_id |
||
| 117 | ) |
||
| 118 | ) |
||
| 119 | ); |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Find the latest notification |
||
| 123 | */ |
||
| 124 | $notification = new WP_Query( $args ); |
||
| 125 | |||
| 126 | if( isset( $notification->post ) ) { |
||
| 127 | |||
| 128 | /* Get settings */ |
||
| 129 | $settings = get_post_meta( $notification->post->ID, '_rn_settings', true ); |
||
| 130 | |||
| 131 | $alert = array( |
||
| 132 | 'title' => $notification->post->post_title, |
||
| 133 | 'message' => htmlentities( $notification->post->post_content ), |
||
| 134 | 'slug' => $notification->post->post_name, |
||
| 135 | 'type' => array() |
||
| 136 | ); |
||
| 137 | |||
| 138 | /* Add settings */ |
||
| 139 | $alert = array_merge( $alert, $settings ); |
||
| 140 | |||
| 141 | /* Check if there are post types limitations */ |
||
| 142 | $pt = wp_get_post_terms( $notification->post->ID, 'rn-pt' ); |
||
| 143 | |||
| 144 | /* Add the supported post types to the response */ |
||
| 145 | if( is_array( $pt ) && !empty( $pt ) ) { |
||
| 146 | |||
| 147 | foreach( $pt as $type ) { |
||
| 148 | |||
| 149 | array_push( $alert['type'], $type->slug ); |
||
| 150 | |||
| 151 | } |
||
| 152 | |||
| 153 | } |
||
| 154 | |||
| 155 | echo json_encode( $alert ); |
||
| 156 | exit; |
||
| 157 | |||
| 158 | } else { |
||
| 159 | |||
| 160 | echo json_encode( array( 'error' => __( 'nothing', 'remote-notifications' ) ) ); |
||
| 161 | exit; |
||
| 162 | |||
| 163 | } |