OSDN Git Service

BugTrack2/62: Do remove the whole design, 'Showing TrackBack-ping list by html'.
[pukiwiki/pukiwiki.git] / plugin / md5.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: md5.inc.php,v 1.22 2005/06/12 10:13:43 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($phrase, $salt, $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         $sha1_enabled = function_exists('sha1');
57         $self = get_script_uri();
58
59         $form = <<<EOD
60 <p><strong>NOTICE: Don't use this feature via untrustful or unsure network</strong></p>
61 <hr>
62 EOD;
63
64         if ($nophrase) $form .= '<strong>NO PHRASE</strong><br />';
65
66         $form .= <<<EOD
67 <form action="$self" method="post">
68  <div>
69   <input type="hidden" name="plugin" value="md5" />
70   <label for="_p_md5_phrase">Phrase:</label>
71   <input type="text" name="phrase"  id="_p_md5_phrase" size="60" $value/><br />
72 EOD;
73
74         if ($sha1_enabled) $form .= <<<EOD
75   <input type="radio" name="scheme" id="_p_md5_sha1" value="x-php-sha1" />
76   <label for="_p_md5_sha1">PHP sha1()</label><br />
77 EOD;
78
79         $form .= <<<EOD
80   <input type="radio" name="scheme" id="_p_md5_md5"  value="x-php-md5" checked="checked" />
81   <label for="_p_md5_md5">PHP md5()</label><br />
82   <input type="radio" name="scheme" id="_p_md5_crpt" value="x-php-crypt" />
83   <label for="_p_md5_crpt">PHP crypt() *</label><br />
84 EOD;
85
86         if ($sha1_enabled) $form .= <<<EOD
87   <input type="radio" name="scheme" id="_p_md5_lssha" value="SSHA" />
88   <label for="_p_md5_lssha">LDAP SSHA (sha-1 with a seed) *</label><br />
89   <input type="radio" name="scheme" id="_p_md5_lsha" value="SHA" />
90   <label for="_p_md5_lsha">LDAP SHA (sha-1)</label><br />
91 EOD;
92
93         $form .= <<<EOD
94   <input type="radio" name="scheme" id="_p_md5_lsmd5" value="SMD5" />
95   <label for="_p_md5_lsmd5">LDAP SMD5 (md5 with a seed) *</label><br />
96   <input type="radio" name="scheme" id="_p_md5_lmd5" value="MD5" />
97   <label for="_p_md5_lmd5">LDAP MD5</label><br />
98
99   <input type="radio" name="scheme" id="_p_md5_lcrpt" value="CRYPT" />
100   <label for="_p_md5_lcrpt">LDAP CRYPT *</label><br />
101
102   <input type="checkbox" name="prefix" id="_p_md5_prefix" checked="checked" />
103   <label for="_p_md5_prefix">Add scheme prefix (RFC2307, Using LDAP as NIS)</label><br />
104
105   <label for="_p_md5_salt">Salt, '{scheme}', '{scheme}salt', or userPassword itself to specify:</label><br />
106   <input type="text" name="salt" id="_p_md5_salt" size="60" /><br />
107
108   <input type="submit" value="Compute" /><br />
109
110   <hr>
111   <p>* = Salt enabled<p/>
112  </div>
113 </form>
114 EOD;
115
116         return $form;
117 }
118 ?>