Passed
Push — master ( b0ecee...6897d9 )
by Kevin
56s queued 16s
created
html/user/account_ownership.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -28,140 +28,140 @@
 block discarded – undo
28 28
 check_tokens($user->authenticator);
29 29
 
30 30
 function account_ownership_action($user) {
31
-  // POST request - the user has submitted the form.
32
-  page_head(tra("Proof of account ownership results"), null, null, null, boinc_recaptcha_get_head_extra());
33
-
34
-  global $recaptcha_private_key;
35
-  if ($recaptcha_private_key) {
36
-      // Recaptcha is enabled on the BOINC server
37
-      if (!boinc_recaptcha_isValidated($recaptcha_private_key)) {
38
-          // The user failed to solve the recaptcha prompt - redirect them to an error message!
39
-          error_page(
40
-              tra("Your reCAPTCHA response was not correct. Please try again.")
41
-          );
42
-      }
43
-  }
44
-
45
-  // Input is passed in from the openssl_sign_form
46
-  $user_data = htmlentities(post_str("user_data", true), ENT_QUOTES, "UTF-8"); // Convert special characters to html equivelant
47
-
48
-  if ((strlen($user_data) > 0) && (strlen($user_data) <= 4096)) {
49
-      require_once("../inc/account_ownership.inc");
50
-      // Check that the private key file exists where specified. If not, redirect to error page.
51
-      if (!file_exists($account_ownership_private_key_file_path)) {
52
-          error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
53
-      }
54
-
55
-      // Check that the public key file exists where specified. If not, redirect to error page.
56
-      if (!file_exists($account_ownership_public_key_file_path)) {
57
-          error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
58
-      }
59
-
60
-      $privkey = fopen($account_ownership_private_key_file_path, "r"); // Opening private key file
61
-      if (!isset($privkey) || empty($privkey)) {
31
+    // POST request - the user has submitted the form.
32
+    page_head(tra("Proof of account ownership results"), null, null, null, boinc_recaptcha_get_head_extra());
33
+
34
+    global $recaptcha_private_key;
35
+    if ($recaptcha_private_key) {
36
+        // Recaptcha is enabled on the BOINC server
37
+        if (!boinc_recaptcha_isValidated($recaptcha_private_key)) {
38
+            // The user failed to solve the recaptcha prompt - redirect them to an error message!
39
+            error_page(
40
+                tra("Your reCAPTCHA response was not correct. Please try again.")
41
+            );
42
+        }
43
+    }
44
+
45
+    // Input is passed in from the openssl_sign_form
46
+    $user_data = htmlentities(post_str("user_data", true), ENT_QUOTES, "UTF-8"); // Convert special characters to html equivelant
47
+
48
+    if ((strlen($user_data) > 0) && (strlen($user_data) <= 4096)) {
49
+        require_once("../inc/account_ownership.inc");
50
+        // Check that the private key file exists where specified. If not, redirect to error page.
51
+        if (!file_exists($account_ownership_private_key_file_path)) {
52
+            error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
53
+        }
54
+
55
+        // Check that the public key file exists where specified. If not, redirect to error page.
56
+        if (!file_exists($account_ownership_public_key_file_path)) {
57
+            error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
58
+        }
59
+
60
+        $privkey = fopen($account_ownership_private_key_file_path, "r"); // Opening private key file
61
+        if (!isset($privkey) || empty($privkey)) {
62 62
         error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
63
-      }
64
-      $privkey_contents = fread($privkey, 8192); // Reading contents of private key into var
65
-      fclose($privkey); // Closing private key file
63
+        }
64
+        $privkey_contents = fread($privkey, 8192); // Reading contents of private key into var
65
+        fclose($privkey); // Closing private key file
66 66
 
67
-      $userid = $user->id; // Retrieving the user's UserId
68
-      $message_data = "$userid $user_data"; // Create the message which will be signed.
67
+        $userid = $user->id; // Retrieving the user's UserId
68
+        $message_data = "$userid $user_data"; // Create the message which will be signed.
69 69
 
70
-      $private_key_pem = openssl_pkey_get_private($privkey_contents); // Loading the private key into memory
71
-      openssl_sign($message_data, $signature, $private_key_pem, OPENSSL_ALGO_SHA512); // Compute signature using SHA512
72
-      openssl_free_key($private_key_pem); // Free the private key from memory for additional security
70
+        $private_key_pem = openssl_pkey_get_private($privkey_contents); // Loading the private key into memory
71
+        openssl_sign($message_data, $signature, $private_key_pem, OPENSSL_ALGO_SHA512); // Compute signature using SHA512
72
+        openssl_free_key($private_key_pem); // Free the private key from memory for additional security
73 73
 
74
-      $pubkey = fopen($account_ownership_public_key_file_path, "r"); // Open public key file
75
-      if ((!isset($pubkey)) || empty($pubkey)) {
74
+        $pubkey = fopen($account_ownership_public_key_file_path, "r"); // Open public key file
75
+        if ((!isset($pubkey)) || empty($pubkey)) {
76 76
         error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
77
-      }
78
-      $pubkey_contents = fread($pubkey, 8192); // Read contents to var
79
-      fclose($pubkey); // Close pub key file
80
-
81
-      $base64_sig = base64_encode($signature); // Base64 encode the generated signature to enable safe output to text file.
82
-      $decoded_sig = base64_decode($base64_sig); // Decode base64 sig for use in sig_verification
83
-      $pubkeyid = openssl_pkey_get_public($pubkey_contents); // fetch public key into memory
84
-      $sig_verification = openssl_verify($message_data, $decoded_sig, $pubkeyid, OPENSSL_ALGO_SHA512); // Verify that the generated signature against the original data, using the public key.
85
-      openssl_free_key($pubkeyid); // Free the public key from memory
86
-
87
-      // Check if signature was successfully validated
88
-      if ($sig_verification == 1) {
89
-          $url_tokens = url_tokens($user->authenticator);
90
-          // The generated signature has been successfully verified using the public key.
91
-          global $master_url; // Define global master_url variable for use in output
92
-          echo "<p>Do not share this information with anyone other than the external system which has requested this proof of account ownership.</p>";
93
-          echo "<textarea rows='13' cols='50' id='result_textbox'><account_ownership_verification>\n<master_url>$master_url</master_url>\n<msg>$message_data</msg>\n<signature>$base64_sig</signature>\n</account_ownership_verification></textarea>";
94
-          echo "<br/><br/><button class='btn btn-success' onclick='copy_result_textbox()'>Copy text</button>";
95
-          echo "<a href='account_ownership.php?$url_tokens'><button class='btn btn-default'>Go back</button></a>";
96
-          echo '<script type="text/javascript">';
97
-          echo 'function copy_result_textbox() {
77
+        }
78
+        $pubkey_contents = fread($pubkey, 8192); // Read contents to var
79
+        fclose($pubkey); // Close pub key file
80
+
81
+        $base64_sig = base64_encode($signature); // Base64 encode the generated signature to enable safe output to text file.
82
+        $decoded_sig = base64_decode($base64_sig); // Decode base64 sig for use in sig_verification
83
+        $pubkeyid = openssl_pkey_get_public($pubkey_contents); // fetch public key into memory
84
+        $sig_verification = openssl_verify($message_data, $decoded_sig, $pubkeyid, OPENSSL_ALGO_SHA512); // Verify that the generated signature against the original data, using the public key.
85
+        openssl_free_key($pubkeyid); // Free the public key from memory
86
+
87
+        // Check if signature was successfully validated
88
+        if ($sig_verification == 1) {
89
+            $url_tokens = url_tokens($user->authenticator);
90
+            // The generated signature has been successfully verified using the public key.
91
+            global $master_url; // Define global master_url variable for use in output
92
+            echo "<p>Do not share this information with anyone other than the external system which has requested this proof of account ownership.</p>";
93
+            echo "<textarea rows='13' cols='50' id='result_textbox'><account_ownership_verification>\n<master_url>$master_url</master_url>\n<msg>$message_data</msg>\n<signature>$base64_sig</signature>\n</account_ownership_verification></textarea>";
94
+            echo "<br/><br/><button class='btn btn-success' onclick='copy_result_textbox()'>Copy text</button>";
95
+            echo "<a href='account_ownership.php?$url_tokens'><button class='btn btn-default'>Go back</button></a>";
96
+            echo '<script type="text/javascript">';
97
+            echo 'function copy_result_textbox() {
98 98
                 var target_textbox = document.getElementById("result_textbox");
99 99
                 target_textbox.select();
100 100
                 document.execCommand("copy");
101 101
                 alert("Copied to clipboard");
102 102
               }';
103
-          echo '</script>';
104
-          page_tail();
105
-
106
-      } elseif ($sig_verification == 0) {
107
-          // The generated signature has not been verified. The private/public keys do not match.
108
-          error_page(tra("Signature verification failed. Contact the project administrator to resolve the issue."));
109
-      } else {
110
-          // Something has gone wrong & an error has occurred.
111
-          error_page(tra("An error occurred during the signature verification. Contact the project administrator to resolve the issue."));
112
-      }
113
-  } else {
114
-      // User data input invalid
115
-      error_page(tra("Invalid input. User input must have a length > 0 and < 4096. <form><input type='button' value='Go back!'' onclick='history.back()'></form>"));
116
-  }
103
+            echo '</script>';
104
+            page_tail();
105
+
106
+        } elseif ($sig_verification == 0) {
107
+            // The generated signature has not been verified. The private/public keys do not match.
108
+            error_page(tra("Signature verification failed. Contact the project administrator to resolve the issue."));
109
+        } else {
110
+            // Something has gone wrong & an error has occurred.
111
+            error_page(tra("An error occurred during the signature verification. Contact the project administrator to resolve the issue."));
112
+        }
113
+    } else {
114
+        // User data input invalid
115
+        error_page(tra("Invalid input. User input must have a length > 0 and < 4096. <form><input type='button' value='Go back!'' onclick='history.back()'></form>"));
116
+    }
117 117
 }
118 118
 
119 119
 function account_ownership_form($user) {
120
-  // GET request - the user has navigated to the page.
121
-  page_head(tra("Generate proof of account ownership"), null, null, null, boinc_recaptcha_get_head_extra());
122
-
123
-  if ($user) { // Verify the user is logged in
124
-      require_once("../inc/account_ownership.inc");
125
-
126
-      if (!file_exists($account_ownership_private_key_file_path)) {
127
-          // Check that the private key file exists where specified. If not, redirect to error page.
128
-          error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
129
-      }
130
-
131
-      if (!file_exists($account_ownership_public_key_file_path)) {
132
-          // Check that the public key file exists where specified. If not, redirect to error page.
133
-          error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
134
-      }
135
-
136
-      echo "<p>This tool is designed to create a proof of account ownership for external systems.</p>";
137
-
138
-      global $recaptcha_public_key;
139
-      if ($recaptcha_public_key) {
140
-          // Recaptcha configured
141
-          echo "<p>Enter a message with length less than 4096 characters into the input textbox below, solve the captcha then click the 'Generate' button.</p>";
142
-      } else {
143
-          // Recaptcha not configured
144
-          echo "<p>Enter a message with length less than 4096 characters into the input textbox below then click the 'Generate' button.</p>";
145
-      }
146
-      echo "<p>A textbox will then appear which contains your proof of account ownership.";
147
-      echo "<form method=post action=account_ownership.php>";
148
-
149
-      echo form_tokens($user->authenticator);
150
-      echo "<textarea rows='4' cols='50' name=user_data type=text size=20 placeholder='Enter text'></textarea><br/><br/>";
151
-
152
-      if ($recaptcha_public_key) {
153
-          // Trigger recaptcha!
154
-          form_general("", boinc_recaptcha_get_html($recaptcha_public_key));
155
-      }
156
-
157
-      echo "<input class=\"btn btn-success\" type=submit value='".tra("Generate")."'>";
158
-      echo "</form><br/><hr/>";
159
-  } else {
160
-      // The user is not logged in!
161
-      echo "<p>You need to be logged in to use this functionality.</p>";
162
-  }
163
-
164
-  page_tail();
120
+    // GET request - the user has navigated to the page.
121
+    page_head(tra("Generate proof of account ownership"), null, null, null, boinc_recaptcha_get_head_extra());
122
+
123
+    if ($user) { // Verify the user is logged in
124
+        require_once("../inc/account_ownership.inc");
125
+
126
+        if (!file_exists($account_ownership_private_key_file_path)) {
127
+            // Check that the private key file exists where specified. If not, redirect to error page.
128
+            error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
129
+        }
130
+
131
+        if (!file_exists($account_ownership_public_key_file_path)) {
132
+            // Check that the public key file exists where specified. If not, redirect to error page.
133
+            error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
134
+        }
135
+
136
+        echo "<p>This tool is designed to create a proof of account ownership for external systems.</p>";
137
+
138
+        global $recaptcha_public_key;
139
+        if ($recaptcha_public_key) {
140
+            // Recaptcha configured
141
+            echo "<p>Enter a message with length less than 4096 characters into the input textbox below, solve the captcha then click the 'Generate' button.</p>";
142
+        } else {
143
+            // Recaptcha not configured
144
+            echo "<p>Enter a message with length less than 4096 characters into the input textbox below then click the 'Generate' button.</p>";
145
+        }
146
+        echo "<p>A textbox will then appear which contains your proof of account ownership.";
147
+        echo "<form method=post action=account_ownership.php>";
148
+
149
+        echo form_tokens($user->authenticator);
150
+        echo "<textarea rows='4' cols='50' name=user_data type=text size=20 placeholder='Enter text'></textarea><br/><br/>";
151
+
152
+        if ($recaptcha_public_key) {
153
+            // Trigger recaptcha!
154
+            form_general("", boinc_recaptcha_get_html($recaptcha_public_key));
155
+        }
156
+
157
+        echo "<input class=\"btn btn-success\" type=submit value='".tra("Generate")."'>";
158
+        echo "</form><br/><hr/>";
159
+    } else {
160
+        // The user is not logged in!
161
+        echo "<p>You need to be logged in to use this functionality.</p>";
162
+    }
163
+
164
+    page_tail();
165 165
 }
166 166
 
167 167
 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Please login to merge, or discard this patch.