Skip to content

Commit

Permalink
Zone template management moved to the class.
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondas committed Feb 9, 2022
1 parent 76fab36 commit ec29a01
Show file tree
Hide file tree
Showing 18 changed files with 657 additions and 610 deletions.
3 changes: 2 additions & 1 deletion add_zone_master.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @license https://opensource.org/licenses/GPL-3.0 GPL
*/

use Poweradmin\ZoneTemplate;
use Poweradmin\ZoneType;

require_once 'inc/toolkit.inc.php';
Expand Down Expand Up @@ -123,7 +124,7 @@

$available_zone_types = array("MASTER", "NATIVE");
$users = do_hook('show_users');
$zone_templates = get_list_zone_templ($_SESSION['userid']);
$zone_templates = ZoneTemplate::get_list_zone_templ($_SESSION['userid']);

echo " <form method=\"post\" action=\"add_zone_master.php\">\n";
echo " <table>\n";
Expand Down
5 changes: 4 additions & 1 deletion add_zone_templ.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* @copyright 2010-2022 Poweradmin Development Team
* @license https://opensource.org/licenses/GPL-3.0 GPL
*/

use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/message.inc.php';

Expand All @@ -38,7 +41,7 @@
} else {

if (isset($_POST['commit'])) {
if (add_zone_templ($_POST, $_SESSION['userid'])) {
if (ZoneTemplate::add_zone_templ($_POST, $_SESSION['userid'])) {
success(SUC_ZONE_TEMPL_ADD);
} // TODO: otherwise repopulate values to form
}
Expand Down
7 changes: 4 additions & 3 deletions add_zone_templ_record.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

use Poweradmin\RecordType;
use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/validation.inc.php';
Expand Down Expand Up @@ -82,8 +83,8 @@
exit;
}

$templ_details = get_zone_templ_details($zone_templ_id);
$owner = get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
$templ_details = ZoneTemplate::get_zone_templ_details($zone_templ_id);
$owner = ZoneTemplate::get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);

/*
If the form as been submitted
Expand All @@ -93,7 +94,7 @@
if (!(do_hook('verify_permission' , 'zone_master_add' )) || !$owner) {
error(ERR_PERM_ADD_RECORD);
} else {
if (add_zone_templ_record($zone_templ_id, $name, $type, $content, $ttl, $prio)) {
if (ZoneTemplate::add_zone_templ_record($zone_templ_id, $name, $type, $content, $ttl, $prio)) {
success(_('The record was successfully added.'));
$name = $type = $content = $ttl = $prio = "";
}
Expand Down
3 changes: 2 additions & 1 deletion bulk_registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @license https://opensource.org/licenses/GPL-3.0 GPL
*/

use Poweradmin\ZoneTemplate;
use Poweradmin\ZoneType;

require_once 'inc/toolkit.inc.php';
Expand Down Expand Up @@ -98,7 +99,7 @@

$available_zone_types = array("MASTER", "NATIVE");
$users = do_hook('show_users');
$zone_templates = get_list_zone_templ($_SESSION['userid']);
$zone_templates = ZoneTemplate::get_list_zone_templ($_SESSION['userid']);

echo " <form method=\"post\" action=\"bulk_registration.php\">\n";
echo " <table>\n";
Expand Down
10 changes: 6 additions & 4 deletions delete_zone_templ.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
* @copyright 2010-2022 Poweradmin Development Team
* @license https://opensource.org/licenses/GPL-3.0 GPL
*/

use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/validation.inc.php';
require_once 'inc/message.inc.php';
require_once 'inc/message.inc.php';

include_once 'inc/header.inc.php';

Expand All @@ -45,18 +47,18 @@
$confirm = $_GET['confirm'];
}

$owner = get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
$owner = ZoneTemplate::get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
if ($zone_templ_id == "-1") {
error(ERR_INV_INPUT);
} else {
if (!do_hook('verify_permission' , 'zone_master_add' ) || !$owner) {
error(ERR_PERM_DEL_ZONE_TEMPL);
} else {
$templ_details = get_zone_templ_details($zone_templ_id);
$templ_details = ZoneTemplate::get_zone_templ_details($zone_templ_id);
echo " <h2>" . _('Delete zone template') . " \"" . $templ_details['name'] . "\"</h2>\n";

if (isset($_GET['confirm']) && $_GET["confirm"] == '1') {
delete_zone_templ($zone_templ_id);
ZoneTemplate::delete_zone_templ($zone_templ_id);
success(SUC_ZONE_TEMPL_DEL);
} else {
echo " <p>" . _('Are you sure?') . "</p>\n";
Expand Down
11 changes: 7 additions & 4 deletions delete_zone_templ_record.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* @copyright 2010-2022 Poweradmin Development Team
* @license https://opensource.org/licenses/GPL-3.0 GPL
*/

use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/validation.inc.php';
require_once 'inc/message.inc.php';
Expand All @@ -52,14 +55,14 @@
if ($record_id == "-1" || $zone_templ_id == "-1") {
error(ERR_INV_INPUT);
} else {
$owner = get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
$owner = ZoneTemplate::get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
if ($confirm == '1' && $owner) {
if (delete_zone_templ_record($record_id)) {
if (ZoneTemplate::delete_zone_templ_record($record_id)) {
success(SUC_RECORD_DEL);
}
} else {
$templ_details = get_zone_templ_details($zone_templ_id);
$record_info = get_zone_templ_record_from_id($record_id);
$templ_details = ZoneTemplate::get_zone_templ_details($zone_templ_id);
$record_info = ZoneTemplate::get_zone_templ_record_from_id($record_id);

echo " <h2>" . _('Delete record in zone') . " \"" . $templ_details['name'] . "\"</h2>\n";

Expand Down
5 changes: 4 additions & 1 deletion dnssec.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* @copyright 2010-2022 Poweradmin Development Team
* @license https://opensource.org/licenses/GPL-3.0 GPL
*/

use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/validation.inc.php';

Expand Down Expand Up @@ -92,7 +95,7 @@
$domain_type = get_domain_type($zone_id);
$domain_name = get_domain_name_by_id($zone_id);
$record_count = count_zone_records($zone_id);
$zone_templates = get_list_zone_templ($_SESSION['userid']);
$zone_templates = ZoneTemplate::get_list_zone_templ($_SESSION['userid']);
$zone_template_id = get_zone_template($zone_id);

echo " <h2>" . _('DNSSEC keys for zone') . " \"" . get_domain_name_by_id($zone_id) . "\"</h2>\n";
Expand Down
5 changes: 4 additions & 1 deletion dnssec_ds_dnskey.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* @copyright 2010-2022 Poweradmin Development Team
* @license https://opensource.org/licenses/GPL-3.0 GPL
*/

use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/validation.inc.php';

Expand Down Expand Up @@ -76,7 +79,7 @@
$domain_type = get_domain_type($zone_id);
$domain_name = get_domain_name_by_id($zone_id);
$record_count = count_zone_records($zone_id);
$zone_templates = get_list_zone_templ($_SESSION['userid']);
$zone_templates = ZoneTemplate::get_list_zone_templ($_SESSION['userid']);
$zone_template_id = get_zone_template($zone_id);

echo " <h2>" . _('DNSSEC public records for zone') . " \"" . get_domain_name_by_id($zone_id) . "\"</h2>\n";
Expand Down
9 changes: 5 additions & 4 deletions edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

use Poweradmin\RecordLog;
use Poweradmin\RecordType;
use Poweradmin\ZoneTemplate;
use Poweradmin\ZoneType;

require_once 'inc/toolkit.inc.php';
Expand Down Expand Up @@ -123,14 +124,14 @@
}

if (isset($_POST['save_as'])) {
if (zone_templ_name_exists($_POST['templ_name'])) {
if (ZoneTemplate::zone_templ_name_exists($_POST['templ_name'])) {
error(ERR_ZONE_TEMPL_EXIST);
} elseif ($_POST['templ_name'] == '') {
error(ERR_ZONE_TEMPL_IS_EMPTY);
} else {
success(SUC_ZONE_TEMPL_ADD);
$records = get_records_from_domain_id($zone_id);
add_zone_templ_save_as($_POST['templ_name'], $_POST['templ_descr'], $_SESSION['userid'], $records, get_domain_name_by_id($zone_id));
ZoneTemplate::add_zone_templ_save_as($_POST['templ_name'], $_POST['templ_descr'], $_SESSION['userid'], $records, get_domain_name_by_id($zone_id));
}
}

Expand Down Expand Up @@ -225,7 +226,7 @@

$domain_type = get_domain_type($zone_id);
$record_count = count_zone_records($zone_id);
$zone_templates = get_list_zone_templ($_SESSION['userid']);
$zone_templates = ZoneTemplate::get_list_zone_templ($_SESSION['userid']);
$zone_template_id = get_zone_template($zone_id);

$zone_name_to_display = get_domain_name_by_id($zone_id);
Expand Down Expand Up @@ -521,7 +522,7 @@
echo " </tr>\n";
echo " </form>\n";
} else {
$zone_template_details = get_zone_templ_details($zone_template_id);
$zone_template_details = ZoneTemplate::get_zone_templ_details($zone_template_id);
echo " <tr><td>" . (isset($zone_template_details) ? strtolower($zone_template_details['name']) : "none" ) . "</td><td>&nbsp;</td></tr>\n";
}

Expand Down
23 changes: 12 additions & 11 deletions edit_zone_templ.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

use Poweradmin\RecordType;
use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/pagination.inc.php';
Expand Down Expand Up @@ -71,33 +72,33 @@
/*
Check permissions
*/
$owner = get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
$owner = ZoneTemplate::get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);

if (isset($_POST['commit']) && $owner) {
success(SUC_ZONE_TEMPL_UPD);
foreach ($_POST['record'] as $record) {
edit_zone_templ_record($record);
ZoneTemplate::edit_zone_templ_record($record);
}
}

if (isset($_POST['edit']) && $owner) {
edit_zone_templ($_POST, $zone_templ_id);
ZoneTemplate::edit_zone_templ($_POST, $zone_templ_id);
}

if (isset($_POST['save_as'])) {
if (zone_templ_name_exists($_POST['templ_name'])) {
if (ZoneTemplate::zone_templ_name_exists($_POST['templ_name'])) {
error(ERR_ZONE_TEMPL_EXIST);
} elseif ($_POST['templ_name'] == '') {
error(ERR_ZONE_TEMPL_IS_EMPTY);
} else {
success(SUC_ZONE_TEMPL_ADD);
$templ_details = get_zone_templ_details($zone_templ_id);
add_zone_templ_save_as($_POST['templ_name'], $_POST['templ_descr'], $_SESSION['userid'], $_POST['record']);
$templ_details = ZoneTemplate::get_zone_templ_details($zone_templ_id);
ZoneTemplate::add_zone_templ_save_as($_POST['templ_name'], $_POST['templ_descr'], $_SESSION['userid'], $_POST['record']);
}
}

if (isset($_POST['update_zones'])) {
$zones = get_list_zone_use_templ($zone_templ_id, $_SESSION['userid']);
$zones = ZoneTemplate::get_list_zone_use_templ($zone_templ_id, $_SESSION['userid']);
success(SUC_ZONES_UPD);
foreach ($zones as $zone) {
update_zone_records($zone['id'], $zone_templ_id);
Expand All @@ -107,18 +108,18 @@
if (!(do_hook('verify_permission' , 'zone_master_add' )) || !$owner) {
error(ERR_PERM_EDIT_ZONE_TEMPL);
} else {
if (zone_templ_id_exists($zone_templ_id) == "0") {
if (ZoneTemplate::zone_templ_id_exists($zone_templ_id) == "0") {
error(ERR_ZONE_TEMPL_NOT_EXIST);
} else {
$record_count = count_zone_templ_records($zone_templ_id);
$templ_details = get_zone_templ_details($zone_templ_id);
$record_count = ZoneTemplate::count_zone_templ_records($zone_templ_id);
$templ_details = ZoneTemplate::get_zone_templ_details($zone_templ_id);
echo " <h2>" . _('Edit zone template') . " \"" . $templ_details['name'] . "\"</h2>\n";

echo " <div class=\"showmax\">\n";
show_pages($record_count, $iface_rowamount, $zone_templ_id);
echo " </div>\n";

$records = get_zone_templ_records($zone_templ_id, ROWSTART, $iface_rowamount, RECORD_SORT_BY);
$records = ZoneTemplate::get_zone_templ_records($zone_templ_id, ROWSTART, $iface_rowamount, RECORD_SORT_BY);
if ($records == "-1") {
echo " <p>" . _("This template zone does not have any records yet.") . "</p>\n";
} else {
Expand Down
7 changes: 4 additions & 3 deletions edit_zone_templ_record.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

use Poweradmin\RecordType;
use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/validation.inc.php';
Expand All @@ -47,7 +48,7 @@
$zone_templ_id = $_GET['zone_templ_id'];
}

$owner = get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
$owner = ZoneTemplate::get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);

if (isset($_POST["commit"])) {
if (!(do_hook('verify_permission' , 'zone_master_add' )) || !$owner) {
Expand All @@ -62,13 +63,13 @@
}
}

$templ_details = get_zone_templ_details($zone_templ_id);
$templ_details = ZoneTemplate::get_zone_templ_details($zone_templ_id);
echo " <h2>" . _('Edit record in zone template') . " \"" . $templ_details['name'] . "\"</h2>\n";

if (!(do_hook('verify_permission' , 'zone_master_add' )) || !$owner) {
error(ERR_PERM_VIEW_RECORD);
} else {
$record = get_zone_templ_record_from_id($record_id);
$record = ZoneTemplate::get_zone_templ_record_from_id($record_id);
echo " <form method=\"post\" action=\"edit_zone_templ_record.php?zone_templ_id=" . $zone_templ_id . "&id=" . $record_id . "\">\n";
echo " <table>\n";
echo " <tr>\n";
Expand Down
3 changes: 2 additions & 1 deletion inc/plugins/users_local/users_local.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

use Poweradmin\Password;
use Poweradmin\ZoneTemplate;

require_once 'inc/toolkit.inc.php';
require_once 'inc/session.inc.php';
Expand Down Expand Up @@ -232,7 +233,7 @@ function delete_user_local($uid, $zones) {
$query = "DELETE FROM users WHERE id = " . $db->quote($uid, 'integer');
$db->query($query);

delete_zone_templ_userid($uid);
ZoneTemplate::delete_zone_templ_userid($uid);
}
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions inc/record.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

require_once('templates.inc.php');
use Poweradmin\ZoneTemplate;

/**
* DNS record functions
Expand Down Expand Up @@ -664,13 +664,13 @@ function add_domain($domain, $owner, $type, $slave_master, $zone_template) {
} elseif ($domain_id && is_numeric($zone_template)) {
global $dns_ttl;

$templ_records = get_zone_templ_records($zone_template);
$templ_records = ZoneTemplate::get_zone_templ_records($zone_template);
if ($templ_records != -1) {
foreach ($templ_records as $r) {
if ((preg_match('/in-addr.arpa/i', $domain) && ($r["type"] == "NS" || $r["type"] == "SOA")) || (!preg_match('/in-addr.arpa/i', $domain))) {
$name = parse_template_value($r["name"], $domain);
$name = ZoneTemplate::parse_template_value($r["name"], $domain);
$type = $r["type"];
$content = parse_template_value($r["content"], $domain);
$content = ZoneTemplate::parse_template_value($r["content"], $domain);
$ttl = $r["ttl"];
$prio = intval($r["prio"]);

Expand Down Expand Up @@ -1754,7 +1754,7 @@ function update_zone_records($zone_id, $zone_template_id) {

if ($zone_master_add == "1" || $zone_slave_add == "1") {
$domain = get_domain_name_by_id($zone_id);
$templ_records = get_zone_templ_records($zone_template_id);
$templ_records = ZoneTemplate::get_zone_templ_records($zone_template_id);

if ($templ_records == -1) {
return;
Expand All @@ -1763,13 +1763,13 @@ function update_zone_records($zone_id, $zone_template_id) {
foreach ($templ_records as $r) {
//fixme: appears to be a bug and regex match should occur against $domain
if ((preg_match('/in-addr.arpa/i', $zone_id) && ($r["type"] == "NS" || $r["type"] == "SOA")) || (!preg_match('/in-addr.arpa/i', $zone_id))) {
$name = parse_template_value($r["name"], $domain);
$name = ZoneTemplate::parse_template_value($r["name"], $domain);
$type = $r["type"];
if ($type == "SOA") {
$db->exec("DELETE FROM records WHERE domain_id = " . $db->quote($zone_id, 'integer') . " AND type = 'SOA'");
$content = get_updated_soa_record($soa_rec);
} else {
$content = parse_template_value($r["content"], $domain);
$content = ZoneTemplate::parse_template_value($r["content"], $domain);
}

$ttl = $r["ttl"];
Expand Down
Loading

0 comments on commit ec29a01

Please sign in to comment.