View Single Post
  #7  
Old 16th October 2012, 01:46
SuperJC SuperJC is offline
Junior Member
 
Join Date: Oct 2012
Posts: 9
Thanks: 2
Thanked 3 Times in 2 Posts
Default

Quote:
Originally Posted by SuperJC View Post
...It probably could be refined...
So, here's some refinements we made to mimic more closely what the WebUI form returns:

Code:
LCL_SERVER_ID_CP="$(mysql -N -u${LCL_MYSQL_ROOT_USERNAME} -p${LCL_MYSQL_ROOT_PASSWORD} -D${LCL_ISPCONFIG_MASTER_SERVER_MYSQL_DB} -e "SELECT server_id FROM server WHERE server_name='${LCL_SERVER_FQDN_CP}';")"
LCL_SERVER_ID_WEB="$(mysql -N -u${LCL_MYSQL_ROOT_USERNAME} -p${LCL_MYSQL_ROOT_PASSWORD} -D${LCL_ISPCONFIG_MASTER_SERVER_MYSQL_DB} -e "SELECT server_id FROM server WHERE server_name='${LCL_SERVER_FQDN_WEB}';")"
LCL_SERVER_ID_MAIL="$(mysql -N -u${LCL_MYSQL_ROOT_USERNAME} -p${LCL_MYSQL_ROOT_PASSWORD} -D${LCL_ISPCONFIG_MASTER_SERVER_MYSQL_DB} -e "SELECT server_id FROM server WHERE server_name='${LCL_SERVER_FQDN_MAIL}';")"
LCL_SERVER_ID_DB="$(mysql -N -u${LCL_MYSQL_ROOT_USERNAME} -p${LCL_MYSQL_ROOT_PASSWORD} -D${LCL_ISPCONFIG_MASTER_SERVER_MYSQL_DB} -e "SELECT server_id FROM server WHERE server_name='${LCL_SERVER_FQDN_DB}';")"
LCL_SERVER_ID_DNS1="$(mysql -N -u${LCL_MYSQL_ROOT_USERNAME} -p${LCL_MYSQL_ROOT_PASSWORD} -D${LCL_ISPCONFIG_MASTER_SERVER_MYSQL_DB} -e "SELECT server_id FROM server WHERE server_name='${LCL_SERVER_FQDN_DNS1}';")"
LCL_SERVER_ID_DNS2="$(mysql -N -u${LCL_MYSQL_ROOT_USERNAME} -p${LCL_MYSQL_ROOT_PASSWORD} -D${LCL_ISPCONFIG_MASTER_SERVER_MYSQL_DB} -e "SELECT server_id FROM server WHERE server_name='${LCL_SERVER_FQDN_DNS2}';")"

php <<PHP1
<?php
include_once('/usr/local/ispconfig/interface/lib/config.inc.php');
\$conf['start_session'] = false;
include_once('/usr/local/ispconfig/interface/lib/app.inc.php');
include_once('/usr/local/ispconfig/interface/lib/classes/db_mysql.inc.php');

	global \$app;
	\$tablename = "server";
	\$index_field = "server_id";

	// CP
	\$index_value = "${LCL_SERVER_ID_CP}";
	\$update_data = array(	"mail_server"		=>	"0",
				"web_server"		=>	"0",
				"dns_server"		=>	"0",
				"file_server"		=>	"0",
				"db_server"		=>	"0",
				"vserver_server"	=>	"0",);
	\$app->db->datalogUpdate(\$tablename, \$update_data, \$index_field, \$index_value, \$force_update = false);

	// WEB
	\$index_value = "${LCL_SERVER_ID_WEB}";
	\$update_data = array(	"mail_server"		=>	"0",
				"web_server"		=>	"1",
				"dns_server"		=>	"0",
				"file_server"		=>	"1",
				"db_server"		=>	"0",
				"vserver_server"	=>	"0",);
	\$app->db->datalogUpdate(\$tablename, \$update_data, \$index_field, \$index_value, \$force_update = false);

	// MAIL
	\$index_value = "${LCL_SERVER_ID_MAIL}";
	\$update_data = array(	"mail_server"		=>	"1",
				"web_server"		=>	"0",
				"dns_server"		=>	"0",
				"file_server"		=>	"0",
				"db_server"		=>	"0",
				"vserver_server"	=>	"0",);
	\$app->db->datalogUpdate(\$tablename, \$update_data, \$index_field, \$index_value, \$force_update = false);

	// DB
	\$index_value = "${LCL_SERVER_ID_DB}";
	\$update_data = array(	"mail_server"		=>	"0",
				"web_server"		=>	"0",
				"dns_server"		=>	"0",
				"file_server"		=>	"0",
				"db_server"		=>	"1",
				"vserver_server"	=>	"0",);
	\$app->db->datalogUpdate(\$tablename, \$update_data, \$index_field, \$index_value, \$force_update = false);

	// DNS1
	\$index_value = "${LCL_SERVER_ID_DNS1}";
	\$update_data = array(	"mail_server"		=>	"0",
				"web_server"		=>	"0",
				"dns_server"		=>	"1",
				"file_server"		=>	"0",
				"db_server"		=>	"0",
				"vserver_server"	=>	"0",);
	\$app->db->datalogUpdate(\$tablename, \$update_data, \$index_field, \$index_value, \$force_update = false);

	// DNS2
	\$index_value = "${LCL_SERVER_ID_DNS2}";
	\$update_data = array(	"mail_server"		=>	"0",
				"web_server"		=>	"0",
				"dns_server"		=>	"1",
				"file_server"		=>	"0",
				"db_server"		=>	"0",
				"vserver_server"	=>	"0",
				"mirror_server_id"	=>	"${LCL_SERVER_ID_DNS1}",);
	\$app->db->datalogUpdate(\$tablename, \$update_data, \$index_field, \$index_value, \$force_update = false);
?>
PHP1
Likely those Server_ID variables could be done in SQL too, but with my limited knowledge of it, I decided to use bash variables.

Comments, suggestions, improvement always welcome!

Thanks,

SuperJC
Reply With Quote