-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 49cbd95
Showing
7 changed files
with
133 additions
and
0 deletions.
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,4 @@ | ||
<?php | ||
|
||
$application = new pm_Application(); | ||
$application->run(); |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<module> | ||
<id>nat</id> | ||
<name>NAT Manager</name> | ||
<description>Plugin provides an ability to manage public/private IP addresses for proper working behind NAT.</description> | ||
<version>1.0</version> | ||
<release>1</release> | ||
<vendor>Parallels, Inc.</vendor> | ||
<plesk_min_version>11.5.30</plesk_min_version> | ||
</module> |
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,81 @@ | ||
<?php | ||
|
||
class IndexController extends pm_Controller_Action | ||
{ | ||
|
||
public function indexAction() | ||
{ | ||
$this->view->pageTitle = $this->lmsg('indexPageTitle'); | ||
$this->view->list = $this->_getIpsList(); | ||
} | ||
|
||
public function indexDataAction() | ||
{ | ||
$this->_helper->json($this->_getIpsList()->fetchData()); | ||
} | ||
|
||
public function updateAddressAction() | ||
{ | ||
$ips = Modules_Nat_NatManager::getIpAddresses(); | ||
// TODO: add validation | ||
$mainIp = $this->_request->getParam('ip'); | ||
$publicIp = $ips[$mainIp]; | ||
|
||
$this->view->pageTitle = $this->lmsg('updateAddressPageTitle'); | ||
|
||
// TODO: add localization | ||
$form = new pm_Form_Simple(); | ||
$form->addElement('text', 'mainIp', array( | ||
'label' => 'Main (or private IP)', | ||
'value' => $mainIp, | ||
'required' => true, | ||
'validators' => array( | ||
array('NotEmpty', true), | ||
), | ||
)); | ||
$form->addElement('text', 'publicIp', array( | ||
'label' => 'Public IP', | ||
'value' => $publicIp, | ||
)); | ||
$form->addControlButtons(array( | ||
'cancelLink' => pm_Context::getBaseUrl(), | ||
)); | ||
|
||
if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { | ||
Modules_Nat_NatManager::updateAddress($form->getValue('mainIp'), $form->getValue('publicIp')); | ||
|
||
$this->_status->addMessage('info', 'IP address was successfully updated.'); | ||
$this->_helper->json(array('redirect' => pm_Context::getBaseUrl())); | ||
} | ||
|
||
$this->view->form = $form; | ||
} | ||
|
||
private function _getIpsList() | ||
{ | ||
$ips = Modules_Nat_NatManager::getIpAddresses(); | ||
$data = array(); | ||
foreach (Modules_Nat_NatManager::getIpAddresses() as $mainIp => $publicIp) { | ||
$data[] = array( | ||
'column-1' => '<a href="' . pm_Context::getActionUrl('index', 'update-address') . '?ip=' . $mainIp . '">' . $mainIp . '</a>', | ||
'column-2' => $publicIp, | ||
); | ||
} | ||
|
||
$list = new pm_View_List_Simple($this->view, $this->_request); | ||
$list->setData($data); | ||
$list->setColumns(array( | ||
'column-1' => array( | ||
'title' => 'Main (or private IP)', | ||
'noEscape' => true, | ||
), | ||
'column-2' => array( | ||
'title' => 'Public IP', | ||
), | ||
)); | ||
$list->setDataUrl(array('action' => 'list-data')); | ||
|
||
return $list; | ||
} | ||
|
||
} |
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,30 @@ | ||
<?php | ||
|
||
class Modules_Nat_NatManager | ||
{ | ||
|
||
public static function getIpAddresses() | ||
{ | ||
$apiResponse = pm_ApiRpc::getService()->call('<ip><get/></ip>'); | ||
$list = array(); | ||
foreach ($apiResponse->ip->get->result->addresses->ip_info as $addressNode) { | ||
$list[(string)$addressNode->ip_address] = (string)$addressNode->public_ip_address; | ||
} | ||
|
||
return $list; | ||
} | ||
|
||
public static function updateAddress($mainIp, $publicIp) | ||
{ | ||
$apiResponse = pm_ApiRpc::getService()->call( | ||
'<ip>' . | ||
'<set>' . | ||
"<filter><ip_address>$mainIp</ip_address></filter>" . | ||
"<public_ip_address>$publicIp</public_ip_address>" . | ||
'</set>' . | ||
'</ip>'); | ||
|
||
// TODO: add error handler | ||
} | ||
|
||
} |
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,6 @@ | ||
<?php | ||
|
||
$messages = array( | ||
'indexPageTitle' => 'IP Addresses for NAT', | ||
'updateAddressPageTitle' => 'IP Address Traslation', | ||
); |
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 @@ | ||
<?php echo $this->renderList($this->list); ?> |
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 @@ | ||
<?php echo $this->form; ?> |