2022-06-12 03:28:43 +02:00
< ? php
2022-09-01 04:21:17 +02:00
if ( processForm ()) {
$_POST [ 'domain' ] = formatAbsoluteDomain ( $_POST [ 'domain' ]);
2022-06-12 03:28:43 +02:00
2022-09-01 04:21:17 +02:00
if ( query ( 'select' , 'zones' , [ 'zone' => $_POST [ 'domain' ]], 'zone' ) !== [])
2022-09-15 19:17:48 +02:00
output ( 403 , 'Cette zone existe déjà sur ce service.' );
2022-06-12 03:28:43 +02:00
2022-10-06 13:12:04 +02:00
exec ( CONF [ 'ns' ][ 'kdig_path' ] . ' ' . ltrim ( strstr ( $_POST [ 'domain' ], '.' ), '.' ) . ' NS +short' , $parentAuthoritatives );
if ( $parentAuthoritatives === [])
output ( 403 , 'Serveurs de noms de la zone parente introuvables' );
2022-09-03 18:12:49 +02:00
foreach ( $parentAuthoritatives as $parentAuthoritative )
checkAbsoluteDomainFormat ( $parentAuthoritative );
2022-10-06 13:12:04 +02:00
2022-10-09 23:33:45 +02:00
exec ( CONF [ 'ns' ][ 'kdig_path' ] . ' ' . $_POST [ 'domain' ] . ' NS @' . $parentAuthoritatives [ 0 ] . ' +noidn' , $results );
2022-11-20 01:05:03 +01:00
if ( preg_match ( '/^' . preg_quote ( $_POST [ 'domain' ], '/' ) . '[\t ]+[0-9]{1,8}[\t ]+IN[\t ]+NS[\t ]+(?<salt>[0-9a-f]{8})-(?<hash>[0-9a-f]{32})\.auth-owner.+$/m' , implode ( " \n " , $results ), $matches ) !== 1 )
2022-10-06 13:12:04 +02:00
output ( 403 , 'Enregistrement d\'authentification introuvable' );
2022-11-20 01:05:03 +01:00
checkAuthToken ( $matches [ 'salt' ], $matches [ 'hash' ]);
2022-08-30 00:37:37 +02:00
2022-09-17 00:49:07 +02:00
rateLimit ();
2022-09-14 17:19:17 +02:00
insert ( 'zones' , [
'zone' => $_POST [ 'domain' ],
'username' => $_SESSION [ 'username' ],
]);
2022-06-12 03:28:43 +02:00
2022-09-01 04:21:17 +02:00
$knotZonePath = CONF [ 'ns' ][ 'knot_zones_path' ] . " / " . $_POST [ 'domain' ] . " zone " ;
2022-11-20 01:05:03 +01:00
$knotZone = implode ( ' ' , [
$_POST [ 'domain' ],
SOA_VALUES [ 'ttl' ],
'SOA' ,
CONF [ 'ns' ][ 'servers' ][ 0 ],
SOA_VALUES [ 'email' ],
1 ,
SOA_VALUES [ 'refresh' ],
SOA_VALUES [ 'retry' ],
SOA_VALUES [ 'expire' ],
SOA_VALUES [ 'negative' ],
]) . " \n " ;
2022-09-01 04:21:17 +02:00
foreach ( CONF [ 'ns' ][ 'servers' ] as $server )
$knotZone .= $_POST [ 'domain' ] . ' 86400 NS ' . $server . " \n " ;
if ( is_int ( file_put_contents ( $knotZonePath , $knotZone )) !== true )
2022-09-15 19:17:48 +02:00
output ( 500 , 'Failed to write new zone file.' );
2022-09-01 04:21:17 +02:00
if ( chmod ( $knotZonePath , 0660 ) !== true )
2022-09-15 19:17:48 +02:00
output ( 500 , 'Failed to chmod new zone file.' );
2022-06-12 03:28:43 +02:00
2022-09-01 04:21:17 +02:00
knotcConfExec ([
" set 'zone[ " . $_POST [ 'domain' ] . " ]' " ,
2022-11-20 01:12:51 +01:00
" set 'zone[ " . $_POST [ 'domain' ] . " ].template' 'niver' " ,
2022-09-01 04:21:17 +02:00
]);
2022-06-12 03:28:43 +02:00
2022-11-20 01:12:51 +01:00
output ( 200 , 'La zone a été créée.' );
2022-09-01 04:21:17 +02:00
}
2022-06-12 03:28:43 +02:00
2022-10-06 13:12:04 +02:00
$proof = getAuthToken ();
2022-09-01 04:21:17 +02:00
?>
2022-09-14 13:30:45 +02:00
< p >
2022-10-06 13:12:04 +02:00
Le domaine doit avoir un < ? = linkToDocs ( 'ns-record' , 'enregistrement NS' ) ?> qui commence par <code><?= $proof ?>.auth-owner</code> lors du traitement de ce formulaire.
</ p >
< p >
La zone sera servie par ces serveurs de noms :
2022-09-14 13:30:45 +02:00
< ul >
< ? php
foreach ( CONF [ 'ns' ][ 'servers' ] as $server )
echo ' <li><code>' . $server . '</code></li>' ;
?>
</ ul >
</ p >
2022-09-01 04:21:17 +02:00
< form method = " post " >
< label for = " domain " > Domaine </ label >< br >
< input required = " " placeholder = " domain.<?= PLACEHOLDER_DOMAIN ?>. " id = " domain " name = " domain " type = " text " >< br >
< input value = " Ajouter " type = " submit " >
</ form >