-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated PHP SDK for cPanel API Tokens #16
Draft
dustin-s
wants to merge
8
commits into
CpanelInc:master
Choose a base branch
from
dustin-s:add-cpanel-api-token-info
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cadfb93
Updated PHP Public API to Utilize cPanel Tokens for API 2
dustin-s 2eefac6
Updated the Inline documentation for phpunit.bootstrap.php
dustin-s f71666e
Updated the README file with the new information
dustin-s 144a7a1
Removing Cruft error_logs from running tests
dustin-s 81f3ce7
Updated the copyright for the sdk files to cPanel L.L.C.
dustin-s 3881ed1
Updated Version Numbers for old and new files.
dustin-s f876c3b
Add helpful comment to the Token Example.
dustin-s 08a65bc
Fix Inconsistent Quotes on Exception in Cpanel/Query/Http/Abstract.php
dustin-s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.phpunit.result.cache | ||
**/error_log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Cpanel_Core_Object | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -13,7 +13,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -31,9 +31,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_Core | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
@@ -48,13 +48,13 @@ | |
* @category Cpanel | ||
* @package Cpanel_Core | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
class Cpanel_Core_Object implements IteratorAggregate | ||
class Cpanel_Core_Object implements IteratorAggregate, Countable | ||
{ | ||
/** | ||
* internal storage location | ||
|
@@ -83,6 +83,11 @@ public function getIterator() | |
{ | ||
return new ArrayIterator($this->dataContainer); | ||
} | ||
|
||
public function count() { | ||
return $this->getIterator()->count(); | ||
} | ||
|
||
/** | ||
* Accessor for storing data internally | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Cpanel_Core_PriorityQueue | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -13,7 +13,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -31,9 +31,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_Core | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
@@ -48,9 +48,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_Core | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Example usage of iterating over a response (Cpanel_Query_Object) | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -13,7 +13,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -31,9 +31,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_PublicAPI | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Example usage of WHM Service | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -13,7 +13,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -31,9 +31,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_PublicAPI | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Example usage of cPanel Service | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -13,7 +13,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -31,9 +31,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_PublicAPI | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Introduction to PublicAPI and the cPanel PHP library | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -13,7 +13,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -31,9 +31,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_PublicAPI | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Example usage of Direct URL query via PublicAPI client | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -13,7 +13,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -31,9 +31,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_PublicAPI | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Example usage of configuration options for the PublicAPI client and cPanel | ||
* PHP library. | ||
* | ||
* Copyright (c) 2011, cPanel, Inc. | ||
* Copyright (c) 2011, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
|
@@ -14,7 +14,7 @@ | |
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, Inc. nor the | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
|
@@ -32,9 +32,9 @@ | |
* @category Cpanel | ||
* @package Cpanel_PublicAPI | ||
* @author David Neimeyer <[email protected]> | ||
* @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) | ||
* @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.1.0 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Example usage of cPanel Service with an API Token | ||
* | ||
* Copyright (c) 2019, cPanel, L.L.C. | ||
* All rights reserved. | ||
* http://cpanel.net | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of cPanel, L.L.C. nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @category Cpanel | ||
* @package Cpanel_PublicAPI | ||
* @author Dustin Scherer <[email protected]> | ||
* @copyright Copyright (c) 2019, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) | ||
* @license http://sdk.cpanel.net/license/bsd.html BSD License | ||
* @version 0.2.0 | ||
* @link http://sdk.cpanel.net | ||
* @since 0.2.0 | ||
*/ | ||
|
||
/** | ||
* Please look at the Introduction_to_PublicAPI.php for more details. | ||
*/ | ||
TRY { | ||
require_once realpath( dirname(__FILE__) . '/../Util/Autoload.php'); | ||
|
||
# Replace these values with real values from your server | ||
# You can generate a cPanel API Token in the Cpanel > API Tokens Interface | ||
$HOST_NAME = '10.1.32.118'; | ||
$HOST_USER = 'green'; | ||
$TOKEN = '33JK2FL611YNDACZX1EO4M1N7O37HHPE'; | ||
|
||
/** | ||
* Getting a cPanel Service object and invoking the api2_request method on | ||
* the cPanel Service object itself. The preferred method is to use the | ||
* cpanel_api{n}_request() method available in the PublicAPI interface, but | ||
* this is here for demonstration purposes of the Service available in the | ||
* cPanel library. | ||
* | ||
* We use the cPanel Service's accessor methods to set initialization | ||
* variables. Authenticating as the user with a token | ||
*/ | ||
$cpanel = Cpanel_PublicAPI::factory('cPanel'); | ||
$cpanel->setUser($HOST_USER) | ||
->setToken($TOKEN) | ||
->setHost($HOST_NAME); | ||
|
||
$service = 'cpanel'; | ||
$queryMF = array( | ||
'module' => 'Email', | ||
'function' => 'listforwards', | ||
'user' => $HOST_USER, | ||
); | ||
$response = $cpanel->api2_request($service, $queryMF); | ||
|
||
echo "API2 response for {$queryMF['module']}::{$queryMF['function']} '\n"; | ||
|
||
foreach ($response->cpanelresult->data as $dataset) { | ||
foreach ($dataset as $key => $value) { | ||
echo "\t$key: $value\n"; | ||
} | ||
} | ||
|
||
echo "\n"; | ||
} | ||
CATCH(Exception $e) { | ||
echo $e->getMessage() . "\n" . $e->getTraceAsString() . "\n"; | ||
} | ||
echo "EOF: You've successfully ended the " . basename(__FILE__) . " script.\n"; | ||
?> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t this say 2019?