<!DOCTYPE html>
<html lang='en'>
<head>
<title>ikiwiki-upstream - Unnamed repository; edit this file to name it for gitweb.</title>
<meta name='generator' content='cgit v1.2.3'/>
<meta name='robots' content='index, nofollow'/>
<link rel='stylesheet' type='text/css' href='/cgit-css/cgit.css'/>
<link rel='stylesheet' type='text/css' href='/cgit-local/local.css'/>
<script type='text/javascript' src='/cgit.js'></script>
<link rel='shortcut icon' href='/favicon.ico'/>
<link rel='alternate' title='Atom feed' href='https://source.jones.dk/ikiwiki-upstream/atom/IkiWiki/Setup?h=master' type='application/atom+xml'/>
<link rel='vcs-git' href='https://source.jones.dk/ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
<link rel='vcs-git' href='user@source.jones.dk:ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
</head>
<body>
<div id='cgit'><table id='header'>
<tr>
<td class='logo' rowspan='2'><a href='/'><img src='/cgit-css/cgit.png' alt='cgit logo'/></a></td>
<td class='main'><a href='/'>index</a> : <a href='/ikiwiki-upstream/'>ikiwiki-upstream</a></td><td class='form'><form method='get'>
<input type='hidden' name='id' value='039f075d61fa9554b6ec81f6aff740e889460f96'/><select name='h' onchange='this.form.submit();'>
<option value='layoutgala'>layoutgala</option>
<option value='master' selected='selected'>master</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Unnamed repository; edit this file to name it for gitweb.</td><td class='sub right'>Jonas Smedegaard</td></tr></table>
<table class='tabs'><tr><td>
<a href='/ikiwiki-upstream/'>summary</a><a href='/ikiwiki-upstream/refs/?id=039f075d61fa9554b6ec81f6aff740e889460f96'>refs</a><a href='/ikiwiki-upstream/log/IkiWiki/Setup'>log</a><a href='/ikiwiki-upstream/tree/IkiWiki/Setup?id=039f075d61fa9554b6ec81f6aff740e889460f96'>tree</a><a href='/ikiwiki-upstream/commit/IkiWiki/Setup?id=039f075d61fa9554b6ec81f6aff740e889460f96'>commit</a><a class='active' href='/ikiwiki-upstream/diff/IkiWiki/Setup?id=039f075d61fa9554b6ec81f6aff740e889460f96'>diff</a></td><td class='form'><form class='right' method='get' action='/ikiwiki-upstream/log/IkiWiki/Setup'>
<input type='hidden' name='id' value='039f075d61fa9554b6ec81f6aff740e889460f96'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/ikiwiki-upstream/diff/?id=039f075d61fa9554b6ec81f6aff740e889460f96'>root</a>/<a href='/ikiwiki-upstream/diff/IkiWiki?id=039f075d61fa9554b6ec81f6aff740e889460f96'>IkiWiki</a>/<a href='/ikiwiki-upstream/diff/IkiWiki/Setup?id=039f075d61fa9554b6ec81f6aff740e889460f96'>Setup</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='039f075d61fa9554b6ec81f6aff740e889460f96'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><div class='diffstat-header'><a href='/ikiwiki-upstream/diff/?id=039f075d61fa9554b6ec81f6aff740e889460f96'>Diffstat</a> (limited to 'IkiWiki/Setup')</div><table summary='diffstat' class='diffstat'></table><div class='diffstat-summary'>0 files changed, 0 insertions, 0 deletions</div><table summary='diff' class='diff'><tr><td></td></tr></table></div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.46.0</a>) at 2025-06-24 04:55:33 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
</span><span class="hl opt">(-</span>charset <span class="hl opt">=&gt; </span><span class="hl sng">&#39;utf-8&#39;</span><span class="hl opt">,</span></li>
<li id="n_17" class="hl">            <span class="hl opt">-</span>cookie <span class="hl opt">=&gt; </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">cookie</span><span class="hl opt">(-</span>httponly <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">, -</span>secure <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">));</span></li>
<li id="n_18" class="hl">    <span class="hl opt">} </span><span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_19" class="hl">        <span class="hl kwc">print </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">header</span><span class="hl opt">(-</span>charset <span class="hl opt">=&gt; </span><span class="hl sng">&#39;utf-8&#39;</span><span class="hl opt">,</span></li>
<li id="n_20" class="hl">            <span class="hl opt">-</span>cookie <span class="hl opt">=&gt; </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">cookie</span><span class="hl opt">(-</span>httponly <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">));</span></li>
<li id="n_21" class="hl">    <span class="hl opt">}</span></li>
<li id="n_22" class="hl"><span class="hl opt">}</span></li>
<li id="n_23" class="hl"></li>
<li id="n_24" class="hl"><span class="hl kwa">sub </span>showform <span class="hl opt">(</span><span class="hl kwb">$$$$</span><span class="hl opt">;&#64;) {</span></li>
<li id="n_25" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$form</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_26" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$buttons</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_27" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_28" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$cgi</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_29" class="hl"></li>
<li id="n_30" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">exists </span><span class="hl kwb">$hooks</span><span class="hl opt">{</span>formbuilder<span class="hl opt">}) {</span></li>
<li id="n_31" class="hl">        run_hooks<span class="hl opt">(</span>formbuilder <span class="hl opt">=&gt; </span><span class="hl kwa">sub </span><span class="hl opt">{</span></li>
<li id="n_32" class="hl">            shift-<span class="hl opt">&gt;(</span>form <span class="hl opt">=&gt; </span><span class="hl kwb">$form</span><span class="hl opt">, </span>cgi <span class="hl opt">=&gt; </span><span class="hl kwb">$cgi</span><span class="hl opt">, </span>session <span class="hl opt">=&gt; </span><span class="hl kwb">$session</span><span class="hl opt">,</span></li>
<li id="n_33" class="hl">                buttons <span class="hl opt">=&gt; </span><span class="hl kwb">$buttons</span><span class="hl opt">);</span></li>
<li id="n_34" class="hl">        <span class="hl opt">});</span></li>
<li id="n_35" class="hl">    <span class="hl opt">}</span></li>
<li id="n_36" class="hl"></li>
<li id="n_37" class="hl">    printheader<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_38" class="hl">    <span class="hl kwc">print </span>misctemplate<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">title</span><span class="hl opt">, </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">render</span><span class="hl opt">(</span>submit <span class="hl opt">=&gt; </span><span class="hl kwb">$buttons</span><span class="hl opt">), </span><span class="hl kwb">&#64;_</span><span class="hl opt">);</span></li>
<li id="n_39" class="hl"><span class="hl opt">}</span></li>
<li id="n_40" class="hl"></li>
<li id="n_41" class="hl"><span class="hl kwa">sub </span>redirect <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_42" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_43" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$url</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_44" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$config</span><span class="hl opt">{</span>w3mmode<span class="hl opt">}) {</span></li>
<li id="n_45" class="hl">        <span class="hl kwc">print </span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">redirect</span><span class="hl opt">(</span><span class="hl kwb">$url</span><span class="hl opt">);</span></li>
<li id="n_46" class="hl">    <span class="hl opt">}</span></li>
<li id="n_47" class="hl">    <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_48" class="hl">        <span class="hl kwc">print </span><span class="hl sng">&quot;Content-type: text/plain</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_49" class="hl">        <span class="hl kwc">print </span><span class="hl sng">&quot;W3m-control: GOTO </span><span class="hl ipl">$url</span><span class="hl sng"></span><span class="hl esc">\n\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_50" class="hl">    <span class="hl opt">}</span></li>
<li id="n_51" class="hl"><span class="hl opt">}</span></li>
<li id="n_52" class="hl"></li>
<li id="n_53" class="hl"><span class="hl kwa">sub </span>decode_cgi_utf8 <span class="hl opt">($) {</span></li>
<li id="n_54" class="hl">    <span class="hl slc"># decode_form_utf8 method is needed for 5.10</span></li>
<li id="n_55" class="hl">    <span class="hl kwa">if </span><span class="hl opt">($] &lt; </span><span class="hl num">5.01</span><span class="hl opt">) {</span></li>
<li id="n_56" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$cgi </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_57" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$f </span><span class="hl opt">(</span><span class="hl kwb">$cgi</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">) {</span></li>
<li id="n_58" class="hl">            <span class="hl kwb">$cgi</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl kwb">$f</span><span class="hl opt">, </span><span class="hl kwc">map </span><span class="hl opt">{ </span>decode_utf8 <span class="hl kwb">$_ </span><span class="hl opt">} </span><span class="hl kwb">$cgi</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl kwb">$f</span><span class="hl opt">));</span></li>
<li id="n_59" class="hl">        <span class="hl opt">}</span></li>
<li id="n_60" class="hl">    <span class="hl opt">}</span></li>
<li id="n_61" class="hl"><span class="hl opt">}</span></li>
<li id="n_62" class="hl"></li>
<li id="n_63" class="hl"><span class="hl kwa">sub </span>decode_form_utf8 <span class="hl opt">($) {</span></li>
<li id="n_64" class="hl">    <span class="hl kwa">if </span><span class="hl opt">($] &gt;= </span><span class="hl num">5.01</span><span class="hl opt">) {</span></li>
<li id="n_65" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$form </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_66" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$f </span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">) {</span></li>
<li id="n_67" class="hl">            <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name  <span class="hl opt">=&gt; </span><span class="hl kwb">$f</span><span class="hl opt">,</span></li>
<li id="n_68" class="hl">                         value <span class="hl opt">=&gt; </span>decode_utf8<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl kwb">$f</span><span class="hl opt">)),</span></li>
<li id="n_69" class="hl">                             force <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">,</span></li>
<li id="n_70" class="hl">            <span class="hl opt">);</span></li>
<li id="n_71" class="hl">        <span class="hl opt">}</span></li>
<li id="n_72" class="hl">    <span class="hl opt">}</span></li>
<li id="n_73" class="hl"><span class="hl opt">}</span></li>
<li id="n_74" class="hl"></li>
<li id="n_75" class="hl"><span class="hl slc"># Check if the user is signed in. If not, redirect to the signin form and</span></li>
<li id="n_76" class="hl"><span class="hl slc"># save their place to return to later.</span></li>
<li id="n_77" class="hl"><span class="hl kwa">sub </span>needsignin <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_78" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_79" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_80" class="hl"></li>
<li id="n_81" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">) ||</span></li>
<li id="n_82" class="hl">        <span class="hl opt">! </span>userinfo_get<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">), </span><span class="hl sng">&quot;regdate&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_83" class="hl">        <span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span>postsignin <span class="hl opt">=&gt; </span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>QUERY_STRING<span class="hl opt">});</span></li>
<li id="n_84" class="hl">        cgi_signin<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_85" class="hl">        cgi_savesession<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_86" class="hl">        <span class="hl kwa">exit</span><span class="hl opt">;</span></li>
<li id="n_87" class="hl">    <span class="hl opt">}</span></li>
<li id="n_88" class="hl"><span class="hl opt">}</span></li>
<li id="n_89" class="hl"></li>
<li id="n_90" class="hl"><span class="hl kwa">sub </span>cgi_signin <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_91" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_92" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_93" class="hl"></li>
<li id="n_94" class="hl">    decode_cgi_utf8<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">);</span></li>
<li id="n_95" class="hl">    <span class="hl kwc">eval </span><span class="hl sng">q{use CGI::FormBuilder}</span><span class="hl opt">;</span></li>
<li id="n_96" class="hl">    error<span class="hl opt">(</span><span class="hl kwb">$&#64;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$&#64;</span><span class="hl opt">;</span></li>
<li id="n_97" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$form </span><span class="hl opt">= </span>CGI<span class="hl opt">::</span>FormBuilder-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">(</span></li>
<li id="n_98" class="hl">        title <span class="hl opt">=&gt; </span><span class="hl sng">&quot;signin&quot;</span><span class="hl opt">,</span></li>
<li id="n_99" class="hl">        name <span class="hl opt">=&gt; </span><span class="hl sng">&quot;signin&quot;</span><span class="hl opt">,</span></li>
<li id="n_100" class="hl">        charset <span class="hl opt">=&gt; </span><span class="hl sng">&quot;utf-8&quot;</span><span class="hl opt">,</span></li>
<li id="n_101" class="hl">        <span class="hl kwa">method </span><span class="hl opt">=&gt; </span><span class="hl sng">&#39;POST&#39;</span><span class="hl opt">,</span></li>
<li id="n_102" class="hl">        required <span class="hl opt">=&gt; </span><span class="hl sng">&#39;NONE&#39;</span><span class="hl opt">,</span></li>
<li id="n_103" class="hl">        javascript <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">,</span></li>
<li id="n_104" class="hl">        params <span class="hl opt">=&gt; </span><span class="hl kwb">$q</span><span class="hl opt">,</span></li>
<li id="n_105" class="hl">        action <span class="hl opt">=&gt; </span><span class="hl kwb">$config</span><span class="hl opt">{</span>cgiurl<span class="hl opt">},</span></li>
<li id="n_106" class="hl">        header <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">,</span></li>
<li id="n_107" class="hl">        template <span class="hl opt">=&gt; {</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&#39;div&#39;</span><span class="hl opt">},</span></li>
<li id="n_108" class="hl">        stylesheet <span class="hl opt">=&gt; </span>baseurl<span class="hl opt">().</span><span class="hl sng">&quot;style.css&quot;</span><span class="hl opt">,</span></li>
<li id="n_109" class="hl">    <span class="hl opt">);</span></li>
<li id="n_110" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$buttons</span><span class="hl opt">=[</span><span class="hl sng">&quot;Login&quot;</span><span class="hl opt">];</span></li>
<li id="n_111" class="hl">    </li>
<li id="n_112" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">) </span><span class="hl kwc">ne </span><span class="hl sng">&quot;signin&quot;</span> <span class="hl opt">&amp;&amp; !</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted</span><span class="hl opt">) {</span></li>
<li id="n_113" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">text</span><span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;You need to log in first.&quot;</span><span class="hl opt">));</span></li>
<li id="n_114" class="hl">    <span class="hl opt">}</span></li>
<li id="n_115" class="hl">    <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name <span class="hl opt">=&gt; </span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">, </span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;hidden&quot;</span><span class="hl opt">, </span>value <span class="hl opt">=&gt; </span><span class="hl sng">&quot;signin&quot;</span><span class="hl opt">,</span></li>
<li id="n_116" class="hl">        force <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_117" class="hl">    </li>
<li id="n_118" class="hl">    decode_form_utf8<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">);</span></li>
<li id="n_119" class="hl">    run_hooks<span class="hl opt">(</span>formbuilder_setup <span class="hl opt">=&gt; </span><span class="hl kwa">sub </span><span class="hl opt">{</span></li>
<li id="n_120" class="hl">        shift-<span class="hl opt">&gt;(</span>form <span class="hl opt">=&gt; </span><span class="hl kwb">$form</span><span class="hl opt">, </span>cgi <span class="hl opt">=&gt; </span><span class="hl kwb">$q</span><span class="hl opt">, </span>session <span class="hl opt">=&gt; </span><span class="hl kwb">$session</span><span class="hl opt">,</span></li>
<li id="n_121" class="hl">                buttons <span class="hl opt">=&gt; </span><span class="hl kwb">$buttons</span><span class="hl opt">);</span></li>
<li id="n_122" class="hl">    <span class="hl opt">});</span></li>
<li id="n_123" class="hl">    decode_form_utf8<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">);</span></li>
<li id="n_124" class="hl"></li>
<li id="n_125" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted</span><span class="hl opt">) {</span></li>
<li id="n_126" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">validate</span><span class="hl opt">;</span></li>
<li id="n_127" class="hl">    <span class="hl opt">}</span></li>
<li id="n_128" class="hl"></li>
<li id="n_129" class="hl">    showform<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">, </span><span class="hl kwb">$buttons</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">, </span><span class="hl kwb">$q</span><span class="hl opt">);</span></li>
<li id="n_130" class="hl"><span class="hl opt">}</span></li>
<li id="n_131" class="hl"></li>
<li id="n_132" class="hl"><span class="hl kwa">sub </span>cgi_postsignin <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_133" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_134" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_135" class="hl">    </li>
<li id="n_136" class="hl">    <span class="hl slc"># Continue with whatever was being done before the signin process.</span></li>
<li id="n_137" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;postsignin&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_138" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$postsignin</span><span class="hl opt">=</span>CGI-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;postsignin&quot;</span><span class="hl opt">));</span></li>
<li id="n_139" class="hl">        <span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">clear</span><span class="hl opt">(</span><span class="hl sng">&quot;postsignin&quot;</span><span class="hl opt">);</span></li>
<li id="n_140" class="hl">        cgi<span class="hl opt">(</span><span class="hl kwb">$postsignin</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_141" class="hl">        cgi_savesession<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_142" class="hl">        <span class="hl kwa">exit</span><span class="hl opt">;</span></li>
<li id="n_143" class="hl">    <span class="hl opt">}</span></li>
<li id="n_144" class="hl">    <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_145" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$config</span><span class="hl opt">{</span>sslcookie<span class="hl opt">} &amp;&amp; ! </span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">https</span><span class="hl opt">()) {</span></li>
<li id="n_146" class="hl">            error<span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;probable misconfiguration: sslcookie is set, but you are attempting to login via http, not https&quot;</span><span class="hl opt">));</span></li>
<li id="n_147" class="hl">        <span class="hl opt">}</span></li>
<li id="n_148" class="hl">        <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_149" class="hl">            error<span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;login failed, perhaps you need to turn on cookies?&quot;</span><span class="hl opt">));</span></li>
<li id="n_150" class="hl">        <span class="hl opt">}</span></li>
<li id="n_151" class="hl">    <span class="hl opt">}</span></li>
<li id="n_152" class="hl"><span class="hl opt">}</span></li>
<li id="n_153" class="hl"></li>
<li id="n_154" class="hl"><span class="hl kwa">sub </span>cgi_prefs <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_155" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_156" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_157" class="hl"></li>
<li id="n_158" class="hl">    needsignin<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_159" class="hl">    decode_cgi_utf8<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">);</span></li>
<li id="n_160" class="hl">    </li>
<li id="n_161" class="hl">    <span class="hl slc"># The session id is stored on the form and checked to</span></li>
<li id="n_162" class="hl">    <span class="hl slc"># guard against CSRF.</span></li>
<li id="n_163" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$sid</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&#39;sid&#39;</span><span class="hl opt">);</span></li>
<li id="n_164" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$sid</span><span class="hl opt">) {</span></li>
<li id="n_165" class="hl">        <span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">delete_all</span><span class="hl opt">;</span></li>
<li id="n_166" class="hl">    <span class="hl opt">}</span></li>
<li id="n_167" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$sid </span><span class="hl kwc">ne </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">id</span><span class="hl opt">) {</span></li>
<li id="n_168" class="hl">        error<span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Your login session has expired.&quot;</span><span class="hl opt">));</span></li>
<li id="n_169" class="hl">    <span class="hl opt">}</span></li>
<li id="n_170" class="hl"></li>
<li id="n_171" class="hl">    <span class="hl kwc">eval </span><span class="hl sng">q{use CGI::FormBuilder}</span><span class="hl opt">;</span></li>
<li id="n_172" class="hl">    error<span class="hl opt">(</span><span class="hl kwb">$&#64;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$&#64;</span><span class="hl opt">;</span></li>
<li id="n_173" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$form </span><span class="hl opt">= </span>CGI<span class="hl opt">::</span>FormBuilder-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">(</span></li>
<li id="n_174" class="hl">        title <span class="hl opt">=&gt; </span><span class="hl sng">&quot;preferences&quot;</span><span class="hl opt">,</span></li>
<li id="n_175" class="hl">        name <span class="hl opt">=&gt; </span><span class="hl sng">&quot;preferences&quot;</span><span class="hl opt">,</span></li>
<li id="n_176" class="hl">        header <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">,</span></li>
<li id="n_177" class="hl">        charset <span class="hl opt">=&gt; </span><span class="hl sng">&quot;utf-8&quot;</span><span class="hl opt">,</span></li>
<li id="n_178" class="hl">        <span class="hl kwa">method </span><span class="hl opt">=&gt; </span><span class="hl sng">&#39;POST&#39;</span><span class="hl opt">,</span></li>
<li id="n_179" class="hl">        validate <span class="hl opt">=&gt; {</span></li>
<li id="n_180" class="hl">            email <span class="hl opt">=&gt; </span><span class="hl sng">&#39;EMAIL&#39;</span><span class="hl opt">,</span></li>
<li id="n_181" class="hl">        <span class="hl opt">},</span></li>
<li id="n_182" class="hl">        required <span class="hl opt">=&gt; </span><span class="hl sng">&#39;NONE&#39;</span><span class="hl opt">,</span></li>
<li id="n_183" class="hl">        javascript <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">,</span></li>
<li id="n_184" class="hl">        params <span class="hl opt">=&gt; </span><span class="hl kwb">$q</span><span class="hl opt">,</span></li>
<li id="n_185" class="hl">        action <span class="hl opt">=&gt; </span><span class="hl kwb">$config</span><span class="hl opt">{</span>cgiurl<span class="hl opt">},</span></li>
<li id="n_186" class="hl">        template <span class="hl opt">=&gt; {</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&#39;div&#39;</span><span class="hl opt">},</span></li>
<li id="n_187" class="hl">        stylesheet <span class="hl opt">=&gt; </span>baseurl<span class="hl opt">().</span><span class="hl sng">&quot;style.css&quot;</span><span class="hl opt">,</span></li>
<li id="n_188" class="hl">        fieldsets <span class="hl opt">=&gt; [</span></li>
<li id="n_189" class="hl">            <span class="hl opt">[</span>login <span class="hl opt">=&gt; </span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Login&quot;</span><span class="hl opt">)],</span></li>
<li id="n_190" class="hl">            <span class="hl opt">[</span>preferences <span class="hl opt">=&gt; </span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Preferences&quot;</span><span class="hl opt">)],</span></li>
<li id="n_191" class="hl">            <span class="hl opt">[</span>admin <span class="hl opt">=&gt; </span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Admin&quot;</span><span class="hl opt">)]</span></li>
<li id="n_192" class="hl">        <span class="hl opt">],</span></li>
<li id="n_193" class="hl">    <span class="hl opt">);</span></li>
<li id="n_194" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$buttons</span><span class="hl opt">=[</span><span class="hl sng">&quot;Save Preferences&quot;</span><span class="hl opt">, </span><span class="hl sng">&quot;Logout&quot;</span><span class="hl opt">, </span><span class="hl sng">&quot;Cancel&quot;</span><span class="hl opt">];</span></li>
<li id="n_195" class="hl">    </li>
<li id="n_196" class="hl">    decode_form_utf8<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">);</span></li>
<li id="n_197" class="hl">    run_hooks<span class="hl opt">(</span>formbuilder_setup <span class="hl opt">=&gt; </span><span class="hl kwa">sub </span><span class="hl opt">{</span></li>
<li id="n_198" class="hl">        shift-<span class="hl opt">&gt;(</span>form <span class="hl opt">=&gt; </span><span class="hl kwb">$form</span><span class="hl opt">, </span>cgi <span class="hl opt">=&gt; </span><span class="hl kwb">$q</span><span class="hl opt">, </span>session <span class="hl opt">=&gt; </span><span class="hl kwb">$session</span><span class="hl opt">,</span></li>
<li id="n_199" class="hl">                buttons <span class="hl opt">=&gt; </span><span class="hl kwb">$buttons</span><span class="hl opt">);</span></li>
<li id="n_200" class="hl">    <span class="hl opt">});</span></li>
<li id="n_201" class="hl">    decode_form_utf8<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">);</span></li>
<li id="n_202" class="hl">    </li>
<li id="n_203" class="hl">    <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name <span class="hl opt">=&gt; </span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">, </span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;hidden&quot;</span><span class="hl opt">, </span>value <span class="hl opt">=&gt; </span><span class="hl sng">&quot;prefs&quot;</span><span class="hl opt">,</span></li>
<li id="n_204" class="hl">        force <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_205" class="hl">    <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name <span class="hl opt">=&gt; </span><span class="hl sng">&quot;sid&quot;</span><span class="hl opt">, </span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;hidden&quot;</span><span class="hl opt">, </span>value <span class="hl opt">=&gt; </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">id</span><span class="hl opt">,</span></li>
<li id="n_206" class="hl">        force <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_207" class="hl">    <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name <span class="hl opt">=&gt; </span><span class="hl sng">&quot;email&quot;</span><span class="hl opt">, </span>size <span class="hl opt">=&gt; </span><span class="hl num">50</span><span class="hl opt">, </span>fieldset <span class="hl opt">=&gt; </span><span class="hl sng">&quot;preferences&quot;</span><span class="hl opt">);</span></li>
<li id="n_208" class="hl">    </li>
<li id="n_209" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$user_name</span><span class="hl opt">=</span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">);</span></li>
<li id="n_210" class="hl"></li>
<li id="n_211" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted</span><span class="hl opt">) {</span></li>
<li id="n_212" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name <span class="hl opt">=&gt; </span><span class="hl sng">&quot;email&quot;</span><span class="hl opt">, </span>force <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">,</span></li>
<li id="n_213" class="hl">            value <span class="hl opt">=&gt; </span>userinfo_get<span class="hl opt">(</span><span class="hl kwb">$user_name</span><span class="hl opt">, </span><span class="hl sng">&quot;email&quot;</span><span class="hl opt">));</span></li>
<li id="n_214" class="hl">    <span class="hl opt">}</span></li>
<li id="n_215" class="hl">    </li>
<li id="n_216" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted </span><span class="hl kwc">eq </span><span class="hl sng">&#39;Logout&#39;</span><span class="hl opt">) {</span></li>
<li id="n_217" class="hl">        <span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwc">delete</span><span class="hl opt">();</span></li>
<li id="n_218" class="hl">        redirect<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$config</span><span class="hl opt">{</span>url<span class="hl opt">});</span></li>
<li id="n_219" class="hl">        <span class="hl kwa">return</span><span class="hl opt">;</span></li>
<li id="n_220" class="hl">    <span class="hl opt">}</span></li>
<li id="n_221" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted </span><span class="hl kwc">eq </span><span class="hl sng">&#39;Cancel&#39;</span><span class="hl opt">) {</span></li>
<li id="n_222" class="hl">        redirect<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$config</span><span class="hl opt">{</span>url<span class="hl opt">});</span></li>
<li id="n_223" class="hl">        <span class="hl kwa">return</span><span class="hl opt">;</span></li>
<li id="n_224" class="hl">    <span class="hl opt">}</span></li>
<li id="n_225" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted </span><span class="hl kwc">eq </span><span class="hl sng">&#39;Save Preferences&#39;</span> <span class="hl opt">&amp;&amp; </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">validate</span><span class="hl opt">) {</span></li>
<li id="n_226" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&#39;email&#39;</span><span class="hl opt">)) {</span></li>
<li id="n_227" class="hl">            userinfo_set<span class="hl opt">(</span><span class="hl kwb">$user_name</span><span class="hl opt">, </span><span class="hl sng">&#39;email&#39;</span><span class="hl opt">, </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&#39;email&#39;</span><span class="hl opt">)) ||</span></li>
<li id="n_228" class="hl">                error<span class="hl opt">(</span><span class="hl sng">&quot;failed to set email&quot;</span><span class="hl opt">);</span></li>
<li id="n_229" class="hl">        <span class="hl opt">}</span></li>
<li id="n_230" class="hl"></li>
<li id="n_231" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">text</span><span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Preferences saved.&quot;</span><span class="hl opt">));</span></li>
<li id="n_232" class="hl">    <span class="hl opt">}</span></li>
<li id="n_233" class="hl">    </li>
<li id="n_234" class="hl">    showform<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">, </span><span class="hl kwb">$buttons</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">, </span><span class="hl kwb">$q</span><span class="hl opt">);</span></li>
<li id="n_235" class="hl"><span class="hl opt">}</span></li>
<li id="n_236" class="hl"></li>
<li id="n_237" class="hl"><span class="hl kwa">sub </span>cgi_custom_failure <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_238" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$header</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_239" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$message</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_240" class="hl"></li>
<li id="n_241" class="hl">    <span class="hl kwc">print </span><span class="hl kwb">$header</span><span class="hl opt">;</span></li>
<li id="n_242" class="hl">    <span class="hl kwc">print </span><span class="hl kwb">$message</span><span class="hl opt">;</span></li>
<li id="n_243" class="hl"></li>
<li id="n_244" class="hl">    <span class="hl slc"># Internet Explod^Hrer won&#39;t show custom 404 responses</span></li>
<li id="n_245" class="hl">    <span class="hl slc"># unless they&#39;re &gt;= 512 bytes</span></li>
<li id="n_246" class="hl">    <span class="hl kwc">print </span><span class="hl sng">&#39; &#39;</span> x <span class="hl num">512</span><span class="hl opt">;</span></li>
<li id="n_247" class="hl"></li>
<li id="n_248" class="hl">    <span class="hl kwa">exit</span><span class="hl opt">;</span></li>
<li id="n_249" class="hl"><span class="hl opt">}</span></li>
<li id="n_250" class="hl"></li>
<li id="n_251" class="hl"><span class="hl kwa">sub </span>check_banned <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_252" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_253" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_254" class="hl"></li>
<li id="n_255" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$name</span><span class="hl opt">=</span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">);</span></li>
<li id="n_256" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$name</span><span class="hl opt">) {</span></li>
<li id="n_257" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">grep </span><span class="hl opt">{ </span><span class="hl kwb">$name </span><span class="hl kwc">eq </span><span class="hl kwb">$_ </span><span class="hl opt">} &#64;{</span><span class="hl kwb">$config</span><span class="hl opt">{</span>banned_users<span class="hl opt">}}) {</span></li>
<li id="n_258" class="hl">            <span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwc">delete</span><span class="hl opt">();</span></li>
<li id="n_259" class="hl">            cgi_savesession<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_260" class="hl">            cgi_custom_failure<span class="hl opt">(</span></li>
<li id="n_261" class="hl">                <span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">header</span><span class="hl opt">(-</span>status <span class="hl opt">=&gt; </span><span class="hl sng">&quot;403 Forbidden&quot;</span><span class="hl opt">),</span></li>
<li id="n_262" class="hl">                gettext<span class="hl opt">(</span><span class="hl sng">&quot;You are banned.&quot;</span><span class="hl opt">));</span></li>
<li id="n_263" class="hl">        <span class="hl opt">}</span></li>
<li id="n_264" class="hl">    <span class="hl opt">}</span></li>
<li id="n_265" class="hl"><span class="hl opt">}</span></li>
<li id="n_266" class="hl"></li>
<li id="n_267" class="hl"><span class="hl kwa">sub </span>cgi_getsession <span class="hl opt">($) {</span></li>
<li id="n_268" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_269" class="hl"></li>
<li id="n_270" class="hl">    <span class="hl kwc">eval </span><span class="hl sng">q{use CGI::Session; use HTML::Entities}</span><span class="hl opt">;</span></li>
<li id="n_271" class="hl">    error<span class="hl opt">(</span><span class="hl kwb">$&#64;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$&#64;</span><span class="hl opt">;</span></li>
<li id="n_272" class="hl">    CGI<span class="hl opt">::</span>Session-<span class="hl opt">&gt;</span><span class="hl kwd">name</span><span class="hl opt">(</span><span class="hl sng">&quot;ikiwiki_session_&quot;</span><span class="hl opt">.</span>encode_entities<span class="hl opt">(</span><span class="hl kwb">$config</span><span class="hl opt">{</span>wikiname<span class="hl opt">}));</span></li>
<li id="n_273" class="hl">    </li>
<li id="n_274" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$oldmask</span><span class="hl opt">=</span><span class="hl kwc">umask</span><span class="hl opt">(</span><span class="hl num">077</span><span class="hl opt">);</span></li>
<li id="n_275" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session </span><span class="hl opt">= </span><span class="hl kwc">eval </span><span class="hl opt">{</span></li>
<li id="n_276" class="hl">        CGI<span class="hl opt">::</span>Session-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">(</span><span class="hl sng">&quot;driver:DB_File&quot;</span><span class="hl opt">, </span><span class="hl kwb">$q</span><span class="hl opt">,</span></li>
<li id="n_277" class="hl">            <span class="hl opt">{ </span>FileName <span class="hl opt">=&gt; </span><span class="hl sng">&quot;</span><span class="hl ipl">$config</span><span class="hl sng">{wikistatedir}/sessions.db&quot;</span> <span class="hl opt">})</span></li>
<li id="n_278" class="hl">    <span class="hl opt">};</span></li>
<li id="n_279" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$session </span><span class="hl opt">|| </span><span class="hl kwb">$&#64;</span><span class="hl opt">) {</span></li>
<li id="n_280" class="hl">        error<span class="hl opt">(</span><span class="hl kwb">$&#64;</span><span class="hl opt">.</span><span class="hl sng">&quot; &quot;</span><span class="hl opt">.</span>CGI<span class="hl opt">::</span>Session-<span class="hl opt">&gt;</span><span class="hl kwd">errstr</span><span class="hl opt">());</span></li>
<li id="n_281" class="hl">    <span class="hl opt">}</span></li>
<li id="n_282" class="hl">    </li>
<li id="n_283" class="hl">    <span class="hl kwc">umask</span><span class="hl opt">(</span><span class="hl kwb">$oldmask</span><span class="hl opt">);</span></li>
<li id="n_284" class="hl"></li>
<li id="n_285" class="hl">    <span class="hl kwa">return </span><span class="hl kwb">$session</span><span class="hl opt">;</span></li>
<li id="n_286" class="hl"><span class="hl opt">}</span></li>
<li id="n_287" class="hl"></li>
<li id="n_288" class="hl"><span class="hl slc"># To guard against CSRF, the user&#39;s session id (sid)</span></li>
<li id="n_289" class="hl"><span class="hl slc"># can be stored on a form. This function will check</span></li>
<li id="n_290" class="hl"><span class="hl slc"># (for logged in users) that the sid on the form matches</span></li>
<li id="n_291" class="hl"><span class="hl slc"># the session id in the cookie.</span></li>
<li id="n_292" class="hl"><span class="hl kwa">sub </span>checksessionexpiry <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_293" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_294" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_295" class="hl"></li>
<li id="n_296" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_297" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$sid</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&#39;sid&#39;</span><span class="hl opt">);</span></li>
<li id="n_298" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$sid </span><span class="hl opt">|| </span><span class="hl kwb">$sid </span><span class="hl kwc">ne </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">id</span><span class="hl opt">) {</span></li>
<li id="n_299" class="hl">            error<span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Your login session has expired.&quot;</span><span class="hl opt">));</span></li>
<li id="n_300" class="hl">        <span class="hl opt">}</span></li>
<li id="n_301" class="hl">    <span class="hl opt">}</span></li>
<li id="n_302" class="hl"><span class="hl opt">}</span></li>
<li id="n_303" class="hl"></li>
<li id="n_304" class="hl"><span class="hl kwa">sub </span>cgi_savesession <span class="hl opt">($) {</span></li>
<li id="n_305" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_306" class="hl"></li>
<li id="n_307" class="hl">    <span class="hl slc"># Force session flush with safe umask.</span></li>
<li id="n_308" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$oldmask</span><span class="hl opt">=</span><span class="hl kwc">umask</span><span class="hl opt">(</span><span class="hl num">077</span><span class="hl opt">);</span></li>
<li id="n_309" class="hl">    <span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">flush</span><span class="hl opt">;</span></li>
<li id="n_310" class="hl">    <span class="hl kwc">umask</span><span class="hl opt">(</span><span class="hl kwb">$oldmask</span><span class="hl opt">);</span></li>
<li id="n_311" class="hl"><span class="hl opt">}</span></li>
<li id="n_312" class="hl"></li>
<li id="n_313" class="hl"><span class="hl kwa">sub </span>cgi <span class="hl opt">(;</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_314" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_315" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_316" class="hl"></li>
<li id="n_317" class="hl">    <span class="hl kwc">eval </span><span class="hl sng">q{use CGI}</span><span class="hl opt">;</span></li>
<li id="n_318" class="hl">    error<span class="hl opt">(</span><span class="hl kwb">$&#64;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$&#64;</span><span class="hl opt">;</span></li>
<li id="n_319" class="hl">    <span class="hl kwb">$CGI</span><span class="hl opt">::</span>DISABLE_UPLOADS<span class="hl opt">=</span><span class="hl kwb">$config</span><span class="hl opt">{</span>cgi_disable_uploads<span class="hl opt">};</span></li>
<li id="n_320" class="hl"></li>
<li id="n_321" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$q</span><span class="hl opt">) {</span></li>
<li id="n_322" class="hl">        <span class="hl kwc">binmode</span><span class="hl opt">(</span>STDIN<span class="hl opt">);</span></li>
<li id="n_323" class="hl">        <span class="hl kwb">$q</span><span class="hl opt">=</span>CGI-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">;</span></li>
<li id="n_324" class="hl">        <span class="hl kwc">binmode</span><span class="hl opt">(</span>STDIN<span class="hl opt">, </span><span class="hl sng">&quot;:utf8&quot;</span><span class="hl opt">);</span></li>
<li id="n_325" class="hl">    </li>
<li id="n_326" class="hl">        run_hooks<span class="hl opt">(</span>cgi <span class="hl opt">=&gt; </span><span class="hl kwa">sub </span><span class="hl opt">{ </span>shift-<span class="hl opt">&gt;(</span><span class="hl kwb">$q</span><span class="hl opt">) });</span></li>
<li id="n_327" class="hl">    <span class="hl opt">}</span></li>
<li id="n_328" class="hl"></li>
<li id="n_329" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$do</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&#39;do&#39;</span><span class="hl opt">);</span></li>
<li id="n_330" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$do </span><span class="hl opt">|| ! </span><span class="hl kwc">length </span><span class="hl kwb">$do</span><span class="hl opt">) {</span></li>
<li id="n_331" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$error </span><span class="hl opt">= </span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">cgi_error</span><span class="hl opt">;</span></li>
<li id="n_332" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$error</span><span class="hl opt">) {</span></li>
<li id="n_333" class="hl">            error<span class="hl opt">(</span><span class="hl sng">&quot;Request not processed: </span><span class="hl ipl">$error</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_334" class="hl">        <span class="hl opt">}</span></li>
<li id="n_335" class="hl">        <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_336" class="hl">            error<span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl esc">\&quot;</span><span class="hl sng">do</span><span class="hl esc">\&quot; </span><span class="hl sng">parameter missing&quot;</span><span class="hl opt">);</span></li>
<li id="n_337" class="hl">        <span class="hl opt">}</span></li>
<li id="n_338" class="hl">    <span class="hl opt">}</span></li>
<li id="n_339" class="hl"></li>
<li id="n_340" class="hl">    <span class="hl slc"># Need to lock the wiki before getting a session.</span></li>
<li id="n_341" class="hl">    lockwiki<span class="hl opt">();</span></li>
<li id="n_342" class="hl">    loadindex<span class="hl opt">();</span></li>
<li id="n_343" class="hl">    </li>
<li id="n_344" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$session</span><span class="hl opt">) {</span></li>
<li id="n_345" class="hl">        <span class="hl kwb">$session</span><span class="hl opt">=</span>cgi_getsession<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">);</span></li>
<li id="n_346" class="hl">    <span class="hl opt">}</span></li>
<li id="n_347" class="hl">    </li>
<li id="n_348" class="hl">    <span class="hl slc"># Auth hooks can sign a user in.</span></li>
<li id="n_349" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$do </span><span class="hl kwc">ne </span><span class="hl sng">&#39;signin&#39;</span> <span class="hl opt">&amp;&amp; ! </span><span class="hl kwc">defined </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_350" class="hl">        run_hooks<span class="hl opt">(</span>auth <span class="hl opt">=&gt; </span><span class="hl kwa">sub </span><span class="hl opt">{</span></li>
<li id="n_351" class="hl">            shift-<span class="hl opt">&gt;(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">)</span></li>
<li id="n_352" class="hl">        <span class="hl opt">});</span></li>
<li id="n_353" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_354" class="hl">            <span class="hl slc"># Make sure whatever user was authed is in the</span></li>
<li id="n_355" class="hl">            <span class="hl slc"># userinfo db.</span></li>
<li id="n_356" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(! </span>userinfo_get<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">), </span><span class="hl sng">&quot;regdate&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_357" class="hl">                userinfo_setall<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">), {</span></li>
<li id="n_358" class="hl">                    email <span class="hl opt">=&gt; </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">,</span></li>
<li id="n_359" class="hl">                    password <span class="hl opt">=&gt; </span><span class="hl sng">&quot;&quot;</span><span class="hl opt">,</span></li>
<li id="n_360" class="hl">                    regdate <span class="hl opt">=&gt; </span><span class="hl kwc">time</span><span class="hl opt">,</span></li>
<li id="n_361" class="hl">                <span class="hl opt">}) || </span>error<span class="hl opt">(</span><span class="hl sng">&quot;failed adding user&quot;</span><span class="hl opt">);</span></li>
<li id="n_362" class="hl">            <span class="hl opt">}</span></li>
<li id="n_363" class="hl">        <span class="hl opt">}</span></li>
<li id="n_364" class="hl">    <span class="hl opt">}</span></li>
<li id="n_365" class="hl">    </li>
<li id="n_366" class="hl">    check_banned<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_367" class="hl">    </li>
<li id="n_368" class="hl">    run_hooks<span class="hl opt">(</span>sessioncgi <span class="hl opt">=&gt; </span><span class="hl kwa">sub </span><span class="hl opt">{ </span>shift-<span class="hl opt">&gt;(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">) });</span></li>
<li id="n_369" class="hl"></li>
<li id="n_370" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$do </span><span class="hl kwc">eq </span><span class="hl sng">&#39;signin&#39;</span><span class="hl opt">) {</span></li>
<li id="n_371" class="hl">        cgi_signin<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_372" class="hl">        cgi_savesession<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_373" class="hl">    <span class="hl opt">}</span></li>
<li id="n_374" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$do </span><span class="hl kwc">eq </span><span class="hl sng">&#39;prefs&#39;</span><span class="hl opt">) {</span></li>
<li id="n_375" class="hl">        cgi_prefs<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_376" class="hl">    <span class="hl opt">}</span></li>
<li id="n_377" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;postsignin&quot;</span><span class="hl opt">) || </span><span class="hl kwb">$do </span><span class="hl kwc">eq </span><span class="hl sng">&#39;postsignin&#39;</span><span class="hl opt">) {</span></li>
<li id="n_378" class="hl">        cgi_postsignin<span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">);</span></li>
<li id="n_379" class="hl">    <span class="hl opt">}</span></li>
<li id="n_380" class="hl">    <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_381" class="hl">        error<span class="hl opt">(</span><span class="hl sng">&quot;unknown do parameter&quot;</span><span class="hl opt">);</span></li>
<li id="n_382" class="hl">    <span class="hl opt">}</span></li>
<li id="n_383" class="hl"><span class="hl opt">}</span></li>
<li id="n_384" class="hl"></li>
<li id="n_385" class="hl"><span class="hl slc"># Does not need to be called directly; all errors will go through here.</span></li>
<li id="n_386" class="hl"><span class="hl kwa">sub </span>cgierror <span class="hl opt">($) {</span></li>
<li id="n_387" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$message</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_388" class="hl"></li>
<li id="n_389" class="hl">    <span class="hl kwc">print </span><span class="hl sng">&quot;Content-type: text/html</span><span class="hl esc">\n\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_390" class="hl">    <span class="hl kwc">print </span>misctemplate<span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Error&quot;</span><span class="hl opt">),</span></li>
<li id="n_391" class="hl">        <span class="hl sng">&quot;&lt;p class=</span><span class="hl esc">\&quot;</span><span class="hl sng">error</span><span class="hl esc">\&quot;</span><span class="hl sng">&gt;&quot;</span><span class="hl opt">.</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;Error&quot;</span><span class="hl opt">).</span><span class="hl sng">&quot;: </span><span class="hl ipl">$message</span><span class="hl sng">&lt;/p&gt;&quot;</span><span class="hl opt">);</span></li>
<li id="n_392" class="hl">    <span class="hl kwc">die </span><span class="hl kwb">$&#64;</span><span class="hl opt">;</span></li>
<li id="n_393" class="hl"><span class="hl opt">}</span></li>
<li id="n_394" class="hl"></li>
<li id="n_395" class="hl"><span class="hl num">1</span></li>
</ol></code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.46.0</a>) at 2025-06-24 04:55:33 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
