From 7cf991d537f2df8bf02587e653632477103316ad Mon Sep 17 00:00:00 2001 From: Li Chen Date: Mon, 25 Nov 2013 19:36:28 +0100 Subject: [PATCH] Add a textarea to show the output of the CA.sh --- misc/CA.sh | 20 +++++++++++++++----- onyx/include/admin/certificate.php | 1 + onyx/include/admin/import_users.php | 4 +++- onyx/tpl/bootstrap/admin/import_users.tpl | 5 +++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/misc/CA.sh b/misc/CA.sh index 1feb3e8c..6805446f 100755 --- a/misc/CA.sh +++ b/misc/CA.sh @@ -25,6 +25,8 @@ usage() [ $# -lt 1 ] && usage +OUTPUT=`mktemp` + case $1 in "-newca" ) # echo -e -n "${GREEN}Create the directories, take care this will delete" @@ -45,7 +47,11 @@ case $1 in sed -i "s/=.*#DIR/= ${ESCAPED} #DIR/" $OPENSSL_CONF sed -i "s/=.*#CERTTYPE/= server #CERTTYPE/" $OPENSSL_CONF - pass=`pwgen 10 1` + pass=`pwgen 10 1` 2> $OUTPUT + if [ $? -ne 0 ]; then + cat $OUTPUT + exit 5 + fi openssl req -batch -new -keyout ${TOP_DIR}/private/${CAKEY} \ -out ${TOP_DIR}/${CAREQ} -passout pass:$pass \ @@ -72,7 +78,7 @@ case $1 in echo -e "${GREEN}Signing the Server crt${COLOR_RST}" openssl ca -policy policy_match -out server.crt -infiles server.csr if [ $? -ne 0 ]; then - echo -e "${RED}Signing failed${COLOR_RST}" + echo -e "${RED}Signing failed for new server${COLOR_RST}" rm -rf server.key server.crt server.csr exit 3 else @@ -94,7 +100,11 @@ case $1 in sed -i "s/=.*#COMMONNAME/= $2#COMMONNAME/" $OPENSSL_CONF sed -i "s/=.*#CERTTYPE/= client #CERTTYPE/" $OPENSSL_CONF - pass=`pwgen 10 1` + pass=`pwgen 10 1` 2> $OUTPUT + if [ $? -ne 0 ]; then + cat $OUTPUT + exit 5 + fi openssl req -batch -new -keyout ${2}.key -out ${2}.csr \ -config ${OPENSSL_CONF} -passout pass:$pass -days ${DAYS} @@ -103,14 +113,14 @@ case $1 in openssl ca -batch -policy policy_match -out ${2}.crt \ -config ${OPENSSL_CONF} -infiles ${2}.csr if [ $? -ne 0 ]; then - echo -e "${RED}Signing failed${COLOR_RST}" + echo -e "${RED}Signing failed for $2 ${COLOR_RST}" exit 3 fi # echo -e "${GREEN}Export the Client files to pkcs12${COLOR_RST}" openssl pkcs12 -export -inkey ${2}.key -in ${2}.crt -name ${2} \ -passin pass:$pass -out ${2}.p12 -passout pass:$pass if [ $? -ne 0 ]; then - echo -e "${RED}pkcs12 export failed${COLOR_RST}" + echo -e "${RED}pkcs12 export failed${COLOR_RST} for $2" exit 4 else echo -e "Exported pkcs12 file is ${2}.p12" diff --git a/onyx/include/admin/certificate.php b/onyx/include/admin/certificate.php index c80b2a66..24a8ddb7 100644 --- a/onyx/include/admin/certificate.php +++ b/onyx/include/admin/certificate.php @@ -28,6 +28,7 @@ function new_client($name, $misc_dir) putenv("OPENSSL_CONF=$misc_dir/openssl.cnf"); putenv("TOP_DIR=$misc_dir/pki"); $output = shell_exec("$misc_dir/CA.sh -newclient $name"); + return $output; } if (!empty($p[2])) diff --git a/onyx/include/admin/import_users.php b/onyx/include/admin/import_users.php index 76c4f292..b9b07dfc 100644 --- a/onyx/include/admin/import_users.php +++ b/onyx/include/admin/import_users.php @@ -31,6 +31,7 @@ if (!empty($_FILES["inputFile"]['tmp_name'])) $elements = $xpath->query("//teams/team"); if (!is_null($elements)) { + $output = ""; foreach ($elements as $element) { $team = new Team(); @@ -72,9 +73,10 @@ if (!empty($_FILES["inputFile"]['tmp_name'])) if (!empty($team->team_name)) { //TODO save the certificate subject - new_client($team->team_name, $misc_dir); + $output .= new_client($team->team_name, $misc_dir); } } + $template->assign("output", $output); } erreur("Fichier XML importé avec succès.", "success"); } diff --git a/onyx/tpl/bootstrap/admin/import_users.tpl b/onyx/tpl/bootstrap/admin/import_users.tpl index 73775932..72ed401c 100644 --- a/onyx/tpl/bootstrap/admin/import_users.tpl +++ b/onyx/tpl/bootstrap/admin/import_users.tpl @@ -10,4 +10,9 @@ + +{if isset($output)} +

Output

+
{$output}
+{/if} {/block}