OSDN Git Service

Cleanup: Rename $key => $phrase, $phrase => $nophrase. Correct order of feature
[pukiwiki/pukiwiki.git] / plugin / md5.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: md5.inc.php,v 1.20 2005/06/04 02:15:28 henoheno Exp $
4 //
5 //  MD5 plugin
6
7 // User interface of pkwk_hash_compute() for system admin
8 function plugin_md5_action()
9 {
10         global $get, $post;
11
12         if (PKWK_SAFE_MODE || PKWK_READONLY) die_message('Prohibited');
13
14         // Wait POST
15         $phrase = isset($post['phrase']) ? $post['phrase'] : '';
16
17         if ($phrase == '') {
18                 // Show the form
19
20                 // If plugin=md5&md5=password, only set it (Don't compute)
21                 $value  = isset($get['md5']) ? $get['md5'] : '';
22
23                 return array(
24                         'msg' =>'Compute userPassword',
25                         'body'=>plugin_md5_show_form(isset($post['phrase']), $value));
26
27         } else {
28                 // Compute (Don't show its $phrase at the same time)
29
30                 $prefix = isset($post['prefix']);
31                 $salt   = isset($post['salt']) ? $post['salt'] : '';
32
33                 // With scheme-prefix or not
34                 if (! preg_match('/^\{.+\}.*$/', $salt)) {
35                         $scheme = isset($post['scheme']) ? '{' . $post['scheme'] . '}': '';
36                         $salt   = $scheme . $salt;
37                 }
38
39                 return array(
40                         'msg' =>'Result',
41                         'body'=>
42                                 //($prefix ? 'userPassword: ' : '') .
43                                 pkwk_hash_compute($salt, $phrase, $prefix, TRUE));
44         }
45 }
46
47 // $nophrase = Passphrase is (submitted but) empty
48 // $value    = Default passphrase value
49 function plugin_md5_show_form($nophrase = FALSE, $value = '')
50 {
51         if (PKWK_SAFE_MODE || PKWK_READONLY) die_message('Prohibited');
52         if (strlen($value) > PKWK_PASSPHRASE_LIMIT_LENGTH)
53                 die_message('Limit: malicious message length');
54
55         if ($value != '') $value = 'value="' . htmlspecialchars($value) . '" ';
56         $self = get_script_uri();
57
58         $form = <<<EOD
59 <p><strong>NOTICE: Don't use this feature via untrustful or unsure network</strong></p>
60 <hr>
61 EOD;
62
63         if ($nophrase) $form .= '<strong>NO PHRASE</strong><br />';
64
65         $form .= <<<EOD
66 <form action="$self" method="post">
67  <div>
68   <input type="hidden" name="plugin" value="md5" />
69   <label for="_p_md5_phrase">Phrase:</label>
70   <input type="text" name="phrase"  id="_p_md5_phrase" size="60" $value/><br />
71
72   <input type="radio" name="scheme" id="_p_md5_sha1" value="x-php-sha1" />
73   <label for="_p_md5_sha1">PHP sha1()</label><br />
74   <input type="radio" name="scheme" id="_p_md5_md5"  value="x-php-md5" checked="checked" />
75   <label for="_p_md5_md5">PHP md5()</label><br />
76   <input type="radio" name="scheme" id="_p_md5_crpt" value="x-php-crypt" />
77   <label for="_p_md5_crpt">PHP crypt() *</label><br />
78
79   <input type="radio" name="scheme" id="_p_md5_lssha" value="SSHA" />
80   <label for="_p_md5_lssha">LDAP SSHA (sha-1 with a seed) *</label><br />
81   <input type="radio" name="scheme" id="_p_md5_lsha" value="SHA" />
82   <label for="_p_md5_lsha">LDAP SHA (sha-1)</label><br />
83
84   <input type="radio" name="scheme" id="_p_md5_lsmd5" value="SMD5" />
85   <label for="_p_md5_lsmd5">LDAP SMD5 (md5 with a seed) *</label><br />
86   <input type="radio" name="scheme" id="_p_md5_lmd5" value="MD5" />
87   <label for="_p_md5_lmd5">LDAP MD5</label><br />
88
89   <input type="radio" name="scheme" id="_p_md5_lcrpt" value="CRYPT" />
90   <label for="_p_md5_lcrpt">LDAP CRYPT *</label><br />
91
92   <input type="checkbox" name="prefix" id="_p_md5_prefix" checked="checked" />
93   <label for="_p_md5_prefix">Add scheme prefix (RFC2307, Using LDAP as NIS)</label><br />
94
95   <label for="_p_md5_salt">Salt, '{scheme}', '{scheme}salt', or userPassword itself to specify:</label><br />
96   <input type="text" name="salt" id="_p_md5_salt" size="60" /><br />
97
98   <input type="submit" value="Compute" /><br />
99
100   <hr>
101   <p>* = Salt enabled<p/>
102  </div>
103 </form>
104 EOD;
105
106         return $form;
107 }
108 ?>