function hook_oneportalcloud_ChangePassword($params) { if (isset($_POST['ac'])) { return 'success'; } $params = $params['params']; if ($params['moduletype'] != 'oneportalcloud') { return 'success'; } $op = new OnePortalCloud($params['configoption1'], $params['configoption2'], $params['configoption3']); $server_id = $params['customfields']['Server ID']; if (empty($server_id)) { return 'Unable to determine Server ID to suspend'; } if (substr(strtoupper($server_id), 0, 3) != 'LSN') { $server_id = 'LSN-' . $server_id; } $ret = $op->changePassword($server_id, $params['password']); if (!$ret->error) { $res = 'success'; } else { $res = $ret->error; } return $res; }
function oneportalcloud_AdminServicesTabFields($params) { check_setup($params); $op = new OnePortalCloud($params['configoption1'], $params['configoption2'], $params['configoption3']); $server_id = $params['customfields']['Server ID']; if (empty($server_id)) { return 'Unable to determine Server ID to suspend'; } if (substr(strtoupper($server_id), 0, 3) != 'LSN') { $server_id = 'LSN-' . $server_id; } $server = $op->serverlist($server_id); if (empty($server)) { return 'Server cancelled or not provisioned yet.'; } //Get console $consolearea = "<link rel=\"stylesheet\" href=\"../modules/servers/oneportalcloud/includes/css/adminArea.css\"/>\n\t<a class='btn' href='{$params['configoption3']}/server/{$server_id}/console' target='_blank'>Open Server Console</a>"; // Get hardware $hardware = $op->gethardware($server_id); $status = $op->getStatus($server_id); $fw_rules = $op->getFireWallRules($server_id); // Get IP addresses $ips = oneportalcloud_ipaddresses($params); $statusarea = ""; if (empty($status->error)) { if ($status->booted) { $statusarea .= "<span class=\"label label-default power label-success\">Online</span>"; } else { $statusarea .= "<span class=\"label label-default offline label-success\">Offline</span>"; } if ($status->suspended) { $statusarea .= "<span class=\"label label-default suspended label-success\">Suspended</span>"; } if ($status->locked) { $statusarea .= "<span class=\"label label-default suspended label-success\">Locked</span>"; } $statusarea .= "<style>.power { background-color: #5cb85c; } .label{ margin-left: 10px;} .offline{ background-color: #FF0000}</style>"; } if (empty($hardware->error)) { $hwtable = '<table id="serverhwtable"><tr><th>Category</th><th>Item</th></tr>'; foreach ($hardware as $item) { $hwtable .= "<tr><td>{$item->category}</td><td>{$item->option}</td></tr>"; } $hwtable .= '</table>'; } if (!empty($ips)) { $var3 = '<table id="serveriptable"><tr><th>Network</th><th>IP Address</th><th>IP Type</th><th>Reverse DNS</th></tr>'; foreach ($ips as $nettype => $network) { $nettype = ucfirst($nettype); foreach ($network as $ip) { if ($nettype == 'Private' || $ip['type'] == 'network' || $ip['type'] == 'gateway' || $ip['type'] == 'broadcast') { $var3 .= "<tr><td>{$nettype}</td><td>{$ip['ipaddress']}</td><td>{$ip['type']}</td><td> </td></tr>"; } else { $var3 .= "<tr><td>{$nettype}</td><td>{$ip['ipaddress']}</td><td>{$ip['type']}</td><td>{$ip['ptr']}</td></tr>"; } } } $var3 .= '</table>'; } else { $var3 = '<p>Unable to determine IP Addresses</p>'; } ob_start(); $has_rules = array(); foreach ($fw_rules->firewall_by_network as $id => $network) { ?> <h3>Firewall Rules for <?php echo $fw_rules->network_interface_obj->{$id}->label; ?> </h3> <?php $has_rules[$id] = true; ?> <table class="serverfwtable" id="fw_rules_<?php echo $id; ?> "> <thead> <tr> <th>Address</th> <th>Command</th> <th>Port</th> <th>Protocol</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach ($network as $fw) { ?> <tr data-value='<?php echo $fw->id; ?> ' data-rule-position='<?php echo $fw->position; ?> ' id='rule_<?php echo $fw->id; ?> ' class='fw_rule'> <td><?php echo $fw->address; ?> </td> <td><?php echo $fw->command; ?> </td> <td><?php echo $fw->port; ?> </td> <td><?php echo $fw->protocol; ?> </td> <td><button type='button' class='btn btn-small btn-danger btn-submit rule_remove' id='<?php echo $fw->id; ?> ' data-network-id='<?php echo $id; ?> '>Remove</button></td> </tr> <?php } ?> </tbody> <tfoot> <tr> <td colspan="4"></td> <td colspan="1"> <button class="add-row btn btn-small btn-success btn-submit" type="button" data-network-id="<?php echo $id; ?> ">Add</button> </td> </tr> </tfoot> </table> <?php } ?> <?php foreach ($fw_rules->network_interface_obj as $nic) { if (!isset($has_rules[$nic->id])) { ?> <h3>Firewall Rules for <?php echo $nic->label; ?> </h3> <table class="serverfwtable" id="fw_rules_<?php echo $nic->id; ?> "> <thead> <tr> <th>Address</th> <th>Command</th> <th>Network Interface</th> <th>Port</th> <th>Protocol</th> <th>Action</th> </tr> </thead> <tbody> <tr id="sry"> <td colspan="5">You have no additional rules configured.</td> </tr> <tfoot> <tr> <td colspan="4"></td> <td colspan="1"> <button class="add-row btn btn-small btn-success btn-submit" type="button" data-network-id="'.$nic->id.'">Add</button> </td> </tr> </tfoot> </tbody> </table> <?php } ?> <?php } ?> <table class='serverdeftable'> <thead> <tr> <th>Network Interface</th> <th>Default Firewall Rule</th> </tr> </thead> <tbody> <?php foreach ($fw_rules->network_interface_obj as $nic) { $default = $nic->default_firewall_rule; $accept_select = $default == 'ACCEPT' ? 'selected' : ''; $drop_select = $default == 'DROP' ? 'selected' : ''; ?> <tr> <td><?php echo $nic->label; ?> </td> <td> <select name='default_rule_<?php echo $nic->id; ?> ' data-network-id='<?php echo $nic->id; ?> '> <option <?php echo $accept_select; ?> value='accept'>ACCEPT</option> <option <?php echo $drop_select; ?> value='drop'>DROP</option> </select> </td> </tr> <?php } ?> </tbody> </table> <div align='center'> <button id="save-changes" class="fw_save btn btn-primary" >Save Firewall changes</button> </div> <div id='save_dialog' title='Save Firewall changes?'> <p>Are you sure you want to make these changes to the firewall? Changes may take up to 5 minutes to become visible.</p> </div> <input type="hidden" name="deletedRules" value="" id="deletedRules"> <script type="text/javascript"> var userid = '<?php echo $params['userid']; ?> '; var serviceid = '<?php echo $params['serviceid']; ?> '; </script> <script type="text/javascript" src="../modules/servers/oneportalcloud/includes/js/adminArea.js"></script> <?php $fwarea = ob_get_contents(); ob_end_clean(); // Send what we've made $fieldsarray = array('Server Console' => $consolearea, 'Server status' => $statusarea, 'Package Items' => $hwtable, 'IP Addresses' => $var3, 'Firewall Information' => $fwarea); return $fieldsarray; }