File: //var/tmp0/brainy/scripts/bindcluster.php
<?php
error_reporting(0);
require_once '/etc/brainy/globals.php';
require_once "{$GLOBALS['brainyusr']}classes/server.php";
require_once "{$GLOBALS['brainyusr']}classes/bindserver.php";
require_once "{$GLOBALS['brainyusr']}classes/black_domain.php";
require_once "{$GLOBALS['brainyusr']}lib/punycode/idna_convert.php";
require_once "{$GLOBALS['brainyusr']}classes/backup.php";
$array_includes=array_diff(scandir($GLOBALS['CLASSES_PATH'].'/includes/backup'),array('.','..'));
foreach($array_includes as $include){
if (strripos($include, ".php")) {
require_once($GLOBALS['CLASSES_PATH']."/includes/backup/$include");
}
}
require_once "{$GLOBALS['brainyusr']}classes/hostacc.php";
class bindcluster extends bindserver {
private $token = '';
private $error = 200;
private $error_text = 'OK';
function bindcluster(){
$this->token=$this->bindserver_getToken();
}
function bindserver_getToken(){
$this->load_vars("{$GLOBALS['brainyetcconf']}bindserver/data");
return $this->module_vars['token'];
}
function bindcluster_validToken($token){
if ($token==$this->token and $token!="") {
return true;
} else {
return false;
}
}
function bindcluster_repeater(){
$answer = array();
if ($this->bindcluster_validToken($_POST['token'])) {
$answer['success']=2;
if (!empty($_POST['act'])){
$answer['result']=$this->bindcluster_run($_POST);
}
} else {
$this->error=207;
$this->error_text = 'Invalid token';
}
$this->bindcluster_showAnswerJson($answer);
}
function bindcluster_run($param){
//file_put_contents("/etc/brainy/aaaa",print_r($param,1));
$this->bindcluster_log($param);
$this->bindserver_named_options();
if ($param['user']=='root') {
switch($param['act']){
case 'add_zones':
return $this->bindserver_addZone("root",$param['zone'],$param['ip']);
break;
case 'delete_btn':
return $this->bindserver_deleteZone($param['zone'],'root');
break;
case 'get_zones':
return $this->bindserver_getZoneTable_forCluster($param);
break;
case 'get_zones2':
return $this->bindserver_getZone_forCluster($param);
break;
case 'get_zones_array':
return $this->bindserver_getZoneByUser('root');
break;
}
}
switch($param['act']){
case 'save_zone_to_file':
$this->bindserver_addZone("root",$param['zone'],'1.1.1.1');
return $this->bindserver_saveZone($param['zone'],$param['text']);
break;
case 'edit_zone':
return implode("\n",$this->bindserver_editZone($param['zone']));
break;
case 'save_defns_table':
return $this->bindserver_saveDefaultNsTable($param['zone']);
break;
case 'rebuilt_defns':
return $this->bindserver_rebuiltDefaultNs();
break;
case 'add_defns':
return $this->bindserver_addDefaultNs($param['host'],$param['ip']);
break;
case 'delete_defns':
return $this->bindserver_deleteDefaultNs($param['host']);
break;
case 'save_defns':
return $this->bindserver_saveDefaultNs($param['oldhost'],$param['host'],$param['ip'],$param['rebuild']);
break;
case 'get_defaultns_array':
return $this->bindserver_getDefaultNsArray();
break;
case 'get_defaultns_ip':
return $this->bindserver_getDefaultNsIP($param['host']);
break;
}
return false;
}
function bindcluster_log($param){
file_put_contents('bindcluster.log',implode(" ",$param)."\n",FILE_APPEND);
}
function bindcluster_showAnswerJson($params){
header('Content-type: application/json; charset=utf-8');
header('HTTP/1.1 '.$this->error.' '.$this->error_text);
$json = $params;
if ($this->error!=200) {
$json['error']=$this->error;
$json['error_text']=$this->error_text;
}
echo json_encode($json);
}
}
//file_put_contents("/etc/brainy/aaaa","fff\n");
$bind = new bindcluster;
$bind->bindcluster_repeater();