Advertisement
Guest User

mlogin

a guest
Oct 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.49 KB | None | 0 0
  1. CREATE OR REPLACE FUNCTION web.mlogin(
  2. character varying[],
  3. character varying[])
  4. RETURNS character varying AS
  5. $BODY$
  6. DECLARE name_array ALIAS FOR $1;
  7. DECLARE value_array ALIAS FOR $2;
  8. DECLARE id varchar;
  9. DECLARE ik varchar;
  10. DECLARE tegevus varchar;
  11. DECLARE new_sess varchar;
  12.  
  13. DECLARE tmp varchar;
  14. DECLARE tmp_arr varchar[];
  15. DECLARE a varchar;
  16.  
  17. declare pealkiri varchar;
  18. declare vorm1 varchar;
  19. declare vorm2 varchar;
  20. declare uuskatse varchar;
  21.  
  22. declare meeles varchar;
  23. declare startpage varchar;
  24.  
  25. --EDGAR. menu declaration
  26. declare vahe text;
  27. declare menu text := coalesce(get_session_variable('MENU'));
  28.  
  29. BEGIN
  30.  
  31. --a:=log(digidoc.m_id_auth_check(get_key('M-SESS')));
  32. --vahe:=name_array;
  33. --a:=log(vahe);
  34. --vahe:=value_array;
  35. --a:=log(vahe);
  36.  
  37.  
  38. if get_session_variable('DAD')='jvolis' then
  39. --startpage:='/';
  40. startpage:='/jvolis/!web.index?login';
  41. else
  42. startpage:=replace(info('start_page'),'::DAD::',get_session_variable('DAD'));
  43. end if;
  44.  
  45. if coalesce(get_session_variable('LOGINLEVEL')::int4, 10) >= 30 then
  46. return pwa.redirect(startpage);
  47. end if;
  48.  
  49. a:=set_session_variable('MENU', 'N');
  50.  
  51. tegevus:=COALESCE(arrayvalue(name_array, value_array, 'tegevus'), '');
  52. id:=to_null(arrayvalue(name_array, value_array, 'id'));
  53.  
  54. meeles:=pwa.cookie_get('MEELES');
  55.  
  56. --a:=log(meeles);
  57.  
  58. if length(id)<=9 and id ~ '^0?5' then -- Tõenäoliselt tegemist on eesti mobiiliga
  59. id:='+372'||ngltrim(id, '0');
  60. elsif not coalesce(asutused.is_isikukood(id), false) and id ~ '^3725\\d{6,8}$' then -- Tõenäoliselt tegemist on eesti mobiiliga
  61. id:='+'||id;
  62. end if;
  63.  
  64. pealkiri:='<p>Lisainfot mobiilse autentimise kohta leiab aadressilt <a class="menulink" href="http://mobiil.id.ee" target="_blank">mobiil.id.ee</a>.</p>';
  65. vorm1:='<form name="m_vorm" id="m_vorm" method="get" action=""><input type="hidden" name="tegevus" value="Alusta autentimist" />
  66. <p>Sisestage isikukood või mobiiltelefoni number kujul +3725xxxxx või 5xxxxx:<br /><br /> <input type="text" name="id"';
  67. vorm2:=' /><br /><br />
  68. <input type="checkbox" name="meeles" '||CASE WHEN meeles is not null then 'checked' else '' end||' />&nbsp;Pea andmed meeles (ühiskasutatava arvuti puhul pole soovitav!)
  69. <br /><br /><br />
  70. <input type="submit" name="submit" value="Alusta autentimist" /></p></form>';
  71.  
  72. uuskatse:='<p>Uue autentimiskatse tegemiseks vajutage lingile: <a class="menulink" href="/gvolis/avalik/m_login/">M-ID</a></p>';
  73.  
  74. if tegevus='Alusta autentimist' and not (coalesce(asutused.is_isikukood(id), false) or coalesce(id, '') in ('90101010092', '90101010072') or coalesce(id, '') ~ '^\\+\\d{6,}$') then
  75. a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
  76. a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
  77. a:=htp.p(pealkiri);
  78. a:=htp.p('<p class="alert">Vale isikukood või mobiiltelefoni number</p>');
  79. a:=htp.p(vorm1||' value="'||escape_html(coalesce(id,meeles,''))||'"'||vorm2);
  80. a:=set_key('M-KOOD_MOBIIL', '');
  81. a:=set_key('M-SESS', '');
  82. a:=set_key('M-KOOD', '');
  83. a:=set_key('M-ISIKUKOOD', '');
  84. a:=set_key('M-EESNIMI', '');
  85. a:=set_key('M-PERENIMI', '');
  86. a:=set_key('M-STATUS', '');
  87. elsif tegevus='Alusta autentimist' then
  88. if get_key('M-KOOD_MOBIIL') = id then
  89. -- Kasutaja tegi refreshi => Staatuse kontroll
  90. if not get_key('M-STATUS')='011' then
  91. a:=set_key('M-STATUS', digidoc.m_id_auth_check(get_key('M-SESS')));
  92. end if;
  93. else
  94. tmp_arr:=digidoc.m_id_auth(id);
  95. if COALESCE(array_upper(tmp_arr, 1), 0) >= 7 and tmp_arr[1]='OK' then
  96. a:=set_key('M-KOOD_MOBIIL', id);
  97. a:=set_key('M-SESS', tmp_arr[3]);
  98. a:=set_key('M-KOOD', tmp_arr[4]);
  99. a:=set_key('M-ISIKUKOOD', tmp_arr[5]);
  100. a:=set_key('M-EESNIMI', tmp_arr[6]);
  101. a:=set_key('M-PERENIMI', tmp_arr[7]);
  102. a:=set_key('M-STATUS', '010'); --OUTSTANDING_TRANSACTION
  103. else
  104. a:=set_key('M-STATUS', tmp_arr[2]);
  105. end if;
  106. end if;
  107.  
  108. ik:=get_key('M-ISIKUKOOD');
  109.  
  110. if get_key('M-STATUS') in ('010') then --OUTSTANDING_TRANSACTION
  111. a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
  112. --EDGAR. Kui ei tahete menyyd, siis ei joonista
  113. if menu<>'N' then
  114. a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
  115. end if;
  116. --a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
  117. a:=htp.p(pealkiri);
  118. if id ~ '^\\+' then
  119. a:=htp.p('<br /><p>Mobiiltelefoni number: '||escape_html(id)||'</p><br />');
  120. else
  121. a:=htp.p('<br /><p>Isikukood: '||escape_html(id)||'</p><br />');
  122. end if;
  123. a:=htp.p('<div id="sonum"><p>Palun oodake! Mõne aja pärast algab Teie mobiiltelefonis autentimisprotseduur.'||COALESCE(' Kontrollkood on: <b>'||to_null(get_key('M-KOOD'))||'</b>', '')||'</p>');
  124. a:=htp.p('<p>Kui olete sisestanud PIN1 koodi mobiiltelefoni, kuid keskkonda sisenemist pole toimunud ca 5 sekundi jooksul, siis värskendage palun <a class="menulink" href="#" onclick="window.location.reload(true)">seda lehekülge</a>.</p>');
  125. a:=htp.p('<p>Kui autentimisprotseduur ei alga pikema aja jooksul, siis kontrollige palun, kas Teie mobiiltelefon on levis ning korrake autentimist, vajutades lingile: <a class="menulink" href="/gvolis/avalik/m_login/">M-ID</a>.</p></div>');
  126. -- a:=htp.p('<script type="text/javascript">setTimeout("window.location.reload(true)", 5000);</script>');
  127. a:=htp.p(web.mlogin_script('tegevus=Alusta%20autentimist&id=')||coalesce(id::text,''));
  128. elsif get_key('M-STATUS')='011' then --USER_AUTHENTICATED
  129. -- Update session
  130. new_sess:=pwa.create_session(get_session_variable('SESSION_ID'),'login','40','M-ID',ik,get_key('M-EESNIMI'),get_key('M-PERENIMI'),null,null,null);
  131. if new_sess='NOTOK' then
  132. a:=set_session_variable('CODE',null);
  133. a:=set_key('M-KOOD_MOBIIL', '');
  134. a:=set_key('M-SESS', '');
  135. a:=set_key('M-KOOD', '');
  136. a:=set_key('M-ISIKUKOOD', '');
  137. a:=set_key('M-EESNIMI', '');
  138. a:=set_key('M-PERENIMI', '');
  139. a:=set_key('M-STATUS', '');
  140. a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
  141. a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
  142. a:=htp.p(pealkiri);
  143. a:=htp.p('<p class="alert">Ligipääs antud keskkonnale on keelatud</p>');
  144. return web.lopp();
  145. else
  146. a:=set_session_variable('SESSION_ID', new_sess);
  147. --a:=pwa.putstringhdr('Set-Cookie: '||get_session_variable('SESSIONKEY')||'='||new_sess||'; PATH=/'||pwa.cookie_domain()||';secure'||'\n');
  148. a:=pwa.putstringhdr('Set-Cookie: '||get_session_variable('SESSIONKEY')||'='||new_sess||'; PATH=/'||pwa.cookie_domain()||''||'\n');
  149. if not asutused.is_isikukood(get_key('M-KOOD_MOBIIL')) then
  150. a:=set_key('MOBIIL',get_key('M-KOOD_MOBIIL'));
  151. end if;
  152. end if;
  153.  
  154. tmp:=to_null(pwa.cookie_get('LOCATION'));
  155. if tmp is null then
  156. return htp.redirect(startpage);
  157. else
  158. a:=pwa.cookie_remove('LOCATION',null,null);
  159. return htp.redirect(unescape_uri(tmp));
  160. end if;
  161. elsif get_key('M-STATUS') in ('004', '012', '013', '014', '015', '016', '017', '018', '301', '303') then -- Kasutajapoolsed vead
  162. a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
  163. a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
  164. a:=htp.p(pealkiri);
  165. if id ~ '^\\+' then
  166. a:=htp.p('<br /><p>Mobiiltelefoni number: '||escape_html(id)||'</p><br />');
  167. else
  168. a:=htp.p('<br /><p>Isikukood: '||escape_html(id)||'</p><br />');
  169. end if;
  170. a:=htp.p('<p class="alert">Autentimisprotseduur ebaõnnestus (veakood: '||get_key('M-STATUS')||') - '||lov_code2value('WEB.M-STATUS',get_key('M-STATUS'))||'</p>');
  171. a:=htp.p(uuskatse);
  172. else -- Süsteemsed vead
  173. a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
  174. a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
  175. a:=htp.p(pealkiri);
  176. if id ~ '^\\+' then
  177. a:=htp.p('<br /><p>Mobiiltelefoni number: '||escape_html(id)||'</p><br />');
  178. else
  179. a:=htp.p('<br /><p>Isikukood: '||escape_html(id)||'</p><br />');
  180. end if;
  181. a:=htp.p('<p class="alert">Autentimisprotseduur ebaõnnestus (veakood: '||get_key('M-STATUS')||') - '||lov_code2value('WEB.M-STATUS',get_key('M-STATUS'))||'</p>');
  182. a:=htp.p(uuskatse);
  183. raise warning 'web.mlogin: tehniline viga! kood=%; kirjeldus=%', get_key('M-STATUS'),lov_code2value('WEB.M-STATUS',get_key('M-STATUS'));
  184. end if;
  185. else
  186. a:=web.algus(gettext('WEB','Mobiil-ID autentimine'));
  187. --EDGAR. Kui ei tahete menyyd, siis ei joonista
  188. if menu<>'N' then
  189. a:=htp.p(volis.panel_start('panel_mlogin','Mobiil-ID autentimine','maximized-fixed',null));
  190. end if;
  191. a:=htp.p(pealkiri);
  192. a:=htp.p(vorm1||coalesce(' value="'||meeles||'"','')||vorm2);
  193.  
  194. --a:=htp.p(web.mlogin_script('X'));
  195.  
  196. a:=set_key('M-KOOD_MOBIIL', '');
  197. a:=set_key('M-SESS', '');
  198. a:=set_key('M-KOOD', '');
  199. a:=set_key('M-ISIKUKOOD', '');
  200. a:=set_key('M-EESNIMI', '');
  201. a:=set_key('M-PERENIMI', '');
  202. a:=set_key('M-STATUS', '');
  203. end if;
  204.  
  205. if id is not null and arrayvalue(name_array, value_array, 'meeles') is not null then
  206. a:=pwa.cookie_set('MEELES',id::varchar,null,(current_timestamp + interval '30 days')::timestamp,'/'||pwa.cookie_domain());
  207. elsif tegevus='Alusta autentimist' and arrayvalue(name_array, value_array, 'meeles') is null then
  208. a:=pwa.cookie_remove('MEELES',null,null);
  209. end if;
  210.  
  211. a:=htp.p(volis.panel_end('panel_mlogin','maximized-fixed'));
  212. return web.lopp();
  213. END;
  214. $BODY$
  215. LANGUAGE plpgsql VOLATILE SECURITY DEFINER
  216. COST 100;
  217. ALTER FUNCTION web.mlogin(character varying[], character varying[])
  218. OWNER TO sysadm;
  219. COMMENT ON FUNCTION web.mlogin(character varying[], character varying[]) IS 'Mobiilse autentimise kasutajaliides (pooleli).';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement