示例#1
0
/**
 * Server Status
 */
function wo_server_status_page()
{
    ?>
<div class="wrap">
	<h2>Server Status</h2>
	<p>
		The following information is helpful when debugging or reporting an issue. Please note that the
		information provided here is a reference only.
	</p>
	<table>
		<tr>
			<th style="text-align:left;">Plugin Build: </th>
			<td>
				<?php 
    echo strpos(_WO()->version, '-') ? _WO()->version . " <span style='color:orange;'><small>You are using a development version of the plugin.</small></span>" : _WO()->version;
    ?>
			</td>
		</tr>

		<tr>
			<th style="text-align:left;">PHP Version (<?php 
    echo PHP_VERSION;
    ?>
): </th>
			<td>
				<?php 
    echo version_compare(PHP_VERSION, '5.3.9') >= 0 ? " <span style='color:green;'>OK</span>" : " <span style='color:red;'>Failed</span> - <small>Please upgrade PHP to 5.4 or greater.</small>";
    ?>
			</td>
		</tr>

		<tr>
			<th style="text-align:left;">Apache Version: </th>
			<td>
				<?php 
    echo function_exists('apache_get_version') ? apache_get_version() : '<strong>apache_get_version()</strong> not enabled.';
    ?>
			</td>
		</tr>

		<tr>
			<th style="text-align:left;">Running CGI: </th>
			<td>
				<?php 
    echo substr(php_sapi_name(), 0, 3) != 'cgi' ? " <span style='color:green;'>OK</span>" : " <span style='color:orange;'>Notice</span> - <small>Header 'Authorization Basic' may not work as expected.</small>";
    ?>
			</td>
		</tr>

		<tr>
			<th style="text-align:left;">Certificates Generated: </th>
			<td>
				<?php 
    echo !wo_has_certificates() ? " <span style='color:red;'>No Certificates Found</span>" : "<span style='color:green;'>Certificates Found</span>";
    ?>
			</td>
		</tr>

		<tr>
			<th style="text-align:left;">License: </th>
			<td>
				<?php 
    echo !_vl() ? " <span style='color:orange;'>Standard" : "<span style='color:green;'>Licensed</span>";
    ?>
			</td>
		</tr>

	</table>
</div>
<?php 
}
    /**
     * [options_do_page description]
     * @return [type] [description]
     */
    public function options_do_page()
    {
        $options = get_option($this->option_name);
        $this->admin_head();
        $scopes = apply_filters('WO_Scopes', null);
        error_reporting(0);
        add_thickbox();
        ?>
			<div class="wrap">
	      <img style="width:40px; float: left; diplay: inline; margin-right: 10px; margin-top: 5px;" src="<?php 
        echo plugins_url('/assets/images/logo.png', WPOAUTH_FILE);
        ?>
" />
	      <h2>WP OAuth Server <strong><small> | v <?php 
        echo _WO()->version;
        ?>
</small></strong></h2>
	     	<br/>
	     	<p></p>
      	<form method="post" action="options.php">
					<?php 
        settings_fields('wo_options');
        ?>
        	<div id="wo_tabs">
						<ul>
					  	<li><a href="#general-settings">General Settings</a></li>
					  	<li><a href="#advanced-configuration">Advanced Configuration</a></li>
					  	<li><a href="#clients">Clients</a></li>
					  	<li><a href="#server-status">Server Status</a></li>
						</ul>

						<!-- GENERAL SETTINGS -->
						<div id="general-settings">
					  	<table class="form-table">
					  		<tr valign="top">
	            		<th scope="row">License Key:</th>
	                <td>
	                 	<input type="text" name="<?php 
        echo $this->option_name;
        ?>
[license]" value="<?php 
        echo $options["license"];
        ?>
" length="40" style="width:300px;"/>
	                 	<?php 
        echo license_status();
        ?>
	                  <?php 
        if (!_vl()) {
            ?>
	                  	<p class="description">Get a license by visiting <a href="https://wp-oauth.com/knowledge-base/" target="_blank">http://wp-oauth.com/pro-license</a>.</p>
	                	<?php 
        } else {
            ?>
	                		<p class="description" style="color:green;">Congratulations and Thank You. Your license is <strong>valid</strong>.</p>
	                	<?php 
        }
        ?>
	                </td>
	              </tr>
	            	<tr valign="top">
	            		<th scope="row">API Enabled:</th>
	                	<td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[enabled]" value="1" <?php 
        echo $options["enabled"] == "1" ? "checked='checked'" : "";
        ?>
 />
	                  	<p class="description">If the API is not enabled, it will present requests with an "Unavailable" message.</p>
	                	</td>
	              	</tr>
	            </table>
					  </div>

					  <!-- ADVANCED CONFIGURATION -->
					  <div id="advanced-configuration">
					  	<h2>Advanced Configuration</h2>
					  	
	            <h3>Grant Types <hr></h3>
	            <p>Control which Grant Types that the server will accept.</p>
							<table class="form-table">

	              <tr valign="top">
	               	<th scope="row">Authorization Code:</th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[auth_code_enabled]" value="1" <?php 
        echo $options["auth_code_enabled"] == "1" ? "checked='checked'" : "";
        ?>
 />
	                  	<p class="description">HTTP redirects and WP login form when authenticating.</p>
	              	  </td>
	              </tr>

	              <tr valign="top">
	               	<th scope="row">Client Credentials:</th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[client_creds_enabled]" value="1" <?php 
        echo $options["client_creds_enabled"] == "1" ? "checked='checked'" : "";
        ?>
 />
	                  	<p class="description">Enable "Client Credentials" Grant Type</p>
	              	  </td>
	              </tr>

	              <tr valign="top">
	               	<th scope="row">User Credentials:</th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[user_creds_enabled]" value="1" <?php 
        echo $options["user_creds_enabled"] == "1" ? "checked='checked'" : "";
        ?>
 />
	                  	<p class="description">Enable "User Credentials" Grant Type</p>
	              	  </td>
	              </tr>

	              <tr valign="top">
	               	<th scope="row">Refresh Tokens:</th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[refresh_tokens_enabled]" value="1" <?php 
        echo $options["refresh_tokens_enabled"] == "1" ? "checked='checked'" : "";
        ?>
 />
	                  	<p class="description">Enable "Refresh Token" Grant Type</p>
	              	  </td>
	              </tr>

	              <tr valign="top">
	               	<th scope="row">Allow Implicit:</th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[implicit_enabled]" value="1" <?php 
        echo $options["implicit_enabled"] == "1" ? "checked='checked'" : "";
        ?>
 />
	                  	<p class="description">Enable "Authorization Code (Implicit)" <a href="http://wp-oauth.com/documentation/server-api/which-grant-type-to-use/">What is this?</a></p>
	              	  </td>
	              </tr>

	            </table>

	            <h3>Misc Settings <hr></h3>
							<table class="form-table">
								<tr valign="top">
	               	<th scope="row">Key Length</th>
	                  <td>
	                  	<input type="number" name="<?php 
        echo $this->option_name;
        ?>
[client_id_length]" min="10" value="<?php 
        echo $options["client_id_length"];
        ?>
" />
	                  	<p class="description">Length of Client ID and Client Secrets when generated.</p>
	              	  </td>
	              </tr>
								<tr valign="top">
	               	<th scope="row">Require Exact Redirect URI:</th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[require_exact_redirect_uri]" value="1" <?php 
        echo $options["require_exact_redirect_uri"] == "1" ? "checked='checked'" : "";
        ?>
 />
	                  	<p class="description">Enable if exact redirect URI is required when authenticating.</p>
	              	  </td>
	              </tr>

	              <tr valign="top">
	               	<th scope="row">Enforce State Parameter:</th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
        echo $this->option_name;
        ?>
[enforce_state]" value="1" <?php 
        echo $options["enforce_state"] == "1" ? "checked='checked'" : "";
        ?>
/>
	                  	<p class="description">Enable if the "state" parameter is required when authenticating. </p>
	              	  </td>
	              </tr>
							</table>

							<!-- OpenID Connect -->
							<h3>OpenID Connect 1.0a <hr></h3>
							<p>
								The OpenID Connect 1.0a works with other systems like Drupal and Moodle.
							</p>
							<table class="form-table">
								<tr valign="top">
	               	<th scope="row">Enable OpenID Connect:</th>
	               	<?php 
        if (_vl($options['license'])) {
            ?>
		                <td>
		                	<input type="checkbox" name="<?php 
            echo $this->option_name;
            ?>
[use_openid_connect]" value="1" <?php 
            echo $options["use_openid_connect"] == "1" ? "checked='checked'" : "";
            ?>
/>
		                  <p class="description">Enable if your server should generate a id_token when OpenID request is made.</p>
		              	</td>
	              	<?php 
        } else {
            ?>
	              		<td>
		                  <input type="checkbox" disabled="yes" />
		                  <p class="description">Enable OpenID Connect 1.0a <a href="https://wp-oauth.com/downloads/wp-oauth-license/" style="color:red;">License Required</a></p>
		              	</td>
	              	<?php 
        }
        ?>
	              </tr>

	              <tr valign="top">
	              	<?php 
        if (_vl($options['license'])) {
            ?>
			           		<th scope="row">ID Token Lifetime</th>
			            	<td>
			                <input type="number" name="<?php 
            echo $this->option_name;
            ?>
[id_token_lifetime]" value="<?php 
            echo $options["id_token_lifetime"];
            ?>
" placeholder="3600" />
			                <p class="description">How long an id_token is valid (in seconds).</p>
			              </td>
			            <?php 
        } else {
            ?>
			            	<th scope="row">ID Token Lifetime</th>
			            	<td>
			                <input type="number" placeholder="3600" disabled="yes" />
			                <p class="description">How long an id_token is valid (in seconds). <a href="https://wp-oauth.com/downloads/wp-oauth-license/" style="color:red;">License Required</a></p>
			              </td>
			            <?php 
        }
        ?>
			          </tr>
			          
							</table>

							<h3>Token Lifetimes <?php 
        echo !_vl() ? ' <i style="color:red;font-size:14px;">License Required</i>' : '';
        ?>
 <hr></h3>
							<p>
								Take control of your token lifetimes easily. By default Access Tokens are valid for 1 hour
								and Refresh Tokens are valid for 24 hours.
							</p>
							<?php 
        if (_vl($options['license'])) {
            ?>
							<table class="form-table">
								<tr valign="top">
	               	<th scope="row">Access Token Lifetime</th>
	                  <td>
	                  	<input type="number" name="<?php 
            echo $this->option_name;
            ?>
[access_token_lifetime]" value="<?php 
            echo $options["access_token_lifetime"];
            ?>
" placeholder="3600" />
	                  	<p class="description">How long an access token is valid (seconds) - Leave blank for default (1 hour)</p>
	              	  </td>
	              </tr>
	              <tr valign="top">
	               	<th scope="row">Refresh Token Lifetime</th>
	                  <td>
	                  	<input type="number" name="<?php 
            echo $this->option_name;
            ?>
[refresh_token_lifetime]" value="<?php 
            echo $options["refresh_token_lifetime"];
            ?>
" placeholder="86400"/>
	                  	<p class="description">How long a refresh token is valid (seconds)- Leave blank for default (24 hours)</p>
	              	  </td>
	              </tr>
							</table>
							<?php 
        }
        ?>

							<h3>Firewall <?php 
        echo !_vl($options['license']) ? ' <i style="color:red;font-size:14px;">License Required</i>' : '';
        ?>
<hr></h3>
							<p>
								The firewall is used to secure your OAuth API by allowing you to block all IP's and only allow
								approved IP's through. The firewall supports whitelisting of IPV4 and IPv6 addresses.
							</p>
							<?php 
        if (_vl($options['license'])) {
            ?>
							<table class="form-table">
	              <tr valign="top">
	               	<th scope="row">Block All Incoming Requests but Whitelisted: </th>
	                  <td>
	                  	<input type="checkbox" name="<?php 
            echo $this->option_name;
            ?>
[firewall_block_all_incomming]" value="1" <?php 
            echo $options["firewall_block_all_incomming"] == "1" ? "checked='checked'" : "";
            ?>
/>
	                  	<p class="description">Block all incomming requests that are not whitelisted below. </p>
	              	  </td>
	              </tr>

	              <tr valign="top">
	               	<th scope="row">IP Whitelist: </th>
	                  <td>
	                  	<textarea name="<?php 
            echo $this->option_name;
            ?>
[firewall_ip_whitelist]" style="margin: 0px;width: 340px;height: 140px;resize: none;" placeholder="127.0.0.1, ::1"><?php 
            echo $options["firewall_ip_whitelist"];
            ?>
</textarea>
	                  	<p class="description">Enter IP addresses separated by commas. IPV4 and IPV6 are supported.</p>
	              	  </td>
	              </tr>
							</table>
						<?php 
        }
        ?>

					  </div>

					  <!-- CLIENTS -->
					  <div id="clients">
					  	<h2>
					  		Clients
					  		<a href="<?php 
        echo WOURI;
        ?>
library/content/create-new-client.php?TB_iframe=true&width=600&height=420" class="add-new-h2 thickbox" title="Add New Client">Add New Client</a>
					  	</h2>

							<?php 
        $wp_list_table = new WO_Table();
        $wp_list_table->prepare_items();
        $wp_list_table->display();
        ?>
						</div>

						<!-- SERVER STATUS CONTENT -->
					  <div id="server-status">
					  	<h2>Server Status</h2>
					  	<p>
					  		The following information is helpful when debugging or reporting an issue. Please note that the
					  		informaiton provided here is a reference only.
					  	</p>
					  	<table>
					  		<tr>
					  			<th style="text-align:right;">Plugin Build: </th>
					  			<td>
										<?php 
        echo strpos(_WO()->version, '-') ? _WO()->version . " <span style='color:orange;'><small>You are using a development version of the plugin.</small></span>" : _WO()->version;
        ?>
					  			</td>
					  		</tr>

					  		<tr>
					  			<th style="text-align:right;">PHP Version (<?php 
        echo PHP_VERSION;
        ?>
): </th>
					  			<td>
										<?php 
        echo version_compare(PHP_VERSION, '5.3.9') >= 0 ? " <span style='color:green;'>OK</span>" : " <span style='color:red;'>Failed</span> - <small>Please upgrade PHP to 5.4 or greater.</small>";
        ?>
					  			</td>
					  		</tr>

					  		<tr>
					  			<th style="text-align:right;">Running CGI: </th>
					  			<td>
					  				<?php 
        echo substr(php_sapi_name(), 0, 3) != 'cgi' ? " <span style='color:green;'>OK</span>" : " <span style='color:orange;'>Notice</span> - <small>Header 'Authorization Basic' may not work as expected.</small>";
        ?>
					  			</td>
					  		</tr>

					  		<tr>
					  			<th style="text-align:right;">Certificates Generated: </th>
					  			<td>
										<?php 
        echo !wo_has_certificates() ? " <span style='color:red;'>No Certificates Found</span>" : "<span style='color:green;'>Certificates Found</span>";
        ?>
									</td>
					  		</tr>

					  		<tr>
					  			<th style="text-align:right;">License: </th>
					  			<td>
										<?php 
        echo !_vl() ? " <span style='color:orange;'>Standard" : "<span style='color:green;'>Licensed</span>";
        ?>
									</td>
					  		</tr>
					  	</table>
					  </div>

					</div>

          <p class="submit">
          	<input type="submit" class="button-primary" value="<?php 
        _e('Save Changes');
        ?>
" />
          </p>
        </form>
	    </div>
<?php 
    }