Version Description
Download this release
Release Info
Developer | mihche |
Plugin | WPBruiser {no- Captcha anti-Spam} |
Version | 3.1.31 |
Comparing to | |
See all releases |
Code changes from version 3.1.29 to 3.1.31
- {assets → 2.0/assets}/admin/images/flags/ad.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ae.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/af.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ag.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ai.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/al.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/am.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/an.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ao.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/aq.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ar.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/as.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/at.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/au.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/aw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ax.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/az.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ba.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bb.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bd.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/be.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bh.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bi.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bj.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bl.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bo.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/br.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bs.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bt.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bv.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/by.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/bz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ca.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/catalonia.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cc.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cd.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ch.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ci.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ck.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cl.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/co.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cs.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cv.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cx.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cy.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/cz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/de.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/dj.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/dk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/dm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/do.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/dz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ec.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ee.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/eg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/eh.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/england.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/er.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/es.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/et.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/eu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/fam.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/fi.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/fj.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/fk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/fm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/fo.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/fr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ga.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gb.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gd.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ge.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gh.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gi.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gl.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gp.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gq.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gs.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gt.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/gy.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/hk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/hm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/hn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/hr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ht.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/hu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/id.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ie.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/il.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/im.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/in.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/io.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/iq.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ir.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/is.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/it.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/je.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/jm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/jo.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/jp.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ke.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/kg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/kh.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ki.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/km.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/kn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/kp.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/kr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/kw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ky.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/kz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/la.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/lb.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/lc.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/li.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/lk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/lr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ls.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/lt.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/lu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/lv.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ly.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ma.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mc.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/md.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/me.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mh.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ml.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mo.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mp.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mq.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ms.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mt.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mv.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mx.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/my.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/mz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/na.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/nc.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ne.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/nf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ng.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ni.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/nl.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/no.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/np.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/nr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/nu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/nz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/om.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pa.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pe.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ph.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pl.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ps.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pt.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/pw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/py.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/qa.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/re.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ro.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/rs.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ru.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/rw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sa.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sb.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sc.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/scotland.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sd.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/se.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sh.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/si.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sj.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sl.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/so.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/st.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sv.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sy.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/sz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tc.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/td.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/th.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tj.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tk.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tl.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/to.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tr.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tt.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tv.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tw.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/tz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ua.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ug.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/um.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/us.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/uy.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/uz.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/va.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/vc.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ve.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/vg.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/vi.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/vn.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/vu.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/wales.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/wf.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ws.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/ye.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/yt.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/za.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/zm.gif +0 -0
- {assets → 2.0/assets}/admin/images/flags/zw.gif +0 -0
- {assets → 2.0/assets}/admin/images/gdbc-favicon.png +0 -0
- {assets → 2.0/assets}/admin/images/gdbc-logo.png +0 -0
- {assets → 2.0/assets}/admin/scripts/bootstrap.min.js +0 -0
- {assets → 2.0/assets}/admin/scripts/easy-pie-chart.js +0 -0
- 2.0/assets/admin/scripts/gdbc-admin.js +47 -0
- {assets → 2.0/assets}/admin/scripts/gdbc-reports.js +0 -0
- {assets → 2.0/assets}/admin/scripts/jquery-flot-tooltip.js +0 -0
- {assets → 2.0/assets}/admin/scripts/jquery-flot.js +0 -0
- {assets → 2.0/assets}/admin/scripts/jquery-jvectormap-1.2.2.min.js +0 -0
- {assets → 2.0/assets}/admin/scripts/jquery-jvectormap-world-mill-en.js +0 -0
- {assets → 2.0/assets}/admin/scripts/morris.js +0 -0
- {assets → 2.0/assets}/admin/scripts/raphael.js +0 -0
- {assets → 2.0/assets}/admin/styles/bootstrap.css +0 -0
- {assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.eot +0 -0
- {assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.svg +0 -0
- {assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.ttf +0 -0
- {assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.woff +0 -0
- 2.0/assets/admin/styles/gdbc-admin.css +832 -0
- {assets → 2.0/assets}/admin/styles/morris.css +0 -0
- {assets → 2.0/assets}/public/scripts/gdbc-client.js.php +0 -0
- {assets → 2.0/assets}/public/scripts/gdbc-public.js +0 -0
- {assets → 2.0/assets}/public/scripts/index.php +0 -0
- 2.0/engine/GdbcAjaxController.php +166 -0
- 2.0/engine/GdbcBruteGuardian.php +230 -0
- 2.0/engine/GdbcIPUtils.php +404 -0
- 2.0/engine/GdbcModulesController.php +566 -0
- 2.0/engine/GdbcNotificationsController.php +152 -0
- 2.0/engine/GdbcRequestController.php +288 -0
- {engine → 2.0/engine}/GdbcTaskScheduler.php +0 -0
- 2.0/engine/GdbcUpdatesController.php +317 -0
- 2.0/engine/GoodByeCaptchaAdmin.php +306 -0
- 2.0/engine/GoodByeCaptchaPublic.php +91 -0
- 2.0/engine/GoodByeCaptchaUtils.php +593 -0
- 2.0/engine/admin/GdbcAdminNotice.php +34 -0
- 2.0/engine/admin/pages/GdbcBaseAdminPage.php +98 -0
- 2.0/engine/admin/pages/GdbcContactFormsAdminPage.php +55 -0
- 2.0/engine/admin/pages/GdbcMembershipAdminPage.php +52 -0
- 2.0/engine/admin/pages/GdbcNotificationsAdminPage.php +41 -0
- 2.0/engine/admin/pages/GdbcOthersAdminPage.php +71 -0
- 2.0/engine/admin/pages/GdbcReportsAdminPage.php +64 -0
- 2.0/engine/admin/pages/GdbcSecurityAdminPage.php +161 -0
- 2.0/engine/admin/pages/GdbcSettingsAdminPage.php +37 -0
- 2.0/engine/admin/pages/GdbcWordpressAdminPage.php +107 -0
- 2.0/engine/db-access/GdbcDbAccessController.php +356 -0
- {engine → 2.0/engine}/entities/GdbcAttemptEntity.php +0 -0
- 2.0/engine/modules/GdbcBaseAdminModule.php +194 -0
- 2.0/engine/modules/GdbcBasePublicModule.php +100 -0
- {engine → 2.0/engine}/modules/black-listed-ips/GdbcBlackListedIpsAdminModule.php +0 -0
- {engine → 2.0/engine}/modules/black-listed-ips/GdbcBlackListedIpsPublicModule.php +0 -0
- 2.0/engine/modules/black-listed-ips/partials/admin-settings.php +214 -0
- 2.0/engine/modules/brute-force/GdbcBruteForceAdminModule.php +156 -0
- 2.0/engine/modules/brute-force/GdbcBruteForcePublicModule.php +66 -0
- 2.0/engine/modules/email-notifications/GdbcEmailNotificationsAdminModule.php +101 -0
- 2.0/engine/modules/email-notifications/GdbcEmailNotificationsPublicModule.php +81 -0
- 2.0/engine/modules/email-notifications/templates/notification-base-layout.html +26 -0
- 2.0/engine/modules/email-notifications/templates/notification-brute-force-attack.php +101 -0
- 2.0/engine/modules/email-notifications/templates/notification-test-mode.php +45 -0
- 2.0/engine/modules/jetpack-contact-form/GdbcJetPackContactFormAdminModule.php +103 -0
- {engine → 2.0/engine}/modules/jetpack-contact-form/GdbcJetPackContactFormPublicModule.php +0 -0
- {engine → 2.0/engine}/modules/mc-for-wp/GdbcMailChimpForWpAdminModule.php +0 -0
- 2.0/engine/modules/mc-for-wp/GdbcMailChimpForWpPublicModule.php +186 -0
- {engine → 2.0/engine}/modules/planso-forms/GdbcPlanSoFormsAdminModule.php +0 -0
- {engine → 2.0/engine}/modules/planso-forms/GdbcPlanSoFormsPublicModule.php +0 -0
- 2.0/engine/modules/reports/GdbcReportsAdminModule.php +593 -0
- {engine → 2.0/engine}/modules/reports/GdbcReportsPublicModule.php +0 -0
- 2.0/engine/modules/reports/partials/blocked-content-table.php +48 -0
- {engine → 2.0/engine}/modules/reports/partials/latest-attempts-locations.php +0 -0
- {engine → 2.0/engine}/modules/reports/partials/latest-attempts-table.php +0 -0
- {engine → 2.0/engine}/modules/reports/partials/modal-dialog.php +0 -0
- {engine → 2.0/engine}/modules/reports/partials/module-table.php +0 -0
- {engine → 2.0/engine}/modules/reports/partials/percentage-chart.php +0 -0
- {engine → 2.0/engine}/modules/reports/partials/reports-details.php +0 -0
- 2.0/engine/modules/reports/partials/reports-stats.php +61 -0
- {engine → 2.0/engine}/modules/seamless-donations/GdbcSeamlessDonationsAdminModule.php +0 -0
- {engine → 2.0/engine}/modules/seamless-donations/GdbcSeamlessDonationsPublicModule.php +0 -0
- 2.0/engine/modules/settings/GdbcSettingsAdminModule.php +245 -0
- 2.0/engine/modules/settings/GdbcSettingsPublicModule.php +41 -0
- {engine → 2.0/engine}/modules/ultimate-member/GdbcUltimateMemberAdminModule.php +0 -0
- 2.0/engine/modules/ultimate-member/GdbcUltimateMemberPublicModule.php +136 -0
- {engine → 2.0/engine}/modules/white-listed-ips/GdbcWhiteListedIpsAdminModule.php +0 -0
- {engine → 2.0/engine}/modules/white-listed-ips/GdbcWhiteListedIpsPublicModule.php +0 -0
- 2.0/engine/modules/white-listed-ips/partials/admin-settings.php +207 -0
- 2.0/engine/modules/wordpress-tweaks/GdbcWordPressTweaksAdminModule.php +133 -0
- 2.0/engine/modules/wordpress-tweaks/GdbcWordPressTweaksPublicModule.php +156 -0
- 2.0/engine/modules/wordpress/GdbcWordPressAdminModule.php +185 -0
- 2.0/engine/modules/wordpress/GdbcWordPressPublicModule.php +314 -0
- {engine → 2.0/engine}/modules/zm-ajax-login-register/GdbcZmAlrAdminModule.php +0 -0
- 2.0/engine/modules/zm-ajax-login-register/GdbcZmAlrPublicModule.php +149 -0
- {engine → 2.0/engine}/tasks/GdbcCheckAttemptsTask.php +0 -0
- {engine → 2.0/engine}/tasks/GdbcLogsCleanerTask.php +0 -0
- 2.0/goodbye-captcha.php +151 -0
- 2.0/includes/MchGdbcLibAutoloader.php +109 -0
- 2.0/includes/modules/MchGdbcBaseAdminModule.php +183 -0
- 2.0/includes/modules/MchGdbcBaseModule.php +108 -0
- {includes → 2.0/includes}/modules/MchGdbcBasePublicModule.php +0 -0
- 2.0/includes/modules/MchGdbcGroupedModules.php +54 -0
- 2.0/includes/modules/MchGdbcModulesController.php +12 -0
- {includes → 2.0/includes}/notices/MchGdbcAdminNotice.php +0 -0
- {includes → 2.0/includes}/plugin/MchGdbcBaseAdminPage.php +0 -0
- 2.0/includes/plugin/MchGdbcBaseAdminPlugin.php +66 -0
- 2.0/includes/plugin/MchGdbcBasePlugin.php +64 -0
- 2.0/includes/plugin/MchGdbcBasePublicPlugin.php +46 -0
- 2.0/includes/plugin/MchGdbcPluginUpdater.php +336 -0
- {includes → 2.0/includes}/task-scheduler/MchGdbcWpTask.php +0 -0
- {includes → 2.0/includes}/task-scheduler/MchGdbcWpTaskScheduler.php +0 -0
- {includes → 2.0/includes}/utils/MchGdbcHtmlUtils.php +0 -0
- 2.0/includes/utils/MchGdbcIPUtils.php +866 -0
- 2.0/includes/utils/MchGdbcUtils.php +117 -0
- 2.0/includes/utils/MchGdbcWpUtils.php +374 -0
- 2.0/includes/vendor/MaxMind/GeoIP.dat +0 -0
- 2.0/includes/vendor/MaxMind/GeoIPv6.dat +0 -0
- 2.0/includes/vendor/MaxMind/MchMaxMindGeoIp.php +1593 -0
- {includes → 2.0/includes}/vendor/MchCache/MchGdbcCache.php +0 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheAPCStorage.php +0 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheAPCUStorage.php +0 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheBaseStorage.php +0 -0
- 2.0/includes/vendor/MchCache/Storage/MchGdbcCacheFileStorage.php +178 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheMemcacheStorage.php +0 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheMemcachedStorage.php +0 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheXCacheStorage.php +0 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheZendDiskStorage.php +0 -0
- {includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheZendMemoryStorage.php +0 -0
- 2.0/includes/vendor/MchCache/Storage/MchGdbcWordPressTransientsStorage.php +82 -0
- 2.0/includes/vendor/MchCrypt/Core/Crypter.php +276 -0
- 2.0/includes/vendor/MchCrypt/Core/Generator.php +320 -0
- 2.0/includes/vendor/MchCrypt/MchCrypt.php +291 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Cipher.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Core.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Includes.inc.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Mode.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Padding.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/README.md +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/3DES.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/3Way.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/AES128.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/AES192.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/AES256.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/ARC4.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Blowfish.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/CAST128.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/CAST256.php +0 -0
- 2.0/includes/vendor/MchCrypt/PhpCrypt/ciphers/DES.php +595 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Enigma.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/RC2.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael.php +0 -0
- 2.0/includes/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael128.php +98 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael192.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael256.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/SimpleXOR.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Skipjack.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Vigenere.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/licenses/ECCN_5D002.txt +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/licenses/GPL.txt +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/CBC.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/CFB.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/CTR.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/ECB.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/NCFB.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/NOFB.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/OFB.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/PCBC.php +0 -0
- 2.0/includes/vendor/MchCrypt/PhpCrypt/modes/Raw.php +116 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/Stream.php +0 -0
- {includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/phpCrypt.php +0 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/AES.php +207 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Base.php +2011 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Blowfish.php +644 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/DES.php +1506 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Hash.php +841 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/RC2.php +652 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/RC4.php +329 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/RSA.php +2997 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Random.php +300 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Rijndael.php +1348 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/TripleDES.php +428 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Twofish.php +895 -0
- 2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/File/ANSI.php +152 -0
{assets → 2.0/assets}/admin/images/flags/ad.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ae.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/af.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ag.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ai.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/al.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/am.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/an.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ao.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/aq.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ar.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/as.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/at.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/au.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/aw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ax.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/az.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ba.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bb.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bd.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/be.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bh.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bi.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bj.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bl.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bo.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/br.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bs.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bt.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bv.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/by.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/bz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ca.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/catalonia.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cc.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cd.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ch.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ci.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ck.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cl.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/co.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cs.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cv.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cx.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cy.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/cz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/de.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/dj.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/dk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/dm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/do.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/dz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ec.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ee.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/eg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/eh.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/england.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/er.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/es.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/et.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/eu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/fam.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/fi.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/fj.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/fk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/fm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/fo.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/fr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ga.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gb.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gd.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ge.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gh.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gi.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gl.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gp.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gq.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gs.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gt.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/gy.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/hk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/hm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/hn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/hr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ht.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/hu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/id.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ie.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/il.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/im.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/in.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/io.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/iq.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ir.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/is.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/it.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/je.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/jm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/jo.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/jp.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ke.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/kg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/kh.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ki.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/km.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/kn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/kp.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/kr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/kw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ky.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/kz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/la.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/lb.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/lc.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/li.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/lk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/lr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ls.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/lt.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/lu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/lv.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ly.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ma.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mc.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/md.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/me.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mh.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ml.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mo.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mp.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mq.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ms.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mt.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mv.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mx.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/my.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/mz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/na.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/nc.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ne.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/nf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ng.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ni.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/nl.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/no.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/np.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/nr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/nu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/nz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/om.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pa.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pe.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ph.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pl.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ps.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pt.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/pw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/py.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/qa.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/re.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ro.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/rs.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ru.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/rw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sa.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sb.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sc.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/scotland.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sd.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/se.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sh.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/si.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sj.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sl.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/so.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/st.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sv.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sy.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/sz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tc.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/td.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/th.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tj.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tk.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tl.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/to.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tr.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tt.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tv.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/tz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ua.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ug.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/um.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/us.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/uy.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/uz.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/va.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/vc.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ve.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/vg.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/vi.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/vn.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/vu.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/wales.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/wf.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ws.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/ye.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/yt.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/za.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/zm.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/flags/zw.gif
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/gdbc-favicon.png
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/images/gdbc-logo.png
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/bootstrap.min.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/easy-pie-chart.js
RENAMED
File without changes
|
2.0/assets/admin/scripts/gdbc-admin.js
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery( document ).ready(function($) {
|
2 |
+
var maxLogsDaysElm = $('#gdbcsettings-settings-MaxLogsDays');
|
3 |
+
|
4 |
+
if(maxLogsDaysElm.length !== 0) {
|
5 |
+
if(maxLogsDaysElm.val() == 0) {
|
6 |
+
maxLogsDaysElm.parent().children('p').first().toggle(false);
|
7 |
+
maxLogsDaysElm.parent().children('p').last().toggle(true);
|
8 |
+
}
|
9 |
+
|
10 |
+
maxLogsDaysElm.change(function () {
|
11 |
+
if ($(this).val() != 0) {
|
12 |
+
$(this).parent().children('p').first().toggle(true);
|
13 |
+
$(this).parent().children('p').last().toggle(false);
|
14 |
+
}
|
15 |
+
else {
|
16 |
+
$(this).parent().children('p').first().toggle(false);
|
17 |
+
$(this).parent().children('p').last().toggle(true);
|
18 |
+
}
|
19 |
+
|
20 |
+
});
|
21 |
+
}
|
22 |
+
|
23 |
+
$('div.mch-admin-notice.is-dismissible').each(function(){
|
24 |
+
var noticeElm = $(this);
|
25 |
+
noticeElm.on('click', '.notice-dismiss', function(event){
|
26 |
+
|
27 |
+
jQuery.ajax({
|
28 |
+
type : "post",
|
29 |
+
cache: false,
|
30 |
+
dataType : "json",
|
31 |
+
url : GdbcAdmin.ajaxUrl,
|
32 |
+
data : {
|
33 |
+
action: 'gdbc-dismiss-' + noticeElm.prop('id'),
|
34 |
+
ajaxRequestNonce: GdbcAdmin.ajaxRequestNonce
|
35 |
+
}
|
36 |
+
});
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
//alert(noticeElm.data('id'));
|
41 |
+
})
|
42 |
+
|
43 |
+
});
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
});
|
{assets → 2.0/assets}/admin/scripts/gdbc-reports.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/jquery-flot-tooltip.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/jquery-flot.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/jquery-jvectormap-1.2.2.min.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/jquery-jvectormap-world-mill-en.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/morris.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/scripts/raphael.js
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/styles/bootstrap.css
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.eot
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.svg
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.ttf
RENAMED
File without changes
|
{assets → 2.0/assets}/admin/styles/fonts/glyphicons-halflings-regular.woff
RENAMED
File without changes
|
2.0/assets/admin/styles/gdbc-admin.css
ADDED
@@ -0,0 +1,832 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body
|
2 |
+
{
|
3 |
+
color: #444;
|
4 |
+
font-family: "Open Sans",sans-serif;
|
5 |
+
font-size: 13px;
|
6 |
+
line-height: 1.4em;
|
7 |
+
color:#444;
|
8 |
+
background-color: #F1F1F1;
|
9 |
+
}
|
10 |
+
|
11 |
+
div.wrap.container-fluid
|
12 |
+
{
|
13 |
+
margin: 10px 20px 0px 2px;
|
14 |
+
padding:0;
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
div.gdbc-settings .clearfix:after
|
20 |
+
{
|
21 |
+
content: ".";
|
22 |
+
display: block;
|
23 |
+
height: 0;
|
24 |
+
clear: both;
|
25 |
+
visibility: hidden;
|
26 |
+
zoom: 1
|
27 |
+
}
|
28 |
+
|
29 |
+
#gdbc-reports-holder
|
30 |
+
{
|
31 |
+
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
|
32 |
+
}
|
33 |
+
#gdbc-reports-holder h3
|
34 |
+
{
|
35 |
+
font-size: 1.5em;
|
36 |
+
}
|
37 |
+
|
38 |
+
#adminmenuwrap{
|
39 |
+
height: 100%
|
40 |
+
}
|
41 |
+
|
42 |
+
#chart-container{ height: 235px; width: 100% }
|
43 |
+
|
44 |
+
.gdbcwidget {
|
45 |
+
border-radius: 0;
|
46 |
+
margin: 0 0 30px;
|
47 |
+
padding: 0;
|
48 |
+
}
|
49 |
+
|
50 |
+
.gdbcwidget .widget-body {
|
51 |
+
min-height: 100px;
|
52 |
+
/*padding-bottom: 13px;*/
|
53 |
+
position: relative;
|
54 |
+
}
|
55 |
+
|
56 |
+
.gdbcwidget header {
|
57 |
+
border-radius: 0;
|
58 |
+
box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.05) inset;
|
59 |
+
background: none repeat scroll 0 0 #fafafa;
|
60 |
+
border: 1px solid #c2c2c2;
|
61 |
+
color: #333;
|
62 |
+
height: 34px;
|
63 |
+
line-height: 40px;
|
64 |
+
padding: 0;
|
65 |
+
font-size: 13px;
|
66 |
+
}
|
67 |
+
|
68 |
+
.gdbcwidget > header {
|
69 |
+
background: none repeat scroll 0 0 #fafafa;
|
70 |
+
border: 1px solid #c2c2c2;
|
71 |
+
color: #333;
|
72 |
+
}
|
73 |
+
|
74 |
+
.gdbcwidget header h2 {
|
75 |
+
float: left;
|
76 |
+
display: inline-block;
|
77 |
+
font-size: 14px;
|
78 |
+
font-weight: 400;
|
79 |
+
height: 100%;
|
80 |
+
letter-spacing: 0;
|
81 |
+
line-height: 34px;
|
82 |
+
margin: 0;
|
83 |
+
position: relative;
|
84 |
+
width: auto;
|
85 |
+
padding: 0 !important;
|
86 |
+
}
|
87 |
+
|
88 |
+
.gdbcwidget > div {
|
89 |
+
border-bottom-color: #ccc !important;
|
90 |
+
border-left-color: #ccc !important;
|
91 |
+
border-radius: 0;
|
92 |
+
border-right-color: #ccc !important;
|
93 |
+
border-style: none solid solid;
|
94 |
+
border-top: medium none;
|
95 |
+
border-width: medium 1px 2px;
|
96 |
+
float: left;
|
97 |
+
font-size: 13px;
|
98 |
+
margin: 0;
|
99 |
+
overflow: visible;
|
100 |
+
padding: 13px 13px 0;
|
101 |
+
position: relative;
|
102 |
+
width: 100%;
|
103 |
+
background-color: #fff !important
|
104 |
+
}
|
105 |
+
|
106 |
+
.no-padding {
|
107 |
+
padding: 0 !important;
|
108 |
+
}
|
109 |
+
|
110 |
+
.row.no-space {
|
111 |
+
margin:0;
|
112 |
+
padding:0;
|
113 |
+
border:none;
|
114 |
+
}
|
115 |
+
|
116 |
+
.no-space {
|
117 |
+
margin: 0;
|
118 |
+
}
|
119 |
+
|
120 |
+
.widget-icon {
|
121 |
+
display:block;
|
122 |
+
float: left;
|
123 |
+
font-size: 111%;
|
124 |
+
height: 32px;
|
125 |
+
line-height: 32px;
|
126 |
+
position: relative;
|
127 |
+
text-align: center;
|
128 |
+
width: 30px
|
129 |
+
}
|
130 |
+
#dashboard-navigation{
|
131 |
+
float: left
|
132 |
+
}
|
133 |
+
|
134 |
+
.gdbcwidget-loader {
|
135 |
+
background-position: center center;
|
136 |
+
background-repeat: no-repeat;
|
137 |
+
display: none;
|
138 |
+
float: right;
|
139 |
+
font-size: 111%;
|
140 |
+
height: 32px;
|
141 |
+
line-height: 32px;
|
142 |
+
margin: 0;
|
143 |
+
text-align: center;
|
144 |
+
width: 32px
|
145 |
+
}
|
146 |
+
|
147 |
+
.no-space > [class*="col-"] {
|
148 |
+
margin: 0 !important;
|
149 |
+
padding-left: 0;
|
150 |
+
padding-right: 0;
|
151 |
+
}
|
152 |
+
|
153 |
+
.nav > li {
|
154 |
+
display: block;
|
155 |
+
position: relative;
|
156 |
+
}
|
157 |
+
|
158 |
+
.nav-tabs > li {
|
159 |
+
float: left;
|
160 |
+
margin-bottom: -2px;
|
161 |
+
margin-right: -3px;
|
162 |
+
}
|
163 |
+
|
164 |
+
.gdbcwidget header:first-child .nav-tabs li {
|
165 |
+
padding-left: 0;
|
166 |
+
}
|
167 |
+
|
168 |
+
.gdbcwidget header .nav-tabs > li.active > a, .gdbcwidget header .nav-tabs > li.active > a:focus, .gdbcwidget header .nav-tabs > li.active > a:hover {
|
169 |
+
-moz-border-bottom-colors: none;
|
170 |
+
-moz-border-left-colors: none;
|
171 |
+
-moz-border-right-colors: none;
|
172 |
+
-moz-border-top-colors: none;
|
173 |
+
background-color: #fff;
|
174 |
+
border-color: -moz-use-text-color #c2c2c2 transparent;
|
175 |
+
border-image: none;
|
176 |
+
border-left: 1px solid #c2c2c2;
|
177 |
+
border-right: 1px solid #c2c2c2;
|
178 |
+
border-style: none solid solid;
|
179 |
+
border-width: medium 1px 1px;
|
180 |
+
color: #555;
|
181 |
+
cursor: default;
|
182 |
+
}
|
183 |
+
|
184 |
+
.gdbcwidget header .nav-tabs > li > a {
|
185 |
+
border: medium none;
|
186 |
+
border-radius: 0;
|
187 |
+
padding: 7px 15px 6px;
|
188 |
+
}
|
189 |
+
|
190 |
+
.module-pagingation
|
191 |
+
{
|
192 |
+
margin-top: 0 !important;
|
193 |
+
margin-bottom: 0 !important
|
194 |
+
}
|
195 |
+
|
196 |
+
.nav-tabs > li.active > a {
|
197 |
+
border-top-width: 0 !important;
|
198 |
+
box-shadow: 0 -2px 0 #57889c;
|
199 |
+
font-weight: 700;
|
200 |
+
margin-top: 1px !important;
|
201 |
+
}
|
202 |
+
|
203 |
+
.nav-tabs > li.active > a, .nav-tabs > li.active > a:focus, .nav-tabs > li.active > a:hover {
|
204 |
+
-moz-border-bottom-colors: none;
|
205 |
+
-moz-border-left-colors: none;
|
206 |
+
-moz-border-right-colors: none;
|
207 |
+
-moz-border-top-colors: none;
|
208 |
+
background-color: #fff;
|
209 |
+
border-color: #ddd #ddd transparent;
|
210 |
+
border-image: none;
|
211 |
+
border-style: solid;
|
212 |
+
border-width: 1px;
|
213 |
+
color: #555;
|
214 |
+
cursor: default;
|
215 |
+
}
|
216 |
+
|
217 |
+
.nav-tabs > li > a {
|
218 |
+
border-radius: 0;
|
219 |
+
color: #333;
|
220 |
+
}
|
221 |
+
.nav-tabs > li > a {
|
222 |
+
border: 1px solid transparent;
|
223 |
+
border-radius: 2px 2px 0 0;
|
224 |
+
line-height: 1.42857;
|
225 |
+
margin-right: 2px;
|
226 |
+
}
|
227 |
+
.nav > li > a {
|
228 |
+
display: block;
|
229 |
+
padding: 9px 10px 10px;
|
230 |
+
position: relative;
|
231 |
+
}
|
232 |
+
|
233 |
+
.vector-map, #gdbc-stats{
|
234 |
+
height: 300px;
|
235 |
+
width: 100%;
|
236 |
+
}
|
237 |
+
|
238 |
+
.vector-map{
|
239 |
+
padding: 10px;
|
240 |
+
}
|
241 |
+
|
242 |
+
.progress {
|
243 |
+
border-radius: 0;
|
244 |
+
height: 7px;
|
245 |
+
margin-bottom: 15px;
|
246 |
+
margin-top: 3px;
|
247 |
+
}
|
248 |
+
|
249 |
+
.easyPieChart{
|
250 |
+
display: inline-block;
|
251 |
+
text-align: center;
|
252 |
+
position: relative;
|
253 |
+
width: 60px;
|
254 |
+
height: 60px;
|
255 |
+
line-height: 60px
|
256 |
+
}
|
257 |
+
|
258 |
+
.easyPieChart canvas{
|
259 |
+
position: absolute;
|
260 |
+
top:0;
|
261 |
+
left:0
|
262 |
+
}
|
263 |
+
|
264 |
+
.pie-chart-widgets > div {
|
265 |
+
border-right: 1px solid #dadada !important;
|
266 |
+
border-top: 1px solid #dadada !important;
|
267 |
+
margin-top: 10px !important;
|
268 |
+
overflow: hidden;
|
269 |
+
padding: 7px 9px;
|
270 |
+
}
|
271 |
+
|
272 |
+
.padding-10
|
273 |
+
{
|
274 |
+
padding: 10px !important;
|
275 |
+
}
|
276 |
+
|
277 |
+
.table img
|
278 |
+
{
|
279 |
+
margin-right: 5px
|
280 |
+
}
|
281 |
+
|
282 |
+
.countriesTable tbody tr, #gdbc-pie-chart table tbody tr{
|
283 |
+
height: 40px;
|
284 |
+
}
|
285 |
+
|
286 |
+
.bg-color-dark-blue{
|
287 |
+
background-color: #4c4f53 !important;
|
288 |
+
}
|
289 |
+
|
290 |
+
.bg-color-blue{
|
291 |
+
background-color: #57889c !important;
|
292 |
+
}
|
293 |
+
|
294 |
+
.bg-color-green{
|
295 |
+
background-color: #71843f !important;
|
296 |
+
}
|
297 |
+
|
298 |
+
.bg-color-dark-orange{
|
299 |
+
background-color: #a57225
|
300 |
+
}
|
301 |
+
|
302 |
+
.view-buttons{
|
303 |
+
width:100%;
|
304 |
+
}
|
305 |
+
|
306 |
+
.view-buttons span
|
307 |
+
{
|
308 |
+
display: inline-block;
|
309 |
+
width: 200px;
|
310 |
+
float:right;
|
311 |
+
}
|
312 |
+
|
313 |
+
/* Map with location of all the attempts */
|
314 |
+
.jvectormap-zoomin,.jvectormap-zoomout
|
315 |
+
{
|
316 |
+
position:absolute;
|
317 |
+
padding:4px;
|
318 |
+
width:22px;
|
319 |
+
height:22px;
|
320 |
+
cursor:pointer;
|
321 |
+
line-height:10px;
|
322 |
+
text-align:center;
|
323 |
+
font-size:14px;
|
324 |
+
border-radius:2px;
|
325 |
+
-webkit-border-radius:2px;
|
326 |
+
-moz-border-radius:2px;
|
327 |
+
box-shadow:inset 0 -2px 0 rgba(0,0,0,.05);
|
328 |
+
-moz-box-shadow:inset 0 -2px 0 rgba(0,0,0,.05);
|
329 |
+
-webkit-box-shadow:inset 0 -2px 0 rgba(0,0,0,.05);
|
330 |
+
background-color:#fff;
|
331 |
+
border:1px solid #bfbfbf
|
332 |
+
}
|
333 |
+
|
334 |
+
.jvectormap-zoomin:hover,.jvectormap-zoomout:hover
|
335 |
+
{
|
336 |
+
background:#eee;border-color:#d9d9d9
|
337 |
+
}
|
338 |
+
|
339 |
+
.jvectormap-zoomin
|
340 |
+
{
|
341 |
+
top:0
|
342 |
+
}
|
343 |
+
|
344 |
+
.jvectormap-zoomout
|
345 |
+
{
|
346 |
+
top:24px
|
347 |
+
}
|
348 |
+
|
349 |
+
.jvectormap-label
|
350 |
+
{
|
351 |
+
position:absolute;
|
352 |
+
display:none;
|
353 |
+
border:solid 1px #CDCDCD;
|
354 |
+
-webkit-border-radius:3px;
|
355 |
+
-moz-border-radius:3px;
|
356 |
+
border-radius:3px;
|
357 |
+
background:#292929;
|
358 |
+
color:#fff;
|
359 |
+
font-family:sans-serif,Verdana;
|
360 |
+
font-size:smaller;
|
361 |
+
padding:3px
|
362 |
+
}
|
363 |
+
|
364 |
+
.bg-color-greenLight {
|
365 |
+
background-color: #71843f !important;
|
366 |
+
}
|
367 |
+
|
368 |
+
.bg-color-blueLight {
|
369 |
+
background-color: #92a2a8 !important;
|
370 |
+
}
|
371 |
+
|
372 |
+
.bg-color-red{
|
373 |
+
background-color: #a90329 !important;
|
374 |
+
}
|
375 |
+
|
376 |
+
.icon-success{
|
377 |
+
color: #5cb85c
|
378 |
+
}
|
379 |
+
|
380 |
+
.icon-danger{
|
381 |
+
color: #d9534f
|
382 |
+
}
|
383 |
+
|
384 |
+
.icon-primary{
|
385 |
+
color: #428bca
|
386 |
+
}
|
387 |
+
|
388 |
+
a.badge:hover{
|
389 |
+
background-color: #92a2a8 !important;
|
390 |
+
}
|
391 |
+
|
392 |
+
a.easy-tool-tip:hover span:hover {
|
393 |
+
background-color: #92a2a8 !important;
|
394 |
+
cursor: hand;
|
395 |
+
}
|
396 |
+
|
397 |
+
.pie-chart-widgets span.label {
|
398 |
+
min-width: 30px;
|
399 |
+
display: block;
|
400 |
+
text-align: center;
|
401 |
+
}
|
402 |
+
|
403 |
+
.dropdown-menu-xs {
|
404 |
+
min-width: 37px;
|
405 |
+
}
|
406 |
+
|
407 |
+
/*modules page*/
|
408 |
+
.toolbar {
|
409 |
+
display: block;
|
410 |
+
margin-bottom: 0;
|
411 |
+
margin-left: 0;
|
412 |
+
margin-right: 0;
|
413 |
+
margin-top: 0;
|
414 |
+
background-attachment: scroll;
|
415 |
+
background-clip: border-box;
|
416 |
+
background-image: none;
|
417 |
+
background-origin: padding-box;
|
418 |
+
background-position: 0 0;
|
419 |
+
background-repeat: repeat;
|
420 |
+
background-size: auto auto;
|
421 |
+
border-bottom-color: #ccc;
|
422 |
+
border-bottom-style: solid;
|
423 |
+
border-bottom-width: 1px;
|
424 |
+
min-height: 42px;
|
425 |
+
padding-bottom: 8px;
|
426 |
+
padding-left: 10px;
|
427 |
+
padding-right: 10px;
|
428 |
+
padding-top: 8px;
|
429 |
+
background-color: #fff;
|
430 |
+
color: #666;
|
431 |
+
outline-color: -moz-use-text-color;
|
432 |
+
outline-style: none;
|
433 |
+
outline-width: 0;
|
434 |
+
position: relative;
|
435 |
+
}
|
436 |
+
|
437 |
+
#modules-chart .inline-group:after {
|
438 |
+
clear: both;
|
439 |
+
content: "";
|
440 |
+
display: table;
|
441 |
+
}
|
442 |
+
|
443 |
+
|
444 |
+
#modules-chart *, #modules-chart *:after, #modules-chart *:before {
|
445 |
+
box-sizing: content-box;
|
446 |
+
margin-bottom: 0;
|
447 |
+
margin-left: 0;
|
448 |
+
margin-right: 0;
|
449 |
+
margin-top: 0;
|
450 |
+
padding-bottom: 0;
|
451 |
+
padding-left: 0;
|
452 |
+
padding-right: 0;
|
453 |
+
padding-top: 0;
|
454 |
+
}
|
455 |
+
|
456 |
+
#modules-chart .inline-group .checkbox, #modules-chart .inline-group .radio {
|
457 |
+
float: left;
|
458 |
+
margin-right: 30px;
|
459 |
+
width: 130px
|
460 |
+
}
|
461 |
+
|
462 |
+
#modules-chart .checkbox, #modules-chart .radio {
|
463 |
+
color: #404040;
|
464 |
+
cursor: pointer;
|
465 |
+
font-size: 13px;
|
466 |
+
line-height: 25px;
|
467 |
+
margin-bottom: 4px;
|
468 |
+
padding-left: 25px;
|
469 |
+
}
|
470 |
+
|
471 |
+
#modules-chart .checkbox input, #modules-chart .radio input {
|
472 |
+
left: -9999px;
|
473 |
+
position: absolute;
|
474 |
+
}
|
475 |
+
|
476 |
+
#modules-chart input[type="checkbox"], .checkbox-inline input[type="checkbox"], .radio input[type="radio"], .radio-inline input[type="radio"] {
|
477 |
+
margin-left: -20px;
|
478 |
+
}
|
479 |
+
|
480 |
+
input[type="checkbox"], input[type="radio"] {
|
481 |
+
line-height: normal;
|
482 |
+
margin-bottom: 0;
|
483 |
+
margin-right: 0;
|
484 |
+
margin-top: 4px;
|
485 |
+
box-sizing: border-box;
|
486 |
+
padding-bottom: 0;
|
487 |
+
padding-left: 0;
|
488 |
+
padding-right: 0;
|
489 |
+
padding-top: 0;
|
490 |
+
}
|
491 |
+
|
492 |
+
#modules-chart .checkbox input:checked + i:after, #modules-chart .radio input:checked + i:after {
|
493 |
+
opacity: 1;
|
494 |
+
}
|
495 |
+
|
496 |
+
#modules-chart .checkbox input:checked + i:after {
|
497 |
+
-moz-font-feature-settings: normal;
|
498 |
+
-moz-font-language-override: normal;
|
499 |
+
-x-system-font: none;
|
500 |
+
content: "";
|
501 |
+
font-family: "Glyphicons Halflings";
|
502 |
+
font-size: 16px;
|
503 |
+
font-size-adjust: none;
|
504 |
+
font-stretch: normal;
|
505 |
+
font-style: normal;
|
506 |
+
font-variant: normal;
|
507 |
+
font-weight: 400;
|
508 |
+
height: 15px;
|
509 |
+
left: 1px;
|
510 |
+
line-height: 19px;
|
511 |
+
text-align: center;
|
512 |
+
top: -1px;
|
513 |
+
width: 15px;
|
514 |
+
color: #3276b1;
|
515 |
+
margin-right: 10px;
|
516 |
+
}
|
517 |
+
|
518 |
+
#modules-chart .checkbox input + i:after {
|
519 |
+
-moz-font-feature-settings: normal;
|
520 |
+
-moz-font-language-override: normal;
|
521 |
+
-x-system-font: none;
|
522 |
+
content: "";
|
523 |
+
font-family: "Glyphicons Halflings";
|
524 |
+
font-size: 16px;
|
525 |
+
font-size-adjust: none;
|
526 |
+
font-stretch: normal;
|
527 |
+
font-style: normal;
|
528 |
+
font-variant: normal;
|
529 |
+
font-weight: 400;
|
530 |
+
height: 15px;
|
531 |
+
left: 1px;
|
532 |
+
line-height: 19px;
|
533 |
+
text-align: center;
|
534 |
+
top: -1px;
|
535 |
+
width: 15px;
|
536 |
+
color: #3276b1;
|
537 |
+
margin-right: 10px;
|
538 |
+
}
|
539 |
+
|
540 |
+
#modules-chart .checkbox input:checked:hover + i:after{
|
541 |
+
content: "";
|
542 |
+
}
|
543 |
+
|
544 |
+
#modules-chart .checkbox input:checked + i, #modules-chart .radio input:checked + i, #modules-chart .toggle input:checked + i {
|
545 |
+
border-bottom-color: #3276b1;
|
546 |
+
border-left-color-ltr-source: physical;
|
547 |
+
border-left-color-rtl-source: physical;
|
548 |
+
border-left-color-value: #3276b1;
|
549 |
+
border-right-color-ltr-source: physical;
|
550 |
+
border-right-color-rtl-source: physical;
|
551 |
+
border-right-color-value: #3276b1;
|
552 |
+
border-top-color: #3276b1
|
553 |
+
}
|
554 |
+
|
555 |
+
#flot-container {
|
556 |
+
height: 235px;
|
557 |
+
width: 100%;
|
558 |
+
}
|
559 |
+
|
560 |
+
#flotTip{
|
561 |
+
padding:3px 5px;
|
562 |
+
background-color:#fff;
|
563 |
+
z-index:9999;
|
564 |
+
color:#333;
|
565 |
+
-webkit-box-shadow:0 1px 8px rgba(0,0,0,.1);
|
566 |
+
-moz-box-shadow:0 1px 8px rgba(0,0,0,.1);
|
567 |
+
box-shadow:0 1px 8px rgba(0,0,0,.1);
|
568 |
+
font-size:14px;
|
569 |
+
border:1px solid #C1C1C1;
|
570 |
+
-moz-border-radius:4px;
|
571 |
+
-khtml-border-radius:4px;
|
572 |
+
-webkit-border-radius:4px;
|
573 |
+
border-radius:4px
|
574 |
+
}
|
575 |
+
|
576 |
+
#flotTip p
|
577 |
+
{
|
578 |
+
text-align: center;
|
579 |
+
margin:0;
|
580 |
+
padding: 0;
|
581 |
+
}
|
582 |
+
|
583 |
+
#flotTip span{
|
584 |
+
color:#38812D;
|
585 |
+
font-weight:700
|
586 |
+
}
|
587 |
+
|
588 |
+
.module-pagination ul{
|
589 |
+
margin-top: 0;
|
590 |
+
margin-bottom: 0
|
591 |
+
}
|
592 |
+
|
593 |
+
.gdbc-settings h3.hndle
|
594 |
+
{
|
595 |
+
padding: 10px 12px 8px !important;
|
596 |
+
}
|
597 |
+
|
598 |
+
.gdbc-settings form table.form-table
|
599 |
+
{
|
600 |
+
width:auto !important;
|
601 |
+
position: relative !important;
|
602 |
+
}
|
603 |
+
|
604 |
+
.gdbc-settings form table.form-table tr
|
605 |
+
{
|
606 |
+
position:relative !important;
|
607 |
+
|
608 |
+
}
|
609 |
+
|
610 |
+
.gdbc-settings form table.form-table th
|
611 |
+
{
|
612 |
+
width: 265px !important;
|
613 |
+
padding: 18px 10px 12px 0 !important;
|
614 |
+
}
|
615 |
+
|
616 |
+
.gdbc-settings form table.form-table td
|
617 |
+
{
|
618 |
+
padding:10px 0;
|
619 |
+
}
|
620 |
+
|
621 |
+
.gdbc-settings form table.form-table td p
|
622 |
+
{
|
623 |
+
left: 0;
|
624 |
+
position: absolute;
|
625 |
+
width: 850px;
|
626 |
+
margin:0 !important;
|
627 |
+
}
|
628 |
+
|
629 |
+
.gdbc-settings form > h3
|
630 |
+
{
|
631 |
+
margin-bottom: 0 !important;
|
632 |
+
padding-bottom: 0 !important;
|
633 |
+
background: #EFEFEF;
|
634 |
+
margin: 0 -12px !important;
|
635 |
+
padding: 8px 12px;
|
636 |
+
border-bottom: 1px solid #cccccc;
|
637 |
+
border-top: 1px solid #cccccc;
|
638 |
+
|
639 |
+
}
|
640 |
+
.gdbc-settings p.submit
|
641 |
+
{
|
642 |
+
padding-top:0 !important;
|
643 |
+
}
|
644 |
+
.gdbc-settings form hr
|
645 |
+
{
|
646 |
+
margin:0 -12px !important;
|
647 |
+
}
|
648 |
+
|
649 |
+
.gdbc-settings div.error, .gdbc-settings div.updated {
|
650 |
+
margin: 15px 0 5px !important;
|
651 |
+
}
|
652 |
+
|
653 |
+
/*.toplevel_page_goodbye-captcha-settings form table.form-table th,*/
|
654 |
+
/*.toplevel_page_goodbye-captcha-settings form table.form-table td,*/
|
655 |
+
/*.goodbye-captcha-new_page_goodbye-captcha-security form table.form-table th,*/
|
656 |
+
/*.goodbye-captcha-new_page_goodbye-captcha-security form table.form-table td*/
|
657 |
+
/*{*/
|
658 |
+
/*padding-bottom: 30px !important;*/
|
659 |
+
/*}*/
|
660 |
+
|
661 |
+
.gdbc-settings form table.form-table td, .gdbc-settings form table.form-table th
|
662 |
+
{
|
663 |
+
padding-bottom: 30px !important;
|
664 |
+
}
|
665 |
+
.gdbc-settings #normal-sortables:empty, .gdbc-settings #advanced-sortables:empty, .gdbc-settings #bottom-sortables:empty
|
666 |
+
{
|
667 |
+
display:none;
|
668 |
+
}
|
669 |
+
|
670 |
+
.text-center
|
671 |
+
{
|
672 |
+
margin-top: 10px;
|
673 |
+
text-align: center !important;
|
674 |
+
}
|
675 |
+
|
676 |
+
.btn-label
|
677 |
+
{
|
678 |
+
background: none repeat scroll 0 0 rgba(0, 0, 0, 0.15);
|
679 |
+
border-radius: 3px 0 0 3px;
|
680 |
+
display: inline-block;
|
681 |
+
left: -12px;
|
682 |
+
padding: 6px 12px;
|
683 |
+
position: relative;
|
684 |
+
}
|
685 |
+
|
686 |
+
.btn {
|
687 |
+
border-radius: 2px;
|
688 |
+
box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.05) inset;
|
689 |
+
}
|
690 |
+
|
691 |
+
a.btn-rate-gdbc
|
692 |
+
{
|
693 |
+
display:none;
|
694 |
+
}
|
695 |
+
|
696 |
+
a.btn-rate-gdbc:hover i.glyphicon
|
697 |
+
{
|
698 |
+
color: #ffff00;
|
699 |
+
}
|
700 |
+
|
701 |
+
.btn-labeled {
|
702 |
+
padding-bottom: 0;
|
703 |
+
padding-top: 0;
|
704 |
+
}
|
705 |
+
|
706 |
+
div.gdbcwidget ul.pagination a:hover
|
707 |
+
{
|
708 |
+
cursor: pointer;
|
709 |
+
}
|
710 |
+
|
711 |
+
#gdbc-barchart-holder div.morris-hover.morris-default-style p
|
712 |
+
{
|
713 |
+
font-weight: bold;
|
714 |
+
margin:0 !important;
|
715 |
+
}
|
716 |
+
#gdbc-barchart-holder div.morris-hover.morris-default-style p span
|
717 |
+
{
|
718 |
+
color: #972d2c;
|
719 |
+
}
|
720 |
+
|
721 |
+
.gdbc-settings .mch-right-side-holder h3.hndle
|
722 |
+
{
|
723 |
+
padding: 0 0 0 10px !important;
|
724 |
+
}
|
725 |
+
|
726 |
+
|
727 |
+
.gdbc-settings .mch-right-side-holder h3.hndle span, .gdbc-settings .mch-right-side-holder h2.hndle span
|
728 |
+
{
|
729 |
+
display:inline-block;
|
730 |
+
padding: 10px 0px 8px 22px !important;
|
731 |
+
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAyJJREFUOI1tkltMVHcQxr///5y9wYrsYvDAohSoGNDEqtDa1htirKttUAMxqfX2VJNWWy9JH9qGpDGpaRse7FtNNAaMrbZ2o42IUiwUUOMt1W5NINTCuixZ2MpyWXb37DlfH1oMUCeZZCaZ7zfJNyMwI2prKW/2dHqHR5Ibw0Px1RMJatludcWDaxsez5wFAHVqs+fDu+vOtFz9LBSOv54yCKsiYJWIpuwW43liABCTxY4Dd/b5moJfGwZV1yw1WJzvPPlSedb3EzZrf//C4tjGNXAsEhBwYqxCiPg0ysdf+GvSin20FflY7m1uOFjrdwPAe91cu8rPE/PvsDu3k1FPB0fW/8ad08QXrgzm5L18OWQp/JHed9rrAaAuQMdrfp7NaCftrWRWO6ndYEy7wfH1j7hrmgdXf3nydiic0OZp9uDe3aXvNzYATVGcvT2EqgwVoyvd+NzjwEVLAhElCWOBipHmqYRl3uY2teACq/Z21gHAwcesSmsltQ6OH+ph5fOto5xMNTgQX2y3KcjOtP0KAL+PY3MKQL4dTXVF4udJye4Dt4/W+/q2OtMtlPInCkETEFHVJAUAqBbTAIAUoYh/z5OculOxily7VSmxWiQJSlKA5ITM09K64gkTkWHjFQAoSUeLABBI4I1Pe7l8EjDPk3Vo5SpPfsUKrWBTZc4WKQVIJGS+x+EDgft/RLefuk57TQG+K3ehLZxE5oknuFT9iLv2dzMPG16IvXqyLHj+m7K+wvkZvaZJAIAsK81umDvH9vdf/bGiy9/eOlYhRMrrQHWJCy2jBnIaB3H6XBhd9WPoOXMPf27v4ptJh0hK/gf45PCLgX07C4+oisDF5oEP1my7/lWiAU8fLBGVNTnYsWA2rgk7JmIKsscATwywKZD6/155856Oj9puRY7puom5buvDRcXO40uXaY2h2e6RgJmaU+oSszIzhNSHGIr4gwt/uBRsTRkcfgYAgOp3b1bdfTh8NDQYX0wTcDokJBmxSsSEKk0CME2oVERaUqeL5Og0AAAc+XIgPdQb2NrTO/pWXyi+JKkbubrOGXOklFIH8PQfWXdiApL00zIAAAAASUVORK5CYII=') 0 center no-repeat;
|
732 |
+
}
|
733 |
+
.gdbc-settings .mch-right-side-holder h2.hndle span
|
734 |
+
{
|
735 |
+
padding:0 0 0 22px !important;
|
736 |
+
}
|
737 |
+
|
738 |
+
.gdbc-settings .metabox-holder h3 {
|
739 |
+
font-size: 14px;
|
740 |
+
line-height: 1.4;
|
741 |
+
margin: 0;
|
742 |
+
padding: 8px 12px;
|
743 |
+
}
|
744 |
+
|
745 |
+
/*#gdbc-help-metabox h3.hndle span*/
|
746 |
+
/*{*/
|
747 |
+
/*border-left: 4px solid #428bca;*/
|
748 |
+
/*}*/
|
749 |
+
|
750 |
+
|
751 |
+
#gdbc-help-metabox .logo-help {
|
752 |
+
width: 70%;
|
753 |
+
display:block;
|
754 |
+
margin: 0 auto;
|
755 |
+
padding:10px;
|
756 |
+
}
|
757 |
+
|
758 |
+
#gdbc-help-metabox .inside
|
759 |
+
{
|
760 |
+
margin:0;
|
761 |
+
background-color: #f9f9f9 !important;
|
762 |
+
}
|
763 |
+
|
764 |
+
#gdbc-help-metabox .contact-help {
|
765 |
+
display:block;
|
766 |
+
text-align: center;
|
767 |
+
border-top: 1px solid #ccc;
|
768 |
+
padding-top:10px;
|
769 |
+
}
|
770 |
+
|
771 |
+
|
772 |
+
div.mch-meta-notice
|
773 |
+
{}
|
774 |
+
|
775 |
+
div.mch-meta-notice-info
|
776 |
+
{
|
777 |
+
border-left:4px solid #428bca; padding:3px 8px; text-align: justify;
|
778 |
+
}
|
779 |
+
|
780 |
+
div.mch-meta-notice-warning
|
781 |
+
{
|
782 |
+
border-left:4px solid #ffba00; background:#fcf8e3; padding:3px 8px; text-align: center
|
783 |
+
}
|
784 |
+
|
785 |
+
|
786 |
+
/*div.mch-plugin-notice*/
|
787 |
+
/*{*/
|
788 |
+
|
789 |
+
/*}*/
|
790 |
+
|
791 |
+
/*div.mch-plugin-notice p*/
|
792 |
+
/*{*/
|
793 |
+
|
794 |
+
/*}*/
|
795 |
+
|
796 |
+
.report-spinner {
|
797 |
+
position: absolute;
|
798 |
+
left: 50%;
|
799 |
+
top: 50%;
|
800 |
+
height:40px;
|
801 |
+
width:40px;
|
802 |
+
margin:0px auto;
|
803 |
+
-webkit-animation: rotation .6s infinite linear;
|
804 |
+
-moz-animation: rotation .6s infinite linear;
|
805 |
+
-o-animation: rotation .6s infinite linear;
|
806 |
+
animation: rotation .6s infinite linear;
|
807 |
+
border-left:6px solid rgba(0,174,239,.15);
|
808 |
+
border-right:6px solid rgba(0,174,239,.15);
|
809 |
+
border-bottom:6px solid rgba(0,174,239,.15);
|
810 |
+
border-top:6px solid rgba(0,174,239,.8);
|
811 |
+
border-radius:100%;
|
812 |
+
}
|
813 |
+
|
814 |
+
@-webkit-keyframes rotation {
|
815 |
+
from {-webkit-transform: rotate(0deg);}
|
816 |
+
to {-webkit-transform: rotate(359deg);}
|
817 |
+
}
|
818 |
+
@-moz-keyframes rotation {
|
819 |
+
from {-moz-transform: rotate(0deg);}
|
820 |
+
to {-moz-transform: rotate(359deg);}
|
821 |
+
}
|
822 |
+
@-o-keyframes rotation {
|
823 |
+
from {-o-transform: rotate(0deg);}
|
824 |
+
to {-o-transform: rotate(359deg);}
|
825 |
+
}
|
826 |
+
@keyframes rotation {
|
827 |
+
from {transform: rotate(0deg);}
|
828 |
+
to {transform: rotate(359deg);}
|
829 |
+
}
|
830 |
+
|
831 |
+
|
832 |
+
|
{assets → 2.0/assets}/admin/styles/morris.css
RENAMED
File without changes
|
{assets → 2.0/assets}/public/scripts/gdbc-client.js.php
RENAMED
File without changes
|
{assets → 2.0/assets}/public/scripts/gdbc-public.js
RENAMED
File without changes
|
{assets → 2.0/assets}/public/scripts/index.php
RENAMED
File without changes
|
2.0/engine/GdbcAjaxController.php
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GdbcAjaxController
|
21 |
+
{
|
22 |
+
CONST ACTION_RETRIEVE_TOKEN = 'gdbcRetrieveToken';
|
23 |
+
CONST AJAX_NONCE_VALUE = __CLASS__;
|
24 |
+
|
25 |
+
public static function processRequest()
|
26 |
+
{
|
27 |
+
if( ! GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_SETTINGS) )
|
28 |
+
return;
|
29 |
+
|
30 |
+
if(self::isPublicGdbcAjaxRequest() ) {
|
31 |
+
|
32 |
+
self::sendAjaxHeaders();
|
33 |
+
|
34 |
+
if ( ! self::clientCanRetrieveToken() ) {
|
35 |
+
wp_send_json_error();
|
36 |
+
}
|
37 |
+
|
38 |
+
$arrTokenData = GdbcRequestController::getEncryptedToken();
|
39 |
+
|
40 |
+
wp_send_json_success( $arrTokenData );
|
41 |
+
|
42 |
+
exit;
|
43 |
+
}
|
44 |
+
|
45 |
+
if( ! did_action ('plugins_loaded') )
|
46 |
+
return;
|
47 |
+
|
48 |
+
foreach(array(
|
49 |
+
|
50 |
+
GdbcModulesController::MODULE_MAIL_CHIMP_FOR_WP,
|
51 |
+
GdbcModulesController::MODULE_ZM_ALR,
|
52 |
+
GdbcModulesController::MODULE_NINJA_FORMS,
|
53 |
+
GdbcModulesController::MODULE_USER_PRO,
|
54 |
+
|
55 |
+
) as $moduleName){
|
56 |
+
|
57 |
+
if(null === ($publicModuleInstance = GdbcModulesController::getPublicModuleInstance($moduleName)))
|
58 |
+
continue;
|
59 |
+
|
60 |
+
$publicModuleInstance->registerAttachedHooks();
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
if(self::isAdminAjaxRequestValid())
|
67 |
+
{
|
68 |
+
$arrAjaxAdminReportsActions = array(
|
69 |
+
'retrieveInitialDashboardData',
|
70 |
+
'retrieveLatestAttemptsTable',
|
71 |
+
'retrieveTotalAttemptsPerModule',
|
72 |
+
'retrieveDetailedAttemptsForChart',
|
73 |
+
'retrieveDetailedAttemptsPerModule',
|
74 |
+
'retrieveFormattedBlockedContent',
|
75 |
+
'retrieveAttemptsPerModuleAndSection',
|
76 |
+
'retrieveAttemptsPerClientIp',
|
77 |
+
'manageClientIpAddress',
|
78 |
+
);
|
79 |
+
|
80 |
+
foreach ($arrAjaxAdminReportsActions as $adminAjaxActionRequest) {
|
81 |
+
add_action('wp_ajax_' . $adminAjaxActionRequest, array(GdbcReportsAdminModule::getInstance(), $adminAjaxActionRequest));
|
82 |
+
}
|
83 |
+
|
84 |
+
foreach(GoodByeCaptchaAdmin::getAdminRegisteredNotices() as $adminNotice){
|
85 |
+
if( !($adminNotice instanceof GdbcAdminNotice) || !$adminNotice->isDismissible())
|
86 |
+
continue;
|
87 |
+
|
88 |
+
add_action('wp_ajax_gdbc-dismiss-' . $adminNotice->getFormattedNoticeKey(), array($adminNotice, 'dismiss'));
|
89 |
+
}
|
90 |
+
|
91 |
+
}
|
92 |
+
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
private static function clientCanRetrieveToken()
|
97 |
+
{
|
98 |
+
$settingsModuleInstance = GdbcModulesController::getPublicModuleInstance(GdbcModulesController::MODULE_SETTINGS);
|
99 |
+
if(null === $settingsModuleInstance)
|
100 |
+
return false;
|
101 |
+
|
102 |
+
if(null === ($hiddenInputName = $settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_HIDDEN_INPUT_NAME)))
|
103 |
+
return false;
|
104 |
+
|
105 |
+
if(empty($_POST[$hiddenInputName]))
|
106 |
+
return false;
|
107 |
+
|
108 |
+
if(!isset($_SERVER['HTTP_ACCEPT']) || false === stripos($_SERVER['HTTP_ACCEPT'], 'json'))
|
109 |
+
return false;
|
110 |
+
|
111 |
+
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (0 !== strcasecmp($_SERVER['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest')))
|
112 |
+
return false;
|
113 |
+
|
114 |
+
require_once( ABSPATH . WPINC . '/pluggable.php' );
|
115 |
+
|
116 |
+
( !defined('LOGGED_IN_COOKIE') && function_exists('wp_cookie_constants') ) ? wp_cookie_constants() : null;
|
117 |
+
|
118 |
+
if(!GoodByeCaptchaUtils::isValidReferer())
|
119 |
+
return false;
|
120 |
+
|
121 |
+
if(false === wp_verify_nonce($_POST[$hiddenInputName], __CLASS__))
|
122 |
+
return false;
|
123 |
+
|
124 |
+
|
125 |
+
if(GdbcIPUtils::isIpAddressBlocked(GdbcIPUtils::getClientIpAddress()))
|
126 |
+
return false;
|
127 |
+
|
128 |
+
return true;
|
129 |
+
|
130 |
+
}
|
131 |
+
|
132 |
+
|
133 |
+
private static function sendAjaxHeaders()
|
134 |
+
{
|
135 |
+
wp_magic_quotes();
|
136 |
+
send_origin_headers();
|
137 |
+
|
138 |
+
@header('X-Robots-Tag: noindex' );
|
139 |
+
|
140 |
+
send_nosniff_header();
|
141 |
+
nocache_headers();
|
142 |
+
|
143 |
+
@header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
144 |
+
@header('Content-Type: application/json; charset=' . get_option( 'blog_charset' ));
|
145 |
+
}
|
146 |
+
|
147 |
+
private static function isPublicGdbcAjaxRequest()
|
148 |
+
{
|
149 |
+
if(empty($_POST['browserInfo']) || empty($_POST['action']) || (self::ACTION_RETRIEVE_TOKEN !== $_POST['action']))
|
150 |
+
return false;
|
151 |
+
|
152 |
+
return true;
|
153 |
+
}
|
154 |
+
|
155 |
+
public static function getAjaxNonce()
|
156 |
+
{
|
157 |
+
require_once( ABSPATH . WPINC . '/pluggable.php' );
|
158 |
+
|
159 |
+
return wp_create_nonce(__CLASS__);
|
160 |
+
}
|
161 |
+
|
162 |
+
public static function isAdminAjaxRequestValid()
|
163 |
+
{
|
164 |
+
return check_ajax_referer(self::AJAX_NONCE_VALUE, 'ajaxRequestNonce', false);
|
165 |
+
}
|
166 |
+
}
|
2.0/engine/GdbcBruteGuardian.php
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GdbcBruteGuardian
|
21 |
+
{
|
22 |
+
|
23 |
+
private static $arrSecurityDirectoryFiles = array(
|
24 |
+
'.htaccess' => 'deny from all',
|
25 |
+
'index.php' => '<?php',
|
26 |
+
'index.html' => '',
|
27 |
+
);
|
28 |
+
|
29 |
+
private static $SITE_UNDER_ATTACK_FLAG = 'gdbc-under-attack-detected';
|
30 |
+
private static $SITE_ATTACK_WARNING_FLAG = 'gdbc-suspicious-ips-detected';
|
31 |
+
|
32 |
+
public static function startGuarding()
|
33 |
+
{
|
34 |
+
if( !GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_SETTINGS) )
|
35 |
+
return;
|
36 |
+
|
37 |
+
if( empty($_POST) )
|
38 |
+
return;
|
39 |
+
|
40 |
+
$loginAttemptsHits = 0;
|
41 |
+
$arrLatestLoginAttempts = GdbcDbAccessController::getLatestLoginAttempts(60, false);
|
42 |
+
foreach($arrLatestLoginAttempts as $index => $loginAttempt){
|
43 |
+
$loginAttemptsHits += $loginAttempt->Hits;
|
44 |
+
$arrLatestLoginAttempts[$loginAttempt->ClientIp] = $loginAttempt->Hits;
|
45 |
+
unset($arrLatestLoginAttempts[$index]);
|
46 |
+
}
|
47 |
+
|
48 |
+
switch(true)
|
49 |
+
{
|
50 |
+
case ($loginAttemptsHits > 35 && !self::isSiteUnderAttack()) :
|
51 |
+
|
52 |
+
self::triggerSiteUnderAttack();
|
53 |
+
|
54 |
+
GdbcNotificationsController::sendBruteForceAttackDetectedEmailNotification($arrLatestLoginAttempts);
|
55 |
+
|
56 |
+
break;
|
57 |
+
|
58 |
+
case ($loginAttemptsHits > 25 && !self::isSiteUnderAttack()) :
|
59 |
+
|
60 |
+
break;
|
61 |
+
|
62 |
+
|
63 |
+
case ($loginAttemptsHits < 15) :
|
64 |
+
|
65 |
+
if(self::isSiteUnderAttack()){
|
66 |
+
self::unTriggerSiteUnderAttack();
|
67 |
+
}
|
68 |
+
|
69 |
+
break;
|
70 |
+
}
|
71 |
+
|
72 |
+
|
73 |
+
if(self::isSiteUnderAttack() && GdbcBruteForcePublicModule::getInstance()->getOption(GdbcBruteForceAdminModule::OPTION_AUTO_BLOCK_IP)) {
|
74 |
+
if( isset($arrLatestLoginAttempts[GdbcIPUtils::getClientIpAddress()]) && $arrLatestLoginAttempts[GdbcIPUtils::getClientIpAddress()] > 4 && (!GdbcIPUtils::isClientIpBlackListed()) ){
|
75 |
+
GdbcBlackListedIpsAdminModule::getInstance()->registerBlackListedIp(GdbcIPUtils::getClientIpAddress());
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
private static function isSiteUnderAttack()
|
83 |
+
{
|
84 |
+
static $siteUnderAttack = null;
|
85 |
+
if(null !== $siteUnderAttack)
|
86 |
+
return $siteUnderAttack;
|
87 |
+
|
88 |
+
return $siteUnderAttack = self::flagExists(self::$SITE_UNDER_ATTACK_FLAG);
|
89 |
+
}
|
90 |
+
|
91 |
+
private static function triggerSiteUnderAttack()
|
92 |
+
{
|
93 |
+
self::setSiteFlag(self::$SITE_UNDER_ATTACK_FLAG, true);
|
94 |
+
|
95 |
+
GdbcSettingsAdminModule::getInstance()->saveSecuredOptions(true);
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
private static function unTriggerSiteUnderAttack()
|
100 |
+
{
|
101 |
+
self::setSiteFlag(self::$SITE_UNDER_ATTACK_FLAG, false);
|
102 |
+
}
|
103 |
+
|
104 |
+
private static function flagExists($flagName)
|
105 |
+
{
|
106 |
+
$cacheHolder = GoodByeCaptchaUtils::getAvailableCacheStorage(self::getBaseCacheDirectoryPath());
|
107 |
+
if(null === $cacheHolder)
|
108 |
+
return 0;
|
109 |
+
|
110 |
+
return $cacheHolder->has($flagName);
|
111 |
+
}
|
112 |
+
|
113 |
+
private static function setSiteFlag($flagName, $flagBooleanValue)
|
114 |
+
{
|
115 |
+
$cacheHolder = GoodByeCaptchaUtils::getAvailableCacheStorage(self::getBaseCacheDirectoryPath());
|
116 |
+
if(null === $cacheHolder)
|
117 |
+
return ;
|
118 |
+
|
119 |
+
if(false === $flagBooleanValue){
|
120 |
+
return $cacheHolder->delete($flagName);
|
121 |
+
}
|
122 |
+
|
123 |
+
if($cacheHolder->getCacheStorage() instanceof MchGdbcCacheFileStorage)
|
124 |
+
{
|
125 |
+
foreach(self::$arrSecurityDirectoryFiles as $fileName => $fileContent)
|
126 |
+
{
|
127 |
+
$filePath = self::getBaseCacheDirectoryPath() . DIRECTORY_SEPARATOR . $fileName;
|
128 |
+
if(MchGdbcWpUtils::fileExists($filePath))
|
129 |
+
break;
|
130 |
+
|
131 |
+
MchGdbcWpUtils::writeContentToFile($fileContent, $filePath, false);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
$cacheHolder->write($flagName, MchGdbcHttpRequest::getServerRequestTime(false));
|
136 |
+
}
|
137 |
+
|
138 |
+
private static function getBaseCacheDirectoryPath()
|
139 |
+
{
|
140 |
+
static $cacheDirectoryPath = false;
|
141 |
+
if(false !== $cacheDirectoryPath)
|
142 |
+
return $cacheDirectoryPath;
|
143 |
+
|
144 |
+
$cacheDirectoryPath = GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_CACHE_DIR_PATH);
|
145 |
+
if(!empty($cacheDirectoryPath)){
|
146 |
+
$cacheDirectoryPath .= DIRECTORY_SEPARATOR . GoodByeCaptcha::PLUGIN_SLUG . DIRECTORY_SEPARATOR . get_current_blog_id();
|
147 |
+
if(MchGdbcWpUtils::isDirectoryUsable($cacheDirectoryPath, true)){
|
148 |
+
return $cacheDirectoryPath;
|
149 |
+
}
|
150 |
+
}
|
151 |
+
|
152 |
+
$cacheDirectoryPath = MchGdbcWpUtils::getDirectoryPathForCache();
|
153 |
+
if(null === $cacheDirectoryPath)
|
154 |
+
return null;
|
155 |
+
|
156 |
+
$cacheDirectoryPath .= DIRECTORY_SEPARATOR . GoodByeCaptcha::PLUGIN_SLUG . DIRECTORY_SEPARATOR . get_current_blog_id();
|
157 |
+
if(! MchGdbcWpUtils::isDirectoryUsable($cacheDirectoryPath, true) ) {
|
158 |
+
return $cacheDirectoryPath = null;
|
159 |
+
}
|
160 |
+
|
161 |
+
GdbcSettingsAdminModule::getInstance()->saveOption(GdbcSettingsAdminModule::OPTION_CACHE_DIR_PATH, MchGdbcWpUtils::getDirectoryPathForCache());
|
162 |
+
|
163 |
+
return $cacheDirectoryPath;
|
164 |
+
}
|
165 |
+
|
166 |
+
public static function logRejectedAttempt(GdbcAttemptEntity $attemptEntity)
|
167 |
+
{
|
168 |
+
if( ((int)GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_MAX_LOGS_DAYS)) < 1 ) //logs are NOT enabled
|
169 |
+
return;
|
170 |
+
|
171 |
+
$attemptEntity->SiteId = get_current_blog_id();
|
172 |
+
$attemptEntity->CreatedDate = MchGdbcHttpRequest::getServerRequestTime();
|
173 |
+
$attemptEntity->ClientIp = GdbcIPUtils::getClientIpAddress();
|
174 |
+
|
175 |
+
|
176 |
+
if( ((int)GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_BLOCKED_CONTENT_LOG_DAYS)) < 1 ) //blocked content logs are NOT enabled
|
177 |
+
$attemptEntity->Notes = null;
|
178 |
+
|
179 |
+
|
180 |
+
GdbcDbAccessController::registerAttempt( $attemptEntity );
|
181 |
+
|
182 |
+
// if(self::isSiteUnderAttack() && GoodByeCaptchaUtils::isLoginAttemptEntity($attemptEntity) && ( !GdbcIPUtils::isClientIpWhiteListed() )){
|
183 |
+
// self::registerClientIpBruteForceRequest();
|
184 |
+
// }
|
185 |
+
|
186 |
+
}
|
187 |
+
|
188 |
+
private static function getIpAddressDirPath($flagName, $ipAddress)
|
189 |
+
{
|
190 |
+
if (null === self::getBaseCacheDirectoryPath())
|
191 |
+
return null;
|
192 |
+
|
193 |
+
$subDirectoryName = null;
|
194 |
+
switch ($flagName)
|
195 |
+
{
|
196 |
+
case self::$SITE_UNDER_ATTACK_FLAG : $subDirectoryName = 'brute-ips'; break;
|
197 |
+
case self::$SITE_ATTACK_WARNING_FLAG : $subDirectoryName = 'suspicious-ips'; break;
|
198 |
+
}
|
199 |
+
|
200 |
+
return self::getBaseCacheDirectoryPath() . DIRECTORY_SEPARATOR . $subDirectoryName . DIRECTORY_SEPARATOR . $ipAddress;
|
201 |
+
}
|
202 |
+
|
203 |
+
private static function isClientIpBruteForcing()
|
204 |
+
{
|
205 |
+
return @is_dir(self::getIpAddressDirPath(self::$SITE_UNDER_ATTACK_FLAG, GdbcIPUtils::getClientIpAddress()));
|
206 |
+
}
|
207 |
+
|
208 |
+
private static function registerClientIpBruteForceRequest()
|
209 |
+
{
|
210 |
+
if(self::isClientIpBruteForcing())
|
211 |
+
{
|
212 |
+
MchGdbcWpUtils::writeContentToFile(null, self::getIpAddressDirPath(self::$SITE_UNDER_ATTACK_FLAG, GdbcIPUtils::getClientIpAddress()) . DIRECTORY_SEPARATOR . MchGdbcHttpRequest::getServerRequestTime(true) . '.gdbc', false);
|
213 |
+
return;
|
214 |
+
}
|
215 |
+
|
216 |
+
if( ! MchGdbcWpUtils::isDirectoryUsable(self::getIpAddressDirPath(self::$SITE_UNDER_ATTACK_FLAG, GdbcIPUtils::getClientIpAddress()), true) )
|
217 |
+
return;
|
218 |
+
|
219 |
+
foreach(self::$arrSecurityDirectoryFiles as $fileName => $fileContent){
|
220 |
+
$filePath = self::getIpAddressDirPath(self::$SITE_UNDER_ATTACK_FLAG, GdbcIPUtils::getClientIpAddress()) . DIRECTORY_SEPARATOR . $fileName;
|
221 |
+
MchGdbcWpUtils::writeContentToFile($fileContent, $filePath, false);
|
222 |
+
}
|
223 |
+
|
224 |
+
MchGdbcWpUtils::writeContentToFile(null, self::getIpAddressDirPath(self::$SITE_UNDER_ATTACK_FLAG, GdbcIPUtils::getClientIpAddress()) . DIRECTORY_SEPARATOR . MchGdbcHttpRequest::getServerRequestTime(true) . '.gdbc', false);
|
225 |
+
}
|
226 |
+
|
227 |
+
private function __construct()
|
228 |
+
{}
|
229 |
+
|
230 |
+
}
|
2.0/engine/GdbcIPUtils.php
ADDED
@@ -0,0 +1,404 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2015 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class GdbcIPUtils
|
22 |
+
{
|
23 |
+
|
24 |
+
public static function getClientIpAddress()
|
25 |
+
{
|
26 |
+
return MchGdbcHttpRequest::getClientIp(array());
|
27 |
+
}
|
28 |
+
|
29 |
+
public static function isClientIpBlackListed()
|
30 |
+
{
|
31 |
+
return self::isIpBlackListed(self::getClientIpAddress());
|
32 |
+
}
|
33 |
+
|
34 |
+
public static function isClientIpWhiteListed()
|
35 |
+
{
|
36 |
+
return self::isIpWhiteListed(self::getClientIpAddress());
|
37 |
+
}
|
38 |
+
|
39 |
+
public static function isIpWhiteListed($ipAddress)
|
40 |
+
{
|
41 |
+
static $arrWhiteVerifiedIPs = array();
|
42 |
+
if(isset($arrWhiteVerifiedIPs[$ipAddress]))
|
43 |
+
return $arrWhiteVerifiedIPs[$ipAddress];
|
44 |
+
|
45 |
+
if( self::isIpInFormattedRanges($ipAddress, GdbcWhiteListedIpsPublicModule::getInstance()->getOption(GdbcWhiteListedIpsAdminModule::OPTION_WHITE_LISTED_IPS)) )
|
46 |
+
$arrWhiteVerifiedIPs[$ipAddress] = true;
|
47 |
+
|
48 |
+
return isset($arrWhiteVerifiedIPs[$ipAddress]);
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
public static function isIpBlackListed($ipAddress)
|
53 |
+
{
|
54 |
+
static $arrBlackVerifiedIPs = array();
|
55 |
+
if(isset($arrBlackVerifiedIPs[$ipAddress]))
|
56 |
+
return $arrBlackVerifiedIPs[$ipAddress];
|
57 |
+
|
58 |
+
if(self::isIpInFormattedRanges($ipAddress, GdbcBlackListedIpsPublicModule::getInstance()->getOption(GdbcBlackListedIpsAdminModule::OPTION_BLACK_LISTED_IPS)))
|
59 |
+
$arrBlackVerifiedIPs[$ipAddress] = true;
|
60 |
+
|
61 |
+
return isset($arrBlackVerifiedIPs[$ipAddress]);
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
public static function isIpAddressBlocked($ipAddress)
|
66 |
+
{
|
67 |
+
if(self::isIpBlackListed($ipAddress))
|
68 |
+
return true;
|
69 |
+
|
70 |
+
if(null === ($bruteForceModuleInstance = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::MODULE_BRUTE_FORCE)))
|
71 |
+
return false;
|
72 |
+
|
73 |
+
if($bruteForceModuleInstance->getOption(GdbcBruteForceAdminModule::OPTION_BLOCK_WEB_ATTACKERS) && MchGdbcUnTrustedIPRanges::isAttachingHostIP($ipAddress))
|
74 |
+
return true;
|
75 |
+
|
76 |
+
if($bruteForceModuleInstance->getOption(GdbcBruteForceAdminModule::OPTION_BLOCK_ANONYMOUS_PROXY) && MchGdbcUnTrustedIPRanges::isAnonymizerProxyIP($ipAddress))
|
77 |
+
return true;
|
78 |
+
|
79 |
+
return false;
|
80 |
+
|
81 |
+
}
|
82 |
+
|
83 |
+
public static function isClientIpProxyAnonymizer($checkBruteForceModuleSettings = true)
|
84 |
+
{
|
85 |
+
static $isAnonymizer = null;
|
86 |
+
if(null !== $isAnonymizer)
|
87 |
+
return $isAnonymizer;
|
88 |
+
|
89 |
+
$bruteForceModuleInstance = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::MODULE_BRUTE_FORCE);
|
90 |
+
if(null === $bruteForceModuleInstance)
|
91 |
+
return $isAnonymizer = false;
|
92 |
+
|
93 |
+
if( $checkBruteForceModuleSettings && (! $bruteForceModuleInstance->getOption(GdbcBruteForceAdminModule::OPTION_BLOCK_ANONYMOUS_PROXY)) )
|
94 |
+
return $isAnonymizer = false;
|
95 |
+
|
96 |
+
return $isAnonymizer = MchGdbcUnTrustedIPRanges::isAnonymizerProxyIP(GdbcIPUtils::getClientIpAddress());
|
97 |
+
}
|
98 |
+
|
99 |
+
public static function isClientIpWebAttacker($checkBruteForceModuleSettings = true)
|
100 |
+
{
|
101 |
+
static $isAttacker = null;
|
102 |
+
if(null !== $isAttacker)
|
103 |
+
return $isAttacker;
|
104 |
+
|
105 |
+
$bruteForceModuleInstance = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::MODULE_BRUTE_FORCE);
|
106 |
+
if(null === $bruteForceModuleInstance)
|
107 |
+
return $isAttacker = false;
|
108 |
+
|
109 |
+
if( $checkBruteForceModuleSettings && (! $bruteForceModuleInstance->getOption(GdbcBruteForceAdminModule::OPTION_BLOCK_WEB_ATTACKERS)) )
|
110 |
+
return $isAttacker = false;
|
111 |
+
|
112 |
+
return $isAttacker = MchGdbcUnTrustedIPRanges::isAttachingHostIP(GdbcIPUtils::getClientIpAddress());
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
public static function isIpProxyAnonymizer($ipAddress)
|
117 |
+
{
|
118 |
+
return MchGdbcUnTrustedIPRanges::isAnonymizerProxyIP($ipAddress);
|
119 |
+
}
|
120 |
+
|
121 |
+
public static function isIpWebAttacker($ipAddress)
|
122 |
+
{
|
123 |
+
return MchGdbcUnTrustedIPRanges::isAttachingHostIP($ipAddress);
|
124 |
+
}
|
125 |
+
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
public static function isIpInFormattedRanges($ipAddress, $arrFormattedRanges)
|
131 |
+
{
|
132 |
+
$ipVersion = MchGdbcIPUtils::getIpAddressVersion($ipAddress);
|
133 |
+
|
134 |
+
if( -1 === $ipVersion )
|
135 |
+
return false;
|
136 |
+
|
137 |
+
if(empty($arrFormattedRanges[$ipVersion]))
|
138 |
+
return false;
|
139 |
+
|
140 |
+
|
141 |
+
if($ipVersion === MchGdbcIPUtils::IP_VERSION_6)
|
142 |
+
{
|
143 |
+
$ipAddress = MchGdbcIPUtils::compressIPV6($ipAddress);
|
144 |
+
if(isset($arrFormattedRanges[$ipVersion][$ipAddress]))
|
145 |
+
return true;
|
146 |
+
|
147 |
+
foreach($arrFormattedRanges[$ipVersion] as $blockedIPRange => $value)
|
148 |
+
{
|
149 |
+
if(false === strpos($blockedIPRange, '/'))
|
150 |
+
continue;
|
151 |
+
|
152 |
+
if( ! MchGdbcIPUtils::isIpInCIDRRange($ipAddress, $blockedIPRange, MchGdbcIPUtils::IP_VERSION_6, true) )
|
153 |
+
continue;
|
154 |
+
|
155 |
+
return true;
|
156 |
+
}
|
157 |
+
|
158 |
+
return false;
|
159 |
+
}
|
160 |
+
|
161 |
+
$ipNumber = MchGdbcIPUtils::ipAddressToNumber($ipAddress, MchGdbcIPUtils::IP_VERSION_4);
|
162 |
+
if(isset($arrFormattedRanges[$ipVersion][$ipNumber])) // single IP
|
163 |
+
return true;
|
164 |
+
|
165 |
+
foreach($arrFormattedRanges[$ipVersion] as $minIpNumber => $maxIpNumber)
|
166 |
+
{
|
167 |
+
if( (1 !== $maxIpNumber) && ($minIpNumber <= $ipNumber) && ($ipNumber <= $maxIpNumber) )
|
168 |
+
return true;
|
169 |
+
}
|
170 |
+
|
171 |
+
return false;
|
172 |
+
|
173 |
+
}
|
174 |
+
|
175 |
+
|
176 |
+
public static function removeIpFromFormattedRange($ipAddress, $arrFormattedRange)
|
177 |
+
{
|
178 |
+
$ipVersion = MchGdbcIPUtils::getIpAddressVersion($ipAddress);
|
179 |
+
if(-1 === $ipVersion)
|
180 |
+
return $arrFormattedRange;
|
181 |
+
|
182 |
+
if($ipVersion === MchGdbcIPUtils::IP_VERSION_6)
|
183 |
+
{
|
184 |
+
unset($arrFormattedRange[MchGdbcIPUtils::compressIPV6($ipAddress)]);
|
185 |
+
return $arrFormattedRange;
|
186 |
+
}
|
187 |
+
|
188 |
+
$ipNumber = MchGdbcIPUtils::ipAddressToNumber($ipAddress, $ipVersion);
|
189 |
+
if(isset($arrFormattedRange[$ipNumber]) && 1 == $arrFormattedRange[$ipNumber])
|
190 |
+
{
|
191 |
+
unset($arrFormattedRange[$ipNumber]);
|
192 |
+
return $arrFormattedRange;
|
193 |
+
}
|
194 |
+
|
195 |
+
$arrSingleIPs = array();
|
196 |
+
$arrNewRanges = array();
|
197 |
+
foreach($arrFormattedRange as $minValue => $maxValue)
|
198 |
+
{
|
199 |
+
if(1 == $maxValue)
|
200 |
+
{
|
201 |
+
$arrSingleIPs[$minValue] = $maxValue;
|
202 |
+
continue;
|
203 |
+
}
|
204 |
+
|
205 |
+
if( ($minValue > $ipNumber) || ($ipNumber > $maxValue) )
|
206 |
+
{
|
207 |
+
$arrNewRanges[] = array($minValue, $maxValue);
|
208 |
+
continue;
|
209 |
+
}
|
210 |
+
|
211 |
+
if($minValue == $ipNumber)
|
212 |
+
{
|
213 |
+
if($minValue + 1 <= $maxValue) {
|
214 |
+
$arrNewRanges[] = array( $minValue + 1, $maxValue );
|
215 |
+
}
|
216 |
+
unset($arrFormattedRange[$minValue]);
|
217 |
+
continue;
|
218 |
+
}
|
219 |
+
|
220 |
+
if($maxValue == $ipNumber)
|
221 |
+
{
|
222 |
+
if($minValue <= $maxValue - 1) {
|
223 |
+
$arrNewRanges[] = array( $minValue, $maxValue - 1 );
|
224 |
+
}
|
225 |
+
unset($arrFormattedRange[$minValue]);
|
226 |
+
continue;
|
227 |
+
}
|
228 |
+
|
229 |
+
if($minValue == $ipNumber - 1)
|
230 |
+
{
|
231 |
+
$arrSingleIPs[$minValue] = 1;
|
232 |
+
$arrNewRanges[] = array( $ipNumber + 1, $maxValue );
|
233 |
+
continue;
|
234 |
+
}
|
235 |
+
|
236 |
+
if($maxValue == $ipNumber + 1)
|
237 |
+
{
|
238 |
+
$arrSingleIPs[$maxValue] = 1;
|
239 |
+
$arrNewRanges[] = array( $minValue, $ipNumber -1 );
|
240 |
+
continue;
|
241 |
+
}
|
242 |
+
|
243 |
+
$arrNewRanges[] = array( $minValue, $ipNumber -1 );
|
244 |
+
$arrNewRanges[] = array( $ipNumber + 1, $maxValue);
|
245 |
+
|
246 |
+
}
|
247 |
+
|
248 |
+
$arrFormattedRange = $arrSingleIPs; unset($arrSingleIPs);
|
249 |
+
|
250 |
+
for($i = 0, $rangeLength = count($arrNewRanges); $i < $rangeLength; ++$i)
|
251 |
+
{
|
252 |
+
if($arrNewRanges[$i][0] < $arrNewRanges[$i][1])
|
253 |
+
continue;
|
254 |
+
|
255 |
+
$arrFormattedRange[$arrNewRanges[$i][0]] = 1;
|
256 |
+
unset($arrNewRanges[$i]);
|
257 |
+
}
|
258 |
+
|
259 |
+
$arrNewRanges = MchGdbcUtils::overlapIntervals($arrNewRanges);
|
260 |
+
|
261 |
+
foreach($arrNewRanges as $arrRange){
|
262 |
+
$arrFormattedRange[ $arrRange[0] ] = $arrRange[1];
|
263 |
+
}
|
264 |
+
|
265 |
+
return $arrFormattedRange;
|
266 |
+
|
267 |
+
}
|
268 |
+
|
269 |
+
public static function getFormattedIpRangeForDb($receivedIpAddress)
|
270 |
+
{
|
271 |
+
if(empty($receivedIpAddress))
|
272 |
+
return array();
|
273 |
+
|
274 |
+
$receivedIpAddress = trim($receivedIpAddress);
|
275 |
+
|
276 |
+
$arrPreparedData = array();
|
277 |
+
$ipVersion = MchGdbcIPUtils::getIpAddressVersion($receivedIpAddress);
|
278 |
+
if(-1 !== $ipVersion) // single IP
|
279 |
+
{
|
280 |
+
if($ipVersion === MchGdbcIPUtils::IP_VERSION_4)
|
281 |
+
{
|
282 |
+
$arrPreparedData[MchGdbcIPUtils::IP_VERSION_4] = array(MchGdbcIPUtils::ipAddressToNumber($receivedIpAddress), 1);
|
283 |
+
}
|
284 |
+
else
|
285 |
+
{
|
286 |
+
$arrPreparedData[MchGdbcIPUtils::IP_VERSION_6] = array(MchGdbcIPUtils::compressIPV6($receivedIpAddress), 1);
|
287 |
+
}
|
288 |
+
|
289 |
+
return $arrPreparedData;
|
290 |
+
}
|
291 |
+
|
292 |
+
$sanitizedRange = MchGdbcIPUtils::sanitizeCIDRRange($receivedIpAddress);
|
293 |
+
if(null !== $sanitizedRange) // CIDR Block
|
294 |
+
{
|
295 |
+
$ipVersion = MchGdbcIPUtils::getIpAddressVersion(MchGdbcIPUtils::sanitizeIpAddress($sanitizedRange));
|
296 |
+
if($ipVersion === MchGdbcIPUtils::IP_VERSION_4)
|
297 |
+
{
|
298 |
+
$sanitizedRange = MchGdbcIPUtils::getCIDRRangeBounds($sanitizedRange);
|
299 |
+
if(empty($sanitizedRange[0]) || empty($sanitizedRange[1]))
|
300 |
+
return array();
|
301 |
+
|
302 |
+
$sanitizedRange[0] = MchGdbcIPUtils::ipAddressToNumber($sanitizedRange[0]);
|
303 |
+
$sanitizedRange[1] = MchGdbcIPUtils::ipAddressToNumber($sanitizedRange[1]);
|
304 |
+
|
305 |
+
$arrPreparedData[$ipVersion] = $sanitizedRange;
|
306 |
+
|
307 |
+
}
|
308 |
+
else // IPV6
|
309 |
+
{
|
310 |
+
list($ipv6, $bits) = explode('/', $sanitizedRange, 2);
|
311 |
+
|
312 |
+
$ipv6 = MchGdbcIPUtils::compressIPV6($ipv6);
|
313 |
+
|
314 |
+
$arrPreparedData[ $ipVersion ] = $bits == MchGdbcIPUtils::IP_V6_MAX_BITS ? array($ipv6, 1) : array("$ipv6/$bits", 1);
|
315 |
+
}
|
316 |
+
|
317 |
+
return $arrPreparedData;
|
318 |
+
}
|
319 |
+
$arrSanitizedRange = explode('-', $receivedIpAddress, 2);
|
320 |
+
if(2 !== count($arrSanitizedRange))
|
321 |
+
return array();
|
322 |
+
|
323 |
+
$sanitizedLowIp = MchGdbcIPUtils::sanitizeIpAddress(MchGdbcIPUtils::sanitizeCIDRRange($arrSanitizedRange[0]));
|
324 |
+
$sanitizedHighIp = MchGdbcIPUtils::sanitizeIpAddress(MchGdbcIPUtils::sanitizeCIDRRange($arrSanitizedRange[1]));
|
325 |
+
|
326 |
+
if(!MchGdbcIPUtils::isValidIpAddress($sanitizedLowIp) || !MchGdbcIPUtils::isValidIpAddress($sanitizedHighIp)) {
|
327 |
+
return array();
|
328 |
+
}
|
329 |
+
|
330 |
+
$ipVersion = MchGdbcIPUtils::getIpAddressVersion($sanitizedLowIp);
|
331 |
+
if($ipVersion !== MchGdbcIPUtils::getIpAddressVersion($sanitizedHighIp))
|
332 |
+
return array();
|
333 |
+
|
334 |
+
if( $ipVersion !== MchGdbcIPUtils::IP_VERSION_4 ) // non standard range allowed just for IPv4
|
335 |
+
return array();
|
336 |
+
|
337 |
+
$minIpNumber = MchGdbcIPUtils::ipAddressToNumber($sanitizedLowIp, MchGdbcIPUtils::IP_VERSION_4);
|
338 |
+
$maxIpNumber = MchGdbcIPUtils::ipAddressToNumber($sanitizedHighIp, MchGdbcIPUtils::IP_VERSION_4);
|
339 |
+
|
340 |
+
if($minIpNumber >= $maxIpNumber) // single IP
|
341 |
+
{
|
342 |
+
$arrPreparedData[$ipVersion] = array($minIpNumber, 1);
|
343 |
+
}
|
344 |
+
else
|
345 |
+
{
|
346 |
+
$arrPreparedData[$ipVersion] = array($minIpNumber, $maxIpNumber);
|
347 |
+
}
|
348 |
+
|
349 |
+
return $arrPreparedData;
|
350 |
+
|
351 |
+
}
|
352 |
+
|
353 |
+
|
354 |
+
public static function getFormattedIpRangesForDisplay($arrSavedIpRanges)
|
355 |
+
{
|
356 |
+
|
357 |
+
$arrIps = array();
|
358 |
+
foreach((array)$arrSavedIpRanges as $ipVersion => $arrSavedIps)
|
359 |
+
{
|
360 |
+
|
361 |
+
foreach($arrSavedIps as $savedIp => $value)
|
362 |
+
{
|
363 |
+
if($ipVersion == MchGdbcIPUtils::IP_VERSION_6)
|
364 |
+
{
|
365 |
+
$arrIps[] = $savedIp . '|' . MchGdbcIPUtils::getCIDRNumberOfHosts($savedIp);
|
366 |
+
continue;
|
367 |
+
}
|
368 |
+
|
369 |
+
if($value === 1)
|
370 |
+
{
|
371 |
+
$arrIps[] = MchGdbcIPUtils::ipAddressFromNumber( $savedIp, MchGdbcIPUtils::IP_VERSION_4 ) . '|' . 1;
|
372 |
+
|
373 |
+
continue;
|
374 |
+
}
|
375 |
+
|
376 |
+
// $arrRange = explode('/', $savedIp);
|
377 |
+
// if(isset($arrRange[1]) && !isset($arrRange[2]))
|
378 |
+
// {
|
379 |
+
// $arrIps[] = $savedIp . '|' . MchGdbcIPUtils::getCIDRNumberOfHosts($savedIp);
|
380 |
+
//
|
381 |
+
// continue;
|
382 |
+
// }
|
383 |
+
|
384 |
+
$arrRange = array($savedIp , $value);
|
385 |
+
if(is_numeric($arrRange[0]) && is_numeric($arrRange[1]))
|
386 |
+
{
|
387 |
+
$displayIp = MchGdbcIPUtils::ipAddressFromNumber($arrRange[0], MchGdbcIPUtils::IP_VERSION_4) . ' - ' . MchGdbcIPUtils::ipAddressFromNumber($arrRange[1], MchGdbcIPUtils::IP_VERSION_4);
|
388 |
+
$displayIp .= '|' . ($arrRange[1] - $arrRange[0] + 1);
|
389 |
+
$arrIps[] = $displayIp;
|
390 |
+
|
391 |
+
continue;
|
392 |
+
}
|
393 |
+
|
394 |
+
}
|
395 |
+
}
|
396 |
+
|
397 |
+
return array_reverse($arrIps);
|
398 |
+
}
|
399 |
+
|
400 |
+
|
401 |
+
|
402 |
+
|
403 |
+
private function __construct(){}
|
404 |
+
}
|
2.0/engine/GdbcModulesController.php
ADDED
@@ -0,0 +1,566 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
spl_autoload_register(array('GdbcModulesController','autoLoadModulesClasses'));
|
22 |
+
|
23 |
+
final class GdbcModulesController
|
24 |
+
{
|
25 |
+
CONST MODULE_SETTINGS = 'Settings';
|
26 |
+
CONST MODULE_WORDPRESS = 'WordPress';
|
27 |
+
CONST MODULE_BRUTE_FORCE = 'BruteForce';
|
28 |
+
|
29 |
+
//CONST MODULE_POPULAR_FORMS = 'PopularForms';
|
30 |
+
|
31 |
+
CONST MODULE_REPORTS = 'Reports';
|
32 |
+
|
33 |
+
CONST MODULE_WOOCOMMERCE = 'WooCommerce';
|
34 |
+
|
35 |
+
CONST MODULE_MAIL_CHIMP_FOR_WP = 'MailChimpForWp';
|
36 |
+
CONST MODULE_MAIL_POET = 'MailPoet';
|
37 |
+
|
38 |
+
CONST MODULE_NINJA_FORMS = 'NinjaForms';
|
39 |
+
CONST MODULE_CONTACT_FORM_7 = 'ContactForm7';
|
40 |
+
CONST MODULE_GRAVITY_FORMS = 'GravityForms';
|
41 |
+
CONST MODULE_FAST_SECURE_FORM = 'FastSecureForm';
|
42 |
+
CONST MODULE_FORMIDABLE_FORMS = 'FormidableForms';
|
43 |
+
CONST MODULE_JETPACK_CONTACT_FORM = 'JetPackContactForm';
|
44 |
+
|
45 |
+
|
46 |
+
CONST MODULE_ULTIMATE_MEMBER = 'UltimateMember';
|
47 |
+
CONST MODULE_USER_PRO = 'UserPro';
|
48 |
+
CONST MODULE_UPME = 'UPME';
|
49 |
+
CONST MODULE_BUDDY_PRESS = 'BuddyPress';
|
50 |
+
CONST MODULE_BB_PRESS = 'BBPress';
|
51 |
+
|
52 |
+
CONST MODULE_BLACK_LISTED_IPS = 'BlackListedIps';
|
53 |
+
CONST MODULE_WHITE_LISTED_IPS = 'WhiteListedIps';
|
54 |
+
|
55 |
+
CONST MODULE_ZM_ALR = 'ZM-ALR';
|
56 |
+
|
57 |
+
CONST MODULE_SEAMLESS_DONATIONS = 'SeamlessDonations';
|
58 |
+
CONST MODULE_WORDPRESS_TWEAKS = 'WordPressTweaks';
|
59 |
+
|
60 |
+
CONST MODULE_PLANSO_FORMS = 'PlanSoForms';
|
61 |
+
CONST MODULE_EMAIL_NOTIFICATIONS = 'EmailNotifications';
|
62 |
+
|
63 |
+
private static $arrRegisteredModules = null;
|
64 |
+
private static $arrAllModules = array(
|
65 |
+
|
66 |
+
|
67 |
+
# --------- Default Modules -------------------------
|
68 |
+
self::MODULE_SETTINGS => array(
|
69 |
+
'info' => array(
|
70 |
+
'ModuleId' => 1,
|
71 |
+
'IsPublic' => true,
|
72 |
+
),
|
73 |
+
|
74 |
+
'classes' => array(
|
75 |
+
'GdbcSettingsAdminModule' => '/modules/settings/GdbcSettingsAdminModule.php',
|
76 |
+
'GdbcSettingsPublicModule' => '/modules/settings/GdbcSettingsPublicModule.php',
|
77 |
+
),
|
78 |
+
|
79 |
+
),
|
80 |
+
|
81 |
+
self::MODULE_WORDPRESS => array(
|
82 |
+
'info' => array(
|
83 |
+
'ModuleId' => 2,
|
84 |
+
'IsPublic' => true,
|
85 |
+
),
|
86 |
+
'classes' => array(
|
87 |
+
'GdbcWordPressAdminModule' => '/modules/wordpress/GdbcWordPressAdminModule.php',
|
88 |
+
'GdbcWordPressPublicModule' => '/modules/wordpress/GdbcWordPressPublicModule.php',
|
89 |
+
)
|
90 |
+
),
|
91 |
+
|
92 |
+
# --------- Contact Forms Modules -------------------------
|
93 |
+
self::MODULE_JETPACK_CONTACT_FORM => array(
|
94 |
+
'info' => array(
|
95 |
+
'ModuleId' => 3,
|
96 |
+
'IsPublic' => true,
|
97 |
+
),
|
98 |
+
'classes' => array(
|
99 |
+
'GdbcJetPackContactFormAdminModule' => '/modules/jetpack-contact-form/GdbcJetPackContactFormAdminModule.php',
|
100 |
+
'GdbcJetPackContactFormPublicModule' => '/modules/jetpack-contact-form/GdbcJetPackContactFormPublicModule.php',
|
101 |
+
)
|
102 |
+
),
|
103 |
+
|
104 |
+
|
105 |
+
self::MODULE_NINJA_FORMS => array(
|
106 |
+
'info' => array(
|
107 |
+
'ModuleId' => 4,
|
108 |
+
'IsPublic' => false,
|
109 |
+
),
|
110 |
+
'classes' => array(
|
111 |
+
'GdbcNinjaFormsAdminModule' => '/modules/ninja-forms/GdbcNinjaFormsAdminModule.php',
|
112 |
+
'GdbcNinjaFormsPublicModule' => '/modules/ninja-forms/GdbcNinjaFormsPublicModule.php',
|
113 |
+
)
|
114 |
+
),
|
115 |
+
|
116 |
+
self::MODULE_CONTACT_FORM_7 => array(
|
117 |
+
'info' => array(
|
118 |
+
'ModuleId' => 5,
|
119 |
+
'IsPublic' => false,
|
120 |
+
),
|
121 |
+
'classes' => array(
|
122 |
+
'GdbcContactForm7AdminModule' => '/modules/contact-form-7/GdbcContactForm7AdminModule.php',
|
123 |
+
'GdbcContactForm7PublicModule' => '/modules/contact-form-7/GdbcContactForm7PublicModule.php',
|
124 |
+
)
|
125 |
+
),
|
126 |
+
|
127 |
+
self::MODULE_GRAVITY_FORMS => array(
|
128 |
+
'info' => array(
|
129 |
+
'ModuleId' => 6,
|
130 |
+
'IsPublic' => false,
|
131 |
+
),
|
132 |
+
'classes' => array(
|
133 |
+
'GdbcGravityFormsAdminModule' => '/modules/gravity-forms/GdbcGravityFormsAdminModule.php',
|
134 |
+
'GdbcGravityFormsPublicModule' => '/modules/gravity-forms/GdbcGravityFormsPublicModule.php',
|
135 |
+
)
|
136 |
+
),
|
137 |
+
|
138 |
+
self::MODULE_FAST_SECURE_FORM => array(
|
139 |
+
'info' => array(
|
140 |
+
'ModuleId' => 7,
|
141 |
+
'IsPublic' => false,
|
142 |
+
),
|
143 |
+
'classes' => array(
|
144 |
+
'GdbcFastSecureFormAdminModule' => '/modules/fast-secure-form/GdbcFastSecureFormAdminModule.php',
|
145 |
+
'GdbcFastSecureFormPublicModule' => '/modules/fast-secure-form/GdbcFastSecureFormPublicModule.php',
|
146 |
+
)
|
147 |
+
),
|
148 |
+
|
149 |
+
self::MODULE_FORMIDABLE_FORMS => array(
|
150 |
+
'info' => array(
|
151 |
+
'ModuleId' => 8,
|
152 |
+
'IsPublic' => false,
|
153 |
+
),
|
154 |
+
'classes' => array(
|
155 |
+
'GdbcFormidableFormsAdminModule' => '/modules/formidable-forms/GdbcFormidableFormsAdminModule.php',
|
156 |
+
'GdbcFormidableFormsPublicModule' => '/modules/formidable-forms/GdbcFormidableFormsPublicModule.php',
|
157 |
+
)
|
158 |
+
),
|
159 |
+
|
160 |
+
|
161 |
+
# --------- Community Modules -------------------------
|
162 |
+
|
163 |
+
self::MODULE_ULTIMATE_MEMBER => array(
|
164 |
+
'info' => array(
|
165 |
+
'ModuleId' => 9,
|
166 |
+
'IsPublic' => true,
|
167 |
+
),
|
168 |
+
'classes' => array(
|
169 |
+
'GdbcUltimateMemberAdminModule' => '/modules/ultimate-member/GdbcUltimateMemberAdminModule.php',
|
170 |
+
'GdbcUltimateMemberPublicModule' => '/modules/ultimate-member/GdbcUltimateMemberPublicModule.php',
|
171 |
+
)
|
172 |
+
),
|
173 |
+
|
174 |
+
self::MODULE_BUDDY_PRESS => array(
|
175 |
+
'info' => array(
|
176 |
+
'ModuleId' => 10,
|
177 |
+
'IsPublic' => false,
|
178 |
+
),
|
179 |
+
'classes' => array(
|
180 |
+
'GdbcBuddyPressAdminModule' => '/modules/buddy-press/GdbcBuddyPressAdminModule.php',
|
181 |
+
'GdbcBuddyPressPublicModule' => '/modules/buddy-press/GdbcBuddyPressPublicModule.php',
|
182 |
+
)
|
183 |
+
),
|
184 |
+
|
185 |
+
self::MODULE_BB_PRESS => array(
|
186 |
+
'info' => array(
|
187 |
+
'ModuleId' => 11,
|
188 |
+
'IsPublic' => false,
|
189 |
+
),
|
190 |
+
'classes' => array(
|
191 |
+
'GdbcBbPressAdminModule' => '/modules/bb-press/GdbcBbPressAdminModule.php',
|
192 |
+
'GdbcBbPressPublicModule' => '/modules/bb-press/GdbcBbPressPublicModule.php',
|
193 |
+
)
|
194 |
+
),
|
195 |
+
|
196 |
+
self::MODULE_USER_PRO => array(
|
197 |
+
'info' => array(
|
198 |
+
'ModuleId' => 12,
|
199 |
+
'IsPublic' => false,
|
200 |
+
),
|
201 |
+
'classes' => array(
|
202 |
+
'GdbcUserProAdminModule' => '/modules/user-pro/GdbcUserProAdminModule.php',
|
203 |
+
'GdbcUserProPublicModule' => '/modules/user-pro/GdbcUserProPublicModule.php',
|
204 |
+
)
|
205 |
+
),
|
206 |
+
|
207 |
+
self::MODULE_UPME => array(
|
208 |
+
'info' => array(
|
209 |
+
'ModuleId' => 13,
|
210 |
+
'IsPublic' => false,
|
211 |
+
),
|
212 |
+
'classes' => array(
|
213 |
+
'GdbcUPMEAdminModule' => '/modules/upme/GdbcUPMEAdminModule.php',
|
214 |
+
'GdbcUPMEPublicModule' => '/modules/upme/GdbcUPMEPublicModule.php',
|
215 |
+
)
|
216 |
+
),
|
217 |
+
|
218 |
+
|
219 |
+
# --------- Subscriptions Modules -------------------------
|
220 |
+
|
221 |
+
|
222 |
+
self::MODULE_MAIL_CHIMP_FOR_WP => array(
|
223 |
+
'info' => array(
|
224 |
+
'ModuleId' => 14,
|
225 |
+
'IsPublic' => true,
|
226 |
+
),
|
227 |
+
'classes' => array(
|
228 |
+
'GdbcMailChimpForWpAdminModule' => '/modules/mc-for-wp/GdbcMailChimpForWpAdminModule.php',
|
229 |
+
'GdbcMailChimpForWpPublicModule' => '/modules/mc-for-wp/GdbcMailChimpForWpPublicModule.php',
|
230 |
+
)
|
231 |
+
),
|
232 |
+
|
233 |
+
self::MODULE_MAIL_POET => array(
|
234 |
+
'info' => array(
|
235 |
+
'ModuleId' => 15,
|
236 |
+
'IsPublic' => false,
|
237 |
+
),
|
238 |
+
'classes' => array(
|
239 |
+
'GdbcMailPoetAdminModule' => '/modules/mail-poet/GdbcMailPoetAdminModule.php',
|
240 |
+
'GdbcMailPoetPublicModule' => '/modules/mail-poet/GdbcMailPoetPublicModule.php',
|
241 |
+
)
|
242 |
+
),
|
243 |
+
|
244 |
+
self::MODULE_WOOCOMMERCE => array(
|
245 |
+
'info' => array(
|
246 |
+
'ModuleId' => 16,
|
247 |
+
'IsPublic' => false,
|
248 |
+
),
|
249 |
+
'classes' => array(
|
250 |
+
'GdbcWooCommerceAdminModule' => '/modules/woocommerce/GdbcWooCommerceAdminModule.php',
|
251 |
+
'GdbcWooCommercePublicModule' => '/modules/woocommerce/GdbcWooCommercePublicModule.php',
|
252 |
+
)
|
253 |
+
),
|
254 |
+
|
255 |
+
|
256 |
+
self::MODULE_REPORTS => array(
|
257 |
+
'info' => array(
|
258 |
+
'ModuleId' => 17,
|
259 |
+
'IsPublic' => true,
|
260 |
+
),
|
261 |
+
'classes' => array(
|
262 |
+
'GdbcReportsAdminModule' => '/modules/reports/GdbcReportsAdminModule.php',
|
263 |
+
'GdbcReportsPublicModule' => '/modules/reports/GdbcReportsPublicModule.php',
|
264 |
+
)
|
265 |
+
),
|
266 |
+
|
267 |
+
self::MODULE_BRUTE_FORCE => array(
|
268 |
+
'info' => array(
|
269 |
+
'ModuleId' => 18,
|
270 |
+
'IsPublic' => true,
|
271 |
+
),
|
272 |
+
'classes' => array(
|
273 |
+
'GdbcBruteForceAdminModule' => '/modules/brute-force/GdbcBruteForceAdminModule.php',
|
274 |
+
'GdbcBruteForcePublicModule' => '/modules/brute-force/GdbcBruteForcePublicModule.php',
|
275 |
+
)
|
276 |
+
),
|
277 |
+
|
278 |
+
|
279 |
+
self::MODULE_BLACK_LISTED_IPS => array(
|
280 |
+
'info' => array(
|
281 |
+
'ModuleId' => 19,
|
282 |
+
'IsPublic' => true,
|
283 |
+
),
|
284 |
+
'classes' => array(
|
285 |
+
'GdbcBlackListedIpsAdminModule' => '/modules/black-listed-ips/GdbcBlackListedIpsAdminModule.php',
|
286 |
+
'GdbcBlackListedIpsPublicModule' => '/modules/black-listed-ips/GdbcBlackListedIpsPublicModule.php',
|
287 |
+
)
|
288 |
+
),
|
289 |
+
|
290 |
+
self::MODULE_WHITE_LISTED_IPS => array(
|
291 |
+
'info' => array(
|
292 |
+
'ModuleId' => 20,
|
293 |
+
'IsPublic' => true,
|
294 |
+
),
|
295 |
+
'classes' => array(
|
296 |
+
'GdbcWhiteListedIpsAdminModule' => '/modules/white-listed-ips/GdbcWhiteListedIpsAdminModule.php',
|
297 |
+
'GdbcWhiteListedIpsPublicModule' => '/modules/white-listed-ips/GdbcWhiteListedIpsPublicModule.php',
|
298 |
+
)
|
299 |
+
),
|
300 |
+
|
301 |
+
self::MODULE_ZM_ALR => array(
|
302 |
+
'info' => array(
|
303 |
+
'ModuleId' => 21,
|
304 |
+
'IsPublic' => true,
|
305 |
+
),
|
306 |
+
'classes' => array(
|
307 |
+
'GdbcZmAlrAdminModule' => '/modules/zm-ajax-login-register/GdbcZmAlrAdminModule.php',
|
308 |
+
'GdbcZmAlrPublicModule' => '/modules/zm-ajax-login-register/GdbcZmAlrPublicModule.php',
|
309 |
+
)
|
310 |
+
),
|
311 |
+
|
312 |
+
self::MODULE_SEAMLESS_DONATIONS => array(
|
313 |
+
'info' => array(
|
314 |
+
'ModuleId' => 22,
|
315 |
+
'IsPublic' => true,
|
316 |
+
),
|
317 |
+
'classes' => array(
|
318 |
+
'GdbcSeamlessDonationsAdminModule' => '/modules/seamless-donations/GdbcSeamlessDonationsAdminModule.php',
|
319 |
+
'GdbcSeamlessDonationsPublicModule' => '/modules/seamless-donations/GdbcSeamlessDonationsPublicModule.php',
|
320 |
+
)
|
321 |
+
),
|
322 |
+
|
323 |
+
self::MODULE_WORDPRESS_TWEAKS => array(
|
324 |
+
'info' => array(
|
325 |
+
'ModuleId' => 23,
|
326 |
+
'IsPublic' => true,
|
327 |
+
),
|
328 |
+
'classes' => array(
|
329 |
+
'GdbcWordPressTweaksAdminModule' => '/modules/wordpress-tweaks/GdbcWordPressTweaksAdminModule.php',
|
330 |
+
'GdbcWordPressTweaksPublicModule' => '/modules/wordpress-tweaks/GdbcWordPressTweaksPublicModule.php',
|
331 |
+
)
|
332 |
+
),
|
333 |
+
|
334 |
+
self::MODULE_EMAIL_NOTIFICATIONS => array(
|
335 |
+
'info' => array(
|
336 |
+
'ModuleId' => 24,
|
337 |
+
'IsPublic' => true,
|
338 |
+
),
|
339 |
+
'classes' => array(
|
340 |
+
'GdbcEmailNotificationsAdminModule' => '/modules/email-notifications/GdbcEmailNotificationsAdminModule.php',
|
341 |
+
'GdbcEmailNotificationsPublicModule' => '/modules/email-notifications/GdbcEmailNotificationsPublicModule.php',
|
342 |
+
)
|
343 |
+
),
|
344 |
+
|
345 |
+
self::MODULE_PLANSO_FORMS => array(
|
346 |
+
'info' => array(
|
347 |
+
'ModuleId' => 25,
|
348 |
+
'IsPublic' => true,
|
349 |
+
),
|
350 |
+
'classes' => array(
|
351 |
+
'GdbcPlanSoFormsAdminModule' => '/modules/planso-forms/GdbcPlanSoFormsAdminModule.php',
|
352 |
+
'GdbcPlanSoFormsPublicModule' => '/modules/planso-forms/GdbcPlanSoFormsPublicModule.php',
|
353 |
+
)
|
354 |
+
),
|
355 |
+
|
356 |
+
);
|
357 |
+
|
358 |
+
public static function getRegisteredModules()
|
359 |
+
{
|
360 |
+
if(null === self::$arrRegisteredModules)
|
361 |
+
self::setRegisteredModules();
|
362 |
+
|
363 |
+
return self::$arrRegisteredModules;
|
364 |
+
}
|
365 |
+
|
366 |
+
private static function setRegisteredModules()
|
367 |
+
{
|
368 |
+
if(null !== self::$arrRegisteredModules)
|
369 |
+
return;
|
370 |
+
|
371 |
+
self::$arrRegisteredModules = array();
|
372 |
+
|
373 |
+
$activatedPlugins = defined('WP_PLUGIN_DIR') ? array_merge( array_flip((array) get_option( 'active_plugins', array())), (array) get_site_option( 'active_sitewide_plugins', array() ) ) : array(); // wp_get_mu_plugins()
|
374 |
+
|
375 |
+
foreach(self::$arrAllModules as $moduleName => $arrModule)
|
376 |
+
{
|
377 |
+
self::$arrRegisteredModules[$moduleName] = array();
|
378 |
+
|
379 |
+
foreach ($arrModule['classes'] as $className => $filePath)
|
380 |
+
{
|
381 |
+
$filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . ( $dirPath = trim( dirname($filePath) , '/\\' ) . DIRECTORY_SEPARATOR . basename($filePath) );
|
382 |
+
|
383 |
+
if(file_exists($filePath))
|
384 |
+
{
|
385 |
+
self::$arrRegisteredModules[$moduleName][$className] = $filePath;
|
386 |
+
continue;
|
387 |
+
}
|
388 |
+
|
389 |
+
foreach($activatedPlugins as $activePlugin => $value)
|
390 |
+
{
|
391 |
+
if(false === strpos($activePlugin, 'GoodByeCaptcha')){
|
392 |
+
unset($activatedPlugins[$activePlugin]);continue;
|
393 |
+
}
|
394 |
+
|
395 |
+
if(false === strpos($activePlugin, "GoodByeCaptcha$moduleName"))
|
396 |
+
continue;
|
397 |
+
|
398 |
+
$filePath = @dirname(WP_PLUGIN_DIR . '/' . $activePlugin ) . "/engine/$dirPath" ;
|
399 |
+
|
400 |
+
break;
|
401 |
+
|
402 |
+
}
|
403 |
+
|
404 |
+
file_exists($filePath) ? self::$arrRegisteredModules[$moduleName][$className] = $filePath : null;
|
405 |
+
}
|
406 |
+
|
407 |
+
if(empty(self::$arrRegisteredModules[$moduleName]))
|
408 |
+
unset(self::$arrRegisteredModules[$moduleName]);
|
409 |
+
}
|
410 |
+
|
411 |
+
|
412 |
+
}
|
413 |
+
|
414 |
+
|
415 |
+
public static function getModuleIdByName($moduleName)
|
416 |
+
{
|
417 |
+
return isset(self::$arrAllModules[$moduleName]['info']['ModuleId']) ? self::$arrAllModules[$moduleName]['info']['ModuleId'] : null;
|
418 |
+
}
|
419 |
+
|
420 |
+
public static function isPublicModule($moduleIdORmoduleName)
|
421 |
+
{
|
422 |
+
$moduleName = ((false === filter_var($moduleIdORmoduleName, FILTER_VALIDATE_INT)) ? $moduleIdORmoduleName : self::getModuleNameById($moduleIdORmoduleName));
|
423 |
+
|
424 |
+
if(!isset(self::$arrAllModules[$moduleName]['info']['IsPublic']))
|
425 |
+
return false;
|
426 |
+
|
427 |
+
#Returns TRUE for true, "1", "true", "on" and "yes"
|
428 |
+
return (false === filter_var(self::$arrAllModules[$moduleName]['info']['IsPublic'], FILTER_VALIDATE_BOOLEAN)) ? false : true;
|
429 |
+
}
|
430 |
+
|
431 |
+
|
432 |
+
public static function unRegisterModule($moduleName)
|
433 |
+
{
|
434 |
+
unset(self::$arrRegisteredModules[(string)$moduleName]);
|
435 |
+
}
|
436 |
+
|
437 |
+
|
438 |
+
public static function getPublicModulesName()
|
439 |
+
{
|
440 |
+
$arrFreeModules = array();
|
441 |
+
foreach(self::$arrAllModules as $moduleName => $arrAllModulesettings)
|
442 |
+
{
|
443 |
+
self::isPublicModule($moduleName) ? $arrFreeModules[] = $moduleName : null;
|
444 |
+
}
|
445 |
+
|
446 |
+
return $arrFreeModules;
|
447 |
+
}
|
448 |
+
|
449 |
+
public static function getModuleNameById($moduleId)
|
450 |
+
{
|
451 |
+
foreach(self::$arrAllModules as $moduleKey => $moduleValue)
|
452 |
+
{
|
453 |
+
if (isset($moduleValue['info']['ModuleId']) && $moduleValue['info']['ModuleId'] == $moduleId)
|
454 |
+
return $moduleKey;
|
455 |
+
}
|
456 |
+
|
457 |
+
return null;
|
458 |
+
}
|
459 |
+
|
460 |
+
public static function getModuleOptionDisplayText($moduleId, $optionId)
|
461 |
+
{
|
462 |
+
if(null === ($moduleAdminInstance = self::getAdminModuleInstance(self::getModuleNameById($moduleId))))
|
463 |
+
return null;
|
464 |
+
|
465 |
+
return $moduleAdminInstance->getOptionDisplayTextByOptionId($optionId);
|
466 |
+
}
|
467 |
+
|
468 |
+
public static function getModuleOptionId($moduleName, $optionName)
|
469 |
+
{
|
470 |
+
if(null === ($moduleAdminInstance = self::getAdminModuleInstance($moduleName)))
|
471 |
+
return null;
|
472 |
+
|
473 |
+
return $moduleAdminInstance->getOptionIdByOptionName($optionName);
|
474 |
+
}
|
475 |
+
|
476 |
+
public static function getModuleDirectoryPath($moduleName)
|
477 |
+
{
|
478 |
+
if(null === self::$arrRegisteredModules)
|
479 |
+
self::setRegisteredModules();
|
480 |
+
|
481 |
+
if(!isset(self::$arrRegisteredModules[$moduleName]) || !is_array(self::$arrRegisteredModules[$moduleName]))
|
482 |
+
return null;
|
483 |
+
|
484 |
+
return @dirname(reset(self::$arrRegisteredModules[$moduleName]));
|
485 |
+
}
|
486 |
+
|
487 |
+
/**
|
488 |
+
*
|
489 |
+
* @staticvar array $arrInstances
|
490 |
+
* @param string $moduleName
|
491 |
+
* @param int $moduleType
|
492 |
+
* @return \MchGdbcBaseModule | null
|
493 |
+
*/
|
494 |
+
private static function getModuleInstance($moduleName, $moduleType)
|
495 |
+
{
|
496 |
+
if(null === self::$arrRegisteredModules)
|
497 |
+
self::setRegisteredModules();
|
498 |
+
|
499 |
+
if(!isset(self::$arrRegisteredModules[$moduleName]))
|
500 |
+
return null;
|
501 |
+
|
502 |
+
foreach (self::$arrRegisteredModules[$moduleName] as $moduleClassName => $filePath)
|
503 |
+
{
|
504 |
+
if(1 === $moduleType && (false === strpos($moduleClassName, 'Admin')))
|
505 |
+
continue;
|
506 |
+
elseif(2 === $moduleType && (false === strpos($moduleClassName, 'Public')))
|
507 |
+
continue;
|
508 |
+
|
509 |
+
if(!method_exists($moduleClassName, 'getInstance'))
|
510 |
+
return null;
|
511 |
+
|
512 |
+
if(false !== ($moduleInstance = call_user_func(array($moduleClassName, 'getInstance'))))
|
513 |
+
return $moduleInstance;
|
514 |
+
}
|
515 |
+
|
516 |
+
return null;
|
517 |
+
}
|
518 |
+
|
519 |
+
/**
|
520 |
+
* @param string $moduleName Module name
|
521 |
+
*
|
522 |
+
* @return \GdbcBaseAdminModule|null
|
523 |
+
*/
|
524 |
+
public static function getAdminModuleInstance($moduleName)
|
525 |
+
{
|
526 |
+
return self::getModuleInstance($moduleName, 1);
|
527 |
+
}
|
528 |
+
|
529 |
+
/**
|
530 |
+
* @param string $moduleName Module name
|
531 |
+
*
|
532 |
+
* @return \MchGdbcBasePublicModule|null
|
533 |
+
*/
|
534 |
+
public static function getPublicModuleInstance($moduleName)
|
535 |
+
{
|
536 |
+
return self::getModuleInstance($moduleName, 2);
|
537 |
+
}
|
538 |
+
|
539 |
+
|
540 |
+
/**
|
541 |
+
* @param $moduleName string Module name
|
542 |
+
*
|
543 |
+
* @return bool
|
544 |
+
*/
|
545 |
+
public static function isModuleRegistered($moduleName)
|
546 |
+
{
|
547 |
+
if(null === self::$arrRegisteredModules)
|
548 |
+
self::setRegisteredModules();
|
549 |
+
|
550 |
+
return isset(self::$arrRegisteredModules[$moduleName]);
|
551 |
+
}
|
552 |
+
|
553 |
+
public static function autoLoadModulesClasses($moduleClassName)
|
554 |
+
{
|
555 |
+
if(null === self::$arrRegisteredModules)
|
556 |
+
self::setRegisteredModules();
|
557 |
+
|
558 |
+
foreach(self::$arrRegisteredModules as $arrModuleClasses)
|
559 |
+
{
|
560 |
+
if(!isset($arrModuleClasses[$moduleClassName]))
|
561 |
+
continue;
|
562 |
+
|
563 |
+
return require_once($arrModuleClasses[$moduleClassName]);
|
564 |
+
}
|
565 |
+
}
|
566 |
+
}
|
2.0/engine/GdbcNotificationsController.php
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GdbcNotificationsController
|
21 |
+
{
|
22 |
+
public static function sendTestModeEmailNotification(GdbcAttemptEntity $gdbcAttemptEntity)
|
23 |
+
{
|
24 |
+
GdbcEmailNotificationsPublicModule::getInstance()->EmailSubject = __('GoodBye Captcha - Test Mode Notification', GoodByeCaptcha::PLUGIN_SLUG);
|
25 |
+
|
26 |
+
$clientIpAddress = GdbcIPUtils::getClientIpAddress();
|
27 |
+
$currentSiteLink = MchGdbcWpUtils::getCurrentBlogLink();
|
28 |
+
$adminFullName = MchGdbcWpUtils::getAdminFullName();
|
29 |
+
empty($adminFullName) ? $adminFullName = MchGdbcWpUtils::getAdminDisplayName() : null;
|
30 |
+
|
31 |
+
$submittedForm = GdbcModulesController::getModuleNameById($gdbcAttemptEntity->ModuleId);
|
32 |
+
$submittedForm .= empty($gdbcAttemptEntity->SectionId) ? '' : '/' . GdbcModulesController::getModuleOptionDisplayText($gdbcAttemptEntity->ModuleId, $gdbcAttemptEntity->SectionId);
|
33 |
+
|
34 |
+
$rejectReason = GdbcRequestController::tokenAlreadyRejected() ? GdbcRequestController::getRejectReasonDescription(GdbcRequestController::getRejectReasonId()) : null;
|
35 |
+
|
36 |
+
$moduleDirPath = GdbcModulesController::getModuleDirectoryPath(GdbcModulesController::MODULE_EMAIL_NOTIFICATIONS);
|
37 |
+
|
38 |
+
if(empty($moduleDirPath))
|
39 |
+
{
|
40 |
+
GdbcEmailNotificationsPublicModule::getInstance()->EmailBodyContent = __('GoodBye Captcha encountered an error while trying to parse the email template!', GoodByeCaptcha::PLUGIN_SLUG);
|
41 |
+
}
|
42 |
+
else
|
43 |
+
{
|
44 |
+
ob_start();
|
45 |
+
require_once ($moduleDirPath . '/templates/notification-test-mode.php');
|
46 |
+
GdbcEmailNotificationsPublicModule::getInstance()->EmailBodyContent = ob_get_clean() . "\n";
|
47 |
+
}
|
48 |
+
|
49 |
+
GdbcEmailNotificationsPublicModule::getInstance()->send(true);
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
public static function sendBruteForceAttackDetectedEmailNotification(array $arrLoginAttempts)
|
54 |
+
{
|
55 |
+
|
56 |
+
if( ! GdbcEmailNotificationsPublicModule::getInstance()->getOption(GdbcEmailNotificationsAdminModule::OPTION_BRUTE_FORCE_ATTACK_DETECTED) )
|
57 |
+
return;
|
58 |
+
|
59 |
+
GdbcEmailNotificationsPublicModule::getInstance()->EmailSubject = __('Alert - Brute Force Attack Detected by GoodBye Captcha!', GoodByeCaptcha::PLUGIN_SLUG);
|
60 |
+
|
61 |
+
$adminFullName = MchGdbcWpUtils::getAdminFullName();
|
62 |
+
empty($adminFullName) ? $adminFullName = MchGdbcWpUtils::getAdminDisplayName() : null;
|
63 |
+
|
64 |
+
$totalHits = 0;
|
65 |
+
$totalIPs = 0;
|
66 |
+
$totalProxyAnonym = 0;
|
67 |
+
$totalWebAttackers = 0;
|
68 |
+
$totalBlackListed = 0;
|
69 |
+
|
70 |
+
$detectedDate = get_date_from_gmt ( date( 'Y-m-d H:i:s', MchGdbcHttpRequest::getServerRequestTime() ), 'l, F d, Y');
|
71 |
+
$detectedTime = get_date_from_gmt ( date( 'Y-m-d H:i:s', MchGdbcHttpRequest::getServerRequestTime() ), 'H:i:s');
|
72 |
+
|
73 |
+
foreach($arrLoginAttempts as $clientIp => $hits)
|
74 |
+
{
|
75 |
+
$totalHits += $hits;
|
76 |
+
$totalIPs++;
|
77 |
+
|
78 |
+
$loginAttempt = new stdClass();
|
79 |
+
$loginAttempt->IsIpBlackListed = GdbcIPUtils::isIpBlackListed($clientIp);
|
80 |
+
$loginAttempt->IsIpProxyAnonym = GdbcIPUtils::isIpProxyAnonymizer($clientIp);
|
81 |
+
$loginAttempt->IsIpWebAttacker = GdbcIPUtils::isIpWebAttacker($clientIp);
|
82 |
+
|
83 |
+
|
84 |
+
$totalBlackListed += $loginAttempt->IsIpBlackListed ? 1 : 0;
|
85 |
+
$totalWebAttackers += $loginAttempt->IsIpWebAttacker ? 1 : 0;
|
86 |
+
$totalProxyAnonym += ($loginAttempt->IsIpProxyAnonym && !$loginAttempt->IsIpWebAttacker) ? 1 : 0;
|
87 |
+
}
|
88 |
+
|
89 |
+
if( 0 === $totalIPs )
|
90 |
+
return;
|
91 |
+
|
92 |
+
$totalBlackListed = $totalBlackListed . ' (' . number_format( 100 - ( ($totalIPs - $totalBlackListed) * (100 / $totalIPs) ), 2, '.', '' ) . '%)';
|
93 |
+
$totalWebAttackers = $totalWebAttackers . ' (' . number_format( 100 - ( ($totalIPs - $totalWebAttackers) * (100 / $totalIPs) ), 2, '.', '' ) . '%)';
|
94 |
+
$totalProxyAnonym = $totalProxyAnonym . ' (' . number_format( 100 - ( ($totalIPs - $totalProxyAnonym) * (100 / $totalIPs) ), 2, '.', '' ) . '%)';
|
95 |
+
|
96 |
+
$arrReplaceableContent = array(
|
97 |
+
|
98 |
+
'{current-site-link}' => MchGdbcWpUtils::getCurrentBlogLink(),
|
99 |
+
'{admin-full-name}' => $adminFullName,
|
100 |
+
'{total-hits}' => $totalHits,
|
101 |
+
'{total-ips}' => $totalIPs,
|
102 |
+
'{total-black-listed}' => $totalBlackListed,
|
103 |
+
'{total-web-attackers}' => $totalWebAttackers,
|
104 |
+
'{total-proxy-anonymizers}' => $totalProxyAnonym,
|
105 |
+
'{detection-date-time}' => $detectedDate . ' at ' . $detectedTime,
|
106 |
+
);
|
107 |
+
|
108 |
+
$arrSuggestions = array(
|
109 |
+
GdbcBruteForceAdminModule::OPTION_AUTO_BLOCK_IP => GdbcBruteForceAdminModule::getInstance()->getOption(GdbcBruteForceAdminModule::OPTION_AUTO_BLOCK_IP),
|
110 |
+
GdbcBruteForceAdminModule::OPTION_BLOCK_WEB_ATTACKERS => GdbcBruteForceAdminModule::getInstance()->getOption(GdbcBruteForceAdminModule::OPTION_BLOCK_WEB_ATTACKERS),
|
111 |
+
GdbcBruteForceAdminModule::OPTION_BLOCK_ANONYMOUS_PROXY => GdbcBruteForceAdminModule::getInstance()->getOption(GdbcBruteForceAdminModule::OPTION_BLOCK_ANONYMOUS_PROXY),
|
112 |
+
);
|
113 |
+
|
114 |
+
foreach($arrSuggestions as $optionName => &$optionInfo)
|
115 |
+
{
|
116 |
+
if(!empty($optionInfo))
|
117 |
+
{
|
118 |
+
unset($arrSuggestions[$optionName]);
|
119 |
+
continue;
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
+
$arrDefaultOptions = GdbcBruteForceAdminModule::getInstance()->getDefaultOptions();
|
124 |
+
if(!isset($arrDefaultOptions[$optionName]['LabelText']))
|
125 |
+
continue;
|
126 |
+
|
127 |
+
$optionInfo = $arrDefaultOptions[$optionName]['LabelText'];
|
128 |
+
}
|
129 |
+
|
130 |
+
$moduleDirPath = GdbcModulesController::getModuleDirectoryPath(GdbcModulesController::MODULE_EMAIL_NOTIFICATIONS);
|
131 |
+
if(empty($moduleDirPath))
|
132 |
+
{
|
133 |
+
GdbcEmailNotificationsPublicModule::getInstance()->EmailBodyContent = __("Brute Force attack detected on " . MchGdbcWpUtils::getCurrentBlogLink(), GoodByeCaptcha::PLUGIN_SLUG);
|
134 |
+
}
|
135 |
+
else
|
136 |
+
{
|
137 |
+
ob_start();
|
138 |
+
require_once ($moduleDirPath . '/templates/notification-brute-force-attack.php');
|
139 |
+
$emailContent = ob_get_clean();
|
140 |
+
|
141 |
+
$emailContent = str_replace(array_keys($arrReplaceableContent), array_values($arrReplaceableContent), $emailContent);
|
142 |
+
|
143 |
+
GdbcEmailNotificationsPublicModule::getInstance()->EmailBodyContent = $emailContent;
|
144 |
+
}
|
145 |
+
|
146 |
+
unset($emailContent, $arrLoginAttempts, $moduleDirPath, $totalHits, $totalIPs, $totalProxyAnonym, $totalWebAttackers);
|
147 |
+
|
148 |
+
GdbcEmailNotificationsPublicModule::getInstance()->send(true);
|
149 |
+
|
150 |
+
}
|
151 |
+
|
152 |
+
}
|
2.0/engine/GdbcRequestController.php
ADDED
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class GdbcRequestController
|
22 |
+
{
|
23 |
+
|
24 |
+
CONST TOKEN_SEPARATOR = '|';
|
25 |
+
|
26 |
+
CONST REJECT_REASON_TOKEN_INVALID = 1;
|
27 |
+
CONST REJECT_REASON_TOKEN_MISSING = 2;
|
28 |
+
CONST REJECT_REASON_TOKEN_EXPIRED = 3;
|
29 |
+
CONST REJECT_REASON_TOKEN_SUBMITTED_EARLY = 4;
|
30 |
+
CONST REJECT_REASON_CLIENT_IP_BLOCKED = 5;
|
31 |
+
CONST REJECT_REASON_BROWSER_INFO_MISSING = 6;
|
32 |
+
CONST REJECT_REASON_BROWSER_INFO_INVALID = 7;
|
33 |
+
CONST REJECT_REASON_CLIENT_IP_UNDETECTABLE = 8;
|
34 |
+
CONST REJECT_REASON_USER_ENUMERATION = 9;
|
35 |
+
CONST REJECT_REASON_PROXY_ANONYMIZER = 10;
|
36 |
+
CONST REJECT_REASON_WEB_ATTACKER = 11;
|
37 |
+
CONST REJECT_REASON_SERVICE_UNAVAILABLE = 12;
|
38 |
+
|
39 |
+
private static $rejectReasonCode = null;
|
40 |
+
private static $browserInfoInputName = null;
|
41 |
+
|
42 |
+
|
43 |
+
public static function isValid(GdbcAttemptEntity $attemptEntity)
|
44 |
+
{
|
45 |
+
static $isRequestValid = null;
|
46 |
+
|
47 |
+
if(null !== $isRequestValid)
|
48 |
+
return $isRequestValid;
|
49 |
+
|
50 |
+
$settingsModuleInstance = GdbcModulesController::getPublicModuleInstance(GdbcModulesController::MODULE_SETTINGS);
|
51 |
+
if(null === $settingsModuleInstance)
|
52 |
+
return $isRequestValid = false;
|
53 |
+
|
54 |
+
$isTestModeActivated = (bool)$settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_TEST_MODE_ACTIVATED);
|
55 |
+
|
56 |
+
if( (!$isTestModeActivated) && GdbcIPUtils::isClientIpWhiteListed())
|
57 |
+
return $isRequestValid = true;
|
58 |
+
|
59 |
+
if( self::isReceivedTokenValid($attemptEntity) && GdbcIPUtils::isClientIpBlackListed()){
|
60 |
+
self::$rejectReasonCode = self::REJECT_REASON_CLIENT_IP_BLOCKED;
|
61 |
+
}
|
62 |
+
elseif( (null === self::$rejectReasonCode) && GdbcIPUtils::isClientIpWebAttacker()){
|
63 |
+
self::$rejectReasonCode = self::REJECT_REASON_WEB_ATTACKER;
|
64 |
+
}
|
65 |
+
elseif( (null === self::$rejectReasonCode) && GdbcIPUtils::isClientIpProxyAnonymizer()){
|
66 |
+
self::$rejectReasonCode = self::REJECT_REASON_PROXY_ANONYMIZER;
|
67 |
+
}
|
68 |
+
|
69 |
+
if($isTestModeActivated){
|
70 |
+
GdbcNotificationsController::sendTestModeEmailNotification($attemptEntity);
|
71 |
+
self::$rejectReasonCode = null;
|
72 |
+
}
|
73 |
+
|
74 |
+
if(null === self::$rejectReasonCode){
|
75 |
+
return $isRequestValid = true;
|
76 |
+
}
|
77 |
+
|
78 |
+
$attemptEntity->ReasonId = self::getRejectReasonId();
|
79 |
+
GdbcBruteGuardian::logRejectedAttempt($attemptEntity);
|
80 |
+
|
81 |
+
return $isRequestValid = false;
|
82 |
+
|
83 |
+
}
|
84 |
+
|
85 |
+
|
86 |
+
private static function isReceivedTokenValid(GdbcAttemptEntity $attemptEntity)
|
87 |
+
{
|
88 |
+
if(self::$rejectReasonCode !== null) {
|
89 |
+
return false;
|
90 |
+
}
|
91 |
+
|
92 |
+
$settingsModuleInstance = GdbcModulesController::getPublicModuleInstance(GdbcModulesController::MODULE_SETTINGS);
|
93 |
+
if(null === $settingsModuleInstance)
|
94 |
+
return false;
|
95 |
+
|
96 |
+
$tokenSecretKey = $settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_TOKEN_SECRET_KEY);
|
97 |
+
$hiddenInputName = $settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_HIDDEN_INPUT_NAME);
|
98 |
+
|
99 |
+
$minSubmissionTime = $settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_MIN_SUBMISSION_TIME);
|
100 |
+
|
101 |
+
// $isPluginInTestMode = (bool)$settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_TEST_MODE_ACTIVATED);
|
102 |
+
|
103 |
+
$isProtectionDisabled = ((bool)$settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_DISABLE_IF_USER_LOGGED_IN)) && MchGdbcWpUtils::isUserLoggedIn();
|
104 |
+
if($isProtectionDisabled) {
|
105 |
+
return true;
|
106 |
+
}
|
107 |
+
|
108 |
+
if(null === GdbcIPUtils::getClientIpAddress())
|
109 |
+
{
|
110 |
+
self::$rejectReasonCode = self::REJECT_REASON_CLIENT_IP_UNDETECTABLE;
|
111 |
+
return false;
|
112 |
+
}
|
113 |
+
|
114 |
+
$receivedToken = isset($_POST[$hiddenInputName]) ? $_POST[$hiddenInputName] : null;
|
115 |
+
|
116 |
+
if(null === $receivedToken){
|
117 |
+
self::$rejectReasonCode = self::REJECT_REASON_TOKEN_MISSING;
|
118 |
+
return false;
|
119 |
+
}
|
120 |
+
|
121 |
+
if(!isset($receivedToken[10])) {
|
122 |
+
self::$rejectReasonCode = self::REJECT_REASON_TOKEN_INVALID;
|
123 |
+
return false;
|
124 |
+
}
|
125 |
+
|
126 |
+
$arrDecryptedToken = json_decode(MchCrypt::decryptToken($tokenSecretKey, $receivedToken), true);
|
127 |
+
|
128 |
+
// if($isPluginInTestMode)
|
129 |
+
// {
|
130 |
+
// //$this->arrTokenDebugData['received-info'] = $arrDecryptedToken;
|
131 |
+
// //$this->arrTokenDebugData['token-data'] = $this->getTokenData();
|
132 |
+
// }
|
133 |
+
|
134 |
+
if( !isset($arrDecryptedToken[0]) || false === ($tokenIndex = strpos($arrDecryptedToken[0], self::TOKEN_SEPARATOR)) )
|
135 |
+
{
|
136 |
+
self::$rejectReasonCode = self::REJECT_REASON_TOKEN_INVALID;
|
137 |
+
return false;
|
138 |
+
}
|
139 |
+
|
140 |
+
self::$browserInfoInputName = substr($arrDecryptedToken[0], 0, $tokenIndex);
|
141 |
+
|
142 |
+
$receivedBrowserInfoInput = isset($_POST[self::$browserInfoInputName]) ? $_POST[self::$browserInfoInputName] : null;
|
143 |
+
|
144 |
+
if( null === $receivedBrowserInfoInput )
|
145 |
+
{
|
146 |
+
self::$rejectReasonCode = self::REJECT_REASON_BROWSER_INFO_MISSING;
|
147 |
+
return false;
|
148 |
+
}
|
149 |
+
|
150 |
+
$receivedBrowserInfoInput = MchGdbcUtils::replaceNonAlphaNumericCharacters($receivedBrowserInfoInput, '');
|
151 |
+
|
152 |
+
if($arrDecryptedToken[0] !== self::$browserInfoInputName . self::TOKEN_SEPARATOR . $receivedBrowserInfoInput)
|
153 |
+
{
|
154 |
+
self::$rejectReasonCode = self::REJECT_REASON_BROWSER_INFO_INVALID;
|
155 |
+
return false;
|
156 |
+
}
|
157 |
+
|
158 |
+
array_shift($arrDecryptedToken);
|
159 |
+
|
160 |
+
$arrTokenData = self::getTokenData();
|
161 |
+
|
162 |
+
$timeSinceGenerated = ((int)array_pop($arrTokenData)) - ((int)array_pop($arrDecryptedToken));
|
163 |
+
|
164 |
+
if($timeSinceGenerated < $minSubmissionTime)
|
165 |
+
{
|
166 |
+
if( ! GoodByeCaptchaUtils::isLoginAttemptEntity($attemptEntity) ){
|
167 |
+
self::$rejectReasonCode = self::REJECT_REASON_TOKEN_SUBMITTED_EARLY;
|
168 |
+
return false;
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
if(count(array_diff($arrDecryptedToken, $arrTokenData)) !== 0)
|
173 |
+
{
|
174 |
+
self::$rejectReasonCode = self::REJECT_REASON_TOKEN_INVALID;
|
175 |
+
return false;
|
176 |
+
}
|
177 |
+
|
178 |
+
unset($_POST[self::$browserInfoInputName], $_POST[$hiddenInputName]);
|
179 |
+
|
180 |
+
global $ultimatemember;
|
181 |
+
|
182 |
+
if(isset($ultimatemember->form))
|
183 |
+
{
|
184 |
+
unset($ultimatemember->form->post_form[self::$browserInfoInputName], $ultimatemember->form->post_form[$hiddenInputName]);
|
185 |
+
unset($ultimatemember->form->post_form['submitted'][self::$browserInfoInputName], $ultimatemember->form->post_form['submitted'][$hiddenInputName]);
|
186 |
+
}
|
187 |
+
|
188 |
+
return true;
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
|
193 |
+
public static function getEncryptedToken()
|
194 |
+
{
|
195 |
+
if( ! isset($_POST['browserInfo']) || null === ($arrBrowserInfo = json_decode(stripcslashes($_POST['browserInfo']), true)))
|
196 |
+
return array();
|
197 |
+
|
198 |
+
foreach ((array)$arrBrowserInfo as $prop => $propValue)
|
199 |
+
{
|
200 |
+
if(!is_array($propValue) && false === strpos($prop, ' '))
|
201 |
+
continue;
|
202 |
+
|
203 |
+
unset($arrBrowserInfo[$prop]);
|
204 |
+
}
|
205 |
+
|
206 |
+
if( ($arrBrowserInfoLength = count($arrBrowserInfo)) < 3)
|
207 |
+
return array();
|
208 |
+
|
209 |
+
$arrKeysToSave = array_flip((array)array_rand($arrBrowserInfo, mt_rand(3, $arrBrowserInfoLength - 1)));
|
210 |
+
|
211 |
+
foreach ($arrKeysToSave as $key => &$val)
|
212 |
+
{
|
213 |
+
$val = var_export($arrBrowserInfo[$key], true);
|
214 |
+
}
|
215 |
+
|
216 |
+
$arrTokenData = self::getTokenData();
|
217 |
+
$browserField = MchGdbcUtils::replaceNonAlphaCharacters(MchCrypt::getRandomString(25), '-');
|
218 |
+
|
219 |
+
array_unshift($arrTokenData, $browserField . self::TOKEN_SEPARATOR . MchGdbcUtils::replaceNonAlphaNumericCharacters(implode('', array_values($arrKeysToSave)), ''));
|
220 |
+
|
221 |
+
return array(
|
222 |
+
'token' => MchCrypt::encryptToken(GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_TOKEN_SECRET_KEY), json_encode($arrTokenData)),
|
223 |
+
$browserField => implode(self::TOKEN_SEPARATOR, array_keys($arrKeysToSave))
|
224 |
+
);
|
225 |
+
|
226 |
+
}
|
227 |
+
|
228 |
+
|
229 |
+
private static function getTokenData()
|
230 |
+
{
|
231 |
+
$arrData = array();
|
232 |
+
|
233 |
+
$arrData[] = get_current_blog_id();
|
234 |
+
$arrData[] = GdbcIPUtils::getClientIpAddress();
|
235 |
+
$arrData[] = GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_TOKEN_CREATED_TIMESTAMP);
|
236 |
+
$arrData[] = MchGdbcHttpRequest::getServerRequestTime();
|
237 |
+
|
238 |
+
return array_filter($arrData);
|
239 |
+
}
|
240 |
+
|
241 |
+
public static function tokenAlreadyRejected()
|
242 |
+
{
|
243 |
+
return null !== self::$rejectReasonCode;
|
244 |
+
}
|
245 |
+
|
246 |
+
public static function getRejectReasonId()
|
247 |
+
{
|
248 |
+
return self::$rejectReasonCode;
|
249 |
+
}
|
250 |
+
|
251 |
+
public static function getRejectReasonDescription($reasonId)
|
252 |
+
{
|
253 |
+
static $arrReasonDescription = null;
|
254 |
+
if(null === $arrReasonDescription)
|
255 |
+
{
|
256 |
+
$arrReasonDescription = array(
|
257 |
+
|
258 |
+
self::REJECT_REASON_TOKEN_INVALID => __('Invalid Token', GoodByeCaptcha::PLUGIN_SLUG),
|
259 |
+
self::REJECT_REASON_TOKEN_MISSING => __('Token Not Submitted', GoodByeCaptcha::PLUGIN_SLUG),
|
260 |
+
self::REJECT_REASON_TOKEN_EXPIRED => __('Token Expired', GoodByeCaptcha::PLUGIN_SLUG),
|
261 |
+
self::REJECT_REASON_TOKEN_SUBMITTED_EARLY => __('Token Submitted Early', GoodByeCaptcha::PLUGIN_SLUG),
|
262 |
+
self::REJECT_REASON_CLIENT_IP_BLOCKED => __('Client IP Blocked', GoodByeCaptcha::PLUGIN_SLUG),
|
263 |
+
self::REJECT_REASON_BROWSER_INFO_MISSING => __('Browser Info Missing', GoodByeCaptcha::PLUGIN_SLUG),
|
264 |
+
self::REJECT_REASON_BROWSER_INFO_INVALID => __('Browser Info Invalid', GoodByeCaptcha::PLUGIN_SLUG),
|
265 |
+
self::REJECT_REASON_CLIENT_IP_UNDETECTABLE => __('Undetectable Client IP', GoodByeCaptcha::PLUGIN_SLUG),
|
266 |
+
self::REJECT_REASON_USER_ENUMERATION => __('User Enumeration', GoodByeCaptcha::PLUGIN_SLUG),
|
267 |
+
self::REJECT_REASON_PROXY_ANONYMIZER => __('Proxy Anonymizer', GoodByeCaptcha::PLUGIN_SLUG),
|
268 |
+
self::REJECT_REASON_WEB_ATTACKER => __('Web Attacker', GoodByeCaptcha::PLUGIN_SLUG),
|
269 |
+
self::REJECT_REASON_SERVICE_UNAVAILABLE => __('Service Unavailable', GoodByeCaptcha::PLUGIN_SLUG),
|
270 |
+
);
|
271 |
+
}
|
272 |
+
|
273 |
+
return isset($arrReasonDescription[$reasonId]) ? $arrReasonDescription[$reasonId] : __('Unknown', GoodByeCaptcha::PLUGIN_SLUG);
|
274 |
+
|
275 |
+
}
|
276 |
+
|
277 |
+
|
278 |
+
public static function getPostedBrowserInfoInputName()
|
279 |
+
{
|
280 |
+
return self::$browserInfoInputName;
|
281 |
+
}
|
282 |
+
|
283 |
+
public static function redirectToHomePage()
|
284 |
+
{
|
285 |
+
wp_redirect( home_url() ); exit;
|
286 |
+
}
|
287 |
+
|
288 |
+
}
|
{engine → 2.0/engine}/GdbcTaskScheduler.php
RENAMED
File without changes
|
2.0/engine/GdbcUpdatesController.php
ADDED
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GdbcUpdatesController
|
21 |
+
{
|
22 |
+
public static function updateToCurrentVersion()
|
23 |
+
{
|
24 |
+
|
25 |
+
if(null === ($settingsModuleInstance = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::MODULE_SETTINGS)))
|
26 |
+
return;
|
27 |
+
|
28 |
+
$savedPluginVersion = $settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_PLUGIN_VERSION);
|
29 |
+
|
30 |
+
if(null === $savedPluginVersion) // fresh install. Save default options
|
31 |
+
{
|
32 |
+
foreach(array_keys(GdbcModulesController::getRegisteredModules()) as $moduleName)
|
33 |
+
{
|
34 |
+
if(null === ($adminModuleInstance = GdbcModulesController::getAdminModuleInstance($moduleName)))
|
35 |
+
continue;
|
36 |
+
|
37 |
+
foreach($adminModuleInstance->getDefaultOptionsValues() as $optionName => $optionValue)
|
38 |
+
{
|
39 |
+
if( ! is_scalar($optionValue) )
|
40 |
+
continue;
|
41 |
+
|
42 |
+
$adminModuleInstance->saveOption($optionName, $optionValue);
|
43 |
+
}
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
$arrPublicModulesKeys = array_flip(GdbcModulesController::getPublicModulesName());
|
48 |
+
foreach( array_keys(GdbcModulesController::getRegisteredModules()) as $registeredModuleName)
|
49 |
+
{
|
50 |
+
if( isset( $arrPublicModulesKeys[$registeredModuleName] ) )
|
51 |
+
continue;
|
52 |
+
|
53 |
+
if( ! defined("GoodByeCaptcha$registeredModuleName::MODULE_VERSION") || -1 !== version_compare(constant("GoodByeCaptcha$registeredModuleName::MODULE_VERSION"), '2.0') )
|
54 |
+
continue;
|
55 |
+
|
56 |
+
GdbcModulesController::unRegisterModule($registeredModuleName);
|
57 |
+
remove_action('plugins_loaded', array("GoodByeCaptcha$registeredModuleName", 'getInstance'));
|
58 |
+
|
59 |
+
}
|
60 |
+
remove_action('plugins_loaded', array( 'GoodByeCaptchaPro', 'getInstance' ));
|
61 |
+
|
62 |
+
if(MchGdbcWpUtils::isUserInDashboard())
|
63 |
+
{
|
64 |
+
$arrActiveSites = MchGdbcWpUtils::isMultiSite() ? MchGdbcWpUtils::getAllBlogIds() : array(get_current_blog_id());
|
65 |
+
|
66 |
+
foreach($arrActiveSites as $blogId) {
|
67 |
+
self::migrateTableDataFromV1($blogId);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
if( 0 === version_compare($savedPluginVersion, GoodByeCaptcha::PLUGIN_VERSION) )
|
72 |
+
return;
|
73 |
+
|
74 |
+
|
75 |
+
$arrActiveSites = MchGdbcWpUtils::isMultiSite() ? MchGdbcWpUtils::getAllBlogIds() : array(get_current_blog_id());
|
76 |
+
|
77 |
+
if( -1 === version_compare($savedPluginVersion, '2.0') )
|
78 |
+
{
|
79 |
+
GdbcTaskScheduler::unScheduleGdbcTasks();
|
80 |
+
delete_site_option('gdbc-blocked-attempts');
|
81 |
+
|
82 |
+
self::updateToVersion_2_0();
|
83 |
+
|
84 |
+
foreach($arrActiveSites as $blogId){
|
85 |
+
self::migrateTableDataFromV1($blogId);
|
86 |
+
}
|
87 |
+
|
88 |
+
}
|
89 |
+
|
90 |
+
|
91 |
+
$settingsModuleInstance->saveOption(GdbcSettingsAdminModule::OPTION_PLUGIN_VERSION, GoodByeCaptcha::PLUGIN_VERSION);
|
92 |
+
|
93 |
+
|
94 |
+
GoodByeCaptchaUtils::flushSiteCache();
|
95 |
+
|
96 |
+
if(GoodByeCaptcha::isNetworkActivated()){
|
97 |
+
foreach($arrActiveSites as $blogId){
|
98 |
+
$blogId != get_current_blog_id() ? GoodByeCaptchaUtils::flushSiteCache($blogId) : null;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
|
103 |
+
}
|
104 |
+
|
105 |
+
private static function updateToVersion_2_0()
|
106 |
+
{
|
107 |
+
global $wpdb;
|
108 |
+
|
109 |
+
$suppressOldValue = $wpdb->suppress_errors(true);
|
110 |
+
$wpdb->hide_errors();
|
111 |
+
|
112 |
+
if(!GdbcDbAccessController::attemptsTableExists()){
|
113 |
+
GdbcDbAccessController::createAttemptsTable();
|
114 |
+
}
|
115 |
+
|
116 |
+
$arrBlogs = MchGdbcWpUtils::isMultiSite() ? MchGdbcWpUtils::getAllBlogIds() : array(get_current_blog_id());
|
117 |
+
|
118 |
+
foreach($arrBlogs as $blogId)
|
119 |
+
{
|
120 |
+
$blogTablePrefix = $wpdb->get_blog_prefix($blogId);
|
121 |
+
|
122 |
+
$gdbcTableName = $blogTablePrefix . 'gdbc_attempts';
|
123 |
+
|
124 |
+
if($wpdb->get_var("SHOW TABLES LIKE '$gdbcTableName'") !== $gdbcTableName)
|
125 |
+
continue;
|
126 |
+
|
127 |
+
$arrQueryResult = $wpdb->get_results("SELECT * FROM $gdbcTableName LIMIT 1");
|
128 |
+
|
129 |
+
if(isset($arrQueryResult[0]->IsDeleted) || empty($arrQueryResult)) {
|
130 |
+
$wpdb->query( "RENAME TABLE $gdbcTableName TO {$gdbcTableName}_old" );
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
GdbcDbAccessController::createAttemptsTable();
|
135 |
+
|
136 |
+
$wpdb->suppress_errors($suppressOldValue);
|
137 |
+
|
138 |
+
}
|
139 |
+
|
140 |
+
private static function migrateTableDataFromV1($blogId)
|
141 |
+
{
|
142 |
+
global $wpdb;
|
143 |
+
$blogTablePrefix = $wpdb->get_blog_prefix($blogId);
|
144 |
+
|
145 |
+
$gdbcOldTableName = $blogTablePrefix . 'gdbc_attempts_old' ;
|
146 |
+
|
147 |
+
if($wpdb->get_var("SHOW TABLES LIKE '$gdbcOldTableName'") !== $gdbcOldTableName)
|
148 |
+
return;
|
149 |
+
|
150 |
+
if( ! GdbcDbAccessController::attemptsTableExists() )
|
151 |
+
return;
|
152 |
+
|
153 |
+
$alreadyBlockedIpsList = (array)$wpdb->get_results("SELECT DISTINCT ClientIp FROM $gdbcOldTableName WHERE IsIpBlocked <> 0 AND IsDeleted = 0");
|
154 |
+
|
155 |
+
foreach($alreadyBlockedIpsList as $ipAddressObject)
|
156 |
+
{
|
157 |
+
$clientIp = MchGdbcIPUtils::ipAddressFromBinary($ipAddressObject->ClientIp);
|
158 |
+
if(!MchGdbcIPUtils::isValidIpAddress($clientIp))
|
159 |
+
continue;
|
160 |
+
|
161 |
+
if(GdbcIPUtils::isIpBlackListed($clientIp))
|
162 |
+
continue;
|
163 |
+
|
164 |
+
GdbcBlackListedIpsAdminModule::getInstance()->registerBlackListedIp($clientIp);
|
165 |
+
|
166 |
+
}
|
167 |
+
|
168 |
+
unset($alreadyBlockedIpsList, $ipAddressObject, $clientIp);
|
169 |
+
|
170 |
+
|
171 |
+
$arrModulesIdMapping = array( // key - oldModuleId
|
172 |
+
1 => GdbcModulesController::MODULE_WORDPRESS ,
|
173 |
+
2 => GdbcModulesController::MODULE_JETPACK_CONTACT_FORM ,
|
174 |
+
3 => GdbcModulesController::MODULE_BUDDY_PRESS ,
|
175 |
+
4 => GdbcModulesController::MODULE_NINJA_FORMS ,
|
176 |
+
5 => GdbcModulesController::MODULE_CONTACT_FORM_7 ,
|
177 |
+
6 => GdbcModulesController::MODULE_GRAVITY_FORMS ,
|
178 |
+
7 => GdbcModulesController::MODULE_FAST_SECURE_FORM ,
|
179 |
+
8 => GdbcModulesController::MODULE_FORMIDABLE_FORMS ,
|
180 |
+
9 => GdbcModulesController::MODULE_MAIL_CHIMP_FOR_WP ,
|
181 |
+
11 => GdbcModulesController::MODULE_USER_PRO ,
|
182 |
+
12 => GdbcModulesController::MODULE_ULTIMATE_MEMBER ,
|
183 |
+
13 => GdbcModulesController::MODULE_WOOCOMMERCE ,
|
184 |
+
14 => GdbcModulesController::MODULE_UPME ,
|
185 |
+
15 => GdbcModulesController::MODULE_PLANSO_FORMS ,
|
186 |
+
16 => GdbcModulesController::MODULE_SEAMLESS_DONATIONS ,
|
187 |
+
);
|
188 |
+
|
189 |
+
|
190 |
+
|
191 |
+
$minDateTime = date('Y-m-d H:i:s', strtotime(((-1) * (30)) . ' days', current_time( 'timestamp' )));
|
192 |
+
$maxDateTime = date('Y-m-d H:i:s', current_time( 'timestamp' ));
|
193 |
+
|
194 |
+
$gdbcAttemptsQuery = "
|
195 |
+
SELECT Id, UNIX_TIMESTAMP(CreatedDate) AS CreatedDate, ModuleId, SectionId, ClientIp, CountryId, ReasonId
|
196 |
+
FROM $gdbcOldTableName WHERE IsDeleted = 0 AND CreatedDate BETWEEN '$minDateTime' AND '$maxDateTime' order by CreatedDate DESC LIMIT 500;
|
197 |
+
";
|
198 |
+
|
199 |
+
|
200 |
+
$gdbcAttemptsList = (array)$wpdb->get_results($gdbcAttemptsQuery);
|
201 |
+
|
202 |
+
$oldSettingsOptions = get_site_option('gdbcsettingsadminmodule-settings');
|
203 |
+
if(!empty($oldSettingsOptions['TrustedIps'][0]) && MchGdbcIPUtils::isValidIpAddress($oldSettingsOptions['TrustedIps'][0]))
|
204 |
+
{
|
205 |
+
if(!GdbcIPUtils::isIpWhiteListed($oldSettingsOptions['TrustedIps'][0])){
|
206 |
+
GdbcWhiteListedIpsAdminModule::getInstance()->registerWhiteListedIp($oldSettingsOptions['TrustedIps'][0]);
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
$oldSettingsOptions = get_site_option('gdbcwordpressadminmodule-settings');
|
211 |
+
if(!empty($oldSettingsOptions['IsCommentsFormActivated']))
|
212 |
+
{
|
213 |
+
GdbcWordPressAdminModule::getInstance()->saveOption(GdbcWordPressAdminModule::WORDPRESS_COMMENTS_FORM, true);
|
214 |
+
}
|
215 |
+
|
216 |
+
if(!empty($oldSettingsOptions['IsLoginFormActivated']))
|
217 |
+
{
|
218 |
+
GdbcWordPressAdminModule::getInstance()->saveOption(GdbcWordPressAdminModule::WORDPRESS_LOGIN_FORM, true);
|
219 |
+
}
|
220 |
+
if(!empty($oldSettingsOptions['IsLostPasswordFormActivated']))
|
221 |
+
{
|
222 |
+
GdbcWordPressAdminModule::getInstance()->saveOption(GdbcWordPressAdminModule::WORDPRESS_LOST_PASSWORD_FORM, true);
|
223 |
+
}
|
224 |
+
if(!empty($oldSettingsOptions['IsUserRegistrationFormActivated']))
|
225 |
+
{
|
226 |
+
GdbcWordPressAdminModule::getInstance()->saveOption(GdbcWordPressAdminModule::WORDPRESS_REGISTRATION_FORM, true);
|
227 |
+
}
|
228 |
+
|
229 |
+
$oldSettingsOptions = get_site_option('gdbcultimatememberadminmodule-settings');
|
230 |
+
if(!empty($oldSettingsOptions['IsUMLoginActivated']) && GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_ULTIMATE_MEMBER))
|
231 |
+
{
|
232 |
+
GdbcUltimateMemberAdminModule::getInstance()->saveOption(GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOGIN_FORM, true);
|
233 |
+
}
|
234 |
+
if(!empty($oldSettingsOptions['IsUMRegisterActivated']) && GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_ULTIMATE_MEMBER))
|
235 |
+
{
|
236 |
+
GdbcUltimateMemberAdminModule::getInstance()->saveOption(GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_REGISTER_FORM, true);
|
237 |
+
}
|
238 |
+
if(!empty($oldSettingsOptions['IsUMLostPasswordActivated']) && GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_ULTIMATE_MEMBER))
|
239 |
+
{
|
240 |
+
GdbcUltimateMemberAdminModule::getInstance()->saveOption(GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOST_PASSWORD_FORM, true);
|
241 |
+
}
|
242 |
+
|
243 |
+
$oldSettingsOptions = get_site_option('gdbcsubscriptionsadminmodule-settings');
|
244 |
+
if(!empty($oldSettingsOptions['IsMCLActivated']) && GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_MAIL_CHIMP_FOR_WP))
|
245 |
+
{
|
246 |
+
GdbcMailChimpForWpAdminModule::getInstance()->saveOption(GdbcMailChimpForWpAdminModule::OPTION_MODULE_MAIL_CHIMP_FOR_WP, true);
|
247 |
+
}
|
248 |
+
|
249 |
+
$oldSettingsOptions = get_site_option('gdbcpopularformsadminmodule-settings');
|
250 |
+
if(!empty($oldSettingsOptions['IsJCFctivated']) && GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_JETPACK_CONTACT_FORM))
|
251 |
+
{
|
252 |
+
GdbcJetPackContactFormAdminModule::getInstance()->saveOption(GdbcJetPackContactFormAdminModule::OPTION_IS_JETPACK_CONTACT_FORM_ACTIVATE, true);
|
253 |
+
}
|
254 |
+
if(!empty($oldSettingsOptions['IsPFActivated']) && GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_PLANSO_FORMS))
|
255 |
+
{
|
256 |
+
GdbcPlanSoFormsAdminModule::getInstance()->saveOption(GdbcPlanSoFormsAdminModule::OPTION_PLANSO_GENERAL_FORM, true);
|
257 |
+
}
|
258 |
+
|
259 |
+
delete_site_option('gdbcsettingsadminmodule-settings');
|
260 |
+
delete_site_option('gdbcwordpressadminmodule-settings');
|
261 |
+
delete_site_option('gdbcultimatememberadminmodule-settings');
|
262 |
+
delete_site_option('gdbcsubscriptionsadminmodule-settings');
|
263 |
+
delete_site_option('gdbcpopularformsadminmodule-settings');
|
264 |
+
|
265 |
+
if(empty($gdbcAttemptsList)) {
|
266 |
+
|
267 |
+
foreach(GdbcModulesController::getRegisteredModules() as $moduleName => $arrModuleInfo)
|
268 |
+
{
|
269 |
+
if(null === ($adminModuleInstance = GdbcModulesController::getAdminModuleInstance($moduleName)))
|
270 |
+
continue;
|
271 |
+
|
272 |
+
$oldOptionKey = strtolower(get_class($adminModuleInstance)) . '-settings';
|
273 |
+
|
274 |
+
MchGdbcWpUtils::isMultiSite() && function_exists('delete_blog_option') ? delete_blog_option($blogId, $oldOptionKey) : delete_option($oldOptionKey);
|
275 |
+
}
|
276 |
+
|
277 |
+
|
278 |
+
$wpdb->query("DROP TABLE IF EXISTS $gdbcOldTableName");
|
279 |
+
return;
|
280 |
+
}
|
281 |
+
|
282 |
+
$arrSelectedIds = array();
|
283 |
+
foreach($gdbcAttemptsList as $gdbcAttempt)
|
284 |
+
{
|
285 |
+
|
286 |
+
empty($gdbcAttempt->SectionId) ? $gdbcAttempt->SectionId = 0 : null;
|
287 |
+
|
288 |
+
$newModuleName = isset($arrModulesIdMapping[$gdbcAttempt->ModuleId]) ? $arrModulesIdMapping[$gdbcAttempt->ModuleId] : null;
|
289 |
+
$newModuleId = GdbcModulesController::getModuleIdByName($newModuleName);
|
290 |
+
|
291 |
+
if(empty($newModuleId))
|
292 |
+
continue;
|
293 |
+
|
294 |
+
$attemptEntity = new GdbcAttemptEntity($newModuleId);
|
295 |
+
|
296 |
+
$attemptEntity->ModuleId = $newModuleId;
|
297 |
+
$attemptEntity->SectionId = !empty($gdbcAttempt->SectionId) ? $gdbcAttempt->SectionId : 0;
|
298 |
+
$attemptEntity->SiteId = $blogId;
|
299 |
+
$attemptEntity->CreatedDate = $gdbcAttempt->CreatedDate;
|
300 |
+
$attemptEntity->ReasonId = $gdbcAttempt->ReasonId;
|
301 |
+
$attemptEntity->ClientIp = MchGdbcIPUtils::ipAddressFromBinary($gdbcAttempt->ClientIp);
|
302 |
+
|
303 |
+
|
304 |
+
if(0 !== GdbcDbAccessController::registerAttempt($attemptEntity)) {
|
305 |
+
$arrSelectedIds[] = $gdbcAttempt->Id;
|
306 |
+
}
|
307 |
+
|
308 |
+
}
|
309 |
+
|
310 |
+
$wpdb->query("DELETE FROM $gdbcOldTableName WHERE Id IN (" . implode(',', $arrSelectedIds) . ")");
|
311 |
+
|
312 |
+
}
|
313 |
+
|
314 |
+
|
315 |
+
private function __construct()
|
316 |
+
{}
|
317 |
+
}
|
2.0/engine/GoodByeCaptchaAdmin.php
ADDED
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GoodByeCaptchaAdmin extends MchGdbcBaseAdminPlugin
|
21 |
+
{
|
22 |
+
CONST GDBC_ADMIN_NOTICES_FILTER_KEY = 'gdbc-admin-notices';
|
23 |
+
|
24 |
+
private static $adminNoticesList = array();
|
25 |
+
|
26 |
+
protected function __construct(array $arrPluginInfo)
|
27 |
+
{
|
28 |
+
|
29 |
+
parent::__construct($arrPluginInfo);
|
30 |
+
|
31 |
+
$this->adminPagesList = array(
|
32 |
+
|
33 |
+
new GdbcSettingsAdminPage(__('Settings', self::$PLUGIN_SLUG), __('General Settings', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
34 |
+
new GdbcSecurityAdminPage(__('Security', self::$PLUGIN_SLUG), __('Security Settings', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
35 |
+
new GdbcWordpressAdminPage(__('WordPress', self::$PLUGIN_SLUG), __('WordPress Settings', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
36 |
+
new GdbcContactFormsAdminPage(__('Contact Forms', self::$PLUGIN_SLUG), __('Contact Forms Plugins', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
37 |
+
new GdbcMembershipAdminPage(__('Membership', self::$PLUGIN_SLUG), __('Membership Page Settings', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
38 |
+
new GdbcOthersAdminPage(__('Others', self::$PLUGIN_SLUG), __('All other popular plugins settings', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
39 |
+
new GdbcNotificationsAdminPage(__('Notifications', self::$PLUGIN_SLUG), __('Notifications Settings', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
40 |
+
new GdbcReportsAdminPage(__('Reports', self::$PLUGIN_SLUG), __('GoodBye Captcha - Blocked Attempts', self::$PLUGIN_SLUG), self::$PLUGIN_SLUG),
|
41 |
+
|
42 |
+
);
|
43 |
+
|
44 |
+
|
45 |
+
if(MchGdbcWpUtils::isMultiSite() && GoodByeCaptcha::isNetworkActivated())
|
46 |
+
{
|
47 |
+
add_action( 'network_admin_menu', array( $this, 'buildPluginMenu' ), 10 );
|
48 |
+
}
|
49 |
+
else
|
50 |
+
{
|
51 |
+
add_action( 'admin_menu', array( $this, 'buildPluginMenu' ), 10 );
|
52 |
+
}
|
53 |
+
|
54 |
+
foreach(self::getAdminRegisteredNotices() as $adminNotice)
|
55 |
+
{
|
56 |
+
if($adminNotice->isDismissible() && $adminNotice->isDismissed())
|
57 |
+
continue;
|
58 |
+
|
59 |
+
if(MchGdbcWpUtils::isMultiSite() && GoodByeCaptcha::isNetworkActivated())
|
60 |
+
{
|
61 |
+
add_action('network_admin_notices', array($adminNotice, 'showNotice'));
|
62 |
+
}
|
63 |
+
else
|
64 |
+
{
|
65 |
+
add_action( 'admin_notices', array( $adminNotice, 'showNotice' ) );
|
66 |
+
}
|
67 |
+
|
68 |
+
}
|
69 |
+
|
70 |
+
}
|
71 |
+
|
72 |
+
public static function getAdminRegisteredNotices()
|
73 |
+
{
|
74 |
+
if( empty(self::$adminNoticesList) )
|
75 |
+
self::registerAdminNotices();
|
76 |
+
|
77 |
+
return self::$adminNoticesList = apply_filters(self::GDBC_ADMIN_NOTICES_FILTER_KEY, self::$adminNoticesList);
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
+
private static function registerAdminNotices()
|
82 |
+
{
|
83 |
+
$bruteForceModuleInstance = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::MODULE_BRUTE_FORCE);
|
84 |
+
|
85 |
+
if( !GdbcIPUtils::isClientIpWhiteListed() && GdbcIPUtils::isClientIpWebAttacker(true) && $bruteForceModuleInstance)
|
86 |
+
{
|
87 |
+
$bruteForceModuleInstance->deleteOption(GdbcBruteForceAdminModule::OPTION_BLOCK_WEB_ATTACKERS, GoodByeCaptcha::isNetworkActivated());
|
88 |
+
$adminNotice = new GdbcAdminNotice( GdbcAdminNotice::USER_IP_WEB_ATTACKER_NOTICE_KEY, GdbcAdminNotice::NOTICE_TYPE_DANGER );
|
89 |
+
|
90 |
+
$noticeMessage = '<p><b>';
|
91 |
+
$noticeMessage .= sprintf( __( "Your IP Address - %s - is reported as a Web Attacker! In order to keep <b>Block Web Attackers IPs</b> option activated you must white-list your IP Address!", GoodByeCaptcha::PLUGIN_SLUG ), esc_html( GdbcIPUtils::getClientIpAddress() ) );
|
92 |
+
$noticeMessage .= '</b></p>';
|
93 |
+
|
94 |
+
$adminNotice->setMessage( $noticeMessage );
|
95 |
+
$adminNotice->setIsDismissible( true );
|
96 |
+
|
97 |
+
self::$adminNoticesList[] = $adminNotice;
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
if( !GdbcIPUtils::isClientIpWhiteListed() && GdbcIPUtils::isClientIpProxyAnonymizer(true))
|
102 |
+
{
|
103 |
+
$bruteForceModuleInstance->deleteOption(GdbcBruteForceAdminModule::OPTION_BLOCK_ANONYMOUS_PROXY, GoodByeCaptcha::isNetworkActivated());
|
104 |
+
|
105 |
+
$adminNotice = new GdbcAdminNotice(GdbcAdminNotice::USER_IP_PROXY_ANONYM_NOTICE_KEY, GdbcAdminNotice::NOTICE_TYPE_DANGER);
|
106 |
+
$noticeMessage = '<p><b>';
|
107 |
+
$noticeMessage .= sprintf(__("Your IP Address - %s - is reported as a dangerous Anonymous Proxy IP! In order to keep <b>Block Anonymous Proxy IPs</b> option activated you must white-list your IP Address!", GoodByeCaptcha::PLUGIN_SLUG), esc_html(GdbcIPUtils::getClientIpAddress()));
|
108 |
+
$noticeMessage .= '</b></p>';
|
109 |
+
|
110 |
+
$adminNotice->setMessage($noticeMessage);
|
111 |
+
$adminNotice->setIsDismissible(false);
|
112 |
+
|
113 |
+
self::$adminNoticesList[] = $adminNotice;
|
114 |
+
|
115 |
+
}
|
116 |
+
|
117 |
+
}
|
118 |
+
|
119 |
+
public function renderPluginActiveAdminPage()
|
120 |
+
{
|
121 |
+
$activeAdminPage = $this->getActivePage();
|
122 |
+
|
123 |
+
$adminPageHtmlCode = '<div class="' . "wrap container-fluid gdbc-settings " . $activeAdminPage->getAdminScreenId() . '">';
|
124 |
+
|
125 |
+
$adminPageHtmlCode .= '<h2 class="nav-tab-wrapper">';
|
126 |
+
|
127 |
+
foreach($this->getRegisteredAdminPages() as $adminPage)
|
128 |
+
{
|
129 |
+
$adminPageHtmlCode .= '<a class="nav-tab' . (($adminPage->isActive()) ? ' nav-tab-active' : '') . '" href="?page=' . $adminPage->getPageMenuSlug() . '">';
|
130 |
+
$adminPageHtmlCode .= $adminPage->getPageMenuTitle() . '</a>';
|
131 |
+
}
|
132 |
+
|
133 |
+
$adminPageHtmlCode .= '</h2>';
|
134 |
+
|
135 |
+
|
136 |
+
echo $adminPageHtmlCode;
|
137 |
+
|
138 |
+
|
139 |
+
if(null !== $activeAdminPage)
|
140 |
+
{
|
141 |
+
$activeAdminPage->renderPageContent();
|
142 |
+
}
|
143 |
+
|
144 |
+
echo '</div>';
|
145 |
+
}
|
146 |
+
|
147 |
+
public function buildPluginMenu()
|
148 |
+
{
|
149 |
+
$arrRegisteredPages = $this->getRegisteredAdminPages();
|
150 |
+
$adminFirstPage = reset($arrRegisteredPages);
|
151 |
+
if(false === $adminFirstPage)
|
152 |
+
return;
|
153 |
+
|
154 |
+
$pageAdminScreenId = add_menu_page(
|
155 |
+
$adminFirstPage->getPageBrowserTitle(),
|
156 |
+
'GoodBye Captcha',
|
157 |
+
'manage_options',
|
158 |
+
$adminFirstPage->getPageMenuSlug(),
|
159 |
+
array($this, 'renderPluginActiveAdminPage'),
|
160 |
+
'dashicons-shield',
|
161 |
+
'53.8393'
|
162 |
+
);
|
163 |
+
|
164 |
+
$this->adminPagesList[0]->setAdminScreenId($pageAdminScreenId);
|
165 |
+
|
166 |
+
$arrSize = count($this->adminPagesList);
|
167 |
+
if(1 === $arrSize)
|
168 |
+
return;
|
169 |
+
|
170 |
+
add_submenu_page(
|
171 |
+
$adminFirstPage->getPageMenuSlug(),
|
172 |
+
$adminFirstPage->getPageBrowserTitle(),
|
173 |
+
$adminFirstPage->getPageMenuTitle(),
|
174 |
+
'manage_options',
|
175 |
+
$adminFirstPage->getPageMenuSlug()
|
176 |
+
);
|
177 |
+
|
178 |
+
|
179 |
+
for($i = 1; $i < $arrSize; ++$i)
|
180 |
+
{
|
181 |
+
if(!$this->adminPagesList[$i]->hasRegisteredModules())
|
182 |
+
{
|
183 |
+
unset($this->adminPagesList[$i]);
|
184 |
+
continue;
|
185 |
+
}
|
186 |
+
|
187 |
+
$pageAdminScreenId = add_submenu_page(
|
188 |
+
$adminFirstPage->getPageMenuSlug(),
|
189 |
+
$this->adminPagesList[$i]->getPageBrowserTitle(),
|
190 |
+
$this->adminPagesList[$i]->getPageMenuTitle(),
|
191 |
+
'manage_options',
|
192 |
+
$this->adminPagesList[$i]->getPageMenuSlug(),
|
193 |
+
array($this, 'renderPluginActiveAdminPage')
|
194 |
+
);
|
195 |
+
|
196 |
+
$this->adminPagesList[$i]->setAdminScreenId($pageAdminScreenId);
|
197 |
+
}
|
198 |
+
|
199 |
+
|
200 |
+
}
|
201 |
+
|
202 |
+
|
203 |
+
|
204 |
+
public function enqueueAdminScriptsAndStyles()
|
205 |
+
{
|
206 |
+
|
207 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-admin-script', plugins_url('/assets/admin/scripts/gdbc-admin.js', self::$PLUGIN_MAIN_FILE), array('jquery'), self::$PLUGIN_VERSION);
|
208 |
+
|
209 |
+
wp_localize_script(self::$PLUGIN_SLUG . '-admin-script', 'GdbcAdmin', array(
|
210 |
+
'ajaxUrl' => admin_url('admin-ajax.php'),
|
211 |
+
'ajaxRequestNonce' => wp_create_nonce(GdbcAjaxController::AJAX_NONCE_VALUE),
|
212 |
+
));
|
213 |
+
|
214 |
+
if(null === ($activeAdminPage = $this->getActivePage()))
|
215 |
+
return;
|
216 |
+
|
217 |
+
if($this->getActivePage() instanceof GdbcReportsAdminPage)
|
218 |
+
{
|
219 |
+
remove_action( 'admin_print_styles', 'print_emoji_styles' );
|
220 |
+
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
|
221 |
+
|
222 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-jquery-flot', plugins_url('/assets/admin/scripts/jquery-flot.js', self::$PLUGIN_MAIN_FILE), array('jquery'), self::$PLUGIN_VERSION);
|
223 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-jquery-flot-tooltip', plugins_url('/assets/admin/scripts/jquery-flot-tooltip.js', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
224 |
+
|
225 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-raphael', plugins_url('/assets/admin/scripts/raphael.js', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
226 |
+
|
227 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-morris', plugins_url('/assets/admin/scripts/morris.js', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
228 |
+
|
229 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-reports-script', plugins_url('/assets/admin/scripts/gdbc-reports.js', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
230 |
+
|
231 |
+
|
232 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-bootstrap', plugins_url('/assets/admin/scripts/bootstrap.min.js', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
233 |
+
|
234 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-jquery-jvectormap', plugins_url('/assets/admin/scripts/jquery-jvectormap-1.2.2.min.js', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
235 |
+
wp_enqueue_script(self::$PLUGIN_SLUG . '-jquery-jvectormap-world', plugins_url('/assets/admin/scripts/jquery-jvectormap-world-mill-en.js', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
236 |
+
|
237 |
+
wp_enqueue_style(self::$PLUGIN_SLUG . '-bootstrap', plugins_url('/assets/admin/styles/bootstrap.css', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
238 |
+
wp_enqueue_style(self::$PLUGIN_SLUG . '-morris', plugins_url('/assets/admin/styles/morris.css', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
239 |
+
}
|
240 |
+
|
241 |
+
|
242 |
+
wp_enqueue_style('dashboard');
|
243 |
+
wp_enqueue_script('dashboard');
|
244 |
+
|
245 |
+
|
246 |
+
wp_enqueue_style (self::$PLUGIN_SLUG . '-admin-style', plugins_url('/assets/admin/styles/gdbc-admin.css', self::$PLUGIN_MAIN_FILE), array(), self::$PLUGIN_VERSION);
|
247 |
+
|
248 |
+
}
|
249 |
+
|
250 |
+
|
251 |
+
public static function getInstance(array $arrPluginInfo)
|
252 |
+
{
|
253 |
+
static $gdbcAdminInstance = null;
|
254 |
+
return null !== $gdbcAdminInstance ? $gdbcAdminInstance : $gdbcAdminInstance = new self($arrPluginInfo);
|
255 |
+
}
|
256 |
+
|
257 |
+
public function initializeAdminPlugin()
|
258 |
+
{
|
259 |
+
parent::initializeAdminPlugin();
|
260 |
+
|
261 |
+
if(MchGdbcWpUtils::isAjaxRequest())
|
262 |
+
return;
|
263 |
+
|
264 |
+
|
265 |
+
add_action('shutdown', array($this, 'executeLowPriorityTasks'));
|
266 |
+
|
267 |
+
}
|
268 |
+
|
269 |
+
public function executeLowPriorityTasks()
|
270 |
+
{
|
271 |
+
|
272 |
+
GdbcDbAccessController::deleteAttemptsOlderThan(GdbcSettingsAdminModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_MAX_LOGS_DAYS));
|
273 |
+
GdbcDbAccessController::clearAttemptsNotesOlderThan(GdbcSettingsAdminModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_BLOCKED_CONTENT_LOG_DAYS));
|
274 |
+
|
275 |
+
if(null === self::$PLUGIN_MAIN_FILE)
|
276 |
+
return;
|
277 |
+
|
278 |
+
if (!current_user_can( 'manage_options' ))
|
279 |
+
return;
|
280 |
+
|
281 |
+
$pluginBaseName = plugin_basename(self::$PLUGIN_MAIN_FILE);
|
282 |
+
$arrBlogActivePlugins = (array) get_option( 'active_plugins', array() );
|
283 |
+
|
284 |
+
$firstActivatedPlugin = reset($arrBlogActivePlugins);
|
285 |
+
if(false === $firstActivatedPlugin || $firstActivatedPlugin === $pluginBaseName)
|
286 |
+
return;
|
287 |
+
|
288 |
+
$gdbcPluginKey = array_search( $pluginBaseName, $arrBlogActivePlugins );
|
289 |
+
if(false === $gdbcPluginKey)
|
290 |
+
return;
|
291 |
+
|
292 |
+
array_splice( $arrBlogActivePlugins, $gdbcPluginKey, 1 );
|
293 |
+
array_unshift( $arrBlogActivePlugins, $pluginBaseName );
|
294 |
+
|
295 |
+
update_option( 'active_plugins', $arrBlogActivePlugins );
|
296 |
+
|
297 |
+
}
|
298 |
+
|
299 |
+
|
300 |
+
public static function onPluginActivate()
|
301 |
+
{}
|
302 |
+
|
303 |
+
private function __clone()
|
304 |
+
{}
|
305 |
+
|
306 |
+
}
|
2.0/engine/GoodByeCaptchaPublic.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GoodByeCaptchaPublic extends MchGdbcBasePublicPlugin
|
21 |
+
{
|
22 |
+
|
23 |
+
private $formHiddenInputName = null;
|
24 |
+
|
25 |
+
protected function __construct(array $arrPluginInfo)
|
26 |
+
{
|
27 |
+
parent::__construct($arrPluginInfo);
|
28 |
+
|
29 |
+
if(!GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_SETTINGS))
|
30 |
+
return ;
|
31 |
+
|
32 |
+
$settingsModuleInstance = GdbcModulesController::getPublicModuleInstance(GdbcModulesController::MODULE_SETTINGS);
|
33 |
+
if(null === $settingsModuleInstance)
|
34 |
+
return;
|
35 |
+
|
36 |
+
$this->formHiddenInputName = $settingsModuleInstance->getOption(GdbcSettingsAdminModule::OPTION_HIDDEN_INPUT_NAME);
|
37 |
+
|
38 |
+
foreach(array_keys((array)GdbcModulesController::getRegisteredModules()) as $moduleName)
|
39 |
+
{
|
40 |
+
$moduleInstance = GdbcModulesController::getPublicModuleInstance($moduleName);
|
41 |
+
|
42 |
+
if( ! ($moduleInstance instanceof MchGdbcBaseModule) )
|
43 |
+
continue;
|
44 |
+
|
45 |
+
call_user_func(array($moduleInstance, 'registerAttachedHooks'));
|
46 |
+
}
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
public function initializePlugin()
|
51 |
+
{
|
52 |
+
parent::initializePlugin();
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
public function registerAfterSetupThemeHooks()
|
58 |
+
{
|
59 |
+
|
60 |
+
add_action('login_enqueue_scripts', array($this, 'enqueuePublicScriptsAndStyles'));
|
61 |
+
}
|
62 |
+
|
63 |
+
public static function getInstance(array $arrPluginInfo)
|
64 |
+
{
|
65 |
+
static $gdbcPublicInstance = null;
|
66 |
+
return null !== $gdbcPublicInstance ? $gdbcPublicInstance : $gdbcPublicInstance = new self($arrPluginInfo);
|
67 |
+
}
|
68 |
+
|
69 |
+
public function enqueuePublicScriptsAndStyles()
|
70 |
+
{
|
71 |
+
$scriptId = self::$PLUGIN_SLUG . '-public-script';
|
72 |
+
|
73 |
+
wp_register_script($scriptId, plugins_url( '/assets/public/scripts/gdbc-public.js', self::$PLUGIN_MAIN_FILE ), array( 'jquery' ), self::$PLUGIN_VERSION);
|
74 |
+
|
75 |
+
wp_localize_script($scriptId, 'Gdbc', array(
|
76 |
+
'ajaxUrl' => MchGdbcWpUtils::getAjaxUrl(),
|
77 |
+
'clientUrl' => esc_url(home_url('/', MchGdbcWpUtils::isSslRequest() ? 'https' : 'http') . '?gdbc-client=' . self::$PLUGIN_VERSION),
|
78 |
+
'formFieldName' => $this->formHiddenInputName,
|
79 |
+
'shortCode' => self::$PLUGIN_SHORT_CODE,
|
80 |
+
'slug' => self::$PLUGIN_SLUG,
|
81 |
+
));
|
82 |
+
|
83 |
+
wp_enqueue_script($scriptId);
|
84 |
+
|
85 |
+
}
|
86 |
+
|
87 |
+
|
88 |
+
private function __clone()
|
89 |
+
{}
|
90 |
+
|
91 |
+
}
|
2.0/engine/GoodByeCaptchaUtils.php
ADDED
@@ -0,0 +1,593 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GoodByeCaptchaUtils
|
21 |
+
{
|
22 |
+
|
23 |
+
public static function isZmAlrActivated()
|
24 |
+
{
|
25 |
+
return defined('ZM_ALR_NAMESPACE');
|
26 |
+
}
|
27 |
+
|
28 |
+
public static function isUserProfileMadeEasyActivated()
|
29 |
+
{
|
30 |
+
return defined('upme_path');
|
31 |
+
}
|
32 |
+
|
33 |
+
public static function isWooCommerceActivated()
|
34 |
+
{
|
35 |
+
return class_exists('WooCommerce');
|
36 |
+
}
|
37 |
+
|
38 |
+
public static function isUltimateMemberActivated()
|
39 |
+
{
|
40 |
+
return class_exists('UM_API');
|
41 |
+
}
|
42 |
+
|
43 |
+
public static function isUjiCountDownActivated()
|
44 |
+
{
|
45 |
+
return class_exists('Uji_Countdown');
|
46 |
+
}
|
47 |
+
|
48 |
+
public static function isMailChimpForWPActivated()
|
49 |
+
{
|
50 |
+
return function_exists('__mc4wp_load_plugin') || function_exists('__mc4wp_premium_load') || function_exists('mc4wp_load_plugin') || function_exists('mc4wp_pro_load_plugin');
|
51 |
+
}
|
52 |
+
|
53 |
+
public static function isNinjaFormsActivated()
|
54 |
+
{
|
55 |
+
return class_exists('Ninja_Forms');
|
56 |
+
}
|
57 |
+
|
58 |
+
public static function isPlanSoFormsActivated()
|
59 |
+
{
|
60 |
+
return function_exists('psfb_register');
|
61 |
+
}
|
62 |
+
|
63 |
+
public static function isSeamlessDonationsActivated()
|
64 |
+
{
|
65 |
+
return function_exists('seamless_donations_init');
|
66 |
+
}
|
67 |
+
|
68 |
+
public static function isGravityFormsActivated()
|
69 |
+
{
|
70 |
+
return class_exists('GFForms');
|
71 |
+
}
|
72 |
+
|
73 |
+
public static function isContactForm7Activated()
|
74 |
+
{
|
75 |
+
return class_exists('WPCF7_ContactForm');
|
76 |
+
}
|
77 |
+
|
78 |
+
public static function isFastSecureFormActivated()
|
79 |
+
{
|
80 |
+
return class_exists('FSCF_Util');
|
81 |
+
}
|
82 |
+
|
83 |
+
public static function isFormidableFormsActivated()
|
84 |
+
{
|
85 |
+
return class_exists('FrmSettings');
|
86 |
+
}
|
87 |
+
|
88 |
+
public static function isUserProPluginActivated()
|
89 |
+
{
|
90 |
+
return class_exists('userpro_api');
|
91 |
+
}
|
92 |
+
|
93 |
+
// public static function setCookie($cookieKey, $cookieValue, $cookieTime, $path = null, $httpOnly = true)
|
94 |
+
// {
|
95 |
+
// if(headers_sent()) return;
|
96 |
+
// return setcookie($cookieKey, $cookieValue, $cookieTime + (isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time()), empty($path) ? COOKIEPATH : $path, COOKIE_DOMAIN, is_ssl(), $httpOnly);
|
97 |
+
// }
|
98 |
+
//
|
99 |
+
// public static function getCookie($cookieKey)
|
100 |
+
// {
|
101 |
+
// return isset($_COOKIE[$cookieKey]) ? $_COOKIE[$cookieKey] : null;
|
102 |
+
// }
|
103 |
+
//
|
104 |
+
// public static function deleteCookie($cookieKey)
|
105 |
+
// {
|
106 |
+
// if(headers_sent()) return;
|
107 |
+
// return setcookie($cookieKey, null, (isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time()) - 3600);
|
108 |
+
// }
|
109 |
+
|
110 |
+
public static function isJetPackContactFormModuleActivated()
|
111 |
+
{
|
112 |
+
return self::isJetPackModuleActivated('contact-form');
|
113 |
+
}
|
114 |
+
|
115 |
+
public static function isJetPackCommentsModuleActivated()
|
116 |
+
{
|
117 |
+
return self::isJetPackModuleActivated('comments');
|
118 |
+
}
|
119 |
+
|
120 |
+
public static function isValidReferer()
|
121 |
+
{
|
122 |
+
static $validReferer = null;
|
123 |
+
if(null !== $validReferer)
|
124 |
+
return $validReferer;
|
125 |
+
|
126 |
+
$referer = wp_get_referer();
|
127 |
+
$actualHost = parse_url(home_url(), PHP_URL_HOST);
|
128 |
+
|
129 |
+
return $validReferer = (!empty($referer) && !empty($actualHost) && false !== stripos($referer, $actualHost));
|
130 |
+
}
|
131 |
+
|
132 |
+
public static function isNginxWebServer()
|
133 |
+
{
|
134 |
+
if(empty($_SERVER['SERVER_SOFTWARE']))
|
135 |
+
return false;
|
136 |
+
|
137 |
+
return (false !== stripos($_SERVER['SERVER_SOFTWARE'], 'nginx')) && (@php_sapi_name() === 'fpm-fcgi');
|
138 |
+
}
|
139 |
+
|
140 |
+
public static function isJetPackPluginActivated()
|
141 |
+
{
|
142 |
+
return class_exists('Jetpack');
|
143 |
+
}
|
144 |
+
|
145 |
+
private static function isJetPackModuleActivated($moduleName)
|
146 |
+
{
|
147 |
+
static $arrActivatedModules = array();
|
148 |
+
if(isset($arrActivatedModules[$moduleName]))
|
149 |
+
return $arrActivatedModules[$moduleName];
|
150 |
+
|
151 |
+
return $arrActivatedModules[$moduleName] = ((null !== ($arrJetPackModules = self::getJetPackActiveModules())) &&
|
152 |
+
in_array(strtolower($moduleName), $arrJetPackModules, true));
|
153 |
+
}
|
154 |
+
|
155 |
+
private static function getJetPackActiveModules()
|
156 |
+
{
|
157 |
+
static $isActivated = null;
|
158 |
+
(null === $isActivated) ? $isActivated = class_exists( 'Jetpack' ) : null;
|
159 |
+
|
160 |
+
if( !$isActivated)
|
161 |
+
return null;
|
162 |
+
|
163 |
+
static $arrJetPackOptions = null;
|
164 |
+
if(null !== $arrJetPackOptions)
|
165 |
+
return $arrJetPackOptions;
|
166 |
+
|
167 |
+
$arrJetPackOptions = get_option('jetpack_active_modules');
|
168 |
+
if(false === $arrJetPackOptions)
|
169 |
+
return null;
|
170 |
+
|
171 |
+
foreach ($arrJetPackOptions as &$moduleName)
|
172 |
+
$moduleName = strtolower(trim($moduleName));
|
173 |
+
|
174 |
+
return $arrJetPackOptions;
|
175 |
+
}
|
176 |
+
|
177 |
+
|
178 |
+
public static function getCountryIdByCode($countryCode)
|
179 |
+
{
|
180 |
+
$countryCode = trim(strtoupper($countryCode));
|
181 |
+
|
182 |
+
foreach (self::getCountryDataSource() as $key => $value)
|
183 |
+
if ($countryCode === $value[1])
|
184 |
+
return $key;
|
185 |
+
|
186 |
+
return 0;
|
187 |
+
}
|
188 |
+
|
189 |
+
public static function getCountryCodeById($countryId)
|
190 |
+
{
|
191 |
+
$arrCountry = self::getCountryDataSource();
|
192 |
+
return isset($arrCountry[$countryId][1]) ? $arrCountry[$countryId][1] : null;
|
193 |
+
}
|
194 |
+
|
195 |
+
public static function getCountryNameById($countryId)
|
196 |
+
{
|
197 |
+
$arrCountry = self::getCountryDataSource();
|
198 |
+
return isset($arrCountry[$countryId][0]) ? $arrCountry[$countryId][0] : null;
|
199 |
+
}
|
200 |
+
|
201 |
+
private static function getCountryDataSource()
|
202 |
+
{
|
203 |
+
return array(
|
204 |
+
1 => array("Afghanistan", "AF"),
|
205 |
+
2 => array("Aland Islands", "AX"),
|
206 |
+
3 => array("Albania", "AL"),
|
207 |
+
4 => array("Algeria", "DZ"),
|
208 |
+
5 => array("American Samoa", "AS"),
|
209 |
+
6 => array("Andorra", "AD"),
|
210 |
+
7 => array("Angola", "AO"),
|
211 |
+
8 => array("Anguilla", "AI"),
|
212 |
+
9 => array("Antarctica", "AQ"),
|
213 |
+
10 => array("Antigua and Barbuda", "AG"),
|
214 |
+
11 => array("Argentina", "AR"),
|
215 |
+
12 => array("Armenia", "AM"),
|
216 |
+
13 => array("Aruba", "AW"),
|
217 |
+
14 => array("Australia", "AU"),
|
218 |
+
15 => array("Austria", "AT"),
|
219 |
+
16 => array("Azerbaijan", "AZ"),
|
220 |
+
17 => array("Bahamas", "BS"),
|
221 |
+
18 => array("Bahrain", "BH"),
|
222 |
+
19 => array("Bangladesh", "BD"),
|
223 |
+
20 => array("Barbados", "BB"),
|
224 |
+
21 => array("Belarus", "BY"),
|
225 |
+
22 => array("Belgium", "BE"),
|
226 |
+
23 => array("Belize", "BZ"),
|
227 |
+
24 => array("Benin", "BJ"),
|
228 |
+
25 => array("Bermuda", "BM"),
|
229 |
+
26 => array("Bhutan", "BT"),
|
230 |
+
27 => array("Bolivia", "BO"),
|
231 |
+
28 => array("Bosnia and Herzegovina", "BA"),
|
232 |
+
29 => array("Botswana", "BW"),
|
233 |
+
30 => array("Bouvet island", "BV"),
|
234 |
+
31 => array("Brazil", "BR"),
|
235 |
+
32 => array("British Indian Ocean", "IO"),
|
236 |
+
33 => array("Brunei Darussalam", "BN"),
|
237 |
+
34 => array("Bulgaria", "BG"),
|
238 |
+
35 => array("Burkina Faso", "BF"),
|
239 |
+
36 => array("Burundi", "BI"),
|
240 |
+
37 => array("Cambodia", "KH"),
|
241 |
+
38 => array("Cameroon", "CM"),
|
242 |
+
39 => array("Canada", "CA"),
|
243 |
+
40 => array("Cape Verde", "CV"),
|
244 |
+
41 => array("Cayman Islands", "KY"),
|
245 |
+
42 => array("Central African Republic", "CF"),
|
246 |
+
43 => array("Chad", "TD"),
|
247 |
+
44 => array("Chile", "CL"),
|
248 |
+
45 => array("China", "CN"),
|
249 |
+
46 => array("Christmas Island", "CX"),
|
250 |
+
47 => array("Cocos Islands", "CC"),
|
251 |
+
48 => array("Colombia", "CO"),
|
252 |
+
49 => array("Comoros", "KM"),
|
253 |
+
50 => array("Congo", "CG"),
|
254 |
+
51 => array("Congo", "CD"),
|
255 |
+
52 => array("Cook Islands", "CK"),
|
256 |
+
53 => array("Costa Rica", "CR"),
|
257 |
+
54 => array("Cote d'Ivoire", "CI"),
|
258 |
+
55 => array("Croatia", "HR"),
|
259 |
+
56 => array("Cuba", "CU"),
|
260 |
+
57 => array("Cyprus", "CY"),
|
261 |
+
58 => array("Czech Republic", "CZ"),
|
262 |
+
59 => array("Denmark", "DK"),
|
263 |
+
60 => array("Djibouti", "DJ"),
|
264 |
+
61 => array("Dominica", "DM"),
|
265 |
+
62 => array("Dominican republic", "DO"),
|
266 |
+
63 => array("Ecuador", "EC"),
|
267 |
+
64 => array("Egypt", "EG"),
|
268 |
+
65 => array("El Salvador", "SV"),
|
269 |
+
66 => array("Equatorial Guinea", "GQ"),
|
270 |
+
67 => array("Eritrea", "ER"),
|
271 |
+
68 => array("Estonia", "EE"),
|
272 |
+
69 => array("Ethiopia", "ET"),
|
273 |
+
70 => array("Falkland Islands", "FK"),
|
274 |
+
71 => array("Faroe Islands", "FO"),
|
275 |
+
72 => array("Fiji", "FJ"),
|
276 |
+
73 => array("Finland", "FI"),
|
277 |
+
74 => array("France", "FR"),
|
278 |
+
75 => array("French Guiana", "GF"),
|
279 |
+
76 => array("French Polynesia", "PF"),
|
280 |
+
77 => array("French Southern Territories", "TF"),
|
281 |
+
78 => array("Gabon", "GA"),
|
282 |
+
79 => array("Gambia", "GM"),
|
283 |
+
80 => array("Georgia", "GE"),
|
284 |
+
81 => array("Germany", "DE"),
|
285 |
+
82 => array("Ghana", "GH"),
|
286 |
+
83 => array("Gibraltar", "GI"),
|
287 |
+
84 => array("Greece", "GR"),
|
288 |
+
85 => array("Greenland", "Gl"),
|
289 |
+
86 => array("Grenada", "GD"),
|
290 |
+
87 => array("Guadeloupe", "GP"),
|
291 |
+
88 => array("Guam", "GU"),
|
292 |
+
89 => array("Guatemala", "GT"),
|
293 |
+
90 => array("Guernsey", "GG"),
|
294 |
+
91 => array("Guinea", "GN"),
|
295 |
+
92 => array("Guinea-Bissau", "GW"),
|
296 |
+
93 => array("Guyana", "GY"),
|
297 |
+
94 => array("Haiti", "HT"),
|
298 |
+
95 => array("Heard and Mcdonald Islands", "HM"),
|
299 |
+
96 => array("Vatican", "VA"),
|
300 |
+
97 => array("Honduras", "HN"),
|
301 |
+
98 => array("Hong Kong", "HK"),
|
302 |
+
99 => array("Hungary", "HU"),
|
303 |
+
100 => array("Iceland", "IS"),
|
304 |
+
101 => array("India", "IN"),
|
305 |
+
102 => array("Indonesia", "ID"),
|
306 |
+
103 => array("Iran", "IR"),
|
307 |
+
104 => array("Iraq", "IQ"),
|
308 |
+
105 => array("Ireland", "IE"),
|
309 |
+
106 => array("Isle of Man", "IM"),
|
310 |
+
107 => array("Israel", "IL"),
|
311 |
+
108 => array("Italy", "IT"),
|
312 |
+
109 => array("Jamaica", "JM"),
|
313 |
+
110 => array("Japan", "JP"),
|
314 |
+
111 => array("Jersey", "JE"),
|
315 |
+
112 => array("Jordan", "JO"),
|
316 |
+
113 => array("Kazakhstan", "KZ"),
|
317 |
+
114 => array("Kenya", "KE"),
|
318 |
+
115 => array("Kiribati", "KI"),
|
319 |
+
116 => array("Korea", "KP"),
|
320 |
+
117 => array("Korea", "KR"),
|
321 |
+
118 => array("Kuwait", "KW"),
|
322 |
+
119 => array("Kyrgyzstan", "KG"),
|
323 |
+
120 => array("Lao Republic", "LA"),
|
324 |
+
121 => array("Latvia", "LV"),
|
325 |
+
122 => array("Lebanon", "LB"),
|
326 |
+
123 => array("Lesotho", "LS"),
|
327 |
+
124 => array("Liberia", "LR"),
|
328 |
+
125 => array("Libyan Arab Jamahiriya", "LY"),
|
329 |
+
126 => array("Liechtenstein", "LI"),
|
330 |
+
127 => array("Lithuania", "LT"),
|
331 |
+
128 => array("Luxembourg", "LU"),
|
332 |
+
129 => array("Macao", "MO"),
|
333 |
+
130 => array("Macedonia", "MK"),
|
334 |
+
131 => array("Madagascar", "MG"),
|
335 |
+
132 => array("Malawi", "MW"),
|
336 |
+
133 => array("Malaysia", "MY"),
|
337 |
+
134 => array("Maldives", "MV"),
|
338 |
+
135 => array("Mali", "Ml"),
|
339 |
+
136 => array("Malta", "MT"),
|
340 |
+
137 => array("Marshall Islands", "MH"),
|
341 |
+
138 => array("Martinique", "MQ"),
|
342 |
+
139 => array("Mauritania", "MR"),
|
343 |
+
140 => array("Mauritius", "MU"),
|
344 |
+
141 => array("Mayotte", "YT"),
|
345 |
+
142 => array("Mexico", "MX"),
|
346 |
+
143 => array("Micronesia", "FM"),
|
347 |
+
144 => array("Moldova", "MD"),
|
348 |
+
145 => array("Monaco", "MC"),
|
349 |
+
146 => array("Mongolia", "MN"),
|
350 |
+
147 => array("Montenegro", "ME"),
|
351 |
+
148 => array("Montserrat", "MS"),
|
352 |
+
149 => array("Morocco", "MA"),
|
353 |
+
150 => array("Mozambique", "MZ"),
|
354 |
+
151 => array("Myanmar", "MM"),
|
355 |
+
152 => array("Namibia", "NA"),
|
356 |
+
153 => array("Nauru", "NR"),
|
357 |
+
154 => array("Nepal", "NP"),
|
358 |
+
155 => array("Netherlands", "NL"),
|
359 |
+
156 => array("Netherlands Antilles", "AN"),
|
360 |
+
157 => array("New Caledonia", "NC"),
|
361 |
+
158 => array("New Zealand", "NZ"),
|
362 |
+
159 => array("Nicaragua", "NI"),
|
363 |
+
160 => array("Niger", "NE"),
|
364 |
+
161 => array("Nigeria", "NG"),
|
365 |
+
162 => array("Niue", "NU"),
|
366 |
+
163 => array("Norfolk Island", "NF"),
|
367 |
+
164 => array("Northern Mariana Islands", "MP"),
|
368 |
+
165 => array("Norway", "NO"),
|
369 |
+
166 => array("Oman", "OM"),
|
370 |
+
167 => array("Pakistan", "PK"),
|
371 |
+
168 => array("Palau", "PW"),
|
372 |
+
169 => array("Palestinian Territory Occupied", "PS"),
|
373 |
+
170 => array("Panama", "PA"),
|
374 |
+
171 => array("Papua New Guinea", "PG"),
|
375 |
+
172 => array("Paraguay", "PY"),
|
376 |
+
173 => array("Peru", "PE"),
|
377 |
+
174 => array("Philippines", "PH"),
|
378 |
+
175 => array("Pitcairn", "PN"),
|
379 |
+
176 => array("Poland", "PL"),
|
380 |
+
177 => array("Portugal", "PT"),
|
381 |
+
178 => array("Puerto rico", "PR"),
|
382 |
+
179 => array("Qatar", "QA"),
|
383 |
+
180 => array("Reunion", "RE"),
|
384 |
+
181 => array("Romania", "RO"),
|
385 |
+
182 => array("Russian Federation", "RU"),
|
386 |
+
183 => array("Rwanda", "RW"),
|
387 |
+
184 => array("Saint Barthelemy", "BL"),
|
388 |
+
185 => array("Saint Helena", "SH"),
|
389 |
+
186 => array("Saint Kitts and Nevis", "KN"),
|
390 |
+
187 => array("Saint Lucia", "LC"),
|
391 |
+
188 => array("Saint Martin", "MF"),
|
392 |
+
189 => array("Saint Pierre and Miquelon", "PM"),
|
393 |
+
190 => array("Saint Vincent", "VC"),
|
394 |
+
191 => array("Samoa", "WS"),
|
395 |
+
192 => array("San Marino", "SM"),
|
396 |
+
193 => array("Sao Tome and Principe", "ST"),
|
397 |
+
194 => array("Saudi Arabia", "SA"),
|
398 |
+
195 => array("Senegal", "SN"),
|
399 |
+
196 => array("Serbia", "RS"),
|
400 |
+
197 => array("Seychelles", "SC"),
|
401 |
+
198 => array("Sierra Leone", "SL"),
|
402 |
+
199 => array("Singapore", "SG"),
|
403 |
+
200 => array("Slovakia", "SK"),
|
404 |
+
201 => array("Slovenia", "SI"),
|
405 |
+
202 => array("Solomon Islands", "SB"),
|
406 |
+
203 => array("Somalia", "SO"),
|
407 |
+
204 => array("South Africa", "ZA"),
|
408 |
+
205 => array("South Georgia and Islands", "GS"),
|
409 |
+
206 => array("Spain", "ES"),
|
410 |
+
207 => array("Sri Lanka", "LK"),
|
411 |
+
208 => array("Sudan", "SD"),
|
412 |
+
209 => array("Suriname", "SR"),
|
413 |
+
210 => array("Svalbard and Jan Mayen", "SJ"),
|
414 |
+
211 => array("Swaziland", "SZ"),
|
415 |
+
212 => array("Sweden", "SE"),
|
416 |
+
213 => array("Switzerland", "CH"),
|
417 |
+
214 => array("Syrian Arab Republic", "SY"),
|
418 |
+
215 => array("Taiwan", "TW"),
|
419 |
+
216 => array("Tajikistan", "TJ"),
|
420 |
+
217 => array("Tanzania", "TZ"),
|
421 |
+
218 => array("Thailand", "TH"),
|
422 |
+
219 => array("Timor-Leste", "TL"),
|
423 |
+
220 => array("Togo", "TG"),
|
424 |
+
221 => array("Tokelau", "TK"),
|
425 |
+
222 => array("Tonga", "TO"),
|
426 |
+
223 => array("Trinidad and Tobago", "TT"),
|
427 |
+
224 => array("Tunisia", "TN"),
|
428 |
+
225 => array("Turkey", "TR"),
|
429 |
+
226 => array("Turkmenistan", "TM"),
|
430 |
+
227 => array("Turks and Caicos Islands", "TC"),
|
431 |
+
228 => array("Tuvalu", "TV"),
|
432 |
+
229 => array("Uganda", "UG"),
|
433 |
+
230 => array("Ukraine", "UA"),
|
434 |
+
231 => array("United Arab Emirates", "AE"),
|
435 |
+
232 => array("United Kingdom", "GB"),
|
436 |
+
233 => array("United States", "US"),
|
437 |
+
234 => array("United States Minor Islands", "UM"),
|
438 |
+
235 => array("Uruguay", "UY"),
|
439 |
+
236 => array("Uzbekistan", "UZ"),
|
440 |
+
237 => array("Vanuatu", "VU"),
|
441 |
+
238 => array("Venezuela", "VE"),
|
442 |
+
239 => array("Vietnam", "VN"),
|
443 |
+
240 => array("Virgin Islands British", "VG"),
|
444 |
+
241 => array("Virgin Islands U.S.", "VI"),
|
445 |
+
242 => array("Wallis and Futuna", "WF"),
|
446 |
+
243 => array("Western Sahara", "EH"),
|
447 |
+
244 => array("Yemen", "YE"),
|
448 |
+
245 => array("Zambia", "ZM"),
|
449 |
+
246 => array("Zimbabwe", "ZW")
|
450 |
+
);
|
451 |
+
}
|
452 |
+
|
453 |
+
public static function isLoginAttemptEntity(GdbcAttemptEntity $attemptEntity)
|
454 |
+
{
|
455 |
+
foreach(self::getAllPossibleLoginAttemptEntities() as $loginAttemptEntity)
|
456 |
+
{
|
457 |
+
if( ($loginAttemptEntity->ModuleId == $attemptEntity->ModuleId) && ($loginAttemptEntity->SectionId == $attemptEntity->SectionId) )
|
458 |
+
return true;
|
459 |
+
}
|
460 |
+
|
461 |
+
return false;
|
462 |
+
}
|
463 |
+
|
464 |
+
public static function getAllPossibleLoginAttemptEntities()
|
465 |
+
{
|
466 |
+
static $loginEntitiesList = null;
|
467 |
+
if(null !== $loginEntitiesList)
|
468 |
+
return $loginEntitiesList;
|
469 |
+
|
470 |
+
$loginEntitiesList = array();
|
471 |
+
|
472 |
+
foreach(GdbcModulesController::getRegisteredModules() as $moduleName => $arrModuleClasses)
|
473 |
+
{
|
474 |
+
switch($moduleName)
|
475 |
+
{
|
476 |
+
case GdbcModulesController::MODULE_WORDPRESS :
|
477 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcWordPressAdminModule::WORDPRESS_LOGIN_FORM);
|
478 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcWordPressAdminModule::WORDPRESS_LOGIN_XML_RPC);
|
479 |
+
break;
|
480 |
+
|
481 |
+
case GdbcModulesController::MODULE_ULTIMATE_MEMBER :
|
482 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOGIN_FORM);
|
483 |
+
break;
|
484 |
+
|
485 |
+
case GdbcModulesController::MODULE_WOOCOMMERCE :
|
486 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcWooCommerceAdminModule::WOOCOMMERCE_LOGIN_FORM);
|
487 |
+
break;
|
488 |
+
|
489 |
+
case GdbcModulesController::MODULE_USER_PRO :
|
490 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcUserProAdminModule::OPTION_LOGIN_FORM_PROTECTION_ACTIVATED);
|
491 |
+
break;
|
492 |
+
|
493 |
+
case GdbcModulesController::MODULE_UPME :
|
494 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcUPMEAdminModule::UPME_LOGIN_FORM);
|
495 |
+
break;
|
496 |
+
|
497 |
+
case GdbcModulesController::MODULE_ZM_ALR :
|
498 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcZmAlrAdminModule::OPTION_ZM_ALR_LOGIN_FORM);
|
499 |
+
break;
|
500 |
+
|
501 |
+
case GdbcModulesController::MODULE_PLANSO_FORMS :
|
502 |
+
$loginEntitiesList[] = new GdbcAttemptEntity(GdbcModulesController::getModuleIdByName($moduleName), GdbcPlanSoFormsAdminModule::OPTION_PLANSO_LOGIN_FORM);
|
503 |
+
break;
|
504 |
+
|
505 |
+
|
506 |
+
}
|
507 |
+
}
|
508 |
+
|
509 |
+
|
510 |
+
foreach($loginEntitiesList as $index => &$attemptEntity)
|
511 |
+
{
|
512 |
+
$attemptEntity->SectionId = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::getModuleNameById($attemptEntity->ModuleId))->getOptionIdByOptionName($attemptEntity->SectionId);
|
513 |
+
unset($attemptEntity->Id, $attemptEntity->ClientIp, $attemptEntity->CreatedDate, $attemptEntity->Notes, $attemptEntity->ReasonId, $attemptEntity->SiteId);
|
514 |
+
}
|
515 |
+
|
516 |
+
return $loginEntitiesList;
|
517 |
+
}
|
518 |
+
|
519 |
+
|
520 |
+
|
521 |
+
|
522 |
+
public static function flushSiteCache($siteId = 0)
|
523 |
+
{
|
524 |
+
$siteId = absint($siteId);
|
525 |
+
if($siteId === 0)
|
526 |
+
$siteId = get_current_blog_id();
|
527 |
+
|
528 |
+
// $blogDetails = get_blog_details($siteId, false);
|
529 |
+
// if(empty($blogDetails))
|
530 |
+
// return;
|
531 |
+
|
532 |
+
unset($blogDetails);
|
533 |
+
|
534 |
+
$shouldSwitchSite = ($siteId !== get_current_blog_id());
|
535 |
+
|
536 |
+
($shouldSwitchSite) ? switch_to_blog( $siteId) : null;
|
537 |
+
|
538 |
+
if(function_exists('w3tc_flush_all')) { // w3tc
|
539 |
+
w3tc_flush_all();
|
540 |
+
}
|
541 |
+
elseif(function_exists('wp_cache_clear_cache')){ // wp super cache
|
542 |
+
wp_cache_clear_cache();
|
543 |
+
}
|
544 |
+
elseif(isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'deleteCache')){ // wp fastest cache
|
545 |
+
$GLOBALS['wp_fastest_cache']->deleteCache();
|
546 |
+
}
|
547 |
+
elseif(class_exists('zencache') && method_exists('zencache', 'clear')){ // zencache
|
548 |
+
zencache::clear();
|
549 |
+
}
|
550 |
+
// elseif{
|
551 |
+
// /*
|
552 |
+
// * @TODO - Support for Wp Rocket
|
553 |
+
// */
|
554 |
+
//
|
555 |
+
// }
|
556 |
+
|
557 |
+
|
558 |
+
($shouldSwitchSite) ? restore_current_blog() : null;
|
559 |
+
}
|
560 |
+
|
561 |
+
|
562 |
+
/*
|
563 |
+
* return /MchGdbcCache
|
564 |
+
*/
|
565 |
+
public static function getAvailableCacheStorage($dirPathForFileStorage)
|
566 |
+
{
|
567 |
+
static $cacheStorage = false;
|
568 |
+
if(false !== $cacheStorage)
|
569 |
+
return $cacheStorage;
|
570 |
+
|
571 |
+
$arrPossibleCacheStorage = array(
|
572 |
+
!empty($dirPathForFileStorage) ? new MchGdbcCacheFileStorage($dirPathForFileStorage, true, 'txt') : null,
|
573 |
+
new MchGdbcWordPressTransientsStorage(false),
|
574 |
+
new MchGdbcCacheAPCUStorage(),
|
575 |
+
new MchGdbcCacheAPCStorage(),
|
576 |
+
new MchGdbcCacheXCacheStorage(),
|
577 |
+
new MchGdbcCacheZendMemoryStorage(),
|
578 |
+
new MchGdbcCacheZendDiskStorage(),
|
579 |
+
new MchGdbcWordPressTransientsStorage(true),
|
580 |
+
);
|
581 |
+
|
582 |
+
foreach ($arrPossibleCacheStorage as $cacheStorageObject) {
|
583 |
+
if (null === $cacheStorageObject || !$cacheStorageObject->isAvailable())
|
584 |
+
continue;
|
585 |
+
|
586 |
+
return $cacheStorage = new MchGdbcCache($cacheStorageObject);
|
587 |
+
}
|
588 |
+
|
589 |
+
return $cacheStorage = null;
|
590 |
+
}
|
591 |
+
|
592 |
+
|
593 |
+
}
|
2.0/engine/admin/GdbcAdminNotice.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright (C) 2015 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class GdbcAdminNotice extends MchGdbcAdminNotice
|
22 |
+
{
|
23 |
+
CONST USER_IP_WEB_ATTACKER_NOTICE_KEY = 'UserIpWebAttacker';
|
24 |
+
CONST USER_IP_PROXY_ANONYM_NOTICE_KEY = 'UserIpProxyAnonym';
|
25 |
+
|
26 |
+
public function __construct($noticeKey, $noticeType, $noticeMessage = null)
|
27 |
+
{
|
28 |
+
parent::__construct( $noticeKey, $noticeType, $noticeMessage );
|
29 |
+
}
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
}
|
2.0/engine/admin/pages/GdbcBaseAdminPage.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class GdbcBaseAdminPage extends MchGdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
private static $arrPageInstances = array();
|
23 |
+
|
24 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
25 |
+
{
|
26 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
27 |
+
$this->setPageLayoutColumns(2);
|
28 |
+
self::$arrPageInstances[get_class($this)] = $this;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function registerPageMetaBoxes()
|
32 |
+
{
|
33 |
+
|
34 |
+
parent::registerPageMetaBoxes();
|
35 |
+
|
36 |
+
if($this->getPageLayoutColumns() <= 1)
|
37 |
+
return;
|
38 |
+
|
39 |
+
add_meta_box(
|
40 |
+
"gdbc-help-metabox",
|
41 |
+
__('Need help? Have questions...?', GoodByeCaptcha::PLUGIN_SLUG),
|
42 |
+
array( $this, 'renderNeedHelpMetaBox' ),
|
43 |
+
$this->getAdminScreenId(),
|
44 |
+
'side',
|
45 |
+
'core',
|
46 |
+
null
|
47 |
+
);
|
48 |
+
|
49 |
+
add_meta_box(
|
50 |
+
"gdbc-help-metabox-test",
|
51 |
+
__('How to verify if it works?', GoodByeCaptcha::PLUGIN_SLUG),
|
52 |
+
array( $this, 'renderHowToTestMetaBox' ),
|
53 |
+
$this->getAdminScreenId(),
|
54 |
+
'side',
|
55 |
+
'low',
|
56 |
+
null
|
57 |
+
);
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
public function renderNeedHelpMetaBox()
|
63 |
+
{
|
64 |
+
$img = plugins_url('/assets/admin/images/gdbc-logo.png', GoodByeCaptcha::PLUGIN_MAIN_FILE);
|
65 |
+
|
66 |
+
$display_div = '<img class="logo-help" src="' . esc_attr($img) . '" />';
|
67 |
+
|
68 |
+
$display_div .= '<p class="contact-help"> <a class = "button-primary" href="' . GoodByeCaptcha::PLUGIN_SITE_URL . '/contact" target="_blank">Contact Us</a></p>';
|
69 |
+
|
70 |
+
echo $display_div;
|
71 |
+
}
|
72 |
+
|
73 |
+
public function renderHowToTestMetaBox()
|
74 |
+
{
|
75 |
+
$settingsPageUrl = isset(self::$arrPageInstances['GdbcSettingsAdminPage']) ? self::$arrPageInstances['GdbcSettingsAdminPage']->getAdminUrl() : '';
|
76 |
+
$notificationsPageUrl = isset(self::$arrPageInstances['GdbcNotificationsAdminPage']) ? self::$arrPageInstances['GdbcNotificationsAdminPage']->getAdminUrl() : '';
|
77 |
+
|
78 |
+
$textInfo = __('In order to verify if GoodBye Captcha works as expected, just go to, ', GoodByeCaptcha::PLUGIN_SLUG);
|
79 |
+
$textInfo .= MchGdbcHtmlUtils::createAnchorElement(__('Settings Page', GoodByeCaptcha::PLUGIN_SLUG), array('href' => $settingsPageUrl));
|
80 |
+
$textInfo .= __(' and <b>Switch the plugin to Test Mode</b>. <br/>While in test mode, the plugin just verifies if it can properly protect the enabled options and sends email notifications to the email address you set in ', GoodByeCaptcha::PLUGIN_SLUG);
|
81 |
+
$textInfo .= MchGdbcHtmlUtils::createAnchorElement(__('Notifications Page', GoodByeCaptcha::PLUGIN_SLUG), array('href' => $notificationsPageUrl));
|
82 |
+
|
83 |
+
$textInfo .= __(' For example, if you want to test the login form protection, just enable protection for the WordPress Login Form, logout from your dashboard and login again. The plugin will send an email notification letting you know if you can keep the protection activated.', GoodByeCaptcha::PLUGIN_SLUG);
|
84 |
+
|
85 |
+
$textInfo .= __(' In case something goes wrong, a warning message will be shown.', GoodByeCaptcha::PLUGIN_SLUG);
|
86 |
+
|
87 |
+
echo '<p style="text-align: justify">' . $textInfo . "</p>";
|
88 |
+
|
89 |
+
$textInfo = '<div class = "mch-meta-notice-warning">';
|
90 |
+
$textInfo .= __('<b>Turn off Test Mode as soon as you\'re done with testing!</b>', GoodByeCaptcha::PLUGIN_SLUG);
|
91 |
+
$textInfo .= '</div>';
|
92 |
+
|
93 |
+
echo $textInfo;
|
94 |
+
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
}
|
2.0/engine/admin/pages/GdbcContactFormsAdminPage.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcContactFormsAdminPage extends GdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
23 |
+
{
|
24 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
25 |
+
|
26 |
+
$modulesList = array();
|
27 |
+
|
28 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_JETPACK_CONTACT_FORM))
|
29 |
+
$modulesList[] = GdbcJetPackContactFormAdminModule::getInstance();
|
30 |
+
|
31 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_CONTACT_FORM_7))
|
32 |
+
$modulesList[] = GdbcContactForm7AdminModule::getInstance();
|
33 |
+
|
34 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_FAST_SECURE_FORM))
|
35 |
+
$modulesList[] = GdbcFastSecureFormAdminModule::getInstance();
|
36 |
+
|
37 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_FORMIDABLE_FORMS))
|
38 |
+
$modulesList[] = GdbcFormidableFormsAdminModule::getInstance();
|
39 |
+
|
40 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_GRAVITY_FORMS))
|
41 |
+
$modulesList[] = GdbcGravityFormsAdminModule::getInstance();
|
42 |
+
|
43 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_NINJA_FORMS))
|
44 |
+
$modulesList[] = GdbcNinjaFormsAdminModule::getInstance();
|
45 |
+
|
46 |
+
$this->registerGroupedModules(array(
|
47 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha - Popular Contact Forms Settings', GoodByeCaptcha::PLUGIN_SLUG), $modulesList)
|
48 |
+
)
|
49 |
+
);
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
}
|
2.0/engine/admin/pages/GdbcMembershipAdminPage.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcMembershipAdminPage extends GdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
23 |
+
{
|
24 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
25 |
+
|
26 |
+
$arrModules = array();
|
27 |
+
|
28 |
+
|
29 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_ULTIMATE_MEMBER))
|
30 |
+
$arrModules[] = GdbcUltimateMemberAdminModule::getInstance();
|
31 |
+
|
32 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_BUDDY_PRESS))
|
33 |
+
$arrModules[] = GdbcBuddyPressAdminModule::getInstance();
|
34 |
+
|
35 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_BB_PRESS))
|
36 |
+
$arrModules[] = GdbcBbPressAdminModule::getInstance();
|
37 |
+
|
38 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_USER_PRO))
|
39 |
+
$arrModules[] = GdbcUserProAdminModule::getInstance();
|
40 |
+
|
41 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_UPME))
|
42 |
+
$arrModules[] = GdbcUPMEAdminModule::getInstance();
|
43 |
+
|
44 |
+
|
45 |
+
$this->registerGroupedModules(array(
|
46 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha - Membership Plugins Settings', GoodByeCaptcha::PLUGIN_SLUG), $arrModules)
|
47 |
+
)
|
48 |
+
);
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
2.0/engine/admin/pages/GdbcNotificationsAdminPage.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright (C) 2015 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
class GdbcNotificationsAdminPage extends GdbcBaseAdminPage
|
22 |
+
{
|
23 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
24 |
+
{
|
25 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
26 |
+
|
27 |
+
$modulesList = array();
|
28 |
+
|
29 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_EMAIL_NOTIFICATIONS))
|
30 |
+
$modulesList[] = GdbcEmailNotificationsAdminModule::getInstance();
|
31 |
+
|
32 |
+
$this->registerGroupedModules(array(
|
33 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha - Notifications Settings', GoodByeCaptcha::PLUGIN_SLUG), $modulesList)
|
34 |
+
)
|
35 |
+
);
|
36 |
+
|
37 |
+
}
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
}
|
2.0/engine/admin/pages/GdbcOthersAdminPage.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcOthersAdminPage extends GdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
23 |
+
{
|
24 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
25 |
+
|
26 |
+
$modulesList = array();
|
27 |
+
|
28 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_MAIL_CHIMP_FOR_WP))
|
29 |
+
$modulesList[] = GdbcMailChimpForWpAdminModule::getInstance();
|
30 |
+
|
31 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_MAIL_POET))
|
32 |
+
$modulesList[] = GdbcMailPoetAdminModule::getInstance();
|
33 |
+
|
34 |
+
|
35 |
+
$this->registerGroupedModules(array(
|
36 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha - Subscriptions Plugins Settings', GoodByeCaptcha::PLUGIN_SLUG), $modulesList)
|
37 |
+
)
|
38 |
+
);
|
39 |
+
|
40 |
+
|
41 |
+
$modulesList = array();
|
42 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_WOOCOMMERCE))
|
43 |
+
$modulesList[] = GdbcWooCommerceAdminModule::getInstance();
|
44 |
+
|
45 |
+
$this->registerGroupedModules(array(
|
46 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha - eCommerce Plugins Settings', GoodByeCaptcha::PLUGIN_SLUG), $modulesList)
|
47 |
+
)
|
48 |
+
);
|
49 |
+
|
50 |
+
|
51 |
+
$modulesList = array();
|
52 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_ZM_ALR))
|
53 |
+
$modulesList[] = GdbcZmAlrAdminModule::getInstance();
|
54 |
+
|
55 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_PLANSO_FORMS))
|
56 |
+
$modulesList[] = GdbcPlanSoFormsAdminModule::getInstance();
|
57 |
+
|
58 |
+
|
59 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_SEAMLESS_DONATIONS))
|
60 |
+
$modulesList[] = GdbcSeamlessDonationsAdminModule::getInstance();
|
61 |
+
|
62 |
+
$this->registerGroupedModules(array(
|
63 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha - Other Popular Plugins', GoodByeCaptcha::PLUGIN_SLUG), $modulesList)
|
64 |
+
)
|
65 |
+
);
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
}
|
70 |
+
|
71 |
+
}
|
2.0/engine/admin/pages/GdbcReportsAdminPage.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcReportsAdminPage extends GdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
23 |
+
{
|
24 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
25 |
+
|
26 |
+
$this->setPageLayoutColumns(1);
|
27 |
+
|
28 |
+
if(!GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_REPORTS))
|
29 |
+
return;
|
30 |
+
|
31 |
+
$this->registerGroupedModules(array(
|
32 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha - Blocked Attempts', GoodByeCaptcha::PLUGIN_SLUG), array(GdbcReportsAdminModule::getInstance()))
|
33 |
+
)
|
34 |
+
);
|
35 |
+
|
36 |
+
|
37 |
+
}
|
38 |
+
|
39 |
+
|
40 |
+
public function renderPageContent()
|
41 |
+
{
|
42 |
+
$arrReportsNavigationTabUrl = array();
|
43 |
+
|
44 |
+
$arrQueryString = array(
|
45 |
+
'page' => $this->getPageMenuSlug()
|
46 |
+
);
|
47 |
+
|
48 |
+
$pageAdminUrl = GoodByeCaptcha::isNetworkActivated() ? network_admin_url('admin.php') : admin_url('admin.php');
|
49 |
+
$arrReportsNavigationTabUrl[] = esc_url(add_query_arg($arrQueryString, $pageAdminUrl));
|
50 |
+
$arrQueryString['gdbc-detailed-report'] = 1;
|
51 |
+
$arrReportsNavigationTabUrl[] = esc_url(add_query_arg($arrQueryString, $pageAdminUrl));
|
52 |
+
|
53 |
+
echo '<div id = "gdbc-reports-holder" class = "clearfix">';
|
54 |
+
echo '<h3>' . __('GoodBye Captcha - Blocked Attempts', GoodByeCaptcha::PLUGIN_SLUG) . '</h3>';
|
55 |
+
|
56 |
+
GdbcReportsAdminModule::getInstance()->renderReportsMainPageContent($arrReportsNavigationTabUrl);
|
57 |
+
|
58 |
+
echo '</div>';
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
}
|
2.0/engine/admin/pages/GdbcSecurityAdminPage.php
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcSecurityAdminPage extends GdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
private $blackListedIpsGroupIndex = null;
|
23 |
+
private $whiteListedIpsGroupIndex = null;
|
24 |
+
|
25 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
26 |
+
{
|
27 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
28 |
+
|
29 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_BRUTE_FORCE))
|
30 |
+
{
|
31 |
+
$this->registerGroupedModules(array(
|
32 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha Brute Force Settings', GoodByeCaptcha::PLUGIN_SLUG), array(
|
33 |
+
GdbcBruteForceAdminModule::getInstance())
|
34 |
+
)
|
35 |
+
));
|
36 |
+
}
|
37 |
+
|
38 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_WHITE_LISTED_IPS))
|
39 |
+
{
|
40 |
+
$this->whiteListedIpsGroupIndex = $this->registerGroupedModules(array(
|
41 |
+
new MchGdbcGroupedModules(__('White Listed IPs', GoodByeCaptcha::PLUGIN_SLUG), array(
|
42 |
+
GdbcWhiteListedIpsAdminModule::getInstance())
|
43 |
+
)
|
44 |
+
));
|
45 |
+
}
|
46 |
+
|
47 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_BLACK_LISTED_IPS))
|
48 |
+
{
|
49 |
+
$this->blackListedIpsGroupIndex = $this->registerGroupedModules(array(
|
50 |
+
new MchGdbcGroupedModules(__('Black Listed IPs', GoodByeCaptcha::PLUGIN_SLUG), array(
|
51 |
+
GdbcBlackListedIpsAdminModule::getInstance())
|
52 |
+
)
|
53 |
+
));
|
54 |
+
}
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
private function getBlackListedIpsInputName()
|
59 |
+
{
|
60 |
+
return esc_attr(GdbcBlackListedIpsAdminModule::getInstance()->getSettingKey() . '[' . GdbcBlackListedIpsAdminModule::OPTION_BLACK_LISTED_IPS . ']');
|
61 |
+
}
|
62 |
+
private function getWhiteListedIpsInputName()
|
63 |
+
{
|
64 |
+
return esc_attr(GdbcWhiteListedIpsAdminModule::getInstance()->getSettingKey() . '[' . GdbcWhiteListedIpsAdminModule::OPTION_WHITE_LISTED_IPS . ']');
|
65 |
+
}
|
66 |
+
|
67 |
+
public function renderGroupModulesSettings($groupIndex = null)
|
68 |
+
{
|
69 |
+
|
70 |
+
if(!is_numeric($groupIndex))
|
71 |
+
{
|
72 |
+
foreach ( func_get_args() as $receivedArgument )
|
73 |
+
{
|
74 |
+
if ( ! isset( $receivedArgument['args'] ) || !is_numeric($receivedArgument['args']))
|
75 |
+
continue;
|
76 |
+
|
77 |
+
$groupIndex = $receivedArgument['args'];
|
78 |
+
break;
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
$this->displayGroupModulesMessages($groupIndex);
|
83 |
+
|
84 |
+
if($this->whiteListedIpsGroupIndex == $groupIndex)
|
85 |
+
{
|
86 |
+
if(null !== GdbcWhiteListedIpsAdminModule::getInstance()->getPartialAdminSettingsFilePath())
|
87 |
+
{
|
88 |
+
include_once GdbcWhiteListedIpsAdminModule::getInstance()->getPartialAdminSettingsFilePath();
|
89 |
+
}
|
90 |
+
|
91 |
+
return;
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
if($this->blackListedIpsGroupIndex == $groupIndex)
|
96 |
+
{
|
97 |
+
if(null !== GdbcBlackListedIpsAdminModule::getInstance()->getPartialAdminSettingsFilePath())
|
98 |
+
{
|
99 |
+
include_once GdbcBlackListedIpsAdminModule::getInstance()->getPartialAdminSettingsFilePath();
|
100 |
+
}
|
101 |
+
|
102 |
+
return;
|
103 |
+
}
|
104 |
+
|
105 |
+
return parent::renderGroupModulesSettings($groupIndex);
|
106 |
+
|
107 |
+
}
|
108 |
+
|
109 |
+
|
110 |
+
public function registerPageMetaBoxes()
|
111 |
+
{
|
112 |
+
parent::registerPageMetaBoxes();
|
113 |
+
|
114 |
+
if($this->getPageLayoutColumns() <= 1)
|
115 |
+
return;
|
116 |
+
|
117 |
+
add_meta_box(
|
118 |
+
"gdbc-help-web-attackers-list",
|
119 |
+
__('Web Attackers IPs List', GoodByeCaptcha::PLUGIN_SLUG),
|
120 |
+
array( $this, 'renderWebAttackersMetaBox' ),
|
121 |
+
$this->getAdminScreenId(),
|
122 |
+
'side',
|
123 |
+
'core',
|
124 |
+
null
|
125 |
+
);
|
126 |
+
|
127 |
+
add_meta_box(
|
128 |
+
"gdbc-help-proxy-anonymizers-list",
|
129 |
+
__('Anonymous Proxy IPs List', GoodByeCaptcha::PLUGIN_SLUG),
|
130 |
+
array( $this, 'renderProxyAnonymizersMetaBox' ),
|
131 |
+
$this->getAdminScreenId(),
|
132 |
+
'side',
|
133 |
+
'core',
|
134 |
+
null
|
135 |
+
);
|
136 |
+
|
137 |
+
}
|
138 |
+
|
139 |
+
public function renderWebAttackersMetaBox()
|
140 |
+
{
|
141 |
+
$textInfo = __('Provides security against the most well known attackers, with the minimum of false positives. Contains more than 100.000 attackers\' IPs reported by <a href="http://www.spamhaus.org/">Spamhaus.org</a>,', GoodByeCaptcha::PLUGIN_SLUG);
|
142 |
+
$textInfo .= __(' <a href="http://www.dshield.org/">DShield.org</a>,', GoodByeCaptcha::PLUGIN_SLUG);
|
143 |
+
$textInfo .= __(' <a href="http://www.openbl.org/">OpenBL.org</a>,', GoodByeCaptcha::PLUGIN_SLUG);
|
144 |
+
$textInfo .= __(' <a href="http://www.blocklist.de/">BlockList.de</a>,', GoodByeCaptcha::PLUGIN_SLUG);
|
145 |
+
$textInfo .= __(' <a href="http://www.projecthoneypot.org/">ProjectHoneypot.org</a> ', GoodByeCaptcha::PLUGIN_SLUG);
|
146 |
+
$textInfo .= __(' and <a href="https://greensnow.co/">GreenSnow.co</a>.', GoodByeCaptcha::PLUGIN_SLUG);
|
147 |
+
|
148 |
+
|
149 |
+
echo '<p>' . $textInfo . '</p>';
|
150 |
+
}
|
151 |
+
|
152 |
+
public function renderProxyAnonymizersMetaBox()
|
153 |
+
{
|
154 |
+
$textInfo = __('Provides protection against the most Proxy used IP addresses identified as high risk by reported by <a href="http://www.spamhaus.org/">Spamhaus.org</a>,', GoodByeCaptcha::PLUGIN_SLUG);
|
155 |
+
$textInfo .= __(' <a href="http://www.projecthoneypot.org/">ProjectHoneypot.org</a> and <a href="https://www.maxmind.com/en/proxy-detection-sample-list">MaxMind.com</a>.', GoodByeCaptcha::PLUGIN_SLUG);
|
156 |
+
$textInfo .= __(' <b>The list also contains the most fraudulent TOR network, TOR Nodes and TOR Exit Points IP Addresses.</b>', GoodByeCaptcha::PLUGIN_SLUG);
|
157 |
+
|
158 |
+
echo '<p style="text-align: justify">' . $textInfo . '</p>';
|
159 |
+
}
|
160 |
+
|
161 |
+
}
|
2.0/engine/admin/pages/GdbcSettingsAdminPage.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcSettingsAdminPage extends GdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
23 |
+
{
|
24 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
25 |
+
|
26 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_SETTINGS))
|
27 |
+
{
|
28 |
+
$this->registerGroupedModules(array(
|
29 |
+
new MchGdbcGroupedModules(__('GoodBye Captcha General Settings', GoodByeCaptcha::PLUGIN_SLUG), array(
|
30 |
+
GdbcSettingsAdminModule::getInstance())
|
31 |
+
)
|
32 |
+
));
|
33 |
+
}
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
}
|
2.0/engine/admin/pages/GdbcWordpressAdminPage.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcWordpressAdminPage extends GdbcBaseAdminPage
|
21 |
+
{
|
22 |
+
public function __construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug)
|
23 |
+
{
|
24 |
+
parent::__construct($pageMenuTitle, $pageBrowserTitle, $pluginSlug);
|
25 |
+
|
26 |
+
if(GdbcModulesController::isModuleRegistered(GdbcModulesController::MODULE_WORDPRESS))
|
27 |
+
{
|
28 |
+
$this->registerGroupedModules(array(
|
29 |
+
new MchGdbcGroupedModules(__('WordPress Standard Forms Settings', GoodByeCaptcha::PLUGIN_SLUG), array(
|
30 |
+
GdbcWordPressAdminModule::getInstance(),
|
31 |
+
)
|
32 |
+
)
|
33 |
+
));
|
34 |
+
|
35 |
+
|
36 |
+
$this->registerGroupedModules(array(
|
37 |
+
new MchGdbcGroupedModules(__('Tweaking WordPress', GoodByeCaptcha::PLUGIN_SLUG), array(
|
38 |
+
GdbcWordPressTweaksAdminModule::getInstance(),
|
39 |
+
)
|
40 |
+
)
|
41 |
+
));
|
42 |
+
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
46 |
+
|
47 |
+
public function registerPageMetaBoxes()
|
48 |
+
{
|
49 |
+
parent::registerPageMetaBoxes();
|
50 |
+
|
51 |
+
if($this->getPageLayoutColumns() <= 1)
|
52 |
+
return;
|
53 |
+
|
54 |
+
add_meta_box(
|
55 |
+
"gdbc-help-xml-rpc",
|
56 |
+
__('Disabling XML-RPC Service', GoodByeCaptcha::PLUGIN_SLUG),
|
57 |
+
array( $this, 'renderXmlRpcMetaBox' ),
|
58 |
+
$this->getAdminScreenId(),
|
59 |
+
'side',
|
60 |
+
'core',
|
61 |
+
null
|
62 |
+
);
|
63 |
+
|
64 |
+
add_meta_box(
|
65 |
+
"gdbc-help-xml-rpc-pingback",
|
66 |
+
__('Disabling XML-RPC Pingbacks', GoodByeCaptcha::PLUGIN_SLUG),
|
67 |
+
array( $this, 'renderXmlRpcPingbacksMetaBox' ),
|
68 |
+
$this->getAdminScreenId(),
|
69 |
+
'side',
|
70 |
+
'core',
|
71 |
+
null
|
72 |
+
);
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
+
public function renderXmlRpcMetaBox()
|
77 |
+
{
|
78 |
+
$textInfo = __('XML-RPC is used in WordPress as an API for third-party clients such as WordPress mobile apps, popular weblog clients like Windows Writer or popular plugins such as Jetpack.', GoodByeCaptcha::PLUGIN_SLUG);
|
79 |
+
$textInfo .= __('If you use any application which calls your XML-RPC Service, <b>do not</b> Completely Disable XML-RPC. Otherwise, completely disabling XML-RPC it is strongly recommended.', GoodByeCaptcha::PLUGIN_SLUG);
|
80 |
+
|
81 |
+
echo '<p style="text-align: justify">' . $textInfo . '</p>';
|
82 |
+
|
83 |
+
|
84 |
+
$textInfo = '<div class = "mch-meta-notice-info">';
|
85 |
+
$textInfo .= __('<span><b>Feel free to Completely Disable XML-RPC if you are using Jetpack plugin</b>. GoodBye Captcha simply allows Jetpack\'s XML-RPC Requests</span>', GoodByeCaptcha::PLUGIN_SLUG);
|
86 |
+
$textInfo .= '</div>';
|
87 |
+
|
88 |
+
echo $textInfo;
|
89 |
+
|
90 |
+
}
|
91 |
+
|
92 |
+
|
93 |
+
public function renderXmlRpcPingbacksMetaBox()
|
94 |
+
{
|
95 |
+
$textInfo = __('XML-RPC is used for Pingbacks and Trackbacks which can be heavily misused to start <a href="https://blog.sucuri.net/2014/03/more-than-162000-wordpress-sites-used-for-distributed-denial-of-service-attack.html">DDoS attacks</a>.', GoodByeCaptcha::PLUGIN_SLUG);
|
96 |
+
|
97 |
+
echo '<p style="text-align: justify">' . $textInfo . '</p>';
|
98 |
+
|
99 |
+
$textInfo = '<div class = "mch-meta-notice-info">';
|
100 |
+
$textInfo .= __('<span>If the <b>Completely Disable XML-RPC</b> option is checked, enabling/disabling this option has no effect!</span>', GoodByeCaptcha::PLUGIN_SLUG);
|
101 |
+
$textInfo .= '</div>';
|
102 |
+
|
103 |
+
echo $textInfo;
|
104 |
+
}
|
105 |
+
|
106 |
+
|
107 |
+
}
|
2.0/engine/db-access/GdbcDbAccessController.php
ADDED
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class GdbcDbAccessController
|
21 |
+
{
|
22 |
+
public static $LAST_INSERTED_ATTEMPT_ID = 0;
|
23 |
+
|
24 |
+
private static function sanitizeEntityNotes($entityNote)
|
25 |
+
{
|
26 |
+
if(is_string($entityNote))
|
27 |
+
{
|
28 |
+
return wp_filter_kses(wp_check_invalid_utf8($entityNote));
|
29 |
+
}
|
30 |
+
|
31 |
+
if(is_array($entityNote))
|
32 |
+
{
|
33 |
+
return array_map( array( __CLASS__, 'sanitizeEntityNotes' ), $entityNote );
|
34 |
+
}
|
35 |
+
|
36 |
+
return $entityNote;
|
37 |
+
}
|
38 |
+
|
39 |
+
public static function registerAttempt(GdbcAttemptEntity $attemptEntity)
|
40 |
+
{
|
41 |
+
self::$LAST_INSERTED_ATTEMPT_ID = 0;
|
42 |
+
|
43 |
+
if(empty($attemptEntity->ModuleId) || empty($attemptEntity->SiteId) || empty($attemptEntity->CreatedDate) || empty($attemptEntity->ReasonId))
|
44 |
+
return;
|
45 |
+
|
46 |
+
unset($attemptEntity->Id);
|
47 |
+
|
48 |
+
if(is_array($attemptEntity->Notes))
|
49 |
+
{
|
50 |
+
$attemptEntity->Notes = array_filter($attemptEntity->Notes);
|
51 |
+
|
52 |
+
$tokenFieldName = GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_HIDDEN_INPUT_NAME);
|
53 |
+
$browserInputName = GdbcRequestController::getPostedBrowserInfoInputName();
|
54 |
+
|
55 |
+
$arrKeysToUnset = array($tokenFieldName, $browserInputName, strtolower($tokenFieldName), strtolower($browserInputName), strtoupper($tokenFieldName), strtoupper($browserInputName), '_wpnonce');
|
56 |
+
foreach($arrKeysToUnset as $keyName)
|
57 |
+
{
|
58 |
+
unset($attemptEntity->Notes[$keyName]);
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
$attemptEntity->Notes = !empty($attemptEntity->Notes) ? maybe_serialize(self::sanitizeEntityNotes($attemptEntity->Notes)) : null;
|
63 |
+
global $wpdb;
|
64 |
+
|
65 |
+
return self::$LAST_INSERTED_ATTEMPT_ID = (false === $wpdb->insert(self::getAttemptsTableName(), array_filter((array)$attemptEntity))) ? 0 : $wpdb->insert_id;
|
66 |
+
}
|
67 |
+
|
68 |
+
|
69 |
+
public static function getCombinedAttemptsPerDay($numberOfDays)
|
70 |
+
{
|
71 |
+
$createdDateTime = self::getDaysAgoTimeStamp($numberOfDays);
|
72 |
+
|
73 |
+
global $wpdb;
|
74 |
+
|
75 |
+
$sqlQuery = "SELECT COUNT(1) AS AttemptsNumber, FROM_UNIXTIME(CreatedDate, '%%Y-%%m-%%d') as CreatedDate FROM " . self::getAttemptsTableName() . " WHERE CreatedDate >= %d ";
|
76 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? '' : ' AND SiteId = %d ';
|
77 |
+
$sqlQuery .= " GROUP BY FROM_UNIXTIME(CreatedDate, '%%Y-%%m-%%d') ORDER BY CreatedDate ";
|
78 |
+
|
79 |
+
$arrParams = array($createdDateTime);
|
80 |
+
GoodByeCaptcha::isNetworkActivated() ? null : $arrParams[] = get_current_blog_id();
|
81 |
+
|
82 |
+
return (array)self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
public static function getLatestAttempts($numberOfAttempts)
|
87 |
+
{
|
88 |
+
global $wpdb;
|
89 |
+
|
90 |
+
$sqlQuery = 'SELECT * FROM ' . self::getAttemptsTableName();
|
91 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? '' : ' WHERE SiteId = %d';
|
92 |
+
$sqlQuery .= ' ORDER BY CreatedDate DESC LIMIT 0, %d';
|
93 |
+
|
94 |
+
$arrParams = array();
|
95 |
+
GoodByeCaptcha::isNetworkActivated() ? null : $arrParams[] = get_current_blog_id();
|
96 |
+
|
97 |
+
$arrParams[] = (int)$numberOfAttempts;
|
98 |
+
|
99 |
+
$latestAttemptsList = (array)self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
100 |
+
|
101 |
+
return $latestAttemptsList;
|
102 |
+
}
|
103 |
+
|
104 |
+
public static function getAttemptsByClientIp($pageNumber, $recordsPerPage = 10)
|
105 |
+
{
|
106 |
+
global $wpdb;
|
107 |
+
|
108 |
+
$sqlQuery = "SELECT COUNT(1) AS Attempts, ClientIp FROM " . self::getAttemptsTableName();
|
109 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' WHERE Id > %d ' : ' WHERE SiteId = %d ';
|
110 |
+
$sqlQuery .= 'GROUP BY ClientIp ORDER BY Attempts DESC LIMIT %d, %d';
|
111 |
+
|
112 |
+
$arrParams = array();
|
113 |
+
|
114 |
+
GoodByeCaptcha::isNetworkActivated() ? null : $arrParams[] = get_current_blog_id();
|
115 |
+
|
116 |
+
$arrParams = array();
|
117 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
118 |
+
$arrParams[] = ($pageNumber-1) * $recordsPerPage;
|
119 |
+
$arrParams[] = $recordsPerPage;
|
120 |
+
|
121 |
+
return (array)self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
122 |
+
|
123 |
+
}
|
124 |
+
|
125 |
+
public static function getTotalAttemptsPerModule()
|
126 |
+
{
|
127 |
+
global $wpdb;
|
128 |
+
$sqlQuery = 'SELECT ModuleId, COUNT(1) as Total FROM ' . self::getAttemptsTableName();
|
129 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' WHERE Id > %d' : ' WHERE SiteId = %d';
|
130 |
+
$sqlQuery .= ' GROUP BY ModuleId';
|
131 |
+
|
132 |
+
$arrParams = array();
|
133 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
134 |
+
|
135 |
+
return (array)self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
136 |
+
}
|
137 |
+
|
138 |
+
public static function getAttemptsPerModuleAndDay($numberOfDays)
|
139 |
+
{
|
140 |
+
global $wpdb;
|
141 |
+
$createdDateTime = self::getDaysAgoTimeStamp($numberOfDays) + 1;
|
142 |
+
|
143 |
+
$sqlQuery = "SELECT ModuleId, FROM_UNIXTIME(CreatedDate, '%%Y-%%m-%%d') AS AttemptDate, COUNT(1) AS AttemptsNumber FROM " . self::getAttemptsTableName();
|
144 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' WHERE Id > %d ' : ' WHERE SiteId = %d ';
|
145 |
+
$sqlQuery .= " AND CreatedDate > $createdDateTime GROUP BY ModuleId, AttemptDate ORDER BY ModuleId ASC, AttemptDate DESC";
|
146 |
+
|
147 |
+
$arrParams = array();
|
148 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
149 |
+
|
150 |
+
return (array)self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
151 |
+
}
|
152 |
+
|
153 |
+
public static function getNumberOfAttemptsByModuleId($moduleId)
|
154 |
+
{
|
155 |
+
global $wpdb;
|
156 |
+
$sqlQuery = 'SELECT COUNT(1) AS Total FROM ' . self::getAttemptsTableName();
|
157 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' WHERE Id > %d ' : ' WHERE SiteId = %d ';
|
158 |
+
$sqlQuery .= ' AND ModuleId = %d ';
|
159 |
+
|
160 |
+
$arrParams = array();
|
161 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
162 |
+
$arrParams[] = $moduleId;
|
163 |
+
|
164 |
+
$arrTotalAttempts = self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
165 |
+
|
166 |
+
return isset($arrTotalAttempts[0]) ? (int)$arrTotalAttempts[0]->Total : 0;
|
167 |
+
|
168 |
+
}
|
169 |
+
|
170 |
+
public static function getAttemptsPerModule($moduleId, $pageNumber, $recordsPerPage)
|
171 |
+
{
|
172 |
+
global $wpdb;
|
173 |
+
|
174 |
+
$pageNumber < 1 ? $pageNumber = 1 : null;
|
175 |
+
|
176 |
+
$sqlQuery = "SELECT * FROM " . self::getAttemptsTableName();
|
177 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' WHERE Id > %d ' : ' WHERE SiteId = %d ';
|
178 |
+
$sqlQuery .= ' AND ModuleId = %d ORDER BY CreatedDate DESC LIMIT %d, %d';
|
179 |
+
|
180 |
+
$arrParams = array();
|
181 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
182 |
+
$arrParams[] = $moduleId;
|
183 |
+
|
184 |
+
$arrParams[] = ($pageNumber-1) * $recordsPerPage;
|
185 |
+
$arrParams[] = $recordsPerPage;
|
186 |
+
|
187 |
+
return (array)self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
188 |
+
}
|
189 |
+
|
190 |
+
public static function getAttemptById($attemptId)
|
191 |
+
{
|
192 |
+
global $wpdb;
|
193 |
+
$sqlQuery = 'SELECT * FROM ' . self::getAttemptsTableName() . ' WHERE Id = %d';
|
194 |
+
$arrGdbcAttempts = self::executePreparedQuery($wpdb->prepare($sqlQuery, $attemptId));
|
195 |
+
return isset($arrGdbcAttempts[0]) ? $arrGdbcAttempts[0] : 0;
|
196 |
+
}
|
197 |
+
|
198 |
+
public static function getAttemptsPerModuleAndSection()
|
199 |
+
{
|
200 |
+
global $wpdb;
|
201 |
+
$sqlQuery = 'SELECT ModuleId, SectionId, Count(ModuleId) AS Attempts FROM ' . self::getAttemptsTableName();
|
202 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' WHERE Id > %d' : ' WHERE SiteId = %d';
|
203 |
+
$sqlQuery .= ' GROUP BY ModuleId, SectionId';
|
204 |
+
|
205 |
+
$arrParams = array();
|
206 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
207 |
+
|
208 |
+
return (array)self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
209 |
+
|
210 |
+
|
211 |
+
}
|
212 |
+
|
213 |
+
private static function getDaysAgoTimeStamp($numberOfDays)
|
214 |
+
{
|
215 |
+
return MchGdbcHttpRequest::getServerRequestTime() - ( absint($numberOfDays) * 3600 * 24 );
|
216 |
+
}
|
217 |
+
|
218 |
+
private static function executePreparedQuery($sqlQuery)
|
219 |
+
{
|
220 |
+
global $wpdb;
|
221 |
+
return null !== ($queryResult = $wpdb->get_results($sqlQuery)) ? $queryResult : array();
|
222 |
+
}
|
223 |
+
|
224 |
+
public static function createAttemptsTable()
|
225 |
+
{
|
226 |
+
global $wpdb;
|
227 |
+
if(self::attemptsTableExists())
|
228 |
+
return false;
|
229 |
+
|
230 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
231 |
+
|
232 |
+
$createTableStatement = "CREATE TABLE " . self::getAttemptsTableName() . " (
|
233 |
+
Id int unsigned NOT NULL auto_increment,
|
234 |
+
CreatedDate int unsigned NOT NULL,
|
235 |
+
SiteId smallint unsigned NOT NULL,
|
236 |
+
ClientIp varchar(45) DEFAULT NULL,
|
237 |
+
ModuleId tinyint unsigned NOT NULL,
|
238 |
+
SectionId tinyint unsigned default 0,
|
239 |
+
ReasonId tinyint unsigned NOT NULL,
|
240 |
+
Notes longtext NOT NULL DEFAULT '',
|
241 |
+
PRIMARY KEY (Id),
|
242 |
+
KEY idx_gdbc_CreatedDateSiteId (CreatedDate, SiteId)
|
243 |
+
)"; //KEY index_gdbc_ClientIp (ClientIp)
|
244 |
+
|
245 |
+
$createTableStatement .= !empty($wpdb->charset) ? " DEFAULT CHARACTER SET {$wpdb->charset}" : '';
|
246 |
+
$createTableStatement .= !empty($wpdb->collate) ? " COLLATE {$wpdb->collate}" : '';
|
247 |
+
|
248 |
+
$result = dbDelta($createTableStatement);
|
249 |
+
|
250 |
+
return !empty($result) ? true : false;
|
251 |
+
|
252 |
+
}
|
253 |
+
|
254 |
+
|
255 |
+
|
256 |
+
public static function deleteAttemptsOlderThan($numberOfDays)
|
257 |
+
{
|
258 |
+
if(empty($numberOfDays))
|
259 |
+
return;
|
260 |
+
|
261 |
+
$createdDateTime = self::getDaysAgoTimeStamp($numberOfDays);
|
262 |
+
|
263 |
+
global $wpdb;
|
264 |
+
$sqlQuery = 'DELETE FROM ' . self::getAttemptsTableName() . ' WHERE CreatedDate < %d ';
|
265 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' AND Id > %d ' : ' AND SiteId = %d ';
|
266 |
+
$sqlQuery .= 'LIMIT 300';
|
267 |
+
|
268 |
+
$arrParams = array($createdDateTime);
|
269 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
270 |
+
|
271 |
+
self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
272 |
+
|
273 |
+
}
|
274 |
+
|
275 |
+
public static function clearAttemptsNotesOlderThan($numberOfDays)
|
276 |
+
{
|
277 |
+
if(empty($numberOfDays))
|
278 |
+
return;
|
279 |
+
|
280 |
+
$createdDateTime = self::getDaysAgoTimeStamp($numberOfDays);
|
281 |
+
|
282 |
+
global $wpdb;
|
283 |
+
$sqlQuery = 'UPDATE ' . self::getAttemptsTableName() . " SET Notes = '' WHERE CreatedDate < %d AND (Notes <> '' OR Notes IS NOT NULL )";
|
284 |
+
$sqlQuery .= GoodByeCaptcha::isNetworkActivated() ? ' AND Id > %d ' : ' AND SiteId = %d ';
|
285 |
+
$sqlQuery .= 'LIMIT 300';
|
286 |
+
|
287 |
+
$arrParams = array($createdDateTime);
|
288 |
+
$arrParams[] = GoodByeCaptcha::isNetworkActivated() ? 0 : get_current_blog_id();
|
289 |
+
|
290 |
+
self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
291 |
+
|
292 |
+
}
|
293 |
+
|
294 |
+
|
295 |
+
public static function getLatestLoginAttempts($numberOfSecondsAgo, $calculateAverage = false)
|
296 |
+
{
|
297 |
+
global $wpdb;
|
298 |
+
|
299 |
+
$averageStatement = ($calculateAverage) ? 'FORMAT( (MAX(CreatedDate) - MIN(CreatedDate)) / (Count(1) - 1) , 2) As TimeAverage,' : '';
|
300 |
+
|
301 |
+
$sqlQuery = "SELECT Count(1) AS Hits, $averageStatement ClientIp FROM " . self::getAttemptsTableName();
|
302 |
+
$sqlQuery .= ' WHERE CreatedDate > %d ' . ( GoodByeCaptcha::isNetworkActivated() ? 'AND SiteId = %d' : '');
|
303 |
+
$sqlQuery .= ' AND ( ';
|
304 |
+
|
305 |
+
foreach(GoodByeCaptchaUtils::getAllPossibleLoginAttemptEntities() as $gdbcAttempt){
|
306 |
+
$sqlQuery .= '(ModuleId = ' . $gdbcAttempt->ModuleId . ' AND SectionId = ' . $gdbcAttempt->SectionId . ') OR ';
|
307 |
+
}
|
308 |
+
|
309 |
+
$sqlQuery = substr($sqlQuery, 0, -4) . ' ) GROUP BY ClientIp';
|
310 |
+
|
311 |
+
$arrParams = array(MchGdbcHttpRequest::getServerRequestTime() - $numberOfSecondsAgo - 1);
|
312 |
+
|
313 |
+
$arrParams = array(
|
314 |
+
MchGdbcHttpRequest::getServerRequestTime() - $numberOfSecondsAgo - 2,
|
315 |
+
get_current_blog_id()
|
316 |
+
);
|
317 |
+
|
318 |
+
|
319 |
+
return self::executePreparedQuery($wpdb->prepare($sqlQuery, $arrParams));
|
320 |
+
|
321 |
+
}
|
322 |
+
|
323 |
+
|
324 |
+
public static function attemptsTableExistsAndIsEmpty()
|
325 |
+
{
|
326 |
+
if(!self::attemptsTableExists())
|
327 |
+
return false;
|
328 |
+
|
329 |
+
global $wpdb;
|
330 |
+
$arrFirstId = $wpdb->get_col('SELECT Id FROM ' . self::getAttemptsTableName() . ' LIMIT 1');
|
331 |
+
return empty($arrFirstId);
|
332 |
+
}
|
333 |
+
|
334 |
+
public static function attemptsTableExists()
|
335 |
+
{
|
336 |
+
global $wpdb;
|
337 |
+
return ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", self::getAttemptsTableName())) === self::getAttemptsTableName());
|
338 |
+
}
|
339 |
+
|
340 |
+
|
341 |
+
public static function getAttemptsTableName()
|
342 |
+
{
|
343 |
+
global $wpdb;
|
344 |
+
return $wpdb->base_prefix . 'gdbc_attempts';
|
345 |
+
}
|
346 |
+
|
347 |
+
|
348 |
+
public static function getLoginAttempts($lastNumberOfSeconds)
|
349 |
+
{
|
350 |
+
// SELECT Count(1) AS Hits , ((MAX(CreatedDate) - MIN(CreatedDate)) / (Count(1) - 1)) As Average, ClientIp
|
351 |
+
// from wp_gdbc_attempts qa where qa.CreatedDate > (1443473534 - (1 * 60)) GROUP BY ClientIp;
|
352 |
+
}
|
353 |
+
|
354 |
+
private function __construct()
|
355 |
+
{}
|
356 |
+
}
|
{engine → 2.0/engine}/entities/GdbcAttemptEntity.php
RENAMED
File without changes
|
2.0/engine/modules/GdbcBaseAdminModule.php
ADDED
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class GdbcBaseAdminModule extends MchGdbcBaseAdminModule
|
21 |
+
{
|
22 |
+
|
23 |
+
protected function __construct()
|
24 |
+
{
|
25 |
+
parent::__construct();
|
26 |
+
}
|
27 |
+
|
28 |
+
public abstract function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity);
|
29 |
+
|
30 |
+
protected function getAllSavedOptions($asNetworkOption = true)
|
31 |
+
{
|
32 |
+
return parent::getAllSavedOptions(GoodByeCaptcha::isNetworkActivated());
|
33 |
+
}
|
34 |
+
|
35 |
+
public function getOption($optionName, $asNetworkOption = true)
|
36 |
+
{
|
37 |
+
return parent::getOption($optionName, GoodByeCaptcha::isNetworkActivated());
|
38 |
+
}
|
39 |
+
|
40 |
+
public function saveOption($optionName, $optionValue, $asNetworkOption = true)
|
41 |
+
{
|
42 |
+
return parent::saveOption($optionName, $optionValue, GoodByeCaptcha::isNetworkActivated());
|
43 |
+
}
|
44 |
+
|
45 |
+
public function renderModuleSettingsSectionHeader(array $arrSectionInfo)
|
46 |
+
{
|
47 |
+
//echo '<h3>' . __('WordPress General Settings', GoodByeCaptcha::PLUGIN_SLUG) . '</h3><hr />';
|
48 |
+
}
|
49 |
+
|
50 |
+
public function renderModuleSettingsField(array $arrSettingsField)
|
51 |
+
{
|
52 |
+
$arrDefaultValues = $this->getDefaultOptionsValues();
|
53 |
+
$optionName = key($arrSettingsField);
|
54 |
+
if(null === $optionName || !array_key_exists($optionName, $arrDefaultValues))
|
55 |
+
return;
|
56 |
+
|
57 |
+
$optionValue = $this->getOption($optionName);
|
58 |
+
// if(null === $optionValue && isset($arrDefaultValues[$optionName]))
|
59 |
+
// {
|
60 |
+
// if(!is_array($arrDefaultValues[$optionName])) {
|
61 |
+
// $optionValue = $arrDefaultValues[$optionName];
|
62 |
+
// }
|
63 |
+
// }
|
64 |
+
|
65 |
+
$arrSettingsField = $arrSettingsField[$optionName];
|
66 |
+
$arrFieldAttributes = array(
|
67 |
+
'name' => $this->getSettingKey() . '[' . $optionName . ']',
|
68 |
+
'type' => !empty($arrSettingsField['InputType']) ? $arrSettingsField['InputType'] : 'text',
|
69 |
+
'value' => $optionValue,
|
70 |
+
'id' => $this->getSettingKey() . '-' . $optionName,
|
71 |
+
);
|
72 |
+
|
73 |
+
if($arrFieldAttributes['type'] === MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX)
|
74 |
+
{
|
75 |
+
!empty($arrFieldAttributes['value']) ? $arrFieldAttributes['checked'] = 'checked' : null;
|
76 |
+
$arrFieldAttributes['value'] = true;
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
switch ($arrFieldAttributes['type'])
|
81 |
+
{
|
82 |
+
case MchGdbcHtmlUtils::FORM_ELEMENT_SELECT :
|
83 |
+
|
84 |
+
echo MchGdbcHtmlUtils::createSelectElement($arrFieldAttributes);
|
85 |
+
|
86 |
+
break;
|
87 |
+
|
88 |
+
default :
|
89 |
+
|
90 |
+
echo MchGdbcHtmlUtils::createInputElement($arrFieldAttributes);
|
91 |
+
}
|
92 |
+
|
93 |
+
if(!empty($arrSettingsField['Description']))
|
94 |
+
{
|
95 |
+
echo '<p class = "description">' . $arrSettingsField['Description'] . '</p>';
|
96 |
+
}
|
97 |
+
|
98 |
+
}
|
99 |
+
|
100 |
+
protected function getFormattedFieldDescription($description)
|
101 |
+
{
|
102 |
+
return '<p class = "description">' . esc_html( $description ); '</p>';
|
103 |
+
}
|
104 |
+
|
105 |
+
|
106 |
+
public function getOptionDisplayTextByOptionId($settingOptionId)
|
107 |
+
{
|
108 |
+
$settingOptionId = (int)$settingOptionId;
|
109 |
+
|
110 |
+
foreach($this->getDefaultOptions() as $arrOptionInfo)
|
111 |
+
{
|
112 |
+
if (isset($arrOptionInfo['Id']) && $arrOptionInfo['Id'] === $settingOptionId && isset($arrOptionInfo['DisplayText']))
|
113 |
+
return esc_html($arrOptionInfo['DisplayText']);
|
114 |
+
}
|
115 |
+
|
116 |
+
return null;
|
117 |
+
}
|
118 |
+
|
119 |
+
public function getOptionIdByOptionName($settingOptionName)
|
120 |
+
{
|
121 |
+
$arrDefaultSettingOptions = $this->getDefaultOptions();
|
122 |
+
|
123 |
+
return isset($arrDefaultSettingOptions[$settingOptionName]['Id']) ? $arrDefaultSettingOptions[$settingOptionName]['Id'] : 0;
|
124 |
+
}
|
125 |
+
|
126 |
+
public function getOptionNameByOptionId($settingOptionId)
|
127 |
+
{
|
128 |
+
$settingOptionId = (int)$settingOptionId;
|
129 |
+
foreach($this->getDefaultOptions() as $optionName => $arrOptionInfo)
|
130 |
+
{
|
131 |
+
if (isset($arrOptionInfo['Id']) && (int)$arrOptionInfo['Id'] === $settingOptionId)
|
132 |
+
return $optionName;
|
133 |
+
}
|
134 |
+
|
135 |
+
return null;
|
136 |
+
}
|
137 |
+
|
138 |
+
protected static function getBlockedContentDisplayableKey($blockedContentKey)
|
139 |
+
{
|
140 |
+
$arrMappedKeys = array(
|
141 |
+
|
142 |
+
'username' => __('Username', GoodByeCaptcha::PLUGIN_SLUG),
|
143 |
+
'password' => __('Password', GoodByeCaptcha::PLUGIN_SLUG),
|
144 |
+
'email' => __('Email', GoodByeCaptcha::PLUGIN_SLUG),
|
145 |
+
'post' => __('Post', GoodByeCaptcha::PLUGIN_SLUG),
|
146 |
+
'page' => __('Page', GoodByeCaptcha::PLUGIN_SLUG),
|
147 |
+
|
148 |
+
'comment_post_ID' => __('Post Id', GoodByeCaptcha::PLUGIN_SLUG),
|
149 |
+
'comment_author' => __('Author', GoodByeCaptcha::PLUGIN_SLUG),
|
150 |
+
'comment_author_email' => __('Email', GoodByeCaptcha::PLUGIN_SLUG),
|
151 |
+
'comment_author_url' => __('Website', GoodByeCaptcha::PLUGIN_SLUG),
|
152 |
+
'comment_content' => __('Content', GoodByeCaptcha::PLUGIN_SLUG),
|
153 |
+
'comment_parent' => __('As Reply to', GoodByeCaptcha::PLUGIN_SLUG),
|
154 |
+
|
155 |
+
'your-name' => __('Name', GoodByeCaptcha::PLUGIN_SLUG),
|
156 |
+
'your-email' => __('Email', GoodByeCaptcha::PLUGIN_SLUG),
|
157 |
+
'your-subject' => __('Subject', GoodByeCaptcha::PLUGIN_SLUG),
|
158 |
+
'your-message' => __('Message', GoodByeCaptcha::PLUGIN_SLUG),
|
159 |
+
|
160 |
+
'page-url' => __('Page URL', GoodByeCaptcha::PLUGIN_SLUG),
|
161 |
+
'post-url' => __('Post URL', GoodByeCaptcha::PLUGIN_SLUG),
|
162 |
+
|
163 |
+
'ADDRESS' => __('Address', GoodByeCaptcha::PLUGIN_SLUG),
|
164 |
+
'FNAME' => __('First Name', GoodByeCaptcha::PLUGIN_SLUG),
|
165 |
+
'LNAME' => __('Last Name', GoodByeCaptcha::PLUGIN_SLUG),
|
166 |
+
'NNAME' => __('Nick Name', GoodByeCaptcha::PLUGIN_SLUG),
|
167 |
+
'GROUPINGS' => __('Group', GoodByeCaptcha::PLUGIN_SLUG),
|
168 |
+
'EMAIL' => __('Email', GoodByeCaptcha::PLUGIN_SLUG),
|
169 |
+
|
170 |
+
|
171 |
+
'honoreestate' => __('State', GoodByeCaptcha::PLUGIN_SLUG),
|
172 |
+
'honoreeprovince' => __('Province', GoodByeCaptcha::PLUGIN_SLUG),
|
173 |
+
'honoreecountry' => __('Country', GoodByeCaptcha::PLUGIN_SLUG),
|
174 |
+
|
175 |
+
'firstname' => __('First Name', GoodByeCaptcha::PLUGIN_SLUG),
|
176 |
+
'lastname' => __('Last Name', GoodByeCaptcha::PLUGIN_SLUG),
|
177 |
+
'phone' => __('Phone', GoodByeCaptcha::PLUGIN_SLUG),
|
178 |
+
|
179 |
+
|
180 |
+
'country' => __('Country', GoodByeCaptcha::PLUGIN_SLUG),
|
181 |
+
'item_name' => __('Item', GoodByeCaptcha::PLUGIN_SLUG),
|
182 |
+
'amount' => __('Amount', GoodByeCaptcha::PLUGIN_SLUG),
|
183 |
+
'paymentmethod' => __('Method', GoodByeCaptcha::PLUGIN_SLUG),
|
184 |
+
|
185 |
+
|
186 |
+
'secretkey' => __('Secret key', GoodByeCaptcha::PLUGIN_SLUG),
|
187 |
+
'authorid' => __('Author Id', GoodByeCaptcha::PLUGIN_SLUG),
|
188 |
+
);
|
189 |
+
|
190 |
+
$blockedKey = trim($blockedContentKey);
|
191 |
+
return isset($arrMappedKeys[$blockedKey]) ? $arrMappedKeys[$blockedKey] : esc_html($blockedContentKey);
|
192 |
+
}
|
193 |
+
|
194 |
+
}
|
2.0/engine/modules/GdbcBasePublicModule.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class GdbcBasePublicModule extends MchGdbcBasePublicModule
|
21 |
+
{
|
22 |
+
private $submittedData = null;
|
23 |
+
|
24 |
+
|
25 |
+
protected $attemptEntity = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @return int
|
29 |
+
*/
|
30 |
+
protected abstract function getModuleId();
|
31 |
+
|
32 |
+
protected function __construct()
|
33 |
+
{
|
34 |
+
parent::__construct();
|
35 |
+
|
36 |
+
$this->submittedData = array();
|
37 |
+
$this->attemptEntity = new GdbcAttemptEntity($this->getModuleId());
|
38 |
+
}
|
39 |
+
|
40 |
+
protected function getAllSavedOptions($asNetworkOption = true)
|
41 |
+
{
|
42 |
+
return parent::getAllSavedOptions(GoodByeCaptcha::isNetworkActivated());
|
43 |
+
}
|
44 |
+
|
45 |
+
public function getOption($optionName, $asNetworkOption = true)
|
46 |
+
{
|
47 |
+
return parent::getOption($optionName, GoodByeCaptcha::isNetworkActivated());
|
48 |
+
}
|
49 |
+
|
50 |
+
protected function setSubmittedData(array $submittedData)
|
51 |
+
{
|
52 |
+
$this->submittedData = $submittedData;
|
53 |
+
}
|
54 |
+
|
55 |
+
protected function getSubmittedData()
|
56 |
+
{
|
57 |
+
return $this->submittedData;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @return GdbcAttemptEntity | null
|
62 |
+
*/
|
63 |
+
|
64 |
+
protected function getAttemptEntity()
|
65 |
+
{
|
66 |
+
return $this->attemptEntity;
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
public function getOptionIdByOptionName($settingOptionName)
|
71 |
+
{
|
72 |
+
|
73 |
+
$adminModuleInstance = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::getModuleNameById($this->getModuleId()));
|
74 |
+
if(null === $adminModuleInstance)
|
75 |
+
return 0;
|
76 |
+
|
77 |
+
return $adminModuleInstance->getOptionIdByOptionName($settingOptionName);
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
public function renderTokenFieldIntoForm()
|
83 |
+
{
|
84 |
+
echo $this->getTokenFieldHtml();
|
85 |
+
}
|
86 |
+
|
87 |
+
public function getTokenFieldHtml()
|
88 |
+
{
|
89 |
+
$hiddenField = GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_HIDDEN_INPUT_NAME);
|
90 |
+
if(!isset($hiddenField[0]))
|
91 |
+
{
|
92 |
+
GdbcSettingsAdminModule::getInstance()->saveSecuredOptions(true);
|
93 |
+
$hiddenField = GdbcSettingsPublicModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_HIDDEN_INPUT_NAME);
|
94 |
+
}
|
95 |
+
|
96 |
+
return '<input type="hidden" autocomplete="off" autocorrect="off" name="' . esc_attr( $hiddenField ) . '" value="" />';
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
}
|
{engine → 2.0/engine}/modules/black-listed-ips/GdbcBlackListedIpsAdminModule.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/black-listed-ips/GdbcBlackListedIpsPublicModule.php
RENAMED
File without changes
|
2.0/engine/modules/black-listed-ips/partials/admin-settings.php
ADDED
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
?>
|
20 |
+
<style type="text/css">
|
21 |
+
|
22 |
+
.gdbc-settings tr.even
|
23 |
+
{
|
24 |
+
background-color:#f5f5f5;
|
25 |
+
}
|
26 |
+
|
27 |
+
.gdbc-blacklisted-ips-holder input[type="text"]
|
28 |
+
{
|
29 |
+
width: 99%;
|
30 |
+
}
|
31 |
+
.gdbc-blacklisted-ips-holder thead tbody > tr form > td:first-child
|
32 |
+
{
|
33 |
+
padding: 0 30px !important;
|
34 |
+
}
|
35 |
+
|
36 |
+
.gdbc-blacklisted-ips-holder td
|
37 |
+
{
|
38 |
+
vertical-align: middle !important;
|
39 |
+
word-wrap: normal !important;
|
40 |
+
}
|
41 |
+
.gdbc-blacklisted-ips-holder th
|
42 |
+
{
|
43 |
+
font-weight: 700;
|
44 |
+
}
|
45 |
+
|
46 |
+
.gdbc-settings .tablenav-pages span.current {
|
47 |
+
font-size: 18px;
|
48 |
+
font-weight: bold;
|
49 |
+
line-height: 30px;
|
50 |
+
padding: 4px 6px;
|
51 |
+
text-decoration: none;
|
52 |
+
}
|
53 |
+
|
54 |
+
</style>
|
55 |
+
|
56 |
+
<?php
|
57 |
+
|
58 |
+
$formAction = GoodByeCaptcha::isNetworkActivated() ? '' : 'options.php';
|
59 |
+
|
60 |
+
?>
|
61 |
+
|
62 |
+
|
63 |
+
<table class="wp-list-table widefat fixed gdbc-blacklisted-ips-holder">
|
64 |
+
<thead>
|
65 |
+
|
66 |
+
<tr>
|
67 |
+
<th></th>
|
68 |
+
<th></th>
|
69 |
+
<th></th>
|
70 |
+
<th></th>
|
71 |
+
</tr>
|
72 |
+
|
73 |
+
|
74 |
+
<tr class = "even">
|
75 |
+
<td colspan="4" style=" text-align: right">
|
76 |
+
<form method="post" action="<?php echo $formAction ?>">
|
77 |
+
<div class="clearfix" style="margin:0 auto; width: 700px;">
|
78 |
+
<input style = "float: left;clear: left; width: 80%;" type="text" name="<?php echo $this->getBlackListedIpsInputName();?>" placeholder="<?php _e('IP/RANGE/CIDR', GoodByeCaptcha::PLUGIN_SLUG); ?>" required />
|
79 |
+
<input style = "float: right;" type="submit" value="<?php _e('Add to BlackList', GoodByeCaptcha::PLUGIN_SLUG); ?>" class="button button-primary" />
|
80 |
+
</div>
|
81 |
+
|
82 |
+
<?php settings_fields( $this->getSettingGroupId($this->blackListedIpsGroupIndex) );?>
|
83 |
+
|
84 |
+
</form>
|
85 |
+
</td>
|
86 |
+
</tr>
|
87 |
+
<tr>
|
88 |
+
<th width="5%"></th>
|
89 |
+
<th width="30%"></th>
|
90 |
+
<th width="50%"></th>
|
91 |
+
<th width="15%"></th>
|
92 |
+
</tr>
|
93 |
+
|
94 |
+
<tr>
|
95 |
+
<th width="5%"><?php _e('Blocked Hosts', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
96 |
+
<th width="30%"><?php _e('IP Address/Range/CIDR', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
97 |
+
<th width="60%"><?php _e('Country', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
98 |
+
<th width="5%" style="text-align: right; padding-right: 22px"><?php _e('Actions', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
99 |
+
</tr>
|
100 |
+
|
101 |
+
</thead>
|
102 |
+
|
103 |
+
<tbody>
|
104 |
+
<?php
|
105 |
+
|
106 |
+
$arrAllIPs = GdbcIPUtils::getFormattedIpRangesForDisplay(GdbcBlackListedIpsAdminModule::getInstance()->getOption(GdbcBlackListedIpsAdminModule::OPTION_BLACK_LISTED_IPS));
|
107 |
+
|
108 |
+
$blackListPageNumber = !empty( $_GET['blackListPageNumber'] ) ? absint( sanitize_text_field($_GET['blackListPageNumber']) ) : 1;
|
109 |
+
|
110 |
+
$recordsPerPage = 10;
|
111 |
+
|
112 |
+
$paginationCode = null;
|
113 |
+
|
114 |
+
$arrRecords = array_chunk($arrAllIPs, $recordsPerPage, true);
|
115 |
+
|
116 |
+
if(isset($arrRecords[1]))
|
117 |
+
{
|
118 |
+
$paginationCode = paginate_links(
|
119 |
+
array(
|
120 |
+
'base' => add_query_arg( 'blackListPageNumber', '%#%' ),
|
121 |
+
'format' => '',
|
122 |
+
'prev_text' => __( '«', GoodByeCaptcha::PLUGIN_SLUG ),
|
123 |
+
'next_text' => __( '»', GoodByeCaptcha::PLUGIN_SLUG ),
|
124 |
+
'total' => ceil(count($arrAllIPs)/$recordsPerPage),
|
125 |
+
'current' => $blackListPageNumber
|
126 |
+
)
|
127 |
+
);
|
128 |
+
}
|
129 |
+
|
130 |
+
if(!empty($arrRecords[$blackListPageNumber - 1]))
|
131 |
+
$arrRecords = $arrRecords[$blackListPageNumber - 1];
|
132 |
+
else
|
133 |
+
$arrRecords = $arrAllIPs;
|
134 |
+
|
135 |
+
foreach($arrRecords as $key => $formattedIp)
|
136 |
+
{
|
137 |
+
|
138 |
+
$arrFormattedIp = explode('|', $formattedIp);
|
139 |
+
if(count($arrFormattedIp) != 2)
|
140 |
+
continue;
|
141 |
+
|
142 |
+
$countryCode = sanitize_text_field(MchGdbcIPUtils::getCountryCode($arrFormattedIp[0]));
|
143 |
+
|
144 |
+
$countryName = GoodByeCaptchaUtils::getCountryNameById(GoodByeCaptchaUtils::getCountryIdByCode($countryCode));
|
145 |
+
|
146 |
+
if(empty($countryName))
|
147 |
+
{
|
148 |
+
$countryName = __('Unavailable', GoodByeCaptcha::PLUGIN_SLUG);
|
149 |
+
}
|
150 |
+
|
151 |
+
$rowClass = (($key % 2) == 0) ? 'even' : '';
|
152 |
+
|
153 |
+
echo '<tr class="' . $rowClass . '">';
|
154 |
+
|
155 |
+
echo '<td width="5%">' . $arrFormattedIp[1] . '</td>';
|
156 |
+
echo '<td width="30%">' . strtoupper($arrFormattedIp[0]) . '</td>';
|
157 |
+
echo '<td width="60%">' . $countryName . '</td>';
|
158 |
+
|
159 |
+
?>
|
160 |
+
|
161 |
+
<td style="text-align: right;" width="5%">
|
162 |
+
<form method="post" action="<?php echo $formAction ?>">
|
163 |
+
<?php settings_fields( $this->getSettingGroupId($this->blackListedIpsGroupIndex) );?>
|
164 |
+
<input type="hidden" name="<?php echo $this->getBlackListedIpsInputName();?>" value="<?php echo 'remove-' . $arrFormattedIp[0]?>" />
|
165 |
+
<input type="submit" value="<?php echo __('Remove', GoodByeCaptcha::PLUGIN_SLUG); ?>" class="button" />
|
166 |
+
</form>
|
167 |
+
</td>
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
<?php
|
172 |
+
|
173 |
+
echo '</tr>';
|
174 |
+
|
175 |
+
}
|
176 |
+
|
177 |
+
|
178 |
+
?>
|
179 |
+
|
180 |
+
|
181 |
+
</tbody>
|
182 |
+
</table>
|
183 |
+
|
184 |
+
|
185 |
+
<?php
|
186 |
+
if(!empty($paginationCode))
|
187 |
+
{
|
188 |
+
echo '<div class="postbox-footer clearfix" style="">';
|
189 |
+
echo '<div class="tablenav"><div class="tablenav-pages" style="margin:0">' . $paginationCode . '</div></div></div>';
|
190 |
+
}
|
191 |
+
?>
|
192 |
+
|
193 |
+
|
194 |
+
<div class="postbox-footer clearfix" style="">
|
195 |
+
|
196 |
+
<dl style="width: 48%; float: left; border-right: 1px solid #ddd; padding-right: 15px">
|
197 |
+
<dt><h4 style="margin: 2px 0; border-bottom: 1px solid #ccc;">Accepted IPV4 Formats</h4></dt>
|
198 |
+
<dd style="margin-left: 0">Standard IPV4 format <span style="float: right">123.123.1.1</span></dd>
|
199 |
+
<dd style="margin-left: 0">Standard CIDR Block format <span style="float: right">123.123.1.1/32</span></dd>
|
200 |
+
<dd style="margin-left: 0">Wildcard Range format <span style="float: right">123.123.1.*</span></dd>
|
201 |
+
<dd style="margin-left: 0">Non-Standard Range format <span style="float: right">123.123.1.1 - 123.123.1.10</span></dd>
|
202 |
+
</dl>
|
203 |
+
|
204 |
+
<dl style="width: 50%; float: right;" >
|
205 |
+
<dt><h4 style="margin: 2px 0; border-bottom: 1px solid #ccc;">Accepted IPV6 Formats</h4></dt>
|
206 |
+
<dd style="margin-left: 0">Fully Uncompressed format <span style="float: right">2002:4559:1FE2:0000:0000:0000:4559:1FE2</span></dd>
|
207 |
+
<dd style="margin-left: 0">Standard CIDR Block format <span style="float: right">2002:4559:1FE2::4559:1FE2/128</span></dd>
|
208 |
+
<dd style="margin-left: 0">Uncompressed format <span style="float: right">2002:4559:1FE2:0:0:0:4559:1FE2</span></dd>
|
209 |
+
<dd style="margin-left: 0">Compressed format <span style="float: right">2002:4559:1FE2::4559:1FE2</span></dd>
|
210 |
+
</dl>
|
211 |
+
|
212 |
+
</div>
|
213 |
+
|
214 |
+
|
2.0/engine/modules/brute-force/GdbcBruteForceAdminModule.php
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcBruteForceAdminModule extends GdbcBaseAdminModule
|
21 |
+
{
|
22 |
+
CONST OPTION_AUTO_BLOCK_IP = 'AutoBlockIp';
|
23 |
+
CONST OPTION_PREVENT_USER_ENUM = 'PreventUserEnum';
|
24 |
+
CONST OPTION_BLOCK_ANONYMOUS_PROXY = 'AnonymousProxy';
|
25 |
+
CONST OPTION_BLOCK_WEB_ATTACKERS = 'WebAttackers';
|
26 |
+
|
27 |
+
protected function __construct()
|
28 |
+
{
|
29 |
+
parent::__construct();
|
30 |
+
}
|
31 |
+
|
32 |
+
public function getDefaultOptions()
|
33 |
+
{
|
34 |
+
static $arrDefaultSettingOptions = null;
|
35 |
+
if(null !== $arrDefaultSettingOptions)
|
36 |
+
return $arrDefaultSettingOptions;
|
37 |
+
|
38 |
+
$arrDefaultSettingOptions = array(
|
39 |
+
|
40 |
+
self::OPTION_AUTO_BLOCK_IP => array(
|
41 |
+
'Id' => 1,
|
42 |
+
'Value' => NULL,
|
43 |
+
'LabelText' => __('Automatically Block IP Addresses', GoodByeCaptcha::PLUGIN_SLUG),
|
44 |
+
'Description' => __('Automatically block IP Addresses that are brute-forcing your system', GoodByeCaptcha::PLUGIN_SLUG),
|
45 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
46 |
+
),
|
47 |
+
|
48 |
+
self::OPTION_PREVENT_USER_ENUM => array(
|
49 |
+
'Id' => 2,
|
50 |
+
'Value' => true,
|
51 |
+
'LabelText' => __('Prevent User Enumeration', GoodByeCaptcha::PLUGIN_SLUG),
|
52 |
+
'Description' => __('Prevents bots from enumerating users by ID in order to find their real username', GoodByeCaptcha::PLUGIN_SLUG),
|
53 |
+
'DisplayText' => __('UserEnumeration', GoodByeCaptcha::PLUGIN_SLUG),
|
54 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
55 |
+
),
|
56 |
+
|
57 |
+
|
58 |
+
self::OPTION_BLOCK_WEB_ATTACKERS => array(
|
59 |
+
'Id' => 3,
|
60 |
+
'Value' => NULL,
|
61 |
+
'LabelText' => __('Block Web Attackers IPs', GoodByeCaptcha::PLUGIN_SLUG),
|
62 |
+
'Description' => __('Blocks most dangerous IP addresses involved in brute force attacks, cross-site scripting or SQL injection', GoodByeCaptcha::PLUGIN_SLUG),
|
63 |
+
'DisplayText' => __('Attacker', GoodByeCaptcha::PLUGIN_SLUG),
|
64 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
65 |
+
),
|
66 |
+
|
67 |
+
self::OPTION_BLOCK_ANONYMOUS_PROXY => array(
|
68 |
+
'Id' => 4,
|
69 |
+
'Value' => NULL,
|
70 |
+
'LabelText' => __('Block Anonymous Proxy IPs', GoodByeCaptcha::PLUGIN_SLUG),
|
71 |
+
'Description' => __('Blocks most dangerous IP addresses associated with web proxies that shield the originator\'s IP address', GoodByeCaptcha::PLUGIN_SLUG),
|
72 |
+
'DisplayText' => __('Anonymizer', GoodByeCaptcha::PLUGIN_SLUG),
|
73 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
74 |
+
),
|
75 |
+
|
76 |
+
);
|
77 |
+
|
78 |
+
return $arrDefaultSettingOptions;
|
79 |
+
|
80 |
+
}
|
81 |
+
|
82 |
+
public function renderModuleSettingsField(array $arrSettingsField)
|
83 |
+
{
|
84 |
+
|
85 |
+
$optionName = key($arrSettingsField);
|
86 |
+
if(null === $optionName || !array_key_exists($optionName, $this->getDefaultOptionsValues()))
|
87 |
+
return;
|
88 |
+
|
89 |
+
parent::renderModuleSettingsField($arrSettingsField);
|
90 |
+
}
|
91 |
+
|
92 |
+
|
93 |
+
public function validateModuleSettingsFields($arrSettingOptions)
|
94 |
+
{
|
95 |
+
$arrSettingOptions = array_map('sanitize_text_field', (array)$arrSettingOptions);
|
96 |
+
|
97 |
+
$this->registerSuccessMessage(__('Your changes were successfully saved!', GoodByeCaptcha::PLUGIN_SLUG));
|
98 |
+
|
99 |
+
return $arrSettingOptions;
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
public function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity)
|
104 |
+
{
|
105 |
+
$attemptEntity->Notes = (array)maybe_unserialize($attemptEntity->Notes);
|
106 |
+
$arrContent = array('table-head-rows' => '', 'table-body-rows' => '');
|
107 |
+
|
108 |
+
$section = null;
|
109 |
+
switch($this->getOptionNameByOptionId($attemptEntity->SectionId))
|
110 |
+
{
|
111 |
+
case self::OPTION_PREVENT_USER_ENUM :
|
112 |
+
$section = __('User Enumeration', GoodByeCaptcha::PLUGIN_SLUG);
|
113 |
+
break;
|
114 |
+
|
115 |
+
default:
|
116 |
+
$section = __('Brute Force', GoodByeCaptcha::PLUGIN_SLUG);
|
117 |
+
break;
|
118 |
+
|
119 |
+
}
|
120 |
+
|
121 |
+
$tableHeadRows = '';
|
122 |
+
$tableBodyRows = '';
|
123 |
+
|
124 |
+
$tableHeadRows .= '<tr>';
|
125 |
+
$tableHeadRows .= '<th colspan="2">' . sprintf(__("%s - Blocked Attempt", GoodByeCaptcha::PLUGIN_SLUG), $section) . '</th>';
|
126 |
+
$tableHeadRows .= '</tr>';
|
127 |
+
|
128 |
+
$tableHeadRows .= '<tr>';
|
129 |
+
$tableHeadRows .= '<th>' . __('Field', GoodByeCaptcha::PLUGIN_SLUG) . '</th>';
|
130 |
+
$tableHeadRows .= '<th>' . __('Value', GoodByeCaptcha::PLUGIN_SLUG) . '</th>';
|
131 |
+
$tableHeadRows .= '</tr>';
|
132 |
+
|
133 |
+
|
134 |
+
foreach($attemptEntity->Notes as $key => $value)
|
135 |
+
{
|
136 |
+
$tableBodyRows .='<tr>';
|
137 |
+
$tableBodyRows .= '<td>' . self::getBlockedContentDisplayableKey($key) . '</td>';
|
138 |
+
$tableBodyRows .= '<td>' . wp_filter_kses(print_r($value, true)) . '</td>';
|
139 |
+
$tableBodyRows .='</tr>';
|
140 |
+
}
|
141 |
+
|
142 |
+
$arrContent['table-head-rows'] = $tableHeadRows;
|
143 |
+
$arrContent['table-body-rows'] = $tableBodyRows;
|
144 |
+
|
145 |
+
return $arrContent;
|
146 |
+
|
147 |
+
}
|
148 |
+
|
149 |
+
public static function getInstance()
|
150 |
+
{
|
151 |
+
static $adminInstance = null;
|
152 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
153 |
+
}
|
154 |
+
|
155 |
+
|
156 |
+
}
|
2.0/engine/modules/brute-force/GdbcBruteForcePublicModule.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcBruteForcePublicModule extends GdbcBasePublicModule
|
21 |
+
{
|
22 |
+
private $preventUserEnumHookIndex = null;
|
23 |
+
|
24 |
+
protected function __construct()
|
25 |
+
{
|
26 |
+
parent::__construct();
|
27 |
+
|
28 |
+
if($this->getOption(GdbcBruteForceAdminModule::OPTION_PREVENT_USER_ENUM))
|
29 |
+
{
|
30 |
+
$this->preventUserEnumHookIndex = $this->addActionHook('pre_get_posts', array($this, 'checkUserEnumeration'), 10, 1);
|
31 |
+
}
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
public function checkUserEnumeration($wpQuery)
|
36 |
+
{
|
37 |
+
if(!$wpQuery->is_main_query() || !$wpQuery->is_author() || empty($_REQUEST['author']) || !is_numeric($_REQUEST['author']))
|
38 |
+
return;
|
39 |
+
|
40 |
+
$wpQuery->set('author_name', '');
|
41 |
+
|
42 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName(GdbcBruteForceAdminModule::OPTION_PREVENT_USER_ENUM);
|
43 |
+
$this->attemptEntity->Notes = array('authorid'=>absint($_REQUEST['author']));
|
44 |
+
$this->attemptEntity->ReasonId = GdbcRequestController::REJECT_REASON_USER_ENUMERATION;
|
45 |
+
|
46 |
+
GdbcBruteGuardian::logRejectedAttempt($this->attemptEntity);
|
47 |
+
|
48 |
+
GdbcRequestController::redirectToHomePage();
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @return int
|
54 |
+
*/
|
55 |
+
protected function getModuleId()
|
56 |
+
{
|
57 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_BRUTE_FORCE);
|
58 |
+
}
|
59 |
+
|
60 |
+
public static function getInstance()
|
61 |
+
{
|
62 |
+
static $publicInstance = null;
|
63 |
+
return null !== $publicInstance ? $publicInstance : $publicInstance = new self();
|
64 |
+
}
|
65 |
+
|
66 |
+
}
|
2.0/engine/modules/email-notifications/GdbcEmailNotificationsAdminModule.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcEmailNotificationsAdminModule extends GdbcBaseAdminModule
|
21 |
+
{
|
22 |
+
CONST OPTION_EMAIL_ADDRESS = 'Email';
|
23 |
+
CONST OPTION_TEST_MODE_NOTIFICATION = 'TestModeNotification';
|
24 |
+
CONST OPTION_BRUTE_FORCE_ATTACK_DETECTED = 'IsUnderAttack';
|
25 |
+
|
26 |
+
protected function __construct()
|
27 |
+
{
|
28 |
+
parent::__construct();
|
29 |
+
}
|
30 |
+
|
31 |
+
public function getDefaultOptions()
|
32 |
+
{
|
33 |
+
static $arrDefaultSettingOptions = null;
|
34 |
+
if(null !== $arrDefaultSettingOptions)
|
35 |
+
return $arrDefaultSettingOptions;
|
36 |
+
|
37 |
+
$arrDefaultSettingOptions = array(
|
38 |
+
|
39 |
+
self::OPTION_BRUTE_FORCE_ATTACK_DETECTED => array(
|
40 |
+
'Value' => true,
|
41 |
+
'LabelText' => __('Brute Force Attack Detected', GoodByeCaptcha::PLUGIN_SLUG),
|
42 |
+
'Description' => __('A notification email will be sent when a brute force attack is detected', GoodByeCaptcha::PLUGIN_SLUG),
|
43 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
44 |
+
),
|
45 |
+
|
46 |
+
self::OPTION_EMAIL_ADDRESS => array(
|
47 |
+
'Value' => MchGdbcWpUtils::getAdminEmailAddress(),
|
48 |
+
'LabelText' => __('Administrator Email Address', GoodByeCaptcha::PLUGIN_SLUG),
|
49 |
+
'Description' => __('The email address where GoodBye Captcha will send notifications', GoodByeCaptcha::PLUGIN_SLUG),
|
50 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_TEXT
|
51 |
+
),
|
52 |
+
|
53 |
+
);
|
54 |
+
|
55 |
+
return $arrDefaultSettingOptions;
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
public function renderModuleSettingsSectionHeader(array $arrSectionInfo)
|
61 |
+
{
|
62 |
+
echo '<h3>' . __('Email Notifications Settings', GoodByeCaptcha::PLUGIN_SLUG) . '</h3><hr />';
|
63 |
+
}
|
64 |
+
|
65 |
+
public function renderModuleSettingsField(array $arrSettingsField)
|
66 |
+
{
|
67 |
+
parent::renderModuleSettingsField($arrSettingsField);
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
public function validateModuleSettingsFields($arrSettingOptions)
|
72 |
+
{
|
73 |
+
|
74 |
+
$arrSettingOptions = array_map('sanitize_text_field', (array)$arrSettingOptions);
|
75 |
+
if(!empty($arrSettingOptions[self::OPTION_EMAIL_ADDRESS]))
|
76 |
+
{
|
77 |
+
$arrSettingOptions[self::OPTION_EMAIL_ADDRESS] = sanitize_email($arrSettingOptions[self::OPTION_EMAIL_ADDRESS]);
|
78 |
+
if(false === is_email($arrSettingOptions[self::OPTION_EMAIL_ADDRESS])){
|
79 |
+
$this->registerErrorMessage(__('Please provide a valid email address!', GoodByeCaptcha::PLUGIN_SLUG));
|
80 |
+
unset($arrSettingOptions[self::OPTION_EMAIL_ADDRESS]);
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
$this->registerSuccessMessage(__('Your changes were successfully saved!', GoodByeCaptcha::PLUGIN_SLUG));
|
85 |
+
|
86 |
+
return $arrSettingOptions;
|
87 |
+
|
88 |
+
}
|
89 |
+
|
90 |
+
public static function getInstance()
|
91 |
+
{
|
92 |
+
static $adminInstance = null;
|
93 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
94 |
+
}
|
95 |
+
|
96 |
+
public function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity)
|
97 |
+
{
|
98 |
+
return null;
|
99 |
+
}
|
100 |
+
|
101 |
+
}
|
2.0/engine/modules/email-notifications/GdbcEmailNotificationsPublicModule.php
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcEmailNotificationsPublicModule extends GdbcBasePublicModule
|
21 |
+
{
|
22 |
+
|
23 |
+
//private $layoutTemplateFilePath = null;
|
24 |
+
//private $isHtmlFormattedEmail = false;
|
25 |
+
|
26 |
+
//public $AddressToSend = null;
|
27 |
+
public $EmailSubject = null;
|
28 |
+
public $EmailBodyContent = null;
|
29 |
+
|
30 |
+
protected function __construct()
|
31 |
+
{
|
32 |
+
parent::__construct();
|
33 |
+
|
34 |
+
if( ! function_exists('wp_mail') ) {
|
35 |
+
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
protected function getModuleId()
|
41 |
+
{
|
42 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_EMAIL_NOTIFICATIONS);
|
43 |
+
}
|
44 |
+
|
45 |
+
public static function getInstance()
|
46 |
+
{
|
47 |
+
static $publicInstance = null;
|
48 |
+
return null !== $publicInstance ? $publicInstance : $publicInstance = new self();
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
public function send($isHtmlFormattedEmail = true)
|
53 |
+
{
|
54 |
+
$emailHeaders = array();
|
55 |
+
$isHtmlFormattedEmail ? $emailHeaders[] = 'Content-Type: text/html; charset=UTF-8' : null;
|
56 |
+
|
57 |
+
$emailAddressToSend = $this->getOption(GdbcEmailNotificationsAdminModule::OPTION_EMAIL_ADDRESS);
|
58 |
+
|
59 |
+
empty($emailAddressToSend) ? $emailAddressToSend = MchGdbcWpUtils::getAdminEmailAddress() : null;
|
60 |
+
|
61 |
+
empty($this->EmailSubject) ? $this->EmailSubject = __('GoodBye Captcha Notification', GoodByeCaptcha::PLUGIN_SLUG) : null;
|
62 |
+
|
63 |
+
//$emailContent = file_get_contents($this->layoutTemplateFilePath);
|
64 |
+
|
65 |
+
$emailContent = @file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'notification-base-layout.html');
|
66 |
+
|
67 |
+
if(false !== $emailContent)
|
68 |
+
{
|
69 |
+
$emailContent = str_replace('{email-body-content}', trim($this->EmailBodyContent), $emailContent);
|
70 |
+
}
|
71 |
+
else
|
72 |
+
{
|
73 |
+
$emailContent = trim($this->EmailBodyContent);
|
74 |
+
}
|
75 |
+
|
76 |
+
@wp_mail($emailAddressToSend, $this->EmailSubject, $emailContent, $emailHeaders);
|
77 |
+
|
78 |
+
}
|
79 |
+
|
80 |
+
|
81 |
+
}
|
2.0/engine/modules/email-notifications/templates/notification-base-layout.html
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
|
3 |
+
<body style="background: #fff;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;">
|
4 |
+
|
5 |
+
<div style="max-width:700px;padding:20px;background:#fff;border-radius:5px;margin:0 auto;font-family: Open Sans,Helvetica,Arial;font-size: 15px;color: #666;">
|
6 |
+
|
7 |
+
<div style="color:#444;font-weight:normal;">
|
8 |
+
<div style="text-align:left;font-weight:600;font-size:20px;padding:10px 0; color:#005790">GoodBye Captcha - Notification</div>
|
9 |
+
<div style="clear:both"></div>
|
10 |
+
</div>
|
11 |
+
|
12 |
+
<div style="padding:5px;border-top:solid 3px #eee;">
|
13 |
+
{email-body-content}
|
14 |
+
</div>
|
15 |
+
|
16 |
+
<div style="color: #999;padding: 10px 0; border-top:3px solid #eee; margin-top: 30px;">
|
17 |
+
<div style="">Enjoy a Spam-Free and Bot-Free Wordpress site!</div>
|
18 |
+
<div style="">The <a href="http://www.goodbyecaptcha.com/" style="color: #3ba1da;text-decoration: none;">GoodBye Captcha</a> Team</div>
|
19 |
+
</div>
|
20 |
+
|
21 |
+
<div style="margin-top:10px; padding:15px;background:#eee;border-radius:3px;text-align:center;">If you need any assistance, please feel free to <a href="http://www.goodbyecaptcha.com/contact/" style="color:#3ba1da;text-decoration:none;">contact us</a>.</div>
|
22 |
+
|
23 |
+
</div>
|
24 |
+
|
25 |
+
</body>
|
26 |
+
</html>
|
2.0/engine/modules/email-notifications/templates/notification-brute-force-attack.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>Hi {admin-full-name},</p>
|
2 |
+
<p>On {detection-date-time}, GoodBye Captcha has detected a Brute Force Attack on your {current-site-link} website.</p>
|
3 |
+
|
4 |
+
|
5 |
+
<table width="100%" cellpadding = "0" cellspacing="0" style="border:1px solid #ddd; background-color: transparent; border-spacing:0; border-collapse: collapse">
|
6 |
+
<caption style = "text-align: left">Statistics at detection time</caption>
|
7 |
+
<thead>
|
8 |
+
<tr>
|
9 |
+
|
10 |
+
<th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px; border-top: 0 none; ">Total Hits</th>
|
11 |
+
<th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px;">Total IPs</th>
|
12 |
+
<th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px;">BlackListed IPs</th>
|
13 |
+
<th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px;">Web Attackers IPs</th>
|
14 |
+
<th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px; ">Anonymizers IPs</th>
|
15 |
+
</tr>
|
16 |
+
</thead>
|
17 |
+
|
18 |
+
<tbody>
|
19 |
+
<?php
|
20 |
+
echo '<tr>';
|
21 |
+
|
22 |
+
echo '<td style = "text-align: center; border: 1px solid #ddd; border-top: 0 none;">{total-hits}</td>';
|
23 |
+
echo '<td style = "text-align: center; border: 1px solid #ddd;">{total-ips}</td>';
|
24 |
+
echo '<td style = "text-align: center; border: 1px solid #ddd;">{total-black-listed}</td>';
|
25 |
+
echo '<td style = "text-align: center; border: 1px solid #ddd;">{total-web-attackers}</td>';
|
26 |
+
echo '<td style = "text-align: center; border: 1px solid #ddd;">{total-proxy-anonymizers}</td>';
|
27 |
+
|
28 |
+
echo '</tr>';
|
29 |
+
?>
|
30 |
+
|
31 |
+
</tbody>
|
32 |
+
|
33 |
+
</table>
|
34 |
+
|
35 |
+
<?php
|
36 |
+
if(!empty($arrSuggestions))
|
37 |
+
{
|
38 |
+
?>
|
39 |
+
|
40 |
+
<table width="100%" cellpadding = "0" cellspacing="0" style="margin-top: 30px; background-color: transparent; border-spacing:0; border-collapse: collapse">
|
41 |
+
<caption style = "text-align: left">Suggestions:</caption>
|
42 |
+
<tbody>
|
43 |
+
|
44 |
+
<?php
|
45 |
+
$suggestionsCounter = 0;
|
46 |
+
foreach($arrSuggestions as $suggestion)
|
47 |
+
{
|
48 |
+
echo '<tr>';
|
49 |
+
echo '<td style = "text-align: left; width: 20px;">' . ++$suggestionsCounter . '.</td>';
|
50 |
+
echo '<td style = "text-align: left; ">' . $suggestion . '</td>';
|
51 |
+
echo '</tr>';
|
52 |
+
}
|
53 |
+
?>
|
54 |
+
|
55 |
+
|
56 |
+
</tbody>
|
57 |
+
</table>
|
58 |
+
<?php
|
59 |
+
}
|
60 |
+
?>
|
61 |
+
|
62 |
+
|
63 |
+
<!--<table width="100%" cellpadding = "0" cellspacing="0" style="border:1px solid #ddd; background-color: transparent; border-spacing:0; border-collapse: collapse">-->
|
64 |
+
<!---->
|
65 |
+
<!-- <thead>-->
|
66 |
+
<!-- <tr>-->
|
67 |
+
<!-- <th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px; border-top: 0 none;">No.</th>-->
|
68 |
+
<!-- <th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px;">Client IP</th>-->
|
69 |
+
<!-- <th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px;">Hits</th>-->
|
70 |
+
<!-- <th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px; ">BlackListed</th>-->
|
71 |
+
<!-- <th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px; ">Attacker</th>-->
|
72 |
+
<!-- <th style = "padding:5px; text-align: center; border: 1px solid #ddd; border-bottom-width: 2px; ">Anonymizer</th>-->
|
73 |
+
<!-- </tr>-->
|
74 |
+
<!-- </thead>-->
|
75 |
+
<!---->
|
76 |
+
<!-- <tbody>-->
|
77 |
+
<!---->
|
78 |
+
<?php
|
79 |
+
|
80 |
+
//$ipCounter = 0; $arrLoginAttempts = array();
|
81 |
+
//foreach($arrLoginAttempts as $loginAttempt)
|
82 |
+
//{
|
83 |
+
// echo "<tr>";
|
84 |
+
//
|
85 |
+
// echo '<td style = "text-align: center; border: 1px solid #ddd;">' . (++$ipCounter) . '</td>';
|
86 |
+
// echo '<td style = "text-align: center; border: 1px solid #ddd;">' . $loginAttempt->ClientIp . '</td>';
|
87 |
+
// echo '<td style = "text-align: center; border: 1px solid #ddd;">' . $loginAttempt->Hits . '</td>';
|
88 |
+
//
|
89 |
+
// echo '<td style = "text-align: center; border: 1px solid #ddd;">' . ($loginAttempt->IsIpBlackListed ? 'Yes' : 'No') . '</td>';
|
90 |
+
// echo '<td style = "text-align: center; border: 1px solid #ddd;">' . ($loginAttempt->IsIpWebAttacker ? 'Yes' : 'No') . '</td>';
|
91 |
+
// echo '<td style = "text-align: center; border: 1px solid #ddd;">' . ($loginAttempt->IsIpProxyAnonym ? 'Yes' : 'No') . '</td>';
|
92 |
+
//
|
93 |
+
// echo "</tr>";
|
94 |
+
//}
|
95 |
+
|
96 |
+
?>
|
97 |
+
<!---->
|
98 |
+
<!---->
|
99 |
+
<!---->
|
100 |
+
<!-- </tbody>-->
|
101 |
+
<!--</table>-->
|
2.0/engine/modules/email-notifications/templates/notification-test-mode.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>Hi <?php echo $adminFullName; ?>,</p>
|
2 |
+
<p>GoodBye Captcha was switched to <b>Test Mode</b> on <?php echo $currentSiteLink; ?> and received the following request information:</p>
|
3 |
+
|
4 |
+
<div style = "padding:10px 0 0;color:#333;">
|
5 |
+
<span style="color:#999; width:125px; display:inline-block;">Submitted Form:</span>
|
6 |
+
<span style="font-weight:bold"><?php echo $submittedForm; ?></span>
|
7 |
+
</div>
|
8 |
+
|
9 |
+
<div style = "padding:10px 0 0;color:#333;">
|
10 |
+
<span style="color:#999; width:125px; display:inline-block;">Test Status:</span>
|
11 |
+
<span style="font-weight:bold"><?php echo empty($rejectReason) ? 'Pass' : 'Rejected';?></span>
|
12 |
+
</div>
|
13 |
+
|
14 |
+
<?php if(!empty($rejectReason)){ ?>
|
15 |
+
|
16 |
+
<div style = "padding:10px 0 0;color:#333;">
|
17 |
+
<span style="color:#999; width:125px; display:inline-block;">Reject Reason:</span>
|
18 |
+
<span style="font-weight:bold"><?php echo $rejectReason; ?></span>
|
19 |
+
</div>
|
20 |
+
|
21 |
+
<?php } ?>
|
22 |
+
|
23 |
+
<div style = "padding:10px 0 0;color:#333;">
|
24 |
+
<span style="color:#999; width:125px; display:inline-block;">Client Ip Address:</span>
|
25 |
+
<span style="font-weight:bold"><?php echo $clientIpAddress;?></span>
|
26 |
+
</div>
|
27 |
+
|
28 |
+
<div style = "padding:10px 0 0;color:#333;">
|
29 |
+
<span style="color:#999; width:125px; display:inline-block;">Client User Agent:</span>
|
30 |
+
<span style="font-weight:bold"><?php echo $_SERVER['HTTP_USER_AGENT'];?></span>
|
31 |
+
</div>
|
32 |
+
|
33 |
+
|
34 |
+
<div style = "padding:10px 0 0">
|
35 |
+
|
36 |
+
<?php if(!empty($rejectReason)){ ?>
|
37 |
+
<p style="font-weight:bold; text-align:center; color:#81040B;">Warning : Do not activate protection for <?php echo $submittedForm . ' !'; ?></p>
|
38 |
+
<?php } ?>
|
39 |
+
|
40 |
+
<?php if(empty($rejectReason)){ ?>
|
41 |
+
<p style="font-weight:bold; text-align:center; color:#208115" >Feel free to activate protection for <?php echo $submittedForm . ' !'; ?></p>
|
42 |
+
<?php } ?>
|
43 |
+
|
44 |
+
</div>
|
45 |
+
|
2.0/engine/modules/jetpack-contact-form/GdbcJetPackContactFormAdminModule.php
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class GdbcJetPackContactFormAdminModule extends GdbcBaseAdminModule
|
22 |
+
{
|
23 |
+
CONST OPTION_IS_JETPACK_CONTACT_FORM_ACTIVATE = 'IsJPCFActivated';
|
24 |
+
|
25 |
+
protected function __construct()
|
26 |
+
{
|
27 |
+
parent::__construct();
|
28 |
+
}
|
29 |
+
|
30 |
+
public function getDefaultOptions()
|
31 |
+
{
|
32 |
+
static $arrDefaultSettingOptions = null;
|
33 |
+
if(null !== $arrDefaultSettingOptions)
|
34 |
+
return $arrDefaultSettingOptions;
|
35 |
+
|
36 |
+
$arrDefaultSettingOptions = array(
|
37 |
+
|
38 |
+
self::OPTION_IS_JETPACK_CONTACT_FORM_ACTIVATE => array(
|
39 |
+
'Id' => 1,
|
40 |
+
'Value' => NULL,
|
41 |
+
'LabelText' => __('Jetpack Contact Form', GoodByeCaptcha::PLUGIN_SLUG),
|
42 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
43 |
+
),
|
44 |
+
|
45 |
+
);
|
46 |
+
|
47 |
+
return $arrDefaultSettingOptions;
|
48 |
+
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
public function validateModuleSettingsFields($arrSettingOptions)
|
53 |
+
{
|
54 |
+
return $arrSettingOptions;
|
55 |
+
}
|
56 |
+
|
57 |
+
public function renderModuleSettingsSectionHeader(array $arrSectionInfo)
|
58 |
+
{
|
59 |
+
echo '<h3>' . __('Popular Contact Forms Settings', GoodByeCaptcha::PLUGIN_SLUG) . '</h3><hr />';
|
60 |
+
echo '<h4>' . __('Enable protection for the following popular contact forms:', GoodByeCaptcha::PLUGIN_SLUG) . '</h4>';
|
61 |
+
}
|
62 |
+
|
63 |
+
public function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity)
|
64 |
+
{
|
65 |
+
$attemptEntity->Notes = (array)maybe_unserialize($attemptEntity->Notes);
|
66 |
+
$arrContent = array('table-head-rows' => '', 'table-body-rows' => '');
|
67 |
+
$formTitle = isset($attemptEntity->Notes['form-title']) ? $attemptEntity->Notes['form-title'] : '';
|
68 |
+
|
69 |
+
unset($attemptEntity->Notes['form-title']);
|
70 |
+
|
71 |
+
$tableHeadRows = '';
|
72 |
+
$tableBodyRows = '';
|
73 |
+
|
74 |
+
$tableHeadRows .= '<tr>';
|
75 |
+
$tableHeadRows .= '<th colspan="2">' . sprintf(__("%s - Blocked Attempt", GoodByeCaptcha::PLUGIN_SLUG), $formTitle) . '</th>';
|
76 |
+
$tableHeadRows .= '</tr>';
|
77 |
+
|
78 |
+
$tableHeadRows .= '<tr>';
|
79 |
+
$tableHeadRows .= '<th>' . __('Field', GoodByeCaptcha::PLUGIN_SLUG) . '</th>';
|
80 |
+
$tableHeadRows .= '<th>' . __('Value', GoodByeCaptcha::PLUGIN_SLUG) . '</th>';
|
81 |
+
$tableHeadRows .= '</tr>';
|
82 |
+
|
83 |
+
foreach($attemptEntity->Notes as $key => $value)
|
84 |
+
{
|
85 |
+
$tableBodyRows .='<tr>';
|
86 |
+
$tableBodyRows .= '<td>' . self::getBlockedContentDisplayableKey($key) . '</td>';
|
87 |
+
$tableBodyRows .= '<td>' . wp_filter_kses(print_r($value, true)) . '</td>';
|
88 |
+
$tableBodyRows .='</tr>';
|
89 |
+
}
|
90 |
+
|
91 |
+
$arrContent['table-head-rows'] = $tableHeadRows;
|
92 |
+
$arrContent['table-body-rows'] = $tableBodyRows;
|
93 |
+
|
94 |
+
return $arrContent;
|
95 |
+
}
|
96 |
+
|
97 |
+
public static function getInstance()
|
98 |
+
{
|
99 |
+
static $adminInstance = null;
|
100 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
101 |
+
}
|
102 |
+
|
103 |
+
}
|
{engine → 2.0/engine}/modules/jetpack-contact-form/GdbcJetPackContactFormPublicModule.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/mc-for-wp/GdbcMailChimpForWpAdminModule.php
RENAMED
File without changes
|
2.0/engine/modules/mc-for-wp/GdbcMailChimpForWpPublicModule.php
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcMailChimpForWpPublicModule extends GdbcBasePublicModule
|
21 |
+
{
|
22 |
+
private $mailChimpFormLists = array();
|
23 |
+
|
24 |
+
public function __construct()
|
25 |
+
{
|
26 |
+
|
27 |
+
parent::__construct();
|
28 |
+
|
29 |
+
if(!GoodByeCaptchaUtils::isMailChimpForWPActivated())
|
30 |
+
return;
|
31 |
+
|
32 |
+
add_filter('mc4wp_form_before_fields', array($this, 'getTokenFieldHtml'));
|
33 |
+
|
34 |
+
|
35 |
+
add_filter('mc4wp_form_errors', array($this, 'validateSubscriptionRequest'), 10, 2);
|
36 |
+
|
37 |
+
|
38 |
+
add_filter('mc4wp_valid_form_request', array($this, 'validateOldSubscriptionRequest'), 10, 2);
|
39 |
+
|
40 |
+
}
|
41 |
+
|
42 |
+
public function validateSubscriptionRequest($arrErrors, $mcForm)
|
43 |
+
{
|
44 |
+
if( ! is_a($mcForm, 'MC4WP_Form') )
|
45 |
+
return $arrErrors;
|
46 |
+
|
47 |
+
!is_array($arrErrors) ? $arrErrors = array() : null;
|
48 |
+
|
49 |
+
$arrFormProperties = get_object_vars($mcForm);
|
50 |
+
if( !isset($arrFormProperties['data']) || empty($mcForm->data))
|
51 |
+
return $arrErrors;
|
52 |
+
|
53 |
+
$arrCapturedData = array();
|
54 |
+
foreach((array)$mcForm->data as $fieldName => $fieldValue)
|
55 |
+
{
|
56 |
+
if(is_scalar($fieldValue))
|
57 |
+
{
|
58 |
+
$arrCapturedData[$fieldName] = $fieldValue;
|
59 |
+
continue;
|
60 |
+
}
|
61 |
+
if(strtolower($fieldName) === 'address')
|
62 |
+
{
|
63 |
+
if(is_array($fieldValue))
|
64 |
+
{
|
65 |
+
$fieldValue = array_merge(array('addr1' => '','city' => '','state' => '', 'zip' => ''), $fieldValue );
|
66 |
+
}
|
67 |
+
elseif(is_string($fieldValue))
|
68 |
+
{
|
69 |
+
$arrAddress = explode(',', $fieldValue);
|
70 |
+
$fieldValue = array(
|
71 |
+
'addr1' => isset($arrAddress[0]) ? $arrAddress[0] : null,
|
72 |
+
'city' => isset($arrAddress[1]) ? $arrAddress[1] : null,
|
73 |
+
'state' => isset($arrAddress[2]) ? $arrAddress[2] : null,
|
74 |
+
'zip' => isset($arrAddress[3]) ? $arrAddress[3] : null,
|
75 |
+
);
|
76 |
+
$fieldValue = array_filter($fieldValue);
|
77 |
+
}
|
78 |
+
|
79 |
+
$arrCapturedData[$fieldName] = (array)$fieldValue;
|
80 |
+
continue;
|
81 |
+
}
|
82 |
+
|
83 |
+
if(strtolower($fieldName) === 'groupings' && is_array($fieldValue))
|
84 |
+
{
|
85 |
+
foreach($fieldValue as $groupId => &$groupData)
|
86 |
+
{
|
87 |
+
if(!is_string($groupData))
|
88 |
+
continue;
|
89 |
+
|
90 |
+
$groupData = explode(',', sanitize_text_field($groupData));
|
91 |
+
}
|
92 |
+
|
93 |
+
$arrCapturedData[$fieldName] = (array)$fieldValue;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
$this->getAttemptEntity()->Notes = $arrCapturedData;
|
98 |
+
|
99 |
+
if( ! GdbcRequestController::isValid($this->getAttemptEntity()) )
|
100 |
+
$arrErrors[] = 'spam';
|
101 |
+
|
102 |
+
return $arrErrors;
|
103 |
+
|
104 |
+
}
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
public function validateOldSubscriptionRequest($isRequestValid, $submittedData)
|
110 |
+
{
|
111 |
+
$submittedData = array_change_key_case((array)$submittedData, CASE_UPPER);
|
112 |
+
$submittedPostData = array_change_key_case((array)$_POST, CASE_UPPER);
|
113 |
+
|
114 |
+
foreach($submittedData as $submittedKey => $submittedValue)
|
115 |
+
{
|
116 |
+
if(!isset($submittedPostData[$submittedKey]))
|
117 |
+
unset($submittedData[$submittedKey]);
|
118 |
+
}
|
119 |
+
|
120 |
+
unset($submittedPostData, $submittedKey, $submittedValue);
|
121 |
+
|
122 |
+
$arrCapturedData = array();
|
123 |
+
foreach((array)$submittedData as $fieldName => $fieldValue)
|
124 |
+
{
|
125 |
+
if(is_scalar($fieldValue))
|
126 |
+
{
|
127 |
+
$arrCapturedData[$fieldName] = $fieldValue;
|
128 |
+
continue;
|
129 |
+
}
|
130 |
+
if(strtolower($fieldName) === 'address')
|
131 |
+
{
|
132 |
+
if(is_array($fieldValue))
|
133 |
+
{
|
134 |
+
$fieldValue = array_merge(array('addr1' => '','city' => '','state' => '', 'zip' => ''), $fieldValue );
|
135 |
+
}
|
136 |
+
elseif(is_string($fieldValue))
|
137 |
+
{
|
138 |
+
$arrAddress = explode(',', $fieldValue);
|
139 |
+
$fieldValue = array(
|
140 |
+
'addr1' => isset($arrAddress[0]) ? $arrAddress[0] : null,
|
141 |
+
'city' => isset($arrAddress[1]) ? $arrAddress[1] : null,
|
142 |
+
'state' => isset($arrAddress[2]) ? $arrAddress[2] : null,
|
143 |
+
'zip' => isset($arrAddress[3]) ? $arrAddress[3] : null,
|
144 |
+
);
|
145 |
+
$fieldValue = array_filter($fieldValue);
|
146 |
+
}
|
147 |
+
|
148 |
+
$arrCapturedData[$fieldName] = (array)$fieldValue;
|
149 |
+
continue;
|
150 |
+
}
|
151 |
+
|
152 |
+
if(strtolower($fieldName) === 'groupings' && is_array($fieldValue))
|
153 |
+
{
|
154 |
+
foreach($fieldValue as $groupId => &$groupData)
|
155 |
+
{
|
156 |
+
if(!is_string($groupData))
|
157 |
+
continue;
|
158 |
+
|
159 |
+
$groupData = explode(',', sanitize_text_field($groupData));
|
160 |
+
}
|
161 |
+
|
162 |
+
$arrCapturedData[$fieldName] = (array)$fieldValue;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
$this->getAttemptEntity()->Notes = $arrCapturedData;
|
167 |
+
|
168 |
+
return GdbcRequestController::isValid($this->getAttemptEntity());
|
169 |
+
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* @return int
|
174 |
+
*/
|
175 |
+
protected function getModuleId()
|
176 |
+
{
|
177 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_MAIL_CHIMP_FOR_WP);
|
178 |
+
}
|
179 |
+
|
180 |
+
public static function getInstance()
|
181 |
+
{
|
182 |
+
static $adminInstance = null;
|
183 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
184 |
+
}
|
185 |
+
|
186 |
+
}
|
{engine → 2.0/engine}/modules/planso-forms/GdbcPlanSoFormsAdminModule.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/planso-forms/GdbcPlanSoFormsPublicModule.php
RENAMED
File without changes
|
2.0/engine/modules/reports/GdbcReportsAdminModule.php
ADDED
@@ -0,0 +1,593 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2015 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class GdbcReportsAdminModule extends GdbcBaseAdminModule
|
22 |
+
{
|
23 |
+
|
24 |
+
private static $statsNumberOfDays = 0;
|
25 |
+
private static $isGdbcNetworkActivated = false;
|
26 |
+
|
27 |
+
protected function __construct()
|
28 |
+
{
|
29 |
+
parent::__construct();
|
30 |
+
|
31 |
+
self::$statsNumberOfDays = (int)GdbcSettingsAdminModule::getInstance()->getOption(GdbcSettingsAdminModule::OPTION_MAX_LOGS_DAYS);
|
32 |
+
|
33 |
+
self::$isGdbcNetworkActivated = GoodByeCaptcha::isNetworkActivated();
|
34 |
+
}
|
35 |
+
|
36 |
+
public function renderReportsMainPageContent($arrReportsNavigationTabUrl)
|
37 |
+
{
|
38 |
+
echo '<section id="widget-grid">';
|
39 |
+
|
40 |
+
if(empty($_GET['gdbc-detailed-report']))
|
41 |
+
{
|
42 |
+
require_once dirname(__FILE__) . '/partials/reports-stats.php';
|
43 |
+
require_once dirname(__FILE__) . '/partials/latest-attempts-table.php';
|
44 |
+
|
45 |
+
$this->renderAttemptsByClientIp();
|
46 |
+
$this->renderAttemptsPercentagePerModule();
|
47 |
+
}
|
48 |
+
else
|
49 |
+
{
|
50 |
+
require_once dirname(__FILE__) . '/partials/reports-details.php';
|
51 |
+
require_once dirname(__FILE__) . '/partials/module-table.php';
|
52 |
+
}
|
53 |
+
|
54 |
+
require_once dirname(__FILE__) . '/partials/modal-dialog.php';
|
55 |
+
|
56 |
+
echo '</section>';
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
private function renderAttemptsPercentagePerModule()
|
61 |
+
{
|
62 |
+
require_once dirname(__FILE__) . '/partials/percentage-chart.php';
|
63 |
+
}
|
64 |
+
|
65 |
+
public function retrieveTotalAttemptsPerModule()
|
66 |
+
{
|
67 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() )
|
68 |
+
exit;
|
69 |
+
|
70 |
+
$attemptsPerModulesList = array();
|
71 |
+
$totalAttempts = 0;
|
72 |
+
foreach(GdbcDbAccessController::getTotalAttemptsPerModule() as $gdbcAttempt)
|
73 |
+
{
|
74 |
+
$moduleName = GdbcModulesController::getModuleNameById($gdbcAttempt->ModuleId);
|
75 |
+
if(empty($moduleName) || $gdbcAttempt->Total == 0)
|
76 |
+
continue;
|
77 |
+
|
78 |
+
$totalAttempts += $gdbcAttempt->Total;
|
79 |
+
$attemptsPerModulesList[] = array(
|
80 |
+
'label' => $moduleName,
|
81 |
+
'value' => $gdbcAttempt->Total
|
82 |
+
);
|
83 |
+
}
|
84 |
+
|
85 |
+
foreach($attemptsPerModulesList as &$gdbcAttempt){
|
86 |
+
$gdbcAttempt['percent'] = round(($gdbcAttempt['value'] / $totalAttempts) * 100 , 1);
|
87 |
+
}
|
88 |
+
|
89 |
+
$ajaxData = array();
|
90 |
+
$ajaxData['TopAttemptsArrayPerModule'] = $attemptsPerModulesList;
|
91 |
+
|
92 |
+
echo json_encode($ajaxData);
|
93 |
+
|
94 |
+
exit;
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
public function retrieveAttemptsPerClientIp()
|
99 |
+
{
|
100 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() )
|
101 |
+
exit;
|
102 |
+
|
103 |
+
$attemptsPerPage = 10;
|
104 |
+
$pageNumber = !empty($_POST['pageNumber']) ? (int) sanitize_text_field($_POST['pageNumber']) : 1;
|
105 |
+
|
106 |
+
|
107 |
+
$totalPages = ceil(count(GdbcDbAccessController::getAttemptsByClientIp(1, PHP_INT_MAX)) / $attemptsPerPage);
|
108 |
+
$pageNumber > $totalPages ? $pageNumber = $totalPages : null;
|
109 |
+
|
110 |
+
$latestAttemptsByClientIp = GdbcDbAccessController::getAttemptsByClientIp($pageNumber, $attemptsPerPage);
|
111 |
+
|
112 |
+
foreach($latestAttemptsByClientIp as $key => &$gdbcAttempt)
|
113 |
+
{
|
114 |
+
//$gdbcAttempt->ClientIp = MchGdbcIPUtils::ipAddressFromBinary($gdbcAttempt->ClientIp);
|
115 |
+
|
116 |
+
$gdbcAttempt->Country = self::getCountryForDisplay($gdbcAttempt->ClientIp);
|
117 |
+
|
118 |
+
$gdbcAttempt->IsIpBlocked = GdbcIPUtils::isIpAddressBlocked($gdbcAttempt->ClientIp);
|
119 |
+
|
120 |
+
$gdbcAttempt->Pages = $totalPages;
|
121 |
+
}
|
122 |
+
|
123 |
+
echo json_encode($latestAttemptsByClientIp);
|
124 |
+
exit;
|
125 |
+
|
126 |
+
}
|
127 |
+
|
128 |
+
private function renderAttemptsByClientIp()
|
129 |
+
{
|
130 |
+
$countryAttemptsJs = '';
|
131 |
+
$latestAttemptsByClientIp = GdbcDbAccessController::getAttemptsByClientIp(1, PHP_INT_MAX);
|
132 |
+
|
133 |
+
$arrCountryAttempts = array();
|
134 |
+
foreach($latestAttemptsByClientIp as $key => $gdbcAttempt)
|
135 |
+
{
|
136 |
+
|
137 |
+
// if(null === ($countryCode = GoodByeCaptchaUtils::getCountryCodeById($gdbcAttempt->CountryId)))
|
138 |
+
// continue;
|
139 |
+
|
140 |
+
//$gdbcAttempt->ClientIp = MchGdbcIPUtils::ipAddressFromBinary($gdbcAttempt->ClientIp);
|
141 |
+
|
142 |
+
if(null === ($countryCode = MchGdbcIPUtils::getCountryCode($gdbcAttempt->ClientIp)))
|
143 |
+
continue;
|
144 |
+
|
145 |
+
$countryCode = sanitize_text_field($countryCode);
|
146 |
+
|
147 |
+
isset($arrCountryAttempts[$countryCode]) ? $arrCountryAttempts[$countryCode] += $gdbcAttempt->Attempts
|
148 |
+
: $arrCountryAttempts[$countryCode] = $gdbcAttempt->Attempts;
|
149 |
+
}
|
150 |
+
|
151 |
+
$countryAttemptsJs = json_encode($arrCountryAttempts);
|
152 |
+
require_once dirname(__FILE__) . '/partials/latest-attempts-locations.php';
|
153 |
+
}
|
154 |
+
|
155 |
+
|
156 |
+
public function retrieveLatestAttemptsTable()
|
157 |
+
{
|
158 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() )
|
159 |
+
exit;
|
160 |
+
|
161 |
+
$ajaxData = array();
|
162 |
+
$ajaxData['TableHeader'] = array(
|
163 |
+
'CreatedDate' => __('Attempt Date', GoodByeCaptcha::PLUGIN_SLUG),
|
164 |
+
'Site' => __('Site', GoodByeCaptcha::PLUGIN_SLUG),
|
165 |
+
'ModuleName' => __('Module/Section', GoodByeCaptcha::PLUGIN_SLUG),
|
166 |
+
'ClientIp' => __('IP Address', GoodByeCaptcha::PLUGIN_SLUG),
|
167 |
+
'Country' => __('Country', GoodByeCaptcha::PLUGIN_SLUG),
|
168 |
+
'Reason' => __('Blocking Reason', GoodByeCaptcha::PLUGIN_SLUG),
|
169 |
+
'Notes' => __('Blocked Content', GoodByeCaptcha::PLUGIN_SLUG)
|
170 |
+
);
|
171 |
+
|
172 |
+
if( !self::$isGdbcNetworkActivated )
|
173 |
+
{
|
174 |
+
unset($ajaxData['TableHeader']['Site']);
|
175 |
+
}
|
176 |
+
|
177 |
+
|
178 |
+
$arrLatestAttempts = GdbcDbAccessController::getLatestAttempts(15);
|
179 |
+
|
180 |
+
foreach($arrLatestAttempts as $index => &$attempt)
|
181 |
+
{
|
182 |
+
|
183 |
+
$attempt->ModuleName = GdbcModulesController::getModuleNameById($attempt->ModuleId);
|
184 |
+
if(null === $attempt->ModuleName)
|
185 |
+
{
|
186 |
+
unset($arrLatestAttempts[$index]);
|
187 |
+
continue;
|
188 |
+
}
|
189 |
+
|
190 |
+
$attempt->CreatedDate = get_date_from_gmt ( date( 'Y-m-d H:i:s', $attempt->CreatedDate ), 'M d, Y H:i:s');
|
191 |
+
|
192 |
+
$sectionName = GdbcModulesController::getModuleOptionDisplayText($attempt->ModuleId, $attempt->SectionId);
|
193 |
+
$attempt->ModuleName .= empty($sectionName) ? '' : '/' . $sectionName;
|
194 |
+
|
195 |
+
$attempt->IsIpBlocked = GdbcIPUtils::isIpAddressBlocked($attempt->ClientIp);
|
196 |
+
$attempt->Reason = GdbcRequestController::getRejectReasonDescription($attempt->ReasonId);
|
197 |
+
|
198 |
+
$attempt->Country = self::getCountryForDisplay($attempt->ClientIp);
|
199 |
+
|
200 |
+
empty($attempt->Country) ? $attempt->Country = 'N/A' : null;
|
201 |
+
|
202 |
+
if(empty($attempt->Notes))
|
203 |
+
{
|
204 |
+
$attempt->Notes = 'N/A';
|
205 |
+
}
|
206 |
+
else
|
207 |
+
{
|
208 |
+
$attempt->Notes = '<button data-toggle="modal" data-target="#gdbc-modal-holder" data-attempt="'. esc_attr($attempt->Id) .'" class="btn btn-xs btn-primary">' . __('View Blocked Content', GoodByeCaptcha::PLUGIN_SLUG) . '</button>';
|
209 |
+
}
|
210 |
+
|
211 |
+
if( self::$isGdbcNetworkActivated )
|
212 |
+
{
|
213 |
+
$attempt->Site = MchGdbcWpUtils::getSiteNameById($attempt->SiteId);
|
214 |
+
empty($attempt->Site) ? $attempt->Site = __('Unknown', GoodByeCaptcha::PLUGIN_SLUG) : null;
|
215 |
+
}
|
216 |
+
else
|
217 |
+
{
|
218 |
+
unset($attempt->SiteId);
|
219 |
+
}
|
220 |
+
|
221 |
+
}
|
222 |
+
|
223 |
+
$ajaxData['TableData'] = $arrLatestAttempts;
|
224 |
+
|
225 |
+
wp_send_json_success( $ajaxData );
|
226 |
+
|
227 |
+
}
|
228 |
+
|
229 |
+
|
230 |
+
public function retrieveInitialDashboardData()
|
231 |
+
{
|
232 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() )
|
233 |
+
exit;
|
234 |
+
|
235 |
+
$arrPreparedData = array();
|
236 |
+
$currentBlogTime = MchGdbcHttpRequest::getServerRequestTime();
|
237 |
+
for ($i = 1 ; $i <= self::$statsNumberOfDays; ++$i)
|
238 |
+
{
|
239 |
+
$arrPreparedData[get_date_from_gmt ( date( 'Y-m-d H:i:s', $currentBlogTime ), 'Y-m-d' )] = 0;
|
240 |
+
$currentBlogTime -= 24 * 3600;
|
241 |
+
}
|
242 |
+
|
243 |
+
$arrCombinedAttempts = GdbcDbAccessController::getCombinedAttemptsPerDay(self::$statsNumberOfDays);
|
244 |
+
foreach($arrCombinedAttempts as $combinedAttempt)
|
245 |
+
{
|
246 |
+
if(isset($arrPreparedData[$combinedAttempt->CreatedDate]))
|
247 |
+
$arrPreparedData[$combinedAttempt->CreatedDate] = $combinedAttempt->AttemptsNumber;
|
248 |
+
}
|
249 |
+
|
250 |
+
foreach($arrPreparedData as $day => $attempts)
|
251 |
+
{
|
252 |
+
$arrPreparedData[strtotime($day) . '000'] = (int)$attempts;
|
253 |
+
unset($arrPreparedData[$day]);
|
254 |
+
}
|
255 |
+
|
256 |
+
echo json_encode(array('ChartDataArray' => $arrPreparedData));
|
257 |
+
exit;
|
258 |
+
}
|
259 |
+
|
260 |
+
|
261 |
+
|
262 |
+
public function retrieveDetailedAttemptsForChart()
|
263 |
+
{
|
264 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() )
|
265 |
+
exit;
|
266 |
+
|
267 |
+
$attemptsByModuleAndDay = GdbcDbAccessController::getAttemptsPerModuleAndDay(self::$statsNumberOfDays);
|
268 |
+
|
269 |
+
$endDate = $startDate = 0;
|
270 |
+
foreach($attemptsByModuleAndDay as $gdbcAttempt)
|
271 |
+
{
|
272 |
+
$attemptTime = strtotime($gdbcAttempt->AttemptDate);
|
273 |
+
|
274 |
+
if($attemptTime >= $endDate)
|
275 |
+
$endDate = $attemptTime;
|
276 |
+
|
277 |
+
if(0 === $startDate)
|
278 |
+
$startDate = $endDate;
|
279 |
+
if($attemptTime < $startDate)
|
280 |
+
$startDate = $attemptTime;
|
281 |
+
}
|
282 |
+
|
283 |
+
$displayableAttemptsArray = $this->createDisplayableAttempts($attemptsByModuleAndDay, $startDate, $endDate);
|
284 |
+
|
285 |
+
$arrModules = array();
|
286 |
+
foreach($attemptsByModuleAndDay as $attempt)
|
287 |
+
{
|
288 |
+
if(! ($moduleName = GdbcModulesController::getModuleNameById($attempt->ModuleId)) )
|
289 |
+
continue;
|
290 |
+
|
291 |
+
$arrModules[$attempt->ModuleId] = $moduleName;
|
292 |
+
}
|
293 |
+
|
294 |
+
$ajaxData = array();
|
295 |
+
$ajaxData['ModulesDescriptionArray'] = $arrModules;
|
296 |
+
$ajaxData['ModulesAttemptsArray'] = $displayableAttemptsArray;
|
297 |
+
|
298 |
+
echo json_encode($ajaxData);
|
299 |
+
|
300 |
+
exit;
|
301 |
+
}
|
302 |
+
|
303 |
+
private function createDisplayableAttempts($attemptsArray, $startDate, $endDate)
|
304 |
+
{
|
305 |
+
if (null === $attemptsArray)
|
306 |
+
return array();
|
307 |
+
|
308 |
+
$displayableArray = array();
|
309 |
+
foreach ($attemptsArray as $attemptObj)
|
310 |
+
{
|
311 |
+
$moduleId = $attemptObj->ModuleId;
|
312 |
+
if (!isset($displayableArray[$moduleId][$attemptObj->AttemptDate])) {
|
313 |
+
$displayableArray[$moduleId][$attemptObj->AttemptDate] = 0;
|
314 |
+
}
|
315 |
+
$displayableArray[$moduleId][$attemptObj->AttemptDate] += $attemptObj->AttemptsNumber;
|
316 |
+
}
|
317 |
+
$numberOfDays = floor(($endDate - $startDate) / (60 * 60 * 24));
|
318 |
+
foreach($displayableArray as &$value)
|
319 |
+
{
|
320 |
+
$newArray = array();
|
321 |
+
for ($i = 0 ; $i <= $numberOfDays ; ++$i) {
|
322 |
+
$day = date('Y-m-d', $startDate + $i * 24 * 60 * 60);
|
323 |
+
$newArray[$day] = 0;
|
324 |
+
if (isset($value[$day]))
|
325 |
+
$newArray[$day] += $value[$day];
|
326 |
+
}
|
327 |
+
$value = $newArray;
|
328 |
+
}
|
329 |
+
$resultArray = array();
|
330 |
+
foreach($displayableArray as $arrKey => $arrValue)
|
331 |
+
{
|
332 |
+
$i = 0;
|
333 |
+
foreach($arrValue as $key1 => $value1)
|
334 |
+
{
|
335 |
+
$resultArray[$arrKey][$i] = array(strtotime($key1) . '000', $value1);
|
336 |
+
$i++;
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
return $resultArray;
|
341 |
+
}
|
342 |
+
|
343 |
+
|
344 |
+
|
345 |
+
public function retrieveDetailedAttemptsPerModule()
|
346 |
+
{
|
347 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() || !isset($_POST['moduleId']) || !is_numeric($_POST['moduleId']))
|
348 |
+
exit;
|
349 |
+
|
350 |
+
$_POST['moduleId'] = sanitize_text_field($_POST['moduleId']);
|
351 |
+
$_POST['pageNumber'] = sanitize_text_field($_POST['pageNumber']);
|
352 |
+
$_POST['orderBy'] = sanitize_text_field($_POST['orderBy']);
|
353 |
+
|
354 |
+
$moduleId = $_POST['moduleId'];
|
355 |
+
$pageNumber = !empty($_POST['pageNumber']) ? (int)$_POST['pageNumber'] : 1;
|
356 |
+
|
357 |
+
|
358 |
+
$recordsNumber = GdbcDbAccessController::getNumberOfAttemptsByModuleId($moduleId);
|
359 |
+
|
360 |
+
$recordsPerPage = 15;
|
361 |
+
$totalPages = ceil($recordsNumber / $recordsPerPage);
|
362 |
+
|
363 |
+
$pageNumber > $totalPages ? $pageNumber = $totalPages : null;
|
364 |
+
|
365 |
+
$moduleName = GdbcModulesController::getModuleNameById($moduleId);
|
366 |
+
|
367 |
+
$moduleInstance = GdbcModulesController::getAdminModuleInstance($moduleName);
|
368 |
+
|
369 |
+
$arrModuleData = GdbcDbAccessController::getAttemptsPerModule($moduleId, $pageNumber, $recordsPerPage);
|
370 |
+
|
371 |
+
$ajaxData = array();
|
372 |
+
$ajaxData['ModuleDataHeader'] = array();
|
373 |
+
$ajaxData['PaginationInfo'] = array(0, 0);
|
374 |
+
|
375 |
+
if (!isset($arrModuleData[0]) || null === $moduleInstance)
|
376 |
+
{
|
377 |
+
$ajaxData['PaginationInfo'] = 0;
|
378 |
+
echo json_encode($ajaxData);
|
379 |
+
exit;
|
380 |
+
}
|
381 |
+
|
382 |
+
$ajaxData['ModuleDataHeader'] = array(
|
383 |
+
'Section' => __('Section', GoodByeCaptcha::PLUGIN_SLUG),
|
384 |
+
'CreatedDate' => __('Attempt Date', GoodByeCaptcha::PLUGIN_SLUG),
|
385 |
+
'Site' => __('Site', GoodByeCaptcha::PLUGIN_SLUG),
|
386 |
+
'ClientIp' => __('IP Address', GoodByeCaptcha::PLUGIN_SLUG),
|
387 |
+
'Country' => __('Country', GoodByeCaptcha::PLUGIN_SLUG),
|
388 |
+
'Reason' => __('Blocking Reason', GoodByeCaptcha::PLUGIN_SLUG),
|
389 |
+
'Notes' => __('Blocked Content', GoodByeCaptcha::PLUGIN_SLUG)
|
390 |
+
);
|
391 |
+
|
392 |
+
|
393 |
+
|
394 |
+
$moduleHasSection = false;
|
395 |
+
foreach($arrModuleData as $gdbcAttempt)
|
396 |
+
if($moduleHasSection = !empty($gdbcAttempt->SectionId))
|
397 |
+
break;
|
398 |
+
|
399 |
+
if(!$moduleHasSection)
|
400 |
+
{
|
401 |
+
unset($ajaxData['ModuleDataHeader']['Section']);
|
402 |
+
}
|
403 |
+
|
404 |
+
|
405 |
+
foreach($arrModuleData as &$attempt)
|
406 |
+
{
|
407 |
+
if($moduleHasSection)
|
408 |
+
{
|
409 |
+
$attempt->Section = GdbcModulesController::getModuleOptionDisplayText($attempt->ModuleId, $attempt->SectionId);
|
410 |
+
empty($attempt->Section) ? $attempt->Section = 'N\A' : null;
|
411 |
+
}
|
412 |
+
|
413 |
+
$attempt->CreatedDate = get_date_from_gmt ( date( 'Y-m-d H:i:s', $attempt->CreatedDate ), 'M d, Y H:i:s');
|
414 |
+
//$sectionName = GdbcModulesController::getModuleOptionDisplayText($attempt->ModuleId, (int)$attempt->SectionId);
|
415 |
+
//$attempt->ModuleName .= '/' . (empty($sectionName) ? 'N/A' : $sectionName);
|
416 |
+
|
417 |
+
//$attempt->ClientIp = MchGdbcIPUtils::ipAddressFromBinary($attempt->ClientIp);
|
418 |
+
|
419 |
+
$attempt->IsIpBlocked = GdbcIPUtils::isIpAddressBlocked($attempt->ClientIp);
|
420 |
+
$attempt->Reason = GdbcRequestController::getRejectReasonDescription($attempt->ReasonId);
|
421 |
+
|
422 |
+
$attempt->Country = self::getCountryForDisplay($attempt->ClientIp);
|
423 |
+
|
424 |
+
empty($attempt->Country) ? $attempt->Country = 'N/A' : null;
|
425 |
+
|
426 |
+
if(empty($attempt->Notes))
|
427 |
+
{
|
428 |
+
$attempt->Notes = 'N/A';
|
429 |
+
}
|
430 |
+
else
|
431 |
+
{
|
432 |
+
$attempt->Notes = '<button data-toggle="modal" data-target="#gdbc-modal-holder" data-attempt="'. esc_attr($attempt->Id) .'" class="btn btn-xs btn-primary">' . __('View Blocked Content', GoodByeCaptcha::PLUGIN_SLUG) . '</button>';
|
433 |
+
}
|
434 |
+
|
435 |
+
if( self::$isGdbcNetworkActivated )
|
436 |
+
{
|
437 |
+
$attempt->Site = MchGdbcWpUtils::getSiteNameById($attempt->SiteId);
|
438 |
+
empty($attempt->Site) ? $attempt->Site = __('Unknown', GoodByeCaptcha::PLUGIN_SLUG) : null;
|
439 |
+
}
|
440 |
+
else
|
441 |
+
{
|
442 |
+
unset($attempt->SiteId);
|
443 |
+
}
|
444 |
+
|
445 |
+
}
|
446 |
+
|
447 |
+
$ajaxData['PaginationInfo'] = array($pageNumber, $totalPages);
|
448 |
+
$ajaxData['ModuleDataRows'] = $arrModuleData;
|
449 |
+
|
450 |
+
echo json_encode($ajaxData);
|
451 |
+
|
452 |
+
exit;
|
453 |
+
}
|
454 |
+
|
455 |
+
|
456 |
+
public function manageClientIpAddress()
|
457 |
+
{
|
458 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() || !isset($_POST['clientIp']) || !isset($_POST['shouldBlock']) || !is_numeric($_POST['shouldBlock']))
|
459 |
+
wp_send_json_error();
|
460 |
+
|
461 |
+
$_POST['clientIp'] = sanitize_text_field($_POST['clientIp']);
|
462 |
+
$_POST['shouldBlock'] = (bool)sanitize_text_field($_POST['shouldBlock']);
|
463 |
+
|
464 |
+
if($_POST['shouldBlock'] && GdbcIPUtils::isIpWhiteListed($_POST['clientIp'])){
|
465 |
+
wp_send_json_error(sprintf(__("Ip Address %s is White-Listed and cannot be blocked !", GoodByeCaptcha::PLUGIN_SLUG), $_POST['clientIp']));
|
466 |
+
}
|
467 |
+
|
468 |
+
if($_POST['shouldBlock'])
|
469 |
+
{
|
470 |
+
if(GdbcIPUtils::isIpAddressBlocked($_POST['clientIp'])) {
|
471 |
+
wp_send_json_error(sprintf(__('Ip Address %s is already blocked !', GoodByeCaptcha::PLUGIN_SLUG), $_POST['clientIp']));
|
472 |
+
}
|
473 |
+
|
474 |
+
GdbcBlackListedIpsAdminModule::getInstance()->registerBlackListedIp($_POST['clientIp']);
|
475 |
+
|
476 |
+
if(GdbcIPUtils::isIpAddressBlocked($_POST['clientIp'])) {
|
477 |
+
wp_send_json_success(sprintf(__('Ip Address %s was successfully Black-Listed !', GoodByeCaptcha::PLUGIN_SLUG), $_POST['clientIp']));
|
478 |
+
}
|
479 |
+
}
|
480 |
+
else
|
481 |
+
{
|
482 |
+
GdbcBlackListedIpsAdminModule::getInstance()->unRegisterBlackListedIp($_POST['clientIp']);
|
483 |
+
wp_send_json_success(sprintf(__('Ip Address %s was successfully removed from Black Listed IPs!', GoodByeCaptcha::PLUGIN_SLUG), $_POST['clientIp']));
|
484 |
+
}
|
485 |
+
|
486 |
+
exit;
|
487 |
+
}
|
488 |
+
|
489 |
+
|
490 |
+
public function getCountryForDisplay($ipAddress)
|
491 |
+
{
|
492 |
+
|
493 |
+
$countryCode = sanitize_text_field(MchGdbcIPUtils::getCountryCode($ipAddress));
|
494 |
+
|
495 |
+
$countryName = GoodByeCaptchaUtils::getCountryNameById(GoodByeCaptchaUtils::getCountryIdByCode($countryCode));
|
496 |
+
|
497 |
+
|
498 |
+
if (empty($countryCode) || empty($countryName))
|
499 |
+
return __('Unknown', GoodByeCaptcha::PLUGIN_SLUG);
|
500 |
+
|
501 |
+
$countryHtmlCode = '<img width="16px" height="11px" title="' . esc_attr($countryName) . '" src="' . plugins_url('/assets/admin/images/flags/' . strtolower($countryCode) . '.gif', GoodByeCaptcha::PLUGIN_MAIN_FILE) . '"/>';
|
502 |
+
$countryHtmlCode .= '<span>' . esc_html($countryName) . '</span>';
|
503 |
+
|
504 |
+
return $countryHtmlCode;
|
505 |
+
}
|
506 |
+
|
507 |
+
|
508 |
+
public function retrieveAttemptsPerModuleAndSection()
|
509 |
+
{
|
510 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() )
|
511 |
+
exit;
|
512 |
+
|
513 |
+
$arrAjaxData = array();
|
514 |
+
$arrAttempts = GdbcDbAccessController::getAttemptsPerModuleAndSection();
|
515 |
+
foreach($arrAttempts as $gdbcAttemptInfo)
|
516 |
+
{
|
517 |
+
|
518 |
+
$arrFormattedAttempt = array('y' => '', 'attempts' => $gdbcAttemptInfo->Attempts);
|
519 |
+
$moduleName = GdbcModulesController::getModuleNameById($gdbcAttemptInfo->ModuleId);
|
520 |
+
if(empty($moduleName))
|
521 |
+
continue;
|
522 |
+
|
523 |
+
$sectionName = GdbcModulesController::getModuleOptionDisplayText($gdbcAttemptInfo->ModuleId, (int)$gdbcAttemptInfo->SectionId);
|
524 |
+
if(empty($sectionName))
|
525 |
+
$sectionName = '';
|
526 |
+
|
527 |
+
$arrFormattedAttempt['module'] = $moduleName;
|
528 |
+
$arrFormattedAttempt['section'] = $sectionName;
|
529 |
+
|
530 |
+
$arrAjaxData[] = $arrFormattedAttempt;
|
531 |
+
}
|
532 |
+
|
533 |
+
$counter = 0;
|
534 |
+
while(count($arrAjaxData) < 8)
|
535 |
+
{
|
536 |
+
$arrFormattedAttempt = array('y' => '', 'attempts' => 0, 'module' => '', 'section' => 0);
|
537 |
+
(++$counter % 2 !== 0) ? array_push($arrAjaxData, $arrFormattedAttempt) : array_unshift($arrAjaxData, $arrFormattedAttempt);
|
538 |
+
}
|
539 |
+
|
540 |
+
echo json_encode($arrAjaxData);
|
541 |
+
exit;
|
542 |
+
}
|
543 |
+
|
544 |
+
|
545 |
+
public function getDefaultOptions() {
|
546 |
+
return array();
|
547 |
+
}
|
548 |
+
|
549 |
+
public function validateModuleSettingsFields( $arrOptions ) {
|
550 |
+
return $arrOptions;
|
551 |
+
}
|
552 |
+
|
553 |
+
public static function getInstance()
|
554 |
+
{
|
555 |
+
static $reportsModuleInstance = null;
|
556 |
+
return null !== $reportsModuleInstance ? $reportsModuleInstance : $reportsModuleInstance = new self();
|
557 |
+
}
|
558 |
+
|
559 |
+
public function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity)
|
560 |
+
{
|
561 |
+
$moduleInstance = GdbcModulesController::getAdminModuleInstance(GdbcModulesController::getModuleNameById($attemptEntity->ModuleId));
|
562 |
+
if(null === $moduleInstance || empty($attemptEntity->Notes))
|
563 |
+
return array();
|
564 |
+
|
565 |
+
$attemptEntity->Notes = maybe_unserialize($attemptEntity->Notes);
|
566 |
+
return $moduleInstance->getFormattedBlockedContent($attemptEntity);
|
567 |
+
}
|
568 |
+
|
569 |
+
public function retrieveFormattedBlockedContent()
|
570 |
+
{
|
571 |
+
if( ! GdbcAjaxController::isAdminAjaxRequestValid() || !isset($_POST['attemptId']) || !is_numeric($_POST['attemptId']))
|
572 |
+
exit;
|
573 |
+
|
574 |
+
$gdbcAttempt = GdbcAttemptEntity::getInstanceFromRawData(GdbcDbAccessController::getAttemptById(absint($_POST['attemptId'])));
|
575 |
+
|
576 |
+
$arrFormattedSavedContent = (array)$this->getFormattedBlockedContent($gdbcAttempt);
|
577 |
+
|
578 |
+
ob_start();
|
579 |
+
require_once dirname(__FILE__) . '/partials/blocked-content-table.php';
|
580 |
+
$formattedHtmlCode = ob_get_clean();
|
581 |
+
|
582 |
+
!isset($arrFormattedSavedContent['table-head-rows']) ? $arrFormattedSavedContent['table-head-rows'] = '' : null;
|
583 |
+
!isset($arrFormattedSavedContent['table-body-rows']) ? $arrFormattedSavedContent['table-body-rows'] = '' : null;
|
584 |
+
|
585 |
+
$formattedHtmlCode = str_replace(array('{table-head-rows}', '{table-body-rows}'), array($arrFormattedSavedContent['table-head-rows'], $arrFormattedSavedContent['table-body-rows']), $formattedHtmlCode);
|
586 |
+
|
587 |
+
echo $formattedHtmlCode;
|
588 |
+
|
589 |
+
exit;
|
590 |
+
}
|
591 |
+
|
592 |
+
|
593 |
+
}
|
{engine → 2.0/engine}/modules/reports/GdbcReportsPublicModule.php
RENAMED
File without changes
|
2.0/engine/modules/reports/partials/blocked-content-table.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
?>
|
21 |
+
<style type="text/css">
|
22 |
+
|
23 |
+
.table-striped-column > tbody > tr td:nth-of-type(odd) {
|
24 |
+
background-color: #f9f9f9;
|
25 |
+
}
|
26 |
+
|
27 |
+
</style>
|
28 |
+
|
29 |
+
<table class="table table-bordered table-striped-column">
|
30 |
+
<thead>
|
31 |
+
{table-head-rows}
|
32 |
+
</thead>
|
33 |
+
<tbody>
|
34 |
+
{table-body-rows}
|
35 |
+
<!-- <tr>-->
|
36 |
+
<!-- <td>Name</td>-->
|
37 |
+
<!-- <td>Mama</td>-->
|
38 |
+
<!-- </tr>-->
|
39 |
+
<!-- <tr>-->
|
40 |
+
<!-- <td></td>-->
|
41 |
+
<!-- <td></td>-->
|
42 |
+
<!-- </tr>-->
|
43 |
+
<!-- <tr>-->
|
44 |
+
<!-- <td></td>-->
|
45 |
+
<!-- <td></td>-->
|
46 |
+
<!-- </tr>-->
|
47 |
+
</tbody>
|
48 |
+
</table>
|
{engine → 2.0/engine}/modules/reports/partials/latest-attempts-locations.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/reports/partials/latest-attempts-table.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/reports/partials/modal-dialog.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/reports/partials/module-table.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/reports/partials/percentage-chart.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/reports/partials/reports-details.php
RENAMED
File without changes
|
2.0/engine/modules/reports/partials/reports-stats.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="row">
|
2 |
+
<article class="col-sm-12">
|
3 |
+
<div id="wid-id-0" class="gdbcwidget clearfix">
|
4 |
+
|
5 |
+
<header>
|
6 |
+
|
7 |
+
<span class="widget-icon icon-primary"><span class="glyphicon glyphicon-dashboard"></span></span>
|
8 |
+
|
9 |
+
<h2> <?php _e('Dashboard', GoodByeCaptcha::PLUGIN_SLUG) ?> </h2>
|
10 |
+
|
11 |
+
<ul id="dashboard-navigation" class="nav nav-tabs pull-right in">
|
12 |
+
<li class="active">
|
13 |
+
<a>
|
14 |
+
<i class="glyphicon glyphicon-stats"></i>
|
15 |
+
<span class="hidden-mobile hidden-tablet"><?php _e('Stats', GoodByeCaptcha::PLUGIN_SLUG) ?></span>
|
16 |
+
</a>
|
17 |
+
</li>
|
18 |
+
<li>
|
19 |
+
<a href="<?php echo $arrReportsNavigationTabUrl[1]; ?>">
|
20 |
+
<i class="glyphicon glyphicon-list-alt"></i>
|
21 |
+
<span class="hidden-mobile hidden-tablet"><?php _e('Detailed', GoodByeCaptcha::PLUGIN_SLUG) ?></span>
|
22 |
+
</a>
|
23 |
+
</li>
|
24 |
+
</ul>
|
25 |
+
|
26 |
+
</header>
|
27 |
+
|
28 |
+
<div class="no-padding">
|
29 |
+
<div class="widget-body" class="tab-content">
|
30 |
+
<div class="tab-pane fade active in padding-10 no-padding-bottom" id="s1">
|
31 |
+
<div class="row no-space">
|
32 |
+
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
33 |
+
<div id="chart-container">
|
34 |
+
</div>
|
35 |
+
</div>
|
36 |
+
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
|
37 |
+
<div class="row">
|
38 |
+
<div class="" id = "gdbc-barchart-holder" style = "position: relative; height: 240px;">
|
39 |
+
</div>
|
40 |
+
|
41 |
+
<div class="col-xs-6 col-sm-6 col-md-12 col-lg-12 text-justify">
|
42 |
+
<p class="text-center pull-right" style="margin: 0">
|
43 |
+
<a class="btn btn-rate-gdbc btn-labeled btn-primary" target = "_blank" href = "https://wordpress.org/support/view/plugin-reviews/goodbye-captcha?filter=5#postform">
|
44 |
+
<span class="btn-label">
|
45 |
+
<i class="glyphicon glyphicon-star"></i>
|
46 |
+
</span>
|
47 |
+
Rate GoodBye Captcha
|
48 |
+
</a>
|
49 |
+
</p>
|
50 |
+
</div>
|
51 |
+
|
52 |
+
</div>
|
53 |
+
</div>
|
54 |
+
</div>
|
55 |
+
</div>
|
56 |
+
</div>
|
57 |
+
</div>
|
58 |
+
</div>
|
59 |
+
</article>
|
60 |
+
</div>
|
61 |
+
|
{engine → 2.0/engine}/modules/seamless-donations/GdbcSeamlessDonationsAdminModule.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/seamless-donations/GdbcSeamlessDonationsPublicModule.php
RENAMED
File without changes
|
2.0/engine/modules/settings/GdbcSettingsAdminModule.php
ADDED
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcSettingsAdminModule extends GdbcBaseAdminModule
|
21 |
+
{
|
22 |
+
CONST OPTION_PLUGIN_VERSION = 'PluginVersion';
|
23 |
+
|
24 |
+
CONST OPTION_TOKEN_SECRET_KEY = 'TokenSecretKey';
|
25 |
+
CONST OPTION_TOKEN_CREATED_TIMESTAMP = 'TokenCreatedTimestamp';
|
26 |
+
CONST OPTION_HIDDEN_INPUT_NAME = 'HiddenInputName';
|
27 |
+
|
28 |
+
CONST OPTION_MIN_SUBMISSION_TIME = 'MinSubmissionTime';
|
29 |
+
|
30 |
+
CONST OPTION_DISABLE_IF_USER_LOGGED_IN = 'DisabledIfUserLoggedIn';
|
31 |
+
|
32 |
+
CONST OPTION_MAX_LOGS_DAYS = 'MaxLogsDays';
|
33 |
+
CONST OPTION_BLOCKED_CONTENT_LOG_DAYS = 'MaxContentLogDays';
|
34 |
+
CONST OPTION_TEST_MODE_ACTIVATED = 'IsTestModeActivated';
|
35 |
+
CONST OPTION_CACHE_DIR_PATH = 'CacheDirPath';
|
36 |
+
|
37 |
+
protected function __construct()
|
38 |
+
{
|
39 |
+
parent::__construct();
|
40 |
+
|
41 |
+
$this->saveSecuredOptions(false);
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getDefaultOptions()
|
45 |
+
{
|
46 |
+
static $arrDefaultSettingOptions = null;
|
47 |
+
if(null !== $arrDefaultSettingOptions)
|
48 |
+
return $arrDefaultSettingOptions;
|
49 |
+
|
50 |
+
$arrDefaultSettingOptions = array(
|
51 |
+
|
52 |
+
self::OPTION_MIN_SUBMISSION_TIME => array(
|
53 |
+
'Value' => 3,
|
54 |
+
'LabelText' => __('Minimum Form Submission Time', GoodByeCaptcha::PLUGIN_SLUG),
|
55 |
+
'Description' => __('Number of seconds before the submission is considered valid', GoodByeCaptcha::PLUGIN_SLUG),
|
56 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_TEXT
|
57 |
+
),
|
58 |
+
|
59 |
+
self::OPTION_BLOCKED_CONTENT_LOG_DAYS => array(
|
60 |
+
'Value' => 10,
|
61 |
+
'LabelText' => __('Keep Blocked Submitted Content For', GoodByeCaptcha::PLUGIN_SLUG),
|
62 |
+
'Description' => __('The blocked submitted data will be saved for the selected number of days', GoodByeCaptcha::PLUGIN_SLUG),
|
63 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_SELECT
|
64 |
+
),
|
65 |
+
|
66 |
+
self::OPTION_MAX_LOGS_DAYS => array(
|
67 |
+
'Value' => 30,
|
68 |
+
'LabelText' => __('Automatically Purge Logs Older Than', GoodByeCaptcha::PLUGIN_SLUG),
|
69 |
+
'Description' => __('Logs older than selected number of days will be automatically purged', GoodByeCaptcha::PLUGIN_SLUG),
|
70 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_SELECT
|
71 |
+
),
|
72 |
+
|
73 |
+
self::OPTION_DISABLE_IF_USER_LOGGED_IN => array(
|
74 |
+
'Value' => NULL,
|
75 |
+
'LabelText' => __('Disable Protection For Logged In Users', GoodByeCaptcha::PLUGIN_SLUG),
|
76 |
+
'Description' => __('If this option is enabled, the protection will be disabled if the user is logged in', GoodByeCaptcha::PLUGIN_SLUG),
|
77 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
78 |
+
),
|
79 |
+
|
80 |
+
self::OPTION_TEST_MODE_ACTIVATED => array(
|
81 |
+
'Value' => NULL,
|
82 |
+
'LabelText' => __('Switch GoodBye Captcha to Test Mode', GoodByeCaptcha::PLUGIN_SLUG),
|
83 |
+
'Description' => __('While in Test Mode you will receive email notifications at {notification-email}', GoodByeCaptcha::PLUGIN_SLUG),
|
84 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
85 |
+
),
|
86 |
+
|
87 |
+
);
|
88 |
+
|
89 |
+
return $arrDefaultSettingOptions;
|
90 |
+
|
91 |
+
}
|
92 |
+
|
93 |
+
|
94 |
+
// public function renderModuleSettingsSectionHeader(array $arrSectionInfo)
|
95 |
+
// {
|
96 |
+
// echo '<h3>' . __('GoodBye Captcha General Settings', GoodByeCaptcha::PLUGIN_SLUG) . '</h3><hr />';
|
97 |
+
// }
|
98 |
+
|
99 |
+
public function renderModuleSettingsField(array $arrSettingsField)
|
100 |
+
{
|
101 |
+
$optionName = key($arrSettingsField);
|
102 |
+
$defaultOptionValues = $this->getDefaultOptionsValues();
|
103 |
+
if(null === $optionName || !array_key_exists($optionName, $defaultOptionValues))
|
104 |
+
return;
|
105 |
+
|
106 |
+
$optionValue = $this->getOption($optionName);
|
107 |
+
if(null === $optionValue && isset($defaultOptionValues[$optionName]))
|
108 |
+
{
|
109 |
+
if(!is_array($defaultOptionValues[$optionName])) {
|
110 |
+
$optionValue = $defaultOptionValues[$optionName];
|
111 |
+
}
|
112 |
+
}
|
113 |
+
|
114 |
+
$arrSettingsField = $arrSettingsField[$optionName];
|
115 |
+
$arrFieldAttributes = array(
|
116 |
+
'name' => $this->getSettingKey() . '[' . $optionName . ']',
|
117 |
+
'type' => !empty($arrSettingsField['InputType']) ? $arrSettingsField['InputType'] : 'text',
|
118 |
+
'value' => $optionValue,
|
119 |
+
'id' => $this->getSettingKey() . '-' . $optionName,
|
120 |
+
);
|
121 |
+
|
122 |
+
if($arrFieldAttributes['type'] === MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX)
|
123 |
+
{
|
124 |
+
!empty($arrFieldAttributes['value']) ? $arrFieldAttributes['checked'] = 'checked' : null;
|
125 |
+
$arrFieldAttributes['value'] = true;
|
126 |
+
}
|
127 |
+
|
128 |
+
if($optionName === self::OPTION_MAX_LOGS_DAYS)
|
129 |
+
{
|
130 |
+
$arrFieldAttributes['options'] = array();
|
131 |
+
for($i = 0; $i <= 6; ++$i) {
|
132 |
+
$arrFieldAttributes['options'][ ( 30 * $i ) . ' days' ] = 30 * $i;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
if($optionName === self::OPTION_BLOCKED_CONTENT_LOG_DAYS)
|
137 |
+
{
|
138 |
+
$arrFieldAttributes['options'] = array();
|
139 |
+
for($i = 0; $i <= 6; ++$i) {
|
140 |
+
$arrFieldAttributes['options'][ ( 5 * $i ) . ' days' ] = 5 * $i;
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
switch ($arrFieldAttributes['type'])
|
145 |
+
{
|
146 |
+
case MchGdbcHtmlUtils::FORM_ELEMENT_SELECT :
|
147 |
+
|
148 |
+
echo MchGdbcHtmlUtils::createSelectElement($arrFieldAttributes);
|
149 |
+
|
150 |
+
break;
|
151 |
+
|
152 |
+
default :
|
153 |
+
|
154 |
+
echo MchGdbcHtmlUtils::createInputElement($arrFieldAttributes);
|
155 |
+
}
|
156 |
+
|
157 |
+
if($optionName === self::OPTION_TEST_MODE_ACTIVATED && !empty($arrSettingsField['Description']))
|
158 |
+
{
|
159 |
+
$arrSettingsField['Description'] = str_replace('{notification-email}', GdbcEmailNotificationsAdminModule::getInstance()->getOption(GdbcEmailNotificationsAdminModule::OPTION_EMAIL_ADDRESS), $arrSettingsField['Description']);
|
160 |
+
}
|
161 |
+
|
162 |
+
if(!empty($arrSettingsField['Description']))
|
163 |
+
{
|
164 |
+
echo '<p class = "description">' . $arrSettingsField['Description'] . '</p>';
|
165 |
+
|
166 |
+
if($optionName === self::OPTION_MAX_LOGS_DAYS)
|
167 |
+
{
|
168 |
+
echo '<p class = "description hidden" style = "color:#d54e21">' . __('By selecting ZERO you TURN OFF logging and you wont be protected against Brute Force attacks !', GoodByeCaptcha::PLUGIN_SLUG) . '</p>';
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
}
|
173 |
+
|
174 |
+
|
175 |
+
public function validateModuleSettingsFields($arrSettingOptions)
|
176 |
+
{
|
177 |
+
|
178 |
+
$arrSettingOptions = array_map('sanitize_text_field', (array)$arrSettingOptions);
|
179 |
+
|
180 |
+
if (empty($arrSettingOptions[self::OPTION_MIN_SUBMISSION_TIME])
|
181 |
+
|| false === ($arrSettingOptions[self::OPTION_MIN_SUBMISSION_TIME] = filter_var($arrSettingOptions[self::OPTION_MIN_SUBMISSION_TIME], FILTER_VALIDATE_INT))
|
182 |
+
|| $arrSettingOptions[self::OPTION_MIN_SUBMISSION_TIME] < 1
|
183 |
+
){
|
184 |
+
$this->registerErrorMessage(__('Minimum Submission Time should be a numeric value greater than 0 !', GoodByeCaptcha::PLUGIN_SLUG));
|
185 |
+
unset($arrSettingOptions[self::OPTION_MIN_SUBMISSION_TIME]);
|
186 |
+
}
|
187 |
+
|
188 |
+
$arrOldSavedOptions = $this->getAllSavedOptions();
|
189 |
+
|
190 |
+
if(!empty($arrOldSavedOptions[self::OPTION_TOKEN_SECRET_KEY]))
|
191 |
+
$arrSettingOptions[self::OPTION_TOKEN_SECRET_KEY] = $arrOldSavedOptions[self::OPTION_TOKEN_SECRET_KEY];
|
192 |
+
|
193 |
+
if(!empty($arrOldSavedOptions[self::OPTION_TOKEN_CREATED_TIMESTAMP]))
|
194 |
+
$arrSettingOptions[self::OPTION_TOKEN_CREATED_TIMESTAMP] = $arrOldSavedOptions[self::OPTION_TOKEN_CREATED_TIMESTAMP];
|
195 |
+
|
196 |
+
if(!empty($arrOldSavedOptions[self::OPTION_HIDDEN_INPUT_NAME]))
|
197 |
+
$arrSettingOptions[self::OPTION_HIDDEN_INPUT_NAME] = $arrOldSavedOptions[self::OPTION_HIDDEN_INPUT_NAME];
|
198 |
+
|
199 |
+
if(!empty($arrOldSavedOptions[self::OPTION_CACHE_DIR_PATH]))
|
200 |
+
$arrSettingOptions[self::OPTION_CACHE_DIR_PATH] = $arrOldSavedOptions[self::OPTION_CACHE_DIR_PATH];
|
201 |
+
|
202 |
+
$arrSettingOptions[self::OPTION_PLUGIN_VERSION] = GoodByeCaptcha::PLUGIN_VERSION;
|
203 |
+
|
204 |
+
$this->registerSuccessMessage(__('Your changes were successfully saved!', GoodByeCaptcha::PLUGIN_SLUG));
|
205 |
+
|
206 |
+
return $arrSettingOptions;
|
207 |
+
|
208 |
+
}
|
209 |
+
|
210 |
+
public function saveSecuredOptions($forceNewValues)
|
211 |
+
{
|
212 |
+
$inputHiddenName = $this->getOption(self::OPTION_HIDDEN_INPUT_NAME);
|
213 |
+
if( (false === (!!$forceNewValues)) && !empty($inputHiddenName) )
|
214 |
+
return;
|
215 |
+
|
216 |
+
if ( defined( 'WP_UNINSTALL_PLUGIN' ) )
|
217 |
+
return;
|
218 |
+
|
219 |
+
$arrSettingOptions = array(
|
220 |
+
self::OPTION_TOKEN_SECRET_KEY => MchCrypt::getRandomString(MchCrypt::getCipherKeySize()),
|
221 |
+
self::OPTION_TOKEN_CREATED_TIMESTAMP => MchGdbcHttpRequest::getServerRequestTime(),
|
222 |
+
self::OPTION_HIDDEN_INPUT_NAME => empty($inputHiddenName) ? MchGdbcUtils::replaceNonAlphaCharacters(MchCrypt::getRandomString(25)) : $inputHiddenName,
|
223 |
+
);
|
224 |
+
|
225 |
+
while( ! isset($arrSettingOptions[self::OPTION_HIDDEN_INPUT_NAME][9]) ) {
|
226 |
+
$arrSettingOptions[ self::OPTION_HIDDEN_INPUT_NAME ] = MchGdbcUtils::replaceNonAlphaCharacters( MchCrypt::getRandomString( 25 ) );
|
227 |
+
}
|
228 |
+
|
229 |
+
foreach($arrSettingOptions as $optionName => $value){
|
230 |
+
$this->saveOption($optionName, $value);
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
public static function getInstance()
|
235 |
+
{
|
236 |
+
static $adminInstance = null;
|
237 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
238 |
+
}
|
239 |
+
|
240 |
+
public function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity)
|
241 |
+
{
|
242 |
+
return null;
|
243 |
+
}
|
244 |
+
|
245 |
+
}
|
2.0/engine/modules/settings/GdbcSettingsPublicModule.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcSettingsPublicModule extends GdbcBasePublicModule
|
21 |
+
{
|
22 |
+
protected function __construct()
|
23 |
+
{
|
24 |
+
parent::__construct();
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @return int
|
29 |
+
*/
|
30 |
+
protected function getModuleId()
|
31 |
+
{
|
32 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_SETTINGS);
|
33 |
+
}
|
34 |
+
|
35 |
+
public static function getInstance()
|
36 |
+
{
|
37 |
+
static $publicInstance = null;
|
38 |
+
return null !== $publicInstance ? $publicInstance : $publicInstance = new self();
|
39 |
+
}
|
40 |
+
|
41 |
+
}
|
{engine → 2.0/engine}/modules/ultimate-member/GdbcUltimateMemberAdminModule.php
RENAMED
File without changes
|
2.0/engine/modules/ultimate-member/GdbcUltimateMemberPublicModule.php
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class GdbcUltimateMemberPublicModule extends GdbcBasePublicModule
|
22 |
+
{
|
23 |
+
|
24 |
+
protected function __construct()
|
25 |
+
{
|
26 |
+
parent::__construct();
|
27 |
+
|
28 |
+
if(!GoodByeCaptchaUtils::isUltimateMemberActivated())
|
29 |
+
return;
|
30 |
+
|
31 |
+
if($this->getOption(GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOGIN_FORM)){
|
32 |
+
$this->registerLoginHooks();
|
33 |
+
}
|
34 |
+
|
35 |
+
if($this->getOption(GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_REGISTER_FORM)){
|
36 |
+
$this->registerRegistrationHooks();
|
37 |
+
}
|
38 |
+
|
39 |
+
if($this->getOption(GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOST_PASSWORD_FORM)){
|
40 |
+
$this->registerLostPasswordHooks();
|
41 |
+
}
|
42 |
+
|
43 |
+
}
|
44 |
+
|
45 |
+
private function registerLoginHooks()
|
46 |
+
{
|
47 |
+
add_action('um_submit_form_errors_hook', array($this, 'validateFormEncryptedToken'), 1);
|
48 |
+
add_action('um_after_login_fields', array($this, 'renderHiddenFieldIntoForm'));
|
49 |
+
}
|
50 |
+
|
51 |
+
public function registerRegistrationHooks()
|
52 |
+
{
|
53 |
+
add_action('um_submit_form_errors_hook__registration', array($this, 'validateFormEncryptedToken'), 1);
|
54 |
+
add_action('um_after_register_fields', array($this, 'renderHiddenFieldIntoForm'));
|
55 |
+
}
|
56 |
+
|
57 |
+
public function registerLostPasswordHooks()
|
58 |
+
{
|
59 |
+
add_action('um_reset_password_page_hidden_fields', array($this, 'renderHiddenFieldIntoForm'), 10);
|
60 |
+
add_action('um_reset_password_errors_hook', array($this, 'validateFormEncryptedToken'), 1);
|
61 |
+
}
|
62 |
+
|
63 |
+
public function renderHiddenFieldIntoForm()
|
64 |
+
{
|
65 |
+
echo $this->getTokenFieldHtml();
|
66 |
+
}
|
67 |
+
|
68 |
+
public function validateFormEncryptedToken($arrRequestInfo)
|
69 |
+
{
|
70 |
+
if(MchGdbcWpUtils::isUserLoggedIn())
|
71 |
+
return;
|
72 |
+
|
73 |
+
$umSection = !empty($arrRequestInfo['_um_password_reset']) ? GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOST_PASSWORD_FORM : null;
|
74 |
+
if(null === $umSection && !empty($arrRequestInfo['mode']))
|
75 |
+
{
|
76 |
+
('login' === $arrRequestInfo['mode']) ? $umSection = GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOGIN_FORM : ('register' === $arrRequestInfo['mode'] ? $umSection = GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_REGISTER_FORM : null);
|
77 |
+
}
|
78 |
+
|
79 |
+
global $ultimatemember;
|
80 |
+
|
81 |
+
if(null === $umSection || !isset($ultimatemember->form) || !(class_exists('UM_Form')) || !($ultimatemember->form instanceof UM_Form))
|
82 |
+
{
|
83 |
+
wp_redirect(esc_url(add_query_arg('err', '1')));
|
84 |
+
exit;
|
85 |
+
}
|
86 |
+
|
87 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName($umSection);
|
88 |
+
|
89 |
+
$arrSubmittedData = array();
|
90 |
+
if(!empty($arrRequestInfo['custom_fields']) && is_serialized($arrRequestInfo['custom_fields']))
|
91 |
+
{
|
92 |
+
$arrFields = (array)maybe_unserialize($arrRequestInfo['custom_fields']);
|
93 |
+
unset($arrRequestInfo['custom_fields']);
|
94 |
+
|
95 |
+
foreach((array)$arrRequestInfo as $formFieldName => $value)
|
96 |
+
{
|
97 |
+
if(!isset($arrFields[$formFieldName]['label']))
|
98 |
+
continue;
|
99 |
+
if(isset($arrFields[$formFieldName]['type']) && $arrFields[$formFieldName]['type'] === 'password')
|
100 |
+
continue;
|
101 |
+
|
102 |
+
$arrSubmittedData[$arrFields[$formFieldName]['label']] = $value;
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
if(isset($_POST['username_b']) && $umSection === GdbcUltimateMemberAdminModule::OPTION_ULTIMATE_MEMBER_LOST_PASSWORD_FORM)
|
107 |
+
{
|
108 |
+
$key = is_email($_POST['username_b']) ? __('Email', GoodByeCaptcha::PLUGIN_SLUG) : __('Username', GoodByeCaptcha::PLUGIN_SLUG);
|
109 |
+
$arrSubmittedData[$key] = $_POST['username_b'];
|
110 |
+
}
|
111 |
+
|
112 |
+
$this->getAttemptEntity()->Notes = $arrSubmittedData;
|
113 |
+
|
114 |
+
if(GdbcRequestController::isValid($this->attemptEntity))
|
115 |
+
return;
|
116 |
+
|
117 |
+
wp_redirect(esc_url(add_query_arg('err', '1')));
|
118 |
+
exit;
|
119 |
+
}
|
120 |
+
|
121 |
+
|
122 |
+
/**
|
123 |
+
* @return int
|
124 |
+
*/
|
125 |
+
protected function getModuleId()
|
126 |
+
{
|
127 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_ULTIMATE_MEMBER);
|
128 |
+
}
|
129 |
+
|
130 |
+
public static function getInstance()
|
131 |
+
{
|
132 |
+
static $adminInstance = null;
|
133 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
134 |
+
}
|
135 |
+
|
136 |
+
}
|
{engine → 2.0/engine}/modules/white-listed-ips/GdbcWhiteListedIpsAdminModule.php
RENAMED
File without changes
|
{engine → 2.0/engine}/modules/white-listed-ips/GdbcWhiteListedIpsPublicModule.php
RENAMED
File without changes
|
2.0/engine/modules/white-listed-ips/partials/admin-settings.php
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
?>
|
20 |
+
<style type="text/css">
|
21 |
+
|
22 |
+
.gdbc-settings tr.even
|
23 |
+
{
|
24 |
+
background-color:#f5f5f5;
|
25 |
+
}
|
26 |
+
|
27 |
+
.gdbc-blacklisted-ips-holder input[type="text"]
|
28 |
+
{
|
29 |
+
width: 99%;
|
30 |
+
}
|
31 |
+
.gdbc-blacklisted-ips-holder thead tbody > tr form > td:first-child
|
32 |
+
{
|
33 |
+
padding: 0 30px !important;
|
34 |
+
}
|
35 |
+
|
36 |
+
.gdbc-blacklisted-ips-holder td
|
37 |
+
{
|
38 |
+
vertical-align: middle !important;
|
39 |
+
word-wrap: normal !important;
|
40 |
+
}
|
41 |
+
.gdbc-blacklisted-ips-holder th
|
42 |
+
{
|
43 |
+
font-weight: 700;
|
44 |
+
}
|
45 |
+
|
46 |
+
</style>
|
47 |
+
|
48 |
+
<?php
|
49 |
+
|
50 |
+
$formAction = GoodByeCaptcha::isNetworkActivated() ? '' : 'options.php';
|
51 |
+
|
52 |
+
?>
|
53 |
+
|
54 |
+
|
55 |
+
<table class="wp-list-table widefat fixed gdbc-blacklisted-ips-holder">
|
56 |
+
<thead>
|
57 |
+
|
58 |
+
<tr>
|
59 |
+
<th></th>
|
60 |
+
<th></th>
|
61 |
+
<th></th>
|
62 |
+
<th></th>
|
63 |
+
</tr>
|
64 |
+
|
65 |
+
|
66 |
+
<tr class = "even">
|
67 |
+
<td colspan="4" style=" text-align: right">
|
68 |
+
<form method="post" action="<?php echo $formAction ?>">
|
69 |
+
<div class="clearfix" style="margin:0 auto; width: 700px;">
|
70 |
+
<input style = "float: left;clear: left; width: 80%;" type="text" name="<?php echo $this->getWhiteListedIpsInputName();?>" placeholder="<?php _e('IP/RANGE/CIDR', GoodByeCaptcha::PLUGIN_SLUG); ?>" required />
|
71 |
+
<input style = "float: right;" type="submit" value="<?php _e('Add to WhiteList', GoodByeCaptcha::PLUGIN_SLUG); ?>" class="button button-primary" />
|
72 |
+
</div>
|
73 |
+
|
74 |
+
<?php settings_fields( $this->getSettingGroupId($this->whiteListedIpsGroupIndex) );?>
|
75 |
+
|
76 |
+
</form>
|
77 |
+
</td>
|
78 |
+
</tr>
|
79 |
+
<tr>
|
80 |
+
<th width="5%"></th>
|
81 |
+
<th width="30%"></th>
|
82 |
+
<th width="50%"></th>
|
83 |
+
<th width="15%"></th>
|
84 |
+
</tr>
|
85 |
+
|
86 |
+
|
87 |
+
<tr>
|
88 |
+
<th width="5%"><?php _e('Hosts', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
89 |
+
<th width="30%"><?php _e('IP Address/Range/CIDR', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
90 |
+
<th width="60%"><?php _e('Country', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
91 |
+
<th width="5%" style="text-align: right; padding-right: 22px"><?php _e('Actions', GoodByeCaptcha::PLUGIN_SLUG); ?></th>
|
92 |
+
</tr>
|
93 |
+
|
94 |
+
</thead>
|
95 |
+
|
96 |
+
<tbody>
|
97 |
+
<?php
|
98 |
+
|
99 |
+
$arrAllIPs = GdbcIPUtils::getFormattedIpRangesForDisplay(GdbcWhiteListedIpsAdminModule::getInstance()->getOption(GdbcWhiteListedIpsAdminModule::OPTION_WHITE_LISTED_IPS));
|
100 |
+
|
101 |
+
$whiteListPageNumber = !empty( $_GET['whiteListPageNumber'] ) ? absint( sanitize_text_field($_GET['whiteListPageNumber']) ) : 1;
|
102 |
+
|
103 |
+
$recordsPerPage = 10;
|
104 |
+
|
105 |
+
$paginationCode = null;
|
106 |
+
|
107 |
+
$arrRecords = array_chunk($arrAllIPs, $recordsPerPage, true);
|
108 |
+
|
109 |
+
if(isset($arrRecords[1]))
|
110 |
+
{
|
111 |
+
$paginationCode = paginate_links(
|
112 |
+
array(
|
113 |
+
'base' => add_query_arg( 'whiteListPageNumber', '%#%' ),
|
114 |
+
'format' => '',
|
115 |
+
'prev_text' => __( '«', GoodByeCaptcha::PLUGIN_SLUG ),
|
116 |
+
'next_text' => __( '»', GoodByeCaptcha::PLUGIN_SLUG ),
|
117 |
+
'total' => ceil(count($arrAllIPs)/$recordsPerPage),
|
118 |
+
'current' => $whiteListPageNumber
|
119 |
+
)
|
120 |
+
);
|
121 |
+
}
|
122 |
+
|
123 |
+
if(!empty($arrRecords[$whiteListPageNumber - 1]))
|
124 |
+
$arrRecords = $arrRecords[$whiteListPageNumber - 1];
|
125 |
+
else
|
126 |
+
$arrRecords = $arrAllIPs;
|
127 |
+
|
128 |
+
unset($arrAllIPs);
|
129 |
+
foreach($arrRecords as $key => $formattedIp)
|
130 |
+
{
|
131 |
+
|
132 |
+
$arrFormattedIp = explode('|', $formattedIp);
|
133 |
+
if(count($arrFormattedIp) != 2)
|
134 |
+
continue;
|
135 |
+
|
136 |
+
$countryCode = sanitize_text_field(MchGdbcIPUtils::getCountryCode($arrFormattedIp[0]));
|
137 |
+
|
138 |
+
$countryName = GoodByeCaptchaUtils::getCountryNameById(GoodByeCaptchaUtils::getCountryIdByCode($countryCode));
|
139 |
+
|
140 |
+
if(empty($countryName))
|
141 |
+
{
|
142 |
+
$countryName = __('Unavailable', GoodByeCaptcha::PLUGIN_SLUG);
|
143 |
+
}
|
144 |
+
|
145 |
+
$rowClass = (($key % 2) == 0) ? 'even' : '';
|
146 |
+
|
147 |
+
echo '<tr class="' . $rowClass . '">';
|
148 |
+
|
149 |
+
echo '<td width="5%">' . $arrFormattedIp[1] . '</td>';
|
150 |
+
echo '<td width="30%">' . strtoupper($arrFormattedIp[0]) . '</td>';
|
151 |
+
echo '<td width="60%">' . $countryName . '</td>';
|
152 |
+
|
153 |
+
?>
|
154 |
+
|
155 |
+
|
156 |
+
<td style="text-align: right;" width="5%">
|
157 |
+
<form method="post" action="<?php echo $formAction ?>">
|
158 |
+
<?php settings_fields( $this->getSettingGroupId($this->whiteListedIpsGroupIndex) );?>
|
159 |
+
<input type="hidden" name="<?php echo $this->getWhiteListedIpsInputName();?>" value="<?php echo 'remove-' . $arrFormattedIp[0]?>" />
|
160 |
+
<input type="submit" value="<?php echo __('Remove', GoodByeCaptcha::PLUGIN_SLUG); ?>" class="button" />
|
161 |
+
</form>
|
162 |
+
</td>
|
163 |
+
|
164 |
+
|
165 |
+
<?php
|
166 |
+
|
167 |
+
echo '</tr>';
|
168 |
+
|
169 |
+
}
|
170 |
+
|
171 |
+
|
172 |
+
?>
|
173 |
+
|
174 |
+
|
175 |
+
</tbody>
|
176 |
+
</table>
|
177 |
+
|
178 |
+
<?php
|
179 |
+
if(!empty($paginationCode))
|
180 |
+
{
|
181 |
+
echo '<div class="postbox-footer clearfix" style="">';
|
182 |
+
echo '<div class="tablenav"><div class="tablenav-pages" style="margin:0">' . $paginationCode . '</div></div></div>';
|
183 |
+
}
|
184 |
+
?>
|
185 |
+
|
186 |
+
|
187 |
+
<div class="postbox-footer clearfix" style="">
|
188 |
+
|
189 |
+
<dl style="width: 48%; float: left; border-right: 1px solid #ddd; padding-right: 15px">
|
190 |
+
<dt><h4 style="margin: 2px 0; border-bottom: 1px solid #ccc;">Accepted IPV4 Formats</h4></dt>
|
191 |
+
<dd style="margin-left: 0">Standard IPV4 format <span style="float: right">123.123.1.1</span></dd>
|
192 |
+
<dd style="margin-left: 0">Standard CIDR Block format <span style="float: right">123.123.1.1/32</span></dd>
|
193 |
+
<dd style="margin-left: 0">Wildcard Range format <span style="float: right">123.123.1.*</span></dd>
|
194 |
+
<dd style="margin-left: 0">Non-Standard Range format <span style="float: right">123.123.1.1 - 123.123.1.10</span></dd>
|
195 |
+
</dl>
|
196 |
+
|
197 |
+
<dl style="width: 50%; float: right;" >
|
198 |
+
<dt><h4 style="margin: 2px 0; border-bottom: 1px solid #ccc;">Accepted IPV6 Formats</h4></dt>
|
199 |
+
<dd style="margin-left: 0">Fully Uncompressed format <span style="float: right">2002:4559:1FE2:0000:0000:0000:4559:1FE2</span></dd>
|
200 |
+
<dd style="margin-left: 0">Standard CIDR Block format <span style="float: right">2002:4559:1FE2::4559:1FE2/128</span></dd>
|
201 |
+
<dd style="margin-left: 0">Uncompressed format <span style="float: right">2002:4559:1FE2:0:0:0:4559:1FE2</span></dd>
|
202 |
+
<dd style="margin-left: 0">Compressed format <span style="float: right">2002:4559:1FE2::4559:1FE2</span></dd>
|
203 |
+
</dl>
|
204 |
+
|
205 |
+
</div>
|
206 |
+
|
207 |
+
|
2.0/engine/modules/wordpress-tweaks/GdbcWordPressTweaksAdminModule.php
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcWordPressTweaksAdminModule extends GdbcBaseAdminModule
|
21 |
+
{
|
22 |
+
|
23 |
+
CONST WORDPRESS_REMOVE_RSD_HEADER = 'HideRSDHeader';
|
24 |
+
CONST WORDPRESS_REMOVE_WLW_HEADER = 'HideWLWHeader';
|
25 |
+
|
26 |
+
CONST WORDPRESS_HIDE_VERSION = 'HideVersion';
|
27 |
+
|
28 |
+
CONST WORDPRESS_XML_RPC_FULLY_DISABLED = 'XmlRpcFullyDisabled';
|
29 |
+
CONST WORDPRESS_XML_RPC_PINGBACK_DISABLED = 'XmlRpcPingDisabled';
|
30 |
+
|
31 |
+
CONST WORDPRESS_COMMENTS_FORM_WEBSITE_FIELD = 'CommentsWebsiteFieldHidden';
|
32 |
+
CONST WORDPRESS_COMMENTS_FORM_NOTES_FIELDS = 'CommentsNoteHidden'; // hides allowed tags and text like "Your email address will not be published"
|
33 |
+
|
34 |
+
protected function __construct()
|
35 |
+
{
|
36 |
+
parent::__construct();
|
37 |
+
}
|
38 |
+
|
39 |
+
public function getDefaultOptions()
|
40 |
+
{
|
41 |
+
static $arrDefaultSettingOptions = null;
|
42 |
+
if(null !== $arrDefaultSettingOptions)
|
43 |
+
return $arrDefaultSettingOptions;
|
44 |
+
|
45 |
+
$arrDefaultSettingOptions = array(
|
46 |
+
|
47 |
+
self::WORDPRESS_HIDE_VERSION => array(
|
48 |
+
'Id' => 1,
|
49 |
+
'Value' => NULL,
|
50 |
+
'LabelText' => __('Hide WordPress Version', GoodByeCaptcha::PLUGIN_SLUG),
|
51 |
+
'Description' => __('This will hide your WordPress version information from potential attackers', GoodByeCaptcha::PLUGIN_SLUG),
|
52 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
53 |
+
),
|
54 |
+
|
55 |
+
self::WORDPRESS_REMOVE_RSD_HEADER => array(
|
56 |
+
'Id' => 2,
|
57 |
+
'Value' => NULL,
|
58 |
+
'LabelText' => __('Remove RSD Header', GoodByeCaptcha::PLUGIN_SLUG),
|
59 |
+
'Description' => __('Removes the RSD (Really Simple Discovery) header. The header is useful only if your blog is integrated with external services such as Flickr', GoodByeCaptcha::PLUGIN_SLUG),
|
60 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
61 |
+
),
|
62 |
+
|
63 |
+
self::WORDPRESS_REMOVE_WLW_HEADER => array(
|
64 |
+
'Id' => 3,
|
65 |
+
'Value' => NULL,
|
66 |
+
'LabelText' => __('Remove WLW Header', GoodByeCaptcha::PLUGIN_SLUG),
|
67 |
+
'Description' => __('Removes the WLW (Windows Live Writer Header) header. The header is useful only if you use Windows Live Writer', GoodByeCaptcha::PLUGIN_SLUG),
|
68 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
69 |
+
),
|
70 |
+
|
71 |
+
self::WORDPRESS_XML_RPC_FULLY_DISABLED => array(
|
72 |
+
'Id' => 4,
|
73 |
+
'Value' => NULL,
|
74 |
+
'LabelText' => __('Completely Disable XML-RPC', GoodByeCaptcha::PLUGIN_SLUG),
|
75 |
+
'Description' => __('<b>It seamlessly works with Jetpack plugin</b>. Do not enable if there is other system such as Android/IOS app that uses your XML-RPC service.', GoodByeCaptcha::PLUGIN_SLUG),
|
76 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
77 |
+
),
|
78 |
+
|
79 |
+
self::WORDPRESS_XML_RPC_PINGBACK_DISABLED => array(
|
80 |
+
'Id' => 5,
|
81 |
+
'Value' => NULL,
|
82 |
+
'LabelText' => __('Disable XML-RPC Pingbacks', GoodByeCaptcha::PLUGIN_SLUG),
|
83 |
+
'Description' => __('Removes just the Pingbacks methods from the XML-RPC service. This will also remove the X-Pingback header', GoodByeCaptcha::PLUGIN_SLUG),
|
84 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
85 |
+
),
|
86 |
+
|
87 |
+
self::WORDPRESS_COMMENTS_FORM_WEBSITE_FIELD => array(
|
88 |
+
'Id' => 6,
|
89 |
+
'Value' => NULL,
|
90 |
+
'LabelText' => __('Hide Comments Website Field', GoodByeCaptcha::PLUGIN_SLUG),
|
91 |
+
'Description' => __('Hides Comments Form Website Url', GoodByeCaptcha::PLUGIN_SLUG),
|
92 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
93 |
+
),
|
94 |
+
|
95 |
+
|
96 |
+
self::WORDPRESS_COMMENTS_FORM_NOTES_FIELDS => array(
|
97 |
+
'Id' => 7,
|
98 |
+
'Value' => NULL,
|
99 |
+
'LabelText' => __('Hide Comments Form Notes Fields', GoodByeCaptcha::PLUGIN_SLUG),
|
100 |
+
'Description' => __('Hides form allowed tags and text like "Your email address will not be published"', GoodByeCaptcha::PLUGIN_SLUG),
|
101 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
102 |
+
),
|
103 |
+
|
104 |
+
);
|
105 |
+
|
106 |
+
return $arrDefaultSettingOptions;
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
+
public function validateModuleSettingsFields($arrSettingOptions)
|
111 |
+
{
|
112 |
+
$this->registerSuccessMessage(__('Your changes were successfully saved!', GoodByeCaptcha::PLUGIN_SLUG));
|
113 |
+
return $arrSettingOptions;
|
114 |
+
}
|
115 |
+
|
116 |
+
// public function renderModuleSettingsSectionHeader(array $arrSectionInfo)
|
117 |
+
// {
|
118 |
+
// echo '<h3>' . __('Tweaking WordPress', GoodByeCaptcha::PLUGIN_SLUG) . '</h3><hr />';
|
119 |
+
// }
|
120 |
+
|
121 |
+
|
122 |
+
public function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity)
|
123 |
+
{
|
124 |
+
return null;
|
125 |
+
}
|
126 |
+
|
127 |
+
public static function getInstance()
|
128 |
+
{
|
129 |
+
static $adminInstance = null;
|
130 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
131 |
+
}
|
132 |
+
|
133 |
+
}
|
2.0/engine/modules/wordpress-tweaks/GdbcWordPressTweaksPublicModule.php
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcWordPressTweaksPublicModule extends GdbcBasePublicModule
|
21 |
+
{
|
22 |
+
|
23 |
+
protected function __construct()
|
24 |
+
{
|
25 |
+
parent::__construct();
|
26 |
+
|
27 |
+
if($this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_COMMENTS_FORM_NOTES_FIELDS))
|
28 |
+
{
|
29 |
+
$this->addFilterHook('comment_form_defaults', array($this, 'hideFormNotesFields'));
|
30 |
+
}
|
31 |
+
|
32 |
+
if($this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_COMMENTS_FORM_WEBSITE_FIELD))
|
33 |
+
{
|
34 |
+
$this->addFilterHook('comment_form_default_fields', array($this, 'hideFormWebSiteField'));
|
35 |
+
}
|
36 |
+
|
37 |
+
if($this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_REMOVE_RSD_HEADER))
|
38 |
+
{
|
39 |
+
remove_action('wp_head', 'rsd_link');
|
40 |
+
}
|
41 |
+
|
42 |
+
if($this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_REMOVE_WLW_HEADER))
|
43 |
+
{
|
44 |
+
remove_action('wp_head', 'wlwmanifest_link');
|
45 |
+
}
|
46 |
+
|
47 |
+
if($this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_HIDE_VERSION))
|
48 |
+
{
|
49 |
+
foreach(array('html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export') as $generatorType) {
|
50 |
+
add_filter("get_the_generator_{$generatorType}", '__return_empty_string');
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
if(MchGdbcWpUtils::isXmlRpcRequest() && (bool)$this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_XML_RPC_FULLY_DISABLED))
|
55 |
+
{
|
56 |
+
$this->blockXmlRpcRequest();
|
57 |
+
}
|
58 |
+
|
59 |
+
if(MchGdbcWpUtils::isXmlRpcRequest() && (bool)$this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_XML_RPC_PINGBACK_DISABLED))
|
60 |
+
{
|
61 |
+
add_filter('xmlrpc_methods', 'removeXPingBackXmlRpcMethods'); // keep this to priority 10
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
if($this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_XML_RPC_FULLY_DISABLED) || $this->getOption(GdbcWordPressTweaksAdminModule::WORDPRESS_XML_RPC_PINGBACK_DISABLED))
|
66 |
+
{
|
67 |
+
add_filter('wp_headers', array($this, 'removeXPingBackHeader'), 9999);
|
68 |
+
add_filter('bloginfo_url', array($this, 'filterXPingBackLink'), 9999, 2);
|
69 |
+
}
|
70 |
+
|
71 |
+
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
private function blockXmlRpcRequest()
|
76 |
+
{
|
77 |
+
if(empty($_POST) || GdbcIPUtils::isClientIpWhiteListed())
|
78 |
+
return;
|
79 |
+
|
80 |
+
if(GoodByeCaptchaUtils::isJetPackPluginActivated() && MchGdbcTrustedIPRanges::isIPInAutomatticRanges(GdbcIPUtils::getClientIpAddress(), MchGdbcIPUtils::getIpAddressVersion(GdbcIPUtils::getClientIpAddress()))) {
|
81 |
+
return;
|
82 |
+
}
|
83 |
+
|
84 |
+
$this->getAttemptEntity()->ModuleId = GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_WORDPRESS);
|
85 |
+
$this->getAttemptEntity()->SectionId = GdbcModulesController::getModuleOptionId(GdbcModulesController::MODULE_WORDPRESS, GdbcWordPressAdminModule::WORDPRESS_LOGIN_XML_RPC);
|
86 |
+
$this->getAttemptEntity()->ReasonId = GdbcRequestController::REJECT_REASON_SERVICE_UNAVAILABLE;
|
87 |
+
|
88 |
+
GdbcBruteGuardian::logRejectedAttempt($this->getAttemptEntity());
|
89 |
+
|
90 |
+
if (!headers_sent()) {
|
91 |
+
header('Connection: close');
|
92 |
+
header('Content-Type: text/xml');
|
93 |
+
header('Date: ' . date('r'));
|
94 |
+
}
|
95 |
+
|
96 |
+
echo '<?xml version="1.0"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>405</int></value></member><member><name>faultString</name><value><string>XML-RPC services are disabled on this site!</string></value></member></struct></value></fault></methodResponse>';
|
97 |
+
exit;
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
public function removeXPingBackXmlRpcMethods($arrXmlRpcMethods)
|
102 |
+
{
|
103 |
+
if(empty($_POST) || GdbcIPUtils::isClientIpWhiteListed())
|
104 |
+
return;
|
105 |
+
|
106 |
+
if(GoodByeCaptchaUtils::isJetPackPluginActivated() && MchGdbcTrustedIPRanges::isIPInAutomatticRanges(GdbcIPUtils::getClientIpAddress(), MchGdbcIPUtils::getIpAddressVersion(GdbcIPUtils::getClientIpAddress()))) {
|
107 |
+
return;
|
108 |
+
}
|
109 |
+
|
110 |
+
unset( $arrXmlRpcMethods['pingback.ping'] );
|
111 |
+
unset( $arrXmlRpcMethods['pingback.extensions.getPingbacks'] );
|
112 |
+
return $arrXmlRpcMethods;
|
113 |
+
}
|
114 |
+
|
115 |
+
public function removeXPingBackHeader($arrHeaders)
|
116 |
+
{
|
117 |
+
unset( $arrHeaders['X-Pingback'] );
|
118 |
+
return $arrHeaders;
|
119 |
+
}
|
120 |
+
|
121 |
+
public function filterXPingBackLink($output, $show )
|
122 |
+
{
|
123 |
+
return ('pingback_url' === $show) ? '' : $output;
|
124 |
+
}
|
125 |
+
|
126 |
+
public function hideFormWebSiteField($arrDefaultFields)
|
127 |
+
{
|
128 |
+
unset($arrDefaultFields['url']);
|
129 |
+
return $arrDefaultFields;
|
130 |
+
}
|
131 |
+
|
132 |
+
public function hideFormNotesFields($arrDefaultFields)
|
133 |
+
{
|
134 |
+
$arrDefaultFields = (array)$arrDefaultFields;
|
135 |
+
$arrDefaultFields['comment_notes_before'] = '';
|
136 |
+
$arrDefaultFields['comment_notes_after'] = '';
|
137 |
+
|
138 |
+
return $arrDefaultFields;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* @return int
|
143 |
+
*/
|
144 |
+
protected function getModuleId()
|
145 |
+
{
|
146 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_WORDPRESS_TWEAKS);
|
147 |
+
}
|
148 |
+
|
149 |
+
public static function getInstance()
|
150 |
+
{
|
151 |
+
static $publicInstance = null;
|
152 |
+
return null !== $publicInstance ? $publicInstance : $publicInstance = new self();
|
153 |
+
}
|
154 |
+
|
155 |
+
|
156 |
+
}
|
2.0/engine/modules/wordpress/GdbcWordPressAdminModule.php
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcWordPressAdminModule extends GdbcBaseAdminModule
|
21 |
+
{
|
22 |
+
CONST WORDPRESS_LOGIN_FORM = 'LoginActivated';
|
23 |
+
CONST WORDPRESS_COMMENTS_FORM = 'CommentsActivated';
|
24 |
+
CONST WORDPRESS_LOST_PASSWORD_FORM = 'LostPasswordActivated';
|
25 |
+
CONST WORDPRESS_REGISTRATION_FORM = 'UserRegisterActivated';
|
26 |
+
CONST WORDPRESS_LOGIN_XML_RPC = 'LoginXmlRpc';
|
27 |
+
|
28 |
+
|
29 |
+
protected function __construct()
|
30 |
+
{
|
31 |
+
parent::__construct();
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getDefaultOptions()
|
35 |
+
{
|
36 |
+
static $arrDefaultSettingOptions = null;
|
37 |
+
if(null !== $arrDefaultSettingOptions)
|
38 |
+
return $arrDefaultSettingOptions;
|
39 |
+
|
40 |
+
$arrDefaultSettingOptions = array(
|
41 |
+
|
42 |
+
self::WORDPRESS_COMMENTS_FORM => array(
|
43 |
+
'Id' => 1,
|
44 |
+
'Value' => NULL,
|
45 |
+
'LabelText' => __('Protect Comments Form', GoodByeCaptcha::PLUGIN_SLUG),
|
46 |
+
'DisplayText' => __('Comments', GoodByeCaptcha::PLUGIN_SLUG),
|
47 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
48 |
+
),
|
49 |
+
|
50 |
+
self::WORDPRESS_LOGIN_FORM => array(
|
51 |
+
'Id' => 2,
|
52 |
+
'Value' => NULL,
|
53 |
+
'LabelText' => __('Protect Login Form', GoodByeCaptcha::PLUGIN_SLUG),
|
54 |
+
'DisplayText' => __('Login', GoodByeCaptcha::PLUGIN_SLUG),
|
55 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
56 |
+
),
|
57 |
+
|
58 |
+
self::WORDPRESS_LOST_PASSWORD_FORM => array(
|
59 |
+
'Id' => 3,
|
60 |
+
'Value' => NULL,
|
61 |
+
'LabelText' => __('Protect Lost Password Form', GoodByeCaptcha::PLUGIN_SLUG),
|
62 |
+
'DisplayText' => __('Lost Password', GoodByeCaptcha::PLUGIN_SLUG),
|
63 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
64 |
+
),
|
65 |
+
|
66 |
+
self::WORDPRESS_REGISTRATION_FORM => array(
|
67 |
+
'Id' => 4,
|
68 |
+
'Value' => NULL,
|
69 |
+
'LabelText' => __('Protect Registration Form', GoodByeCaptcha::PLUGIN_SLUG),
|
70 |
+
'DisplayText' => __('Registration', GoodByeCaptcha::PLUGIN_SLUG),
|
71 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_CHECKBOX
|
72 |
+
),
|
73 |
+
|
74 |
+
self::WORDPRESS_LOGIN_XML_RPC => array(
|
75 |
+
'Id' => 5,
|
76 |
+
'Value' => NULL,
|
77 |
+
'LabelText' => null,
|
78 |
+
'DisplayText' => __('XML-RPC Login', GoodByeCaptcha::PLUGIN_SLUG),
|
79 |
+
'InputType' => MchGdbcHtmlUtils::FORM_ELEMENT_INPUT_HIDDEN
|
80 |
+
),
|
81 |
+
|
82 |
+
);
|
83 |
+
|
84 |
+
return $arrDefaultSettingOptions;
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
public function validateModuleSettingsFields($arrSettingOptions)
|
89 |
+
{
|
90 |
+
$this->registerSuccessMessage(__('Your changes were successfully saved!', GoodByeCaptcha::PLUGIN_SLUG));
|
91 |
+
return $arrSettingOptions;
|
92 |
+
}
|
93 |
+
|
94 |
+
// public function renderModuleSettingsSectionHeader(array $arrSectionInfo)
|
95 |
+
// {
|
96 |
+
// echo '<h3>' . __('WordPress Standard Forms Protection', GoodByeCaptcha::PLUGIN_SLUG) . '</h3><hr />';
|
97 |
+
// }
|
98 |
+
|
99 |
+
|
100 |
+
public function getFormattedBlockedContent(GdbcAttemptEntity $attemptEntity)
|
101 |
+
{
|
102 |
+
$optionName = $this->getOptionNameByOptionId($attemptEntity->SectionId);
|
103 |
+
|
104 |
+
$attemptEntity->Notes = (array)maybe_unserialize($attemptEntity->Notes);
|
105 |
+
|
106 |
+
$arrContent = array('table-head-rows' => '', 'table-body-rows' => '');
|
107 |
+
|
108 |
+
if(null === $optionName)
|
109 |
+
return $arrContent;
|
110 |
+
|
111 |
+
$tableHeadRows = '';
|
112 |
+
$tableBodyRows = '';
|
113 |
+
|
114 |
+
$tableHeadRows .= '<tr>';
|
115 |
+
$tableHeadRows .= '<th colspan="2">' . sprintf(__("Blocked %s Attempt", GoodByeCaptcha::PLUGIN_SLUG), $this->getOptionDisplayTextByOptionId($attemptEntity->SectionId)) . '</th>';
|
116 |
+
$tableHeadRows .= '</tr>';
|
117 |
+
|
118 |
+
$tableHeadRows .= '<tr>';
|
119 |
+
$tableHeadRows .= '<th>' . __('Field', GoodByeCaptcha::PLUGIN_SLUG) . '</th>';
|
120 |
+
$tableHeadRows .= '<th>' . __('Value', GoodByeCaptcha::PLUGIN_SLUG) . '</th>';
|
121 |
+
$tableHeadRows .= '</tr>';
|
122 |
+
|
123 |
+
if(isset($attemptEntity->Notes['comment_content']))
|
124 |
+
{
|
125 |
+
$commentContent = $attemptEntity->Notes['comment_content'];
|
126 |
+
unset($attemptEntity->Notes['comment_content']);
|
127 |
+
$attemptEntity->Notes['comment_content'] = $commentContent;
|
128 |
+
unset($commentContent);
|
129 |
+
}
|
130 |
+
|
131 |
+
if(isset($attemptEntity->Notes['comment_parent']))
|
132 |
+
{
|
133 |
+
$parentCommentLink = (string)get_comment_link(absint($attemptEntity->Notes['comment_parent']));
|
134 |
+
$parentCommentFiledValue = __('Comment Id ', GoodByeCaptcha::PLUGIN_SLUG);
|
135 |
+
|
136 |
+
if(strpos($parentCommentLink, 'http') === 0) {
|
137 |
+
$attemptEntity->Notes['comment_parent'] = '<a target = "blank" href = '. esc_attr($parentCommentLink) .'>' . $parentCommentFiledValue . absint($attemptEntity->Notes['comment_parent']) . '</a>';
|
138 |
+
}
|
139 |
+
else{
|
140 |
+
$attemptEntity->Notes['comment_parent'] = $parentCommentFiledValue . absint($attemptEntity->Notes['comment_parent']);
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
if(isset($attemptEntity->Notes['comment_post_ID']))
|
145 |
+
{
|
146 |
+
$permaLink = get_permalink(absint($attemptEntity->Notes['comment_post_ID']));
|
147 |
+
$title = get_the_title(absint($attemptEntity->Notes['comment_post_ID']));
|
148 |
+
|
149 |
+
if(!empty($title))
|
150 |
+
{
|
151 |
+
unset($attemptEntity->Notes['comment_post_ID']);
|
152 |
+
$attemptEntity->Notes = array_merge(array('post' => '<a href="'.esc_attr($permaLink).'">'. esc_html($title) . '</a>'), $attemptEntity->Notes);
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
if(isset($attemptEntity->Notes['user_id']))
|
157 |
+
{
|
158 |
+
if($wpUser = get_user_by('id', absint($attemptEntity->Notes['user_id']))){
|
159 |
+
$attemptEntity->Notes['username'] = $wpUser->user_login;
|
160 |
+
}
|
161 |
+
|
162 |
+
unset($attemptEntity->Notes['user_id']);
|
163 |
+
}
|
164 |
+
|
165 |
+
foreach($attemptEntity->Notes as $key => $value)
|
166 |
+
{
|
167 |
+
$tableBodyRows .='<tr>';
|
168 |
+
$tableBodyRows .= '<td>' . self::getBlockedContentDisplayableKey($key) . '</td>';
|
169 |
+
$tableBodyRows .= '<td>' . wp_kses_stripslashes(wp_filter_kses(print_r($value, true))) . '</td>';
|
170 |
+
$tableBodyRows .='</tr>';
|
171 |
+
}
|
172 |
+
|
173 |
+
$arrContent['table-head-rows'] = $tableHeadRows;
|
174 |
+
$arrContent['table-body-rows'] = $tableBodyRows;
|
175 |
+
|
176 |
+
return $arrContent;
|
177 |
+
}
|
178 |
+
|
179 |
+
public static function getInstance()
|
180 |
+
{
|
181 |
+
static $adminInstance = null;
|
182 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
183 |
+
}
|
184 |
+
|
185 |
+
}
|
2.0/engine/modules/wordpress/GdbcWordPressPublicModule.php
ADDED
@@ -0,0 +1,314 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class GdbcWordPressPublicModule extends GdbcBasePublicModule
|
21 |
+
{
|
22 |
+
private $commentFormActionIndex = null;
|
23 |
+
private $loginFormHookIndex = null;
|
24 |
+
private $loginFormBottomHookIndex = null;
|
25 |
+
|
26 |
+
protected function __construct()
|
27 |
+
{
|
28 |
+
parent::__construct();
|
29 |
+
|
30 |
+
if($this->getOption(GdbcWordPressAdminModule::WORDPRESS_LOGIN_FORM) !== null)
|
31 |
+
{
|
32 |
+
$this->activateLoginHooks();
|
33 |
+
}
|
34 |
+
|
35 |
+
if($this->getOption(GdbcWordPressAdminModule::WORDPRESS_REGISTRATION_FORM))
|
36 |
+
{
|
37 |
+
$this->activateRegisterHooks();
|
38 |
+
}
|
39 |
+
|
40 |
+
if($this->getOption(GdbcWordPressAdminModule::WORDPRESS_COMMENTS_FORM) !== null)
|
41 |
+
{
|
42 |
+
$this->activateCommentsHooks();
|
43 |
+
}
|
44 |
+
|
45 |
+
if($this->getOption(GdbcWordPressAdminModule::WORDPRESS_LOST_PASSWORD_FORM))
|
46 |
+
{
|
47 |
+
$this->activateLostPasswordHooks();
|
48 |
+
}
|
49 |
+
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
private function activateCommentsHooks()
|
55 |
+
{
|
56 |
+
|
57 |
+
$this->addActionHook('comment_form_after_fields', array($this, 'renderTokenFieldIntoCommentsForm'), 1);
|
58 |
+
|
59 |
+
$this->addActionHook('comment_form_logged_in_after', array($this, 'renderTokenFieldIntoCommentsForm'), 1);
|
60 |
+
|
61 |
+
$this->commentFormActionIndex = $this->addActionHook('comment_form', array($this, 'renderTokenFieldIntoForm'));
|
62 |
+
|
63 |
+
$this->addFilterHook('preprocess_comment', array($this, 'validateCommentsFormEncryptedToken'), 1);
|
64 |
+
|
65 |
+
if(defined('EPOCH_VER'))
|
66 |
+
{
|
67 |
+
$this->addFilterHook('epoch_iframe_scripts', array($this, 'registerEpochGgbcScriptId'));
|
68 |
+
}
|
69 |
+
|
70 |
+
}
|
71 |
+
|
72 |
+
public function registerEpochGgbcScriptId($arrScripts)
|
73 |
+
{
|
74 |
+
if( !is_array($arrScripts))
|
75 |
+
$arrScripts = array();
|
76 |
+
|
77 |
+
$arrScripts[] = 'jquery-core';
|
78 |
+
$arrScripts[] = GoodByeCaptcha::PLUGIN_SLUG . '-public-script';
|
79 |
+
|
80 |
+
return $arrScripts;
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
public function renderTokenFieldIntoCommentsForm()
|
85 |
+
{
|
86 |
+
$this->removeHookByIndex($this->commentFormActionIndex);
|
87 |
+
$this->renderTokenFieldIntoForm();
|
88 |
+
}
|
89 |
+
|
90 |
+
private function activateLoginHooks()
|
91 |
+
{
|
92 |
+
$this->loginFormHookIndex = $this->addActionHook('login_form', array($this, 'renderTokenFieldIntoLoginForm'));
|
93 |
+
$this->loginFormBottomHookIndex = $this->addActionHook('login_form_bottom', array($this, 'getTokenFieldForLoginForm'));
|
94 |
+
|
95 |
+
$this->addFilterHook('wp_authenticate_user', array($this, 'validateLoginUserAuthentication'), 25, 2);
|
96 |
+
$this->addFilterHook('authenticate', array($this, 'validateLoginAuthentication'), 73, 3);
|
97 |
+
|
98 |
+
$this->addActionHook('wp_authenticate', array($this, 'preventBruteForceAuthentication'), 1, 2);
|
99 |
+
|
100 |
+
$this->addActionHook('wp_login_failed', array($this, 'registerXmlRpcFailedLogin'), 1, 1);
|
101 |
+
|
102 |
+
}
|
103 |
+
|
104 |
+
public function registerXmlRpcFailedLogin($userName)
|
105 |
+
{
|
106 |
+
if( ! MchGdbcWpUtils::isXmlRpcRequest() )
|
107 |
+
return;
|
108 |
+
|
109 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName(GdbcWordpressAdminModule::WORDPRESS_LOGIN_XML_RPC);
|
110 |
+
$this->attemptEntity->Notes = array('username' => sanitize_user($userName));
|
111 |
+
|
112 |
+
GdbcBruteGuardian::logRejectedAttempt($this->getAttemptEntity());
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
public function preventBruteForceAuthentication($userName, $password)
|
117 |
+
{
|
118 |
+
if(empty($userName) || GdbcIPUtils::isClientIpWhiteListed())
|
119 |
+
return;
|
120 |
+
|
121 |
+
$validateResponse = $this->validateLoginAuthentication(new WP_Error(), $userName, $password);
|
122 |
+
if( ! is_wp_error($validateResponse) )
|
123 |
+
return;
|
124 |
+
|
125 |
+
if($validateResponse->get_error_code() !== GoodByeCaptcha::PLUGIN_SLUG)
|
126 |
+
return;
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
public function validateLoginUserAuthentication($wpUser, $password)
|
131 |
+
{
|
132 |
+
$userName = isset($wpUser->data->user_login) ? $wpUser->data->user_login : '';
|
133 |
+
|
134 |
+
return $this->validateLoginAuthentication($wpUser, $userName, $password);
|
135 |
+
}
|
136 |
+
|
137 |
+
public function validateLoginAuthentication($wpUser, $userName, $password)
|
138 |
+
{
|
139 |
+
|
140 |
+
if (is_wp_error($wpUser) && in_array($wpUser->get_error_code(), array('empty_username', 'empty_password')) ) {
|
141 |
+
return $wpUser;
|
142 |
+
}
|
143 |
+
|
144 |
+
if(MchGdbcWpUtils::isXmlRpcRequest()) {
|
145 |
+
return $wpUser;
|
146 |
+
}
|
147 |
+
|
148 |
+
$arrSubmittedData = array(
|
149 |
+
'username' => sanitize_user($userName),
|
150 |
+
//'password' => $password
|
151 |
+
);
|
152 |
+
|
153 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName(GdbcWordpressAdminModule::WORDPRESS_LOGIN_FORM);
|
154 |
+
$this->attemptEntity->Notes = $arrSubmittedData;
|
155 |
+
|
156 |
+
return GdbcRequestController::isValid($this->attemptEntity)
|
157 |
+
? $wpUser
|
158 |
+
: new WP_Error(GoodByeCaptcha::PLUGIN_SLUG, __('Invalid username or incorrect password!', GoodByeCaptcha::PLUGIN_SLUG));
|
159 |
+
|
160 |
+
}
|
161 |
+
|
162 |
+
public function renderTokenFieldIntoLoginForm()
|
163 |
+
{
|
164 |
+
$this->renderTokenFieldIntoForm();
|
165 |
+
$this->removeHookByIndex($this->loginFormBottomHookIndex);
|
166 |
+
}
|
167 |
+
|
168 |
+
public function getTokenFieldForLoginForm()
|
169 |
+
{
|
170 |
+
$this->removeHookByIndex($this->loginFormHookIndex);
|
171 |
+
return $this->getTokenFieldHtml();
|
172 |
+
}
|
173 |
+
|
174 |
+
public function activateRegisterHooks()
|
175 |
+
{
|
176 |
+
$this->addActionHook('register_form', array($this, 'renderTokenFieldIntoForm'));
|
177 |
+
$this->addActionHook('signup_extra_fields', array($this, 'renderTokenFieldIntoForm'));
|
178 |
+
|
179 |
+
$this->addFilterHook('registration_errors', array($this, 'validateRegisterFormEncryptedToken'), 10, 3 );
|
180 |
+
$this->addFilterHook('wpmu_validate_user_signup', array($this, 'validateMURegisterFormEncryptedToken'), 10, 1);
|
181 |
+
|
182 |
+
}
|
183 |
+
|
184 |
+
public function validateMURegisterFormEncryptedToken($results)
|
185 |
+
{
|
186 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName(GdbcWordpressAdminModule::WORDPRESS_REGISTRATION_FORM);
|
187 |
+
|
188 |
+
$this->attemptEntity->Notes = array(
|
189 |
+
'username' => !empty($results['user_name']) ? $results['user_name'] : '',
|
190 |
+
'email' => !empty($results['user_email']) ? $results['user_email'] : '',
|
191 |
+
);
|
192 |
+
|
193 |
+
if(GdbcRequestController::isValid($this->attemptEntity))
|
194 |
+
return $results;
|
195 |
+
|
196 |
+
empty($results['errors']) || !is_wp_error($results['errors']) ? $results['errors'] = new WP_Error() : null;
|
197 |
+
|
198 |
+
$results['errors']->add('gdbc-invalid-token', __('Registration Error!', GoodByeCaptcha::PLUGIN_SLUG));
|
199 |
+
|
200 |
+
return $results;
|
201 |
+
}
|
202 |
+
|
203 |
+
public function validateRegisterFormEncryptedToken($wpError, $sanitizedUserName, $userEmail)
|
204 |
+
{
|
205 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName(GdbcWordpressAdminModule::WORDPRESS_REGISTRATION_FORM);
|
206 |
+
$this->attemptEntity->Notes = array(
|
207 |
+
'username' => $sanitizedUserName,
|
208 |
+
'email' => sanitize_email($userEmail)
|
209 |
+
);
|
210 |
+
|
211 |
+
if(GdbcRequestController::isValid($this->attemptEntity))
|
212 |
+
return $wpError;
|
213 |
+
|
214 |
+
!is_wp_error($wpError) ? $wpError = new WP_Error() : null;
|
215 |
+
|
216 |
+
$wpError->add('gdbc-invalid-token', __('Registration Error!', GoodByeCaptcha::PLUGIN_SLUG));
|
217 |
+
|
218 |
+
return $wpError;
|
219 |
+
}
|
220 |
+
|
221 |
+
|
222 |
+
public function activateLostPasswordHooks()
|
223 |
+
{
|
224 |
+
$this->addActionHook('lostpassword_form', array($this, 'renderTokenFieldIntoForm'), 10);
|
225 |
+
$this->addActionHook('lostpassword_post', array($this, 'validateLostPasswordFormEncryptedToken'), 10);
|
226 |
+
}
|
227 |
+
|
228 |
+
|
229 |
+
public function validateLostPasswordFormEncryptedToken()
|
230 |
+
{
|
231 |
+
|
232 |
+
$this->getAttemptEntity()->SectionId = $this->getOptionIdByOptionName(GdbcWordpressAdminModule::WORDPRESS_LOST_PASSWORD_FORM);
|
233 |
+
|
234 |
+
$userName = !empty($_POST['user_login']) ? $_POST['user_login'] : '';
|
235 |
+
|
236 |
+
if(!empty($userName))
|
237 |
+
{
|
238 |
+
$userName = (strpos($userName, '@') === false) ? sanitize_user($userName) : sanitize_email($userName);
|
239 |
+
}
|
240 |
+
|
241 |
+
$this->getAttemptEntity()->Notes = array('username' => $userName);
|
242 |
+
|
243 |
+
if(GdbcRequestController::isValid($this->getAttemptEntity()))
|
244 |
+
return;
|
245 |
+
|
246 |
+
wp_safe_redirect(wp_login_url());
|
247 |
+
|
248 |
+
exit;
|
249 |
+
}
|
250 |
+
|
251 |
+
|
252 |
+
public function validateCommentsFormEncryptedToken($arrComment)
|
253 |
+
{
|
254 |
+
|
255 |
+
$arrWordPressCommentsType = array('comment' => 1, 'pingback' => 1, 'trackback' => 1);
|
256 |
+
|
257 |
+
if( is_admin() || ( !empty($arrComment['comment_type']) && !isset($arrWordPressCommentsType[strtolower($arrComment['comment_type'])]) ) )
|
258 |
+
return $arrComment;
|
259 |
+
|
260 |
+
$arrComment['comment_post_ID'] = (!empty($arrComment['comment_post_ID']) && is_numeric($arrComment['comment_post_ID'])) ? (int)$arrComment['comment_post_ID'] : 0;
|
261 |
+
|
262 |
+
if(0 === $arrComment['comment_post_ID']) {
|
263 |
+
wp_safe_redirect(home_url('/'));exit;
|
264 |
+
}
|
265 |
+
|
266 |
+
if(!array_key_exists(get_post_type($arrComment['comment_post_ID']), get_post_types( array('public' => true, '_builtin' => true)) ))
|
267 |
+
{
|
268 |
+
return $arrComment; // not a regular wordpress post
|
269 |
+
}
|
270 |
+
|
271 |
+
|
272 |
+
$this->getAttemptEntity()->SectionId = $this->getOptionIdByOptionName(GdbcWordpressAdminModule::WORDPRESS_COMMENTS_FORM);
|
273 |
+
$this->getAttemptEntity()->Notes = array_filter($arrComment);
|
274 |
+
|
275 |
+
unset(
|
276 |
+
$this->attemptEntity->Notes['user_ID']
|
277 |
+
);
|
278 |
+
|
279 |
+
|
280 |
+
if( GdbcRequestController::isValid($this->getAttemptEntity()) )
|
281 |
+
return $arrComment;
|
282 |
+
|
283 |
+
|
284 |
+
$postPermaLink = get_permalink($arrComment['comment_post_ID']);
|
285 |
+
|
286 |
+
empty($postPermaLink) ? wp_safe_redirect(home_url('/')) : wp_safe_redirect($postPermaLink);
|
287 |
+
|
288 |
+
exit;
|
289 |
+
|
290 |
+
// if(null !== GoodByeCaptcha::getModulesControllerInstance()->getModuleSettingOption(GdbcModulesController::MODULE_WORDPRESS, GdbcWordpressAdminModule::STORE_SPAM_ATTEMPTS))
|
291 |
+
// {
|
292 |
+
// $arrComment['comment_approved'] = 'spam';
|
293 |
+
// wp_insert_comment($arrComment);
|
294 |
+
//
|
295 |
+
// return $arrComment;
|
296 |
+
// }
|
297 |
+
|
298 |
+
}
|
299 |
+
|
300 |
+
|
301 |
+
public static function getInstance()
|
302 |
+
{
|
303 |
+
static $publicInstance = null;
|
304 |
+
return null !== $publicInstance ? $publicInstance : $publicInstance = new self();
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* @return int
|
309 |
+
*/
|
310 |
+
protected function getModuleId()
|
311 |
+
{
|
312 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_WORDPRESS);
|
313 |
+
}
|
314 |
+
}
|
{engine → 2.0/engine}/modules/zm-ajax-login-register/GdbcZmAlrAdminModule.php
RENAMED
File without changes
|
2.0/engine/modules/zm-ajax-login-register/GdbcZmAlrPublicModule.php
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class GdbcZmAlrPublicModule extends GdbcBasePublicModule
|
22 |
+
{
|
23 |
+
private $arrStatusLoginError = null;
|
24 |
+
private $arrStatusRegisterError = null;
|
25 |
+
|
26 |
+
private $arrCapturedData = null;
|
27 |
+
protected function __construct()
|
28 |
+
{
|
29 |
+
parent::__construct();
|
30 |
+
|
31 |
+
if(!GoodByeCaptchaUtils::isZmAlrActivated())
|
32 |
+
return;
|
33 |
+
|
34 |
+
$this->arrCapturedData = array();
|
35 |
+
|
36 |
+
$this->arrStatusLoginError = array('gdbc-login-error' => array(
|
37 |
+
'description' => __('Invalid username or password!', GoodByeCaptcha::PLUGIN_SLUG),
|
38 |
+
'cssClass' => 'error-container',
|
39 |
+
'code' => 'show_notice'
|
40 |
+
));
|
41 |
+
|
42 |
+
$this->arrStatusRegisterError = array('gdbc-register-error' => array(
|
43 |
+
'description' => __('An error occurred while registering your account!', GoodByeCaptcha::PLUGIN_SLUG),
|
44 |
+
'cssClass' => 'error-container',
|
45 |
+
'code' => 'show_notice'
|
46 |
+
));
|
47 |
+
|
48 |
+
|
49 |
+
if($this->getOption(GdbcZmAlrAdminModule::OPTION_ZM_ALR_LOGIN_FORM)){
|
50 |
+
$this->registerLoginHooks();
|
51 |
+
}
|
52 |
+
|
53 |
+
if($this->getOption(GdbcZmAlrAdminModule::OPTION_ZM_ALR_REGISTER_FORM)){
|
54 |
+
$this->registerRegistrationHooks();
|
55 |
+
}
|
56 |
+
|
57 |
+
add_filter('zm_alr_status_codes', array($this, 'registerGdbcStatusCode'), 10, 1);
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
public function registerGdbcStatusCode($arrStatusCode)
|
62 |
+
{
|
63 |
+
$arrStatusCode = (array)$arrStatusCode;
|
64 |
+
$arrStatusCode[key($this->arrStatusLoginError)] = reset($this->arrStatusLoginError);
|
65 |
+
$arrStatusCode[key($this->arrStatusRegisterError)] = reset($this->arrStatusRegisterError);
|
66 |
+
|
67 |
+
return $arrStatusCode;
|
68 |
+
}
|
69 |
+
|
70 |
+
private function registerLoginHooks()
|
71 |
+
{
|
72 |
+
$this->addFilterHook('zm_alr_login_above_fields', array($this, 'renderHiddenFieldIntoForm'), 99, 1);
|
73 |
+
$this->addFilterHook('zm_alr_login_form_params' , array($this, 'captureSubmittedData'), 1, 1);
|
74 |
+
|
75 |
+
$this->addFilterHook('zm_alr_login_submit_pre_status_error' , array($this, 'validateLoginRequest'), 1, 1);
|
76 |
+
|
77 |
+
}
|
78 |
+
|
79 |
+
public function registerRegistrationHooks()
|
80 |
+
{
|
81 |
+
$this->addFilterHook('zm_alr_register_above_fields', array($this, 'renderHiddenFieldIntoForm'), 99, 1);
|
82 |
+
$this->addFilterHook('zm_alr_register_setup_new_user_args' , array($this, 'captureSubmittedData'), 1, 1);
|
83 |
+
|
84 |
+
$this->addFilterHook('zm_alr_register_submit_pre_status_error' , array($this, 'validateRegisterRequest'), 1, 1);
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
public function validateLoginRequest($preStatus)
|
89 |
+
{
|
90 |
+
$this->attemptEntity->Notes = $this->arrCapturedData;
|
91 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName(GdbcZmAlrAdminModule::OPTION_ZM_ALR_LOGIN_FORM);
|
92 |
+
|
93 |
+
|
94 |
+
if(GdbcRequestController::isValid($this->attemptEntity))
|
95 |
+
return $preStatus;
|
96 |
+
|
97 |
+
reset($this->arrStatusLoginError);
|
98 |
+
return key($this->arrStatusLoginError);
|
99 |
+
}
|
100 |
+
|
101 |
+
public function validateRegisterRequest($preStatus)
|
102 |
+
{
|
103 |
+
$this->attemptEntity->Notes = $this->arrCapturedData;
|
104 |
+
$this->attemptEntity->SectionId = $this->getOptionIdByOptionName(GdbcZmAlrAdminModule::OPTION_ZM_ALR_REGISTER_FORM);
|
105 |
+
|
106 |
+
if(GdbcRequestController::isValid($this->attemptEntity))
|
107 |
+
return $preStatus;
|
108 |
+
|
109 |
+
reset($this->arrStatusRegisterError);
|
110 |
+
return key($this->arrStatusRegisterError);
|
111 |
+
}
|
112 |
+
|
113 |
+
|
114 |
+
public function captureSubmittedData($arrSubmittedData)
|
115 |
+
{
|
116 |
+
$this->arrCapturedData['username'] = isset($arrSubmittedData['user_login']) ? sanitize_user($arrSubmittedData['user_login']) : null;
|
117 |
+
$this->arrCapturedData['email'] = isset($arrSubmittedData['email']) ? sanitize_email($arrSubmittedData['email']) : null;
|
118 |
+
if(null === $this->arrCapturedData['email'])
|
119 |
+
unset($this->arrCapturedData['email']);
|
120 |
+
|
121 |
+
return $arrSubmittedData;
|
122 |
+
}
|
123 |
+
|
124 |
+
public function renderHiddenFieldIntoForm($aboveFieldsHtml)
|
125 |
+
{
|
126 |
+
$aboveFieldsHtml .= $this->getTokenFieldHtml();
|
127 |
+
|
128 |
+
if( ! MchGdbcWpUtils::isAjaxRequest() )
|
129 |
+
return $aboveFieldsHtml;
|
130 |
+
|
131 |
+
return '<script type="text/javascript">(new jQuery.GdbcClient()).requestTokens();</script>' . $aboveFieldsHtml;
|
132 |
+
}
|
133 |
+
|
134 |
+
|
135 |
+
/**
|
136 |
+
* @return int
|
137 |
+
*/
|
138 |
+
protected function getModuleId()
|
139 |
+
{
|
140 |
+
return GdbcModulesController::getModuleIdByName(GdbcModulesController::MODULE_ZM_ALR);
|
141 |
+
}
|
142 |
+
|
143 |
+
public static function getInstance()
|
144 |
+
{
|
145 |
+
static $adminInstance = null;
|
146 |
+
return null !== $adminInstance ? $adminInstance : $adminInstance = new self();
|
147 |
+
}
|
148 |
+
|
149 |
+
}
|
{engine → 2.0/engine}/tasks/GdbcCheckAttemptsTask.php
RENAMED
File without changes
|
{engine → 2.0/engine}/tasks/GdbcLogsCleanerTask.php
RENAMED
File without changes
|
2.0/goodbye-captcha.php
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package GoodBye Captcha
|
5 |
+
* @author Mihai Chelaru
|
6 |
+
* @license GPL-2.0+
|
7 |
+
* @link http://www.goodbyecaptcha.com
|
8 |
+
* @copyright 2015 GoodBye Captcha
|
9 |
+
*
|
10 |
+
* @wordpress-plugin
|
11 |
+
* Plugin Name: GoodBye Captcha
|
12 |
+
* Plugin URI: http://www.goodbyecaptcha.com
|
13 |
+
* Description: An extremely powerful anti-spam plugin that blocks spambots without annoying captcha images.
|
14 |
+
* Version: 2.0
|
15 |
+
* Author: Mihai Chelaru
|
16 |
+
* Author URI: http://www.goodbyecaptcha.com
|
17 |
+
* Text Domain: goodbye-captcha
|
18 |
+
* License: GPL-2.0+
|
19 |
+
* Domain Path: /languages
|
20 |
+
*/
|
21 |
+
|
22 |
+
class GoodByeCaptcha
|
23 |
+
{
|
24 |
+
CONST PLUGIN_VERSION = '2.0';
|
25 |
+
CONST PLUGIN_SHORT_CODE = 'gdbc';
|
26 |
+
CONST PLUGIN_SLUG = 'goodbye-captcha';
|
27 |
+
CONST PLUGIN_SITE_URL = 'http://www.goodbyecaptcha.com';
|
28 |
+
CONST PLUGIN_MAIN_FILE = __FILE__;
|
29 |
+
|
30 |
+
private static $arrPluginInfo = array(
|
31 |
+
|
32 |
+
'PLUGIN_DOMAIN_PATH' => 'languages',
|
33 |
+
'PLUGIN_MAIN_FILE' => self::PLUGIN_MAIN_FILE,
|
34 |
+
'PLUGIN_SHORT_CODE' => self::PLUGIN_SHORT_CODE,
|
35 |
+
'PLUGIN_VERSION' => self::PLUGIN_VERSION,
|
36 |
+
'PLUGIN_SLUG' => self::PLUGIN_SLUG,
|
37 |
+
|
38 |
+
);
|
39 |
+
|
40 |
+
private static $arrClassMap = array(
|
41 |
+
|
42 |
+
'GoodByeCaptchaPublic' => '/engine/GoodByeCaptchaPublic.php',
|
43 |
+
'GoodByeCaptchaAdmin' => '/engine/GoodByeCaptchaAdmin.php',
|
44 |
+
'GdbcAjaxController' => '/engine/GdbcAjaxController.php',
|
45 |
+
'GoodByeCaptchaUtils' => '/engine/GoodByeCaptchaUtils.php',
|
46 |
+
'GdbcRequestController' => '/engine/GdbcRequestController.php',
|
47 |
+
'GdbcIPUtils' => '/engine/GdbcIPUtils.php',
|
48 |
+
'GdbcUpdatesController' => '/engine/GdbcUpdatesController.php',
|
49 |
+
'GdbcModulesController' => '/engine/GdbcModulesController.php',
|
50 |
+
'GdbcBaseAdminModule' => '/engine/modules/GdbcBaseAdminModule.php',
|
51 |
+
'GdbcBasePublicModule' => '/engine/modules/GdbcBasePublicModule.php',
|
52 |
+
|
53 |
+
'GdbcBaseAdminPage' => '/engine/admin/pages/GdbcBaseAdminPage.php',
|
54 |
+
'GdbcContactFormsAdminPage' => '/engine/admin/pages/GdbcContactFormsAdminPage.php',
|
55 |
+
'GdbcSettingsAdminPage' => '/engine/admin/pages/GdbcSettingsAdminPage.php',
|
56 |
+
'GdbcWordpressAdminPage' => '/engine/admin/pages/GdbcWordpressAdminPage.php',
|
57 |
+
'GdbcNotificationsAdminPage' => '/engine/admin/pages/GdbcNotificationsAdminPage.php',
|
58 |
+
'GdbcMembershipAdminPage' => '/engine/admin/pages/GdbcMembershipAdminPage.php',
|
59 |
+
'GdbcSecurityAdminPage' => '/engine/admin/pages/GdbcSecurityAdminPage.php',
|
60 |
+
'GdbcOthersAdminPage' => '/engine/admin/pages/GdbcOthersAdminPage.php',
|
61 |
+
'GdbcReportsAdminPage' => '/engine/admin/pages/GdbcReportsAdminPage.php',
|
62 |
+
'GdbcAdminNotice' => '/engine/admin/GdbcAdminNotice.php',
|
63 |
+
|
64 |
+
'GdbcDbAccessController' => '/engine/db-access/GdbcDbAccessController.php',
|
65 |
+
'GdbcBruteGuardian' => '/engine/GdbcBruteGuardian.php',
|
66 |
+
'GdbcAttemptEntity' => '/engine/entities/GdbcAttemptEntity.php',
|
67 |
+
'GdbcNotificationsController' => '/engine/GdbcNotificationsController.php',
|
68 |
+
'GdbcLogsCleanerTask' => '/engine/tasks/GdbcLogsCleanerTask.php',
|
69 |
+
'GdbcTaskScheduler' => '/engine/GdbcTaskScheduler.php',
|
70 |
+
|
71 |
+
);
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
protected function __construct()
|
76 |
+
{
|
77 |
+
GdbcUpdatesController::updateToCurrentVersion();
|
78 |
+
|
79 |
+
if(MchGdbcWpUtils::isAjaxRequest()) {
|
80 |
+
GdbcAjaxController::processRequest();
|
81 |
+
}
|
82 |
+
elseif(MchGdbcWpUtils::isUserInDashboard()){
|
83 |
+
GoodByeCaptchaAdmin::getInstance(self::$arrPluginInfo);
|
84 |
+
}
|
85 |
+
else{
|
86 |
+
GoodByeCaptchaPublic::getInstance(self::$arrPluginInfo);
|
87 |
+
}
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
public static function classAutoLoad($className)
|
92 |
+
{
|
93 |
+
if( !isset(self::$arrClassMap[$className]) )
|
94 |
+
return null;
|
95 |
+
|
96 |
+
$filePath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . trim(self::$arrClassMap[$className], '/\\');
|
97 |
+
|
98 |
+
return file_exists($filePath) ? include $filePath : null;
|
99 |
+
}
|
100 |
+
|
101 |
+
public static function isNetworkActivated()
|
102 |
+
{
|
103 |
+
static $isNetworkActivated = null;
|
104 |
+
return null !== $isNetworkActivated ? $isNetworkActivated : $isNetworkActivated = MchGdbcWpUtils::isPluginNetworkActivated(self::PLUGIN_MAIN_FILE);
|
105 |
+
}
|
106 |
+
|
107 |
+
public static function getInstance()
|
108 |
+
{
|
109 |
+
static $gdbcInstance = null;
|
110 |
+
return (null !== $gdbcInstance) ? $gdbcInstance : $gdbcInstance = new self();
|
111 |
+
}
|
112 |
+
|
113 |
+
public static function activate()
|
114 |
+
{
|
115 |
+
GoodByeCaptchaAdmin::onPluginActivate();
|
116 |
+
}
|
117 |
+
|
118 |
+
public static function deactivate($isForNetwork)
|
119 |
+
{}
|
120 |
+
|
121 |
+
}
|
122 |
+
|
123 |
+
require_once dirname( __FILE__ ) . '/includes/MchGdbcLibAutoloader.php';
|
124 |
+
|
125 |
+
spl_autoload_register( array( 'GoodByeCaptcha', 'classAutoLoad' ), false);
|
126 |
+
|
127 |
+
GdbcIPUtils::getClientIpAddress();
|
128 |
+
|
129 |
+
if(!empty($_GET['gdbc-client']) && file_exists(dirname(__FILE__) . '/assets/public/scripts/gdbc-client.js.php'))
|
130 |
+
{
|
131 |
+
require_once(ABSPATH .'wp-includes/pluggable.php');
|
132 |
+
( !defined('LOGGED_IN_COOKIE') && function_exists('wp_cookie_constants') ) ? wp_cookie_constants() : null;
|
133 |
+
require dirname( __FILE__ ) . '/assets/public/scripts/gdbc-client.js.php';
|
134 |
+
exit;
|
135 |
+
}
|
136 |
+
|
137 |
+
|
138 |
+
if( defined('ABSPATH') )
|
139 |
+
{
|
140 |
+
if (MchGdbcWpUtils::isAjaxRequest()) {
|
141 |
+
GdbcAjaxController::processRequest();
|
142 |
+
}
|
143 |
+
|
144 |
+
GdbcBruteGuardian::startGuarding();
|
145 |
+
|
146 |
+
register_activation_hook(__FILE__, array('GoodByeCaptcha', 'activate'));
|
147 |
+
|
148 |
+
register_deactivation_hook(__FILE__, array('GoodByeCaptcha', 'deactivate'));
|
149 |
+
|
150 |
+
add_action('plugins_loaded', array('GoodByeCaptcha', 'getInstance'), 0);
|
151 |
+
}
|
2.0/includes/MchGdbcLibAutoloader.php
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
/*
|
22 |
+
* REMOVE MchWp class after 2.0 release
|
23 |
+
*/
|
24 |
+
//class MchWp
|
25 |
+
//{
|
26 |
+
// public static function isUserInDashboad(){return false;}
|
27 |
+
//}
|
28 |
+
|
29 |
+
if (!defined('PHP_VERSION_ID'))
|
30 |
+
{
|
31 |
+
$version = explode('.', PHP_VERSION);
|
32 |
+
|
33 |
+
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
|
34 |
+
|
35 |
+
unset($version);
|
36 |
+
}
|
37 |
+
|
38 |
+
(PHP_VERSION_ID < 50300)
|
39 |
+
? spl_autoload_register( array( 'MchGdbcLibAutoloader', 'autoLoadLibraryClasses' ), false)
|
40 |
+
: spl_autoload_register( array( 'MchGdbcLibAutoloader', 'autoLoadLibraryClasses' ), false, true );
|
41 |
+
|
42 |
+
final class MchGdbcLibAutoloader
|
43 |
+
{
|
44 |
+
public static function autoLoadLibraryClasses($className)
|
45 |
+
{
|
46 |
+
static $arrClassMap = null;
|
47 |
+
if(null === $arrClassMap) {
|
48 |
+
|
49 |
+
$arrClassMap = array(
|
50 |
+
|
51 |
+
'MchGdbcBaseModule' => '/modules/MchGdbcBaseModule.php',
|
52 |
+
'MchGdbcBasePublicModule' => '/modules/MchGdbcBasePublicModule.php',
|
53 |
+
'MchGdbcBaseAdminModule' => '/modules/MchGdbcBaseAdminModule.php',
|
54 |
+
'MchGdbcGroupedModules' => '/modules/MchGdbcGroupedModules.php',
|
55 |
+
|
56 |
+
'MchGdbcBasePlugin' => '/plugin/MchGdbcBasePlugin.php',
|
57 |
+
'MchGdbcBaseAdminPlugin' => '/plugin/MchGdbcBaseAdminPlugin.php',
|
58 |
+
'MchGdbcBasePublicPlugin' => '/plugin/MchGdbcBasePublicPlugin.php',
|
59 |
+
'MchGdbcBaseAdminPage' => '/plugin/MchGdbcBaseAdminPage.php',
|
60 |
+
|
61 |
+
'MchGdbcUtils' => '/utils/MchGdbcUtils.php',
|
62 |
+
'MchGdbcWpUtils' => '/utils/MchGdbcWpUtils.php',
|
63 |
+
'MchGdbcHtmlUtils' => '/utils/MchGdbcHtmlUtils.php',
|
64 |
+
'MchGdbcIPUtils' => '/utils/MchGdbcIPUtils.php',
|
65 |
+
|
66 |
+
'MchCrypt' => '/vendor/MchCrypt/MchCrypt.php',
|
67 |
+
'Crypt_Blowfish' => '/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Blowfish.php',
|
68 |
+
'Math_BigInteger' => '/vendor/MchCrypt/PhpSecLib-0.3.10/Math/BigInteger.php',
|
69 |
+
|
70 |
+
'MchGdbcHttpRequest' => '/vendor/MchHttp/MchGdbcHttpRequest.php',
|
71 |
+
'MchGdbcTrustedIPRanges' =>'/vendor/MchHttp/MchGdbcTrustedIPRanges.php',
|
72 |
+
'MchGdbcUnTrustedIPRanges' =>'/vendor/MchHttp/MchGdbcUnTrustedIPRanges.php',
|
73 |
+
|
74 |
+
'MchGdbcHttpUtil' => '/vendor/MchHttp/MchGdbcHttpUtil.php',
|
75 |
+
'MchMaxMindGeoIp' => '/vendor/MaxMind/MchMaxMindGeoIp.php',
|
76 |
+
|
77 |
+
'MchGdbcCache' => '/vendor/MchCache/MchGdbcCache.php',
|
78 |
+
'MchGdbcCacheFileStorage' => '/vendor/MchCache/Storage/MchGdbcCacheFileStorage.php',
|
79 |
+
'MchGdbcWordPressTransientsStorage' => '/vendor/MchCache/Storage/MchGdbcWordPressTransientsStorage.php',
|
80 |
+
'MchGdbcCacheAPCUStorage' => '/vendor/MchCache/Storage/MchGdbcCacheAPCUStorage.php',
|
81 |
+
'MchGdbcCacheAPCStorage' => '/vendor/MchCache/Storage/MchGdbcCacheAPCStorage.php',
|
82 |
+
'MchGdbcCacheXCacheStorage' => '/vendor/MchCache/Storage/MchGdbcCacheXCacheStorage.php',
|
83 |
+
'MchGdbcCacheZendMemoryStorage' => '/vendor/MchCache/Storage/MchGdbcCacheZendMemoryStorage.php',
|
84 |
+
'MchGdbcCacheZendDiskStorage' => '/vendor/MchCache/Storage/MchGdbcCacheZendDiskStorage.php',
|
85 |
+
|
86 |
+
'MchGdbcCacheBaseStorage' => '/vendor/MchCache/Storage/MchGdbcCacheBaseStorage.php',
|
87 |
+
|
88 |
+
|
89 |
+
'MchGdbcWpTaskScheduler' => '/task-scheduler/MchGdbcWpTaskScheduler.php',
|
90 |
+
'MchGdbcWpTask' => '/task-scheduler/MchGdbcWpTask.php',
|
91 |
+
'MchGdbcAdminNotice' => '/notices/MchGdbcAdminNotice.php',
|
92 |
+
|
93 |
+
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
return isset($arrClassMap[$className]) ? file_exists($filePath = dirname(__FILE__) . $arrClassMap[$className])
|
98 |
+
? include ($filePath)
|
99 |
+
: null
|
100 |
+
: null;
|
101 |
+
}
|
102 |
+
|
103 |
+
private function __clone()
|
104 |
+
{}
|
105 |
+
|
106 |
+
private function __construct()
|
107 |
+
{}
|
108 |
+
|
109 |
+
}
|
2.0/includes/modules/MchGdbcBaseAdminModule.php
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class MchGdbcBaseAdminModule extends MchGdbcBaseModule
|
21 |
+
{
|
22 |
+
private $arrDefaultOptionsValues = array();
|
23 |
+
private $arrRegisteredMessages = array();
|
24 |
+
|
25 |
+
|
26 |
+
public abstract function getDefaultOptions();
|
27 |
+
public abstract function validateModuleSettingsFields($arrOptions);
|
28 |
+
|
29 |
+
protected function __construct()
|
30 |
+
{
|
31 |
+
parent::__construct();
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
public function getSettingKey()
|
36 |
+
{
|
37 |
+
return $this->moduleSettingsKey;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getDefaultOptionsValues()
|
41 |
+
{
|
42 |
+
if(empty($this->arrDefaultOptionsValues))
|
43 |
+
{
|
44 |
+
foreach((array)$this->getDefaultOptions() as $optionName => $arrOptionInfo)
|
45 |
+
{
|
46 |
+
$this->arrDefaultOptionsValues[$optionName] = isset($arrOptionInfo['Value']) ? $arrOptionInfo['Value'] : null;
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
return $this->arrDefaultOptionsValues;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function saveNetworkSettingOptions(array $arrSettingOptions)
|
54 |
+
{
|
55 |
+
$this->isUsedNetworkWide = true;
|
56 |
+
$arrSettingOptions = $this->validateModuleSettingsFields($arrSettingOptions);
|
57 |
+
|
58 |
+
remove_filter('sanitize_option_' . $this->getSettingKey(), array($this, 'validateModuleSettingsFields'));
|
59 |
+
|
60 |
+
update_site_option($this->getSettingKey(), $arrSettingOptions);
|
61 |
+
|
62 |
+
wp_safe_redirect(add_query_arg('updated', '1'));
|
63 |
+
}
|
64 |
+
|
65 |
+
public function saveOption($optionName, $optionValue, $asNetworkOption)
|
66 |
+
{
|
67 |
+
$this->isUsedNetworkWide = !!$asNetworkOption;
|
68 |
+
$arrSavedOptions = $this->getAllSavedOptions($asNetworkOption);
|
69 |
+
|
70 |
+
$arrSavedOptions[$optionName] = $optionValue;
|
71 |
+
|
72 |
+
return ($this->isUsedNetworkWide) ? update_site_option($this->moduleSettingsKey, $arrSavedOptions) : update_option($this->moduleSettingsKey, $arrSavedOptions);
|
73 |
+
}
|
74 |
+
|
75 |
+
public function deleteOption($optionName, $asNetworkOption)
|
76 |
+
{
|
77 |
+
$this->isUsedNetworkWide = !!$asNetworkOption;
|
78 |
+
$arrSavedOptions = $this->getAllSavedOptions($this->isUsedNetworkWide);
|
79 |
+
|
80 |
+
unset($arrSavedOptions[$optionName]);
|
81 |
+
|
82 |
+
return ($this->isUsedNetworkWide) ? update_site_option($this->moduleSettingsKey, $arrSavedOptions) : update_option($this->moduleSettingsKey, $arrSavedOptions);
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
public function deleteAllSettingOptions($asNetworkOption)
|
87 |
+
{
|
88 |
+
$this->isUsedNetworkWide = !!$asNetworkOption;
|
89 |
+
return ($this->isUsedNetworkWide) ? delete_site_option($this->moduleSettingsKey) : delete_option($this->moduleSettingsKey);
|
90 |
+
}
|
91 |
+
|
92 |
+
protected function registerErrorMessage($messageToDisplay)
|
93 |
+
{
|
94 |
+
$this->registerAdminMessage('ErrorMessage', $messageToDisplay);
|
95 |
+
//add_settings_error($this->getSettingKey(), $this->getSettingKey(), $messageToDisplay, 'error');
|
96 |
+
}
|
97 |
+
|
98 |
+
protected function registerSuccessMessage($messageToDisplay)
|
99 |
+
{
|
100 |
+
$this->registerAdminMessage('SuccessMessage', $messageToDisplay);
|
101 |
+
|
102 |
+
//add_settings_error($this->getSettingKey(), $this->getSettingKey(), $messageToDisplay, 'updated');
|
103 |
+
}
|
104 |
+
|
105 |
+
protected function registerWarningMessage($messageToDisplay)
|
106 |
+
{
|
107 |
+
$this->registerAdminMessage('WarningMessage', $messageToDisplay);
|
108 |
+
}
|
109 |
+
|
110 |
+
private function registerAdminMessage($messageType, $message)
|
111 |
+
{
|
112 |
+
$this->arrRegisteredMessages[$messageType] = $message;
|
113 |
+
}
|
114 |
+
|
115 |
+
public function getFormattedMessagesForDisplay()
|
116 |
+
{
|
117 |
+
$arrSavedOptions = $this->getAllSavedOptions($this->isUsedNetworkWide);
|
118 |
+
|
119 |
+
|
120 |
+
$htmlCode = '<div class = "mch-settings-message" style = "{holder-style}"><h3 style = "margin-bottom: 5px;">{message}</h3></div>';
|
121 |
+
|
122 |
+
$arrMessageType = array(
|
123 |
+
'ErrorMessage' => array(
|
124 |
+
'border-left:' => '4px solid #ce4844',
|
125 |
+
'background:' => '#f2dede'
|
126 |
+
),
|
127 |
+
|
128 |
+
'SuccessMessage' => array(
|
129 |
+
'border-left:' => '4px solid #7ad03a',
|
130 |
+
'background:' => '#dff0d8'
|
131 |
+
),
|
132 |
+
|
133 |
+
'WarningMessage' => array(
|
134 |
+
'border-left:' => '4px solid #ffba00',
|
135 |
+
'background:' => '#fcf8e3'
|
136 |
+
),
|
137 |
+
);
|
138 |
+
|
139 |
+
foreach($arrMessageType as $messageType => $arrStyleInfo)
|
140 |
+
{
|
141 |
+
if(empty($arrSavedOptions[$messageType]))
|
142 |
+
continue;
|
143 |
+
|
144 |
+
$holderStyle = '';
|
145 |
+
foreach($arrStyleInfo as $styleKey => $value)
|
146 |
+
$holderStyle .= $styleKey . $value . ';';
|
147 |
+
|
148 |
+
$htmlCode = str_replace(array('{holder-style}', '{message}'), array($holderStyle, wp_filter_kses($arrSavedOptions[$messageType])), $htmlCode);
|
149 |
+
return $htmlCode;
|
150 |
+
}
|
151 |
+
|
152 |
+
return null;
|
153 |
+
|
154 |
+
}
|
155 |
+
|
156 |
+
public function saveRegisteredAdminMessages()
|
157 |
+
{
|
158 |
+
|
159 |
+
$arrSavedOptions = $this->getAllSavedOptions($this->isUsedNetworkWide);
|
160 |
+
$shouldUpdateOptions = !empty($this->arrRegisteredMessages);
|
161 |
+
|
162 |
+
foreach(array('ErrorMessage', 'SuccessMessage', 'WarningMessage') as $messageType)
|
163 |
+
{
|
164 |
+
$shouldUpdateOptions = (true === $shouldUpdateOptions) ? true : isset($arrSavedOptions[$messageType]);
|
165 |
+
unset($arrSavedOptions[$messageType]);
|
166 |
+
}
|
167 |
+
|
168 |
+
// print_r($arrSavedOptions);
|
169 |
+
// return;
|
170 |
+
|
171 |
+
|
172 |
+
if(!$shouldUpdateOptions)
|
173 |
+
return;
|
174 |
+
|
175 |
+
foreach($this->arrRegisteredMessages as $messageType => $message)
|
176 |
+
{
|
177 |
+
$arrSavedOptions[$messageType] = $message;
|
178 |
+
}
|
179 |
+
|
180 |
+
$this->isUsedNetworkWide ? update_site_option($this->moduleSettingsKey, $arrSavedOptions) : update_option($this->moduleSettingsKey, $arrSavedOptions);
|
181 |
+
}
|
182 |
+
|
183 |
+
}
|
2.0/includes/modules/MchGdbcBaseModule.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class MchGdbcBaseModule
|
21 |
+
{
|
22 |
+
|
23 |
+
protected $arrRegisteredHooks = null;
|
24 |
+
protected $moduleSettingsKey = null;
|
25 |
+
protected $isUsedNetworkWide = false;
|
26 |
+
|
27 |
+
protected function __construct()
|
28 |
+
{
|
29 |
+
$this->moduleSettingsKey = str_replace(array('adminmodule', 'publicmodule'), '', MchGdbcUtils::replaceNonAlphaNumericCharacters(strtolower(get_class($this)), '-'));
|
30 |
+
$this->moduleSettingsKey .= '-settings';
|
31 |
+
|
32 |
+
$this->arrRegisteredHooks = array(1 => array(), 2 => array()); // 1 - key for actions, 2 - key for filters
|
33 |
+
}
|
34 |
+
|
35 |
+
protected function getAllSavedOptions($asNetworkOption)
|
36 |
+
{
|
37 |
+
$this->isUsedNetworkWide = (!!$asNetworkOption);
|
38 |
+
return ($this->isUsedNetworkWide) ? (array)get_site_option($this->moduleSettingsKey, array()) : (array)get_option($this->moduleSettingsKey, array());
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getOption($optionName, $asNetworkOption = true)
|
42 |
+
{
|
43 |
+
$arrAllSavedOptions = $this->getAllSavedOptions($asNetworkOption);
|
44 |
+
return isset($arrAllSavedOptions[$optionName]) ? $arrAllSavedOptions[$optionName] : null;
|
45 |
+
}
|
46 |
+
|
47 |
+
public function addActionHook($actionName, array $arrCallback, $priority = 10, $numberOfArgumentsToPass = 1)
|
48 |
+
{
|
49 |
+
return $this->addHook(1, $actionName, $arrCallback, $priority, $numberOfArgumentsToPass);
|
50 |
+
}
|
51 |
+
|
52 |
+
public function addFilterHook($filterName, array $arrCallback, $priority = 10, $numberOfArgumentsToPass = 1)
|
53 |
+
{
|
54 |
+
return $this->addHook(2, $filterName, $arrCallback, $priority, $numberOfArgumentsToPass);
|
55 |
+
}
|
56 |
+
|
57 |
+
private function addHook($hookType, $hookName, array $arrCallback, $priority, $numberOfArgumentsToPass)
|
58 |
+
{
|
59 |
+
if(1 !== $hookType && 2 !== $hookType)
|
60 |
+
return;
|
61 |
+
|
62 |
+
static $hookCounter = 0;
|
63 |
+
++$hookCounter;
|
64 |
+
$hookIndex = (1 === $hookType) ? 'a_' : 'f_';
|
65 |
+
$hookIndex .= "$hookCounter-$hookType-$hookName-$priority-$numberOfArgumentsToPass";
|
66 |
+
|
67 |
+
$this->arrRegisteredHooks[$hookType][$hookIndex] = array($hookName, $arrCallback, $priority, $numberOfArgumentsToPass);
|
68 |
+
|
69 |
+
return $hookIndex;
|
70 |
+
}
|
71 |
+
|
72 |
+
public function removeHookByIndex($hookIndex)
|
73 |
+
{
|
74 |
+
foreach($this->arrRegisteredHooks as $hookType => $arrIndexedHooks)
|
75 |
+
{
|
76 |
+
if(!isset($arrIndexedHooks[$hookIndex][3]))
|
77 |
+
continue;
|
78 |
+
|
79 |
+
(1 === $hookType) //hookName , $arrCallBack , $priority , $numberOfArguments
|
80 |
+
? remove_action($arrIndexedHooks[$hookIndex][0], $arrIndexedHooks[$hookIndex][1], $arrIndexedHooks[$hookIndex][2], $arrIndexedHooks[$hookIndex][3])
|
81 |
+
: remove_filter($arrIndexedHooks[$hookIndex][0], $arrIndexedHooks[$hookIndex][1], $arrIndexedHooks[$hookIndex][2], $arrIndexedHooks[$hookIndex][3]);
|
82 |
+
|
83 |
+
unset($this->arrRegisteredHooks[$hookType][$hookIndex]);
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
public function registerAttachedHooks()
|
88 |
+
{
|
89 |
+
static $arrAlreadyRegisteredHooks = array();
|
90 |
+
|
91 |
+
foreach($this->arrRegisteredHooks as $hookType => $arrIndexedHooks)
|
92 |
+
{
|
93 |
+
foreach($arrIndexedHooks as $hookIndex => $arrHookInfo)
|
94 |
+
{
|
95 |
+
if(!isset($arrHookInfo[3]) || isset($arrAlreadyRegisteredHooks[$hookIndex]))
|
96 |
+
continue;
|
97 |
+
|
98 |
+
(1 === $hookType) //hookName , $callBack , $priority , $numberOfArguments
|
99 |
+
? add_action($arrHookInfo[0], $arrHookInfo[1], $arrHookInfo[2], $arrHookInfo[3])
|
100 |
+
: add_filter($arrHookInfo[0], $arrHookInfo[1], $arrHookInfo[2], $arrHookInfo[3]);
|
101 |
+
|
102 |
+
$arrAlreadyRegisteredHooks[$hookIndex] = true;
|
103 |
+
}
|
104 |
+
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
}
|
{includes → 2.0/includes}/modules/MchGdbcBasePublicModule.php
RENAMED
File without changes
|
2.0/includes/modules/MchGdbcGroupedModules.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class MchGdbcGroupedModules
|
5 |
+
{
|
6 |
+
private $groupedModulesList = null;
|
7 |
+
private $groupTitle = null;
|
8 |
+
private $groupDescription = null;
|
9 |
+
|
10 |
+
public function __construct($groupTitle = null, array $groupedModulesList = null)
|
11 |
+
{
|
12 |
+
$this->groupTitle = $groupTitle;
|
13 |
+
$this->groupedModulesList = array();
|
14 |
+
|
15 |
+
foreach((array)$groupedModulesList as $adminModule)
|
16 |
+
if($adminModule instanceof MchGdbcBaseAdminModule)
|
17 |
+
$this->groupedModulesList[] = $adminModule;
|
18 |
+
|
19 |
+
}
|
20 |
+
|
21 |
+
public function addModule(MchGdbcBaseAdminModule $adminModule)
|
22 |
+
{
|
23 |
+
$this->groupedModulesList[] = $adminModule;
|
24 |
+
}
|
25 |
+
|
26 |
+
public function getGroupedModules()
|
27 |
+
{
|
28 |
+
return $this->groupedModulesList;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function hasModules()
|
32 |
+
{
|
33 |
+
return isset($this->groupedModulesList[0]);
|
34 |
+
}
|
35 |
+
|
36 |
+
public function getGroupTitle()
|
37 |
+
{
|
38 |
+
return $this->groupTitle;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getGroupDescription()
|
42 |
+
{
|
43 |
+
return $this->groupDescription;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function setGroupTitle( $groupTitle ) {
|
47 |
+
$this->groupTitle = $groupTitle;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function setGroupDescription( $groupDescription ) {
|
51 |
+
$this->groupDescription = $groupDescription;
|
52 |
+
}
|
53 |
+
|
54 |
+
}
|
2.0/includes/modules/MchGdbcModulesController.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: 4over
|
5 |
+
* Date: 6/5/15
|
6 |
+
* Time: 4:41 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
class MchGdbcModulesController
|
10 |
+
{
|
11 |
+
//public
|
12 |
+
}
|
{includes → 2.0/includes}/notices/MchGdbcAdminNotice.php
RENAMED
File without changes
|
{includes → 2.0/includes}/plugin/MchGdbcBaseAdminPage.php
RENAMED
File without changes
|
2.0/includes/plugin/MchGdbcBaseAdminPlugin.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class MchGdbcBaseAdminPlugin extends MchGdbcBasePlugin
|
21 |
+
{
|
22 |
+
|
23 |
+
protected $adminPagesList = array();
|
24 |
+
|
25 |
+
//public abstract function getAdminPages();
|
26 |
+
|
27 |
+
public abstract function enqueueAdminScriptsAndStyles();
|
28 |
+
|
29 |
+
protected function __construct(array $arrPluginInfo)
|
30 |
+
{
|
31 |
+
parent::__construct($arrPluginInfo);
|
32 |
+
|
33 |
+
add_action('admin_enqueue_scripts', array( $this, 'enqueueAdminScriptsAndStyles' ));
|
34 |
+
add_action('admin_init', array($this, 'initializeAdminPlugin'));
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
public function registerAdminPage(MchGdbcBaseAdminPage $adminPage)
|
39 |
+
{
|
40 |
+
$this->adminPagesList[] = $adminPage;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function getRegisteredAdminPages()
|
44 |
+
{
|
45 |
+
return $this->adminPagesList;
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @return MchGdbcBaseAdminPage | null
|
50 |
+
*/
|
51 |
+
protected function getActivePage()
|
52 |
+
{
|
53 |
+
foreach($this->getRegisteredAdminPages() as $adminPage)
|
54 |
+
if($adminPage->isActive())
|
55 |
+
return $adminPage;
|
56 |
+
|
57 |
+
return null;
|
58 |
+
}
|
59 |
+
|
60 |
+
public function initializeAdminPlugin()
|
61 |
+
{}
|
62 |
+
|
63 |
+
private function __clone()
|
64 |
+
{}
|
65 |
+
|
66 |
+
}
|
2.0/includes/plugin/MchGdbcBasePlugin.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2014 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class MchGdbcBasePlugin
|
21 |
+
{
|
22 |
+
protected static $PLUGIN_VERSION = null;
|
23 |
+
protected static $PLUGIN_SLUG = null;
|
24 |
+
protected static $PLUGIN_MAIN_FILE = null;
|
25 |
+
protected static $PLUGIN_SHORT_CODE = null;
|
26 |
+
|
27 |
+
protected static $PLUGIN_DIRECTORY_PATH = null;
|
28 |
+
protected static $PLUGIN_DIRECTORY_NAME = null;
|
29 |
+
protected static $PLUGIN_BASE_NAME = null;
|
30 |
+
|
31 |
+
protected static $PLUGIN_URL = null;
|
32 |
+
|
33 |
+
//private $isPluginNetworkActivated = null;
|
34 |
+
|
35 |
+
protected function __construct(array $arrPluginInfo)
|
36 |
+
{
|
37 |
+
self::$PLUGIN_SLUG = isset($arrPluginInfo['PLUGIN_SLUG']) ? $arrPluginInfo['PLUGIN_SLUG'] : null;
|
38 |
+
self::$PLUGIN_VERSION = isset($arrPluginInfo['PLUGIN_VERSION']) ? $arrPluginInfo['PLUGIN_VERSION'] : null;
|
39 |
+
self::$PLUGIN_MAIN_FILE = isset($arrPluginInfo['PLUGIN_MAIN_FILE']) ? $arrPluginInfo['PLUGIN_MAIN_FILE'] : null;
|
40 |
+
self::$PLUGIN_SHORT_CODE = isset($arrPluginInfo['PLUGIN_SHORT_CODE']) ? $arrPluginInfo['PLUGIN_SHORT_CODE'] : null;
|
41 |
+
|
42 |
+
self::$PLUGIN_DIRECTORY_PATH = (null !== self::$PLUGIN_MAIN_FILE ? dirname(self::$PLUGIN_MAIN_FILE) : null);
|
43 |
+
|
44 |
+
self::$PLUGIN_DIRECTORY_NAME = (null !== self::$PLUGIN_DIRECTORY_PATH ? plugin_basename(self::$PLUGIN_DIRECTORY_PATH) : null);
|
45 |
+
|
46 |
+
self::$PLUGIN_URL = (null !== self::$PLUGIN_MAIN_FILE ? untrailingslashit( plugins_url( '/', self::$PLUGIN_MAIN_FILE ) ) : null);
|
47 |
+
|
48 |
+
self::$PLUGIN_BASE_NAME = (null !== self::$PLUGIN_MAIN_FILE ? plugin_basename(self::$PLUGIN_MAIN_FILE) : null);
|
49 |
+
|
50 |
+
add_action('init', array($this, 'initializePlugin' ) );
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
|
55 |
+
public function initializePlugin()
|
56 |
+
{
|
57 |
+
$locale = apply_filters('plugin_locale', get_locale(), self::$PLUGIN_SLUG);
|
58 |
+
|
59 |
+
load_textdomain(self::$PLUGIN_SLUG, trailingslashit( WP_LANG_DIR ) . self::$PLUGIN_SLUG . DIRECTORY_SEPARATOR . self::$PLUGIN_SLUG . '-' . $locale . '.mo' );
|
60 |
+
|
61 |
+
load_plugin_textdomain(self::$PLUGIN_SLUG, false, self::$PLUGIN_SLUG . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR );
|
62 |
+
}
|
63 |
+
|
64 |
+
}
|
2.0/includes/plugin/MchGdbcBasePublicPlugin.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
abstract class MchGdbcBasePublicPlugin extends MchGdbcBasePlugin
|
21 |
+
{
|
22 |
+
|
23 |
+
public abstract function enqueuePublicScriptsAndStyles();
|
24 |
+
public abstract function registerAfterSetupThemeHooks();
|
25 |
+
|
26 |
+
protected function __construct(array $arrPluginInfo)
|
27 |
+
{
|
28 |
+
parent::__construct($arrPluginInfo);
|
29 |
+
|
30 |
+
add_action('wp_enqueue_scripts', array( $this, 'enqueuePublicScriptsAndStyles' ));
|
31 |
+
add_action('after_setup_theme', array( $this, 'registerAfterSetupThemeHooks' ));
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
public function initializePlugin()
|
36 |
+
{
|
37 |
+
parent::initializePlugin();
|
38 |
+
}
|
39 |
+
|
40 |
+
private function __clone()
|
41 |
+
{}
|
42 |
+
|
43 |
+
private function __wakeup()
|
44 |
+
{}
|
45 |
+
|
46 |
+
}
|
2.0/includes/plugin/MchGdbcPluginUpdater.php
ADDED
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Allows plugins to use their own update API.
|
4 |
+
*
|
5 |
+
* @author Pippin Williamson
|
6 |
+
* @version 1.6
|
7 |
+
*/
|
8 |
+
|
9 |
+
class MchGdbcPluginUpdater
|
10 |
+
{
|
11 |
+
private $api_url = '';
|
12 |
+
private $api_data = array();
|
13 |
+
private $name = '';
|
14 |
+
private $slug = '';
|
15 |
+
private $version = '';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Class constructor.
|
19 |
+
*
|
20 |
+
* @uses plugin_basename()
|
21 |
+
* @uses hook()
|
22 |
+
*
|
23 |
+
* @param string $_api_url The URL pointing to the custom API endpoint.
|
24 |
+
* @param string $_plugin_file Path to the plugin file.
|
25 |
+
* @param array $_api_data Optional data to send with API calls.
|
26 |
+
*/
|
27 |
+
function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
|
28 |
+
$this->api_url = trailingslashit( $_api_url );
|
29 |
+
$this->api_data = $_api_data;
|
30 |
+
$this->name = plugin_basename( $_plugin_file );
|
31 |
+
$this->slug = basename( $_plugin_file, '.php' );
|
32 |
+
$this->version = $_api_data['version'];
|
33 |
+
|
34 |
+
// Set up hooks.
|
35 |
+
$this->init();
|
36 |
+
add_action( 'admin_init', array( $this, 'show_changelog' ) );
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Set up WordPress filters to hook into WP's update process.
|
41 |
+
*
|
42 |
+
* @uses add_filter()
|
43 |
+
*
|
44 |
+
* @return void
|
45 |
+
*/
|
46 |
+
public function init() {
|
47 |
+
|
48 |
+
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
|
49 |
+
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
|
50 |
+
|
51 |
+
add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Check for Updates at the defined API endpoint and modify the update array.
|
56 |
+
*
|
57 |
+
* This function dives into the update API just when WordPress creates its update array,
|
58 |
+
* then adds a custom API call and injects the custom plugin data retrieved from the API.
|
59 |
+
* It is reassembled from parts of the native WordPress plugin update code.
|
60 |
+
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
|
61 |
+
*
|
62 |
+
* @uses api_request()
|
63 |
+
*
|
64 |
+
* @param array $_transient_data Update array build by WordPress.
|
65 |
+
* @return array Modified update array with custom plugin data.
|
66 |
+
*/
|
67 |
+
function check_update( $_transient_data ) {
|
68 |
+
|
69 |
+
global $pagenow;
|
70 |
+
|
71 |
+
if( ! is_object( $_transient_data ) ) {
|
72 |
+
$_transient_data = new stdClass;
|
73 |
+
}
|
74 |
+
|
75 |
+
if( 'plugins.php' == $pagenow && is_multisite() ) {
|
76 |
+
return $_transient_data;
|
77 |
+
}
|
78 |
+
|
79 |
+
if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
|
80 |
+
|
81 |
+
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
|
82 |
+
|
83 |
+
if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
|
84 |
+
|
85 |
+
if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
86 |
+
|
87 |
+
if ( empty( $version_info->plugin ) ) {
|
88 |
+
$version_info->plugin = $this->name;
|
89 |
+
}
|
90 |
+
|
91 |
+
$_transient_data->response[ $this->name ] = $version_info;
|
92 |
+
|
93 |
+
}
|
94 |
+
|
95 |
+
$_transient_data->last_checked = time();
|
96 |
+
$_transient_data->checked[ $this->name ] = $this->version;
|
97 |
+
|
98 |
+
}
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
return $_transient_data;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
|
107 |
+
*
|
108 |
+
* @param string $file
|
109 |
+
* @param array $plugin
|
110 |
+
*/
|
111 |
+
public function show_update_notification( $file, $plugin ) {
|
112 |
+
|
113 |
+
if( ! current_user_can( 'update_plugins' ) ) {
|
114 |
+
return;
|
115 |
+
}
|
116 |
+
|
117 |
+
if( ! is_multisite() ) {
|
118 |
+
return;
|
119 |
+
}
|
120 |
+
|
121 |
+
if ( $this->name != $file ) {
|
122 |
+
return;
|
123 |
+
}
|
124 |
+
|
125 |
+
// Remove our filter on the site transient
|
126 |
+
remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
|
127 |
+
|
128 |
+
$update_cache = get_site_transient( 'update_plugins' );
|
129 |
+
|
130 |
+
if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
|
131 |
+
|
132 |
+
$cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' );
|
133 |
+
$version_info = get_transient( $cache_key );
|
134 |
+
|
135 |
+
if( false === $version_info ) {
|
136 |
+
|
137 |
+
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
|
138 |
+
|
139 |
+
set_transient( $cache_key, $version_info, 3600 );
|
140 |
+
}
|
141 |
+
|
142 |
+
|
143 |
+
if( ! is_object( $version_info ) ) {
|
144 |
+
return;
|
145 |
+
}
|
146 |
+
|
147 |
+
if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
148 |
+
|
149 |
+
$update_cache->response[ $this->name ] = $version_info;
|
150 |
+
|
151 |
+
}
|
152 |
+
|
153 |
+
$update_cache->last_checked = time();
|
154 |
+
$update_cache->checked[ $this->name ] = $this->version;
|
155 |
+
|
156 |
+
set_site_transient( 'update_plugins', $update_cache );
|
157 |
+
|
158 |
+
} else {
|
159 |
+
|
160 |
+
$version_info = $update_cache->response[ $this->name ];
|
161 |
+
|
162 |
+
}
|
163 |
+
|
164 |
+
// Restore our filter
|
165 |
+
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
|
166 |
+
|
167 |
+
if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
168 |
+
|
169 |
+
// build a plugin list row, with update notification
|
170 |
+
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
|
171 |
+
echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
|
172 |
+
|
173 |
+
$changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
|
174 |
+
|
175 |
+
if ( empty( $version_info->download_link ) ) {
|
176 |
+
printf(
|
177 |
+
__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'easy-digital-downloads' ),
|
178 |
+
esc_html( $version_info->name ),
|
179 |
+
esc_url( $changelog_link ),
|
180 |
+
esc_html( $version_info->new_version )
|
181 |
+
);
|
182 |
+
} else {
|
183 |
+
printf(
|
184 |
+
__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'easy-digital-downloads' ),
|
185 |
+
esc_html( $version_info->name ),
|
186 |
+
esc_url( $changelog_link ),
|
187 |
+
esc_html( $version_info->new_version ),
|
188 |
+
esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
|
189 |
+
);
|
190 |
+
}
|
191 |
+
|
192 |
+
echo '</div></td></tr>';
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Updates information on the "View version x.x details" page with custom data.
|
199 |
+
*
|
200 |
+
* @uses api_request()
|
201 |
+
*
|
202 |
+
* @param mixed $_data
|
203 |
+
* @param string $_action
|
204 |
+
* @param object $_args
|
205 |
+
* @return object $_data
|
206 |
+
*/
|
207 |
+
function plugins_api_filter( $_data, $_action = '', $_args = null ) {
|
208 |
+
|
209 |
+
|
210 |
+
if ( $_action != 'plugin_information' ) {
|
211 |
+
|
212 |
+
return $_data;
|
213 |
+
|
214 |
+
}
|
215 |
+
|
216 |
+
if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
|
217 |
+
|
218 |
+
return $_data;
|
219 |
+
|
220 |
+
}
|
221 |
+
|
222 |
+
$to_send = array(
|
223 |
+
'slug' => $this->slug,
|
224 |
+
'is_ssl' => is_ssl(),
|
225 |
+
'fields' => array(
|
226 |
+
'banners' => false, // These will be supported soon hopefully
|
227 |
+
'reviews' => false
|
228 |
+
)
|
229 |
+
);
|
230 |
+
|
231 |
+
$api_response = $this->api_request( 'plugin_information', $to_send );
|
232 |
+
|
233 |
+
if ( false !== $api_response ) {
|
234 |
+
$_data = $api_response;
|
235 |
+
}
|
236 |
+
|
237 |
+
return $_data;
|
238 |
+
}
|
239 |
+
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Disable SSL verification in order to prevent download update failures
|
243 |
+
*
|
244 |
+
* @param array $args
|
245 |
+
* @param string $url
|
246 |
+
* @return object $array
|
247 |
+
*/
|
248 |
+
function http_request_args( $args, $url ) {
|
249 |
+
// If it is an https request and we are performing a package download, disable ssl verification
|
250 |
+
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
|
251 |
+
$args['sslverify'] = false;
|
252 |
+
}
|
253 |
+
return $args;
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Calls the API and, if successfull, returns the object delivered by the API.
|
258 |
+
*
|
259 |
+
* @uses get_bloginfo()
|
260 |
+
* @uses wp_remote_post()
|
261 |
+
* @uses is_wp_error()
|
262 |
+
*
|
263 |
+
* @param string $_action The requested action.
|
264 |
+
* @param array $_data Parameters for the API action.
|
265 |
+
* @return false|object
|
266 |
+
*/
|
267 |
+
private function api_request( $_action, $_data ) {
|
268 |
+
|
269 |
+
global $wp_version;
|
270 |
+
|
271 |
+
$data = array_merge( $this->api_data, $_data );
|
272 |
+
|
273 |
+
if ( $data['slug'] != $this->slug )
|
274 |
+
return;
|
275 |
+
|
276 |
+
if ( empty( $data['license'] ) )
|
277 |
+
return;
|
278 |
+
|
279 |
+
if( $this->api_url == home_url() ) {
|
280 |
+
return false; // Don't allow a plugin to ping itself
|
281 |
+
}
|
282 |
+
|
283 |
+
$api_params = array(
|
284 |
+
'edd_action' => 'get_version',
|
285 |
+
'license' => $data['license'],
|
286 |
+
'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
|
287 |
+
'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
|
288 |
+
'slug' => $data['slug'],
|
289 |
+
'author' => $data['author'],
|
290 |
+
'url' => home_url()
|
291 |
+
);
|
292 |
+
|
293 |
+
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
|
294 |
+
|
295 |
+
if ( ! is_wp_error( $request ) ) {
|
296 |
+
$request = json_decode( wp_remote_retrieve_body( $request ) );
|
297 |
+
}
|
298 |
+
|
299 |
+
if ( $request && isset( $request->sections ) ) {
|
300 |
+
$request->sections = maybe_unserialize( $request->sections );
|
301 |
+
} else {
|
302 |
+
$request = false;
|
303 |
+
}
|
304 |
+
|
305 |
+
return $request;
|
306 |
+
}
|
307 |
+
|
308 |
+
public function show_changelog() {
|
309 |
+
|
310 |
+
|
311 |
+
if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
|
312 |
+
return;
|
313 |
+
}
|
314 |
+
|
315 |
+
if( empty( $_REQUEST['plugin'] ) ) {
|
316 |
+
return;
|
317 |
+
}
|
318 |
+
|
319 |
+
if( empty( $_REQUEST['slug'] ) ) {
|
320 |
+
return;
|
321 |
+
}
|
322 |
+
|
323 |
+
if( ! current_user_can( 'update_plugins' ) ) {
|
324 |
+
wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
325 |
+
}
|
326 |
+
|
327 |
+
$response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
|
328 |
+
|
329 |
+
if( $response && isset( $response->sections['changelog'] ) ) {
|
330 |
+
echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
|
331 |
+
}
|
332 |
+
|
333 |
+
|
334 |
+
exit;
|
335 |
+
}
|
336 |
+
}
|
{includes → 2.0/includes}/task-scheduler/MchGdbcWpTask.php
RENAMED
File without changes
|
{includes → 2.0/includes}/task-scheduler/MchGdbcWpTaskScheduler.php
RENAMED
File without changes
|
{includes → 2.0/includes}/utils/MchGdbcHtmlUtils.php
RENAMED
File without changes
|
2.0/includes/utils/MchGdbcIPUtils.php
ADDED
@@ -0,0 +1,866 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
|
21 |
+
final class MchGdbcIPUtils
|
22 |
+
{
|
23 |
+
CONST IP_VERSION_4 = 4;
|
24 |
+
CONST IP_VERSION_6 = 6;
|
25 |
+
|
26 |
+
CONST IP_V4_MAX_BITS = 32;
|
27 |
+
CONST IP_V6_MAX_BITS = 128;
|
28 |
+
|
29 |
+
public static function ipAddressToBinary($ipAddress, $ipVersion = null)
|
30 |
+
{
|
31 |
+
static $arrBinaryIp = array();
|
32 |
+
if(isset($arrBinaryIp[$ipAddress]))
|
33 |
+
return $arrBinaryIp[$ipAddress];
|
34 |
+
|
35 |
+
(null === $ipVersion) ? $ipVersion = self::getIpAddressVersion($ipAddress) : null;
|
36 |
+
|
37 |
+
if( -1 === $ipVersion)
|
38 |
+
return null;
|
39 |
+
|
40 |
+
(count($arrBinaryIp) > 20) ? array_shift($arrBinaryIp) : null;
|
41 |
+
|
42 |
+
if($ipVersion === self::IP_VERSION_4)
|
43 |
+
{
|
44 |
+
if(self::hasIpV4Support()) {
|
45 |
+
return (false !== ($binStr = inet_pton($ipAddress))) ? $arrBinaryIp[$ipAddress] = $binStr : null;
|
46 |
+
}
|
47 |
+
|
48 |
+
return $arrBinaryIp[$ipAddress] = pack('N', ip2long($ipAddress));
|
49 |
+
}
|
50 |
+
|
51 |
+
if(self::hasIPV6Support()) {
|
52 |
+
return (false !== ($binStr = inet_pton($ipAddress))) ? $arrBinaryIp[$ipAddress] = $binStr : null;
|
53 |
+
}
|
54 |
+
|
55 |
+
$binary = explode(':', $ipAddress);
|
56 |
+
$binaryCount = count($binary);
|
57 |
+
if (($doub = array_search('', $binary, 1)) !== false)
|
58 |
+
{
|
59 |
+
$length = (!$doub || $doub === ($binaryCount - 1) ? 2 : 1);
|
60 |
+
array_splice($binary, $doub, $length, array_fill(0, 8 + $length - $binaryCount, 0));
|
61 |
+
}
|
62 |
+
|
63 |
+
$binary = array_map('hexdec', $binary);
|
64 |
+
array_unshift($binary, 'n*');
|
65 |
+
|
66 |
+
return $arrBinaryIp[$ipAddress] = call_user_func_array('pack', $binary);
|
67 |
+
|
68 |
+
|
69 |
+
}
|
70 |
+
|
71 |
+
public static function ipAddressFromBinary($binaryString)
|
72 |
+
{
|
73 |
+
$strLength = strlen($binaryString);
|
74 |
+
|
75 |
+
if(4 === $strLength && !self::hasIpV4Support())
|
76 |
+
return self::ipV4FromBinary($binaryString);
|
77 |
+
|
78 |
+
if(16 === $strLength && !self::hasIPV6Support())
|
79 |
+
return self::ipV6FromBinary($binaryString);
|
80 |
+
|
81 |
+
return ($strLength === 4 || $strLength === 16) ?
|
82 |
+
(false !== ($ipAddress = inet_ntop($binaryString))) ? $ipAddress : null : null;
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
public static function isPublicIpAddress($ipAddress, $ipVersion = null)
|
87 |
+
{
|
88 |
+
(null === $ipVersion) ? $ipVersion = self::getIpAddressVersion($ipAddress) : -1;
|
89 |
+
|
90 |
+
if($ipVersion === self::IP_VERSION_4 && 0 === strpos($ipAddress, '127.0.0'))
|
91 |
+
return false;
|
92 |
+
|
93 |
+
if($ipVersion === self::IP_VERSION_6 && (0 === strpos($ipAddress, '::') ? '::1' === $ipAddress : '::1' === self::compressIPV6($ipAddress)))
|
94 |
+
return false;
|
95 |
+
|
96 |
+
return false !== filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
|
97 |
+
}
|
98 |
+
|
99 |
+
public static function compressIPV6($ipAddress, $shouldValidate = false)
|
100 |
+
{
|
101 |
+
if($shouldValidate && (self::IP_VERSION_6 !== self::getIpAddressVersion($ipAddress)))
|
102 |
+
return null;
|
103 |
+
|
104 |
+
return self::hasIPV6Support() ? inet_ntop(inet_pton($ipAddress)) : self::ipAddressFromBinary(self::ipAddressToBinary($ipAddress));
|
105 |
+
}
|
106 |
+
|
107 |
+
public static function expandIPV6($ipAddress, $shouldValidate = false)
|
108 |
+
{
|
109 |
+
if($shouldValidate && (self::IP_VERSION_6 !== self::getIpAddressVersion($ipAddress)))
|
110 |
+
return null;
|
111 |
+
|
112 |
+
return self::hasIPV6Support() ? implode(':', str_split(bin2hex(inet_pton($ipAddress)), 4)) : implode(':', str_split(bin2hex(self::ipAddressToBinary($ipAddress, self::IP_VERSION_6)), 4));
|
113 |
+
}
|
114 |
+
|
115 |
+
public static function ipAddressToNumber($ipAddress, $ipVersion = -1, $cacheResult = false)
|
116 |
+
{
|
117 |
+
static $arrCache = array();
|
118 |
+
if(isset($arrCache[$ipVersion][$ipAddress]))
|
119 |
+
return $arrCache[$ipVersion][$ipAddress];
|
120 |
+
|
121 |
+
(-1 === $ipVersion) ? $ipVersion = self::getIpAddressVersion($ipAddress) : -1;
|
122 |
+
if(-1 === $ipVersion)
|
123 |
+
return null;
|
124 |
+
|
125 |
+
if($ipVersion === self::IP_VERSION_4) {
|
126 |
+
return $cacheResult ? $arrCache[$ipVersion][$ipAddress] = sprintf( '%u', ip2long( $ipAddress ) ) : sprintf( '%u', ip2long( $ipAddress ) );
|
127 |
+
}
|
128 |
+
|
129 |
+
$bytes = 16;
|
130 |
+
$ipv6long = '';
|
131 |
+
|
132 |
+
$binaryIp = self::ipAddressToBinary($ipAddress, self::IP_VERSION_6);
|
133 |
+
while ($bytes > 0)
|
134 |
+
{
|
135 |
+
$bin = sprintf('%08b',(ord($binaryIp[$bytes-1])));
|
136 |
+
$ipv6long = $bin.$ipv6long;
|
137 |
+
$bytes--;
|
138 |
+
}
|
139 |
+
|
140 |
+
$out = new Math_BigInteger($ipv6long, 2);
|
141 |
+
|
142 |
+
return $cacheResult ? $arrCache[$ipVersion][$ipAddress] = $out->toString() : $out->toString();
|
143 |
+
|
144 |
+
}
|
145 |
+
|
146 |
+
public static function ipAddressFromNumber($number, $ipVersion)
|
147 |
+
{
|
148 |
+
if($ipVersion === self::IP_VERSION_4)
|
149 |
+
{
|
150 |
+
return long2ip(-(4294967295 - ($number - 1)));
|
151 |
+
}
|
152 |
+
|
153 |
+
$binNumber = new Math_BigInteger($number);
|
154 |
+
$binNumber = str_pad($binNumber->toBits(), 128, '0', STR_PAD_LEFT);
|
155 |
+
|
156 |
+
$bytes = 0;
|
157 |
+
$ipv6 = '';
|
158 |
+
while ($bytes < 8)
|
159 |
+
{
|
160 |
+
$part = dechex(bindec(substr($binNumber, ($bytes *16 ), 16)));
|
161 |
+
$part = str_pad($part, 4, '0', STR_PAD_LEFT);
|
162 |
+
$ipv6 .= $part.':';
|
163 |
+
++$bytes;
|
164 |
+
}
|
165 |
+
|
166 |
+
return substr($ipv6, 0, strlen($ipv6) -1);
|
167 |
+
}
|
168 |
+
|
169 |
+
|
170 |
+
public static function isValidIpAddress($ipAddress)
|
171 |
+
{
|
172 |
+
return (-1 !== self::getIpAddressVersion($ipAddress));
|
173 |
+
}
|
174 |
+
|
175 |
+
|
176 |
+
private static function ipV6FromBinary($binaryString)
|
177 |
+
{
|
178 |
+
return preg_replace(
|
179 |
+
array('/(?::?\b0+\b:?){2,}/', '/\b0+([^0])/e'),
|
180 |
+
array('::', '(int)"$1"?"$1":"0$1"'),
|
181 |
+
substr(chunk_split(bin2hex($binaryString), 4, ':'), 0, -1));
|
182 |
+
}
|
183 |
+
|
184 |
+
private static function ipV4FromBinary($binaryString)
|
185 |
+
{
|
186 |
+
$decode = unpack('N', $binaryString);
|
187 |
+
return isset($decode[1]) ? long2ip($decode[1]) : null;
|
188 |
+
}
|
189 |
+
|
190 |
+
public static function getIpAddressVersion($ipAddress)
|
191 |
+
{
|
192 |
+
static $arrIpVersions = array();
|
193 |
+
if(isset($arrIpVersions[$ipAddress]))
|
194 |
+
return $arrIpVersions[$ipAddress];
|
195 |
+
|
196 |
+
if(false !== filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
|
197 |
+
return $arrIpVersions[$ipAddress] = self::IP_VERSION_4;
|
198 |
+
|
199 |
+
if(false !== filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
200 |
+
return $arrIpVersions[$ipAddress] = self::IP_VERSION_6;
|
201 |
+
|
202 |
+
return -1;
|
203 |
+
}
|
204 |
+
|
205 |
+
|
206 |
+
public static function sanitizeIpAddress($ipString)
|
207 |
+
{
|
208 |
+
$ipString = trim($ipString);
|
209 |
+
false !== ($posSlash = strpos($ipString, '/')) ? $ipString = substr($ipString, 0, $posSlash) : null;
|
210 |
+
|
211 |
+
if(false === ($posColon = strrpos($ipString, ':')))
|
212 |
+
return $ipString;
|
213 |
+
|
214 |
+
$posDot = strrpos($ipString, '.');
|
215 |
+
$posRBrac = strpos($ipString, ']');
|
216 |
+
|
217 |
+
($posRBrac !== false && $ipString[0] === '[') ? $ipString = substr($ipString, 1, $posRBrac - 1) : null;
|
218 |
+
|
219 |
+
if ($posDot !== false)
|
220 |
+
{
|
221 |
+
$posColon > $posDot ? $ipString = substr($ipString, 0, $posColon) : null;
|
222 |
+
}
|
223 |
+
elseif (strpos($ipString, ':') === $posColon)
|
224 |
+
{
|
225 |
+
$ipString = substr($ipString, 0, $posColon);
|
226 |
+
}
|
227 |
+
|
228 |
+
return $ipString;
|
229 |
+
}
|
230 |
+
|
231 |
+
|
232 |
+
public static function sanitizeCIDRRange($ipRangeString)
|
233 |
+
{
|
234 |
+
static $arrSanitizedRanges = array();
|
235 |
+
if(isset($arrSanitizedRanges[$ipRangeString]))
|
236 |
+
return $arrSanitizedRanges[$ipRangeString];
|
237 |
+
|
238 |
+
$sanitizedKey = $ipRangeString;
|
239 |
+
|
240 |
+
$ipRangeString = trim($ipRangeString);
|
241 |
+
if (empty($ipRangeString))
|
242 |
+
return null;
|
243 |
+
|
244 |
+
$bits = null;
|
245 |
+
if (false !== strpos($ipRangeString, '*'))
|
246 |
+
{
|
247 |
+
if (preg_match('~(^|\.)\*\.\d+(\.|$)~D', $ipRangeString))
|
248 |
+
return null;
|
249 |
+
|
250 |
+
$bits = 32 - (8 * substr_count($ipRangeString, '*'));
|
251 |
+
$ipRangeString = str_replace('*', '0', $ipRangeString);
|
252 |
+
}
|
253 |
+
|
254 |
+
if (false !== ($pos = strpos($ipRangeString, '/'))) {
|
255 |
+
$bits = substr($ipRangeString, $pos + 1);
|
256 |
+
$ipRangeString = substr($ipRangeString, 0, $pos);
|
257 |
+
}
|
258 |
+
|
259 |
+
if(-1 === ($ipVersion = self::getIpAddressVersion($ipRangeString)))
|
260 |
+
return null;
|
261 |
+
|
262 |
+
$maxBits = ($ipVersion === 4) ? 32 : 128;
|
263 |
+
|
264 |
+
(null === $bits) ? $bits = $maxBits : null;
|
265 |
+
|
266 |
+
return ($bits < 0 || $bits > $maxBits) ? null : $arrSanitizedRanges[$sanitizedKey] = "$ipRangeString/$bits";
|
267 |
+
|
268 |
+
}
|
269 |
+
|
270 |
+
public static function getCIDRRangeBounds($ipCIDR)
|
271 |
+
{
|
272 |
+
if (null === ($ipCIDR = self::sanitizeCIDRRange($ipCIDR)))
|
273 |
+
return array();
|
274 |
+
|
275 |
+
static $arrCachedRangeBounds = array();
|
276 |
+
if(isset($arrCachedRangeBounds[$ipCIDR]))
|
277 |
+
return $arrCachedRangeBounds[$ipCIDR];
|
278 |
+
|
279 |
+
list($range, $bits) = explode('/', $ipCIDR, 2);
|
280 |
+
|
281 |
+
$high = $low = self::ipAddressToBinary($range);
|
282 |
+
if (null === $low)
|
283 |
+
return array();
|
284 |
+
|
285 |
+
$lowLen = strlen($low);
|
286 |
+
$i = $lowLen - 1;
|
287 |
+
$bits = ($lowLen * 8) - $bits;
|
288 |
+
for ($n = (int)($bits / 8); $n > 0; $n--, $i--)
|
289 |
+
{
|
290 |
+
$low[$i] = chr(0);
|
291 |
+
$high[$i] = chr(255);
|
292 |
+
}
|
293 |
+
|
294 |
+
if ($n = $bits % 8)
|
295 |
+
{
|
296 |
+
$low[$i] = chr(ord($low[$i]) & ~((1 << $n) - 1));
|
297 |
+
$high[$i] = chr(ord($high[$i]) | ((1 << $n) - 1));
|
298 |
+
}
|
299 |
+
|
300 |
+
return $arrCachedRangeBounds[$ipCIDR] = array(self::ipAddressFromBinary($low), self::ipAddressFromBinary($high));
|
301 |
+
}
|
302 |
+
|
303 |
+
|
304 |
+
public static function generateRandomIPV4($justPublic = true)
|
305 |
+
{
|
306 |
+
$ipAddress = null;
|
307 |
+
|
308 |
+
while(true)
|
309 |
+
{
|
310 |
+
mt_srand();
|
311 |
+
$ipAddress = mt_rand(0,255).".".mt_rand(0,255).".".mt_rand(0,255).".".mt_rand(0,255);
|
312 |
+
|
313 |
+
if(!$justPublic)
|
314 |
+
break;
|
315 |
+
|
316 |
+
if(false !== filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
|
317 |
+
break;
|
318 |
+
|
319 |
+
}
|
320 |
+
|
321 |
+
return $ipAddress;
|
322 |
+
}
|
323 |
+
|
324 |
+
public static function generateRandomIPV6($justPublic = true)
|
325 |
+
{
|
326 |
+
$ipAddress = null;
|
327 |
+
|
328 |
+
while(true)
|
329 |
+
{
|
330 |
+
//mt_srand();
|
331 |
+
$ipAddress = self::compressIPV6(wordwrap('2001' . substr(sha1(mt_rand()), -28), 4, ':', true));
|
332 |
+
|
333 |
+
if(!$justPublic)
|
334 |
+
break;
|
335 |
+
|
336 |
+
if(false !== filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
|
337 |
+
break;
|
338 |
+
}
|
339 |
+
|
340 |
+
return $ipAddress;
|
341 |
+
}
|
342 |
+
|
343 |
+
public static function isIpInCIDRRange($ipAddress, $cidrRange, $ipVersion = -1, $alreadySanitized = false)
|
344 |
+
{
|
345 |
+
$ipVersion = (int)$ipVersion;
|
346 |
+
if(!$alreadySanitized) {
|
347 |
+
$ipAddress = self::sanitizeIpAddress( $ipAddress );
|
348 |
+
if ( null === ( $cidrRange = self::sanitizeCIDRRange( $cidrRange ) ) ) {
|
349 |
+
return false;
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
list($ipAddressRange, $netMask) = explode('/', $cidrRange, 2);
|
354 |
+
|
355 |
+
$netMask = (int)$netMask;
|
356 |
+
|
357 |
+
if(-1 === $ipVersion)
|
358 |
+
{
|
359 |
+
$ipVersion = self::getIpAddressVersion($ipAddress);
|
360 |
+
if ( -1 === $ipVersion ) {
|
361 |
+
return false;
|
362 |
+
}
|
363 |
+
|
364 |
+
if( $ipVersion !== self::getIpAddressVersion($ipAddressRange) ) {
|
365 |
+
return false;
|
366 |
+
}
|
367 |
+
}
|
368 |
+
|
369 |
+
if($ipVersion === self::IP_VERSION_4)
|
370 |
+
{
|
371 |
+
if($netMask === self::IP_V4_MAX_BITS){
|
372 |
+
return $ipAddressRange === $ipAddress;
|
373 |
+
}
|
374 |
+
|
375 |
+
return 0 === self::compareIPV4($ipAddress, $ipAddressRange, $netMask);
|
376 |
+
}
|
377 |
+
|
378 |
+
return 0 === self::compareIPV6($ipAddress, $ipAddressRange, $netMask);
|
379 |
+
|
380 |
+
}
|
381 |
+
|
382 |
+
public static function getMaxIpAddressFromCIDR($ipRangeCIDR)
|
383 |
+
{
|
384 |
+
$arrInfo = self::getCIDRRangeBounds($ipRangeCIDR);
|
385 |
+
|
386 |
+
return isset($arrInfo[1]) ? $arrInfo[1] : null;
|
387 |
+
|
388 |
+
}
|
389 |
+
|
390 |
+
public static function getMinIpAddressFromCIDR($ipRangeCIDR)
|
391 |
+
{
|
392 |
+
$arrInfo = self::getCIDRRangeBounds($ipRangeCIDR);
|
393 |
+
|
394 |
+
return isset($arrInfo[0]) ? $arrInfo[0] : null;
|
395 |
+
}
|
396 |
+
|
397 |
+
|
398 |
+
private static function getIpMaxPrefix($ipAddressORCIDR, $ipVersion = -1)
|
399 |
+
{
|
400 |
+
if(null === ($ipAddressORCIDR = self::sanitizeCIDRRange($ipAddressORCIDR)))
|
401 |
+
return -1;
|
402 |
+
|
403 |
+
list($ipAddress, $cidrRange) = explode('/', $ipAddressORCIDR, 2);
|
404 |
+
|
405 |
+
if(empty($ipAddress) || !isset($cidrRange) || $cidrRange < 0)
|
406 |
+
return -1;
|
407 |
+
|
408 |
+
(-1 === $ipVersion) ? $ipVersion = self::getIpAddressVersion($ipAddress) : null;
|
409 |
+
|
410 |
+
$maxBits = ($ipVersion === 4) ? 32 : 128;
|
411 |
+
|
412 |
+
$ipToNumber = self::ipAddressToNumber($ipAddress, $ipVersion);
|
413 |
+
|
414 |
+
while($cidrRange > 0)
|
415 |
+
{
|
416 |
+
if(4 === $ipVersion)
|
417 |
+
{
|
418 |
+
//$mask = pow(2, $maxBits) - pow(2, $maxBits - ($cidrRange -1));
|
419 |
+
//$mask = self::ipAddressToNumber(self::getIpAddressNetMask("$ipAddress/" . ($cidrRange - 1)));
|
420 |
+
$mask = ((1 << 32) -1) << (32 - ($cidrRange - 1)) ;
|
421 |
+
|
422 |
+
if ( ((int)$mask & (int)$ipToNumber) != (int)$ipToNumber )
|
423 |
+
return $cidrRange;
|
424 |
+
}
|
425 |
+
else
|
426 |
+
{
|
427 |
+
$maxBitsBigInt = self::mathBigIntPow(2, $maxBits);
|
428 |
+
$cidrBitsBigInt = self::mathBigIntPow(2, $maxBits - ($cidrRange -1));
|
429 |
+
$mask = $maxBitsBigInt->subtract($cidrBitsBigInt);
|
430 |
+
|
431 |
+
$ipToNumberBigInt = new Math_BigInteger($ipToNumber);
|
432 |
+
|
433 |
+
if($ipToNumberBigInt->compare($ipToNumberBigInt->bitwise_and($mask), $ipToNumberBigInt) != 0)
|
434 |
+
return $cidrRange;
|
435 |
+
}
|
436 |
+
|
437 |
+
$cidrRange --;
|
438 |
+
}
|
439 |
+
|
440 |
+
return $cidrRange;
|
441 |
+
|
442 |
+
}
|
443 |
+
|
444 |
+
private static function mathBigIntPow($number, $exp)
|
445 |
+
{
|
446 |
+
if(0 === $exp)
|
447 |
+
return new Math_BigInteger(1);
|
448 |
+
if(1 === $exp)
|
449 |
+
return new Math_BigInteger($number);
|
450 |
+
|
451 |
+
$odd = $exp % 2;
|
452 |
+
$exp -= $odd;
|
453 |
+
|
454 |
+
$number = new Math_BigInteger($number);
|
455 |
+
$multiplyResult = $number->multiply($number);
|
456 |
+
|
457 |
+
$result = self::mathBigIntPow($multiplyResult->value, $exp / 2);
|
458 |
+
|
459 |
+
(1 === $odd) ? $result = $result->multiply($number) : null;
|
460 |
+
|
461 |
+
return $result;
|
462 |
+
|
463 |
+
}
|
464 |
+
|
465 |
+
public static function combineCIDRRanges(array $arrCIDRRanges)
|
466 |
+
{
|
467 |
+
$arrCIDRRanges = self::getSortedCIDRs($arrCIDRRanges);
|
468 |
+
$newArrCIDRRanges = array();
|
469 |
+
|
470 |
+
while(!empty($arrCIDRRanges))
|
471 |
+
{
|
472 |
+
$ipCIDR = array_shift($arrCIDRRanges);
|
473 |
+
$startIpAddress = self::getMinIpAddressFromCIDR($ipCIDR);
|
474 |
+
|
475 |
+
$ipVersion = self::getIpAddressVersion($startIpAddress);
|
476 |
+
|
477 |
+
$max = new Math_BigInteger(self::ipAddressFromNumber($startIpAddress, $ipVersion));
|
478 |
+
|
479 |
+
$max = $max->add(new Math_BigInteger(self::getCIDRNumberOfHosts($ipCIDR)));
|
480 |
+
|
481 |
+
while(!empty($arrCIDRRanges))
|
482 |
+
{
|
483 |
+
$compareIpCIDR = self::getMinIpAddressFromCIDR($arrCIDRRanges[0]);
|
484 |
+
$compareIpNumber = new Math_BigInteger(self::ipAddressToNumber($compareIpCIDR, self::getIpAddressVersion($compareIpCIDR)));
|
485 |
+
|
486 |
+
if($max->compare($compareIpNumber) >= 0)
|
487 |
+
break;
|
488 |
+
|
489 |
+
$compareIpCIDR = array_shift( $arrCIDRRanges );
|
490 |
+
|
491 |
+
$newMax = $compareIpNumber->add( new Math_BigInteger( self::getCIDRNumberOfHosts( $compareIpCIDR ) ) );
|
492 |
+
|
493 |
+
if ( $newMax->compare( $max ) > 0 ) {
|
494 |
+
$max = $newMax;
|
495 |
+
}
|
496 |
+
|
497 |
+
}
|
498 |
+
|
499 |
+
$newIpAddressNumber = $max->subtract(new Math_BigInteger(1));
|
500 |
+
$newIpAddress = self::ipAddressFromNumber($newIpAddressNumber->value, $ipVersion);
|
501 |
+
|
502 |
+
$rangeCIDR = self::getCIDRListFromRange($startIpAddress, $newIpAddress);
|
503 |
+
|
504 |
+
$newArrCIDRRanges = array_merge($newArrCIDRRanges, $rangeCIDR);
|
505 |
+
}
|
506 |
+
|
507 |
+
return $newArrCIDRRanges;
|
508 |
+
}
|
509 |
+
|
510 |
+
public static function getCIDRListFromRange($startIp, $endIp)
|
511 |
+
{
|
512 |
+
|
513 |
+
$ipVersion = self::getIpAddressVersion($startIp);
|
514 |
+
|
515 |
+
if(-1 === $ipVersion || $ipVersion !== self::getIpAddressVersion($endIp))
|
516 |
+
return array();
|
517 |
+
|
518 |
+
$arrIpAddressRange = array();
|
519 |
+
|
520 |
+
if($ipVersion === self::IP_VERSION_4)
|
521 |
+
{
|
522 |
+
$startIpNumber = self::ipAddressToNumber($startIp, self::IP_VERSION_4);
|
523 |
+
$endIpNumber = self::ipAddressToNumber($endIp, self::IP_VERSION_4);
|
524 |
+
|
525 |
+
if($startIpNumber >= $endIpNumber)
|
526 |
+
return array(self::sanitizeCIDRRange($startIp));
|
527 |
+
|
528 |
+
$log2Value = log(2);
|
529 |
+
while($endIpNumber >= $startIpNumber)
|
530 |
+
{
|
531 |
+
$startIpFromNumber = self::ipAddressFromNumber($startIpNumber, self::IP_VERSION_4);
|
532 |
+
$prefix = self::getIpMaxPrefix($startIpFromNumber);
|
533 |
+
$diff = 32 - floor( log( $endIpNumber - $startIpNumber + 1) / $log2Value );
|
534 |
+
|
535 |
+
$prefix < $diff ? $prefix = $diff : null;
|
536 |
+
|
537 |
+
$arrIpAddressRange[] = $startIpFromNumber . "/$prefix";
|
538 |
+
$startIpNumber += pow(2, 32 - $prefix);
|
539 |
+
}
|
540 |
+
|
541 |
+
return $arrIpAddressRange;
|
542 |
+
}
|
543 |
+
|
544 |
+
// if($ipVersion === self::IP_VERSION_6)
|
545 |
+
// {
|
546 |
+
// $startIPBin = str_pad(self::ipAddressToBitRepresentation($startIp, self::IP_VERSION_6), 128, '0', STR_PAD_LEFT);
|
547 |
+
// $endIPBin = str_pad(self::ipAddressToBitRepresentation($endIp, self::IP_VERSION_6), 128, '0', STR_PAD_LEFT);
|
548 |
+
// $IPIncBin = $startIPBin;
|
549 |
+
//
|
550 |
+
// echo "$IPIncBin";exit;
|
551 |
+
//
|
552 |
+
// while (strcmp($IPIncBin, $endIPBin) <= 0)
|
553 |
+
// {
|
554 |
+
// $longNetwork = 128;
|
555 |
+
// $IPNetBin = $IPIncBin;
|
556 |
+
// while (($IPIncBin[$longNetwork - 1] == '0') && (strcmp(substr_replace($IPNetBin, '1', $longNetwork - 1, 1), $endIPBin) <= 0))
|
557 |
+
// {
|
558 |
+
// $IPNetBin[$longNetwork - 1] = '1';
|
559 |
+
// $longNetwork--;
|
560 |
+
// }
|
561 |
+
//
|
562 |
+
// $arrIpAddressRange[] = self::ipAddressFromBitRepresentation($IPIncBin) . "/$longNetwork";
|
563 |
+
// $IPIncBin = self::ipAddressFromBitRepresentation(self::addbin2bin(chr(1), self::ipAddressToBitRepresentation($IPNetBin)));
|
564 |
+
// $IPIncBin = str_pad($IPIncBin, 128, '0', STR_PAD_LEFT);
|
565 |
+
// print_r($arrIpAddressRange);
|
566 |
+
// //$IPIncBin = str_pad(wfHelperBin::bin2str(wfHelperBin::addbin2bin(chr(1), wfHelperBin::str2bin($IPNetBin))), 128, '0', STR_PAD_LEFT);
|
567 |
+
// }
|
568 |
+
//
|
569 |
+
// return $arrIpAddressRange;
|
570 |
+
// }
|
571 |
+
|
572 |
+
return $arrIpAddressRange;
|
573 |
+
|
574 |
+
}
|
575 |
+
|
576 |
+
private static function sortCIDRCallback($firstCIDR, $secondCIDR)
|
577 |
+
{
|
578 |
+
$firstArrRange = self::getCIDRRangeBounds(self::sanitizeCIDRRange($firstCIDR));
|
579 |
+
$secondArrRange = self::getCIDRRangeBounds(self::sanitizeCIDRRange($secondCIDR));
|
580 |
+
|
581 |
+
list($firstIpAddress, $firstCIDRRange) = $firstArrRange;
|
582 |
+
list($secondIpAddress, $secondCIDRRange) = $secondArrRange;
|
583 |
+
|
584 |
+
if(0 !== ( $comp = strcmp(self::ipAddressToNumber($firstIpAddress), self::ipAddressToNumber($secondIpAddress))))
|
585 |
+
return $comp;
|
586 |
+
|
587 |
+
return strcmp($firstCIDRRange, $secondCIDRRange);
|
588 |
+
}
|
589 |
+
|
590 |
+
private static function getSortedCIDRs(array $arrCIDR)
|
591 |
+
{
|
592 |
+
|
593 |
+
usort($arrCIDR, array(__CLASS__, 'sortCIDRCallback'));
|
594 |
+
return $arrCIDR;
|
595 |
+
|
596 |
+
//$arrCIDR = array_map('self::sanitizeCIDRRange', $arrCIDR);
|
597 |
+
|
598 |
+
//print_r($arrCIDR);exit;
|
599 |
+
}
|
600 |
+
|
601 |
+
|
602 |
+
public static function getIpAddressNetMask($ipAddressORCIDR, $ipVersion = null)
|
603 |
+
{
|
604 |
+
if(null === ($ipAddressORCIDR = self::sanitizeCIDRRange($ipAddressORCIDR)))
|
605 |
+
return null;
|
606 |
+
|
607 |
+
list($ipAddress, $cidrRange) = explode('/', $ipAddressORCIDR, 2);
|
608 |
+
|
609 |
+
if(empty($ipAddress) || !isset($cidrRange) || $cidrRange < 0)
|
610 |
+
return null;
|
611 |
+
|
612 |
+
(null === $ipVersion) ? $ipVersion = self::getIpAddressVersion($ipAddress) : null;
|
613 |
+
|
614 |
+
if($ipVersion === self::IP_VERSION_4 && $cidrRange <= 32)
|
615 |
+
{
|
616 |
+
return long2ip( ((1 << 32) -1) << (32 - $cidrRange) );
|
617 |
+
}
|
618 |
+
|
619 |
+
if($ipVersion === self::IP_VERSION_6 && $cidrRange <= 128)
|
620 |
+
{
|
621 |
+
$hexMask = '';
|
622 |
+
foreach(str_split(str_repeat("1", (128 - (128 - $cidrRange))).str_repeat("0", 128 - $cidrRange), 4) as $segment)
|
623 |
+
$hexMask .= base_convert( $segment, 2, 16);
|
624 |
+
|
625 |
+
return substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hexMask), 0, -1);
|
626 |
+
}
|
627 |
+
|
628 |
+
return null;
|
629 |
+
|
630 |
+
}
|
631 |
+
|
632 |
+
public static function getIpAddressNetwork($ipAddress, $ipVersion = null)
|
633 |
+
{
|
634 |
+
return self::getMinIpAddressFromCIDR($ipAddress);
|
635 |
+
}
|
636 |
+
|
637 |
+
public static function getIpAddressBroadcast($ipAddress, $ipVersion = null)
|
638 |
+
{
|
639 |
+
return self::getMaxIpAddressFromCIDR($ipAddress);
|
640 |
+
}
|
641 |
+
|
642 |
+
|
643 |
+
public static function getCIDRNumberOfHosts($ipAddressOrCIDR)
|
644 |
+
{
|
645 |
+
if(null === ($ipAddressOrCIDR = self::sanitizeCIDRRange($ipAddressOrCIDR)))
|
646 |
+
return null;
|
647 |
+
|
648 |
+
$arrRangeBounds = self::getCIDRRangeBounds($ipAddressOrCIDR);
|
649 |
+
if(empty($arrRangeBounds))
|
650 |
+
return null;
|
651 |
+
|
652 |
+
$ipVersion = self::getIpAddressVersion($arrRangeBounds[1]);
|
653 |
+
|
654 |
+
if(self::IP_VERSION_4 === $ipVersion)
|
655 |
+
{
|
656 |
+
$arrCidr = explode('/', $ipAddressOrCIDR, 2);
|
657 |
+
return pow(2, 32 - $arrCidr[1]);
|
658 |
+
//echo 1 + (self::ipAddressToNumber($arrRangeBounds[1], $ipVersion) - self::ipAddressToNumber($arrRangeBounds[0], $ipVersion)) . "\n";
|
659 |
+
//return 1 + (self::ipAddressToNumber($arrRangeBounds[1], $ipVersion) - self::ipAddressToNumber($arrRangeBounds[0], $ipVersion));
|
660 |
+
}
|
661 |
+
|
662 |
+
$numberOfHosts = new Math_BigInteger(self::ipAddressToNumber($arrRangeBounds[1], $ipVersion));
|
663 |
+
$numberOfHosts = $numberOfHosts->subtract(new Math_BigInteger(self::ipAddressToNumber($arrRangeBounds[0], $ipVersion)));
|
664 |
+
$numberOfHosts = $numberOfHosts->add(new Math_BigInteger(1));
|
665 |
+
|
666 |
+
return $numberOfHosts->toString();
|
667 |
+
}
|
668 |
+
|
669 |
+
|
670 |
+
public static function getAllIpAddressesFromCIDR($ipRangeCIDR)
|
671 |
+
{
|
672 |
+
if(null === ($ipRangeCIDR = self::sanitizeCIDRRange($ipRangeCIDR)))
|
673 |
+
return null;
|
674 |
+
|
675 |
+
$arrRangeBounds = self::getCIDRRangeBounds($ipRangeCIDR);
|
676 |
+
if(empty($arrRangeBounds))
|
677 |
+
return null;
|
678 |
+
|
679 |
+
$ipVersion = self::getIpAddressVersion($arrRangeBounds[1]);
|
680 |
+
|
681 |
+
$lowIpNumber = self::ipAddressToNumber($arrRangeBounds[0], $ipVersion);
|
682 |
+
$highIpNumber = self::ipAddressToNumber($arrRangeBounds[1], $ipVersion);
|
683 |
+
|
684 |
+
$arrAllIps = array(self::IP_VERSION_6 === $ipVersion ? self::expandIPV6($arrRangeBounds[0], false) : $arrRangeBounds[0]);
|
685 |
+
|
686 |
+
if(8 === PHP_INT_SIZE && self::IP_VERSION_4 === $ipVersion)
|
687 |
+
{
|
688 |
+
for(++$lowIpNumber;$lowIpNumber < $highIpNumber; ++$lowIpNumber)
|
689 |
+
{
|
690 |
+
$arrAllIps[] = self::ipAddressFromNumber($lowIpNumber, $ipVersion);
|
691 |
+
}
|
692 |
+
}
|
693 |
+
else
|
694 |
+
{
|
695 |
+
$bigNumberOne = new Math_BigInteger(1);
|
696 |
+
$lowIpNumber = new Math_BigInteger($lowIpNumber);
|
697 |
+
$lowIpNumber = $lowIpNumber->add($bigNumberOne);
|
698 |
+
$highIpNumber = new Math_BigInteger($highIpNumber);
|
699 |
+
|
700 |
+
while(!$lowIpNumber->equals($highIpNumber))
|
701 |
+
{
|
702 |
+
$arrAllIps[] = self::ipAddressFromNumber($lowIpNumber->toString(), $ipVersion);
|
703 |
+
$lowIpNumber = $lowIpNumber->add($bigNumberOne);
|
704 |
+
}
|
705 |
+
}
|
706 |
+
|
707 |
+
$arrAllIps[] = self::IP_VERSION_6 === $ipVersion ? self::expandIPV6($arrRangeBounds[1], false) : $arrRangeBounds[1];
|
708 |
+
|
709 |
+
return $arrAllIps;
|
710 |
+
|
711 |
+
}
|
712 |
+
|
713 |
+
|
714 |
+
private static function compareIPV4($firstIpAddress, $secondIpAddress, $netMask)
|
715 |
+
{
|
716 |
+
return substr_compare(sprintf('%032b', ip2long($firstIpAddress)), sprintf('%032b', ip2long($secondIpAddress)), 0, $netMask);
|
717 |
+
}
|
718 |
+
|
719 |
+
private static function compareIPV6($firstIpAddress, $secondIpAddress, $netMask)
|
720 |
+
{
|
721 |
+
$bytesAddr = unpack("n*", self::ipAddressToBinary($secondIpAddress));
|
722 |
+
$bytesTest = unpack("n*", self::ipAddressToBinary($firstIpAddress));
|
723 |
+
|
724 |
+
for ($i = 1, $ceil = ceil($netMask / 16); $i <= $ceil; ++$i)
|
725 |
+
{
|
726 |
+
($left = $netMask - 16 * ($i-1)) > 16 ? $left = 16 : null;
|
727 |
+
|
728 |
+
$mask = ~(0xffff >> $left) & 0xffff;
|
729 |
+
|
730 |
+
if (($bytesAddr[$i] & $mask) != ($bytesTest[$i] & $mask))
|
731 |
+
return -1;
|
732 |
+
}
|
733 |
+
|
734 |
+
return 0;
|
735 |
+
}
|
736 |
+
|
737 |
+
public static function getCIDRFromNetMask($netMask, $shouldValidate = true)
|
738 |
+
{
|
739 |
+
if($shouldValidate)
|
740 |
+
{
|
741 |
+
$netMask = self::sanitizeIpAddress( $netMask );
|
742 |
+
if ( self::IP_VERSION_4 !== self::getIpAddressVersion( $netMask ) ) {
|
743 |
+
return - 1;
|
744 |
+
}
|
745 |
+
|
746 |
+
}
|
747 |
+
|
748 |
+
// $bits = 0;
|
749 |
+
// foreach(explode('.', $netMask) as $octect)
|
750 |
+
// {
|
751 |
+
// $bin = str_replace ( '0' , '' , decbin($octect));
|
752 |
+
// $bits += strlen($bin);
|
753 |
+
// }
|
754 |
+
//
|
755 |
+
// return $bits;
|
756 |
+
|
757 |
+
$bits = 32 - log( ( (ip2long($netMask)) ^ 4294967295) + 1, 2 );
|
758 |
+
|
759 |
+
return ($bits > 0 && (false !== filter_var($bits, FILTER_VALIDATE_INT))) ? $bits : -1;
|
760 |
+
|
761 |
+
}
|
762 |
+
|
763 |
+
private static function ipAddressToBitRepresentation($ipAddress, $ipVersion = null)
|
764 |
+
{
|
765 |
+
(null === $ipVersion) ? $ipVersion = self::getIpAddressVersion($ipAddress) : null;
|
766 |
+
|
767 |
+
if(-1 === $ipVersion)
|
768 |
+
return null;
|
769 |
+
|
770 |
+
if($ipVersion === self::IP_VERSION_4)
|
771 |
+
{
|
772 |
+
return base_convert(self::ipAddressToNumber($ipAddress, self::IP_VERSION_4), 10, 2);
|
773 |
+
}
|
774 |
+
|
775 |
+
$ipAddress = self::ipAddressToBinary($ipAddress, self::IP_VERSION_6);
|
776 |
+
|
777 |
+
$bits = 15;
|
778 |
+
$ipbin = '';
|
779 |
+
while ($bits >= 0)
|
780 |
+
{
|
781 |
+
$ipbin = sprintf('%08b', (ord($ipAddress[$bits]))) . $ipbin;
|
782 |
+
$bits--;
|
783 |
+
}
|
784 |
+
|
785 |
+
return $ipbin;
|
786 |
+
}
|
787 |
+
|
788 |
+
private static function ipAddressFromBitRepresentation($ipAddressBitRepresented)
|
789 |
+
{
|
790 |
+
if(!isset($ipAddressBitRepresented[32])) // is ipv4
|
791 |
+
{
|
792 |
+
return self::ipAddressFromNumber(base_convert($ipAddressBitRepresented, 2, 10), self::IP_VERSION_4);
|
793 |
+
}
|
794 |
+
|
795 |
+
$ipAddressBitRepresented = str_pad($ipAddressBitRepresented, 128, '0',STR_PAD_LEFT);
|
796 |
+
|
797 |
+
$bits = 0;
|
798 |
+
$ipv6 = '';
|
799 |
+
while ($bits <= 7)
|
800 |
+
{
|
801 |
+
$ipv6 .= dechex(bindec(substr($ipAddressBitRepresented , ($bits * 16) ,16))) . ':';
|
802 |
+
$bits++;
|
803 |
+
}
|
804 |
+
|
805 |
+
return $ipv6;
|
806 |
+
}
|
807 |
+
|
808 |
+
private static function hasIpV4Support()
|
809 |
+
{
|
810 |
+
static $hasSupport = null;
|
811 |
+
|
812 |
+
if(null !== $hasSupport)
|
813 |
+
return $hasSupport;
|
814 |
+
|
815 |
+
return $hasSupport = (!(PHP_VERSION_ID < 50300 && ('so' !== PHP_SHLIB_SUFFIX))) && @inet_pton('127.0.0.1');
|
816 |
+
}
|
817 |
+
|
818 |
+
private static function hasIPV6Support()
|
819 |
+
{
|
820 |
+
|
821 |
+
static $ipv6Supported = null;
|
822 |
+
|
823 |
+
if(null !== $ipv6Supported)
|
824 |
+
return $ipv6Supported;
|
825 |
+
|
826 |
+
return $ipv6Supported = self::hasIpV4Support() && ((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'));
|
827 |
+
}
|
828 |
+
|
829 |
+
|
830 |
+
public static function getCountryCode($ipAddress)
|
831 |
+
{
|
832 |
+
// static $countryCode = 0;
|
833 |
+
// if(0 !== $countryCode)
|
834 |
+
// return $countryCode;
|
835 |
+
//
|
836 |
+
// if( !empty( $_SERVER['HTTP_CF_IPCOUNTRY'] ) )
|
837 |
+
// {
|
838 |
+
// return $countryCode = sanitize_text_field( strtoupper( $_SERVER['HTTP_CF_IPCOUNTRY'] ) );
|
839 |
+
// }
|
840 |
+
|
841 |
+
$ipAddressVersion = MchGdbcIPUtils::getIpAddressVersion($ipAddress);
|
842 |
+
if( -1 === $ipAddressVersion)
|
843 |
+
return $countryCode = null;
|
844 |
+
|
845 |
+
$maxMindGeoIp = new MchMaxMindGeoIp();
|
846 |
+
|
847 |
+
try
|
848 |
+
{
|
849 |
+
$maxMindGeoIp->geoip_open( null, 0, $ipAddressVersion );
|
850 |
+
|
851 |
+
$countryCode = ( $ipAddressVersion === MchGdbcIPUtils::IP_VERSION_4 ? $maxMindGeoIp->geoip_country_code_by_addr( $ipAddress ) : $maxMindGeoIp->geoip_country_code_by_addr_v6( $ipAddress ) );
|
852 |
+
|
853 |
+
$maxMindGeoIp->geoip_close();
|
854 |
+
|
855 |
+
$countryCode = ! empty( $countryCode ) ? strtoupper( $countryCode ) : null;
|
856 |
+
}
|
857 |
+
catch(Exception $e)
|
858 |
+
{
|
859 |
+
$countryCode = null;
|
860 |
+
$maxMindGeoIp->geoip_close();
|
861 |
+
}
|
862 |
+
|
863 |
+
return $countryCode;
|
864 |
+
}
|
865 |
+
|
866 |
+
}
|
2.0/includes/utils/MchGdbcUtils.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class MchGdbcUtils
|
21 |
+
{
|
22 |
+
public static function stripNonAlphaCharacters($strText)
|
23 |
+
{
|
24 |
+
return preg_replace("/[^a-z]/i", '', $strText );
|
25 |
+
}
|
26 |
+
|
27 |
+
public static function replaceNonAlphaCharacters($strText, $token = '-')
|
28 |
+
{
|
29 |
+
$strText = str_replace(' ', '-', $strText);
|
30 |
+
$strText = preg_replace('/[^A-Za-z\-]/', '-', $strText);
|
31 |
+
$strText = preg_replace('/-+/', $token, trim($strText, '-'));
|
32 |
+
|
33 |
+
return $token === '-' ? $strText : str_replace('-', $token, $strText);
|
34 |
+
}
|
35 |
+
|
36 |
+
public static function replaceNonAlphaNumericCharacters($strText, $token = '-')
|
37 |
+
{
|
38 |
+
$strText = str_replace(' ', '-', $strText);
|
39 |
+
$strText = preg_replace('/[^A-Za-z0-9\-]/', '-', $strText);
|
40 |
+
$strText = preg_replace('/-+/', $token, trim($strText, '-'));
|
41 |
+
return $token === '-' ? $strText : str_replace('-', $token, $strText);
|
42 |
+
}
|
43 |
+
|
44 |
+
public static function stripLeftAndRightSlashes($str)
|
45 |
+
{
|
46 |
+
return trim($str, '/\\');
|
47 |
+
}
|
48 |
+
|
49 |
+
public static function stringStartsWith($string, $stringToFind)
|
50 |
+
{
|
51 |
+
return 0 === strpos($string, $stringToFind);
|
52 |
+
}
|
53 |
+
|
54 |
+
public static function stringEndsWith($string, $stringToFind, $caseSensitive = true)
|
55 |
+
{
|
56 |
+
return 0 === substr_compare($string, $stringToFind, -($count = strlen($stringToFind)) , $count, $caseSensitive ? false : true);
|
57 |
+
}
|
58 |
+
|
59 |
+
public static function normalizeNewLine($strText, $to = PHP_EOL )
|
60 |
+
{
|
61 |
+
if ( ! is_string($strText) )
|
62 |
+
return $strText;
|
63 |
+
|
64 |
+
$arrNewLine = array( "\r\n", "\r", "\n" );
|
65 |
+
|
66 |
+
if ( ! in_array($to, $arrNewLine) )
|
67 |
+
return $strText;
|
68 |
+
|
69 |
+
return str_replace($arrNewLine, $to, $strText);
|
70 |
+
}
|
71 |
+
|
72 |
+
/*
|
73 |
+
* $arr = array(
|
74 |
+
0 => array(1, 5),
|
75 |
+
1 => array(4, 8),
|
76 |
+
2 => array(19, 24),
|
77 |
+
3 => array(6, 9),
|
78 |
+
4 => array(11, 17),
|
79 |
+
);
|
80 |
+
|
81 |
+
should return
|
82 |
+
array(
|
83 |
+
0 => array(1, 9), // 1-5, 4-8 and 6-9 are overlapping, so they are merged
|
84 |
+
1 => array(11, 17),
|
85 |
+
2 => array(19, 24),
|
86 |
+
);
|
87 |
+
*/
|
88 |
+
public static function overlapIntervals(array $arrIntervals)
|
89 |
+
{
|
90 |
+
if(!isset($arrIntervals[1]))
|
91 |
+
return $arrIntervals;
|
92 |
+
|
93 |
+
$arrIntervals = array_values($arrIntervals);
|
94 |
+
usort($arrIntervals, array(__CLASS__, 'sortIntervals'));
|
95 |
+
$n = 0; $len = count($arrIntervals);
|
96 |
+
for ($i = 1; $i < $len; ++$i)
|
97 |
+
{
|
98 |
+
if ($arrIntervals[$i][0] > $arrIntervals[$n][1] + 1) {
|
99 |
+
$n = $i;
|
100 |
+
}
|
101 |
+
else
|
102 |
+
{
|
103 |
+
if ($arrIntervals[$n][1] < $arrIntervals[$i][1])
|
104 |
+
$arrIntervals[$n][1] = $arrIntervals[$i][1];
|
105 |
+
|
106 |
+
unset($arrIntervals[$i]);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
return array_values($arrIntervals);
|
111 |
+
}
|
112 |
+
|
113 |
+
private static function sortIntervals($firstArray, $secondArray)
|
114 |
+
{
|
115 |
+
return $firstArray[0] - $secondArray[0];
|
116 |
+
}
|
117 |
+
}
|
2.0/includes/utils/MchGdbcWpUtils.php
ADDED
@@ -0,0 +1,374 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
final class MchGdbcWpUtils
|
21 |
+
{
|
22 |
+
public static function getSiteNameById($siteId)
|
23 |
+
{
|
24 |
+
return get_blog_option($siteId, 'blogname', null);
|
25 |
+
}
|
26 |
+
|
27 |
+
public static function isUserLoggedIn()
|
28 |
+
{
|
29 |
+
return is_user_logged_in();
|
30 |
+
}
|
31 |
+
|
32 |
+
public static function isAdminLoggedIn()
|
33 |
+
{
|
34 |
+
return self::isSuperAdminLoggedIn();
|
35 |
+
}
|
36 |
+
|
37 |
+
public static function isSuperAdminLoggedIn()
|
38 |
+
{
|
39 |
+
return is_super_admin();
|
40 |
+
}
|
41 |
+
|
42 |
+
public static function isUserInDashboard()
|
43 |
+
{
|
44 |
+
return ( ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) && is_admin() );
|
45 |
+
}
|
46 |
+
|
47 |
+
public static function isAdminInDashboard()
|
48 |
+
{
|
49 |
+
return self::isAdminLoggedIn() && self::isUserInDashboard();
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
public static function isUserInNetworkDashboard()
|
54 |
+
{
|
55 |
+
return is_network_admin();
|
56 |
+
}
|
57 |
+
|
58 |
+
public static function isAdminInNetworkDashboard()
|
59 |
+
{
|
60 |
+
return self::isAdminLoggedIn() && self::isUserInNetworkDashboard();
|
61 |
+
}
|
62 |
+
|
63 |
+
public static function isAjaxRequest()
|
64 |
+
{
|
65 |
+
return ( defined( 'DOING_AJAX' ) && DOING_AJAX && is_admin());
|
66 |
+
}
|
67 |
+
public static function isXmlRpcRequest()
|
68 |
+
{
|
69 |
+
return defined('XMLRPC_REQUEST') && XMLRPC_REQUEST;
|
70 |
+
}
|
71 |
+
|
72 |
+
public static function isMultiSite()
|
73 |
+
{
|
74 |
+
return is_multisite();
|
75 |
+
}
|
76 |
+
|
77 |
+
public static function getAdminEmailAddress()
|
78 |
+
{
|
79 |
+
return get_bloginfo('admin_email');
|
80 |
+
}
|
81 |
+
|
82 |
+
public static function getAdminDisplayName()
|
83 |
+
{
|
84 |
+
if(! function_exists('get_user_by') )
|
85 |
+
require_once(ABSPATH .'wp-includes/pluggable.php');
|
86 |
+
|
87 |
+
$adminUser = get_user_by('email', get_bloginfo('admin_email')); //get_option( 'admin_email' );
|
88 |
+
if(false === $adminUser)
|
89 |
+
return null;
|
90 |
+
|
91 |
+
return !empty($adminUser->display_name) ? $adminUser->display_name : null;
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
public static function getAdminFullName()
|
96 |
+
{
|
97 |
+
if(! function_exists('get_user_by') )
|
98 |
+
require_once(ABSPATH .'wp-includes/pluggable.php');
|
99 |
+
|
100 |
+
$adminUser = get_user_by('email', get_bloginfo('admin_email')); //get_option( 'admin_email' );
|
101 |
+
if(false === $adminUser)
|
102 |
+
return null;
|
103 |
+
|
104 |
+
$adminFullName = empty($adminUser->first_name) ? '' : $adminUser->first_name;
|
105 |
+
$adminFullName .= empty($adminUser->last_name) ? '' : ' ' . $adminUser->last_name;
|
106 |
+
|
107 |
+
return trim($adminFullName);
|
108 |
+
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
public static function isPluginNetworkActivated($pluginFilePath)
|
113 |
+
{
|
114 |
+
if(!self::isMultiSite())
|
115 |
+
return false;
|
116 |
+
|
117 |
+
function_exists( 'is_plugin_active_for_network' ) || require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
118 |
+
|
119 |
+
return !empty($pluginFilePath) ? is_plugin_active_for_network(plugin_basename($pluginFilePath)) : false;
|
120 |
+
}
|
121 |
+
|
122 |
+
public static function isPermaLinkActivated()
|
123 |
+
{
|
124 |
+
return (bool)(get_option('permalink_structure'));
|
125 |
+
}
|
126 |
+
|
127 |
+
// public static function getServerRequestTime($withMicroSecondPrecision = false)
|
128 |
+
// {
|
129 |
+
// static $requestTime = null;
|
130 |
+
// if(null !== $requestTime && !$withMicroSecondPrecision)
|
131 |
+
// return $requestTime;
|
132 |
+
//
|
133 |
+
// if($withMicroSecondPrecision && isset($_SERVER['REQUEST_TIME_FLOAT'])){
|
134 |
+
// return $_SERVER['REQUEST_TIME_FLOAT'];
|
135 |
+
// }
|
136 |
+
//
|
137 |
+
// return $requestTime = ( empty($_SERVER['REQUEST_TIME']) ? time() : $_SERVER['REQUEST_TIME'] );
|
138 |
+
// }
|
139 |
+
|
140 |
+
public static function getAjaxUrl()
|
141 |
+
{
|
142 |
+
$ajaxUrl = admin_url('admin-ajax.php', self::isSslRequest() ? 'admin' : 'http');
|
143 |
+
|
144 |
+
if(0 === strpos(self::getCurrentPageUrl(), 'https') && 0 !== strpos($ajaxUrl, 'https'))
|
145 |
+
return str_replace('http:', 'https:', $ajaxUrl);
|
146 |
+
|
147 |
+
if(0 === strpos(self::getCurrentPageUrl(), 'http:') && 0 !== strpos($ajaxUrl, 'http:'))
|
148 |
+
return str_replace('https:', 'http:', $ajaxUrl);
|
149 |
+
|
150 |
+
return $ajaxUrl;
|
151 |
+
}
|
152 |
+
|
153 |
+
public static function isSslRequest()
|
154 |
+
{
|
155 |
+
static $isSsl = null;
|
156 |
+
if(null !== $isSsl)
|
157 |
+
return $isSsl;
|
158 |
+
|
159 |
+
if (isset($_SERVER['HTTP_CF_VISITOR']) && false !== strpos($_SERVER['HTTP_CF_VISITOR'], 'https'))
|
160 |
+
return $isSsl = true;
|
161 |
+
|
162 |
+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && stripos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0)
|
163 |
+
return $isSsl = true;
|
164 |
+
|
165 |
+
// if (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == 443)) # wp is_ssl() function is looking for port 443 as well
|
166 |
+
// return $isSsl = true;
|
167 |
+
|
168 |
+
if(isset($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] === 'on')
|
169 |
+
return $isSsl = true;
|
170 |
+
|
171 |
+
if(stripos(get_option('siteurl'), 'https') === 0)
|
172 |
+
return $isSsl = true;
|
173 |
+
|
174 |
+
return $isSsl = is_ssl();
|
175 |
+
}
|
176 |
+
|
177 |
+
public static function getCurrentPageUrl()
|
178 |
+
{
|
179 |
+
static $pageUrl = null;
|
180 |
+
|
181 |
+
if(null !== $pageUrl)
|
182 |
+
return $pageUrl;
|
183 |
+
|
184 |
+
if(is_front_page())
|
185 |
+
return $pageUrl = home_url('/', self::isSslRequest());
|
186 |
+
|
187 |
+
$pageUrl = self::isSslRequest() ? 'https://' : 'http://';
|
188 |
+
|
189 |
+
if(isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != 80))
|
190 |
+
$pageUrl .= $_SERVER['SERVER_NAME' ]. ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
|
191 |
+
else
|
192 |
+
$pageUrl .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
193 |
+
|
194 |
+
return $pageUrl = esc_url($pageUrl);
|
195 |
+
|
196 |
+
}
|
197 |
+
|
198 |
+
public static function getCurrentBlogLink()
|
199 |
+
{
|
200 |
+
return '<a href = "'. esc_url(get_bloginfo('url')) .'">' . get_bloginfo('name') . '</a>';
|
201 |
+
}
|
202 |
+
|
203 |
+
public static function getAllBlogIds()
|
204 |
+
{
|
205 |
+
global $wpdb;
|
206 |
+
|
207 |
+
if( empty($wpdb->blogs) )
|
208 |
+
return array();
|
209 |
+
|
210 |
+
return false === ( $arrBlogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'" ) ) ? array() : $arrBlogs;
|
211 |
+
|
212 |
+
}
|
213 |
+
|
214 |
+
|
215 |
+
public static function getDirectoryPathForCache()
|
216 |
+
{
|
217 |
+
$arrPossibleDirectoryPath = array(
|
218 |
+
//dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_temp',
|
219 |
+
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'cache',
|
220 |
+
WP_CONTENT_DIR,
|
221 |
+
);
|
222 |
+
|
223 |
+
$arrUploadDirInfo = wp_upload_dir();
|
224 |
+
if(MchGdbcWpUtils::isMultiSite()){
|
225 |
+
switch_to_blog( 1 );
|
226 |
+
$arrUploadDirInfo = wp_upload_dir();
|
227 |
+
restore_current_blog();
|
228 |
+
}
|
229 |
+
|
230 |
+
(!empty($arrUploadDirInfo['error']) && !empty($arrUploadDirInfo['basedir']))
|
231 |
+
? $arrPossibleDirectoryPath[] = $arrUploadDirInfo['basedir'] : null;
|
232 |
+
|
233 |
+
defined('WP_TEMP_DIR') ? $arrPossibleDirectoryPath[] = WP_TEMP_DIR : null;
|
234 |
+
|
235 |
+
$arrPossibleDirectoryPath[] = @sys_get_temp_dir();
|
236 |
+
$arrPossibleDirectoryPath[] = @ini_get('upload_tmp_dir');
|
237 |
+
|
238 |
+
!empty($_SERVER['TMP']) ? $arrPossibleDirectoryPath[] = $_SERVER['TMP'] : null;
|
239 |
+
!empty($_SERVER['TEMP']) ? $arrPossibleDirectoryPath[] = $_SERVER['TEMP'] : null;
|
240 |
+
!empty($_SERVER['TMPDIR']) ? $arrPossibleDirectoryPath[] = $_SERVER['TMPDIR'] : null;
|
241 |
+
|
242 |
+
$arrPossibleDirectoryPath[] = ('so' !== PHP_SHLIB_SUFFIX) ? 'C:/Temp' : '/tmp';
|
243 |
+
|
244 |
+
foreach($arrPossibleDirectoryPath as $directoryPath)
|
245 |
+
{
|
246 |
+
$tempDirPath = rtrim($directoryPath, '/\\');
|
247 |
+
if(self::isDirectoryUsable($tempDirPath, false) )
|
248 |
+
return $tempDirPath;
|
249 |
+
}
|
250 |
+
|
251 |
+
return null;
|
252 |
+
}
|
253 |
+
|
254 |
+
|
255 |
+
private static function isPathAccessible($path)
|
256 |
+
{
|
257 |
+
$openBaseDirSettings = strtolower( str_replace( '\\', '/', ini_get( 'open_basedir' ) ) );
|
258 |
+
if(empty($openBaseDirSettings))
|
259 |
+
return true;
|
260 |
+
|
261 |
+
$path = trailingslashit( strtolower( str_replace( '\\', '/', $path ) ) );
|
262 |
+
|
263 |
+
foreach( (array)explode( PATH_SEPARATOR, $openBaseDirSettings ) as $openPath)
|
264 |
+
{
|
265 |
+
if(empty($openPath))
|
266 |
+
continue;
|
267 |
+
|
268 |
+
if( 0 === strpos($path, $openPath) )
|
269 |
+
return true;
|
270 |
+
}
|
271 |
+
|
272 |
+
return false;
|
273 |
+
|
274 |
+
}
|
275 |
+
|
276 |
+
public static function isDirectoryUsable($directoryPath, $createIfNotExists = false)
|
277 |
+
{
|
278 |
+
PHP_VERSION_ID < 50300 ? @clearstatcache() : @clearstatcache(true, $directoryPath);
|
279 |
+
|
280 |
+
if(!@is_dir($directoryPath) || !@is_readable($directoryPath))
|
281 |
+
{
|
282 |
+
|
283 |
+
if(!self::isPathAccessible($directoryPath))
|
284 |
+
return false;
|
285 |
+
|
286 |
+
if(!self::createDirectory($directoryPath))
|
287 |
+
return false;
|
288 |
+
}
|
289 |
+
|
290 |
+
return function_exists('wp_is_writable') ? wp_is_writable($directoryPath) && @is_readable($directoryPath): @is_writable($directoryPath) && @is_readable($directoryPath);
|
291 |
+
}
|
292 |
+
|
293 |
+
// public static function lockFile($exclusiveLock = true)
|
294 |
+
// {
|
295 |
+
//
|
296 |
+
// }
|
297 |
+
|
298 |
+
|
299 |
+
public static function createDirectory($directoryPath)
|
300 |
+
{
|
301 |
+
return wp_mkdir_p(rtrim($directoryPath, '/\\'));
|
302 |
+
}
|
303 |
+
|
304 |
+
public static function writeContentToFile($content, $filePath, $exclusiveLock = true)
|
305 |
+
{
|
306 |
+
$filePointer = @fopen($filePath, 'wb'); // ab - for append
|
307 |
+
if(false === $filePointer)
|
308 |
+
return 0;
|
309 |
+
|
310 |
+
if( false === flock( $filePointer, ( $exclusiveLock ? LOCK_EX : LOCK_EX|LOCK_NB ) ) ){
|
311 |
+
fclose($filePointer);
|
312 |
+
return 0;
|
313 |
+
}
|
314 |
+
|
315 |
+
$bytesWritten = fwrite($filePointer, $content);
|
316 |
+
flock($filePointer, LOCK_UN);
|
317 |
+
fclose($filePointer);
|
318 |
+
|
319 |
+
return (false === $bytesWritten) ? 0 : $bytesWritten;
|
320 |
+
|
321 |
+
}
|
322 |
+
|
323 |
+
public static function deleteFile($filePath)
|
324 |
+
{
|
325 |
+
return @unlink( $filePath );
|
326 |
+
}
|
327 |
+
|
328 |
+
public static function fileExists($filePath, $clearStatCache = true)
|
329 |
+
{
|
330 |
+
if($clearStatCache) {
|
331 |
+
PHP_VERSION_ID < 50300 ? @clearstatcache() : @clearstatcache(true, $filePath);
|
332 |
+
}
|
333 |
+
|
334 |
+
return @file_exists($filePath);
|
335 |
+
}
|
336 |
+
|
337 |
+
public static function getDirectoryFiles($dirPath)
|
338 |
+
{
|
339 |
+
if( (! @is_dir($dirPath) ) || ( ! @is_readable($dirPath) ) )
|
340 |
+
return array();
|
341 |
+
|
342 |
+
$arrFiles = array();
|
343 |
+
|
344 |
+
foreach ( new DirectoryIterator ( $dirPath ) as $file ) {
|
345 |
+
if(!$file->isFile()) continue;
|
346 |
+
$arrFiles[] = $file->getPathName();
|
347 |
+
}
|
348 |
+
|
349 |
+
return $arrFiles;
|
350 |
+
}
|
351 |
+
|
352 |
+
public static function getDirectorySubDirectories($directoryPath)
|
353 |
+
{
|
354 |
+
$arrSubDirectories = glob(rtrim($directoryPath, '/\\') . '/*' , GLOB_ONLYDIR | GLOB_NOSORT);
|
355 |
+
|
356 |
+
return false === $arrSubDirectories ? array() : $arrSubDirectories;
|
357 |
+
}
|
358 |
+
|
359 |
+
public static function deleteDirectoryContent($directoryPath)
|
360 |
+
{
|
361 |
+
$directoryPath = rtrim($directoryPath, '/\\');
|
362 |
+
if(empty($directoryPath) || !@is_dir($directoryPath))
|
363 |
+
return;
|
364 |
+
|
365 |
+
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directoryPath), RecursiveIteratorIterator::CHILD_FIRST) as $fileInfo){
|
366 |
+
$fileInfo->isDir() ? @rmdir($fileInfo->getRealPath()): @unlink($fileInfo->getRealPath());
|
367 |
+
}
|
368 |
+
|
369 |
+
@rmdir($directoryPath);
|
370 |
+
|
371 |
+
}
|
372 |
+
|
373 |
+
private function __construct(){}
|
374 |
+
}
|
2.0/includes/vendor/MaxMind/GeoIP.dat
ADDED
Binary file
|
2.0/includes/vendor/MaxMind/GeoIPv6.dat
ADDED
Binary file
|
2.0/includes/vendor/MaxMind/MchMaxMindGeoIp.php
ADDED
@@ -0,0 +1,1593 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This class is a fork of WC_Geo_IP class from WooCommerce.
|
5 |
+
*/
|
6 |
+
|
7 |
+
|
8 |
+
class MchMaxMindGeoIp
|
9 |
+
{
|
10 |
+
const GEOIP_COUNTRY_BEGIN = 16776960;
|
11 |
+
const GEOIP_STATE_BEGIN_REV0 = 16700000;
|
12 |
+
const GEOIP_STATE_BEGIN_REV1 = 16000000;
|
13 |
+
const GEOIP_MEMORY_CACHE = 1;
|
14 |
+
const GEOIP_SHARED_MEMORY = 2;
|
15 |
+
const STRUCTURE_INFO_MAX_SIZE = 20;
|
16 |
+
const GEOIP_COUNTRY_EDITION = 1;
|
17 |
+
const GEOIP_PROXY_EDITION = 8;
|
18 |
+
const GEOIP_ASNUM_EDITION = 9;
|
19 |
+
const GEOIP_NETSPEED_EDITION = 10;
|
20 |
+
const GEOIP_REGION_EDITION_REV0 = 7;
|
21 |
+
const GEOIP_REGION_EDITION_REV1 = 3;
|
22 |
+
const GEOIP_CITY_EDITION_REV0 = 6;
|
23 |
+
const GEOIP_CITY_EDITION_REV1 = 2;
|
24 |
+
const GEOIP_ORG_EDITION = 5;
|
25 |
+
const GEOIP_ISP_EDITION = 4;
|
26 |
+
const SEGMENT_RECORD_LENGTH = 3;
|
27 |
+
const STANDARD_RECORD_LENGTH = 3;
|
28 |
+
const ORG_RECORD_LENGTH = 4;
|
29 |
+
const GEOIP_SHM_KEY = 0x4f415401;
|
30 |
+
const GEOIP_DOMAIN_EDITION = 11;
|
31 |
+
const GEOIP_COUNTRY_EDITION_V6 = 12;
|
32 |
+
const GEOIP_LOCATIONA_EDITION = 13;
|
33 |
+
const GEOIP_ACCURACYRADIUS_EDITION = 14;
|
34 |
+
const GEOIP_CITY_EDITION_REV1_V6 = 30;
|
35 |
+
const GEOIP_CITY_EDITION_REV0_V6 = 31;
|
36 |
+
const GEOIP_NETSPEED_EDITION_REV1 = 32;
|
37 |
+
const GEOIP_NETSPEED_EDITION_REV1_V6 = 33;
|
38 |
+
const GEOIP_USERTYPE_EDITION = 28;
|
39 |
+
const GEOIP_USERTYPE_EDITION_V6 = 29;
|
40 |
+
const GEOIP_ASNUM_EDITION_V6 = 21;
|
41 |
+
const GEOIP_ISP_EDITION_V6 = 22;
|
42 |
+
const GEOIP_ORG_EDITION_V6 = 23;
|
43 |
+
const GEOIP_DOMAIN_EDITION_V6 = 24;
|
44 |
+
public $flags;
|
45 |
+
public $filehandle;
|
46 |
+
public $memory_buffer;
|
47 |
+
public $databaseType;
|
48 |
+
public $databaseSegments;
|
49 |
+
public $record_length;
|
50 |
+
public $shmid;
|
51 |
+
public $GEOIP_COUNTRY_CODES = array(
|
52 |
+
'',
|
53 |
+
'AP',
|
54 |
+
'EU',
|
55 |
+
'AD',
|
56 |
+
'AE',
|
57 |
+
'AF',
|
58 |
+
'AG',
|
59 |
+
'AI',
|
60 |
+
'AL',
|
61 |
+
'AM',
|
62 |
+
'CW',
|
63 |
+
'AO',
|
64 |
+
'AQ',
|
65 |
+
'AR',
|
66 |
+
'AS',
|
67 |
+
'AT',
|
68 |
+
'AU',
|
69 |
+
'AW',
|
70 |
+
'AZ',
|
71 |
+
'BA',
|
72 |
+
'BB',
|
73 |
+
'BD',
|
74 |
+
'BE',
|
75 |
+
'BF',
|
76 |
+
'BG',
|
77 |
+
'BH',
|
78 |
+
'BI',
|
79 |
+
'BJ',
|
80 |
+
'BM',
|
81 |
+
'BN',
|
82 |
+
'BO',
|
83 |
+
'BR',
|
84 |
+
'BS',
|
85 |
+
'BT',
|
86 |
+
'BV',
|
87 |
+
'BW',
|
88 |
+
'BY',
|
89 |
+
'BZ',
|
90 |
+
'CA',
|
91 |
+
'CC',
|
92 |
+
'CD',
|
93 |
+
'CF',
|
94 |
+
'CG',
|
95 |
+
'CH',
|
96 |
+
'CI',
|
97 |
+
'CK',
|
98 |
+
'CL',
|
99 |
+
'CM',
|
100 |
+
'CN',
|
101 |
+
'CO',
|
102 |
+
'CR',
|
103 |
+
'CU',
|
104 |
+
'CV',
|
105 |
+
'CX',
|
106 |
+
'CY',
|
107 |
+
'CZ',
|
108 |
+
'DE',
|
109 |
+
'DJ',
|
110 |
+
'DK',
|
111 |
+
'DM',
|
112 |
+
'DO',
|
113 |
+
'DZ',
|
114 |
+
'EC',
|
115 |
+
'EE',
|
116 |
+
'EG',
|
117 |
+
'EH',
|
118 |
+
'ER',
|
119 |
+
'ES',
|
120 |
+
'ET',
|
121 |
+
'FI',
|
122 |
+
'FJ',
|
123 |
+
'FK',
|
124 |
+
'FM',
|
125 |
+
'FO',
|
126 |
+
'FR',
|
127 |
+
'SX',
|
128 |
+
'GA',
|
129 |
+
'GB',
|
130 |
+
'GD',
|
131 |
+
'GE',
|
132 |
+
'GF',
|
133 |
+
'GH',
|
134 |
+
'GI',
|
135 |
+
'GL',
|
136 |
+
'GM',
|
137 |
+
'GN',
|
138 |
+
'GP',
|
139 |
+
'GQ',
|
140 |
+
'GR',
|
141 |
+
'GS',
|
142 |
+
'GT',
|
143 |
+
'GU',
|
144 |
+
'GW',
|
145 |
+
'GY',
|
146 |
+
'HK',
|
147 |
+
'HM',
|
148 |
+
'HN',
|
149 |
+
'HR',
|
150 |
+
'HT',
|
151 |
+
'HU',
|
152 |
+
'ID',
|
153 |
+
'IE',
|
154 |
+
'IL',
|
155 |
+
'IN',
|
156 |
+
'IO',
|
157 |
+
'IQ',
|
158 |
+
'IR',
|
159 |
+
'IS',
|
160 |
+
'IT',
|
161 |
+
'JM',
|
162 |
+
'JO',
|
163 |
+
'JP',
|
164 |
+
'KE',
|
165 |
+
'KG',
|
166 |
+
'KH',
|
167 |
+
'KI',
|
168 |
+
'KM',
|
169 |
+
'KN',
|
170 |
+
'KP',
|
171 |
+
'KR',
|
172 |
+
'KW',
|
173 |
+
'KY',
|
174 |
+
'KZ',
|
175 |
+
'LA',
|
176 |
+
'LB',
|
177 |
+
'LC',
|
178 |
+
'LI',
|
179 |
+
'LK',
|
180 |
+
'LR',
|
181 |
+
'LS',
|
182 |
+
'LT',
|
183 |
+
'LU',
|
184 |
+
'LV',
|
185 |
+
'LY',
|
186 |
+
'MA',
|
187 |
+
'MC',
|
188 |
+
'MD',
|
189 |
+
'MG',
|
190 |
+
'MH',
|
191 |
+
'MK',
|
192 |
+
'ML',
|
193 |
+
'MM',
|
194 |
+
'MN',
|
195 |
+
'MO',
|
196 |
+
'MP',
|
197 |
+
'MQ',
|
198 |
+
'MR',
|
199 |
+
'MS',
|
200 |
+
'MT',
|
201 |
+
'MU',
|
202 |
+
'MV',
|
203 |
+
'MW',
|
204 |
+
'MX',
|
205 |
+
'MY',
|
206 |
+
'MZ',
|
207 |
+
'NA',
|
208 |
+
'NC',
|
209 |
+
'NE',
|
210 |
+
'NF',
|
211 |
+
'NG',
|
212 |
+
'NI',
|
213 |
+
'NL',
|
214 |
+
'NO',
|
215 |
+
'NP',
|
216 |
+
'NR',
|
217 |
+
'NU',
|
218 |
+
'NZ',
|
219 |
+
'OM',
|
220 |
+
'PA',
|
221 |
+
'PE',
|
222 |
+
'PF',
|
223 |
+
'PG',
|
224 |
+
'PH',
|
225 |
+
'PK',
|
226 |
+
'PL',
|
227 |
+
'PM',
|
228 |
+
'PN',
|
229 |
+
'PR',
|
230 |
+
'PS',
|
231 |
+
'PT',
|
232 |
+
'PW',
|
233 |
+
'PY',
|
234 |
+
'QA',
|
235 |
+
'RE',
|
236 |
+
'RO',
|
237 |
+
'RU',
|
238 |
+
'RW',
|
239 |
+
'SA',
|
240 |
+
'SB',
|
241 |
+
'SC',
|
242 |
+
'SD',
|
243 |
+
'SE',
|
244 |
+
'SG',
|
245 |
+
'SH',
|
246 |
+
'SI',
|
247 |
+
'SJ',
|
248 |
+
'SK',
|
249 |
+
'SL',
|
250 |
+
'SM',
|
251 |
+
'SN',
|
252 |
+
'SO',
|
253 |
+
'SR',
|
254 |
+
'ST',
|
255 |
+
'SV',
|
256 |
+
'SY',
|
257 |
+
'SZ',
|
258 |
+
'TC',
|
259 |
+
'TD',
|
260 |
+
'TF',
|
261 |
+
'TG',
|
262 |
+
'TH',
|
263 |
+
'TJ',
|
264 |
+
'TK',
|
265 |
+
'TM',
|
266 |
+
'TN',
|
267 |
+
'TO',
|
268 |
+
'TL',
|
269 |
+
'TR',
|
270 |
+
'TT',
|
271 |
+
'TV',
|
272 |
+
'TW',
|
273 |
+
'TZ',
|
274 |
+
'UA',
|
275 |
+
'UG',
|
276 |
+
'UM',
|
277 |
+
'US',
|
278 |
+
'UY',
|
279 |
+
'UZ',
|
280 |
+
'VA',
|
281 |
+
'VC',
|
282 |
+
'VE',
|
283 |
+
'VG',
|
284 |
+
'VI',
|
285 |
+
'VN',
|
286 |
+
'VU',
|
287 |
+
'WF',
|
288 |
+
'WS',
|
289 |
+
'YE',
|
290 |
+
'YT',
|
291 |
+
'RS',
|
292 |
+
'ZA',
|
293 |
+
'ZM',
|
294 |
+
'ME',
|
295 |
+
'ZW',
|
296 |
+
'A1',
|
297 |
+
'A2',
|
298 |
+
'O1',
|
299 |
+
'AX',
|
300 |
+
'GG',
|
301 |
+
'IM',
|
302 |
+
'JE',
|
303 |
+
'BL',
|
304 |
+
'MF',
|
305 |
+
'BQ',
|
306 |
+
'SS',
|
307 |
+
'O1'
|
308 |
+
);
|
309 |
+
public $GEOIP_COUNTRY_CODES3 = array(
|
310 |
+
'',
|
311 |
+
'AP',
|
312 |
+
'EU',
|
313 |
+
'AND',
|
314 |
+
'ARE',
|
315 |
+
'AFG',
|
316 |
+
'ATG',
|
317 |
+
'AIA',
|
318 |
+
'ALB',
|
319 |
+
'ARM',
|
320 |
+
'CUW',
|
321 |
+
'AGO',
|
322 |
+
'ATA',
|
323 |
+
'ARG',
|
324 |
+
'ASM',
|
325 |
+
'AUT',
|
326 |
+
'AUS',
|
327 |
+
'ABW',
|
328 |
+
'AZE',
|
329 |
+
'BIH',
|
330 |
+
'BRB',
|
331 |
+
'BGD',
|
332 |
+
'BEL',
|
333 |
+
'BFA',
|
334 |
+
'BGR',
|
335 |
+
'BHR',
|
336 |
+
'BDI',
|
337 |
+
'BEN',
|
338 |
+
'BMU',
|
339 |
+
'BRN',
|
340 |
+
'BOL',
|
341 |
+
'BRA',
|
342 |
+
'BHS',
|
343 |
+
'BTN',
|
344 |
+
'BVT',
|
345 |
+
'BWA',
|
346 |
+
'BLR',
|
347 |
+
'BLZ',
|
348 |
+
'CAN',
|
349 |
+
'CCK',
|
350 |
+
'COD',
|
351 |
+
'CAF',
|
352 |
+
'COG',
|
353 |
+
'CHE',
|
354 |
+
'CIV',
|
355 |
+
'COK',
|
356 |
+
'CHL',
|
357 |
+
'CMR',
|
358 |
+
'CHN',
|
359 |
+
'COL',
|
360 |
+
'CRI',
|
361 |
+
'CUB',
|
362 |
+
'CPV',
|
363 |
+
'CXR',
|
364 |
+
'CYP',
|
365 |
+
'CZE',
|
366 |
+
'DEU',
|
367 |
+
'DJI',
|
368 |
+
'DNK',
|
369 |
+
'DMA',
|
370 |
+
'DOM',
|
371 |
+
'DZA',
|
372 |
+
'ECU',
|
373 |
+
'EST',
|
374 |
+
'EGY',
|
375 |
+
'ESH',
|
376 |
+
'ERI',
|
377 |
+
'ESP',
|
378 |
+
'ETH',
|
379 |
+
'FIN',
|
380 |
+
'FJI',
|
381 |
+
'FLK',
|
382 |
+
'FSM',
|
383 |
+
'FRO',
|
384 |
+
'FRA',
|
385 |
+
'SXM',
|
386 |
+
'GAB',
|
387 |
+
'GBR',
|
388 |
+
'GRD',
|
389 |
+
'GEO',
|
390 |
+
'GUF',
|
391 |
+
'GHA',
|
392 |
+
'GIB',
|
393 |
+
'GRL',
|
394 |
+
'GMB',
|
395 |
+
'GIN',
|
396 |
+
'GLP',
|
397 |
+
'GNQ',
|
398 |
+
'GRC',
|
399 |
+
'SGS',
|
400 |
+
'GTM',
|
401 |
+
'GUM',
|
402 |
+
'GNB',
|
403 |
+
'GUY',
|
404 |
+
'HKG',
|
405 |
+
'HMD',
|
406 |
+
'HND',
|
407 |
+
'HRV',
|
408 |
+
'HTI',
|
409 |
+
'HUN',
|
410 |
+
'IDN',
|
411 |
+
'IRL',
|
412 |
+
'ISR',
|
413 |
+
'IND',
|
414 |
+
'IOT',
|
415 |
+
'IRQ',
|
416 |
+
'IRN',
|
417 |
+
'ISL',
|
418 |
+
'ITA',
|
419 |
+
'JAM',
|
420 |
+
'JOR',
|
421 |
+
'JPN',
|
422 |
+
'KEN',
|
423 |
+
'KGZ',
|
424 |
+
'KHM',
|
425 |
+
'KIR',
|
426 |
+
'COM',
|
427 |
+
'KNA',
|
428 |
+
'PRK',
|
429 |
+
'KOR',
|
430 |
+
'KWT',
|
431 |
+
'CYM',
|
432 |
+
'KAZ',
|
433 |
+
'LAO',
|
434 |
+
'LBN',
|
435 |
+
'LCA',
|
436 |
+
'LIE',
|
437 |
+
'LKA',
|
438 |
+
'LBR',
|
439 |
+
'LSO',
|
440 |
+
'LTU',
|
441 |
+
'LUX',
|
442 |
+
'LVA',
|
443 |
+
'LBY',
|
444 |
+
'MAR',
|
445 |
+
'MCO',
|
446 |
+
'MDA',
|
447 |
+
'MDG',
|
448 |
+
'MHL',
|
449 |
+
'MKD',
|
450 |
+
'MLI',
|
451 |
+
'MMR',
|
452 |
+
'MNG',
|
453 |
+
'MAC',
|
454 |
+
'MNP',
|
455 |
+
'MTQ',
|
456 |
+
'MRT',
|
457 |
+
'MSR',
|
458 |
+
'MLT',
|
459 |
+
'MUS',
|
460 |
+
'MDV',
|
461 |
+
'MWI',
|
462 |
+
'MEX',
|
463 |
+
'MYS',
|
464 |
+
'MOZ',
|
465 |
+
'NAM',
|
466 |
+
'NCL',
|
467 |
+
'NER',
|
468 |
+
'NFK',
|
469 |
+
'NGA',
|
470 |
+
'NIC',
|
471 |
+
'NLD',
|
472 |
+
'NOR',
|
473 |
+
'NPL',
|
474 |
+
'NRU',
|
475 |
+
'NIU',
|
476 |
+
'NZL',
|
477 |
+
'OMN',
|
478 |
+
'PAN',
|
479 |
+
'PER',
|
480 |
+
'PYF',
|
481 |
+
'PNG',
|
482 |
+
'PHL',
|
483 |
+
'PAK',
|
484 |
+
'POL',
|
485 |
+
'SPM',
|
486 |
+
'PCN',
|
487 |
+
'PRI',
|
488 |
+
'PSE',
|
489 |
+
'PRT',
|
490 |
+
'PLW',
|
491 |
+
'PRY',
|
492 |
+
'QAT',
|
493 |
+
'REU',
|
494 |
+
'ROU',
|
495 |
+
'RUS',
|
496 |
+
'RWA',
|
497 |
+
'SAU',
|
498 |
+
'SLB',
|
499 |
+
'SYC',
|
500 |
+
'SDN',
|
501 |
+
'SWE',
|
502 |
+
'SGP',
|
503 |
+
'SHN',
|
504 |
+
'SVN',
|
505 |
+
'SJM',
|
506 |
+
'SVK',
|
507 |
+
'SLE',
|
508 |
+
'SMR',
|
509 |
+
'SEN',
|
510 |
+
'SOM',
|
511 |
+
'SUR',
|
512 |
+
'STP',
|
513 |
+
'SLV',
|
514 |
+
'SYR',
|
515 |
+
'SWZ',
|
516 |
+
'TCA',
|
517 |
+
'TCD',
|
518 |
+
'ATF',
|
519 |
+
'TGO',
|
520 |
+
'THA',
|
521 |
+
'TJK',
|
522 |
+
'TKL',
|
523 |
+
'TKM',
|
524 |
+
'TUN',
|
525 |
+
'TON',
|
526 |
+
'TLS',
|
527 |
+
'TUR',
|
528 |
+
'TTO',
|
529 |
+
'TUV',
|
530 |
+
'TWN',
|
531 |
+
'TZA',
|
532 |
+
'UKR',
|
533 |
+
'UGA',
|
534 |
+
'UMI',
|
535 |
+
'USA',
|
536 |
+
'URY',
|
537 |
+
'UZB',
|
538 |
+
'VAT',
|
539 |
+
'VCT',
|
540 |
+
'VEN',
|
541 |
+
'VGB',
|
542 |
+
'VIR',
|
543 |
+
'VNM',
|
544 |
+
'VUT',
|
545 |
+
'WLF',
|
546 |
+
'WSM',
|
547 |
+
'YEM',
|
548 |
+
'MYT',
|
549 |
+
'SRB',
|
550 |
+
'ZAF',
|
551 |
+
'ZMB',
|
552 |
+
'MNE',
|
553 |
+
'ZWE',
|
554 |
+
'A1',
|
555 |
+
'A2',
|
556 |
+
'O1',
|
557 |
+
'ALA',
|
558 |
+
'GGY',
|
559 |
+
'IMN',
|
560 |
+
'JEY',
|
561 |
+
'BLM',
|
562 |
+
'MAF',
|
563 |
+
'BES',
|
564 |
+
'SSD',
|
565 |
+
'O1'
|
566 |
+
);
|
567 |
+
public $GEOIP_COUNTRY_NAMES = array(
|
568 |
+
'',
|
569 |
+
'Asia/Pacific Region',
|
570 |
+
'Europe',
|
571 |
+
'Andorra',
|
572 |
+
'United Arab Emirates',
|
573 |
+
'Afghanistan',
|
574 |
+
'Antigua and Barbuda',
|
575 |
+
'Anguilla',
|
576 |
+
'Albania',
|
577 |
+
'Armenia',
|
578 |
+
'Curacao',
|
579 |
+
'Angola',
|
580 |
+
'Antarctica',
|
581 |
+
'Argentina',
|
582 |
+
'American Samoa',
|
583 |
+
'Austria',
|
584 |
+
'Australia',
|
585 |
+
'Aruba',
|
586 |
+
'Azerbaijan',
|
587 |
+
'Bosnia and Herzegovina',
|
588 |
+
'Barbados',
|
589 |
+
'Bangladesh',
|
590 |
+
'Belgium',
|
591 |
+
'Burkina Faso',
|
592 |
+
'Bulgaria',
|
593 |
+
'Bahrain',
|
594 |
+
'Burundi',
|
595 |
+
'Benin',
|
596 |
+
'Bermuda',
|
597 |
+
'Brunei Darussalam',
|
598 |
+
'Bolivia',
|
599 |
+
'Brazil',
|
600 |
+
'Bahamas',
|
601 |
+
'Bhutan',
|
602 |
+
'Bouvet Island',
|
603 |
+
'Botswana',
|
604 |
+
'Belarus',
|
605 |
+
'Belize',
|
606 |
+
'Canada',
|
607 |
+
'Cocos (Keeling) Islands',
|
608 |
+
'Congo, The Democratic Republic of the',
|
609 |
+
'Central African Republic',
|
610 |
+
'Congo',
|
611 |
+
'Switzerland',
|
612 |
+
"Cote D'Ivoire",
|
613 |
+
'Cook Islands',
|
614 |
+
'Chile',
|
615 |
+
'Cameroon',
|
616 |
+
'China',
|
617 |
+
'Colombia',
|
618 |
+
'Costa Rica',
|
619 |
+
'Cuba',
|
620 |
+
'Cape Verde',
|
621 |
+
'Christmas Island',
|
622 |
+
'Cyprus',
|
623 |
+
'Czech Republic',
|
624 |
+
'Germany',
|
625 |
+
'Djibouti',
|
626 |
+
'Denmark',
|
627 |
+
'Dominica',
|
628 |
+
'Dominican Republic',
|
629 |
+
'Algeria',
|
630 |
+
'Ecuador',
|
631 |
+
'Estonia',
|
632 |
+
'Egypt',
|
633 |
+
'Western Sahara',
|
634 |
+
'Eritrea',
|
635 |
+
'Spain',
|
636 |
+
'Ethiopia',
|
637 |
+
'Finland',
|
638 |
+
'Fiji',
|
639 |
+
'Falkland Islands (Malvinas)',
|
640 |
+
'Micronesia, Federated States of',
|
641 |
+
'Faroe Islands',
|
642 |
+
'France',
|
643 |
+
'Sint Maarten (Dutch part)',
|
644 |
+
'Gabon',
|
645 |
+
'United Kingdom',
|
646 |
+
'Grenada',
|
647 |
+
'Georgia',
|
648 |
+
'French Guiana',
|
649 |
+
'Ghana',
|
650 |
+
'Gibraltar',
|
651 |
+
'Greenland',
|
652 |
+
'Gambia',
|
653 |
+
'Guinea',
|
654 |
+
'Guadeloupe',
|
655 |
+
'Equatorial Guinea',
|
656 |
+
'Greece',
|
657 |
+
'South Georgia and the South Sandwich Islands',
|
658 |
+
'Guatemala',
|
659 |
+
'Guam',
|
660 |
+
'Guinea-Bissau',
|
661 |
+
'Guyana',
|
662 |
+
'Hong Kong',
|
663 |
+
'Heard Island and McDonald Islands',
|
664 |
+
'Honduras',
|
665 |
+
'Croatia',
|
666 |
+
'Haiti',
|
667 |
+
'Hungary',
|
668 |
+
'Indonesia',
|
669 |
+
'Ireland',
|
670 |
+
'Israel',
|
671 |
+
'India',
|
672 |
+
'British Indian Ocean Territory',
|
673 |
+
'Iraq',
|
674 |
+
'Iran, Islamic Republic of',
|
675 |
+
'Iceland',
|
676 |
+
'Italy',
|
677 |
+
'Jamaica',
|
678 |
+
'Jordan',
|
679 |
+
'Japan',
|
680 |
+
'Kenya',
|
681 |
+
'Kyrgyzstan',
|
682 |
+
'Cambodia',
|
683 |
+
'Kiribati',
|
684 |
+
'Comoros',
|
685 |
+
'Saint Kitts and Nevis',
|
686 |
+
"Korea, Democratic People's Republic of",
|
687 |
+
'Korea, Republic of',
|
688 |
+
'Kuwait',
|
689 |
+
'Cayman Islands',
|
690 |
+
'Kazakhstan',
|
691 |
+
"Lao People's Democratic Republic",
|
692 |
+
'Lebanon',
|
693 |
+
'Saint Lucia',
|
694 |
+
'Liechtenstein',
|
695 |
+
'Sri Lanka',
|
696 |
+
'Liberia',
|
697 |
+
'Lesotho',
|
698 |
+
'Lithuania',
|
699 |
+
'Luxembourg',
|
700 |
+
'Latvia',
|
701 |
+
'Libya',
|
702 |
+
'Morocco',
|
703 |
+
'Monaco',
|
704 |
+
'Moldova, Republic of',
|
705 |
+
'Madagascar',
|
706 |
+
'Marshall Islands',
|
707 |
+
'Macedonia',
|
708 |
+
'Mali',
|
709 |
+
'Myanmar',
|
710 |
+
'Mongolia',
|
711 |
+
'Macau',
|
712 |
+
'Northern Mariana Islands',
|
713 |
+
'Martinique',
|
714 |
+
'Mauritania',
|
715 |
+
'Montserrat',
|
716 |
+
'Malta',
|
717 |
+
'Mauritius',
|
718 |
+
'Maldives',
|
719 |
+
'Malawi',
|
720 |
+
'Mexico',
|
721 |
+
'Malaysia',
|
722 |
+
'Mozambique',
|
723 |
+
'Namibia',
|
724 |
+
'New Caledonia',
|
725 |
+
'Niger',
|
726 |
+
'Norfolk Island',
|
727 |
+
'Nigeria',
|
728 |
+
'Nicaragua',
|
729 |
+
'Netherlands',
|
730 |
+
'Norway',
|
731 |
+
'Nepal',
|
732 |
+
'Nauru',
|
733 |
+
'Niue',
|
734 |
+
'New Zealand',
|
735 |
+
'Oman',
|
736 |
+
'Panama',
|
737 |
+
'Peru',
|
738 |
+
'French Polynesia',
|
739 |
+
'Papua New Guinea',
|
740 |
+
'Philippines',
|
741 |
+
'Pakistan',
|
742 |
+
'Poland',
|
743 |
+
'Saint Pierre and Miquelon',
|
744 |
+
'Pitcairn Islands',
|
745 |
+
'Puerto Rico',
|
746 |
+
'Palestinian Territory',
|
747 |
+
'Portugal',
|
748 |
+
'Palau',
|
749 |
+
'Paraguay',
|
750 |
+
'Qatar',
|
751 |
+
'Reunion',
|
752 |
+
'Romania',
|
753 |
+
'Russian Federation',
|
754 |
+
'Rwanda',
|
755 |
+
'Saudi Arabia',
|
756 |
+
'Solomon Islands',
|
757 |
+
'Seychelles',
|
758 |
+
'Sudan',
|
759 |
+
'Sweden',
|
760 |
+
'Singapore',
|
761 |
+
'Saint Helena',
|
762 |
+
'Slovenia',
|
763 |
+
'Svalbard and Jan Mayen',
|
764 |
+
'Slovakia',
|
765 |
+
'Sierra Leone',
|
766 |
+
'San Marino',
|
767 |
+
'Senegal',
|
768 |
+
'Somalia',
|
769 |
+
'Suriname',
|
770 |
+
'Sao Tome and Principe',
|
771 |
+
'El Salvador',
|
772 |
+
'Syrian Arab Republic',
|
773 |
+
'Swaziland',
|
774 |
+
'Turks and Caicos Islands',
|
775 |
+
'Chad',
|
776 |
+
'French Southern Territories',
|
777 |
+
'Togo',
|
778 |
+
'Thailand',
|
779 |
+
'Tajikistan',
|
780 |
+
'Tokelau',
|
781 |
+
'Turkmenistan',
|
782 |
+
'Tunisia',
|
783 |
+
'Tonga',
|
784 |
+
'Timor-Leste',
|
785 |
+
'Turkey',
|
786 |
+
'Trinidad and Tobago',
|
787 |
+
'Tuvalu',
|
788 |
+
'Taiwan',
|
789 |
+
'Tanzania, United Republic of',
|
790 |
+
'Ukraine',
|
791 |
+
'Uganda',
|
792 |
+
'United States Minor Outlying Islands',
|
793 |
+
'United States',
|
794 |
+
'Uruguay',
|
795 |
+
'Uzbekistan',
|
796 |
+
'Holy See (Vatican City State)',
|
797 |
+
'Saint Vincent and the Grenadines',
|
798 |
+
'Venezuela',
|
799 |
+
'Virgin Islands, British',
|
800 |
+
'Virgin Islands, U.S.',
|
801 |
+
'Vietnam',
|
802 |
+
'Vanuatu',
|
803 |
+
'Wallis and Futuna',
|
804 |
+
'Samoa',
|
805 |
+
'Yemen',
|
806 |
+
'Mayotte',
|
807 |
+
'Serbia',
|
808 |
+
'South Africa',
|
809 |
+
'Zambia',
|
810 |
+
'Montenegro',
|
811 |
+
'Zimbabwe',
|
812 |
+
'Anonymous Proxy',
|
813 |
+
'Satellite Provider',
|
814 |
+
'Other',
|
815 |
+
'Aland Islands',
|
816 |
+
'Guernsey',
|
817 |
+
'Isle of Man',
|
818 |
+
'Jersey',
|
819 |
+
'Saint Barthelemy',
|
820 |
+
'Saint Martin',
|
821 |
+
'Bonaire, Saint Eustatius and Saba',
|
822 |
+
'South Sudan',
|
823 |
+
'Other'
|
824 |
+
);
|
825 |
+
public $GEOIP_CONTINENT_CODES = array(
|
826 |
+
'--',
|
827 |
+
'AS',
|
828 |
+
'EU',
|
829 |
+
'EU',
|
830 |
+
'AS',
|
831 |
+
'AS',
|
832 |
+
'NA',
|
833 |
+
'NA',
|
834 |
+
'EU',
|
835 |
+
'AS',
|
836 |
+
'NA',
|
837 |
+
'AF',
|
838 |
+
'AN',
|
839 |
+
'SA',
|
840 |
+
'OC',
|
841 |
+
'EU',
|
842 |
+
'OC',
|
843 |
+
'NA',
|
844 |
+
'AS',
|
845 |
+
'EU',
|
846 |
+
'NA',
|
847 |
+
'AS',
|
848 |
+
'EU',
|
849 |
+
'AF',
|
850 |
+
'EU',
|
851 |
+
'AS',
|
852 |
+
'AF',
|
853 |
+
'AF',
|
854 |
+
'NA',
|
855 |
+
'AS',
|
856 |
+
'SA',
|
857 |
+
'SA',
|
858 |
+
'NA',
|
859 |
+
'AS',
|
860 |
+
'AN',
|
861 |
+
'AF',
|
862 |
+
'EU',
|
863 |
+
'NA',
|
864 |
+
'NA',
|
865 |
+
'AS',
|
866 |
+
'AF',
|
867 |
+
'AF',
|
868 |
+
'AF',
|
869 |
+
'EU',
|
870 |
+
'AF',
|
871 |
+
'OC',
|
872 |
+
'SA',
|
873 |
+
'AF',
|
874 |
+
'AS',
|
875 |
+
'SA',
|
876 |
+
'NA',
|
877 |
+
'NA',
|
878 |
+
'AF',
|
879 |
+
'AS',
|
880 |
+
'AS',
|
881 |
+
'EU',
|
882 |
+
'EU',
|
883 |
+
'AF',
|
884 |
+
'EU',
|
885 |
+
'NA',
|
886 |
+
'NA',
|
887 |
+
'AF',
|
888 |
+
'SA',
|
889 |
+
'EU',
|
890 |
+
'AF',
|
891 |
+
'AF',
|
892 |
+
'AF',
|
893 |
+
'EU',
|
894 |
+
'AF',
|
895 |
+
'EU',
|
896 |
+
'OC',
|
897 |
+
'SA',
|
898 |
+
'OC',
|
899 |
+
'EU',
|
900 |
+
'EU',
|
901 |
+
'NA',
|
902 |
+
'AF',
|
903 |
+
'EU',
|
904 |
+
'NA',
|
905 |
+
'AS',
|
906 |
+
'SA',
|
907 |
+
'AF',
|
908 |
+
'EU',
|
909 |
+
'NA',
|
910 |
+
'AF',
|
911 |
+
'AF',
|
912 |
+
'NA',
|
913 |
+
'AF',
|
914 |
+
'EU',
|
915 |
+
'AN',
|
916 |
+
'NA',
|
917 |
+
'OC',
|
918 |
+
'AF',
|
919 |
+
'SA',
|
920 |
+
'AS',
|
921 |
+
'AN',
|
922 |
+
'NA',
|
923 |
+
'EU',
|
924 |
+
'NA',
|
925 |
+
'EU',
|
926 |
+
'AS',
|
927 |
+
'EU',
|
928 |
+
'AS',
|
929 |
+
'AS',
|
930 |
+
'AS',
|
931 |
+
'AS',
|
932 |
+
'AS',
|
933 |
+
'EU',
|
934 |
+
'EU',
|
935 |
+
'NA',
|
936 |
+
'AS',
|
937 |
+
'AS',
|
938 |
+
'AF',
|
939 |
+
'AS',
|
940 |
+
'AS',
|
941 |
+
'OC',
|
942 |
+
'AF',
|
943 |
+
'NA',
|
944 |
+
'AS',
|
945 |
+
'AS',
|
946 |
+
'AS',
|
947 |
+
'NA',
|
948 |
+
'AS',
|
949 |
+
'AS',
|
950 |
+
'AS',
|
951 |
+
'NA',
|
952 |
+
'EU',
|
953 |
+
'AS',
|
954 |
+
'AF',
|
955 |
+
'AF',
|
956 |
+
'EU',
|
957 |
+
'EU',
|
958 |
+
'EU',
|
959 |
+
'AF',
|
960 |
+
'AF',
|
961 |
+
'EU',
|
962 |
+
'EU',
|
963 |
+
'AF',
|
964 |
+
'OC',
|
965 |
+
'EU',
|
966 |
+
'AF',
|
967 |
+
'AS',
|
968 |
+
'AS',
|
969 |
+
'AS',
|
970 |
+
'OC',
|
971 |
+
'NA',
|
972 |
+
'AF',
|
973 |
+
'NA',
|
974 |
+
'EU',
|
975 |
+
'AF',
|
976 |
+
'AS',
|
977 |
+
'AF',
|
978 |
+
'NA',
|
979 |
+
'AS',
|
980 |
+
'AF',
|
981 |
+
'AF',
|
982 |
+
'OC',
|
983 |
+
'AF',
|
984 |
+
'OC',
|
985 |
+
'AF',
|
986 |
+
'NA',
|
987 |
+
'EU',
|
988 |
+
'EU',
|
989 |
+
'AS',
|
990 |
+
'OC',
|
991 |
+
'OC',
|
992 |
+
'OC',
|
993 |
+
'AS',
|
994 |
+
'NA',
|
995 |
+
'SA',
|
996 |
+
'OC',
|
997 |
+
'OC',
|
998 |
+
'AS',
|
999 |
+
'AS',
|
1000 |
+
'EU',
|
1001 |
+
'NA',
|
1002 |
+
'OC',
|
1003 |
+
'NA',
|
1004 |
+
'AS',
|
1005 |
+
'EU',
|
1006 |
+
'OC',
|
1007 |
+
'SA',
|
1008 |
+
'AS',
|
1009 |
+
'AF',
|
1010 |
+
'EU',
|
1011 |
+
'EU',
|
1012 |
+
'AF',
|
1013 |
+
'AS',
|
1014 |
+
'OC',
|
1015 |
+
'AF',
|
1016 |
+
'AF',
|
1017 |
+
'EU',
|
1018 |
+
'AS',
|
1019 |
+
'AF',
|
1020 |
+
'EU',
|
1021 |
+
'EU',
|
1022 |
+
'EU',
|
1023 |
+
'AF',
|
1024 |
+
'EU',
|
1025 |
+
'AF',
|
1026 |
+
'AF',
|
1027 |
+
'SA',
|
1028 |
+
'AF',
|
1029 |
+
'NA',
|
1030 |
+
'AS',
|
1031 |
+
'AF',
|
1032 |
+
'NA',
|
1033 |
+
'AF',
|
1034 |
+
'AN',
|
1035 |
+
'AF',
|
1036 |
+
'AS',
|
1037 |
+
'AS',
|
1038 |
+
'OC',
|
1039 |
+
'AS',
|
1040 |
+
'AF',
|
1041 |
+
'OC',
|
1042 |
+
'AS',
|
1043 |
+
'EU',
|
1044 |
+
'NA',
|
1045 |
+
'OC',
|
1046 |
+
'AS',
|
1047 |
+
'AF',
|
1048 |
+
'EU',
|
1049 |
+
'AF',
|
1050 |
+
'OC',
|
1051 |
+
'NA',
|
1052 |
+
'SA',
|
1053 |
+
'AS',
|
1054 |
+
'EU',
|
1055 |
+
'NA',
|
1056 |
+
'SA',
|
1057 |
+
'NA',
|
1058 |
+
'NA',
|
1059 |
+
'AS',
|
1060 |
+
'OC',
|
1061 |
+
'OC',
|
1062 |
+
'OC',
|
1063 |
+
'AS',
|
1064 |
+
'AF',
|
1065 |
+
'EU',
|
1066 |
+
'AF',
|
1067 |
+
'AF',
|
1068 |
+
'EU',
|
1069 |
+
'AF',
|
1070 |
+
'--',
|
1071 |
+
'--',
|
1072 |
+
'--',
|
1073 |
+
'EU',
|
1074 |
+
'EU',
|
1075 |
+
'EU',
|
1076 |
+
'EU',
|
1077 |
+
'NA',
|
1078 |
+
'NA',
|
1079 |
+
'NA',
|
1080 |
+
'AF',
|
1081 |
+
'--'
|
1082 |
+
);
|
1083 |
+
/**
|
1084 |
+
* Open geoip file
|
1085 |
+
*
|
1086 |
+
* @param string $filename
|
1087 |
+
* @param int $flags
|
1088 |
+
*/
|
1089 |
+
public function geoip_open( $filename, $flags = 0, $ipVersion = MchGdbcIPUtils::IP_VERSION_4) {
|
1090 |
+
$this->flags = $flags;
|
1091 |
+
if ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
|
1092 |
+
$this->shmid = @shmop_open( self::GEOIP_SHM_KEY, "a", 0, 0 );
|
1093 |
+
}
|
1094 |
+
else
|
1095 |
+
{
|
1096 |
+
if(null === $filename)
|
1097 |
+
{
|
1098 |
+
$filename = dirname(__FILE__) . ( ($ipVersion === MchGdbcIPUtils::IP_VERSION_4) ? '/GeoIP.dat' : '/GeoIPv6.dat' );
|
1099 |
+
}
|
1100 |
+
|
1101 |
+
$this->filehandle = @fopen( $filename, 'rb' ); //or trigger_error( "GeoIP API: Can not open $filename\n", E_USER_ERROR );
|
1102 |
+
if(false === $this->filehandle)
|
1103 |
+
throw new Exception("GeoIP API: Can not open $filename\n");
|
1104 |
+
|
1105 |
+
if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
|
1106 |
+
$s_array = fstat( $this->filehandle );
|
1107 |
+
$this->memory_buffer = fread( $this->filehandle, $s_array['size'] );
|
1108 |
+
}
|
1109 |
+
}
|
1110 |
+
|
1111 |
+
$this->_setup_segments();
|
1112 |
+
}
|
1113 |
+
/**
|
1114 |
+
* Setup segments
|
1115 |
+
*
|
1116 |
+
* @return WC_Geo_IP instance
|
1117 |
+
*/
|
1118 |
+
private function _setup_segments() {
|
1119 |
+
$this->databaseType = self::GEOIP_COUNTRY_EDITION;
|
1120 |
+
$this->record_length = self::STANDARD_RECORD_LENGTH;
|
1121 |
+
if ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
|
1122 |
+
$offset = @shmop_size( $this->shmid ) - 3;
|
1123 |
+
for ( $i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++ ) {
|
1124 |
+
$delim = @shmop_read( $this->shmid, $offset, 3 );
|
1125 |
+
$offset += 3;
|
1126 |
+
if ( $delim == ( chr( 255 ) . chr( 255 ) . chr( 255 ) ) ) {
|
1127 |
+
$this->databaseType = ord( @shmop_read( $this->shmid, $offset, 1 ) );
|
1128 |
+
if ( $this->databaseType >= 106 ) {
|
1129 |
+
$this->databaseType -= 105;
|
1130 |
+
}
|
1131 |
+
$offset++;
|
1132 |
+
if ( $this->databaseType == self::GEOIP_REGION_EDITION_REV0 ) {
|
1133 |
+
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV0;
|
1134 |
+
} elseif ( $this->databaseType == self::GEOIP_REGION_EDITION_REV1 ) {
|
1135 |
+
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV1;
|
1136 |
+
} elseif ( ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0 )
|
1137 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1 )
|
1138 |
+
|| ( $this->databaseType == self::GEOIP_ORG_EDITION )
|
1139 |
+
|| ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
|
1140 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
|
1141 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
|
1142 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION )
|
1143 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
|
1144 |
+
|| ( $this->databaseType == self::GEOIP_USERTYPE_EDITION )
|
1145 |
+
|| ( $this->databaseType == self::GEOIP_USERTYPE_EDITION_V6 )
|
1146 |
+
|| ( $this->databaseType == self::GEOIP_LOCATIONA_EDITION )
|
1147 |
+
|| ( $this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION )
|
1148 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 )
|
1149 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 )
|
1150 |
+
|| ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1 )
|
1151 |
+
|| ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6 )
|
1152 |
+
|| ( $this->databaseType == self::GEOIP_ASNUM_EDITION )
|
1153 |
+
|| ( $this->databaseType == self::GEOIP_ASNUM_EDITION_V6 )
|
1154 |
+
) {
|
1155 |
+
$this->databaseSegments = 0;
|
1156 |
+
$buf = @shmop_read( $this->shmid, $offset, self::SEGMENT_RECORD_LENGTH );
|
1157 |
+
for ( $j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++ ) {
|
1158 |
+
$this->databaseSegments += ( ord( $buf[ $j ] ) << ( $j * 8 ) );
|
1159 |
+
}
|
1160 |
+
if ( ( $this->databaseType == self::GEOIP_ORG_EDITION )
|
1161 |
+
|| ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
|
1162 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
|
1163 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
|
1164 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION )
|
1165 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
|
1166 |
+
) {
|
1167 |
+
$this->record_length = self::ORG_RECORD_LENGTH;
|
1168 |
+
}
|
1169 |
+
}
|
1170 |
+
break;
|
1171 |
+
} else {
|
1172 |
+
$offset -= 4;
|
1173 |
+
}
|
1174 |
+
}
|
1175 |
+
if ( ( $this->databaseType == self::GEOIP_COUNTRY_EDITION )
|
1176 |
+
|| ( $this->databaseType == self::GEOIP_COUNTRY_EDITION_V6 )
|
1177 |
+
|| ( $this->databaseType == self::GEOIP_PROXY_EDITION )
|
1178 |
+
|| ( $this->databaseType == self::GEOIP_NETSPEED_EDITION )
|
1179 |
+
) {
|
1180 |
+
$this->databaseSegments = self::GEOIP_COUNTRY_BEGIN;
|
1181 |
+
}
|
1182 |
+
} else {
|
1183 |
+
$filepos = ftell( $this->filehandle );
|
1184 |
+
fseek( $this->filehandle, -3, SEEK_END );
|
1185 |
+
for ( $i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++ ) {
|
1186 |
+
$delim = fread( $this->filehandle, 3 );
|
1187 |
+
if ( $delim == ( chr( 255 ) . chr( 255 ) . chr( 255 ) ) ) {
|
1188 |
+
$this->databaseType = ord( fread( $this->filehandle, 1 ) );
|
1189 |
+
if ( $this->databaseType >= 106 ) {
|
1190 |
+
$this->databaseType -= 105;
|
1191 |
+
}
|
1192 |
+
if ( $this->databaseType == self::GEOIP_REGION_EDITION_REV0 ) {
|
1193 |
+
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV0;
|
1194 |
+
} elseif ( $this->databaseType == self::GEOIP_REGION_EDITION_REV1 ) {
|
1195 |
+
$this->databaseSegments = self::GEOIP_STATE_BEGIN_REV1;
|
1196 |
+
} elseif ( ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0 )
|
1197 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1 )
|
1198 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 )
|
1199 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 )
|
1200 |
+
|| ( $this->databaseType == self::GEOIP_ORG_EDITION )
|
1201 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
|
1202 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION )
|
1203 |
+
|| ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
|
1204 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
|
1205 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
|
1206 |
+
|| ( $this->databaseType == self::GEOIP_LOCATIONA_EDITION )
|
1207 |
+
|| ( $this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION )
|
1208 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 )
|
1209 |
+
|| ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 )
|
1210 |
+
|| ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1 )
|
1211 |
+
|| ( $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6 )
|
1212 |
+
|| ( $this->databaseType == self::GEOIP_USERTYPE_EDITION )
|
1213 |
+
|| ( $this->databaseType == self::GEOIP_USERTYPE_EDITION_V6 )
|
1214 |
+
|| ( $this->databaseType == self::GEOIP_ASNUM_EDITION )
|
1215 |
+
|| ( $this->databaseType == self::GEOIP_ASNUM_EDITION_V6 )
|
1216 |
+
) {
|
1217 |
+
$this->databaseSegments = 0;
|
1218 |
+
$buf = fread( $this->filehandle, self::SEGMENT_RECORD_LENGTH );
|
1219 |
+
for ( $j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++ ) {
|
1220 |
+
$this->databaseSegments += ( ord( $buf[ $j ] ) << ( $j * 8 ) );
|
1221 |
+
}
|
1222 |
+
if ( ( $this->databaseType == self::GEOIP_ORG_EDITION )
|
1223 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION )
|
1224 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION )
|
1225 |
+
|| ( $this->databaseType == self::GEOIP_ORG_EDITION_V6 )
|
1226 |
+
|| ( $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 )
|
1227 |
+
|| ( $this->databaseType == self::GEOIP_ISP_EDITION_V6 )
|
1228 |
+
) {
|
1229 |
+
$this->record_length = self::ORG_RECORD_LENGTH;
|
1230 |
+
}
|
1231 |
+
}
|
1232 |
+
break;
|
1233 |
+
} else {
|
1234 |
+
fseek( $this->filehandle, -4, SEEK_CUR );
|
1235 |
+
}
|
1236 |
+
}
|
1237 |
+
if ( ( $this->databaseType == self::GEOIP_COUNTRY_EDITION )
|
1238 |
+
|| ( $this->databaseType == self::GEOIP_COUNTRY_EDITION_V6 )
|
1239 |
+
|| ( $this->databaseType == self::GEOIP_PROXY_EDITION )
|
1240 |
+
|| ( $this->databaseType == self::GEOIP_NETSPEED_EDITION )
|
1241 |
+
) {
|
1242 |
+
$this->databaseSegments = self::GEOIP_COUNTRY_BEGIN;
|
1243 |
+
}
|
1244 |
+
fseek( $this->filehandle, $filepos, SEEK_SET );
|
1245 |
+
}
|
1246 |
+
return $this;
|
1247 |
+
}
|
1248 |
+
/**
|
1249 |
+
* Close geoip file
|
1250 |
+
*
|
1251 |
+
* @return bool
|
1252 |
+
*/
|
1253 |
+
public function geoip_close() {
|
1254 |
+
if ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
|
1255 |
+
return true;
|
1256 |
+
}
|
1257 |
+
|
1258 |
+
return @fclose( $this->filehandle );
|
1259 |
+
}
|
1260 |
+
/**
|
1261 |
+
* Common get record
|
1262 |
+
*
|
1263 |
+
* @param string $seek_country
|
1264 |
+
* @return MchMaxMindGeoIpRecord instance
|
1265 |
+
*/
|
1266 |
+
private function _common_get_record( $seek_country ) {
|
1267 |
+
// workaround php's broken substr, strpos, etc handling with
|
1268 |
+
// mbstring.func_overload and mbstring.internal_encoding
|
1269 |
+
$mbExists = extension_loaded( 'mbstring' );
|
1270 |
+
if ( $mbExists ) {
|
1271 |
+
$enc = mb_internal_encoding();
|
1272 |
+
mb_internal_encoding( 'ISO-8859-1' );
|
1273 |
+
}
|
1274 |
+
$record_pointer = $seek_country + ( 2 * $this->record_length - 1 ) * $this->databaseSegments;
|
1275 |
+
if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
|
1276 |
+
$record_buf = substr( $this->memory_buffer, $record_pointer, FULL_RECORD_LENGTH );
|
1277 |
+
} elseif ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
|
1278 |
+
$record_buf = @shmop_read( $this->shmid, $record_pointer, FULL_RECORD_LENGTH );
|
1279 |
+
} else {
|
1280 |
+
fseek( $this->filehandle, $record_pointer, SEEK_SET );
|
1281 |
+
$record_buf = fread( $this->filehandle, FULL_RECORD_LENGTH );
|
1282 |
+
}
|
1283 |
+
$record = new MchMaxMindGeoIpRecord();
|
1284 |
+
$record_buf_pos = 0;
|
1285 |
+
$char = ord( substr( $record_buf, $record_buf_pos, 1 ) );
|
1286 |
+
|
1287 |
+
if(isset($this->GEOIP_COUNTRY_CODES[ $char ])) {
|
1288 |
+
$record->country_code = $this->GEOIP_COUNTRY_CODES[ $char ];
|
1289 |
+
return $record;
|
1290 |
+
}
|
1291 |
+
|
1292 |
+
$record->country_code3 = $this->GEOIP_COUNTRY_CODES3[ $char ];
|
1293 |
+
$record->country_name = $this->GEOIP_COUNTRY_NAMES[ $char ];
|
1294 |
+
$record->continent_code = $this->GEOIP_CONTINENT_CODES[ $char ];
|
1295 |
+
$str_length = 0;
|
1296 |
+
$record_buf_pos++;
|
1297 |
+
// Get region
|
1298 |
+
$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
|
1299 |
+
while ( $char != 0 ) {
|
1300 |
+
$str_length++;
|
1301 |
+
$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
|
1302 |
+
}
|
1303 |
+
if ( $str_length > 0 ) {
|
1304 |
+
$record->region = substr( $record_buf, $record_buf_pos, $str_length );
|
1305 |
+
}
|
1306 |
+
$record_buf_pos += $str_length + 1;
|
1307 |
+
$str_length = 0;
|
1308 |
+
// Get city
|
1309 |
+
$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
|
1310 |
+
while ( $char != 0 ) {
|
1311 |
+
$str_length++;
|
1312 |
+
$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
|
1313 |
+
}
|
1314 |
+
if ( $str_length > 0 ) {
|
1315 |
+
$record->city = substr( $record_buf, $record_buf_pos, $str_length );
|
1316 |
+
}
|
1317 |
+
$record_buf_pos += $str_length + 1;
|
1318 |
+
$str_length = 0;
|
1319 |
+
// Get postal code
|
1320 |
+
$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
|
1321 |
+
while ( $char != 0 ) {
|
1322 |
+
$str_length++;
|
1323 |
+
$char = ord( substr( $record_buf, $record_buf_pos + $str_length, 1 ) );
|
1324 |
+
}
|
1325 |
+
if ( $str_length > 0 ) {
|
1326 |
+
$record->postal_code = substr( $record_buf, $record_buf_pos, $str_length );
|
1327 |
+
}
|
1328 |
+
$record_buf_pos += $str_length + 1;
|
1329 |
+
// Get latitude and longitude
|
1330 |
+
$latitude = 0;
|
1331 |
+
$longitude = 0;
|
1332 |
+
for ( $j = 0; $j < 3; ++$j ) {
|
1333 |
+
$char = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
|
1334 |
+
$latitude += ( $char << ( $j * 8 ) );
|
1335 |
+
}
|
1336 |
+
$record->latitude = ( $latitude / 10000 ) - 180;
|
1337 |
+
for ( $j = 0; $j < 3; ++$j ) {
|
1338 |
+
$char = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
|
1339 |
+
$longitude += ( $char << ( $j * 8 ) );
|
1340 |
+
}
|
1341 |
+
$record->longitude = ( $longitude / 10000 ) - 180;
|
1342 |
+
if ( self::GEOIP_CITY_EDITION_REV1 == $this->databaseType ) {
|
1343 |
+
$metroarea_combo = 0;
|
1344 |
+
if ( $record->country_code == "US" ) {
|
1345 |
+
for ( $j = 0; $j < 3; ++$j ) {
|
1346 |
+
$char = ord( substr( $record_buf, $record_buf_pos++, 1 ) );
|
1347 |
+
$metroarea_combo += ( $char << ( $j * 8 ) );
|
1348 |
+
}
|
1349 |
+
$record->metro_code = $record->dma_code = floor( $metroarea_combo / 1000 );
|
1350 |
+
$record->area_code = $metroarea_combo % 1000;
|
1351 |
+
}
|
1352 |
+
}
|
1353 |
+
if ( $mbExists ) {
|
1354 |
+
mb_internal_encoding( $enc );
|
1355 |
+
}
|
1356 |
+
|
1357 |
+
return $record;
|
1358 |
+
}
|
1359 |
+
/**
|
1360 |
+
* Get record
|
1361 |
+
*
|
1362 |
+
* @param int $ipnum
|
1363 |
+
* @return MchMaxMindGeoIpRecord instance
|
1364 |
+
*/
|
1365 |
+
private function _get_record( $ipnum ) {
|
1366 |
+
$seek_country = $this->_geoip_seek_country( $ipnum );
|
1367 |
+
if ( $seek_country == $this->databaseSegments ) {
|
1368 |
+
return null;
|
1369 |
+
}
|
1370 |
+
return $this->_common_get_record( $seek_country );
|
1371 |
+
}
|
1372 |
+
/**
|
1373 |
+
* Seek country IPv6
|
1374 |
+
*
|
1375 |
+
* @param int $ipnum [description]
|
1376 |
+
* @return bool|int
|
1377 |
+
*/
|
1378 |
+
function _geoip_seek_country_v6( $ipnum ) {
|
1379 |
+
// arrays from unpack start with offset 1
|
1380 |
+
// yet another php mystery. array_merge work around
|
1381 |
+
// this broken behaviour
|
1382 |
+
$v6vec = array_merge( unpack( 'C16', $ipnum ) );
|
1383 |
+
$offset = 0;
|
1384 |
+
for ( $depth = 127; $depth >= 0; --$depth ) {
|
1385 |
+
if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
|
1386 |
+
$buf = $this->_safe_substr(
|
1387 |
+
$this->memory_buffer,
|
1388 |
+
2 * $this->record_length * $offset,
|
1389 |
+
2 * $this->record_length
|
1390 |
+
);
|
1391 |
+
} elseif ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
|
1392 |
+
$buf = @shmop_read(
|
1393 |
+
$this->shmid,
|
1394 |
+
2 * $this->record_length * $offset,
|
1395 |
+
2 * $this->record_length
|
1396 |
+
);
|
1397 |
+
} else
|
1398 |
+
{
|
1399 |
+
if(fseek( $this->filehandle, 2 * $this->record_length * $offset, SEEK_SET ) !== 0)
|
1400 |
+
throw new Exception('GeoIP API: fseek failed');
|
1401 |
+
//or trigger_error( 'GeoIP API: fseek failed', E_USER_ERROR );
|
1402 |
+
|
1403 |
+
$buf = fread( $this->filehandle, 2 * $this->record_length );
|
1404 |
+
}
|
1405 |
+
$x = array( 0, 0 );
|
1406 |
+
for ( $i = 0; $i < 2; ++$i ) {
|
1407 |
+
for ( $j = 0; $j < $this->record_length; ++$j ) {
|
1408 |
+
$x[ $i ] += ord( $buf[ $this->record_length * $i + $j ] ) << ( $j * 8 );
|
1409 |
+
}
|
1410 |
+
}
|
1411 |
+
$bnum = 127 - $depth;
|
1412 |
+
$idx = $bnum >> 3;
|
1413 |
+
$b_mask = 1 << ( $bnum & 7 ^ 7 );
|
1414 |
+
if ( ( $v6vec[ $idx ] & $b_mask ) > 0 ) {
|
1415 |
+
if ( $x[1] >= $this->databaseSegments ) {
|
1416 |
+
return $x[1];
|
1417 |
+
}
|
1418 |
+
$offset = $x[1];
|
1419 |
+
} else {
|
1420 |
+
if ( $x[0] >= $this->databaseSegments ) {
|
1421 |
+
return $x[0];
|
1422 |
+
}
|
1423 |
+
$offset = $x[0];
|
1424 |
+
}
|
1425 |
+
}
|
1426 |
+
|
1427 |
+
throw new Exception('GeoIP API: Error traversing database - perhaps it is corrupt?');
|
1428 |
+
//trigger_error( 'GeoIP API: Error traversing database - perhaps it is corrupt?', E_USER_ERROR );
|
1429 |
+
|
1430 |
+
//return false;
|
1431 |
+
}
|
1432 |
+
/**
|
1433 |
+
* Seek country
|
1434 |
+
*
|
1435 |
+
* @param int $ipnum
|
1436 |
+
* @return bool|int
|
1437 |
+
*/
|
1438 |
+
private function _geoip_seek_country( $ipnum ) {
|
1439 |
+
$offset = 0;
|
1440 |
+
for ( $depth = 31; $depth >= 0; --$depth ) {
|
1441 |
+
if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
|
1442 |
+
$buf = $this->_safe_substr(
|
1443 |
+
$this->memory_buffer,
|
1444 |
+
2 * $this->record_length * $offset,
|
1445 |
+
2 * $this->record_length
|
1446 |
+
);
|
1447 |
+
} elseif ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
|
1448 |
+
$buf = @shmop_read(
|
1449 |
+
$this->shmid,
|
1450 |
+
2 * $this->record_length * $offset,
|
1451 |
+
2 * $this->record_length
|
1452 |
+
);
|
1453 |
+
} else
|
1454 |
+
{
|
1455 |
+
if(fseek( $this->filehandle, 2 * $this->record_length * $offset, SEEK_SET ) !== 0)
|
1456 |
+
throw new Exception('GeoIP API: fseek failed');
|
1457 |
+
|
1458 |
+
//or trigger_error( 'GeoIP API: fseek failed', E_USER_ERROR );
|
1459 |
+
$buf = fread( $this->filehandle, 2 * $this->record_length );
|
1460 |
+
}
|
1461 |
+
$x = array( 0, 0 );
|
1462 |
+
for ( $i = 0; $i < 2; ++$i ) {
|
1463 |
+
for ( $j = 0; $j < $this->record_length; ++$j ) {
|
1464 |
+
$x[ $i ] += ord( $buf[ $this->record_length * $i + $j ] ) << ( $j * 8 );
|
1465 |
+
}
|
1466 |
+
}
|
1467 |
+
if ( $ipnum & ( 1 << $depth ) ) {
|
1468 |
+
if ( $x[1] >= $this->databaseSegments ) {
|
1469 |
+
return $x[1];
|
1470 |
+
}
|
1471 |
+
$offset = $x[1];
|
1472 |
+
} else {
|
1473 |
+
if ( $x[0] >= $this->databaseSegments ) {
|
1474 |
+
return $x[0];
|
1475 |
+
}
|
1476 |
+
$offset = $x[0];
|
1477 |
+
}
|
1478 |
+
}
|
1479 |
+
|
1480 |
+
throw new Exception('GeoIP API: Error traversing database - perhaps it is corrupt?');
|
1481 |
+
|
1482 |
+
//trigger_error( 'GeoIP API: Error traversing database - perhaps it is corrupt?', E_USER_ERROR );
|
1483 |
+
|
1484 |
+
//return false;
|
1485 |
+
}
|
1486 |
+
/**
|
1487 |
+
* Record by addr
|
1488 |
+
*
|
1489 |
+
* @param string $addr
|
1490 |
+
* @return int
|
1491 |
+
*/
|
1492 |
+
public function geoip_record_by_addr( $addr ) {
|
1493 |
+
if ( $addr == null ) {
|
1494 |
+
return 0;
|
1495 |
+
}
|
1496 |
+
$ipnum = ip2long( $addr );
|
1497 |
+
return $this->_get_record( $ipnum );
|
1498 |
+
}
|
1499 |
+
/**
|
1500 |
+
* Country ID by addr IPv6
|
1501 |
+
*
|
1502 |
+
* @param string $addr
|
1503 |
+
* @return int
|
1504 |
+
*/
|
1505 |
+
public function geoip_country_id_by_addr_v6( $addr ) {
|
1506 |
+
$ipnum = inet_pton( $addr );
|
1507 |
+
return $this->_geoip_seek_country_v6( $ipnum ) - self::GEOIP_COUNTRY_BEGIN;
|
1508 |
+
}
|
1509 |
+
/**
|
1510 |
+
* Country ID by addr
|
1511 |
+
*
|
1512 |
+
* @param string $addr
|
1513 |
+
* @return int
|
1514 |
+
*/
|
1515 |
+
public function geoip_country_id_by_addr( $addr ) {
|
1516 |
+
$ipnum = ip2long( $addr );
|
1517 |
+
return $this->_geoip_seek_country( $ipnum ) - self::GEOIP_COUNTRY_BEGIN;
|
1518 |
+
}
|
1519 |
+
/**
|
1520 |
+
* Country code by addr IPv6
|
1521 |
+
*
|
1522 |
+
* @param string $addr
|
1523 |
+
* @return bool|int
|
1524 |
+
*/
|
1525 |
+
public function geoip_country_code_by_addr_v6( $addr ) {
|
1526 |
+
$country_id = $this->geoip_country_id_by_addr_v6( $addr );
|
1527 |
+
if ( $country_id !== false && !empty($this->GEOIP_COUNTRY_CODES[ $country_id ]) ) {
|
1528 |
+
return $this->GEOIP_COUNTRY_CODES[ $country_id ];
|
1529 |
+
}
|
1530 |
+
return null;
|
1531 |
+
}
|
1532 |
+
/**
|
1533 |
+
* Country code by addr
|
1534 |
+
*
|
1535 |
+
* @param string $addr
|
1536 |
+
* @return bool|int
|
1537 |
+
*/
|
1538 |
+
public function geoip_country_code_by_addr( $addr ) {
|
1539 |
+
if ( $this->databaseType == self::GEOIP_CITY_EDITION_REV1 ) {
|
1540 |
+
$record = $this->geoip_record_by_addr( $addr);
|
1541 |
+
if ( !empty($record->country_code) ) {
|
1542 |
+
return $record->country_code;
|
1543 |
+
}
|
1544 |
+
} else {
|
1545 |
+
$country_id = $this->geoip_country_id_by_addr( $addr );
|
1546 |
+
if ( $country_id !== false && !empty($this->GEOIP_COUNTRY_CODES[ $country_id ]) ) {
|
1547 |
+
return $this->GEOIP_COUNTRY_CODES[ $country_id ];
|
1548 |
+
}
|
1549 |
+
}
|
1550 |
+
|
1551 |
+
return null;
|
1552 |
+
}
|
1553 |
+
/**
|
1554 |
+
* Encode string
|
1555 |
+
*
|
1556 |
+
* @param string $string
|
1557 |
+
* @param int $start
|
1558 |
+
* @param int $length
|
1559 |
+
*
|
1560 |
+
* @return string
|
1561 |
+
*/
|
1562 |
+
private function _safe_substr( $string, $start, $length ) {
|
1563 |
+
// workaround php's broken substr, strpos, etc handling with
|
1564 |
+
// mbstring.func_overload and mbstring.internal_encoding
|
1565 |
+
$mb_exists = extension_loaded( 'mbstring' );
|
1566 |
+
if ( $mb_exists ) {
|
1567 |
+
$enc = mb_internal_encoding();
|
1568 |
+
mb_internal_encoding( 'ISO-8859-1' );
|
1569 |
+
}
|
1570 |
+
$buf = substr( $string, $start, $length );
|
1571 |
+
if ( $mb_exists ) {
|
1572 |
+
mb_internal_encoding( $enc );
|
1573 |
+
}
|
1574 |
+
return $buf;
|
1575 |
+
}
|
1576 |
+
}
|
1577 |
+
/**
|
1578 |
+
* Geo IP Record class
|
1579 |
+
*/
|
1580 |
+
class MchMaxMindGeoIpRecord {
|
1581 |
+
public $country_code;
|
1582 |
+
public $country_code3;
|
1583 |
+
public $country_name;
|
1584 |
+
public $region;
|
1585 |
+
public $city;
|
1586 |
+
public $postal_code;
|
1587 |
+
public $latitude;
|
1588 |
+
public $longitude;
|
1589 |
+
public $area_code;
|
1590 |
+
public $dma_code; // metro and dma code are the same. use metro_code
|
1591 |
+
public $metro_code;
|
1592 |
+
public $continent_code;
|
1593 |
+
}
|
{includes → 2.0/includes}/vendor/MchCache/MchGdbcCache.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheAPCStorage.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheAPCUStorage.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheBaseStorage.php
RENAMED
File without changes
|
2.0/includes/vendor/MchCache/Storage/MchGdbcCacheFileStorage.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class MchGdbcCacheFileStorage extends MchGdbcCacheBaseStorage
|
21 |
+
{
|
22 |
+
|
23 |
+
protected $path;
|
24 |
+
protected $extension;
|
25 |
+
protected $canSkipOnWriting = false;
|
26 |
+
|
27 |
+
public function __construct($path, $canSkipOnWriting = false, $extension = 'cache')
|
28 |
+
{
|
29 |
+
$this->path = rtrim($path, '/\\');
|
30 |
+
|
31 |
+
$extension = trim($extension, '.');
|
32 |
+
|
33 |
+
$this->extension = empty($extension) ? '' : '.' . $extension;
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
public function isAvailable()
|
38 |
+
{
|
39 |
+
return (null === $this->isAvailable)
|
40 |
+
? $this->isAvailable = (@file_exists($this->path) && @is_readable($this->path) && @is_writable($this->path))
|
41 |
+
: $this->isAvailable;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getStorageType()
|
45 |
+
{
|
46 |
+
return self::STORAGE_TYPE_DISK;
|
47 |
+
}
|
48 |
+
|
49 |
+
|
50 |
+
private function getCacheFilePath($key)
|
51 |
+
{
|
52 |
+
return $this->path . DIRECTORY_SEPARATOR . $key . $this->extension;
|
53 |
+
}
|
54 |
+
|
55 |
+
public function write($key, $value, $ttl = 0)
|
56 |
+
{
|
57 |
+
$ttl = (int)$ttl;
|
58 |
+
$ttl = ( ($ttl === 0) ? 31556926 : $ttl) + ( empty($_SERVER['REQUEST_TIME']) ? time() : $_SERVER['REQUEST_TIME'] );
|
59 |
+
|
60 |
+
$data = $ttl . PHP_EOL . $value;
|
61 |
+
|
62 |
+
$cacheFilePath = $this->getCacheFilePath($key);
|
63 |
+
$filePointer = @fopen($cacheFilePath, 'wb');
|
64 |
+
if(false === $filePointer)
|
65 |
+
return 0;
|
66 |
+
|
67 |
+
if( false === flock( $filePointer, ( $this->canSkipOnWriting ? LOCK_EX|LOCK_NB : LOCK_EX ) ) ){
|
68 |
+
fclose($filePointer);
|
69 |
+
return 0;
|
70 |
+
}
|
71 |
+
$bytesWritten = fwrite($filePointer, $data);
|
72 |
+
flock($filePointer, LOCK_UN);
|
73 |
+
fclose($filePointer);
|
74 |
+
|
75 |
+
return (false === $bytesWritten) ? 0 : $bytesWritten;
|
76 |
+
}
|
77 |
+
|
78 |
+
public function read($key)
|
79 |
+
{
|
80 |
+
$cacheFilePath = $this->getCacheFilePath($key);
|
81 |
+
|
82 |
+
if(!file_exists($cacheFilePath))
|
83 |
+
return null;
|
84 |
+
|
85 |
+
$filePointer = @fopen($cacheFilePath, 'rb');
|
86 |
+
if(false === $filePointer)
|
87 |
+
return null;
|
88 |
+
|
89 |
+
$isLocked = flock( $filePointer, LOCK_SH );
|
90 |
+
|
91 |
+
if( $isLocked && (( empty($_SERVER['REQUEST_TIME']) ? time() : $_SERVER['REQUEST_TIME'] ) <= (int) trim(fgets($filePointer))) )
|
92 |
+
{
|
93 |
+
$cachedContent = '';
|
94 |
+
|
95 |
+
while(!feof($filePointer))
|
96 |
+
{
|
97 |
+
$cachedContent .= fgets($filePointer);
|
98 |
+
}
|
99 |
+
|
100 |
+
flock( $filePointer, LOCK_UN );
|
101 |
+
fclose( $filePointer );
|
102 |
+
|
103 |
+
return $cachedContent;
|
104 |
+
}
|
105 |
+
|
106 |
+
|
107 |
+
$isLocked ? flock( $filePointer, LOCK_UN ) : null;
|
108 |
+
|
109 |
+
fclose( $filePointer );
|
110 |
+
|
111 |
+
@unlink($cacheFilePath);
|
112 |
+
|
113 |
+
//PHP_VERSION_ID < 50300 ? @clearstatcache() : @clearstatcache(true, $cacheFilePath);
|
114 |
+
|
115 |
+
return null;
|
116 |
+
|
117 |
+
}
|
118 |
+
|
119 |
+
public function has($key)
|
120 |
+
{
|
121 |
+
$cacheFilePath = $this->getCacheFilePath($key);
|
122 |
+
|
123 |
+
return @file_exists($cacheFilePath);
|
124 |
+
|
125 |
+
// if( ! @file_exists($cacheFilePath) )
|
126 |
+
// return false;
|
127 |
+
|
128 |
+
$filePointer = @fopen($cacheFilePath, 'rb');
|
129 |
+
if(false === $filePointer)
|
130 |
+
return false;
|
131 |
+
|
132 |
+
if(false === flock( $filePointer, LOCK_SH ))
|
133 |
+
{
|
134 |
+
fclose( $filePointer );
|
135 |
+
return false;
|
136 |
+
}
|
137 |
+
|
138 |
+
//echo trim(fgets($filePointer)) . ' - ' . time();exit;
|
139 |
+
$expired = ( ( empty($_SERVER['REQUEST_TIME']) ? time() : $_SERVER['REQUEST_TIME'] ) < (int) trim(fgets($filePointer)) );
|
140 |
+
|
141 |
+
flock( $filePointer, LOCK_UN );
|
142 |
+
fclose( $filePointer );
|
143 |
+
|
144 |
+
if($expired)
|
145 |
+
{
|
146 |
+
@unlink($cacheFilePath);
|
147 |
+
//PHP_VERSION_ID < 50300 ? @clearstatcache() : @clearstatcache(true, $cacheFilePath);
|
148 |
+
}
|
149 |
+
|
150 |
+
return $expired;
|
151 |
+
}
|
152 |
+
|
153 |
+
|
154 |
+
public function delete($key)
|
155 |
+
{
|
156 |
+
$cacheFilePath = $this->getCacheFilePath($key);
|
157 |
+
return @file_exists($cacheFilePath) ? @unlink($cacheFilePath) : false;
|
158 |
+
}
|
159 |
+
|
160 |
+
public function clear()
|
161 |
+
{
|
162 |
+
$pattern = $this->path . '/' . $this->prefix . '*' . $this->extension;
|
163 |
+
|
164 |
+
foreach(glob($pattern) as $file)
|
165 |
+
{
|
166 |
+
if(!is_dir($file))
|
167 |
+
{
|
168 |
+
if(@unlink($file) === false)
|
169 |
+
{
|
170 |
+
return false;
|
171 |
+
}
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
return true;
|
176 |
+
}
|
177 |
+
|
178 |
+
}
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheMemcacheStorage.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheMemcachedStorage.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheXCacheStorage.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheZendDiskStorage.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCache/Storage/MchGdbcCacheZendMemoryStorage.php
RENAMED
File without changes
|
2.0/includes/vendor/MchCache/Storage/MchGdbcWordPressTransientsStorage.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright (C) 2015 Mihai Chelaru
|
4 |
+
*
|
5 |
+
* This program is free software; you can redistribute it and/or
|
6 |
+
* modify it under the terms of the GNU General Public License
|
7 |
+
* as published by the Free Software Foundation; either version 2
|
8 |
+
* of the License, or (at your option) any later version.
|
9 |
+
*
|
10 |
+
* This program is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* You should have received a copy of the GNU General Public License
|
16 |
+
* along with this program; if not, write to the Free Software
|
17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
+
*/
|
19 |
+
|
20 |
+
class MchGdbcWordPressTransientsStorage extends MchGdbcCacheBaseStorage
|
21 |
+
{
|
22 |
+
private $canUseDataBase = true;
|
23 |
+
|
24 |
+
public function __construct($canUseDataBase = true)
|
25 |
+
{
|
26 |
+
$this->canUseDataBase = (boolean)$canUseDataBase;
|
27 |
+
parent::__construct();
|
28 |
+
|
29 |
+
}
|
30 |
+
|
31 |
+
public function write($key, $value, $ttl = 0)
|
32 |
+
{
|
33 |
+
return set_transient($this->sanitizeTransientKey($key), $value, $ttl);
|
34 |
+
}
|
35 |
+
|
36 |
+
public function read($key)
|
37 |
+
{
|
38 |
+
$value = get_transient($this->sanitizeTransientKey($key));
|
39 |
+
return false !== $value ? $value : null;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function has($key)
|
43 |
+
{
|
44 |
+
return null !== $this->read($key);
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
public function delete($key)
|
49 |
+
{
|
50 |
+
return delete_transient($this->sanitizeTransientKey($key));
|
51 |
+
}
|
52 |
+
|
53 |
+
private function sanitizeTransientKey($key)
|
54 |
+
{
|
55 |
+
return isset($key[40]) ? md5($key) : $key;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function clear()
|
59 |
+
{
|
60 |
+
return ;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function isAvailable()
|
64 |
+
{
|
65 |
+
if(null !== $this->isAvailable)
|
66 |
+
return $this->isAvailable;
|
67 |
+
|
68 |
+
if($this->canUseDataBase)
|
69 |
+
{
|
70 |
+
return $this->isAvailable = true;
|
71 |
+
}
|
72 |
+
|
73 |
+
return ($this->isAvailable = file_exists( WP_CONTENT_DIR . '/object-cache.php' ));
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
public function getStorageType()
|
78 |
+
{
|
79 |
+
return self::STORAGE_TYPE_DISK;
|
80 |
+
}
|
81 |
+
|
82 |
+
}
|
2.0/includes/vendor/MchCrypt/Core/Crypter.php
ADDED
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class MchCrypt_Core_Crypter
|
22 |
+
{
|
23 |
+
|
24 |
+
CONST CIPHER_DES = 1;
|
25 |
+
CONST CIPHER_RC2 = 2;
|
26 |
+
CONST CIPHER_3DES = 3;
|
27 |
+
CONST CIPHER_ARC4 = 4;
|
28 |
+
CONST CIPHER_GOST = 5;
|
29 |
+
CONST CIPHER_3WAY = 6;
|
30 |
+
CONST CIPHER_ENIGMA = 7;
|
31 |
+
CONST CIPHER_AES_128 = 8;
|
32 |
+
CONST CIPHER_AES_192 = 9;
|
33 |
+
CONST CIPHER_AES_256 = 10;
|
34 |
+
CONST CIPHER_CAST_128 = 11;
|
35 |
+
CONST CIPHER_CAST_256 = 12;
|
36 |
+
CONST CIPHER_BLOWFISH = 13;
|
37 |
+
CONST CIPHER_VIGENERE = 14;
|
38 |
+
CONST CIPHER_SKIPJACK = 15;
|
39 |
+
CONST CIPHER_SIMPLEXOR = 16;
|
40 |
+
CONST CIPHER_RIJNDAEL_128 = 17;
|
41 |
+
CONST CIPHER_RIJNDAEL_192 = 18;
|
42 |
+
CONST CIPHER_RIJNDAEL_256 = 19;
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
CONST MODE_CBC = 1;
|
47 |
+
CONST MODE_CFB = 2;
|
48 |
+
CONST MODE_CTR = 3;
|
49 |
+
CONST MODE_ECB = 4;
|
50 |
+
CONST MODE_NCFB = 5;
|
51 |
+
CONST MODE_NOFB = 6;
|
52 |
+
CONST MODE_OFB = 7;
|
53 |
+
|
54 |
+
private static $arrCipherNames = array(
|
55 |
+
self::CIPHER_DES => 'DES',
|
56 |
+
self::CIPHER_RC2 => 'RC2',
|
57 |
+
self::CIPHER_3DES => '3DES',
|
58 |
+
self::CIPHER_ARC4 => 'ARC4',
|
59 |
+
self::CIPHER_GOST => 'GOST',
|
60 |
+
self::CIPHER_3WAY => '3-Way',
|
61 |
+
self::CIPHER_ENIGMA => 'Enigma',
|
62 |
+
self::CIPHER_AES_128 => 'AES-128',
|
63 |
+
self::CIPHER_AES_192 => 'AES-192',
|
64 |
+
self::CIPHER_AES_256 => 'AES-256',
|
65 |
+
self::CIPHER_CAST_128 => 'CAST-128',
|
66 |
+
self::CIPHER_CAST_256 => 'CAST-256',
|
67 |
+
self::CIPHER_BLOWFISH => 'Blowfish',
|
68 |
+
self::CIPHER_VIGENERE => 'Vigenere',
|
69 |
+
self::CIPHER_SKIPJACK => 'Skipjack',
|
70 |
+
self::CIPHER_SIMPLEXOR => 'SimpleXOR',
|
71 |
+
self::CIPHER_RIJNDAEL_128 => 'Rijndael-128',
|
72 |
+
self::CIPHER_RIJNDAEL_192 => 'Rijndael-192',
|
73 |
+
self::CIPHER_RIJNDAEL_256 => 'Rijndael-256',
|
74 |
+
);
|
75 |
+
|
76 |
+
|
77 |
+
private static $arrModeNames = array(
|
78 |
+
self::MODE_CBC => 'CBC',
|
79 |
+
self::MODE_CFB => 'CFB',
|
80 |
+
self::MODE_CTR => 'CTR',
|
81 |
+
self::MODE_ECB => 'ECB',
|
82 |
+
self::MODE_OFB => 'OFB',
|
83 |
+
self::MODE_NCFB => 'NCFB',
|
84 |
+
self::MODE_NOFB => 'NOFB',
|
85 |
+
|
86 |
+
);
|
87 |
+
|
88 |
+
|
89 |
+
private $cipherId = null;
|
90 |
+
private $cipherName = null;
|
91 |
+
|
92 |
+
private $secretKey = null;
|
93 |
+
|
94 |
+
private $encryptionMode = null;
|
95 |
+
private $randomSalt = null;
|
96 |
+
|
97 |
+
|
98 |
+
public function __construct($cipherId = self::CIPHER_BLOWFISH, $encryptionModeId = self::MODE_CBC)
|
99 |
+
{
|
100 |
+
$this->cipherId = (int)$cipherId;
|
101 |
+
$this->cipherName = strtolower(self::$arrCipherNames[$cipherId]);
|
102 |
+
$this->encryptionMode = strtolower(self::$arrModeNames[$encryptionModeId]);
|
103 |
+
|
104 |
+
// if(!$this->isValidCipherId($cipherId) || (0 === $this->getCipherKeySize()))
|
105 |
+
// {
|
106 |
+
//
|
107 |
+
// }
|
108 |
+
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
public function getRandomSalt()
|
113 |
+
{
|
114 |
+
return null !== $this->randomSalt ? $this->randomSalt : $this->randomSalt = MchCrypt::getRandomBytes($this->getCipherSaltSize());
|
115 |
+
}
|
116 |
+
|
117 |
+
public function getCipherName()
|
118 |
+
{
|
119 |
+
return $this->cipherName;
|
120 |
+
}
|
121 |
+
|
122 |
+
public function setSecretKey($strKey)
|
123 |
+
{
|
124 |
+
if(empty($strKey))
|
125 |
+
{
|
126 |
+
throw new InvalidArgumentException('The key cannot be empty!');
|
127 |
+
}
|
128 |
+
|
129 |
+
if(!self::isMCryptExtensionLoaded())
|
130 |
+
{
|
131 |
+
return $this->secretKey = $strKey;
|
132 |
+
}
|
133 |
+
|
134 |
+
$keyLength = strlen($strKey);
|
135 |
+
|
136 |
+
$cipherSupportedKeySizes = mcrypt_module_get_supported_key_sizes($this->cipherName);
|
137 |
+
|
138 |
+
if(empty($cipherSupportedKeySizes))
|
139 |
+
{
|
140 |
+
if($keyLength <= $this->getCipherKeySize())
|
141 |
+
{
|
142 |
+
$this->secretKey = $strKey;
|
143 |
+
return;
|
144 |
+
}
|
145 |
+
|
146 |
+
throw new InvalidArgumentException("The size of the key must be between 1 and " . $this->getCipherKeySize() . " bytes!");
|
147 |
+
}
|
148 |
+
|
149 |
+
if(!in_array($keyLength, $cipherSupportedKeySizes))
|
150 |
+
{
|
151 |
+
throw new InvalidArgumentException('The accepted key sizes are: ' . implode( ' or ', $cipherSupportedKeySizes ));
|
152 |
+
}
|
153 |
+
|
154 |
+
$this->secretKey = $strKey;
|
155 |
+
}
|
156 |
+
|
157 |
+
private function isValidCipherId($chiperId)
|
158 |
+
{
|
159 |
+
if(!isset(self::$arrCipherNames[$chiperId]))
|
160 |
+
{
|
161 |
+
throw new OutOfBoundsException('The chiperId parameter should be an integer between 1 and ' . count(self::$arrCipherNames));
|
162 |
+
}
|
163 |
+
|
164 |
+
return true;
|
165 |
+
}
|
166 |
+
|
167 |
+
|
168 |
+
public function encrypt($strTextToEncrypt)
|
169 |
+
{
|
170 |
+
if(null === $this->secretKey)
|
171 |
+
{
|
172 |
+
throw new RuntimeException('Please provide a secret key for cryptor!');
|
173 |
+
}
|
174 |
+
|
175 |
+
if(empty($strTextToEncrypt))
|
176 |
+
{
|
177 |
+
throw new InvalidArgumentException('The data that will be encrypted cannot be empty!');
|
178 |
+
}
|
179 |
+
|
180 |
+
if(null === $this->randomSalt)
|
181 |
+
{
|
182 |
+
$this->randomSalt = $this->getRandomSalt();
|
183 |
+
}
|
184 |
+
|
185 |
+
|
186 |
+
if(!self::isMCryptExtensionLoaded())
|
187 |
+
{
|
188 |
+
|
189 |
+
$phpCryptCipher = new PhpCrypt($this->secretKey, self::$arrCipherNames[$this->cipherId], strtoupper($this->encryptionMode), PhpCrypt::PAD_PKCS7);
|
190 |
+
|
191 |
+
$phpCryptCipher->IV($this->randomSalt);
|
192 |
+
|
193 |
+
return $this->randomSalt . $phpCryptCipher->encrypt($strTextToEncrypt);
|
194 |
+
}
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
$padLength = $this->getCipherBlockSize() - (strlen($strTextToEncrypt) % $this->getCipherBlockSize());
|
199 |
+
$strTextToEncrypt .= str_repeat(chr($padLength), $padLength);
|
200 |
+
|
201 |
+
return $this->randomSalt . mcrypt_encrypt($this->cipherName, $this->secretKey, $strTextToEncrypt, $this->encryptionMode, $this->randomSalt);
|
202 |
+
|
203 |
+
}
|
204 |
+
|
205 |
+
public function decrypt($strEncrypted)
|
206 |
+
{
|
207 |
+
$salt = substr($strEncrypted, 0, $this->getCipherSaltSize());
|
208 |
+
$encryptedData = substr($strEncrypted, $this->getCipherSaltSize());
|
209 |
+
|
210 |
+
if(!self::isMCryptExtensionLoaded())
|
211 |
+
{
|
212 |
+
$phpCryptCipher = new PhpCrypt($this->secretKey, self::$arrCipherNames[$this->cipherId], strtoupper($this->encryptionMode), PhpCrypt::PAD_PKCS7);
|
213 |
+
|
214 |
+
$phpCryptCipher->IV($salt);
|
215 |
+
|
216 |
+
return $this->randomSalt . $phpCryptCipher->decrypt($encryptedData);
|
217 |
+
}
|
218 |
+
|
219 |
+
$decryptedData = mcrypt_decrypt($this->cipherName, $this->secretKey, $encryptedData, $this->encryptionMode, $salt);
|
220 |
+
|
221 |
+
return substr($decryptedData, 0, -ord($decryptedData[strlen($decryptedData) - 1]));
|
222 |
+
|
223 |
+
}
|
224 |
+
|
225 |
+
public function getCipherKeySize()
|
226 |
+
{
|
227 |
+
|
228 |
+
$arrSize = array();
|
229 |
+
|
230 |
+
$arrSize[self::CIPHER_DES] = 8;
|
231 |
+
$arrSize[self::CIPHER_RC2] = 128;
|
232 |
+
$arrSize[self::CIPHER_GOST] = 32;
|
233 |
+
$arrSize[self::CIPHER_CAST_128] = 16;
|
234 |
+
$arrSize[self::CIPHER_CAST_256] = 32;
|
235 |
+
$arrSize[self::CIPHER_BLOWFISH] = 56;
|
236 |
+
$arrSize[self::CIPHER_RIJNDAEL_128] = 32;
|
237 |
+
$arrSize[self::CIPHER_RIJNDAEL_192] = 32;
|
238 |
+
$arrSize[self::CIPHER_RIJNDAEL_256] = 32;
|
239 |
+
|
240 |
+
return isset($arrSize[$this->cipherId]) ? $arrSize[$this->cipherId] : 0;
|
241 |
+
|
242 |
+
}
|
243 |
+
|
244 |
+
public function getCipherSaltSize()
|
245 |
+
{
|
246 |
+
return $this->getCipherBlockSize();
|
247 |
+
}
|
248 |
+
|
249 |
+
private function getCipherBlockSize()
|
250 |
+
{
|
251 |
+
static $arrSize = array(
|
252 |
+
self::CIPHER_DES => 8,
|
253 |
+
self::CIPHER_RC2 => 8,
|
254 |
+
self::CIPHER_GOST => 8,
|
255 |
+
self::CIPHER_CAST_128 => 8,
|
256 |
+
self::CIPHER_CAST_256 => 16,
|
257 |
+
self::CIPHER_BLOWFISH => 8,
|
258 |
+
self::CIPHER_RIJNDAEL_128 => 16,
|
259 |
+
self::CIPHER_RIJNDAEL_192 => 24,
|
260 |
+
self::CIPHER_RIJNDAEL_256 => 32
|
261 |
+
);
|
262 |
+
|
263 |
+
return isset($arrSize[$this->cipherId]) ? $arrSize[$this->cipherId] : 0;
|
264 |
+
}
|
265 |
+
|
266 |
+
|
267 |
+
private static function isMCryptExtensionLoaded()
|
268 |
+
{
|
269 |
+
return MchCrypt_Core_Generator::canUseMCrypt();
|
270 |
+
|
271 |
+
// static $isLoaded = null;
|
272 |
+
//
|
273 |
+
// return (null !== $isLoaded) ? $isLoaded : $isLoaded = extension_loaded('mcrypt');
|
274 |
+
}
|
275 |
+
|
276 |
+
}
|
2.0/includes/vendor/MchCrypt/Core/Generator.php
ADDED
@@ -0,0 +1,320 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
final class MchCrypt_Core_Generator
|
22 |
+
{
|
23 |
+
|
24 |
+
private static $canGenerateSecure = null;
|
25 |
+
|
26 |
+
public static function canGenerateSecure()
|
27 |
+
{
|
28 |
+
return (null !== self::$canGenerateSecure) ?
|
29 |
+
self::$canGenerateSecure :
|
30 |
+
self::$canGenerateSecure = self::canUseMCrypt() || self::canUseOpenSSL() || self::canUseDevURandom();
|
31 |
+
|
32 |
+
}
|
33 |
+
|
34 |
+
public static function generateRandomString($length, $secure = true, $characters = null)
|
35 |
+
{
|
36 |
+
if(($length = (int)$length) > 256)
|
37 |
+
{
|
38 |
+
$length = 256;
|
39 |
+
}
|
40 |
+
|
41 |
+
$randomString = '';
|
42 |
+
$characterslength = 94;
|
43 |
+
|
44 |
+
(!empty($characters)) ? $characterslength = strlen($characters) : $characters = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
|
45 |
+
|
46 |
+
$arrNumberInfo = self::getNumberInfo($characterslength);
|
47 |
+
$arrNumberInfo[0] *= $length ;
|
48 |
+
$arrNumberInfo[1] = 256 - (256 % $length);
|
49 |
+
|
50 |
+
while(!isset($randomString[$length -1]))
|
51 |
+
{
|
52 |
+
$randomBytes = self::generateRandomBytes($arrNumberInfo[0], $secure);
|
53 |
+
|
54 |
+
for ($i = 0; $i < $arrNumberInfo[0]; ++$i)
|
55 |
+
{
|
56 |
+
if (ord($randomBytes[$i]) <= $arrNumberInfo[1])
|
57 |
+
{
|
58 |
+
$randomString .= $characters[ord($randomBytes[$i]) % $characterslength];
|
59 |
+
}
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
return !isset($randomString[$length]) ? $randomString : substr($randomString, 0, $length);
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
public static function generateRandomIntegerInRange($min, $max, $secure = true)
|
68 |
+
{
|
69 |
+
$randomNumber = 0;
|
70 |
+
|
71 |
+
if(($rangeNumber = ($max = (int)$max) - ($min = (int)$min)) <= 0)
|
72 |
+
return $min;
|
73 |
+
|
74 |
+
$arrNumberInfo = self::getNumberInfo($rangeNumber);
|
75 |
+
|
76 |
+
do
|
77 |
+
{
|
78 |
+
$randomNumber = hexdec(bin2hex(self::generateRandomBytes($arrNumberInfo[0], $secure))) & $arrNumberInfo[1];
|
79 |
+
}
|
80 |
+
while($randomNumber > $rangeNumber);
|
81 |
+
|
82 |
+
return $min + $randomNumber;
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
|
87 |
+
private static function getNumberInfo($number)
|
88 |
+
{
|
89 |
+
static $rangeInfo = array();
|
90 |
+
|
91 |
+
if(isset($rangeInfo[$number]))
|
92 |
+
{
|
93 |
+
return $rangeInfo[$number];
|
94 |
+
}
|
95 |
+
|
96 |
+
$rangeInfo[$number] = array();
|
97 |
+
$bitsCounter = (int)(floor(log($number, 2) + 1));
|
98 |
+
|
99 |
+
|
100 |
+
$rangeInfo[$number] = array();
|
101 |
+
$rangeInfo[$number][] = (int) max(ceil($bitsCounter / 8), 1);
|
102 |
+
|
103 |
+
if( ($bitsCounter == (PHP_INT_SIZE * 8)) || ($bitsCounter == (PHP_INT_SIZE * 8) - 1))
|
104 |
+
{
|
105 |
+
$rangeInfo[$number][] = (8 === PHP_INT_SIZE) ? 0x7fffffffffffffff : 0xccccccc;
|
106 |
+
}
|
107 |
+
else
|
108 |
+
{
|
109 |
+
$rangeInfo[$number][] = (int)((1 << $bitsCounter) - 1);
|
110 |
+
}
|
111 |
+
|
112 |
+
return $rangeInfo[$number];
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
+
public static function generateRandomBytes($length, $secure = true)
|
117 |
+
{
|
118 |
+
|
119 |
+
$randomResult = '';
|
120 |
+
|
121 |
+
if($length <= 32 || !$secure)
|
122 |
+
{
|
123 |
+
$randomResult = self::getRandomBytes($length, $secure);
|
124 |
+
}
|
125 |
+
else
|
126 |
+
{
|
127 |
+
for($i = 0, $iterations = ceil($length / 32); $i < $iterations ; ++$i)
|
128 |
+
{
|
129 |
+
$randomResult .= self::getRandomBytes(32, true);
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
while(!isset($randomResult[$length - 1])) // this should not happen but...
|
134 |
+
{
|
135 |
+
$randomResult .= self::getBytesUsingMTRand(($length % 32) + 1);
|
136 |
+
}
|
137 |
+
|
138 |
+
return substr($randomResult, 0, $length);
|
139 |
+
}
|
140 |
+
|
141 |
+
|
142 |
+
private static function getRandomBytes($length, $secure = true)
|
143 |
+
{
|
144 |
+
|
145 |
+
if(!$secure)
|
146 |
+
{
|
147 |
+
return self::getBytesUsingMTRand($length);
|
148 |
+
}
|
149 |
+
|
150 |
+
if(!self::canGenerateSecure())
|
151 |
+
{
|
152 |
+
throw new Exception('Cannot generate secure random bytes!');
|
153 |
+
}
|
154 |
+
|
155 |
+
if(null !== ($randomResult = self::getBytesUsingOpenSSL($length)))
|
156 |
+
return $randomResult;
|
157 |
+
|
158 |
+
if(null !== ($randomResult = self::getBytesUsingDevURandom($length)))
|
159 |
+
return $randomResult;
|
160 |
+
|
161 |
+
if(null !== ($randomResult = self::getBytesUsingMCrypt($length)))
|
162 |
+
return $randomResult;
|
163 |
+
|
164 |
+
// $openSSLResult = self::getBytesUsingOpenSSL($length);
|
165 |
+
// $uRandomResult = self::getBytesUsingDevURandom($length);
|
166 |
+
// $mCryptResult = self::getBytesUsingMCrypt($length);
|
167 |
+
|
168 |
+
// if(null !== $openSSLResult)
|
169 |
+
// {
|
170 |
+
// $randomResult = $openSSLResult;
|
171 |
+
// }
|
172 |
+
//
|
173 |
+
//
|
174 |
+
// if(null !== $uRandomResult)
|
175 |
+
// {
|
176 |
+
// (null === $randomResult) ?
|
177 |
+
// $randomResult = $uRandomResult :
|
178 |
+
// $randomResult ^= hash_hmac('sha256', $uRandomResult, $randomResult, true);
|
179 |
+
//
|
180 |
+
// }
|
181 |
+
//
|
182 |
+
// if(null !== $mCryptResult)
|
183 |
+
// {
|
184 |
+
// (null === $randomResult) ?
|
185 |
+
// $randomResult = $mCryptResult :
|
186 |
+
// $randomResult ^= hash_hmac('sha256', $mCryptResult, $randomResult, true);
|
187 |
+
// }
|
188 |
+
//
|
189 |
+
if((null === $randomResult) && self::isWindowsOS())
|
190 |
+
{
|
191 |
+
$randomResult = self::getBytesUsingCapicom($length);
|
192 |
+
}
|
193 |
+
|
194 |
+
|
195 |
+
return $randomResult;
|
196 |
+
}
|
197 |
+
|
198 |
+
|
199 |
+
|
200 |
+
private static function getBytesUsingCapicom($length)
|
201 |
+
{
|
202 |
+
static $canUseCapicom = null;
|
203 |
+
|
204 |
+
if(null !== $canUseCapicom && !$canUseCapicom)
|
205 |
+
{
|
206 |
+
return null;
|
207 |
+
}
|
208 |
+
|
209 |
+
if((null === $canUseCapicom) && (false === ($canUseCapicom = class_exists('\\COM', false))))
|
210 |
+
{
|
211 |
+
return null;
|
212 |
+
}
|
213 |
+
|
214 |
+
try
|
215 |
+
{
|
216 |
+
$comRandomBytes = new COM('CAPICOM.Utilities.1');
|
217 |
+
return str_pad(base64_decode($comRandomBytes->GetRandom($length, 0)), $length, chr(0));
|
218 |
+
}
|
219 |
+
catch (Exception $ex)
|
220 |
+
{
|
221 |
+
return null;
|
222 |
+
}
|
223 |
+
|
224 |
+
}
|
225 |
+
|
226 |
+
|
227 |
+
public static function canUseDevURandom()
|
228 |
+
{
|
229 |
+
static $canUseURandom = null;
|
230 |
+
|
231 |
+
return null !== $canUseURandom ? $canUseURandom : $canUseURandom = (@is_readable('/dev/urandom'));
|
232 |
+
}
|
233 |
+
|
234 |
+
private static function getBytesUsingDevURandom($length)
|
235 |
+
{
|
236 |
+
if(!self::canUseDevURandom())
|
237 |
+
return null;
|
238 |
+
|
239 |
+
if(PHP_VERSION_ID >= 50303)
|
240 |
+
{
|
241 |
+
if(! ($fileResource = fopen('/dev/urandom', 'rb')) || 0 !== stream_set_read_buffer($fileResource, 0))
|
242 |
+
{
|
243 |
+
fclose($fileResource);
|
244 |
+
return null;
|
245 |
+
}
|
246 |
+
|
247 |
+
$randomBytes = fread($fileResource, $length);
|
248 |
+
fclose($fileResource);
|
249 |
+
|
250 |
+
return $randomBytes;
|
251 |
+
}
|
252 |
+
|
253 |
+
$randomBytes = file_get_contents('/dev/urandom', false, null, -1, $length);
|
254 |
+
|
255 |
+
return (false !== $randomBytes) ? $randomBytes : null;
|
256 |
+
}
|
257 |
+
|
258 |
+
public static function canUseMCrypt()
|
259 |
+
{
|
260 |
+
static $canUseMCrypt = null; //http://bugs.php.net/55169
|
261 |
+
return null !== $canUseMCrypt ? $canUseMCrypt : $canUseMCrypt = (((PHP_VERSION_ID >= 50307) || !self::isWindowsOS()) &&
|
262 |
+
function_exists('mcrypt_create_iv'));
|
263 |
+
}
|
264 |
+
|
265 |
+
private static function getBytesUsingMCrypt($length)
|
266 |
+
{
|
267 |
+
if(!self::canUseMCrypt())
|
268 |
+
{
|
269 |
+
return null;
|
270 |
+
}
|
271 |
+
|
272 |
+
return (false !== ($randomBytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM))) ? $randomBytes : null;
|
273 |
+
}
|
274 |
+
|
275 |
+
|
276 |
+
public static function canUseOpenSSL()
|
277 |
+
{
|
278 |
+
static $canUseOpenSSL = null;
|
279 |
+
|
280 |
+
return null !== $canUseOpenSSL ? $canUseOpenSSL : $canUseOpenSSL = (((PHP_VERSION_ID >= 50304) || !self::isWindowsOS()) &&
|
281 |
+
function_exists('openssl_random_pseudo_bytes'));
|
282 |
+
}
|
283 |
+
|
284 |
+
|
285 |
+
private static function getBytesUsingOpenSSL($length)
|
286 |
+
{
|
287 |
+
if(!self::canUseOpenSSL())
|
288 |
+
{
|
289 |
+
return null;
|
290 |
+
}
|
291 |
+
|
292 |
+
$strongCryptoCreated = false;
|
293 |
+
$randomBytes = openssl_random_pseudo_bytes($length, $strongCryptoCreated);
|
294 |
+
|
295 |
+
return $strongCryptoCreated ? $randomBytes : null;
|
296 |
+
|
297 |
+
}
|
298 |
+
|
299 |
+
|
300 |
+
private static function getBytesUsingMTRand($length)
|
301 |
+
{
|
302 |
+
$randomBytes = '';
|
303 |
+
|
304 |
+
for($i = 0; $i < $length; $i++)
|
305 |
+
{
|
306 |
+
$randomBytes .= chr((mt_rand() ^ mt_rand()) % 256);
|
307 |
+
}
|
308 |
+
|
309 |
+
return $randomBytes;
|
310 |
+
}
|
311 |
+
|
312 |
+
|
313 |
+
public static function isWindowsOS()
|
314 |
+
{
|
315 |
+
return ('so' !== PHP_SHLIB_SUFFIX);
|
316 |
+
}
|
317 |
+
|
318 |
+
private function __construct()
|
319 |
+
{}
|
320 |
+
}
|
2.0/includes/vendor/MchCrypt/MchCrypt.php
ADDED
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright (C) 2014 Mihai Chelaru
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or
|
7 |
+
* modify it under the terms of the GNU General Public License
|
8 |
+
* as published by the Free Software Foundation; either version 2
|
9 |
+
* of the License, or (at your option) any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program; if not, write to the Free Software
|
18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
if (!defined('PHP_VERSION_ID'))
|
22 |
+
{
|
23 |
+
$version = explode('.', PHP_VERSION);
|
24 |
+
|
25 |
+
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
|
26 |
+
|
27 |
+
unset($version);
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
if( ! function_exists( 'mchCryptAutoLoader' ) )
|
32 |
+
{
|
33 |
+
|
34 |
+
function mchCryptAutoLoader($className)
|
35 |
+
{
|
36 |
+
|
37 |
+
static $arrClassMap = array(
|
38 |
+
'MchCrypt_Core_Generator' => '/Core/Generator.php',
|
39 |
+
'MchCrypt_Core_Crypter' => '/Core/Crypter.php',
|
40 |
+
'PhpCrypt' => '/PhpCrypt/phpCrypt.php',
|
41 |
+
'Crypt_Blowfish' => '/PhpSecLib-0.3.10/Crypt/Blowfish.php',
|
42 |
+
);
|
43 |
+
|
44 |
+
return isset($arrClassMap[$className]) ? include_once dirname(__FILE__) . $arrClassMap[$className] : null;
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
spl_autoload_register('mchCryptAutoLoader');
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
final class MchCrypt
|
53 |
+
{
|
54 |
+
CONST DERIVED_KEY_ITERATIONS = 1000;
|
55 |
+
|
56 |
+
public static function getRandomIntegerInRange($min = 1, $max = PHP_INT_MAX, $forceSecureRandomBytes = false)
|
57 |
+
{
|
58 |
+
return MchCrypt_Core_Generator::generateRandomIntegerInRange($min, $max, ((bool)$forceSecureRandomBytes) ? true : self::canGenerateSecureRandomBytes());
|
59 |
+
}
|
60 |
+
|
61 |
+
public static function getRandomString($strLength = 64, $forceSecureRandomBytes = false, $characters = null)
|
62 |
+
{
|
63 |
+
return MchCrypt_Core_Generator::generateRandomString($strLength, ((bool)$forceSecureRandomBytes) ? true : self::canGenerateSecureRandomBytes(), $characters);
|
64 |
+
}
|
65 |
+
|
66 |
+
public static function getRandomToken($tokenLength = 32, $isForUrl = true, $forceSecureRandomBytes = false)
|
67 |
+
{
|
68 |
+
$randomToken = base64_encode(self::getRandomString($tokenLength, $forceSecureRandomBytes));
|
69 |
+
|
70 |
+
return (!$isForUrl) ? $randomToken : str_replace( array('+', '/', '='), array('-', '_', ''), $randomToken);
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
public static function getRandomBytes($length, $forceSecure = false)
|
75 |
+
{
|
76 |
+
return MchCrypt_Core_Generator::generateRandomBytes($length, ((bool)$forceSecure) ? true : self::canGenerateSecureRandomBytes());
|
77 |
+
}
|
78 |
+
|
79 |
+
public static function getCipherKeySize($cipherId = MchCrypt_Core_Crypter::CIPHER_BLOWFISH, $encryptionModeId = MchCrypt_Core_Crypter::MODE_CBC)
|
80 |
+
{
|
81 |
+
$crypter = new MchCrypt_Core_Crypter($cipherId, $encryptionModeId);
|
82 |
+
return $crypter->getCipherKeySize();
|
83 |
+
}
|
84 |
+
|
85 |
+
|
86 |
+
private static function deriveKey($secretKey, $salt, $length)
|
87 |
+
{
|
88 |
+
|
89 |
+
if(PHP_VERSION_ID >= 50500)
|
90 |
+
{
|
91 |
+
return hash_pbkdf2('sha256', $secretKey, $salt, self::DERIVED_KEY_ITERATIONS, $length, true);
|
92 |
+
}
|
93 |
+
|
94 |
+
$blockCount = ceil($length / 32);
|
95 |
+
|
96 |
+
$hash = '';
|
97 |
+
for($i = 1; $i <= $blockCount; ++$i)
|
98 |
+
{
|
99 |
+
$last = $xorsum = hash_hmac('sha256', $salt . pack("N", $i), $secretKey, true);
|
100 |
+
for ($j = 1; $j < self::DERIVED_KEY_ITERATIONS ; ++$j)
|
101 |
+
{
|
102 |
+
$xorsum ^= ($last = hash_hmac('sha256', $last, $secretKey, true));
|
103 |
+
}
|
104 |
+
|
105 |
+
$hash .= $xorsum;
|
106 |
+
}
|
107 |
+
|
108 |
+
return substr($hash, 0, $length);
|
109 |
+
}
|
110 |
+
|
111 |
+
private static function compareDerivedKeys($firstDerivedKey, $secondDerivedKey)
|
112 |
+
{
|
113 |
+
$firstDerivedKey = (string) $firstDerivedKey;
|
114 |
+
$secondDerivedKey = (string) $secondDerivedKey;
|
115 |
+
$firstDerivedKeyLength = strlen($firstDerivedKey);
|
116 |
+
$secondDerivedKeyLength = strlen($secondDerivedKey);
|
117 |
+
|
118 |
+
$result = 0;
|
119 |
+
for ($i = 0, $length = min($firstDerivedKeyLength, $secondDerivedKeyLength); $i < $length; ++$i)
|
120 |
+
{
|
121 |
+
$result |= ord($firstDerivedKey[$i]) ^ ord($secondDerivedKey[$i]);
|
122 |
+
}
|
123 |
+
|
124 |
+
return (0 === ($result |= $firstDerivedKeyLength ^ $secondDerivedKeyLength));
|
125 |
+
|
126 |
+
}
|
127 |
+
|
128 |
+
public static function encryptToken($secretKey, $strTextToEncrypt, $cipherId = MchCrypt_Core_Crypter::CIPHER_BLOWFISH, $encryptionModeId = MchCrypt_Core_Crypter::MODE_CBC)
|
129 |
+
{
|
130 |
+
try
|
131 |
+
{
|
132 |
+
$crypter = new MchCrypt_Core_Crypter($cipherId, $encryptionModeId);
|
133 |
+
|
134 |
+
// $cryptBlowfish = new Crypt_Blowfish();
|
135 |
+
// $cryptBlowfish->setPassword($secretKey, 'pbkdf2', 'sha1', $crypter->getRandomSalt(), 1000);
|
136 |
+
// $encryptedToken = $cryptBlowfish->encrypt($strTextToEncrypt);
|
137 |
+
|
138 |
+
$derivedKey = self::deriveKey($secretKey, $crypter->getRandomSalt(), 2 * $crypter->getCipherKeySize());
|
139 |
+
|
140 |
+
$cipherSecretKey = substr($derivedKey, 0, $crypter->getCipherKeySize());
|
141 |
+
|
142 |
+
$crypter->setSecretKey($cipherSecretKey);
|
143 |
+
|
144 |
+
$encryptedData = $crypter->encrypt(self::tryToCompressString($strTextToEncrypt));
|
145 |
+
|
146 |
+
$tokenKeyHmac = substr($derivedKey, $crypter->getCipherKeySize());
|
147 |
+
|
148 |
+
$hashedToken = hash_hmac('md5', $encryptedData, $tokenKeyHmac, true);
|
149 |
+
|
150 |
+
$encryptedToken = $hashedToken . $encryptedData;
|
151 |
+
|
152 |
+
|
153 |
+
return str_replace( array('+', '/', '='), array('-', '_', ''), base64_encode($encryptedToken));
|
154 |
+
|
155 |
+
}
|
156 |
+
catch(Exception $ex)
|
157 |
+
{
|
158 |
+
return null;
|
159 |
+
//$exClass = get_class($ex);
|
160 |
+
//throw new $exClass($ex->getMessage());
|
161 |
+
}
|
162 |
+
|
163 |
+
|
164 |
+
}
|
165 |
+
|
166 |
+
|
167 |
+
public static function decryptToken($secretKey, $strEncryptedToken, $cipherId = MchCrypt_Core_Crypter::CIPHER_BLOWFISH, $encryptionModeId = MchCrypt_Core_Crypter::MODE_CBC)
|
168 |
+
{
|
169 |
+
try
|
170 |
+
{
|
171 |
+
$strEncryptedToken = str_replace(array('-','_'), array('+','/'), $strEncryptedToken);
|
172 |
+
|
173 |
+
if(0 !== ($mod4 = strlen($strEncryptedToken) % 4))
|
174 |
+
{
|
175 |
+
$strEncryptedToken .= substr('====', $mod4);
|
176 |
+
}
|
177 |
+
|
178 |
+
$hmacSize = 16;
|
179 |
+
$strEncryptedToken = base64_decode($strEncryptedToken);
|
180 |
+
|
181 |
+
if(false === $strEncryptedToken || !isset($strEncryptedToken[$hmacSize -1]))
|
182 |
+
return null;
|
183 |
+
|
184 |
+
$hashedToken = substr($strEncryptedToken, 0, $hmacSize);
|
185 |
+
$encryptedData = substr($strEncryptedToken, $hmacSize);
|
186 |
+
|
187 |
+
if(empty($encryptedData) || empty($hashedToken))
|
188 |
+
return null;
|
189 |
+
|
190 |
+
$crypter = new MchCrypt_Core_Crypter($cipherId, $encryptionModeId);
|
191 |
+
|
192 |
+
$derivedKey = self::deriveKey($secretKey, substr($encryptedData, 0, $crypter->getCipherSaltSize()), 2 * $crypter->getCipherKeySize());
|
193 |
+
$cipherSecretKey = substr($derivedKey, 0, $crypter->getCipherKeySize());
|
194 |
+
|
195 |
+
if(empty($cipherSecretKey))
|
196 |
+
return null;
|
197 |
+
|
198 |
+
$crypter->setSecretKey($cipherSecretKey);
|
199 |
+
|
200 |
+
$tokenKeyHmac = substr($derivedKey, $crypter->getCipherKeySize());
|
201 |
+
|
202 |
+
$expectedHashedToken = hash_hmac('md5', $encryptedData, $tokenKeyHmac, true);
|
203 |
+
|
204 |
+
|
205 |
+
return self::compareDerivedKeys($expectedHashedToken, $hashedToken) ? self::decompressString($crypter->decrypt($encryptedData)) : null;
|
206 |
+
|
207 |
+
}
|
208 |
+
catch(Exception $ex)
|
209 |
+
{
|
210 |
+
return null;
|
211 |
+
|
212 |
+
// $exClass = get_class($ex);
|
213 |
+
// throw new $exClass($ex->getMessage());
|
214 |
+
}
|
215 |
+
|
216 |
+
}
|
217 |
+
|
218 |
+
|
219 |
+
private static function tryToCompressString($strToCompress)
|
220 |
+
{
|
221 |
+
|
222 |
+
if(!isset($strToCompress[0]))
|
223 |
+
return $strToCompress;
|
224 |
+
|
225 |
+
if(self::isZLibAvailable())
|
226 |
+
return gzdeflate($strToCompress, 9);
|
227 |
+
|
228 |
+
if(self::isBZip2Available())
|
229 |
+
return bzcompress($strToCompress, 9);
|
230 |
+
|
231 |
+
if(self::isLzfAvailable())
|
232 |
+
return lzf_compress($strToCompress);
|
233 |
+
|
234 |
+
return $strToCompress;
|
235 |
+
}
|
236 |
+
|
237 |
+
private static function decompressString($compressedStr)
|
238 |
+
{
|
239 |
+
if(!isset($compressedStr[0]))
|
240 |
+
return $compressedStr;
|
241 |
+
|
242 |
+
if(self::isZLibAvailable())
|
243 |
+
return gzinflate($compressedStr);
|
244 |
+
|
245 |
+
if(self::isBZip2Available())
|
246 |
+
return bzdecompress($compressedStr);
|
247 |
+
|
248 |
+
if(self::isLzfAvailable())
|
249 |
+
return lzf_decompress($compressedStr);
|
250 |
+
|
251 |
+
return $compressedStr;
|
252 |
+
|
253 |
+
}
|
254 |
+
|
255 |
+
public static function isWindowsOS()
|
256 |
+
{
|
257 |
+
return MchCrypt_Core_Generator::isWindowsOS();
|
258 |
+
}
|
259 |
+
|
260 |
+
public static function canUseMCrypt()
|
261 |
+
{
|
262 |
+
return MchCrypt_Core_Generator::canUseMCrypt();
|
263 |
+
}
|
264 |
+
|
265 |
+
public static function canGenerateSecureRandomBytes()
|
266 |
+
{
|
267 |
+
return MchCrypt_Core_Generator::canGenerateSecure();
|
268 |
+
}
|
269 |
+
|
270 |
+
public static function isZLibAvailable()
|
271 |
+
{
|
272 |
+
static $isLoaded = null;
|
273 |
+
return null !== $isLoaded ? $isLoaded : $isLoaded = extension_loaded('zlib');
|
274 |
+
}
|
275 |
+
|
276 |
+
public static function isBZip2Available()
|
277 |
+
{
|
278 |
+
static $isLoaded = null;
|
279 |
+
return null !== $isLoaded ? $isLoaded : $isLoaded = extension_loaded('bz2');
|
280 |
+
}
|
281 |
+
|
282 |
+
public static function isLzfAvailable()
|
283 |
+
{
|
284 |
+
static $isLoaded = null;
|
285 |
+
return null !== $isLoaded ? $isLoaded : $isLoaded = extension_loaded('lzf');
|
286 |
+
|
287 |
+
}
|
288 |
+
|
289 |
+
private function __construct()
|
290 |
+
{}
|
291 |
+
}
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Cipher.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Core.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Includes.inc.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Mode.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/Padding.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/README.md
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/3DES.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/3Way.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/AES128.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/AES192.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/AES256.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/ARC4.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Blowfish.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/CAST128.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/CAST256.php
RENAMED
File without changes
|
2.0/includes/vendor/MchCrypt/PhpCrypt/ciphers/DES.php
ADDED
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Author: Ryan Gilfether
|
4 |
+
* URL: http://www.gilfether.com/phpCrypt
|
5 |
+
* Date: Sep 4, 2005
|
6 |
+
* Copyright (C) 2005 Ryan Gilfether
|
7 |
+
*
|
8 |
+
* This file is part of phpCrypt
|
9 |
+
*
|
10 |
+
* phpCrypt is free software; you can redistribute it and/or modify
|
11 |
+
* it under the terms of the GNU General Public License as published by
|
12 |
+
* the Free Software Foundation; either version 3 of the License, or
|
13 |
+
* (at your option) any later version
|
14 |
+
*
|
15 |
+
* This program is distributed in the hope that it will be useful,
|
16 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
+
* GNU General Public License for more details.
|
19 |
+
*
|
20 |
+
* You should have received a copy of the GNU General Public License
|
21 |
+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
22 |
+
*/
|
23 |
+
|
24 |
+
|
25 |
+
require_once(dirname(__FILE__)."/../Cipher.php");
|
26 |
+
require_once(dirname(__FILE__)."/../phpCrypt.php");
|
27 |
+
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Implements DES Encryption
|
31 |
+
* Resources used to implement this algorithm:
|
32 |
+
* J. Orlin Grabbe, The Des Algorithm Illustrated, http://orlingrabbe.com/des.htm
|
33 |
+
* Bruce Schneier, Applied Cryptography (2nd edition), 1996, pp. 265-300
|
34 |
+
*
|
35 |
+
* @author Ryan Gilfether
|
36 |
+
* @link http://www.gilfether.com/phpcrypt
|
37 |
+
* @copyright 2005 Ryan Gilfether
|
38 |
+
*/
|
39 |
+
class PhpCrypt_Cipher_DES extends PhpCrypt_Cipher
|
40 |
+
{
|
41 |
+
/** @type integer BYTES_BLOCK The block size, in bytes */
|
42 |
+
const BYTES_BLOCK = 8; // 64 bits
|
43 |
+
|
44 |
+
/** @type integer BYTES_KEY The key size, in bytes */
|
45 |
+
const BYTES_KEY = 8; // 64 bits
|
46 |
+
|
47 |
+
/** @type array $sub_keys The permutated subkeys */
|
48 |
+
protected $sub_keys = array();
|
49 |
+
|
50 |
+
/*
|
51 |
+
* Tables initialized in the initTables()
|
52 |
+
*/
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @type array $_pc1 Permutated choice 1 (PC1),
|
56 |
+
* This should be considered a constant
|
57 |
+
*/
|
58 |
+
protected static $_pc1 = array();
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @type array $_pc2 Permutated choice 2 (PC2),
|
62 |
+
* This should be considered a constant
|
63 |
+
*/
|
64 |
+
protected static $_pc2 = array();
|
65 |
+
|
66 |
+
/**
|
67 |
+
* @type array $_key_sched The key schedule,
|
68 |
+
* This should be considered a constant
|
69 |
+
*/
|
70 |
+
protected static $_key_sched = array();
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @type array $_ip The Initial Permutation (IP),
|
74 |
+
* This should be considered a constant
|
75 |
+
*/
|
76 |
+
private static $_ip = array();
|
77 |
+
|
78 |
+
/**
|
79 |
+
* @type array $_e The Expansion table (E),
|
80 |
+
* This should be considered a constant
|
81 |
+
*/
|
82 |
+
private static $_e = array();
|
83 |
+
|
84 |
+
/**
|
85 |
+
* @type array $_s The Substitution Box (S),
|
86 |
+
* This should be considered a constant
|
87 |
+
*/
|
88 |
+
private static $_s = array();
|
89 |
+
|
90 |
+
/**
|
91 |
+
* @type array $_p The Permutation table (P),
|
92 |
+
* This should be considered a constant
|
93 |
+
*/
|
94 |
+
private static $_p = array();
|
95 |
+
|
96 |
+
/**
|
97 |
+
* @type array $_ip The The Final Permutation table (FP),
|
98 |
+
* This should be considered a constant
|
99 |
+
*/
|
100 |
+
private static $_fp = array();
|
101 |
+
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Constructor, used only when calling this class directly
|
105 |
+
* for classes that extend this class, call __construct1()
|
106 |
+
*
|
107 |
+
* @param string $key The key used for Encryption/Decryption
|
108 |
+
* @return void
|
109 |
+
*/
|
110 |
+
public function __construct($key)
|
111 |
+
{
|
112 |
+
// set the DES key
|
113 |
+
parent::__construct(PhpCrypt::CIPHER_DES, $key, self::BYTES_KEY);
|
114 |
+
|
115 |
+
// initialize variables
|
116 |
+
$this->initTables();
|
117 |
+
|
118 |
+
// DES requires that data is 64 bits
|
119 |
+
$this->blockSize(self::BYTES_BLOCK);
|
120 |
+
|
121 |
+
// create the 16 rounds of 56 bit keys
|
122 |
+
$this->keyPermutation();
|
123 |
+
}
|
124 |
+
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Second Constructor, used only by child classes that extend this class
|
128 |
+
*
|
129 |
+
* @param string $cipher The name of the cipher extending this class
|
130 |
+
* @param string $key The key used for Encryption/Decryption
|
131 |
+
* @param integer $key_byte_sz The required byte size of the extending cipher
|
132 |
+
* @return void
|
133 |
+
*/
|
134 |
+
protected function __construct1($cipher, $key, $key_byte_sz)
|
135 |
+
{
|
136 |
+
// set the key and key size
|
137 |
+
parent::__construct($cipher, $key, $key_byte_sz);
|
138 |
+
|
139 |
+
// initialize variables
|
140 |
+
$this->initTables();
|
141 |
+
}
|
142 |
+
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Destructor
|
146 |
+
*
|
147 |
+
* @return void
|
148 |
+
*/
|
149 |
+
public function __destruct()
|
150 |
+
{
|
151 |
+
parent::__destruct();
|
152 |
+
}
|
153 |
+
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Encrypt plain text data using DES
|
157 |
+
*
|
158 |
+
* @param string $data A plain text string
|
159 |
+
* @return boolean Returns true
|
160 |
+
*/
|
161 |
+
public function encrypt(&$text)
|
162 |
+
{
|
163 |
+
$this->operation(parent::ENCRYPT);
|
164 |
+
return $this->des($text);
|
165 |
+
}
|
166 |
+
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Decrypt a DES encrypted string
|
170 |
+
*
|
171 |
+
* @param string $encrypted A DES encrypted string
|
172 |
+
* @return boolean Returns true
|
173 |
+
*/
|
174 |
+
public function decrypt(&$text)
|
175 |
+
{
|
176 |
+
$this->operation(parent::DECRYPT);
|
177 |
+
return $this->des($text);
|
178 |
+
}
|
179 |
+
|
180 |
+
|
181 |
+
/**
|
182 |
+
* This is where the actual encrypt/decryption takes place. Since
|
183 |
+
* encryption and decryption are the same algorithm in DES, we only
|
184 |
+
* need one function to do both.
|
185 |
+
*
|
186 |
+
* @param string $data The string to be encrypted or decrypted
|
187 |
+
* @return boolean Returns true
|
188 |
+
*/
|
189 |
+
protected function des(&$data)
|
190 |
+
{
|
191 |
+
$l = array();
|
192 |
+
$r = array();
|
193 |
+
|
194 |
+
// step two: Initial Permutation (IP) of plaintext
|
195 |
+
$data = $this->ip($data);
|
196 |
+
|
197 |
+
// divide the permuted block IP into a left half L0 of 32 bits,
|
198 |
+
// and a right half R0 of 32 bits
|
199 |
+
$l[0] = substr($data, 0, 32);
|
200 |
+
$r[0] = substr($data, 32, 32);
|
201 |
+
|
202 |
+
for($n = 1; $n <= 16; ++$n)
|
203 |
+
{
|
204 |
+
$l[$n] = $r[$n-1];
|
205 |
+
|
206 |
+
if($this->operation() == parent::DECRYPT)
|
207 |
+
$f = $this->F($r[$n-1], $this->sub_keys[16-$n]);
|
208 |
+
else
|
209 |
+
$f = $this->F($r[$n-1], $this->sub_keys[$n-1]);
|
210 |
+
|
211 |
+
// XOR F with Ln
|
212 |
+
$r[$n] = $this->xorBin($l[$n-1], $f);
|
213 |
+
}
|
214 |
+
|
215 |
+
// now we combine L[16] and R[16] back into a 64-bit string, but we reverse
|
216 |
+
// L[16] and R[16] so that it becomes R[16]L[16]
|
217 |
+
$data = $r[16].$l[16];
|
218 |
+
|
219 |
+
// now do the final permutation
|
220 |
+
$data = $this->fp($data);
|
221 |
+
$data = parent::bin2Str($data);
|
222 |
+
|
223 |
+
return true;
|
224 |
+
}
|
225 |
+
|
226 |
+
|
227 |
+
/**
|
228 |
+
* The Key permutation, based on tables $_pc1 and $_pc2
|
229 |
+
* Create 16 subkeys, each of which is 48-bits long.
|
230 |
+
*
|
231 |
+
* @return void
|
232 |
+
*/
|
233 |
+
private function keyPermutation()
|
234 |
+
{
|
235 |
+
$this->sub_keys = array();
|
236 |
+
$pc1m = array();
|
237 |
+
$pcr = array();
|
238 |
+
$c = array();
|
239 |
+
$d = array();
|
240 |
+
|
241 |
+
// convert the key to binary
|
242 |
+
$binkey = parent::str2Bin($this->key());
|
243 |
+
|
244 |
+
// reduce the key down to 56bits based on table $_pc1
|
245 |
+
for($i = 0; $i < 56; ++$i)
|
246 |
+
$pc1m[$i] = $binkey[self::$_pc1[$i] - 1];
|
247 |
+
|
248 |
+
// split $pc1m in half (C0 and D0)
|
249 |
+
$c[0] = array_slice($pc1m, 0, 28);
|
250 |
+
$d[0] = array_slice($pc1m, 28, 28);
|
251 |
+
|
252 |
+
// now that $c[0] and $d[0] are defined, create 16 blocks for Cn and Dn
|
253 |
+
// where 1 <= n <= 16
|
254 |
+
for($i = 1; $i <= 16; ++$i)
|
255 |
+
{
|
256 |
+
// now set the next Cn and Dn as the previous Cn and Dn
|
257 |
+
$c[$i] = $c[$i-1];
|
258 |
+
$d[$i] = $d[$i-1];
|
259 |
+
|
260 |
+
for($j = 0; $j < self::$_key_sched[$i-1]; ++$j)
|
261 |
+
{
|
262 |
+
// do a left shift, move each bit one place to the left,
|
263 |
+
// except for the first bit, which is cycled to the end
|
264 |
+
// of the block.
|
265 |
+
$c[$i][] = array_shift($c[$i]);
|
266 |
+
$d[$i][] = array_shift($d[$i]);
|
267 |
+
}
|
268 |
+
|
269 |
+
// We now form the sub_keys (Kn), for 1<=n<=16, by applying the
|
270 |
+
// following permutation table to each of the concatenated
|
271 |
+
// pairs CnDn. Each pair has 56 bits, but PC-2 only uses 48
|
272 |
+
// of these.
|
273 |
+
$CnDn = array_merge($c[$i], $d[$i]);
|
274 |
+
$this->sub_keys[$i-1] = "";
|
275 |
+
for($j = 0; $j < 48; ++$j)
|
276 |
+
$this->sub_keys[$i-1] .= $CnDn[self::$_pc2[$j] - 1];
|
277 |
+
}
|
278 |
+
|
279 |
+
// the sub_keys are created, we are done with the key permutation
|
280 |
+
}
|
281 |
+
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Initial Permutation (IP)
|
285 |
+
* Now we encode each 64-bit block of data. There is an initial permutation IP of
|
286 |
+
* the 64 bits of the message data M. This rearranges the bits according to the
|
287 |
+
* following table, where the entries in the table show the new arrangement of the
|
288 |
+
* bits from their initial order. The 58th bit of M becomes the first bit of IP.
|
289 |
+
* The 50th bit of M becomes the second bit of IP. The 7th bit of M is the last
|
290 |
+
* bit of IP.
|
291 |
+
*
|
292 |
+
* According to the book Applied Cryptography (Bruce Schneier, 2nd edition, pg. 271):
|
293 |
+
* The initial permution was used to make it easier to load plain text and cipher text
|
294 |
+
* data into a DES chip in byte-sized pieces when doing DES in hardware. The IP and FP
|
295 |
+
* are not necessary in software implementations and do not affect the security. However,
|
296 |
+
* the IP and FP are part of the DES standard and not implementing it would deviate from
|
297 |
+
* the standard, so we will do it here in phpCrypt.
|
298 |
+
*
|
299 |
+
* @param string $m The plain text message
|
300 |
+
* @return array the Initial Permutation (IP)
|
301 |
+
*/
|
302 |
+
private function ip($text)
|
303 |
+
{
|
304 |
+
$text = parent::str2Bin($text);
|
305 |
+
$ip = "";
|
306 |
+
|
307 |
+
// loop through the 64 bit block, ordering it occording to $_ip
|
308 |
+
for($i = 0; $i < 64; ++$i)
|
309 |
+
$ip .= $text[self::$_ip[$i] - 1];
|
310 |
+
|
311 |
+
return $ip;
|
312 |
+
}
|
313 |
+
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Function F - To calculate f, we first expand each block Rn-1 from 32 bits to 48 bits.
|
317 |
+
* This is done by using a selection table that repeats some of the bits in Rn-1. We'll
|
318 |
+
* call the use of this selection table the function E. Thus E(Rn-1) has a 32 bit input
|
319 |
+
* block, and a 48 bit output block.
|
320 |
+
*
|
321 |
+
* @param array $r 32 bit binary, each bit in an array element
|
322 |
+
* @param string $k 48 bit binary string
|
323 |
+
* @return string 48 bit binary string
|
324 |
+
*/
|
325 |
+
private function f($r, $k)
|
326 |
+
{
|
327 |
+
$bin = parent::xorBin($k, $this->E($r));
|
328 |
+
|
329 |
+
// create a 32-bit string from $bits by passing it through the S-Boxes
|
330 |
+
$bin = $this->s($bin);
|
331 |
+
|
332 |
+
// now send permute $bin as defined by table self::$_p
|
333 |
+
$bin = $this->p($bin);
|
334 |
+
|
335 |
+
return $bin;
|
336 |
+
}
|
337 |
+
|
338 |
+
|
339 |
+
/**
|
340 |
+
* Function E - Let E be such that the 48 bits of its output, written as 8 blocks of
|
341 |
+
* 6 bits each, are obtained by selecting the bits in its inputs in order according
|
342 |
+
* to the self::$_e[] table.
|
343 |
+
* This is only used in the F() function
|
344 |
+
*
|
345 |
+
* @param array $r 32 bit binary, each bit in an array element
|
346 |
+
* @return string 48 bit binary string
|
347 |
+
*/
|
348 |
+
private function e($r)
|
349 |
+
{
|
350 |
+
$e = "";
|
351 |
+
for($i = 0; $i < 48; ++$i)
|
352 |
+
$e .= $r[self::$_e[$i] - 1];
|
353 |
+
|
354 |
+
return $e;
|
355 |
+
}
|
356 |
+
|
357 |
+
|
358 |
+
/**
|
359 |
+
* S-Box
|
360 |
+
* Take a 48-bit string from F() and run it through the S-Boxes, this requires
|
361 |
+
* us to break up the 48-bit string into 8 groups of 6 bits before sending it
|
362 |
+
* through the S-Boxes
|
363 |
+
*
|
364 |
+
* @param string $bits The 48-bit string from F() to be processed
|
365 |
+
* @return string A 32-bit string from created from the 48-bit string after passing through S-Boxes
|
366 |
+
*/
|
367 |
+
private function s($bits)
|
368 |
+
{
|
369 |
+
$s = "";
|
370 |
+
|
371 |
+
for($i = 0; $i <= 42; $i += 6)
|
372 |
+
{
|
373 |
+
$sbits = substr($bits, $i, 6);
|
374 |
+
|
375 |
+
// we need to determine the S-Box column number and row number
|
376 |
+
// from the 6 bit string passed in, this is done using the following method:
|
377 |
+
// The First & Last bits represent a number between 0-3, used to determine which row
|
378 |
+
// The middle 4 bits represent a number between 0-15, used to determine the column
|
379 |
+
$row = bindec("{$sbits[0]}{$sbits[5]}");
|
380 |
+
$col = bindec("{$sbits[1]}{$sbits[2]}{$sbits[3]}{$sbits[4]}");
|
381 |
+
|
382 |
+
// determine the position in the S-BOX, S-Box table is in self::$_s[]
|
383 |
+
$pos = ($row * 16) + $col;
|
384 |
+
|
385 |
+
// get the integer from the S-Box and convert it to binary
|
386 |
+
$bin = decbin(self::$_s[($i/6)][$pos]);
|
387 |
+
$s .= str_pad($bin, 4, "0", STR_PAD_LEFT);
|
388 |
+
}
|
389 |
+
|
390 |
+
return $s;
|
391 |
+
}
|
392 |
+
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Permutation P
|
396 |
+
* The permutation P is defined in self::$_p. P() returns a 32-bit output
|
397 |
+
* from a 32-bit input from a binary string from the S-BOX by permuting
|
398 |
+
* the bits of the input block.
|
399 |
+
* This is only used inside of F() function
|
400 |
+
*
|
401 |
+
* @param string $s A 32-bit string originating from being passed through S-Box
|
402 |
+
* @return string A 32-bit string, which is $s permuted through table self::$_p
|
403 |
+
*/
|
404 |
+
private function p($s)
|
405 |
+
{
|
406 |
+
$p = "";
|
407 |
+
for($i = 0; $i < 32; ++$i)
|
408 |
+
$p .= $s[self::$_p[$i] - 1];
|
409 |
+
|
410 |
+
return $p;
|
411 |
+
}
|
412 |
+
|
413 |
+
|
414 |
+
/**
|
415 |
+
* Final Permutation (FP)
|
416 |
+
* Read the comment about IP and FP being unecessary in software implmented DES (though
|
417 |
+
* we will do it to follow the DES standard).
|
418 |
+
*
|
419 |
+
* @param string $bin A 64-bit binary string
|
420 |
+
* @return string A 64-bit binary string that has been run through self::$_fp[] table
|
421 |
+
*/
|
422 |
+
private function fp($bin)
|
423 |
+
{
|
424 |
+
$fp = "";
|
425 |
+
for($i = 0; $i < 64; ++$i)
|
426 |
+
$fp .= $bin[self::$_fp[$i] - 1];
|
427 |
+
|
428 |
+
return $fp;
|
429 |
+
}
|
430 |
+
|
431 |
+
|
432 |
+
/**
|
433 |
+
* Initialize all the tables, this function is called inside the constructor
|
434 |
+
*
|
435 |
+
* @return void
|
436 |
+
*/
|
437 |
+
private function initTables()
|
438 |
+
{
|
439 |
+
// permuted choice 1 (PC1)
|
440 |
+
// these values are chars and should be run through chr() when used
|
441 |
+
self::$_pc1 = array(
|
442 |
+
57, 49, 41, 33, 25, 17, 9,
|
443 |
+
1, 58, 50, 42, 34, 26, 18,
|
444 |
+
10, 2, 59, 51, 43, 35, 27,
|
445 |
+
19, 11, 3, 60, 52, 44, 36,
|
446 |
+
63, 55, 47, 39, 31, 23, 15,
|
447 |
+
7, 62, 54, 46, 38, 30, 22,
|
448 |
+
14, 6, 61, 53, 45, 37, 29,
|
449 |
+
21, 13, 5, 28, 20, 12, 4
|
450 |
+
);
|
451 |
+
|
452 |
+
// permuted choice 2 (PC2)
|
453 |
+
// these values are chars and should be run through chr() when used
|
454 |
+
self::$_pc2 = array(
|
455 |
+
14, 17, 11, 24, 1, 5,
|
456 |
+
3, 28, 15, 6, 21, 10,
|
457 |
+
23, 19, 12, 4, 26, 8,
|
458 |
+
16, 7, 27, 20, 13, 2,
|
459 |
+
41, 52, 31, 37, 47, 55,
|
460 |
+
30, 40, 51, 45, 33, 48,
|
461 |
+
44, 49, 39, 56, 34, 53,
|
462 |
+
46, 42, 50, 36, 29, 32
|
463 |
+
);
|
464 |
+
|
465 |
+
// initial permutation (IP)
|
466 |
+
self::$_ip = array(
|
467 |
+
58, 50, 42, 34, 26, 18, 10, 2,
|
468 |
+
60, 52, 44, 36, 28, 20, 12, 4,
|
469 |
+
62, 54, 46, 38, 30, 22, 14, 6,
|
470 |
+
64, 56, 48, 40, 32, 24, 16, 8,
|
471 |
+
57, 49, 41, 33, 25, 17, 9, 1,
|
472 |
+
59, 51, 43, 35, 27, 19, 11, 3,
|
473 |
+
61, 53, 45, 37, 29, 21, 13, 5,
|
474 |
+
63, 55, 47, 39, 31, 23, 15, 7
|
475 |
+
);
|
476 |
+
|
477 |
+
// expansion (E)
|
478 |
+
self::$_e = array(
|
479 |
+
32, 1, 2, 3, 4, 5,
|
480 |
+
4, 5, 6, 7, 8, 9,
|
481 |
+
8, 9, 10, 11, 12, 13,
|
482 |
+
12, 13, 14, 15, 16, 17,
|
483 |
+
16, 17, 18, 19, 20, 21,
|
484 |
+
20, 21, 22, 23, 24, 25,
|
485 |
+
24, 25, 26, 27, 28, 29,
|
486 |
+
28, 29, 30, 31, 32, 1
|
487 |
+
);
|
488 |
+
|
489 |
+
// substition box (S)
|
490 |
+
self::$_s = array(
|
491 |
+
/* S1 */
|
492 |
+
array(
|
493 |
+
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
|
494 |
+
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
|
495 |
+
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
|
496 |
+
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
|
497 |
+
),
|
498 |
+
|
499 |
+
/* S2 */
|
500 |
+
array(
|
501 |
+
15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
|
502 |
+
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
|
503 |
+
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
|
504 |
+
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
|
505 |
+
),
|
506 |
+
|
507 |
+
/* S3 */
|
508 |
+
array(
|
509 |
+
10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
|
510 |
+
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
|
511 |
+
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
|
512 |
+
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
|
513 |
+
),
|
514 |
+
|
515 |
+
/* S4 */
|
516 |
+
array(
|
517 |
+
7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
|
518 |
+
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
|
519 |
+
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
|
520 |
+
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
|
521 |
+
),
|
522 |
+
|
523 |
+
/* S5 */
|
524 |
+
array(
|
525 |
+
2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
|
526 |
+
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
|
527 |
+
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
|
528 |
+
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
|
529 |
+
),
|
530 |
+
|
531 |
+
/* S6 */
|
532 |
+
array(
|
533 |
+
12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
|
534 |
+
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
|
535 |
+
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
|
536 |
+
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
|
537 |
+
),
|
538 |
+
|
539 |
+
/* S7 */
|
540 |
+
array(
|
541 |
+
4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
|
542 |
+
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
|
543 |
+
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
|
544 |
+
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
|
545 |
+
),
|
546 |
+
|
547 |
+
/* S8 */
|
548 |
+
array(
|
549 |
+
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
|
550 |
+
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
|
551 |
+
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
|
552 |
+
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
|
553 |
+
)
|
554 |
+
);
|
555 |
+
|
556 |
+
// permutation (P)
|
557 |
+
self::$_p = array(
|
558 |
+
16, 7, 20, 21,
|
559 |
+
29, 12, 28, 17,
|
560 |
+
1, 15, 23, 26,
|
561 |
+
5, 18, 31, 10,
|
562 |
+
2, 8, 24, 14,
|
563 |
+
32, 27, 3, 9,
|
564 |
+
19, 13, 30, 6,
|
565 |
+
22, 11, 4, 25
|
566 |
+
);
|
567 |
+
|
568 |
+
// final permutation (FP)
|
569 |
+
self::$_fp = array(
|
570 |
+
40, 8, 48, 16, 56, 24, 64, 32,
|
571 |
+
39, 7, 47, 15, 55, 23, 63, 31,
|
572 |
+
38, 6, 46, 14, 54, 22, 62, 30,
|
573 |
+
37, 5, 45, 13, 53, 21, 61, 29,
|
574 |
+
36, 4, 44, 12, 52, 20, 60, 28,
|
575 |
+
35, 3, 43, 11, 51, 19, 59, 27,
|
576 |
+
34, 2, 42, 10, 50, 18, 58, 26,
|
577 |
+
33, 1, 41, 9, 49, 17, 57, 25
|
578 |
+
);
|
579 |
+
|
580 |
+
// key schedule used in KeyPermutation()
|
581 |
+
self::$_key_sched = array(1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1);
|
582 |
+
}
|
583 |
+
|
584 |
+
|
585 |
+
/**
|
586 |
+
* Indicates this is a block cipher
|
587 |
+
*
|
588 |
+
* @return integer Returns Cipher::BLOCK
|
589 |
+
*/
|
590 |
+
public function type()
|
591 |
+
{
|
592 |
+
return parent::BLOCK;
|
593 |
+
}
|
594 |
+
}
|
595 |
+
?>
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Enigma.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/RC2.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael.php
RENAMED
File without changes
|
2.0/includes/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael128.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Author: Ryan Gilfether
|
4 |
+
* URL: http://www.gilfether.com/phpCrypt
|
5 |
+
* Date: April 3, 2013
|
6 |
+
* Copyright (C) 2013 Ryan Gilfether
|
7 |
+
*
|
8 |
+
* This file is part of phpCrypt
|
9 |
+
*
|
10 |
+
* phpCrypt is free software; you can redistribute it and/or modify
|
11 |
+
* it under the terms of the GNU General Public License as published by
|
12 |
+
* the Free Software Foundation; either version 3 of the License, or
|
13 |
+
* (at your option) any later version
|
14 |
+
*
|
15 |
+
* This program is distributed in the hope that it will be useful,
|
16 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
+
* GNU General Public License for more details.
|
19 |
+
*
|
20 |
+
* You should have received a copy of the GNU General Public License
|
21 |
+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
22 |
+
*/
|
23 |
+
|
24 |
+
|
25 |
+
require_once(dirname(__FILE__)."/Rijndael.php");
|
26 |
+
require_once(dirname(__FILE__)."/../phpCrypt.php");
|
27 |
+
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Implement Rijndael with a 16 bytes (128 bits) data block
|
31 |
+
* Key sizes can be 16, 24, 32 bytes (128, 192, 256 bits)
|
32 |
+
* References used to implement this cipher:
|
33 |
+
* http://www.net-security.org/dl/articles/AESbyExample.pdf
|
34 |
+
*
|
35 |
+
* @author Ryan Gilfether
|
36 |
+
* @link http://www.gilfether.com/phpcrypt
|
37 |
+
* @copyright 2013 Ryan Gilfether
|
38 |
+
*/
|
39 |
+
class PhpCrypt_Cipher_Rijndael_128 extends PhpCrypt_Cipher_Rijndael
|
40 |
+
{
|
41 |
+
/** @type integer BITS_BLOCK The size of the block, in bits */
|
42 |
+
const BYTES_BLOCK = 16;
|
43 |
+
|
44 |
+
//const BITS_KEY = 0;
|
45 |
+
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Constructor
|
49 |
+
* Sets the key used for encryption. Also sets the requied block size
|
50 |
+
* This should only be used when calling this class directly, for classes
|
51 |
+
* that extend this class, they should call __construct1()
|
52 |
+
*
|
53 |
+
* @param string $key string containing the user supplied encryption key
|
54 |
+
* @return void
|
55 |
+
*/
|
56 |
+
public function __construct($key)
|
57 |
+
{
|
58 |
+
// Set up the key
|
59 |
+
parent::__construct(PhpCrypt::CIPHER_RIJNDAEL_128, $key);
|
60 |
+
|
61 |
+
// required block size in bits
|
62 |
+
$this->blockSize(self::BYTES_BLOCK);
|
63 |
+
|
64 |
+
// expand the key
|
65 |
+
$this->expandKey();
|
66 |
+
}
|
67 |
+
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Constructor, used only by classes that extend this class
|
71 |
+
*
|
72 |
+
* @param string $cipher_name The pre-defined cipher name of the child class
|
73 |
+
* @param string $key The key used for encryption/decryption
|
74 |
+
* @param integer $req_key_len The required key length, in bits
|
75 |
+
* @return void
|
76 |
+
*/
|
77 |
+
protected function __construct1($cipher_name, $key, $req_key_len)
|
78 |
+
{
|
79 |
+
parent::__construct($cipher_name, $key, $req_key_len);
|
80 |
+
|
81 |
+
// required block size in bits
|
82 |
+
$this->blockSize(self::BYTES_BLOCK);
|
83 |
+
|
84 |
+
// expand the key
|
85 |
+
$this->expandKey();
|
86 |
+
}
|
87 |
+
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Destructor
|
91 |
+
*
|
92 |
+
* @return void
|
93 |
+
*/
|
94 |
+
public function __destruct()
|
95 |
+
{
|
96 |
+
parent::__destruct();
|
97 |
+
}
|
98 |
+
}
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael192.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Rijndael256.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/SimpleXOR.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Skipjack.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/ciphers/Vigenere.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/licenses/ECCN_5D002.txt
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/licenses/GPL.txt
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/CBC.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/CFB.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/CTR.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/ECB.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/NCFB.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/NOFB.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/OFB.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/PCBC.php
RENAMED
File without changes
|
2.0/includes/vendor/MchCrypt/PhpCrypt/modes/Raw.php
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Author: Ryan Gilfether
|
4 |
+
* URL: http://www.gilfether.com/phpCrypt
|
5 |
+
* Date: March 5, 2013
|
6 |
+
* Copyright (C) 2013 Ryan Gilfether
|
7 |
+
*
|
8 |
+
* This file is part of phpCrypt
|
9 |
+
*
|
10 |
+
* phpCrypt is free software; you can redistribute it and/or modify
|
11 |
+
* it under the terms of the GNU General Public License as published by
|
12 |
+
* the Free Software Foundation; either version 3 of the License, or
|
13 |
+
* (at your option) any later version
|
14 |
+
*
|
15 |
+
* This program is distributed in the hope that it will be useful,
|
16 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
+
* GNU General Public License for more details.
|
19 |
+
*
|
20 |
+
* You should have received a copy of the GNU General Public License
|
21 |
+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
22 |
+
*/
|
23 |
+
|
24 |
+
|
25 |
+
require_once(dirname(__FILE__)."/../Cipher.php");
|
26 |
+
require_once(dirname(__FILE__)."/../Mode.php");
|
27 |
+
require_once(dirname(__FILE__)."/../phpCrypt.php");
|
28 |
+
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Allows Raw encryption of block or stream cipher, this does not use any
|
32 |
+
* mode, rather is simply calls the Encryption/Decryption method of the
|
33 |
+
* Cipher selected. The data encrypted/decrypted must be the same length
|
34 |
+
* as required by the Cipher. No padding is used.
|
35 |
+
*
|
36 |
+
* @author Ryan Gilfether
|
37 |
+
* @link http://www.gilfether.com/phpcrypt
|
38 |
+
* @copyright 2013 Ryan Gilfether
|
39 |
+
*/
|
40 |
+
class PhpCrypt_Mode_Raw extends PhpCrypt_Mode
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* Constructor
|
44 |
+
* Sets the cipher object that will be used for encryption
|
45 |
+
*
|
46 |
+
* @param object $cipher one of the phpCrypt encryption cipher objects
|
47 |
+
* @return void
|
48 |
+
*/
|
49 |
+
public function __construct($cipher)
|
50 |
+
{
|
51 |
+
parent::__construct(PhpCrypt::MODE_RAW, $cipher);
|
52 |
+
}
|
53 |
+
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Constructor used by classes that extend this class
|
57 |
+
* Used by Mode_Stream, which extends this class
|
58 |
+
*
|
59 |
+
* @param object $cipher One of phpCrypts cipher objects
|
60 |
+
* @param integer $mode The mode constant identifier
|
61 |
+
* @return void
|
62 |
+
*/
|
63 |
+
protected function __construct1($mode, $cipher)
|
64 |
+
{
|
65 |
+
parent::__construct($mode, $cipher);
|
66 |
+
}
|
67 |
+
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Destructor
|
71 |
+
*/
|
72 |
+
public function __destruct()
|
73 |
+
{
|
74 |
+
parent::__destruct();
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Encrypts an the string using the Cipher with no Mode
|
80 |
+
* NOTE: The data in $text must be the exact length required by the Cipher
|
81 |
+
*
|
82 |
+
* @param string $str the string to be encrypted
|
83 |
+
* @return boolean Always returns false
|
84 |
+
*/
|
85 |
+
public function encrypt(&$text)
|
86 |
+
{
|
87 |
+
$this->cipher->encrypt($text);
|
88 |
+
return true;
|
89 |
+
}
|
90 |
+
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Decrypts one block of cipher text, not using any mode.
|
94 |
+
* NOTE: The data in $text must be the exact length required by the Cipher
|
95 |
+
*
|
96 |
+
* @param string $str the string to be decrypted
|
97 |
+
* @return boolean Always returns false
|
98 |
+
*/
|
99 |
+
public function decrypt(&$text)
|
100 |
+
{
|
101 |
+
$this->cipher->decrypt($text);
|
102 |
+
return true;
|
103 |
+
}
|
104 |
+
|
105 |
+
|
106 |
+
/**
|
107 |
+
* This mode does not require an IV
|
108 |
+
*
|
109 |
+
* @return boolean false
|
110 |
+
*/
|
111 |
+
public function requiresIV()
|
112 |
+
{
|
113 |
+
return false;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
?>
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/modes/Stream.php
RENAMED
File without changes
|
{includes → 2.0/includes}/vendor/MchCrypt/PhpCrypt/phpCrypt.php
RENAMED
File without changes
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/AES.php
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of AES.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available/possible, and an internal implementation, otherwise.
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* If {@link Crypt_AES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
|
11 |
+
* {@link Crypt_AES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
|
12 |
+
* it'll be null-padded to 192-bits and 192 bits will be the key length until {@link Crypt_AES::setKey() setKey()}
|
13 |
+
* is called, again, at which point, it'll be recalculated.
|
14 |
+
*
|
15 |
+
* Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't
|
16 |
+
* make a whole lot of sense. {@link Crypt_AES::setBlockLength() setBlockLength()}, for instance. Calling that function,
|
17 |
+
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
|
18 |
+
*
|
19 |
+
* Here's a short example of how to use this library:
|
20 |
+
* <code>
|
21 |
+
* <?php
|
22 |
+
* include 'Crypt/AES.php';
|
23 |
+
*
|
24 |
+
* $aes = new Crypt_AES();
|
25 |
+
*
|
26 |
+
* $aes->setKey('abcdefghijklmnop');
|
27 |
+
*
|
28 |
+
* $size = 10 * 1024;
|
29 |
+
* $plaintext = '';
|
30 |
+
* for ($i = 0; $i < $size; $i++) {
|
31 |
+
* $plaintext.= 'a';
|
32 |
+
* }
|
33 |
+
*
|
34 |
+
* echo $aes->decrypt($aes->encrypt($plaintext));
|
35 |
+
* ?>
|
36 |
+
* </code>
|
37 |
+
*
|
38 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
39 |
+
* of this software and associated documentation files (the "Software"), to deal
|
40 |
+
* in the Software without restriction, including without limitation the rights
|
41 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
42 |
+
* copies of the Software, and to permit persons to whom the Software is
|
43 |
+
* furnished to do so, subject to the following conditions:
|
44 |
+
*
|
45 |
+
* The above copyright notice and this permission notice shall be included in
|
46 |
+
* all copies or substantial portions of the Software.
|
47 |
+
*
|
48 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
49 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
50 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
51 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
52 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
53 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
54 |
+
* THE SOFTWARE.
|
55 |
+
*
|
56 |
+
* @category Crypt
|
57 |
+
* @package Crypt_AES
|
58 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
59 |
+
* @copyright 2008 Jim Wigginton
|
60 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
61 |
+
* @link http://phpseclib.sourceforge.net
|
62 |
+
*/
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Include Crypt_Rijndael
|
66 |
+
*/
|
67 |
+
if (!class_exists('Crypt_Rijndael')) {
|
68 |
+
include_once 'Rijndael.php';
|
69 |
+
}
|
70 |
+
|
71 |
+
/**#@+
|
72 |
+
* @access public
|
73 |
+
* @see Crypt_AES::encrypt()
|
74 |
+
* @see Crypt_AES::decrypt()
|
75 |
+
*/
|
76 |
+
/**
|
77 |
+
* Encrypt / decrypt using the Counter mode.
|
78 |
+
*
|
79 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
80 |
+
*
|
81 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
82 |
+
*/
|
83 |
+
define('CRYPT_AES_MODE_CTR', CRYPT_MODE_CTR);
|
84 |
+
/**
|
85 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
86 |
+
*
|
87 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
88 |
+
*/
|
89 |
+
define('CRYPT_AES_MODE_ECB', CRYPT_MODE_ECB);
|
90 |
+
/**
|
91 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
92 |
+
*
|
93 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
94 |
+
*/
|
95 |
+
define('CRYPT_AES_MODE_CBC', CRYPT_MODE_CBC);
|
96 |
+
/**
|
97 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
98 |
+
*
|
99 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
100 |
+
*/
|
101 |
+
define('CRYPT_AES_MODE_CFB', CRYPT_MODE_CFB);
|
102 |
+
/**
|
103 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
104 |
+
*
|
105 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
106 |
+
*/
|
107 |
+
define('CRYPT_AES_MODE_OFB', CRYPT_MODE_OFB);
|
108 |
+
/**#@-*/
|
109 |
+
|
110 |
+
/**#@+
|
111 |
+
* @access private
|
112 |
+
* @see Crypt_Base::Crypt_Base()
|
113 |
+
*/
|
114 |
+
/**
|
115 |
+
* Toggles the internal implementation
|
116 |
+
*/
|
117 |
+
define('CRYPT_AES_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
118 |
+
/**
|
119 |
+
* Toggles the mcrypt implementation
|
120 |
+
*/
|
121 |
+
define('CRYPT_AES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
122 |
+
/**#@-*/
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Pure-PHP implementation of AES.
|
126 |
+
*
|
127 |
+
* @package Crypt_AES
|
128 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
129 |
+
* @access public
|
130 |
+
*/
|
131 |
+
class Crypt_AES extends Crypt_Rijndael
|
132 |
+
{
|
133 |
+
/**
|
134 |
+
* The namespace used by the cipher for its constants.
|
135 |
+
*
|
136 |
+
* @see Crypt_Base::const_namespace
|
137 |
+
* @var String
|
138 |
+
* @access private
|
139 |
+
*/
|
140 |
+
var $const_namespace = 'AES';
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Dummy function
|
144 |
+
*
|
145 |
+
* Since Crypt_AES extends Crypt_Rijndael, this function is, technically, available, but it doesn't do anything.
|
146 |
+
*
|
147 |
+
* @see Crypt_Rijndael::setBlockLength()
|
148 |
+
* @access public
|
149 |
+
* @param Integer $length
|
150 |
+
*/
|
151 |
+
function setBlockLength($length)
|
152 |
+
{
|
153 |
+
return;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Sets the key length
|
158 |
+
*
|
159 |
+
* Valid key lengths are 128, 192, and 256. If the length is less than 128, it will be rounded up to
|
160 |
+
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
|
161 |
+
*
|
162 |
+
* @see Crypt_Rijndael:setKeyLength()
|
163 |
+
* @access public
|
164 |
+
* @param Integer $length
|
165 |
+
*/
|
166 |
+
function setKeyLength($length)
|
167 |
+
{
|
168 |
+
switch ($length) {
|
169 |
+
case 160:
|
170 |
+
$length = 192;
|
171 |
+
break;
|
172 |
+
case 224:
|
173 |
+
$length = 256;
|
174 |
+
}
|
175 |
+
parent::setKeyLength($length);
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Sets the key.
|
180 |
+
*
|
181 |
+
* Rijndael supports five different key lengths, AES only supports three.
|
182 |
+
*
|
183 |
+
* @see Crypt_Rijndael:setKey()
|
184 |
+
* @see setKeyLength()
|
185 |
+
* @access public
|
186 |
+
* @param String $key
|
187 |
+
*/
|
188 |
+
function setKey($key)
|
189 |
+
{
|
190 |
+
parent::setKey($key);
|
191 |
+
|
192 |
+
if (!$this->explicit_key_length) {
|
193 |
+
$length = strlen($key);
|
194 |
+
switch (true) {
|
195 |
+
case $length <= 16:
|
196 |
+
$this->key_size = 16;
|
197 |
+
break;
|
198 |
+
case $length <= 24:
|
199 |
+
$this->key_size = 24;
|
200 |
+
break;
|
201 |
+
default:
|
202 |
+
$this->key_size = 32;
|
203 |
+
}
|
204 |
+
$this->_setupEngine();
|
205 |
+
}
|
206 |
+
}
|
207 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Base.php
ADDED
@@ -0,0 +1,2011 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Base Class for all Crypt_* cipher classes
|
5 |
+
*
|
6 |
+
* PHP versions 4 and 5
|
7 |
+
*
|
8 |
+
* Internally for phpseclib developers:
|
9 |
+
* If you plan to add a new cipher class, please note following rules:
|
10 |
+
*
|
11 |
+
* - The new Crypt_* cipher class should extend Crypt_Base
|
12 |
+
*
|
13 |
+
* - Following methods are then required to be overridden/overloaded:
|
14 |
+
*
|
15 |
+
* - _encryptBlock()
|
16 |
+
*
|
17 |
+
* - _decryptBlock()
|
18 |
+
*
|
19 |
+
* - _setupKey()
|
20 |
+
*
|
21 |
+
* - All other methods are optional to be overridden/overloaded
|
22 |
+
*
|
23 |
+
* - Look at the source code of the current ciphers how they extend Crypt_Base
|
24 |
+
* and take one of them as a start up for the new cipher class.
|
25 |
+
*
|
26 |
+
* - Please read all the other comments/notes/hints here also for each class var/method
|
27 |
+
*
|
28 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
29 |
+
* of this software and associated documentation files (the "Software"), to deal
|
30 |
+
* in the Software without restriction, including without limitation the rights
|
31 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
32 |
+
* copies of the Software, and to permit persons to whom the Software is
|
33 |
+
* furnished to do so, subject to the following conditions:
|
34 |
+
*
|
35 |
+
* The above copyright notice and this permission notice shall be included in
|
36 |
+
* all copies or substantial portions of the Software.
|
37 |
+
*
|
38 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
39 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
40 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
41 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
42 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
43 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
44 |
+
* THE SOFTWARE.
|
45 |
+
*
|
46 |
+
* @category Crypt
|
47 |
+
* @package Crypt_Base
|
48 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
49 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
50 |
+
* @copyright 2007 Jim Wigginton
|
51 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
52 |
+
* @link http://phpseclib.sourceforge.net
|
53 |
+
*/
|
54 |
+
|
55 |
+
/**#@+
|
56 |
+
* @access public
|
57 |
+
* @see Crypt_Base::encrypt()
|
58 |
+
* @see Crypt_Base::decrypt()
|
59 |
+
*/
|
60 |
+
/**
|
61 |
+
* Encrypt / decrypt using the Counter mode.
|
62 |
+
*
|
63 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
64 |
+
*
|
65 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
66 |
+
*/
|
67 |
+
define('CRYPT_MODE_CTR', -1);
|
68 |
+
/**
|
69 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
70 |
+
*
|
71 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
72 |
+
*/
|
73 |
+
define('CRYPT_MODE_ECB', 1);
|
74 |
+
/**
|
75 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
76 |
+
*
|
77 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
78 |
+
*/
|
79 |
+
define('CRYPT_MODE_CBC', 2);
|
80 |
+
/**
|
81 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
82 |
+
*
|
83 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
84 |
+
*/
|
85 |
+
define('CRYPT_MODE_CFB', 3);
|
86 |
+
/**
|
87 |
+
* Encrypt / decrypt using the Output Feedback mode.
|
88 |
+
*
|
89 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
90 |
+
*/
|
91 |
+
define('CRYPT_MODE_OFB', 4);
|
92 |
+
/**
|
93 |
+
* Encrypt / decrypt using streaming mode.
|
94 |
+
*
|
95 |
+
*/
|
96 |
+
define('CRYPT_MODE_STREAM', 5);
|
97 |
+
/**#@-*/
|
98 |
+
|
99 |
+
/**#@+
|
100 |
+
* @access private
|
101 |
+
* @see Crypt_Base::Crypt_Base()
|
102 |
+
*/
|
103 |
+
/**
|
104 |
+
* Base value for the internal implementation $engine switch
|
105 |
+
*/
|
106 |
+
define('CRYPT_MODE_INTERNAL', 1);
|
107 |
+
/**
|
108 |
+
* Base value for the mcrypt implementation $engine switch
|
109 |
+
*/
|
110 |
+
define('CRYPT_MODE_MCRYPT', 2);
|
111 |
+
/**#@-*/
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Base Class for all Crypt_* cipher classes
|
115 |
+
*
|
116 |
+
* @package Crypt_Base
|
117 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
118 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
119 |
+
* @access public
|
120 |
+
*/
|
121 |
+
class Crypt_Base
|
122 |
+
{
|
123 |
+
/**
|
124 |
+
* The Encryption Mode
|
125 |
+
*
|
126 |
+
* @see Crypt_Base::Crypt_Base()
|
127 |
+
* @var Integer
|
128 |
+
* @access private
|
129 |
+
*/
|
130 |
+
var $mode;
|
131 |
+
|
132 |
+
/**
|
133 |
+
* The Block Length of the block cipher
|
134 |
+
*
|
135 |
+
* @var Integer
|
136 |
+
* @access private
|
137 |
+
*/
|
138 |
+
var $block_size = 16;
|
139 |
+
|
140 |
+
/**
|
141 |
+
* The Key
|
142 |
+
*
|
143 |
+
* @see Crypt_Base::setKey()
|
144 |
+
* @var String
|
145 |
+
* @access private
|
146 |
+
*/
|
147 |
+
var $key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
148 |
+
|
149 |
+
/**
|
150 |
+
* The Initialization Vector
|
151 |
+
*
|
152 |
+
* @see Crypt_Base::setIV()
|
153 |
+
* @var String
|
154 |
+
* @access private
|
155 |
+
*/
|
156 |
+
var $iv;
|
157 |
+
|
158 |
+
/**
|
159 |
+
* A "sliding" Initialization Vector
|
160 |
+
*
|
161 |
+
* @see Crypt_Base::enableContinuousBuffer()
|
162 |
+
* @see Crypt_Base::_clearBuffers()
|
163 |
+
* @var String
|
164 |
+
* @access private
|
165 |
+
*/
|
166 |
+
var $encryptIV;
|
167 |
+
|
168 |
+
/**
|
169 |
+
* A "sliding" Initialization Vector
|
170 |
+
*
|
171 |
+
* @see Crypt_Base::enableContinuousBuffer()
|
172 |
+
* @see Crypt_Base::_clearBuffers()
|
173 |
+
* @var String
|
174 |
+
* @access private
|
175 |
+
*/
|
176 |
+
var $decryptIV;
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Continuous Buffer status
|
180 |
+
*
|
181 |
+
* @see Crypt_Base::enableContinuousBuffer()
|
182 |
+
* @var Boolean
|
183 |
+
* @access private
|
184 |
+
*/
|
185 |
+
var $continuousBuffer = false;
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Encryption buffer for CTR, OFB and CFB modes
|
189 |
+
*
|
190 |
+
* @see Crypt_Base::encrypt()
|
191 |
+
* @see Crypt_Base::_clearBuffers()
|
192 |
+
* @var Array
|
193 |
+
* @access private
|
194 |
+
*/
|
195 |
+
var $enbuffer;
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Decryption buffer for CTR, OFB and CFB modes
|
199 |
+
*
|
200 |
+
* @see Crypt_Base::decrypt()
|
201 |
+
* @see Crypt_Base::_clearBuffers()
|
202 |
+
* @var Array
|
203 |
+
* @access private
|
204 |
+
*/
|
205 |
+
var $debuffer;
|
206 |
+
|
207 |
+
/**
|
208 |
+
* mcrypt resource for encryption
|
209 |
+
*
|
210 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
211 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
212 |
+
*
|
213 |
+
* @see Crypt_Base::encrypt()
|
214 |
+
* @var Resource
|
215 |
+
* @access private
|
216 |
+
*/
|
217 |
+
var $enmcrypt;
|
218 |
+
|
219 |
+
/**
|
220 |
+
* mcrypt resource for decryption
|
221 |
+
*
|
222 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
223 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
224 |
+
*
|
225 |
+
* @see Crypt_Base::decrypt()
|
226 |
+
* @var Resource
|
227 |
+
* @access private
|
228 |
+
*/
|
229 |
+
var $demcrypt;
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Does the enmcrypt resource need to be (re)initialized?
|
233 |
+
*
|
234 |
+
* @see Crypt_Twofish::setKey()
|
235 |
+
* @see Crypt_Twofish::setIV()
|
236 |
+
* @var Boolean
|
237 |
+
* @access private
|
238 |
+
*/
|
239 |
+
var $enchanged = true;
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Does the demcrypt resource need to be (re)initialized?
|
243 |
+
*
|
244 |
+
* @see Crypt_Twofish::setKey()
|
245 |
+
* @see Crypt_Twofish::setIV()
|
246 |
+
* @var Boolean
|
247 |
+
* @access private
|
248 |
+
*/
|
249 |
+
var $dechanged = true;
|
250 |
+
|
251 |
+
/**
|
252 |
+
* mcrypt resource for CFB mode
|
253 |
+
*
|
254 |
+
* mcrypt's CFB mode, in (and only in) buffered context,
|
255 |
+
* is broken, so phpseclib implements the CFB mode by it self,
|
256 |
+
* even when the mcrypt php extension is available.
|
257 |
+
*
|
258 |
+
* In order to do the CFB-mode work (fast) phpseclib
|
259 |
+
* use a separate ECB-mode mcrypt resource.
|
260 |
+
*
|
261 |
+
* @link http://phpseclib.sourceforge.net/cfb-demo.phps
|
262 |
+
* @see Crypt_Base::encrypt()
|
263 |
+
* @see Crypt_Base::decrypt()
|
264 |
+
* @see Crypt_Base::_setupMcrypt()
|
265 |
+
* @var Resource
|
266 |
+
* @access private
|
267 |
+
*/
|
268 |
+
var $ecb;
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Optimizing value while CFB-encrypting
|
272 |
+
*
|
273 |
+
* Only relevant if $continuousBuffer enabled
|
274 |
+
* and $engine == CRYPT_MODE_MCRYPT
|
275 |
+
*
|
276 |
+
* It's faster to re-init $enmcrypt if
|
277 |
+
* $buffer bytes > $cfb_init_len than
|
278 |
+
* using the $ecb resource furthermore.
|
279 |
+
*
|
280 |
+
* This value depends of the chosen cipher
|
281 |
+
* and the time it would be needed for it's
|
282 |
+
* initialization [by mcrypt_generic_init()]
|
283 |
+
* which, typically, depends on the complexity
|
284 |
+
* on its internaly Key-expanding algorithm.
|
285 |
+
*
|
286 |
+
* @see Crypt_Base::encrypt()
|
287 |
+
* @var Integer
|
288 |
+
* @access private
|
289 |
+
*/
|
290 |
+
var $cfb_init_len = 600;
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Does internal cipher state need to be (re)initialized?
|
294 |
+
*
|
295 |
+
* @see setKey()
|
296 |
+
* @see setIV()
|
297 |
+
* @see disableContinuousBuffer()
|
298 |
+
* @var Boolean
|
299 |
+
* @access private
|
300 |
+
*/
|
301 |
+
var $changed = true;
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Padding status
|
305 |
+
*
|
306 |
+
* @see Crypt_Base::enablePadding()
|
307 |
+
* @var Boolean
|
308 |
+
* @access private
|
309 |
+
*/
|
310 |
+
var $padding = true;
|
311 |
+
|
312 |
+
/**
|
313 |
+
* Is the mode one that is paddable?
|
314 |
+
*
|
315 |
+
* @see Crypt_Base::Crypt_Base()
|
316 |
+
* @var Boolean
|
317 |
+
* @access private
|
318 |
+
*/
|
319 |
+
var $paddable = false;
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Holds which crypt engine internaly should be use,
|
323 |
+
* which will be determined automatically on __construct()
|
324 |
+
*
|
325 |
+
* Currently available $engines are:
|
326 |
+
* - CRYPT_MODE_MCRYPT (fast, php-extension: mcrypt, extension_loaded('mcrypt') required)
|
327 |
+
* - CRYPT_MODE_INTERNAL (slower, pure php-engine, no php-extension required)
|
328 |
+
*
|
329 |
+
* In the pipeline... maybe. But currently not available:
|
330 |
+
* - CRYPT_MODE_OPENSSL (very fast, php-extension: openssl, extension_loaded('openssl') required)
|
331 |
+
*
|
332 |
+
* If possible, CRYPT_MODE_MCRYPT will be used for each cipher.
|
333 |
+
* Otherwise CRYPT_MODE_INTERNAL
|
334 |
+
*
|
335 |
+
* @see Crypt_Base::encrypt()
|
336 |
+
* @see Crypt_Base::decrypt()
|
337 |
+
* @var Integer
|
338 |
+
* @access private
|
339 |
+
*/
|
340 |
+
var $engine;
|
341 |
+
|
342 |
+
/**
|
343 |
+
* The mcrypt specific name of the cipher
|
344 |
+
*
|
345 |
+
* Only used if $engine == CRYPT_MODE_MCRYPT
|
346 |
+
*
|
347 |
+
* @link http://www.php.net/mcrypt_module_open
|
348 |
+
* @link http://www.php.net/mcrypt_list_algorithms
|
349 |
+
* @see Crypt_Base::_setupMcrypt()
|
350 |
+
* @var String
|
351 |
+
* @access private
|
352 |
+
*/
|
353 |
+
var $cipher_name_mcrypt;
|
354 |
+
|
355 |
+
/**
|
356 |
+
* The default password key_size used by setPassword()
|
357 |
+
*
|
358 |
+
* @see Crypt_Base::setPassword()
|
359 |
+
* @var Integer
|
360 |
+
* @access private
|
361 |
+
*/
|
362 |
+
var $password_key_size = 32;
|
363 |
+
|
364 |
+
/**
|
365 |
+
* The default salt used by setPassword()
|
366 |
+
*
|
367 |
+
* @see Crypt_Base::setPassword()
|
368 |
+
* @var String
|
369 |
+
* @access private
|
370 |
+
*/
|
371 |
+
var $password_default_salt = 'phpseclib/salt';
|
372 |
+
|
373 |
+
/**
|
374 |
+
* The namespace used by the cipher for its constants.
|
375 |
+
*
|
376 |
+
* ie: AES.php is using CRYPT_AES_MODE_* for its constants
|
377 |
+
* so $const_namespace is AES
|
378 |
+
*
|
379 |
+
* DES.php is using CRYPT_DES_MODE_* for its constants
|
380 |
+
* so $const_namespace is DES... and so on
|
381 |
+
*
|
382 |
+
* All CRYPT_<$const_namespace>_MODE_* are aliases of
|
383 |
+
* the generic CRYPT_MODE_* constants, so both could be used
|
384 |
+
* for each cipher.
|
385 |
+
*
|
386 |
+
* Example:
|
387 |
+
* $aes = new Crypt_AES(CRYPT_AES_MODE_CFB); // $aes will operate in cfb mode
|
388 |
+
* $aes = new Crypt_AES(CRYPT_MODE_CFB); // identical
|
389 |
+
*
|
390 |
+
* @see Crypt_Base::Crypt_Base()
|
391 |
+
* @var String
|
392 |
+
* @access private
|
393 |
+
*/
|
394 |
+
var $const_namespace;
|
395 |
+
|
396 |
+
/**
|
397 |
+
* The name of the performance-optimized callback function
|
398 |
+
*
|
399 |
+
* Used by encrypt() / decrypt()
|
400 |
+
* only if $engine == CRYPT_MODE_INTERNAL
|
401 |
+
*
|
402 |
+
* @see Crypt_Base::encrypt()
|
403 |
+
* @see Crypt_Base::decrypt()
|
404 |
+
* @see Crypt_Base::_setupInlineCrypt()
|
405 |
+
* @see Crypt_Base::$use_inline_crypt
|
406 |
+
* @var Callback
|
407 |
+
* @access private
|
408 |
+
*/
|
409 |
+
var $inline_crypt;
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Holds whether performance-optimized $inline_crypt() can/should be used.
|
413 |
+
*
|
414 |
+
* @see Crypt_Base::encrypt()
|
415 |
+
* @see Crypt_Base::decrypt()
|
416 |
+
* @see Crypt_Base::inline_crypt
|
417 |
+
* @var mixed
|
418 |
+
* @access private
|
419 |
+
*/
|
420 |
+
var $use_inline_crypt;
|
421 |
+
|
422 |
+
/**
|
423 |
+
* Default Constructor.
|
424 |
+
*
|
425 |
+
* Determines whether or not the mcrypt extension should be used.
|
426 |
+
*
|
427 |
+
* $mode could be:
|
428 |
+
*
|
429 |
+
* - CRYPT_MODE_ECB
|
430 |
+
*
|
431 |
+
* - CRYPT_MODE_CBC
|
432 |
+
*
|
433 |
+
* - CRYPT_MODE_CTR
|
434 |
+
*
|
435 |
+
* - CRYPT_MODE_CFB
|
436 |
+
*
|
437 |
+
* - CRYPT_MODE_OFB
|
438 |
+
*
|
439 |
+
* (or the alias constants of the chosen cipher, for example for AES: CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC ...)
|
440 |
+
*
|
441 |
+
* If not explicitly set, CRYPT_MODE_CBC will be used.
|
442 |
+
*
|
443 |
+
* @param optional Integer $mode
|
444 |
+
* @access public
|
445 |
+
*/
|
446 |
+
function Crypt_Base($mode = CRYPT_MODE_CBC)
|
447 |
+
{
|
448 |
+
$const_crypt_mode = 'CRYPT_' . $this->const_namespace . '_MODE';
|
449 |
+
|
450 |
+
// Determining the availibility of mcrypt support for the cipher
|
451 |
+
if (!defined($const_crypt_mode)) {
|
452 |
+
switch (true) {
|
453 |
+
case extension_loaded('mcrypt') && in_array($this->cipher_name_mcrypt, mcrypt_list_algorithms()):
|
454 |
+
define($const_crypt_mode, CRYPT_MODE_MCRYPT);
|
455 |
+
break;
|
456 |
+
default:
|
457 |
+
define($const_crypt_mode, CRYPT_MODE_INTERNAL);
|
458 |
+
}
|
459 |
+
}
|
460 |
+
|
461 |
+
// Determining which internal $engine should be used.
|
462 |
+
// The fastes possible first.
|
463 |
+
switch (true) {
|
464 |
+
case empty($this->cipher_name_mcrypt): // The cipher module has no mcrypt-engine support at all so we force CRYPT_MODE_INTERNAL
|
465 |
+
$this->engine = CRYPT_MODE_INTERNAL;
|
466 |
+
break;
|
467 |
+
case constant($const_crypt_mode) == CRYPT_MODE_MCRYPT:
|
468 |
+
$this->engine = CRYPT_MODE_MCRYPT;
|
469 |
+
break;
|
470 |
+
default:
|
471 |
+
$this->engine = CRYPT_MODE_INTERNAL;
|
472 |
+
}
|
473 |
+
|
474 |
+
// $mode dependent settings
|
475 |
+
switch ($mode) {
|
476 |
+
case CRYPT_MODE_ECB:
|
477 |
+
$this->paddable = true;
|
478 |
+
$this->mode = $mode;
|
479 |
+
break;
|
480 |
+
case CRYPT_MODE_CTR:
|
481 |
+
case CRYPT_MODE_CFB:
|
482 |
+
case CRYPT_MODE_OFB:
|
483 |
+
case CRYPT_MODE_STREAM:
|
484 |
+
$this->mode = $mode;
|
485 |
+
break;
|
486 |
+
case CRYPT_MODE_CBC:
|
487 |
+
default:
|
488 |
+
$this->paddable = true;
|
489 |
+
$this->mode = CRYPT_MODE_CBC;
|
490 |
+
}
|
491 |
+
|
492 |
+
// Determining whether inline crypting can be used by the cipher
|
493 |
+
if ($this->use_inline_crypt !== false && function_exists('create_function')) {
|
494 |
+
$this->use_inline_crypt = true;
|
495 |
+
}
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* Sets the initialization vector. (optional)
|
500 |
+
*
|
501 |
+
* SetIV is not required when CRYPT_MODE_ECB (or ie for AES: CRYPT_AES_MODE_ECB) is being used. If not explicitly set, it'll be assumed
|
502 |
+
* to be all zero's.
|
503 |
+
*
|
504 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
505 |
+
*
|
506 |
+
* @access public
|
507 |
+
* @param String $iv
|
508 |
+
*/
|
509 |
+
function setIV($iv)
|
510 |
+
{
|
511 |
+
if ($this->mode == CRYPT_MODE_ECB) {
|
512 |
+
return;
|
513 |
+
}
|
514 |
+
|
515 |
+
$this->iv = $iv;
|
516 |
+
$this->changed = true;
|
517 |
+
}
|
518 |
+
|
519 |
+
/**
|
520 |
+
* Sets the key.
|
521 |
+
*
|
522 |
+
* The min/max length(s) of the key depends on the cipher which is used.
|
523 |
+
* If the key not fits the length(s) of the cipher it will paded with null bytes
|
524 |
+
* up to the closest valid key length. If the key is more than max length,
|
525 |
+
* we trim the excess bits.
|
526 |
+
*
|
527 |
+
* If the key is not explicitly set, it'll be assumed to be all null bytes.
|
528 |
+
*
|
529 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
530 |
+
*
|
531 |
+
* @access public
|
532 |
+
* @param String $key
|
533 |
+
*/
|
534 |
+
function setKey($key)
|
535 |
+
{
|
536 |
+
$this->key = $key;
|
537 |
+
$this->changed = true;
|
538 |
+
}
|
539 |
+
|
540 |
+
/**
|
541 |
+
* Sets the password.
|
542 |
+
*
|
543 |
+
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
|
544 |
+
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2} or pbkdf1:
|
545 |
+
* $hash, $salt, $count, $dkLen
|
546 |
+
*
|
547 |
+
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
|
548 |
+
*
|
549 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
550 |
+
*
|
551 |
+
* @see Crypt/Hash.php
|
552 |
+
* @param String $password
|
553 |
+
* @param optional String $method
|
554 |
+
* @return Boolean
|
555 |
+
* @access public
|
556 |
+
*/
|
557 |
+
function setPassword($password, $method = 'pbkdf2')
|
558 |
+
{
|
559 |
+
$key = '';
|
560 |
+
|
561 |
+
switch ($method) {
|
562 |
+
default: // 'pbkdf2' or 'pbkdf1'
|
563 |
+
$func_args = func_get_args();
|
564 |
+
|
565 |
+
// Hash function
|
566 |
+
$hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
|
567 |
+
|
568 |
+
// WPA and WPA2 use the SSID as the salt
|
569 |
+
$salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
|
570 |
+
|
571 |
+
// RFC2898#section-4.2 uses 1,000 iterations by default
|
572 |
+
// WPA and WPA2 use 4,096.
|
573 |
+
$count = isset($func_args[4]) ? $func_args[4] : 1000;
|
574 |
+
|
575 |
+
// Keylength
|
576 |
+
if (isset($func_args[5])) {
|
577 |
+
$dkLen = $func_args[5];
|
578 |
+
} else {
|
579 |
+
$dkLen = $method == 'pbkdf1' ? 2 * $this->password_key_size : $this->password_key_size;
|
580 |
+
}
|
581 |
+
|
582 |
+
switch (true) {
|
583 |
+
case $method == 'pbkdf1':
|
584 |
+
if (!class_exists('Crypt_Hash')) {
|
585 |
+
include_once 'Crypt/Hash.php';
|
586 |
+
}
|
587 |
+
$hashObj = new Crypt_Hash();
|
588 |
+
$hashObj->setHash($hash);
|
589 |
+
if ($dkLen > $hashObj->getLength()) {
|
590 |
+
user_error('Derived key too long');
|
591 |
+
return false;
|
592 |
+
}
|
593 |
+
$t = $password . $salt;
|
594 |
+
for ($i = 0; $i < $count; ++$i) {
|
595 |
+
$t = $hashObj->hash($t);
|
596 |
+
}
|
597 |
+
$key = substr($t, 0, $dkLen);
|
598 |
+
|
599 |
+
$this->setKey(substr($key, 0, $dkLen >> 1));
|
600 |
+
$this->setIV(substr($key, $dkLen >> 1));
|
601 |
+
|
602 |
+
return true;
|
603 |
+
// Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
|
604 |
+
case !function_exists('hash_pbkdf2'):
|
605 |
+
case !function_exists('hash_algos'):
|
606 |
+
case !in_array($hash, hash_algos()):
|
607 |
+
if (!class_exists('Crypt_Hash')) {
|
608 |
+
include_once 'Crypt/Hash.php';
|
609 |
+
}
|
610 |
+
$i = 1;
|
611 |
+
while (strlen($key) < $dkLen) {
|
612 |
+
$hmac = new Crypt_Hash();
|
613 |
+
$hmac->setHash($hash);
|
614 |
+
$hmac->setKey($password);
|
615 |
+
$f = $u = $hmac->hash($salt . pack('N', $i++));
|
616 |
+
for ($j = 2; $j <= $count; ++$j) {
|
617 |
+
$u = $hmac->hash($u);
|
618 |
+
$f^= $u;
|
619 |
+
}
|
620 |
+
$key.= $f;
|
621 |
+
}
|
622 |
+
$key = substr($key, 0, $dkLen);
|
623 |
+
break;
|
624 |
+
default:
|
625 |
+
$key = hash_pbkdf2($hash, $password, $salt, $count, $dkLen, true);
|
626 |
+
}
|
627 |
+
}
|
628 |
+
|
629 |
+
$this->setKey($key);
|
630 |
+
|
631 |
+
return true;
|
632 |
+
}
|
633 |
+
|
634 |
+
/**
|
635 |
+
* Encrypts a message.
|
636 |
+
*
|
637 |
+
* $plaintext will be padded with additional bytes such that it's length is a multiple of the block size. Other cipher
|
638 |
+
* implementations may or may not pad in the same manner. Other common approaches to padding and the reasons why it's
|
639 |
+
* necessary are discussed in the following
|
640 |
+
* URL:
|
641 |
+
*
|
642 |
+
* {@link http://www.di-mgt.com.au/cryptopad.html http://www.di-mgt.com.au/cryptopad.html}
|
643 |
+
*
|
644 |
+
* An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does.
|
645 |
+
* strlen($plaintext) will still need to be a multiple of the block size, however, arbitrary values can be added to make it that
|
646 |
+
* length.
|
647 |
+
*
|
648 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
649 |
+
*
|
650 |
+
* @see Crypt_Base::decrypt()
|
651 |
+
* @access public
|
652 |
+
* @param String $plaintext
|
653 |
+
* @return String $cipertext
|
654 |
+
*/
|
655 |
+
function encrypt($plaintext)
|
656 |
+
{
|
657 |
+
if ($this->engine == CRYPT_MODE_MCRYPT) {
|
658 |
+
if ($this->changed) {
|
659 |
+
$this->_setupMcrypt();
|
660 |
+
$this->changed = false;
|
661 |
+
}
|
662 |
+
if ($this->enchanged) {
|
663 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
|
664 |
+
$this->enchanged = false;
|
665 |
+
}
|
666 |
+
|
667 |
+
// re: {@link http://phpseclib.sourceforge.net/cfb-demo.phps}
|
668 |
+
// using mcrypt's default handing of CFB the above would output two different things. using phpseclib's
|
669 |
+
// rewritten CFB implementation the above outputs the same thing twice.
|
670 |
+
if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) {
|
671 |
+
$block_size = $this->block_size;
|
672 |
+
$iv = &$this->encryptIV;
|
673 |
+
$pos = &$this->enbuffer['pos'];
|
674 |
+
$len = strlen($plaintext);
|
675 |
+
$ciphertext = '';
|
676 |
+
$i = 0;
|
677 |
+
if ($pos) {
|
678 |
+
$orig_pos = $pos;
|
679 |
+
$max = $block_size - $pos;
|
680 |
+
if ($len >= $max) {
|
681 |
+
$i = $max;
|
682 |
+
$len-= $max;
|
683 |
+
$pos = 0;
|
684 |
+
} else {
|
685 |
+
$i = $len;
|
686 |
+
$pos+= $len;
|
687 |
+
$len = 0;
|
688 |
+
}
|
689 |
+
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
690 |
+
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
691 |
+
$this->enbuffer['enmcrypt_init'] = true;
|
692 |
+
}
|
693 |
+
if ($len >= $block_size) {
|
694 |
+
if ($this->enbuffer['enmcrypt_init'] === false || $len > $this->cfb_init_len) {
|
695 |
+
if ($this->enbuffer['enmcrypt_init'] === true) {
|
696 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
|
697 |
+
$this->enbuffer['enmcrypt_init'] = false;
|
698 |
+
}
|
699 |
+
$ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % $block_size));
|
700 |
+
$iv = substr($ciphertext, -$block_size);
|
701 |
+
$len%= $block_size;
|
702 |
+
} else {
|
703 |
+
while ($len >= $block_size) {
|
704 |
+
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, $block_size);
|
705 |
+
$ciphertext.= $iv;
|
706 |
+
$len-= $block_size;
|
707 |
+
$i+= $block_size;
|
708 |
+
}
|
709 |
+
}
|
710 |
+
}
|
711 |
+
|
712 |
+
if ($len) {
|
713 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
714 |
+
$block = $iv ^ substr($plaintext, -$len);
|
715 |
+
$iv = substr_replace($iv, $block, 0, $len);
|
716 |
+
$ciphertext.= $block;
|
717 |
+
$pos = $len;
|
718 |
+
}
|
719 |
+
|
720 |
+
return $ciphertext;
|
721 |
+
}
|
722 |
+
|
723 |
+
if ($this->paddable) {
|
724 |
+
$plaintext = $this->_pad($plaintext);
|
725 |
+
}
|
726 |
+
|
727 |
+
$ciphertext = mcrypt_generic($this->enmcrypt, $plaintext);
|
728 |
+
|
729 |
+
if (!$this->continuousBuffer) {
|
730 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
|
731 |
+
}
|
732 |
+
|
733 |
+
return $ciphertext;
|
734 |
+
}
|
735 |
+
|
736 |
+
if ($this->changed) {
|
737 |
+
$this->_setup();
|
738 |
+
$this->changed = false;
|
739 |
+
}
|
740 |
+
if ($this->use_inline_crypt) {
|
741 |
+
$inline = $this->inline_crypt;
|
742 |
+
return $inline('encrypt', $this, $plaintext);
|
743 |
+
}
|
744 |
+
if ($this->paddable) {
|
745 |
+
$plaintext = $this->_pad($plaintext);
|
746 |
+
}
|
747 |
+
|
748 |
+
$buffer = &$this->enbuffer;
|
749 |
+
$block_size = $this->block_size;
|
750 |
+
$ciphertext = '';
|
751 |
+
switch ($this->mode) {
|
752 |
+
case CRYPT_MODE_ECB:
|
753 |
+
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
754 |
+
$ciphertext.= $this->_encryptBlock(substr($plaintext, $i, $block_size));
|
755 |
+
}
|
756 |
+
break;
|
757 |
+
case CRYPT_MODE_CBC:
|
758 |
+
$xor = $this->encryptIV;
|
759 |
+
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
760 |
+
$block = substr($plaintext, $i, $block_size);
|
761 |
+
$block = $this->_encryptBlock($block ^ $xor);
|
762 |
+
$xor = $block;
|
763 |
+
$ciphertext.= $block;
|
764 |
+
}
|
765 |
+
if ($this->continuousBuffer) {
|
766 |
+
$this->encryptIV = $xor;
|
767 |
+
}
|
768 |
+
break;
|
769 |
+
case CRYPT_MODE_CTR:
|
770 |
+
$xor = $this->encryptIV;
|
771 |
+
if (strlen($buffer['encrypted'])) {
|
772 |
+
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
773 |
+
$block = substr($plaintext, $i, $block_size);
|
774 |
+
if (strlen($block) > strlen($buffer['encrypted'])) {
|
775 |
+
$buffer['encrypted'].= $this->_encryptBlock($this->_generateXor($xor, $block_size));
|
776 |
+
}
|
777 |
+
$key = $this->_stringShift($buffer['encrypted'], $block_size);
|
778 |
+
$ciphertext.= $block ^ $key;
|
779 |
+
}
|
780 |
+
} else {
|
781 |
+
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
782 |
+
$block = substr($plaintext, $i, $block_size);
|
783 |
+
$key = $this->_encryptBlock($this->_generateXor($xor, $block_size));
|
784 |
+
$ciphertext.= $block ^ $key;
|
785 |
+
}
|
786 |
+
}
|
787 |
+
if ($this->continuousBuffer) {
|
788 |
+
$this->encryptIV = $xor;
|
789 |
+
if ($start = strlen($plaintext) % $block_size) {
|
790 |
+
$buffer['encrypted'] = substr($key, $start) . $buffer['encrypted'];
|
791 |
+
}
|
792 |
+
}
|
793 |
+
break;
|
794 |
+
case CRYPT_MODE_CFB:
|
795 |
+
// cfb loosely routines inspired by openssl's:
|
796 |
+
// {@link http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1}
|
797 |
+
if ($this->continuousBuffer) {
|
798 |
+
$iv = &$this->encryptIV;
|
799 |
+
$pos = &$buffer['pos'];
|
800 |
+
} else {
|
801 |
+
$iv = $this->encryptIV;
|
802 |
+
$pos = 0;
|
803 |
+
}
|
804 |
+
$len = strlen($plaintext);
|
805 |
+
$i = 0;
|
806 |
+
if ($pos) {
|
807 |
+
$orig_pos = $pos;
|
808 |
+
$max = $block_size - $pos;
|
809 |
+
if ($len >= $max) {
|
810 |
+
$i = $max;
|
811 |
+
$len-= $max;
|
812 |
+
$pos = 0;
|
813 |
+
} else {
|
814 |
+
$i = $len;
|
815 |
+
$pos+= $len;
|
816 |
+
$len = 0;
|
817 |
+
}
|
818 |
+
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
819 |
+
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
820 |
+
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
821 |
+
}
|
822 |
+
while ($len >= $block_size) {
|
823 |
+
$iv = $this->_encryptBlock($iv) ^ substr($plaintext, $i, $block_size);
|
824 |
+
$ciphertext.= $iv;
|
825 |
+
$len-= $block_size;
|
826 |
+
$i+= $block_size;
|
827 |
+
}
|
828 |
+
if ($len) {
|
829 |
+
$iv = $this->_encryptBlock($iv);
|
830 |
+
$block = $iv ^ substr($plaintext, $i);
|
831 |
+
$iv = substr_replace($iv, $block, 0, $len);
|
832 |
+
$ciphertext.= $block;
|
833 |
+
$pos = $len;
|
834 |
+
}
|
835 |
+
break;
|
836 |
+
case CRYPT_MODE_OFB:
|
837 |
+
$xor = $this->encryptIV;
|
838 |
+
if (strlen($buffer['xor'])) {
|
839 |
+
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
840 |
+
$block = substr($plaintext, $i, $block_size);
|
841 |
+
if (strlen($block) > strlen($buffer['xor'])) {
|
842 |
+
$xor = $this->_encryptBlock($xor);
|
843 |
+
$buffer['xor'].= $xor;
|
844 |
+
}
|
845 |
+
$key = $this->_stringShift($buffer['xor'], $block_size);
|
846 |
+
$ciphertext.= $block ^ $key;
|
847 |
+
}
|
848 |
+
} else {
|
849 |
+
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
850 |
+
$xor = $this->_encryptBlock($xor);
|
851 |
+
$ciphertext.= substr($plaintext, $i, $block_size) ^ $xor;
|
852 |
+
}
|
853 |
+
$key = $xor;
|
854 |
+
}
|
855 |
+
if ($this->continuousBuffer) {
|
856 |
+
$this->encryptIV = $xor;
|
857 |
+
if ($start = strlen($plaintext) % $block_size) {
|
858 |
+
$buffer['xor'] = substr($key, $start) . $buffer['xor'];
|
859 |
+
}
|
860 |
+
}
|
861 |
+
break;
|
862 |
+
case CRYPT_MODE_STREAM:
|
863 |
+
$ciphertext = $this->_encryptBlock($plaintext);
|
864 |
+
break;
|
865 |
+
}
|
866 |
+
|
867 |
+
return $ciphertext;
|
868 |
+
}
|
869 |
+
|
870 |
+
/**
|
871 |
+
* Decrypts a message.
|
872 |
+
*
|
873 |
+
* If strlen($ciphertext) is not a multiple of the block size, null bytes will be added to the end of the string until
|
874 |
+
* it is.
|
875 |
+
*
|
876 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
877 |
+
*
|
878 |
+
* @see Crypt_Base::encrypt()
|
879 |
+
* @access public
|
880 |
+
* @param String $ciphertext
|
881 |
+
* @return String $plaintext
|
882 |
+
*/
|
883 |
+
function decrypt($ciphertext)
|
884 |
+
{
|
885 |
+
if ($this->engine == CRYPT_MODE_MCRYPT) {
|
886 |
+
$block_size = $this->block_size;
|
887 |
+
if ($this->changed) {
|
888 |
+
$this->_setupMcrypt();
|
889 |
+
$this->changed = false;
|
890 |
+
}
|
891 |
+
if ($this->dechanged) {
|
892 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
|
893 |
+
$this->dechanged = false;
|
894 |
+
}
|
895 |
+
|
896 |
+
if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) {
|
897 |
+
$iv = &$this->decryptIV;
|
898 |
+
$pos = &$this->debuffer['pos'];
|
899 |
+
$len = strlen($ciphertext);
|
900 |
+
$plaintext = '';
|
901 |
+
$i = 0;
|
902 |
+
if ($pos) {
|
903 |
+
$orig_pos = $pos;
|
904 |
+
$max = $block_size - $pos;
|
905 |
+
if ($len >= $max) {
|
906 |
+
$i = $max;
|
907 |
+
$len-= $max;
|
908 |
+
$pos = 0;
|
909 |
+
} else {
|
910 |
+
$i = $len;
|
911 |
+
$pos+= $len;
|
912 |
+
$len = 0;
|
913 |
+
}
|
914 |
+
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
915 |
+
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
916 |
+
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
917 |
+
}
|
918 |
+
if ($len >= $block_size) {
|
919 |
+
$cb = substr($ciphertext, $i, $len - $len % $block_size);
|
920 |
+
$plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
921 |
+
$iv = substr($cb, -$block_size);
|
922 |
+
$len%= $block_size;
|
923 |
+
}
|
924 |
+
if ($len) {
|
925 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
926 |
+
$plaintext.= $iv ^ substr($ciphertext, -$len);
|
927 |
+
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
928 |
+
$pos = $len;
|
929 |
+
}
|
930 |
+
|
931 |
+
return $plaintext;
|
932 |
+
}
|
933 |
+
|
934 |
+
if ($this->paddable) {
|
935 |
+
// we pad with chr(0) since that's what mcrypt_generic does. to quote from {@link http://www.php.net/function.mcrypt-generic}:
|
936 |
+
// "The data is padded with "\0" to make sure the length of the data is n * blocksize."
|
937 |
+
$ciphertext = str_pad($ciphertext, strlen($ciphertext) + ($block_size - strlen($ciphertext) % $block_size) % $block_size, chr(0));
|
938 |
+
}
|
939 |
+
|
940 |
+
$plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);
|
941 |
+
|
942 |
+
if (!$this->continuousBuffer) {
|
943 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
|
944 |
+
}
|
945 |
+
|
946 |
+
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
947 |
+
}
|
948 |
+
|
949 |
+
if ($this->changed) {
|
950 |
+
$this->_setup();
|
951 |
+
$this->changed = false;
|
952 |
+
}
|
953 |
+
if ($this->use_inline_crypt) {
|
954 |
+
$inline = $this->inline_crypt;
|
955 |
+
return $inline('decrypt', $this, $ciphertext);
|
956 |
+
}
|
957 |
+
|
958 |
+
$block_size = $this->block_size;
|
959 |
+
if ($this->paddable) {
|
960 |
+
// we pad with chr(0) since that's what mcrypt_generic does [...]
|
961 |
+
$ciphertext = str_pad($ciphertext, strlen($ciphertext) + ($block_size - strlen($ciphertext) % $block_size) % $block_size, chr(0));
|
962 |
+
}
|
963 |
+
|
964 |
+
$buffer = &$this->debuffer;
|
965 |
+
$plaintext = '';
|
966 |
+
switch ($this->mode) {
|
967 |
+
case CRYPT_MODE_ECB:
|
968 |
+
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
969 |
+
$plaintext.= $this->_decryptBlock(substr($ciphertext, $i, $block_size));
|
970 |
+
}
|
971 |
+
break;
|
972 |
+
case CRYPT_MODE_CBC:
|
973 |
+
$xor = $this->decryptIV;
|
974 |
+
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
975 |
+
$block = substr($ciphertext, $i, $block_size);
|
976 |
+
$plaintext.= $this->_decryptBlock($block) ^ $xor;
|
977 |
+
$xor = $block;
|
978 |
+
}
|
979 |
+
if ($this->continuousBuffer) {
|
980 |
+
$this->decryptIV = $xor;
|
981 |
+
}
|
982 |
+
break;
|
983 |
+
case CRYPT_MODE_CTR:
|
984 |
+
$xor = $this->decryptIV;
|
985 |
+
if (strlen($buffer['ciphertext'])) {
|
986 |
+
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
987 |
+
$block = substr($ciphertext, $i, $block_size);
|
988 |
+
if (strlen($block) > strlen($buffer['ciphertext'])) {
|
989 |
+
$buffer['ciphertext'].= $this->_encryptBlock($this->_generateXor($xor, $block_size));
|
990 |
+
}
|
991 |
+
$key = $this->_stringShift($buffer['ciphertext'], $block_size);
|
992 |
+
$plaintext.= $block ^ $key;
|
993 |
+
}
|
994 |
+
} else {
|
995 |
+
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
996 |
+
$block = substr($ciphertext, $i, $block_size);
|
997 |
+
$key = $this->_encryptBlock($this->_generateXor($xor, $block_size));
|
998 |
+
$plaintext.= $block ^ $key;
|
999 |
+
}
|
1000 |
+
}
|
1001 |
+
if ($this->continuousBuffer) {
|
1002 |
+
$this->decryptIV = $xor;
|
1003 |
+
if ($start = strlen($ciphertext) % $block_size) {
|
1004 |
+
$buffer['ciphertext'] = substr($key, $start) . $buffer['ciphertext'];
|
1005 |
+
}
|
1006 |
+
}
|
1007 |
+
break;
|
1008 |
+
case CRYPT_MODE_CFB:
|
1009 |
+
if ($this->continuousBuffer) {
|
1010 |
+
$iv = &$this->decryptIV;
|
1011 |
+
$pos = &$buffer['pos'];
|
1012 |
+
} else {
|
1013 |
+
$iv = $this->decryptIV;
|
1014 |
+
$pos = 0;
|
1015 |
+
}
|
1016 |
+
$len = strlen($ciphertext);
|
1017 |
+
$i = 0;
|
1018 |
+
if ($pos) {
|
1019 |
+
$orig_pos = $pos;
|
1020 |
+
$max = $block_size - $pos;
|
1021 |
+
if ($len >= $max) {
|
1022 |
+
$i = $max;
|
1023 |
+
$len-= $max;
|
1024 |
+
$pos = 0;
|
1025 |
+
} else {
|
1026 |
+
$i = $len;
|
1027 |
+
$pos+= $len;
|
1028 |
+
$len = 0;
|
1029 |
+
}
|
1030 |
+
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
1031 |
+
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
1032 |
+
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
1033 |
+
}
|
1034 |
+
while ($len >= $block_size) {
|
1035 |
+
$iv = $this->_encryptBlock($iv);
|
1036 |
+
$cb = substr($ciphertext, $i, $block_size);
|
1037 |
+
$plaintext.= $iv ^ $cb;
|
1038 |
+
$iv = $cb;
|
1039 |
+
$len-= $block_size;
|
1040 |
+
$i+= $block_size;
|
1041 |
+
}
|
1042 |
+
if ($len) {
|
1043 |
+
$iv = $this->_encryptBlock($iv);
|
1044 |
+
$plaintext.= $iv ^ substr($ciphertext, $i);
|
1045 |
+
$iv = substr_replace($iv, substr($ciphertext, $i), 0, $len);
|
1046 |
+
$pos = $len;
|
1047 |
+
}
|
1048 |
+
break;
|
1049 |
+
case CRYPT_MODE_OFB:
|
1050 |
+
$xor = $this->decryptIV;
|
1051 |
+
if (strlen($buffer['xor'])) {
|
1052 |
+
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
1053 |
+
$block = substr($ciphertext, $i, $block_size);
|
1054 |
+
if (strlen($block) > strlen($buffer['xor'])) {
|
1055 |
+
$xor = $this->_encryptBlock($xor);
|
1056 |
+
$buffer['xor'].= $xor;
|
1057 |
+
}
|
1058 |
+
$key = $this->_stringShift($buffer['xor'], $block_size);
|
1059 |
+
$plaintext.= $block ^ $key;
|
1060 |
+
}
|
1061 |
+
} else {
|
1062 |
+
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
1063 |
+
$xor = $this->_encryptBlock($xor);
|
1064 |
+
$plaintext.= substr($ciphertext, $i, $block_size) ^ $xor;
|
1065 |
+
}
|
1066 |
+
$key = $xor;
|
1067 |
+
}
|
1068 |
+
if ($this->continuousBuffer) {
|
1069 |
+
$this->decryptIV = $xor;
|
1070 |
+
if ($start = strlen($ciphertext) % $block_size) {
|
1071 |
+
$buffer['xor'] = substr($key, $start) . $buffer['xor'];
|
1072 |
+
}
|
1073 |
+
}
|
1074 |
+
break;
|
1075 |
+
case CRYPT_MODE_STREAM:
|
1076 |
+
$plaintext = $this->_decryptBlock($ciphertext);
|
1077 |
+
break;
|
1078 |
+
}
|
1079 |
+
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
/**
|
1083 |
+
* Pad "packets".
|
1084 |
+
*
|
1085 |
+
* Block ciphers working by encrypting between their specified [$this->]block_size at a time
|
1086 |
+
* If you ever need to encrypt or decrypt something that isn't of the proper length, it becomes necessary to
|
1087 |
+
* pad the input so that it is of the proper length.
|
1088 |
+
*
|
1089 |
+
* Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH,
|
1090 |
+
* where "packets" are padded with random bytes before being encrypted. Unpad these packets and you risk stripping
|
1091 |
+
* away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is
|
1092 |
+
* transmitted separately)
|
1093 |
+
*
|
1094 |
+
* @see Crypt_Base::disablePadding()
|
1095 |
+
* @access public
|
1096 |
+
*/
|
1097 |
+
function enablePadding()
|
1098 |
+
{
|
1099 |
+
$this->padding = true;
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
/**
|
1103 |
+
* Do not pad packets.
|
1104 |
+
*
|
1105 |
+
* @see Crypt_Base::enablePadding()
|
1106 |
+
* @access public
|
1107 |
+
*/
|
1108 |
+
function disablePadding()
|
1109 |
+
{
|
1110 |
+
$this->padding = false;
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
/**
|
1114 |
+
* Treat consecutive "packets" as if they are a continuous buffer.
|
1115 |
+
*
|
1116 |
+
* Say you have a 32-byte plaintext $plaintext. Using the default behavior, the two following code snippets
|
1117 |
+
* will yield different outputs:
|
1118 |
+
*
|
1119 |
+
* <code>
|
1120 |
+
* echo $rijndael->encrypt(substr($plaintext, 0, 16));
|
1121 |
+
* echo $rijndael->encrypt(substr($plaintext, 16, 16));
|
1122 |
+
* </code>
|
1123 |
+
* <code>
|
1124 |
+
* echo $rijndael->encrypt($plaintext);
|
1125 |
+
* </code>
|
1126 |
+
*
|
1127 |
+
* The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates
|
1128 |
+
* another, as demonstrated with the following:
|
1129 |
+
*
|
1130 |
+
* <code>
|
1131 |
+
* $rijndael->encrypt(substr($plaintext, 0, 16));
|
1132 |
+
* echo $rijndael->decrypt($rijndael->encrypt(substr($plaintext, 16, 16)));
|
1133 |
+
* </code>
|
1134 |
+
* <code>
|
1135 |
+
* echo $rijndael->decrypt($rijndael->encrypt(substr($plaintext, 16, 16)));
|
1136 |
+
* </code>
|
1137 |
+
*
|
1138 |
+
* With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different
|
1139 |
+
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
|
1140 |
+
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
|
1141 |
+
*
|
1142 |
+
* Put another way, when the continuous buffer is enabled, the state of the Crypt_*() object changes after each
|
1143 |
+
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
|
1144 |
+
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
|
1145 |
+
* however, they are also less intuitive and more likely to cause you problems.
|
1146 |
+
*
|
1147 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
1148 |
+
*
|
1149 |
+
* @see Crypt_Base::disableContinuousBuffer()
|
1150 |
+
* @access public
|
1151 |
+
*/
|
1152 |
+
function enableContinuousBuffer()
|
1153 |
+
{
|
1154 |
+
if ($this->mode == CRYPT_MODE_ECB) {
|
1155 |
+
return;
|
1156 |
+
}
|
1157 |
+
|
1158 |
+
$this->continuousBuffer = true;
|
1159 |
+
}
|
1160 |
+
|
1161 |
+
/**
|
1162 |
+
* Treat consecutive packets as if they are a discontinuous buffer.
|
1163 |
+
*
|
1164 |
+
* The default behavior.
|
1165 |
+
*
|
1166 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
1167 |
+
*
|
1168 |
+
* @see Crypt_Base::enableContinuousBuffer()
|
1169 |
+
* @access public
|
1170 |
+
*/
|
1171 |
+
function disableContinuousBuffer()
|
1172 |
+
{
|
1173 |
+
if ($this->mode == CRYPT_MODE_ECB) {
|
1174 |
+
return;
|
1175 |
+
}
|
1176 |
+
if (!$this->continuousBuffer) {
|
1177 |
+
return;
|
1178 |
+
}
|
1179 |
+
|
1180 |
+
$this->continuousBuffer = false;
|
1181 |
+
$this->changed = true;
|
1182 |
+
}
|
1183 |
+
|
1184 |
+
/**
|
1185 |
+
* Encrypts a block
|
1186 |
+
*
|
1187 |
+
* Note: Must extend by the child Crypt_* class
|
1188 |
+
*
|
1189 |
+
* @access private
|
1190 |
+
* @param String $in
|
1191 |
+
* @return String
|
1192 |
+
*/
|
1193 |
+
function _encryptBlock($in)
|
1194 |
+
{
|
1195 |
+
user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
1196 |
+
}
|
1197 |
+
|
1198 |
+
/**
|
1199 |
+
* Decrypts a block
|
1200 |
+
*
|
1201 |
+
* Note: Must extend by the child Crypt_* class
|
1202 |
+
*
|
1203 |
+
* @access private
|
1204 |
+
* @param String $in
|
1205 |
+
* @return String
|
1206 |
+
*/
|
1207 |
+
function _decryptBlock($in)
|
1208 |
+
{
|
1209 |
+
user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
/**
|
1213 |
+
* Setup the key (expansion)
|
1214 |
+
*
|
1215 |
+
* Only used if $engine == CRYPT_MODE_INTERNAL
|
1216 |
+
*
|
1217 |
+
* Note: Must extend by the child Crypt_* class
|
1218 |
+
*
|
1219 |
+
* @see Crypt_Base::_setup()
|
1220 |
+
* @access private
|
1221 |
+
*/
|
1222 |
+
function _setupKey()
|
1223 |
+
{
|
1224 |
+
user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
/**
|
1228 |
+
* Setup the CRYPT_MODE_INTERNAL $engine
|
1229 |
+
*
|
1230 |
+
* (re)init, if necessary, the internal cipher $engine and flush all $buffers
|
1231 |
+
* Used (only) if $engine == CRYPT_MODE_INTERNAL
|
1232 |
+
*
|
1233 |
+
* _setup() will be called each time if $changed === true
|
1234 |
+
* typically this happens when using one or more of following public methods:
|
1235 |
+
*
|
1236 |
+
* - setKey()
|
1237 |
+
*
|
1238 |
+
* - setIV()
|
1239 |
+
*
|
1240 |
+
* - disableContinuousBuffer()
|
1241 |
+
*
|
1242 |
+
* - First run of encrypt() / decrypt() with no init-settings
|
1243 |
+
*
|
1244 |
+
* Internally: _setup() is called always before(!) en/decryption.
|
1245 |
+
*
|
1246 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
1247 |
+
*
|
1248 |
+
* @see setKey()
|
1249 |
+
* @see setIV()
|
1250 |
+
* @see disableContinuousBuffer()
|
1251 |
+
* @access private
|
1252 |
+
*/
|
1253 |
+
function _setup()
|
1254 |
+
{
|
1255 |
+
$this->_clearBuffers();
|
1256 |
+
$this->_setupKey();
|
1257 |
+
|
1258 |
+
if ($this->use_inline_crypt) {
|
1259 |
+
$this->_setupInlineCrypt();
|
1260 |
+
}
|
1261 |
+
}
|
1262 |
+
|
1263 |
+
/**
|
1264 |
+
* Setup the CRYPT_MODE_MCRYPT $engine
|
1265 |
+
*
|
1266 |
+
* (re)init, if necessary, the (ext)mcrypt resources and flush all $buffers
|
1267 |
+
* Used (only) if $engine = CRYPT_MODE_MCRYPT
|
1268 |
+
*
|
1269 |
+
* _setupMcrypt() will be called each time if $changed === true
|
1270 |
+
* typically this happens when using one or more of following public methods:
|
1271 |
+
*
|
1272 |
+
* - setKey()
|
1273 |
+
*
|
1274 |
+
* - setIV()
|
1275 |
+
*
|
1276 |
+
* - disableContinuousBuffer()
|
1277 |
+
*
|
1278 |
+
* - First run of encrypt() / decrypt()
|
1279 |
+
*
|
1280 |
+
*
|
1281 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
1282 |
+
*
|
1283 |
+
* @see setKey()
|
1284 |
+
* @see setIV()
|
1285 |
+
* @see disableContinuousBuffer()
|
1286 |
+
* @access private
|
1287 |
+
*/
|
1288 |
+
function _setupMcrypt()
|
1289 |
+
{
|
1290 |
+
$this->_clearBuffers();
|
1291 |
+
$this->enchanged = $this->dechanged = true;
|
1292 |
+
|
1293 |
+
if (!isset($this->enmcrypt)) {
|
1294 |
+
static $mcrypt_modes = array(
|
1295 |
+
CRYPT_MODE_CTR => 'ctr',
|
1296 |
+
CRYPT_MODE_ECB => MCRYPT_MODE_ECB,
|
1297 |
+
CRYPT_MODE_CBC => MCRYPT_MODE_CBC,
|
1298 |
+
CRYPT_MODE_CFB => 'ncfb',
|
1299 |
+
CRYPT_MODE_OFB => MCRYPT_MODE_NOFB,
|
1300 |
+
CRYPT_MODE_STREAM => MCRYPT_MODE_STREAM,
|
1301 |
+
);
|
1302 |
+
|
1303 |
+
$this->demcrypt = mcrypt_module_open($this->cipher_name_mcrypt, '', $mcrypt_modes[$this->mode], '');
|
1304 |
+
$this->enmcrypt = mcrypt_module_open($this->cipher_name_mcrypt, '', $mcrypt_modes[$this->mode], '');
|
1305 |
+
|
1306 |
+
// we need the $ecb mcrypt resource (only) in MODE_CFB with enableContinuousBuffer()
|
1307 |
+
// to workaround mcrypt's broken ncfb implementation in buffered mode
|
1308 |
+
// see: {@link http://phpseclib.sourceforge.net/cfb-demo.phps}
|
1309 |
+
if ($this->mode == CRYPT_MODE_CFB) {
|
1310 |
+
$this->ecb = mcrypt_module_open($this->cipher_name_mcrypt, '', MCRYPT_MODE_ECB, '');
|
1311 |
+
}
|
1312 |
+
|
1313 |
+
} // else should mcrypt_generic_deinit be called?
|
1314 |
+
|
1315 |
+
if ($this->mode == CRYPT_MODE_CFB) {
|
1316 |
+
mcrypt_generic_init($this->ecb, $this->key, str_repeat("\0", $this->block_size));
|
1317 |
+
}
|
1318 |
+
}
|
1319 |
+
|
1320 |
+
/**
|
1321 |
+
* Pads a string
|
1322 |
+
*
|
1323 |
+
* Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize.
|
1324 |
+
* $this->block_size - (strlen($text) % $this->block_size) bytes are added, each of which is equal to
|
1325 |
+
* chr($this->block_size - (strlen($text) % $this->block_size)
|
1326 |
+
*
|
1327 |
+
* If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless
|
1328 |
+
* and padding will, hence forth, be enabled.
|
1329 |
+
*
|
1330 |
+
* @see Crypt_Base::_unpad()
|
1331 |
+
* @param String $text
|
1332 |
+
* @access private
|
1333 |
+
* @return String
|
1334 |
+
*/
|
1335 |
+
function _pad($text)
|
1336 |
+
{
|
1337 |
+
$length = strlen($text);
|
1338 |
+
|
1339 |
+
if (!$this->padding) {
|
1340 |
+
if ($length % $this->block_size == 0) {
|
1341 |
+
return $text;
|
1342 |
+
} else {
|
1343 |
+
user_error("The plaintext's length ($length) is not a multiple of the block size ({$this->block_size})");
|
1344 |
+
$this->padding = true;
|
1345 |
+
}
|
1346 |
+
}
|
1347 |
+
|
1348 |
+
$pad = $this->block_size - ($length % $this->block_size);
|
1349 |
+
|
1350 |
+
return str_pad($text, $length + $pad, chr($pad));
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
/**
|
1354 |
+
* Unpads a string.
|
1355 |
+
*
|
1356 |
+
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong
|
1357 |
+
* and false will be returned.
|
1358 |
+
*
|
1359 |
+
* @see Crypt_Base::_pad()
|
1360 |
+
* @param String $text
|
1361 |
+
* @access private
|
1362 |
+
* @return String
|
1363 |
+
*/
|
1364 |
+
function _unpad($text)
|
1365 |
+
{
|
1366 |
+
if (!$this->padding) {
|
1367 |
+
return $text;
|
1368 |
+
}
|
1369 |
+
|
1370 |
+
$length = ord($text[strlen($text) - 1]);
|
1371 |
+
|
1372 |
+
if (!$length || $length > $this->block_size) {
|
1373 |
+
return false;
|
1374 |
+
}
|
1375 |
+
|
1376 |
+
return substr($text, 0, -$length);
|
1377 |
+
}
|
1378 |
+
|
1379 |
+
/**
|
1380 |
+
* Clears internal buffers
|
1381 |
+
*
|
1382 |
+
* Clearing/resetting the internal buffers is done everytime
|
1383 |
+
* after disableContinuousBuffer() or on cipher $engine (re)init
|
1384 |
+
* ie after setKey() or setIV()
|
1385 |
+
*
|
1386 |
+
* Note: Could, but not must, extend by the child Crypt_* class
|
1387 |
+
*
|
1388 |
+
* @access public
|
1389 |
+
*/
|
1390 |
+
function _clearBuffers()
|
1391 |
+
{
|
1392 |
+
$this->enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
1393 |
+
$this->debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
1394 |
+
|
1395 |
+
// mcrypt's handling of invalid's $iv:
|
1396 |
+
// $this->encryptIV = $this->decryptIV = strlen($this->iv) == $this->block_size ? $this->iv : str_repeat("\0", $this->block_size);
|
1397 |
+
$this->encryptIV = $this->decryptIV = str_pad(substr($this->iv, 0, $this->block_size), $this->block_size, "\0");
|
1398 |
+
}
|
1399 |
+
|
1400 |
+
/**
|
1401 |
+
* String Shift
|
1402 |
+
*
|
1403 |
+
* Inspired by array_shift
|
1404 |
+
*
|
1405 |
+
* @param String $string
|
1406 |
+
* @param optional Integer $index
|
1407 |
+
* @access private
|
1408 |
+
* @return String
|
1409 |
+
*/
|
1410 |
+
function _stringShift(&$string, $index = 1)
|
1411 |
+
{
|
1412 |
+
$substr = substr($string, 0, $index);
|
1413 |
+
$string = substr($string, $index);
|
1414 |
+
return $substr;
|
1415 |
+
}
|
1416 |
+
|
1417 |
+
/**
|
1418 |
+
* Generate CTR XOR encryption key
|
1419 |
+
*
|
1420 |
+
* Encrypt the output of this and XOR it against the ciphertext / plaintext to get the
|
1421 |
+
* plaintext / ciphertext in CTR mode.
|
1422 |
+
*
|
1423 |
+
* @see Crypt_Base::decrypt()
|
1424 |
+
* @see Crypt_Base::encrypt()
|
1425 |
+
* @param String $iv
|
1426 |
+
* @param Integer $length
|
1427 |
+
* @access private
|
1428 |
+
* @return String $xor
|
1429 |
+
*/
|
1430 |
+
function _generateXor(&$iv, $length)
|
1431 |
+
{
|
1432 |
+
$xor = '';
|
1433 |
+
$block_size = $this->block_size;
|
1434 |
+
$num_blocks = floor(($length + ($block_size - 1)) / $block_size);
|
1435 |
+
for ($i = 0; $i < $num_blocks; $i++) {
|
1436 |
+
$xor.= $iv;
|
1437 |
+
for ($j = 4; $j <= $block_size; $j+= 4) {
|
1438 |
+
$temp = substr($iv, -$j, 4);
|
1439 |
+
switch ($temp) {
|
1440 |
+
case "\xFF\xFF\xFF\xFF":
|
1441 |
+
$iv = substr_replace($iv, "\x00\x00\x00\x00", -$j, 4);
|
1442 |
+
break;
|
1443 |
+
case "\x7F\xFF\xFF\xFF":
|
1444 |
+
$iv = substr_replace($iv, "\x80\x00\x00\x00", -$j, 4);
|
1445 |
+
break 2;
|
1446 |
+
default:
|
1447 |
+
extract(unpack('Ncount', $temp));
|
1448 |
+
$iv = substr_replace($iv, pack('N', $count + 1), -$j, 4);
|
1449 |
+
break 2;
|
1450 |
+
}
|
1451 |
+
}
|
1452 |
+
}
|
1453 |
+
|
1454 |
+
return $xor;
|
1455 |
+
}
|
1456 |
+
|
1457 |
+
/**
|
1458 |
+
* Setup the performance-optimized function for de/encrypt()
|
1459 |
+
*
|
1460 |
+
* Stores the created (or existing) callback function-name
|
1461 |
+
* in $this->inline_crypt
|
1462 |
+
*
|
1463 |
+
* Internally for phpseclib developers:
|
1464 |
+
*
|
1465 |
+
* _setupInlineCrypt() would be called only if:
|
1466 |
+
*
|
1467 |
+
* - $engine == CRYPT_MODE_INTERNAL and
|
1468 |
+
*
|
1469 |
+
* - $use_inline_crypt === true
|
1470 |
+
*
|
1471 |
+
* - each time on _setup(), after(!) _setupKey()
|
1472 |
+
*
|
1473 |
+
*
|
1474 |
+
* This ensures that _setupInlineCrypt() has always a
|
1475 |
+
* full ready2go initializated internal cipher $engine state
|
1476 |
+
* where, for example, the keys allready expanded,
|
1477 |
+
* keys/block_size calculated and such.
|
1478 |
+
*
|
1479 |
+
* It is, each time if called, the responsibility of _setupInlineCrypt():
|
1480 |
+
*
|
1481 |
+
* - to set $this->inline_crypt to a valid and fully working callback function
|
1482 |
+
* as a (faster) replacement for encrypt() / decrypt()
|
1483 |
+
*
|
1484 |
+
* - NOT to create unlimited callback functions (for memory reasons!)
|
1485 |
+
* no matter how often _setupInlineCrypt() would be called. At some
|
1486 |
+
* point of amount they must be generic re-useable.
|
1487 |
+
*
|
1488 |
+
* - the code of _setupInlineCrypt() it self,
|
1489 |
+
* and the generated callback code,
|
1490 |
+
* must be, in following order:
|
1491 |
+
* - 100% safe
|
1492 |
+
* - 100% compatible to encrypt()/decrypt()
|
1493 |
+
* - using only php5+ features/lang-constructs/php-extensions if
|
1494 |
+
* compatibility (down to php4) or fallback is provided
|
1495 |
+
* - readable/maintainable/understandable/commented and... not-cryptic-styled-code :-)
|
1496 |
+
* - >= 10% faster than encrypt()/decrypt() [which is, by the way,
|
1497 |
+
* the reason for the existence of _setupInlineCrypt() :-)]
|
1498 |
+
* - memory-nice
|
1499 |
+
* - short (as good as possible)
|
1500 |
+
*
|
1501 |
+
* Note: - _setupInlineCrypt() is using _createInlineCryptFunction() to create the full callback function code.
|
1502 |
+
* - In case of using inline crypting, _setupInlineCrypt() must extend by the child Crypt_* class.
|
1503 |
+
* - The following variable names are reserved:
|
1504 |
+
* - $_* (all variable names prefixed with an underscore)
|
1505 |
+
* - $self (object reference to it self. Do not use $this, but $self instead)
|
1506 |
+
* - $in (the content of $in has to en/decrypt by the generated code)
|
1507 |
+
* - The callback function should not use the 'return' statement, but en/decrypt'ing the content of $in only
|
1508 |
+
*
|
1509 |
+
*
|
1510 |
+
* @see Crypt_Base::_setup()
|
1511 |
+
* @see Crypt_Base::_createInlineCryptFunction()
|
1512 |
+
* @see Crypt_Base::encrypt()
|
1513 |
+
* @see Crypt_Base::decrypt()
|
1514 |
+
* @access private
|
1515 |
+
*/
|
1516 |
+
function _setupInlineCrypt()
|
1517 |
+
{
|
1518 |
+
// If a Crypt_* class providing inline crypting it must extend _setupInlineCrypt()
|
1519 |
+
|
1520 |
+
// If, for any reason, an extending Crypt_Base() Crypt_* class
|
1521 |
+
// not using inline crypting then it must be ensured that: $this->use_inline_crypt = false
|
1522 |
+
// ie in the class var declaration of $use_inline_crypt in general for the Crypt_* class,
|
1523 |
+
// in the constructor at object instance-time
|
1524 |
+
// or, if it's runtime-specific, at runtime
|
1525 |
+
|
1526 |
+
$this->use_inline_crypt = false;
|
1527 |
+
}
|
1528 |
+
|
1529 |
+
/**
|
1530 |
+
* Creates the performance-optimized function for en/decrypt()
|
1531 |
+
*
|
1532 |
+
* Internally for phpseclib developers:
|
1533 |
+
*
|
1534 |
+
* _createInlineCryptFunction():
|
1535 |
+
*
|
1536 |
+
* - merge the $cipher_code [setup'ed by _setupInlineCrypt()]
|
1537 |
+
* with the current [$this->]mode of operation code
|
1538 |
+
*
|
1539 |
+
* - create the $inline function, which called by encrypt() / decrypt()
|
1540 |
+
* as its replacement to speed up the en/decryption operations.
|
1541 |
+
*
|
1542 |
+
* - return the name of the created $inline callback function
|
1543 |
+
*
|
1544 |
+
* - used to speed up en/decryption
|
1545 |
+
*
|
1546 |
+
*
|
1547 |
+
*
|
1548 |
+
* The main reason why can speed up things [up to 50%] this way are:
|
1549 |
+
*
|
1550 |
+
* - using variables more effective then regular.
|
1551 |
+
* (ie no use of expensive arrays but integers $k_0, $k_1 ...
|
1552 |
+
* or even, for example, the pure $key[] values hardcoded)
|
1553 |
+
*
|
1554 |
+
* - avoiding 1000's of function calls of ie _encryptBlock()
|
1555 |
+
* but inlining the crypt operations.
|
1556 |
+
* in the mode of operation for() loop.
|
1557 |
+
*
|
1558 |
+
* - full loop unroll the (sometimes key-dependent) rounds
|
1559 |
+
* avoiding this way ++$i counters and runtime-if's etc...
|
1560 |
+
*
|
1561 |
+
* The basic code architectur of the generated $inline en/decrypt()
|
1562 |
+
* lambda function, in pseudo php, is:
|
1563 |
+
*
|
1564 |
+
* <code>
|
1565 |
+
* +----------------------------------------------------------------------------------------------+
|
1566 |
+
* | callback $inline = create_function: |
|
1567 |
+
* | lambda_function_0001_crypt_ECB($action, $text) |
|
1568 |
+
* | { |
|
1569 |
+
* | INSERT PHP CODE OF: |
|
1570 |
+
* | $cipher_code['init_crypt']; // general init code. |
|
1571 |
+
* | // ie: $sbox'es declarations used for |
|
1572 |
+
* | // encrypt and decrypt'ing. |
|
1573 |
+
* | |
|
1574 |
+
* | switch ($action) { |
|
1575 |
+
* | case 'encrypt': |
|
1576 |
+
* | INSERT PHP CODE OF: |
|
1577 |
+
* | $cipher_code['init_encrypt']; // encrypt sepcific init code. |
|
1578 |
+
* | ie: specified $key or $box |
|
1579 |
+
* | declarations for encrypt'ing. |
|
1580 |
+
* | |
|
1581 |
+
* | foreach ($ciphertext) { |
|
1582 |
+
* | $in = $block_size of $ciphertext; |
|
1583 |
+
* | |
|
1584 |
+
* | INSERT PHP CODE OF: |
|
1585 |
+
* | $cipher_code['encrypt_block']; // encrypt's (string) $in, which is always: |
|
1586 |
+
* | // strlen($in) == $this->block_size |
|
1587 |
+
* | // here comes the cipher algorithm in action |
|
1588 |
+
* | // for encryption. |
|
1589 |
+
* | // $cipher_code['encrypt_block'] has to |
|
1590 |
+
* | // encrypt the content of the $in variable |
|
1591 |
+
* | |
|
1592 |
+
* | $plaintext .= $in; |
|
1593 |
+
* | } |
|
1594 |
+
* | return $plaintext; |
|
1595 |
+
* | |
|
1596 |
+
* | case 'decrypt': |
|
1597 |
+
* | INSERT PHP CODE OF: |
|
1598 |
+
* | $cipher_code['init_decrypt']; // decrypt sepcific init code |
|
1599 |
+
* | ie: specified $key or $box |
|
1600 |
+
* | declarations for decrypt'ing. |
|
1601 |
+
* | foreach ($plaintext) { |
|
1602 |
+
* | $in = $block_size of $plaintext; |
|
1603 |
+
* | |
|
1604 |
+
* | INSERT PHP CODE OF: |
|
1605 |
+
* | $cipher_code['decrypt_block']; // decrypt's (string) $in, which is always |
|
1606 |
+
* | // strlen($in) == $this->block_size |
|
1607 |
+
* | // here comes the cipher algorithm in action |
|
1608 |
+
* | // for decryption. |
|
1609 |
+
* | // $cipher_code['decrypt_block'] has to |
|
1610 |
+
* | // decrypt the content of the $in variable |
|
1611 |
+
* | $ciphertext .= $in; |
|
1612 |
+
* | } |
|
1613 |
+
* | return $ciphertext; |
|
1614 |
+
* | } |
|
1615 |
+
* | } |
|
1616 |
+
* +----------------------------------------------------------------------------------------------+
|
1617 |
+
* </code>
|
1618 |
+
*
|
1619 |
+
* See also the Crypt_*::_setupInlineCrypt()'s for
|
1620 |
+
* productive inline $cipher_code's how they works.
|
1621 |
+
*
|
1622 |
+
* Structure of:
|
1623 |
+
* <code>
|
1624 |
+
* $cipher_code = array(
|
1625 |
+
* 'init_crypt' => (string) '', // optional
|
1626 |
+
* 'init_encrypt' => (string) '', // optional
|
1627 |
+
* 'init_decrypt' => (string) '', // optional
|
1628 |
+
* 'encrypt_block' => (string) '', // required
|
1629 |
+
* 'decrypt_block' => (string) '' // required
|
1630 |
+
* );
|
1631 |
+
* </code>
|
1632 |
+
*
|
1633 |
+
* @see Crypt_Base::_setupInlineCrypt()
|
1634 |
+
* @see Crypt_Base::encrypt()
|
1635 |
+
* @see Crypt_Base::decrypt()
|
1636 |
+
* @param Array $cipher_code
|
1637 |
+
* @access private
|
1638 |
+
* @return String (the name of the created callback function)
|
1639 |
+
*/
|
1640 |
+
function _createInlineCryptFunction($cipher_code)
|
1641 |
+
{
|
1642 |
+
$block_size = $this->block_size;
|
1643 |
+
|
1644 |
+
// optional
|
1645 |
+
$init_crypt = isset($cipher_code['init_crypt']) ? $cipher_code['init_crypt'] : '';
|
1646 |
+
$init_encrypt = isset($cipher_code['init_encrypt']) ? $cipher_code['init_encrypt'] : '';
|
1647 |
+
$init_decrypt = isset($cipher_code['init_decrypt']) ? $cipher_code['init_decrypt'] : '';
|
1648 |
+
// required
|
1649 |
+
$encrypt_block = $cipher_code['encrypt_block'];
|
1650 |
+
$decrypt_block = $cipher_code['decrypt_block'];
|
1651 |
+
|
1652 |
+
// Generating mode of operation inline code,
|
1653 |
+
// merged with the $cipher_code algorithm
|
1654 |
+
// for encrypt- and decryption.
|
1655 |
+
switch ($this->mode) {
|
1656 |
+
case CRYPT_MODE_ECB:
|
1657 |
+
$encrypt = $init_encrypt . '
|
1658 |
+
$_ciphertext = "";
|
1659 |
+
$_text = $self->_pad($_text);
|
1660 |
+
$_plaintext_len = strlen($_text);
|
1661 |
+
|
1662 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1663 |
+
$in = substr($_text, $_i, '.$block_size.');
|
1664 |
+
'.$encrypt_block.'
|
1665 |
+
$_ciphertext.= $in;
|
1666 |
+
}
|
1667 |
+
|
1668 |
+
return $_ciphertext;
|
1669 |
+
';
|
1670 |
+
|
1671 |
+
$decrypt = $init_decrypt . '
|
1672 |
+
$_plaintext = "";
|
1673 |
+
$_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
|
1674 |
+
$_ciphertext_len = strlen($_text);
|
1675 |
+
|
1676 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1677 |
+
$in = substr($_text, $_i, '.$block_size.');
|
1678 |
+
'.$decrypt_block.'
|
1679 |
+
$_plaintext.= $in;
|
1680 |
+
}
|
1681 |
+
|
1682 |
+
return $self->_unpad($_plaintext);
|
1683 |
+
';
|
1684 |
+
break;
|
1685 |
+
case CRYPT_MODE_CTR:
|
1686 |
+
$encrypt = $init_encrypt . '
|
1687 |
+
$_ciphertext = "";
|
1688 |
+
$_plaintext_len = strlen($_text);
|
1689 |
+
$_xor = $self->encryptIV;
|
1690 |
+
$_buffer = &$self->enbuffer;
|
1691 |
+
|
1692 |
+
if (strlen($_buffer["encrypted"])) {
|
1693 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1694 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1695 |
+
if (strlen($_block) > strlen($_buffer["encrypted"])) {
|
1696 |
+
$in = $self->_generateXor($_xor, '.$block_size.');
|
1697 |
+
'.$encrypt_block.'
|
1698 |
+
$_buffer["encrypted"].= $in;
|
1699 |
+
}
|
1700 |
+
$_key = $self->_stringShift($_buffer["encrypted"], '.$block_size.');
|
1701 |
+
$_ciphertext.= $_block ^ $_key;
|
1702 |
+
}
|
1703 |
+
} else {
|
1704 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1705 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1706 |
+
$in = $self->_generateXor($_xor, '.$block_size.');
|
1707 |
+
'.$encrypt_block.'
|
1708 |
+
$_key = $in;
|
1709 |
+
$_ciphertext.= $_block ^ $_key;
|
1710 |
+
}
|
1711 |
+
}
|
1712 |
+
if ($self->continuousBuffer) {
|
1713 |
+
$self->encryptIV = $_xor;
|
1714 |
+
if ($_start = $_plaintext_len % '.$block_size.') {
|
1715 |
+
$_buffer["encrypted"] = substr($_key, $_start) . $_buffer["encrypted"];
|
1716 |
+
}
|
1717 |
+
}
|
1718 |
+
|
1719 |
+
return $_ciphertext;
|
1720 |
+
';
|
1721 |
+
|
1722 |
+
$decrypt = $init_encrypt . '
|
1723 |
+
$_plaintext = "";
|
1724 |
+
$_ciphertext_len = strlen($_text);
|
1725 |
+
$_xor = $self->decryptIV;
|
1726 |
+
$_buffer = &$self->debuffer;
|
1727 |
+
|
1728 |
+
if (strlen($_buffer["ciphertext"])) {
|
1729 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1730 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1731 |
+
if (strlen($_block) > strlen($_buffer["ciphertext"])) {
|
1732 |
+
$in = $self->_generateXor($_xor, '.$block_size.');
|
1733 |
+
'.$encrypt_block.'
|
1734 |
+
$_buffer["ciphertext"].= $in;
|
1735 |
+
}
|
1736 |
+
$_key = $self->_stringShift($_buffer["ciphertext"], '.$block_size.');
|
1737 |
+
$_plaintext.= $_block ^ $_key;
|
1738 |
+
}
|
1739 |
+
} else {
|
1740 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1741 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1742 |
+
$in = $self->_generateXor($_xor, '.$block_size.');
|
1743 |
+
'.$encrypt_block.'
|
1744 |
+
$_key = $in;
|
1745 |
+
$_plaintext.= $_block ^ $_key;
|
1746 |
+
}
|
1747 |
+
}
|
1748 |
+
if ($self->continuousBuffer) {
|
1749 |
+
$self->decryptIV = $_xor;
|
1750 |
+
if ($_start = $_ciphertext_len % '.$block_size.') {
|
1751 |
+
$_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"];
|
1752 |
+
}
|
1753 |
+
}
|
1754 |
+
|
1755 |
+
return $_plaintext;
|
1756 |
+
';
|
1757 |
+
break;
|
1758 |
+
case CRYPT_MODE_CFB:
|
1759 |
+
$encrypt = $init_encrypt . '
|
1760 |
+
$_ciphertext = "";
|
1761 |
+
$_buffer = &$self->enbuffer;
|
1762 |
+
|
1763 |
+
if ($self->continuousBuffer) {
|
1764 |
+
$_iv = &$self->encryptIV;
|
1765 |
+
$_pos = &$_buffer["pos"];
|
1766 |
+
} else {
|
1767 |
+
$_iv = $self->encryptIV;
|
1768 |
+
$_pos = 0;
|
1769 |
+
}
|
1770 |
+
$_len = strlen($_text);
|
1771 |
+
$_i = 0;
|
1772 |
+
if ($_pos) {
|
1773 |
+
$_orig_pos = $_pos;
|
1774 |
+
$_max = '.$block_size.' - $_pos;
|
1775 |
+
if ($_len >= $_max) {
|
1776 |
+
$_i = $_max;
|
1777 |
+
$_len-= $_max;
|
1778 |
+
$_pos = 0;
|
1779 |
+
} else {
|
1780 |
+
$_i = $_len;
|
1781 |
+
$_pos+= $_len;
|
1782 |
+
$_len = 0;
|
1783 |
+
}
|
1784 |
+
$_ciphertext = substr($_iv, $_orig_pos) ^ $_text;
|
1785 |
+
$_iv = substr_replace($_iv, $_ciphertext, $_orig_pos, $_i);
|
1786 |
+
}
|
1787 |
+
while ($_len >= '.$block_size.') {
|
1788 |
+
$in = $_iv;
|
1789 |
+
'.$encrypt_block.';
|
1790 |
+
$_iv = $in ^ substr($_text, $_i, '.$block_size.');
|
1791 |
+
$_ciphertext.= $_iv;
|
1792 |
+
$_len-= '.$block_size.';
|
1793 |
+
$_i+= '.$block_size.';
|
1794 |
+
}
|
1795 |
+
if ($_len) {
|
1796 |
+
$in = $_iv;
|
1797 |
+
'.$encrypt_block.'
|
1798 |
+
$_iv = $in;
|
1799 |
+
$_block = $_iv ^ substr($_text, $_i);
|
1800 |
+
$_iv = substr_replace($_iv, $_block, 0, $_len);
|
1801 |
+
$_ciphertext.= $_block;
|
1802 |
+
$_pos = $_len;
|
1803 |
+
}
|
1804 |
+
return $_ciphertext;
|
1805 |
+
';
|
1806 |
+
|
1807 |
+
$decrypt = $init_encrypt . '
|
1808 |
+
$_plaintext = "";
|
1809 |
+
$_buffer = &$self->debuffer;
|
1810 |
+
|
1811 |
+
if ($self->continuousBuffer) {
|
1812 |
+
$_iv = &$self->decryptIV;
|
1813 |
+
$_pos = &$_buffer["pos"];
|
1814 |
+
} else {
|
1815 |
+
$_iv = $self->decryptIV;
|
1816 |
+
$_pos = 0;
|
1817 |
+
}
|
1818 |
+
$_len = strlen($_text);
|
1819 |
+
$_i = 0;
|
1820 |
+
if ($_pos) {
|
1821 |
+
$_orig_pos = $_pos;
|
1822 |
+
$_max = '.$block_size.' - $_pos;
|
1823 |
+
if ($_len >= $_max) {
|
1824 |
+
$_i = $_max;
|
1825 |
+
$_len-= $_max;
|
1826 |
+
$_pos = 0;
|
1827 |
+
} else {
|
1828 |
+
$_i = $_len;
|
1829 |
+
$_pos+= $_len;
|
1830 |
+
$_len = 0;
|
1831 |
+
}
|
1832 |
+
$_plaintext = substr($_iv, $_orig_pos) ^ $_text;
|
1833 |
+
$_iv = substr_replace($_iv, substr($_text, 0, $_i), $_orig_pos, $_i);
|
1834 |
+
}
|
1835 |
+
while ($_len >= '.$block_size.') {
|
1836 |
+
$in = $_iv;
|
1837 |
+
'.$encrypt_block.'
|
1838 |
+
$_iv = $in;
|
1839 |
+
$cb = substr($_text, $_i, '.$block_size.');
|
1840 |
+
$_plaintext.= $_iv ^ $cb;
|
1841 |
+
$_iv = $cb;
|
1842 |
+
$_len-= '.$block_size.';
|
1843 |
+
$_i+= '.$block_size.';
|
1844 |
+
}
|
1845 |
+
if ($_len) {
|
1846 |
+
$in = $_iv;
|
1847 |
+
'.$encrypt_block.'
|
1848 |
+
$_iv = $in;
|
1849 |
+
$_plaintext.= $_iv ^ substr($_text, $_i);
|
1850 |
+
$_iv = substr_replace($_iv, substr($_text, $_i), 0, $_len);
|
1851 |
+
$_pos = $_len;
|
1852 |
+
}
|
1853 |
+
|
1854 |
+
return $_plaintext;
|
1855 |
+
';
|
1856 |
+
break;
|
1857 |
+
case CRYPT_MODE_OFB:
|
1858 |
+
$encrypt = $init_encrypt . '
|
1859 |
+
$_ciphertext = "";
|
1860 |
+
$_plaintext_len = strlen($_text);
|
1861 |
+
$_xor = $self->encryptIV;
|
1862 |
+
$_buffer = &$self->enbuffer;
|
1863 |
+
|
1864 |
+
if (strlen($_buffer["xor"])) {
|
1865 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1866 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1867 |
+
if (strlen($_block) > strlen($_buffer["xor"])) {
|
1868 |
+
$in = $_xor;
|
1869 |
+
'.$encrypt_block.'
|
1870 |
+
$_xor = $in;
|
1871 |
+
$_buffer["xor"].= $_xor;
|
1872 |
+
}
|
1873 |
+
$_key = $self->_stringShift($_buffer["xor"], '.$block_size.');
|
1874 |
+
$_ciphertext.= $_block ^ $_key;
|
1875 |
+
}
|
1876 |
+
} else {
|
1877 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1878 |
+
$in = $_xor;
|
1879 |
+
'.$encrypt_block.'
|
1880 |
+
$_xor = $in;
|
1881 |
+
$_ciphertext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
|
1882 |
+
}
|
1883 |
+
$_key = $_xor;
|
1884 |
+
}
|
1885 |
+
if ($self->continuousBuffer) {
|
1886 |
+
$self->encryptIV = $_xor;
|
1887 |
+
if ($_start = $_plaintext_len % '.$block_size.') {
|
1888 |
+
$_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
|
1889 |
+
}
|
1890 |
+
}
|
1891 |
+
return $_ciphertext;
|
1892 |
+
';
|
1893 |
+
|
1894 |
+
$decrypt = $init_encrypt . '
|
1895 |
+
$_plaintext = "";
|
1896 |
+
$_ciphertext_len = strlen($_text);
|
1897 |
+
$_xor = $self->decryptIV;
|
1898 |
+
$_buffer = &$self->debuffer;
|
1899 |
+
|
1900 |
+
if (strlen($_buffer["xor"])) {
|
1901 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1902 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1903 |
+
if (strlen($_block) > strlen($_buffer["xor"])) {
|
1904 |
+
$in = $_xor;
|
1905 |
+
'.$encrypt_block.'
|
1906 |
+
$_xor = $in;
|
1907 |
+
$_buffer["xor"].= $_xor;
|
1908 |
+
}
|
1909 |
+
$_key = $self->_stringShift($_buffer["xor"], '.$block_size.');
|
1910 |
+
$_plaintext.= $_block ^ $_key;
|
1911 |
+
}
|
1912 |
+
} else {
|
1913 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1914 |
+
$in = $_xor;
|
1915 |
+
'.$encrypt_block.'
|
1916 |
+
$_xor = $in;
|
1917 |
+
$_plaintext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
|
1918 |
+
}
|
1919 |
+
$_key = $_xor;
|
1920 |
+
}
|
1921 |
+
if ($self->continuousBuffer) {
|
1922 |
+
$self->decryptIV = $_xor;
|
1923 |
+
if ($_start = $_ciphertext_len % '.$block_size.') {
|
1924 |
+
$_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
|
1925 |
+
}
|
1926 |
+
}
|
1927 |
+
return $_plaintext;
|
1928 |
+
';
|
1929 |
+
break;
|
1930 |
+
case CRYPT_MODE_STREAM:
|
1931 |
+
$encrypt = $init_encrypt . '
|
1932 |
+
$_ciphertext = "";
|
1933 |
+
'.$encrypt_block.'
|
1934 |
+
return $_ciphertext;
|
1935 |
+
';
|
1936 |
+
$decrypt = $init_decrypt . '
|
1937 |
+
$_plaintext = "";
|
1938 |
+
'.$decrypt_block.'
|
1939 |
+
return $_plaintext;
|
1940 |
+
';
|
1941 |
+
break;
|
1942 |
+
// case CRYPT_MODE_CBC:
|
1943 |
+
default:
|
1944 |
+
$encrypt = $init_encrypt . '
|
1945 |
+
$_ciphertext = "";
|
1946 |
+
$_text = $self->_pad($_text);
|
1947 |
+
$_plaintext_len = strlen($_text);
|
1948 |
+
|
1949 |
+
$in = $self->encryptIV;
|
1950 |
+
|
1951 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1952 |
+
$in = substr($_text, $_i, '.$block_size.') ^ $in;
|
1953 |
+
'.$encrypt_block.'
|
1954 |
+
$_ciphertext.= $in;
|
1955 |
+
}
|
1956 |
+
|
1957 |
+
if ($self->continuousBuffer) {
|
1958 |
+
$self->encryptIV = $in;
|
1959 |
+
}
|
1960 |
+
|
1961 |
+
return $_ciphertext;
|
1962 |
+
';
|
1963 |
+
|
1964 |
+
$decrypt = $init_decrypt . '
|
1965 |
+
$_plaintext = "";
|
1966 |
+
$_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
|
1967 |
+
$_ciphertext_len = strlen($_text);
|
1968 |
+
|
1969 |
+
$_iv = $self->decryptIV;
|
1970 |
+
|
1971 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1972 |
+
$in = $_block = substr($_text, $_i, '.$block_size.');
|
1973 |
+
'.$decrypt_block.'
|
1974 |
+
$_plaintext.= $in ^ $_iv;
|
1975 |
+
$_iv = $_block;
|
1976 |
+
}
|
1977 |
+
|
1978 |
+
if ($self->continuousBuffer) {
|
1979 |
+
$self->decryptIV = $_iv;
|
1980 |
+
}
|
1981 |
+
|
1982 |
+
return $self->_unpad($_plaintext);
|
1983 |
+
';
|
1984 |
+
break;
|
1985 |
+
}
|
1986 |
+
|
1987 |
+
// Create the $inline function and return its name as string. Ready to run!
|
1988 |
+
return create_function('$_action, &$self, $_text', $init_crypt . 'if ($_action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }');
|
1989 |
+
}
|
1990 |
+
|
1991 |
+
/**
|
1992 |
+
* Holds the lambda_functions table (classwide)
|
1993 |
+
*
|
1994 |
+
* Each name of the lambda function, created from
|
1995 |
+
* _setupInlineCrypt() && _createInlineCryptFunction()
|
1996 |
+
* is stored, classwide (!), here for reusing.
|
1997 |
+
*
|
1998 |
+
* The string-based index of $function is a classwide
|
1999 |
+
* uniqe value representing, at least, the $mode of
|
2000 |
+
* operation (or more... depends of the optimizing level)
|
2001 |
+
* for which $mode the lambda function was created.
|
2002 |
+
*
|
2003 |
+
* @access private
|
2004 |
+
* @return &Array
|
2005 |
+
*/
|
2006 |
+
function &_getLambdaFunctions()
|
2007 |
+
{
|
2008 |
+
static $functions = array();
|
2009 |
+
return $functions;
|
2010 |
+
}
|
2011 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Blowfish.php
ADDED
@@ -0,0 +1,644 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of Blowfish.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* Useful resources are as follows:
|
11 |
+
*
|
12 |
+
* - {@link http://en.wikipedia.org/wiki/Blowfish_(cipher) Wikipedia description of Blowfish}
|
13 |
+
*
|
14 |
+
* Here's a short example of how to use this library:
|
15 |
+
* <code>
|
16 |
+
* <?php
|
17 |
+
* include 'Crypt/Blowfish.php';
|
18 |
+
*
|
19 |
+
* $blowfish = new Crypt_Blowfish();
|
20 |
+
*
|
21 |
+
* $blowfish->setKey('12345678901234567890123456789012');
|
22 |
+
*
|
23 |
+
* $plaintext = str_repeat('a', 1024);
|
24 |
+
*
|
25 |
+
* echo $blowfish->decrypt($blowfish->encrypt($plaintext));
|
26 |
+
* ?>
|
27 |
+
* </code>
|
28 |
+
*
|
29 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
30 |
+
* of this software and associated documentation files (the "Software"), to deal
|
31 |
+
* in the Software without restriction, including without limitation the rights
|
32 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
33 |
+
* copies of the Software, and to permit persons to whom the Software is
|
34 |
+
* furnished to do so, subject to the following conditions:
|
35 |
+
*
|
36 |
+
* The above copyright notice and this permission notice shall be included in
|
37 |
+
* all copies or substantial portions of the Software.
|
38 |
+
*
|
39 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
40 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
41 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
42 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
43 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
44 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
45 |
+
* THE SOFTWARE.
|
46 |
+
*
|
47 |
+
* @category Crypt
|
48 |
+
* @package Crypt_Blowfish
|
49 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
50 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
51 |
+
* @copyright 2007 Jim Wigginton
|
52 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
53 |
+
* @link http://phpseclib.sourceforge.net
|
54 |
+
*/
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Include Crypt_Base
|
58 |
+
*
|
59 |
+
* Base cipher class
|
60 |
+
*/
|
61 |
+
if (!class_exists('Crypt_Base')) {
|
62 |
+
include_once 'Base.php';
|
63 |
+
}
|
64 |
+
|
65 |
+
/**#@+
|
66 |
+
* @access public
|
67 |
+
* @see Crypt_Blowfish::encrypt()
|
68 |
+
* @see Crypt_Blowfish::decrypt()
|
69 |
+
*/
|
70 |
+
/**
|
71 |
+
* Encrypt / decrypt using the Counter mode.
|
72 |
+
*
|
73 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
74 |
+
*
|
75 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
76 |
+
*/
|
77 |
+
define('CRYPT_BLOWFISH_MODE_CTR', CRYPT_MODE_CTR);
|
78 |
+
/**
|
79 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
80 |
+
*
|
81 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
82 |
+
*/
|
83 |
+
define('CRYPT_BLOWFISH_MODE_ECB', CRYPT_MODE_ECB);
|
84 |
+
/**
|
85 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
86 |
+
*
|
87 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
88 |
+
*/
|
89 |
+
define('CRYPT_BLOWFISH_MODE_CBC', CRYPT_MODE_CBC);
|
90 |
+
/**
|
91 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
92 |
+
*
|
93 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
94 |
+
*/
|
95 |
+
define('CRYPT_BLOWFISH_MODE_CFB', CRYPT_MODE_CFB);
|
96 |
+
/**
|
97 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
98 |
+
*
|
99 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
100 |
+
*/
|
101 |
+
define('CRYPT_BLOWFISH_MODE_OFB', CRYPT_MODE_OFB);
|
102 |
+
/**#@-*/
|
103 |
+
|
104 |
+
/**#@+
|
105 |
+
* @access private
|
106 |
+
* @see Crypt_Base::Crypt_Base()
|
107 |
+
*/
|
108 |
+
/**
|
109 |
+
* Toggles the internal implementation
|
110 |
+
*/
|
111 |
+
define('CRYPT_BLOWFISH_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
112 |
+
/**
|
113 |
+
* Toggles the mcrypt implementation
|
114 |
+
*/
|
115 |
+
define('CRYPT_BLOWFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
116 |
+
/**#@-*/
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Pure-PHP implementation of Blowfish.
|
120 |
+
*
|
121 |
+
* @package Crypt_Blowfish
|
122 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
123 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
124 |
+
* @access public
|
125 |
+
*/
|
126 |
+
class Crypt_Blowfish extends Crypt_Base
|
127 |
+
{
|
128 |
+
/**
|
129 |
+
* Block Length of the cipher
|
130 |
+
*
|
131 |
+
* @see Crypt_Base::block_size
|
132 |
+
* @var Integer
|
133 |
+
* @access private
|
134 |
+
*/
|
135 |
+
var $block_size = 8;
|
136 |
+
|
137 |
+
/**
|
138 |
+
* The default password key_size used by setPassword()
|
139 |
+
*
|
140 |
+
* @see Crypt_Base::password_key_size
|
141 |
+
* @see Crypt_Base::setPassword()
|
142 |
+
* @var Integer
|
143 |
+
* @access private
|
144 |
+
*/
|
145 |
+
var $password_key_size = 56;
|
146 |
+
|
147 |
+
/**
|
148 |
+
* The namespace used by the cipher for its constants.
|
149 |
+
*
|
150 |
+
* @see Crypt_Base::const_namespace
|
151 |
+
* @var String
|
152 |
+
* @access private
|
153 |
+
*/
|
154 |
+
var $const_namespace = 'BLOWFISH';
|
155 |
+
|
156 |
+
/**
|
157 |
+
* The mcrypt specific name of the cipher
|
158 |
+
*
|
159 |
+
* @see Crypt_Base::cipher_name_mcrypt
|
160 |
+
* @var String
|
161 |
+
* @access private
|
162 |
+
*/
|
163 |
+
var $cipher_name_mcrypt = 'blowfish';
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Optimizing value while CFB-encrypting
|
167 |
+
*
|
168 |
+
* @see Crypt_Base::cfb_init_len
|
169 |
+
* @var Integer
|
170 |
+
* @access private
|
171 |
+
*/
|
172 |
+
var $cfb_init_len = 500;
|
173 |
+
|
174 |
+
/**
|
175 |
+
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
|
176 |
+
*
|
177 |
+
* S-Box 1
|
178 |
+
*
|
179 |
+
* @access private
|
180 |
+
* @var array
|
181 |
+
*/
|
182 |
+
var $sbox0 = array (
|
183 |
+
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
|
184 |
+
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
185 |
+
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
|
186 |
+
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
|
187 |
+
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
|
188 |
+
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
|
189 |
+
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
|
190 |
+
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
|
191 |
+
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
|
192 |
+
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
|
193 |
+
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
|
194 |
+
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
|
195 |
+
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
|
196 |
+
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
|
197 |
+
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
|
198 |
+
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
|
199 |
+
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
|
200 |
+
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
|
201 |
+
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
|
202 |
+
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
|
203 |
+
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
|
204 |
+
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
|
205 |
+
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
|
206 |
+
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
|
207 |
+
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
|
208 |
+
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
|
209 |
+
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
|
210 |
+
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
|
211 |
+
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
|
212 |
+
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
|
213 |
+
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
|
214 |
+
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
|
215 |
+
);
|
216 |
+
|
217 |
+
/**
|
218 |
+
* S-Box 1
|
219 |
+
*
|
220 |
+
* @access private
|
221 |
+
* @var array
|
222 |
+
*/
|
223 |
+
var $sbox1 = array(
|
224 |
+
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
|
225 |
+
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
|
226 |
+
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
|
227 |
+
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
|
228 |
+
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
|
229 |
+
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
|
230 |
+
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
|
231 |
+
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
|
232 |
+
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
|
233 |
+
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
|
234 |
+
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
|
235 |
+
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
|
236 |
+
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
|
237 |
+
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
|
238 |
+
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
|
239 |
+
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
|
240 |
+
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
|
241 |
+
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
|
242 |
+
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
|
243 |
+
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
|
244 |
+
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
|
245 |
+
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
|
246 |
+
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
|
247 |
+
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
|
248 |
+
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
|
249 |
+
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
|
250 |
+
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
|
251 |
+
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
|
252 |
+
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
|
253 |
+
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
|
254 |
+
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
|
255 |
+
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
|
256 |
+
);
|
257 |
+
|
258 |
+
/**
|
259 |
+
* S-Box 2
|
260 |
+
*
|
261 |
+
* @access private
|
262 |
+
* @var array
|
263 |
+
*/
|
264 |
+
var $sbox2 = array(
|
265 |
+
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
|
266 |
+
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
|
267 |
+
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
|
268 |
+
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
|
269 |
+
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
|
270 |
+
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
|
271 |
+
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
|
272 |
+
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
|
273 |
+
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
|
274 |
+
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
|
275 |
+
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
|
276 |
+
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
|
277 |
+
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
|
278 |
+
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
|
279 |
+
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
|
280 |
+
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
|
281 |
+
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
|
282 |
+
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
|
283 |
+
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
|
284 |
+
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
|
285 |
+
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
|
286 |
+
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
|
287 |
+
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
|
288 |
+
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
|
289 |
+
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
|
290 |
+
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
|
291 |
+
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
|
292 |
+
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
|
293 |
+
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
|
294 |
+
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
|
295 |
+
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
|
296 |
+
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
|
297 |
+
);
|
298 |
+
|
299 |
+
/**
|
300 |
+
* S-Box 3
|
301 |
+
*
|
302 |
+
* @access private
|
303 |
+
* @var array
|
304 |
+
*/
|
305 |
+
var $sbox3 = array(
|
306 |
+
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
|
307 |
+
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
|
308 |
+
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
|
309 |
+
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
|
310 |
+
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
|
311 |
+
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
|
312 |
+
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
|
313 |
+
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
|
314 |
+
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
|
315 |
+
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
|
316 |
+
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
|
317 |
+
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
|
318 |
+
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
|
319 |
+
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
|
320 |
+
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
|
321 |
+
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
|
322 |
+
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
|
323 |
+
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
|
324 |
+
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
|
325 |
+
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
|
326 |
+
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
|
327 |
+
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
|
328 |
+
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
|
329 |
+
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
|
330 |
+
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
|
331 |
+
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
|
332 |
+
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
|
333 |
+
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
|
334 |
+
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
|
335 |
+
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
|
336 |
+
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
|
337 |
+
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
|
338 |
+
);
|
339 |
+
|
340 |
+
/**
|
341 |
+
* P-Array consists of 18 32-bit subkeys
|
342 |
+
*
|
343 |
+
* @var array $parray
|
344 |
+
* @access private
|
345 |
+
*/
|
346 |
+
var $parray = array(
|
347 |
+
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
|
348 |
+
0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
|
349 |
+
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b
|
350 |
+
);
|
351 |
+
|
352 |
+
/**
|
353 |
+
* The BCTX-working Array
|
354 |
+
*
|
355 |
+
* Holds the expanded key [p] and the key-depended s-boxes [sb]
|
356 |
+
*
|
357 |
+
* @var array $bctx
|
358 |
+
* @access private
|
359 |
+
*/
|
360 |
+
var $bctx;
|
361 |
+
|
362 |
+
/**
|
363 |
+
* Holds the last used key
|
364 |
+
*
|
365 |
+
* @var Array
|
366 |
+
* @access private
|
367 |
+
*/
|
368 |
+
var $kl;
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Sets the key.
|
372 |
+
*
|
373 |
+
* Keys can be of any length. Blowfish, itself, requires the use of a key between 32 and max. 448-bits long.
|
374 |
+
* If the key is less than 32-bits we NOT fill the key to 32bit but let the key as it is to be compatible
|
375 |
+
* with mcrypt because mcrypt act this way with blowfish key's < 32 bits.
|
376 |
+
*
|
377 |
+
* If the key is more than 448-bits, we trim the excess bits.
|
378 |
+
*
|
379 |
+
* If the key is not explicitly set, or empty, it'll be assumed a 128 bits key to be all null bytes.
|
380 |
+
*
|
381 |
+
* @access public
|
382 |
+
* @see Crypt_Base::setKey()
|
383 |
+
* @param String $key
|
384 |
+
*/
|
385 |
+
function setKey($key)
|
386 |
+
{
|
387 |
+
$keylength = strlen($key);
|
388 |
+
|
389 |
+
if (!$keylength) {
|
390 |
+
$key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
391 |
+
} elseif ($keylength > 56) {
|
392 |
+
$key = substr($key, 0, 56);
|
393 |
+
}
|
394 |
+
|
395 |
+
parent::setKey($key);
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Setup the key (expansion)
|
400 |
+
*
|
401 |
+
* @see Crypt_Base::_setupKey()
|
402 |
+
* @access private
|
403 |
+
*/
|
404 |
+
function _setupKey()
|
405 |
+
{
|
406 |
+
if (isset($this->kl['key']) && $this->key === $this->kl['key']) {
|
407 |
+
// already expanded
|
408 |
+
return;
|
409 |
+
}
|
410 |
+
$this->kl = array('key' => $this->key);
|
411 |
+
|
412 |
+
/* key-expanding p[] and S-Box building sb[] */
|
413 |
+
$this->bctx = array(
|
414 |
+
'p' => array(),
|
415 |
+
'sb' => array(
|
416 |
+
$this->sbox0,
|
417 |
+
$this->sbox1,
|
418 |
+
$this->sbox2,
|
419 |
+
$this->sbox3
|
420 |
+
)
|
421 |
+
);
|
422 |
+
|
423 |
+
// unpack binary string in unsigned chars
|
424 |
+
$key = array_values(unpack('C*', $this->key));
|
425 |
+
$keyl = count($key);
|
426 |
+
for ($j = 0, $i = 0; $i < 18; ++$i) {
|
427 |
+
// xor P1 with the first 32-bits of the key, xor P2 with the second 32-bits ...
|
428 |
+
for ($data = 0, $k = 0; $k < 4; ++$k) {
|
429 |
+
$data = ($data << 8) | $key[$j];
|
430 |
+
if (++$j >= $keyl) {
|
431 |
+
$j = 0;
|
432 |
+
}
|
433 |
+
}
|
434 |
+
$this->bctx['p'][] = $this->parray[$i] ^ $data;
|
435 |
+
}
|
436 |
+
|
437 |
+
// encrypt the zero-string, replace P1 and P2 with the encrypted data,
|
438 |
+
// encrypt P3 and P4 with the new P1 and P2, do it with all P-array and subkeys
|
439 |
+
$data = "\0\0\0\0\0\0\0\0";
|
440 |
+
for ($i = 0; $i < 18; $i += 2) {
|
441 |
+
list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data)));
|
442 |
+
$this->bctx['p'][$i ] = $l;
|
443 |
+
$this->bctx['p'][$i + 1] = $r;
|
444 |
+
}
|
445 |
+
for ($i = 0; $i < 4; ++$i) {
|
446 |
+
for ($j = 0; $j < 256; $j += 2) {
|
447 |
+
list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data)));
|
448 |
+
$this->bctx['sb'][$i][$j ] = $l;
|
449 |
+
$this->bctx['sb'][$i][$j + 1] = $r;
|
450 |
+
}
|
451 |
+
}
|
452 |
+
}
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Encrypts a block
|
456 |
+
*
|
457 |
+
* @access private
|
458 |
+
* @param String $in
|
459 |
+
* @return String
|
460 |
+
*/
|
461 |
+
function _encryptBlock($in)
|
462 |
+
{
|
463 |
+
$p = $this->bctx["p"];
|
464 |
+
// extract($this->bctx["sb"], EXTR_PREFIX_ALL, "sb"); // slower
|
465 |
+
$sb_0 = $this->bctx["sb"][0];
|
466 |
+
$sb_1 = $this->bctx["sb"][1];
|
467 |
+
$sb_2 = $this->bctx["sb"][2];
|
468 |
+
$sb_3 = $this->bctx["sb"][3];
|
469 |
+
|
470 |
+
$in = unpack("N*", $in);
|
471 |
+
$l = $in[1];
|
472 |
+
$r = $in[2];
|
473 |
+
|
474 |
+
for ($i = 0; $i < 16; $i+= 2) {
|
475 |
+
$l^= $p[$i];
|
476 |
+
$r^= ($sb_0[$l >> 24 & 0xff] +
|
477 |
+
$sb_1[$l >> 16 & 0xff] ^
|
478 |
+
$sb_2[$l >> 8 & 0xff]) +
|
479 |
+
$sb_3[$l & 0xff];
|
480 |
+
|
481 |
+
$r^= $p[$i + 1];
|
482 |
+
$l^= ($sb_0[$r >> 24 & 0xff] +
|
483 |
+
$sb_1[$r >> 16 & 0xff] ^
|
484 |
+
$sb_2[$r >> 8 & 0xff]) +
|
485 |
+
$sb_3[$r & 0xff];
|
486 |
+
}
|
487 |
+
return pack("N*", $r ^ $p[17], $l ^ $p[16]);
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Decrypts a block
|
492 |
+
*
|
493 |
+
* @access private
|
494 |
+
* @param String $in
|
495 |
+
* @return String
|
496 |
+
*/
|
497 |
+
function _decryptBlock($in)
|
498 |
+
{
|
499 |
+
$p = $this->bctx["p"];
|
500 |
+
$sb_0 = $this->bctx["sb"][0];
|
501 |
+
$sb_1 = $this->bctx["sb"][1];
|
502 |
+
$sb_2 = $this->bctx["sb"][2];
|
503 |
+
$sb_3 = $this->bctx["sb"][3];
|
504 |
+
|
505 |
+
$in = unpack("N*", $in);
|
506 |
+
$l = $in[1];
|
507 |
+
$r = $in[2];
|
508 |
+
|
509 |
+
for ($i = 17; $i > 2; $i-= 2) {
|
510 |
+
$l^= $p[$i];
|
511 |
+
$r^= ($sb_0[$l >> 24 & 0xff] +
|
512 |
+
$sb_1[$l >> 16 & 0xff] ^
|
513 |
+
$sb_2[$l >> 8 & 0xff]) +
|
514 |
+
$sb_3[$l & 0xff];
|
515 |
+
|
516 |
+
$r^= $p[$i - 1];
|
517 |
+
$l^= ($sb_0[$r >> 24 & 0xff] +
|
518 |
+
$sb_1[$r >> 16 & 0xff] ^
|
519 |
+
$sb_2[$r >> 8 & 0xff]) +
|
520 |
+
$sb_3[$r & 0xff];
|
521 |
+
}
|
522 |
+
|
523 |
+
return pack("N*", $r ^ $p[0], $l ^ $p[1]);
|
524 |
+
}
|
525 |
+
|
526 |
+
/**
|
527 |
+
* Setup the performance-optimized function for de/encrypt()
|
528 |
+
*
|
529 |
+
* @see Crypt_Base::_setupInlineCrypt()
|
530 |
+
* @access private
|
531 |
+
*/
|
532 |
+
function _setupInlineCrypt()
|
533 |
+
{
|
534 |
+
$lambda_functions =& Crypt_Blowfish::_getLambdaFunctions();
|
535 |
+
|
536 |
+
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
|
537 |
+
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
|
538 |
+
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10);
|
539 |
+
|
540 |
+
switch (true) {
|
541 |
+
case $gen_hi_opt_code:
|
542 |
+
$code_hash = md5(str_pad("Crypt_Blowfish, {$this->mode}, ", 32, "\0") . $this->key);
|
543 |
+
break;
|
544 |
+
default:
|
545 |
+
$code_hash = "Crypt_Blowfish, {$this->mode}";
|
546 |
+
}
|
547 |
+
|
548 |
+
if (!isset($lambda_functions[$code_hash])) {
|
549 |
+
switch (true) {
|
550 |
+
case $gen_hi_opt_code:
|
551 |
+
$p = $this->bctx['p'];
|
552 |
+
$init_crypt = '
|
553 |
+
static $sb_0, $sb_1, $sb_2, $sb_3;
|
554 |
+
if (!$sb_0) {
|
555 |
+
$sb_0 = $self->bctx["sb"][0];
|
556 |
+
$sb_1 = $self->bctx["sb"][1];
|
557 |
+
$sb_2 = $self->bctx["sb"][2];
|
558 |
+
$sb_3 = $self->bctx["sb"][3];
|
559 |
+
}
|
560 |
+
';
|
561 |
+
break;
|
562 |
+
default:
|
563 |
+
$p = array();
|
564 |
+
for ($i = 0; $i < 18; ++$i) {
|
565 |
+
$p[] = '$p_' . $i;
|
566 |
+
}
|
567 |
+
$init_crypt = '
|
568 |
+
list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"];
|
569 |
+
list(' . implode(',', $p) . ') = $self->bctx["p"];
|
570 |
+
|
571 |
+
';
|
572 |
+
}
|
573 |
+
|
574 |
+
// Generating encrypt code:
|
575 |
+
$encrypt_block = '
|
576 |
+
$in = unpack("N*", $in);
|
577 |
+
$l = $in[1];
|
578 |
+
$r = $in[2];
|
579 |
+
';
|
580 |
+
for ($i = 0; $i < 16; $i+= 2) {
|
581 |
+
$encrypt_block.= '
|
582 |
+
$l^= ' . $p[$i] . ';
|
583 |
+
$r^= ($sb_0[$l >> 24 & 0xff] +
|
584 |
+
$sb_1[$l >> 16 & 0xff] ^
|
585 |
+
$sb_2[$l >> 8 & 0xff]) +
|
586 |
+
$sb_3[$l & 0xff];
|
587 |
+
|
588 |
+
$r^= ' . $p[$i + 1] . ';
|
589 |
+
$l^= ($sb_0[$r >> 24 & 0xff] +
|
590 |
+
$sb_1[$r >> 16 & 0xff] ^
|
591 |
+
$sb_2[$r >> 8 & 0xff]) +
|
592 |
+
$sb_3[$r & 0xff];
|
593 |
+
';
|
594 |
+
}
|
595 |
+
$encrypt_block.= '
|
596 |
+
$in = pack("N*",
|
597 |
+
$r ^ ' . $p[17] . ',
|
598 |
+
$l ^ ' . $p[16] . '
|
599 |
+
);
|
600 |
+
';
|
601 |
+
|
602 |
+
// Generating decrypt code:
|
603 |
+
$decrypt_block = '
|
604 |
+
$in = unpack("N*", $in);
|
605 |
+
$l = $in[1];
|
606 |
+
$r = $in[2];
|
607 |
+
';
|
608 |
+
|
609 |
+
for ($i = 17; $i > 2; $i-= 2) {
|
610 |
+
$decrypt_block.= '
|
611 |
+
$l^= ' . $p[$i] . ';
|
612 |
+
$r^= ($sb_0[$l >> 24 & 0xff] +
|
613 |
+
$sb_1[$l >> 16 & 0xff] ^
|
614 |
+
$sb_2[$l >> 8 & 0xff]) +
|
615 |
+
$sb_3[$l & 0xff];
|
616 |
+
|
617 |
+
$r^= ' . $p[$i - 1] . ';
|
618 |
+
$l^= ($sb_0[$r >> 24 & 0xff] +
|
619 |
+
$sb_1[$r >> 16 & 0xff] ^
|
620 |
+
$sb_2[$r >> 8 & 0xff]) +
|
621 |
+
$sb_3[$r & 0xff];
|
622 |
+
';
|
623 |
+
}
|
624 |
+
|
625 |
+
$decrypt_block.= '
|
626 |
+
$in = pack("N*",
|
627 |
+
$r ^ ' . $p[0] . ',
|
628 |
+
$l ^ ' . $p[1] . '
|
629 |
+
);
|
630 |
+
';
|
631 |
+
|
632 |
+
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
|
633 |
+
array(
|
634 |
+
'init_crypt' => $init_crypt,
|
635 |
+
'init_encrypt' => '',
|
636 |
+
'init_decrypt' => '',
|
637 |
+
'encrypt_block' => $encrypt_block,
|
638 |
+
'decrypt_block' => $decrypt_block
|
639 |
+
)
|
640 |
+
);
|
641 |
+
}
|
642 |
+
$this->inline_crypt = $lambda_functions[$code_hash];
|
643 |
+
}
|
644 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/DES.php
ADDED
@@ -0,0 +1,1506 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of DES.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* Useful resources are as follows:
|
11 |
+
*
|
12 |
+
* - {@link http://en.wikipedia.org/wiki/DES_supplementary_material Wikipedia: DES supplementary material}
|
13 |
+
* - {@link http://www.itl.nist.gov/fipspubs/fip46-2.htm FIPS 46-2 - (DES), Data Encryption Standard}
|
14 |
+
* - {@link http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-DES.html JavaScript DES Example}
|
15 |
+
*
|
16 |
+
* Here's a short example of how to use this library:
|
17 |
+
* <code>
|
18 |
+
* <?php
|
19 |
+
* include 'Crypt/DES.php';
|
20 |
+
*
|
21 |
+
* $des = new Crypt_DES();
|
22 |
+
*
|
23 |
+
* $des->setKey('abcdefgh');
|
24 |
+
*
|
25 |
+
* $size = 10 * 1024;
|
26 |
+
* $plaintext = '';
|
27 |
+
* for ($i = 0; $i < $size; $i++) {
|
28 |
+
* $plaintext.= 'a';
|
29 |
+
* }
|
30 |
+
*
|
31 |
+
* echo $des->decrypt($des->encrypt($plaintext));
|
32 |
+
* ?>
|
33 |
+
* </code>
|
34 |
+
*
|
35 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
36 |
+
* of this software and associated documentation files (the "Software"), to deal
|
37 |
+
* in the Software without restriction, including without limitation the rights
|
38 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
39 |
+
* copies of the Software, and to permit persons to whom the Software is
|
40 |
+
* furnished to do so, subject to the following conditions:
|
41 |
+
*
|
42 |
+
* The above copyright notice and this permission notice shall be included in
|
43 |
+
* all copies or substantial portions of the Software.
|
44 |
+
*
|
45 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
46 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
47 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
48 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
49 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
50 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
51 |
+
* THE SOFTWARE.
|
52 |
+
*
|
53 |
+
* @category Crypt
|
54 |
+
* @package Crypt_DES
|
55 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
56 |
+
* @copyright 2007 Jim Wigginton
|
57 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
58 |
+
* @link http://phpseclib.sourceforge.net
|
59 |
+
*/
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Include Crypt_Base
|
63 |
+
*
|
64 |
+
* Base cipher class
|
65 |
+
*/
|
66 |
+
if (!class_exists('Crypt_Base')) {
|
67 |
+
include_once 'Base.php';
|
68 |
+
}
|
69 |
+
|
70 |
+
/**#@+
|
71 |
+
* @access private
|
72 |
+
* @see Crypt_DES::_setupKey()
|
73 |
+
* @see Crypt_DES::_processBlock()
|
74 |
+
*/
|
75 |
+
/**
|
76 |
+
* Contains $keys[CRYPT_DES_ENCRYPT]
|
77 |
+
*/
|
78 |
+
define('CRYPT_DES_ENCRYPT', 0);
|
79 |
+
/**
|
80 |
+
* Contains $keys[CRYPT_DES_DECRYPT]
|
81 |
+
*/
|
82 |
+
define('CRYPT_DES_DECRYPT', 1);
|
83 |
+
/**#@-*/
|
84 |
+
|
85 |
+
/**#@+
|
86 |
+
* @access public
|
87 |
+
* @see Crypt_DES::encrypt()
|
88 |
+
* @see Crypt_DES::decrypt()
|
89 |
+
*/
|
90 |
+
/**
|
91 |
+
* Encrypt / decrypt using the Counter mode.
|
92 |
+
*
|
93 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
94 |
+
*
|
95 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
96 |
+
*/
|
97 |
+
define('CRYPT_DES_MODE_CTR', CRYPT_MODE_CTR);
|
98 |
+
/**
|
99 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
100 |
+
*
|
101 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
102 |
+
*/
|
103 |
+
define('CRYPT_DES_MODE_ECB', CRYPT_MODE_ECB);
|
104 |
+
/**
|
105 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
106 |
+
*
|
107 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
108 |
+
*/
|
109 |
+
define('CRYPT_DES_MODE_CBC', CRYPT_MODE_CBC);
|
110 |
+
/**
|
111 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
112 |
+
*
|
113 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
114 |
+
*/
|
115 |
+
define('CRYPT_DES_MODE_CFB', CRYPT_MODE_CFB);
|
116 |
+
/**
|
117 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
118 |
+
*
|
119 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
120 |
+
*/
|
121 |
+
define('CRYPT_DES_MODE_OFB', CRYPT_MODE_OFB);
|
122 |
+
/**#@-*/
|
123 |
+
|
124 |
+
/**#@+
|
125 |
+
* @access private
|
126 |
+
* @see Crypt_Base::Crypt_Base()
|
127 |
+
*/
|
128 |
+
/**
|
129 |
+
* Toggles the internal implementation
|
130 |
+
*/
|
131 |
+
define('CRYPT_DES_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
132 |
+
/**
|
133 |
+
* Toggles the mcrypt implementation
|
134 |
+
*/
|
135 |
+
define('CRYPT_DES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
136 |
+
/**#@-*/
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Pure-PHP implementation of DES.
|
140 |
+
*
|
141 |
+
* @package Crypt_DES
|
142 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
143 |
+
* @access public
|
144 |
+
*/
|
145 |
+
class Crypt_DES extends Crypt_Base
|
146 |
+
{
|
147 |
+
/**
|
148 |
+
* Block Length of the cipher
|
149 |
+
*
|
150 |
+
* @see Crypt_Base::block_size
|
151 |
+
* @var Integer
|
152 |
+
* @access private
|
153 |
+
*/
|
154 |
+
var $block_size = 8;
|
155 |
+
|
156 |
+
/**
|
157 |
+
* The Key
|
158 |
+
*
|
159 |
+
* @see Crypt_Base::key
|
160 |
+
* @see setKey()
|
161 |
+
* @var String
|
162 |
+
* @access private
|
163 |
+
*/
|
164 |
+
var $key = "\0\0\0\0\0\0\0\0";
|
165 |
+
|
166 |
+
/**
|
167 |
+
* The default password key_size used by setPassword()
|
168 |
+
*
|
169 |
+
* @see Crypt_Base::password_key_size
|
170 |
+
* @see Crypt_Base::setPassword()
|
171 |
+
* @var Integer
|
172 |
+
* @access private
|
173 |
+
*/
|
174 |
+
var $password_key_size = 8;
|
175 |
+
|
176 |
+
/**
|
177 |
+
* The namespace used by the cipher for its constants.
|
178 |
+
*
|
179 |
+
* @see Crypt_Base::const_namespace
|
180 |
+
* @var String
|
181 |
+
* @access private
|
182 |
+
*/
|
183 |
+
var $const_namespace = 'DES';
|
184 |
+
|
185 |
+
/**
|
186 |
+
* The mcrypt specific name of the cipher
|
187 |
+
*
|
188 |
+
* @see Crypt_Base::cipher_name_mcrypt
|
189 |
+
* @var String
|
190 |
+
* @access private
|
191 |
+
*/
|
192 |
+
var $cipher_name_mcrypt = 'des';
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Optimizing value while CFB-encrypting
|
196 |
+
*
|
197 |
+
* @see Crypt_Base::cfb_init_len
|
198 |
+
* @var Integer
|
199 |
+
* @access private
|
200 |
+
*/
|
201 |
+
var $cfb_init_len = 500;
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Switch for DES/3DES encryption
|
205 |
+
*
|
206 |
+
* Used only if $engine == CRYPT_DES_MODE_INTERNAL
|
207 |
+
*
|
208 |
+
* @see Crypt_DES::_setupKey()
|
209 |
+
* @see Crypt_DES::_processBlock()
|
210 |
+
* @var Integer
|
211 |
+
* @access private
|
212 |
+
*/
|
213 |
+
var $des_rounds = 1;
|
214 |
+
|
215 |
+
/**
|
216 |
+
* max possible size of $key
|
217 |
+
*
|
218 |
+
* @see Crypt_DES::setKey()
|
219 |
+
* @var String
|
220 |
+
* @access private
|
221 |
+
*/
|
222 |
+
var $key_size_max = 8;
|
223 |
+
|
224 |
+
/**
|
225 |
+
* The Key Schedule
|
226 |
+
*
|
227 |
+
* @see Crypt_DES::_setupKey()
|
228 |
+
* @var Array
|
229 |
+
* @access private
|
230 |
+
*/
|
231 |
+
var $keys;
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Shuffle table.
|
235 |
+
*
|
236 |
+
* For each byte value index, the entry holds an 8-byte string
|
237 |
+
* with each byte containing all bits in the same state as the
|
238 |
+
* corresponding bit in the index value.
|
239 |
+
*
|
240 |
+
* @see Crypt_DES::_processBlock()
|
241 |
+
* @see Crypt_DES::_setupKey()
|
242 |
+
* @var Array
|
243 |
+
* @access private
|
244 |
+
*/
|
245 |
+
var $shuffle = array(
|
246 |
+
"\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\xFF",
|
247 |
+
"\x00\x00\x00\x00\x00\x00\xFF\x00", "\x00\x00\x00\x00\x00\x00\xFF\xFF",
|
248 |
+
"\x00\x00\x00\x00\x00\xFF\x00\x00", "\x00\x00\x00\x00\x00\xFF\x00\xFF",
|
249 |
+
"\x00\x00\x00\x00\x00\xFF\xFF\x00", "\x00\x00\x00\x00\x00\xFF\xFF\xFF",
|
250 |
+
"\x00\x00\x00\x00\xFF\x00\x00\x00", "\x00\x00\x00\x00\xFF\x00\x00\xFF",
|
251 |
+
"\x00\x00\x00\x00\xFF\x00\xFF\x00", "\x00\x00\x00\x00\xFF\x00\xFF\xFF",
|
252 |
+
"\x00\x00\x00\x00\xFF\xFF\x00\x00", "\x00\x00\x00\x00\xFF\xFF\x00\xFF",
|
253 |
+
"\x00\x00\x00\x00\xFF\xFF\xFF\x00", "\x00\x00\x00\x00\xFF\xFF\xFF\xFF",
|
254 |
+
"\x00\x00\x00\xFF\x00\x00\x00\x00", "\x00\x00\x00\xFF\x00\x00\x00\xFF",
|
255 |
+
"\x00\x00\x00\xFF\x00\x00\xFF\x00", "\x00\x00\x00\xFF\x00\x00\xFF\xFF",
|
256 |
+
"\x00\x00\x00\xFF\x00\xFF\x00\x00", "\x00\x00\x00\xFF\x00\xFF\x00\xFF",
|
257 |
+
"\x00\x00\x00\xFF\x00\xFF\xFF\x00", "\x00\x00\x00\xFF\x00\xFF\xFF\xFF",
|
258 |
+
"\x00\x00\x00\xFF\xFF\x00\x00\x00", "\x00\x00\x00\xFF\xFF\x00\x00\xFF",
|
259 |
+
"\x00\x00\x00\xFF\xFF\x00\xFF\x00", "\x00\x00\x00\xFF\xFF\x00\xFF\xFF",
|
260 |
+
"\x00\x00\x00\xFF\xFF\xFF\x00\x00", "\x00\x00\x00\xFF\xFF\xFF\x00\xFF",
|
261 |
+
"\x00\x00\x00\xFF\xFF\xFF\xFF\x00", "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF",
|
262 |
+
"\x00\x00\xFF\x00\x00\x00\x00\x00", "\x00\x00\xFF\x00\x00\x00\x00\xFF",
|
263 |
+
"\x00\x00\xFF\x00\x00\x00\xFF\x00", "\x00\x00\xFF\x00\x00\x00\xFF\xFF",
|
264 |
+
"\x00\x00\xFF\x00\x00\xFF\x00\x00", "\x00\x00\xFF\x00\x00\xFF\x00\xFF",
|
265 |
+
"\x00\x00\xFF\x00\x00\xFF\xFF\x00", "\x00\x00\xFF\x00\x00\xFF\xFF\xFF",
|
266 |
+
"\x00\x00\xFF\x00\xFF\x00\x00\x00", "\x00\x00\xFF\x00\xFF\x00\x00\xFF",
|
267 |
+
"\x00\x00\xFF\x00\xFF\x00\xFF\x00", "\x00\x00\xFF\x00\xFF\x00\xFF\xFF",
|
268 |
+
"\x00\x00\xFF\x00\xFF\xFF\x00\x00", "\x00\x00\xFF\x00\xFF\xFF\x00\xFF",
|
269 |
+
"\x00\x00\xFF\x00\xFF\xFF\xFF\x00", "\x00\x00\xFF\x00\xFF\xFF\xFF\xFF",
|
270 |
+
"\x00\x00\xFF\xFF\x00\x00\x00\x00", "\x00\x00\xFF\xFF\x00\x00\x00\xFF",
|
271 |
+
"\x00\x00\xFF\xFF\x00\x00\xFF\x00", "\x00\x00\xFF\xFF\x00\x00\xFF\xFF",
|
272 |
+
"\x00\x00\xFF\xFF\x00\xFF\x00\x00", "\x00\x00\xFF\xFF\x00\xFF\x00\xFF",
|
273 |
+
"\x00\x00\xFF\xFF\x00\xFF\xFF\x00", "\x00\x00\xFF\xFF\x00\xFF\xFF\xFF",
|
274 |
+
"\x00\x00\xFF\xFF\xFF\x00\x00\x00", "\x00\x00\xFF\xFF\xFF\x00\x00\xFF",
|
275 |
+
"\x00\x00\xFF\xFF\xFF\x00\xFF\x00", "\x00\x00\xFF\xFF\xFF\x00\xFF\xFF",
|
276 |
+
"\x00\x00\xFF\xFF\xFF\xFF\x00\x00", "\x00\x00\xFF\xFF\xFF\xFF\x00\xFF",
|
277 |
+
"\x00\x00\xFF\xFF\xFF\xFF\xFF\x00", "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF",
|
278 |
+
"\x00\xFF\x00\x00\x00\x00\x00\x00", "\x00\xFF\x00\x00\x00\x00\x00\xFF",
|
279 |
+
"\x00\xFF\x00\x00\x00\x00\xFF\x00", "\x00\xFF\x00\x00\x00\x00\xFF\xFF",
|
280 |
+
"\x00\xFF\x00\x00\x00\xFF\x00\x00", "\x00\xFF\x00\x00\x00\xFF\x00\xFF",
|
281 |
+
"\x00\xFF\x00\x00\x00\xFF\xFF\x00", "\x00\xFF\x00\x00\x00\xFF\xFF\xFF",
|
282 |
+
"\x00\xFF\x00\x00\xFF\x00\x00\x00", "\x00\xFF\x00\x00\xFF\x00\x00\xFF",
|
283 |
+
"\x00\xFF\x00\x00\xFF\x00\xFF\x00", "\x00\xFF\x00\x00\xFF\x00\xFF\xFF",
|
284 |
+
"\x00\xFF\x00\x00\xFF\xFF\x00\x00", "\x00\xFF\x00\x00\xFF\xFF\x00\xFF",
|
285 |
+
"\x00\xFF\x00\x00\xFF\xFF\xFF\x00", "\x00\xFF\x00\x00\xFF\xFF\xFF\xFF",
|
286 |
+
"\x00\xFF\x00\xFF\x00\x00\x00\x00", "\x00\xFF\x00\xFF\x00\x00\x00\xFF",
|
287 |
+
"\x00\xFF\x00\xFF\x00\x00\xFF\x00", "\x00\xFF\x00\xFF\x00\x00\xFF\xFF",
|
288 |
+
"\x00\xFF\x00\xFF\x00\xFF\x00\x00", "\x00\xFF\x00\xFF\x00\xFF\x00\xFF",
|
289 |
+
"\x00\xFF\x00\xFF\x00\xFF\xFF\x00", "\x00\xFF\x00\xFF\x00\xFF\xFF\xFF",
|
290 |
+
"\x00\xFF\x00\xFF\xFF\x00\x00\x00", "\x00\xFF\x00\xFF\xFF\x00\x00\xFF",
|
291 |
+
"\x00\xFF\x00\xFF\xFF\x00\xFF\x00", "\x00\xFF\x00\xFF\xFF\x00\xFF\xFF",
|
292 |
+
"\x00\xFF\x00\xFF\xFF\xFF\x00\x00", "\x00\xFF\x00\xFF\xFF\xFF\x00\xFF",
|
293 |
+
"\x00\xFF\x00\xFF\xFF\xFF\xFF\x00", "\x00\xFF\x00\xFF\xFF\xFF\xFF\xFF",
|
294 |
+
"\x00\xFF\xFF\x00\x00\x00\x00\x00", "\x00\xFF\xFF\x00\x00\x00\x00\xFF",
|
295 |
+
"\x00\xFF\xFF\x00\x00\x00\xFF\x00", "\x00\xFF\xFF\x00\x00\x00\xFF\xFF",
|
296 |
+
"\x00\xFF\xFF\x00\x00\xFF\x00\x00", "\x00\xFF\xFF\x00\x00\xFF\x00\xFF",
|
297 |
+
"\x00\xFF\xFF\x00\x00\xFF\xFF\x00", "\x00\xFF\xFF\x00\x00\xFF\xFF\xFF",
|
298 |
+
"\x00\xFF\xFF\x00\xFF\x00\x00\x00", "\x00\xFF\xFF\x00\xFF\x00\x00\xFF",
|
299 |
+
"\x00\xFF\xFF\x00\xFF\x00\xFF\x00", "\x00\xFF\xFF\x00\xFF\x00\xFF\xFF",
|
300 |
+
"\x00\xFF\xFF\x00\xFF\xFF\x00\x00", "\x00\xFF\xFF\x00\xFF\xFF\x00\xFF",
|
301 |
+
"\x00\xFF\xFF\x00\xFF\xFF\xFF\x00", "\x00\xFF\xFF\x00\xFF\xFF\xFF\xFF",
|
302 |
+
"\x00\xFF\xFF\xFF\x00\x00\x00\x00", "\x00\xFF\xFF\xFF\x00\x00\x00\xFF",
|
303 |
+
"\x00\xFF\xFF\xFF\x00\x00\xFF\x00", "\x00\xFF\xFF\xFF\x00\x00\xFF\xFF",
|
304 |
+
"\x00\xFF\xFF\xFF\x00\xFF\x00\x00", "\x00\xFF\xFF\xFF\x00\xFF\x00\xFF",
|
305 |
+
"\x00\xFF\xFF\xFF\x00\xFF\xFF\x00", "\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF",
|
306 |
+
"\x00\xFF\xFF\xFF\xFF\x00\x00\x00", "\x00\xFF\xFF\xFF\xFF\x00\x00\xFF",
|
307 |
+
"\x00\xFF\xFF\xFF\xFF\x00\xFF\x00", "\x00\xFF\xFF\xFF\xFF\x00\xFF\xFF",
|
308 |
+
"\x00\xFF\xFF\xFF\xFF\xFF\x00\x00", "\x00\xFF\xFF\xFF\xFF\xFF\x00\xFF",
|
309 |
+
"\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
|
310 |
+
"\xFF\x00\x00\x00\x00\x00\x00\x00", "\xFF\x00\x00\x00\x00\x00\x00\xFF",
|
311 |
+
"\xFF\x00\x00\x00\x00\x00\xFF\x00", "\xFF\x00\x00\x00\x00\x00\xFF\xFF",
|
312 |
+
"\xFF\x00\x00\x00\x00\xFF\x00\x00", "\xFF\x00\x00\x00\x00\xFF\x00\xFF",
|
313 |
+
"\xFF\x00\x00\x00\x00\xFF\xFF\x00", "\xFF\x00\x00\x00\x00\xFF\xFF\xFF",
|
314 |
+
"\xFF\x00\x00\x00\xFF\x00\x00\x00", "\xFF\x00\x00\x00\xFF\x00\x00\xFF",
|
315 |
+
"\xFF\x00\x00\x00\xFF\x00\xFF\x00", "\xFF\x00\x00\x00\xFF\x00\xFF\xFF",
|
316 |
+
"\xFF\x00\x00\x00\xFF\xFF\x00\x00", "\xFF\x00\x00\x00\xFF\xFF\x00\xFF",
|
317 |
+
"\xFF\x00\x00\x00\xFF\xFF\xFF\x00", "\xFF\x00\x00\x00\xFF\xFF\xFF\xFF",
|
318 |
+
"\xFF\x00\x00\xFF\x00\x00\x00\x00", "\xFF\x00\x00\xFF\x00\x00\x00\xFF",
|
319 |
+
"\xFF\x00\x00\xFF\x00\x00\xFF\x00", "\xFF\x00\x00\xFF\x00\x00\xFF\xFF",
|
320 |
+
"\xFF\x00\x00\xFF\x00\xFF\x00\x00", "\xFF\x00\x00\xFF\x00\xFF\x00\xFF",
|
321 |
+
"\xFF\x00\x00\xFF\x00\xFF\xFF\x00", "\xFF\x00\x00\xFF\x00\xFF\xFF\xFF",
|
322 |
+
"\xFF\x00\x00\xFF\xFF\x00\x00\x00", "\xFF\x00\x00\xFF\xFF\x00\x00\xFF",
|
323 |
+
"\xFF\x00\x00\xFF\xFF\x00\xFF\x00", "\xFF\x00\x00\xFF\xFF\x00\xFF\xFF",
|
324 |
+
"\xFF\x00\x00\xFF\xFF\xFF\x00\x00", "\xFF\x00\x00\xFF\xFF\xFF\x00\xFF",
|
325 |
+
"\xFF\x00\x00\xFF\xFF\xFF\xFF\x00", "\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF",
|
326 |
+
"\xFF\x00\xFF\x00\x00\x00\x00\x00", "\xFF\x00\xFF\x00\x00\x00\x00\xFF",
|
327 |
+
"\xFF\x00\xFF\x00\x00\x00\xFF\x00", "\xFF\x00\xFF\x00\x00\x00\xFF\xFF",
|
328 |
+
"\xFF\x00\xFF\x00\x00\xFF\x00\x00", "\xFF\x00\xFF\x00\x00\xFF\x00\xFF",
|
329 |
+
"\xFF\x00\xFF\x00\x00\xFF\xFF\x00", "\xFF\x00\xFF\x00\x00\xFF\xFF\xFF",
|
330 |
+
"\xFF\x00\xFF\x00\xFF\x00\x00\x00", "\xFF\x00\xFF\x00\xFF\x00\x00\xFF",
|
331 |
+
"\xFF\x00\xFF\x00\xFF\x00\xFF\x00", "\xFF\x00\xFF\x00\xFF\x00\xFF\xFF",
|
332 |
+
"\xFF\x00\xFF\x00\xFF\xFF\x00\x00", "\xFF\x00\xFF\x00\xFF\xFF\x00\xFF",
|
333 |
+
"\xFF\x00\xFF\x00\xFF\xFF\xFF\x00", "\xFF\x00\xFF\x00\xFF\xFF\xFF\xFF",
|
334 |
+
"\xFF\x00\xFF\xFF\x00\x00\x00\x00", "\xFF\x00\xFF\xFF\x00\x00\x00\xFF",
|
335 |
+
"\xFF\x00\xFF\xFF\x00\x00\xFF\x00", "\xFF\x00\xFF\xFF\x00\x00\xFF\xFF",
|
336 |
+
"\xFF\x00\xFF\xFF\x00\xFF\x00\x00", "\xFF\x00\xFF\xFF\x00\xFF\x00\xFF",
|
337 |
+
"\xFF\x00\xFF\xFF\x00\xFF\xFF\x00", "\xFF\x00\xFF\xFF\x00\xFF\xFF\xFF",
|
338 |
+
"\xFF\x00\xFF\xFF\xFF\x00\x00\x00", "\xFF\x00\xFF\xFF\xFF\x00\x00\xFF",
|
339 |
+
"\xFF\x00\xFF\xFF\xFF\x00\xFF\x00", "\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF",
|
340 |
+
"\xFF\x00\xFF\xFF\xFF\xFF\x00\x00", "\xFF\x00\xFF\xFF\xFF\xFF\x00\xFF",
|
341 |
+
"\xFF\x00\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF",
|
342 |
+
"\xFF\xFF\x00\x00\x00\x00\x00\x00", "\xFF\xFF\x00\x00\x00\x00\x00\xFF",
|
343 |
+
"\xFF\xFF\x00\x00\x00\x00\xFF\x00", "\xFF\xFF\x00\x00\x00\x00\xFF\xFF",
|
344 |
+
"\xFF\xFF\x00\x00\x00\xFF\x00\x00", "\xFF\xFF\x00\x00\x00\xFF\x00\xFF",
|
345 |
+
"\xFF\xFF\x00\x00\x00\xFF\xFF\x00", "\xFF\xFF\x00\x00\x00\xFF\xFF\xFF",
|
346 |
+
"\xFF\xFF\x00\x00\xFF\x00\x00\x00", "\xFF\xFF\x00\x00\xFF\x00\x00\xFF",
|
347 |
+
"\xFF\xFF\x00\x00\xFF\x00\xFF\x00", "\xFF\xFF\x00\x00\xFF\x00\xFF\xFF",
|
348 |
+
"\xFF\xFF\x00\x00\xFF\xFF\x00\x00", "\xFF\xFF\x00\x00\xFF\xFF\x00\xFF",
|
349 |
+
"\xFF\xFF\x00\x00\xFF\xFF\xFF\x00", "\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF",
|
350 |
+
"\xFF\xFF\x00\xFF\x00\x00\x00\x00", "\xFF\xFF\x00\xFF\x00\x00\x00\xFF",
|
351 |
+
"\xFF\xFF\x00\xFF\x00\x00\xFF\x00", "\xFF\xFF\x00\xFF\x00\x00\xFF\xFF",
|
352 |
+
"\xFF\xFF\x00\xFF\x00\xFF\x00\x00", "\xFF\xFF\x00\xFF\x00\xFF\x00\xFF",
|
353 |
+
"\xFF\xFF\x00\xFF\x00\xFF\xFF\x00", "\xFF\xFF\x00\xFF\x00\xFF\xFF\xFF",
|
354 |
+
"\xFF\xFF\x00\xFF\xFF\x00\x00\x00", "\xFF\xFF\x00\xFF\xFF\x00\x00\xFF",
|
355 |
+
"\xFF\xFF\x00\xFF\xFF\x00\xFF\x00", "\xFF\xFF\x00\xFF\xFF\x00\xFF\xFF",
|
356 |
+
"\xFF\xFF\x00\xFF\xFF\xFF\x00\x00", "\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF",
|
357 |
+
"\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF",
|
358 |
+
"\xFF\xFF\xFF\x00\x00\x00\x00\x00", "\xFF\xFF\xFF\x00\x00\x00\x00\xFF",
|
359 |
+
"\xFF\xFF\xFF\x00\x00\x00\xFF\x00", "\xFF\xFF\xFF\x00\x00\x00\xFF\xFF",
|
360 |
+
"\xFF\xFF\xFF\x00\x00\xFF\x00\x00", "\xFF\xFF\xFF\x00\x00\xFF\x00\xFF",
|
361 |
+
"\xFF\xFF\xFF\x00\x00\xFF\xFF\x00", "\xFF\xFF\xFF\x00\x00\xFF\xFF\xFF",
|
362 |
+
"\xFF\xFF\xFF\x00\xFF\x00\x00\x00", "\xFF\xFF\xFF\x00\xFF\x00\x00\xFF",
|
363 |
+
"\xFF\xFF\xFF\x00\xFF\x00\xFF\x00", "\xFF\xFF\xFF\x00\xFF\x00\xFF\xFF",
|
364 |
+
"\xFF\xFF\xFF\x00\xFF\xFF\x00\x00", "\xFF\xFF\xFF\x00\xFF\xFF\x00\xFF",
|
365 |
+
"\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF",
|
366 |
+
"\xFF\xFF\xFF\xFF\x00\x00\x00\x00", "\xFF\xFF\xFF\xFF\x00\x00\x00\xFF",
|
367 |
+
"\xFF\xFF\xFF\xFF\x00\x00\xFF\x00", "\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF",
|
368 |
+
"\xFF\xFF\xFF\xFF\x00\xFF\x00\x00", "\xFF\xFF\xFF\xFF\x00\xFF\x00\xFF",
|
369 |
+
"\xFF\xFF\xFF\xFF\x00\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF",
|
370 |
+
"\xFF\xFF\xFF\xFF\xFF\x00\x00\x00", "\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF",
|
371 |
+
"\xFF\xFF\xFF\xFF\xFF\x00\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF",
|
372 |
+
"\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF",
|
373 |
+
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
|
374 |
+
);
|
375 |
+
|
376 |
+
/**
|
377 |
+
* IP mapping helper table.
|
378 |
+
*
|
379 |
+
* Indexing this table with each source byte performs the initial bit permutation.
|
380 |
+
*
|
381 |
+
* @var Array
|
382 |
+
* @access private
|
383 |
+
*/
|
384 |
+
var $ipmap = array(
|
385 |
+
0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31,
|
386 |
+
0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33,
|
387 |
+
0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71,
|
388 |
+
0x42, 0x52, 0x43, 0x53, 0x62, 0x72, 0x63, 0x73,
|
389 |
+
0x04, 0x14, 0x05, 0x15, 0x24, 0x34, 0x25, 0x35,
|
390 |
+
0x06, 0x16, 0x07, 0x17, 0x26, 0x36, 0x27, 0x37,
|
391 |
+
0x44, 0x54, 0x45, 0x55, 0x64, 0x74, 0x65, 0x75,
|
392 |
+
0x46, 0x56, 0x47, 0x57, 0x66, 0x76, 0x67, 0x77,
|
393 |
+
0x80, 0x90, 0x81, 0x91, 0xA0, 0xB0, 0xA1, 0xB1,
|
394 |
+
0x82, 0x92, 0x83, 0x93, 0xA2, 0xB2, 0xA3, 0xB3,
|
395 |
+
0xC0, 0xD0, 0xC1, 0xD1, 0xE0, 0xF0, 0xE1, 0xF1,
|
396 |
+
0xC2, 0xD2, 0xC3, 0xD3, 0xE2, 0xF2, 0xE3, 0xF3,
|
397 |
+
0x84, 0x94, 0x85, 0x95, 0xA4, 0xB4, 0xA5, 0xB5,
|
398 |
+
0x86, 0x96, 0x87, 0x97, 0xA6, 0xB6, 0xA7, 0xB7,
|
399 |
+
0xC4, 0xD4, 0xC5, 0xD5, 0xE4, 0xF4, 0xE5, 0xF5,
|
400 |
+
0xC6, 0xD6, 0xC7, 0xD7, 0xE6, 0xF6, 0xE7, 0xF7,
|
401 |
+
0x08, 0x18, 0x09, 0x19, 0x28, 0x38, 0x29, 0x39,
|
402 |
+
0x0A, 0x1A, 0x0B, 0x1B, 0x2A, 0x3A, 0x2B, 0x3B,
|
403 |
+
0x48, 0x58, 0x49, 0x59, 0x68, 0x78, 0x69, 0x79,
|
404 |
+
0x4A, 0x5A, 0x4B, 0x5B, 0x6A, 0x7A, 0x6B, 0x7B,
|
405 |
+
0x0C, 0x1C, 0x0D, 0x1D, 0x2C, 0x3C, 0x2D, 0x3D,
|
406 |
+
0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F,
|
407 |
+
0x4C, 0x5C, 0x4D, 0x5D, 0x6C, 0x7C, 0x6D, 0x7D,
|
408 |
+
0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F,
|
409 |
+
0x88, 0x98, 0x89, 0x99, 0xA8, 0xB8, 0xA9, 0xB9,
|
410 |
+
0x8A, 0x9A, 0x8B, 0x9B, 0xAA, 0xBA, 0xAB, 0xBB,
|
411 |
+
0xC8, 0xD8, 0xC9, 0xD9, 0xE8, 0xF8, 0xE9, 0xF9,
|
412 |
+
0xCA, 0xDA, 0xCB, 0xDB, 0xEA, 0xFA, 0xEB, 0xFB,
|
413 |
+
0x8C, 0x9C, 0x8D, 0x9D, 0xAC, 0xBC, 0xAD, 0xBD,
|
414 |
+
0x8E, 0x9E, 0x8F, 0x9F, 0xAE, 0xBE, 0xAF, 0xBF,
|
415 |
+
0xCC, 0xDC, 0xCD, 0xDD, 0xEC, 0xFC, 0xED, 0xFD,
|
416 |
+
0xCE, 0xDE, 0xCF, 0xDF, 0xEE, 0xFE, 0xEF, 0xFF
|
417 |
+
);
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Inverse IP mapping helper table.
|
421 |
+
* Indexing this table with a byte value reverses the bit order.
|
422 |
+
*
|
423 |
+
* @var Array
|
424 |
+
* @access private
|
425 |
+
*/
|
426 |
+
var $invipmap = array(
|
427 |
+
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
428 |
+
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
429 |
+
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
430 |
+
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
431 |
+
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
|
432 |
+
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
433 |
+
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
|
434 |
+
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
435 |
+
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
|
436 |
+
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
437 |
+
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
|
438 |
+
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
439 |
+
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
|
440 |
+
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
441 |
+
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
|
442 |
+
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
443 |
+
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
|
444 |
+
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
445 |
+
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
|
446 |
+
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
447 |
+
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
|
448 |
+
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
449 |
+
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
|
450 |
+
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
451 |
+
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
|
452 |
+
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
453 |
+
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
|
454 |
+
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
455 |
+
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
|
456 |
+
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
457 |
+
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
|
458 |
+
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
459 |
+
);
|
460 |
+
|
461 |
+
/**
|
462 |
+
* Pre-permuted S-box1
|
463 |
+
*
|
464 |
+
* Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the
|
465 |
+
* P table: concatenation can then be replaced by exclusive ORs.
|
466 |
+
*
|
467 |
+
* @var Array
|
468 |
+
* @access private
|
469 |
+
*/
|
470 |
+
var $sbox1 = array(
|
471 |
+
0x00808200, 0x00000000, 0x00008000, 0x00808202,
|
472 |
+
0x00808002, 0x00008202, 0x00000002, 0x00008000,
|
473 |
+
0x00000200, 0x00808200, 0x00808202, 0x00000200,
|
474 |
+
0x00800202, 0x00808002, 0x00800000, 0x00000002,
|
475 |
+
0x00000202, 0x00800200, 0x00800200, 0x00008200,
|
476 |
+
0x00008200, 0x00808000, 0x00808000, 0x00800202,
|
477 |
+
0x00008002, 0x00800002, 0x00800002, 0x00008002,
|
478 |
+
0x00000000, 0x00000202, 0x00008202, 0x00800000,
|
479 |
+
0x00008000, 0x00808202, 0x00000002, 0x00808000,
|
480 |
+
0x00808200, 0x00800000, 0x00800000, 0x00000200,
|
481 |
+
0x00808002, 0x00008000, 0x00008200, 0x00800002,
|
482 |
+
0x00000200, 0x00000002, 0x00800202, 0x00008202,
|
483 |
+
0x00808202, 0x00008002, 0x00808000, 0x00800202,
|
484 |
+
0x00800002, 0x00000202, 0x00008202, 0x00808200,
|
485 |
+
0x00000202, 0x00800200, 0x00800200, 0x00000000,
|
486 |
+
0x00008002, 0x00008200, 0x00000000, 0x00808002
|
487 |
+
);
|
488 |
+
|
489 |
+
/**
|
490 |
+
* Pre-permuted S-box2
|
491 |
+
*
|
492 |
+
* @var Array
|
493 |
+
* @access private
|
494 |
+
*/
|
495 |
+
var $sbox2 = array(
|
496 |
+
0x40084010, 0x40004000, 0x00004000, 0x00084010,
|
497 |
+
0x00080000, 0x00000010, 0x40080010, 0x40004010,
|
498 |
+
0x40000010, 0x40084010, 0x40084000, 0x40000000,
|
499 |
+
0x40004000, 0x00080000, 0x00000010, 0x40080010,
|
500 |
+
0x00084000, 0x00080010, 0x40004010, 0x00000000,
|
501 |
+
0x40000000, 0x00004000, 0x00084010, 0x40080000,
|
502 |
+
0x00080010, 0x40000010, 0x00000000, 0x00084000,
|
503 |
+
0x00004010, 0x40084000, 0x40080000, 0x00004010,
|
504 |
+
0x00000000, 0x00084010, 0x40080010, 0x00080000,
|
505 |
+
0x40004010, 0x40080000, 0x40084000, 0x00004000,
|
506 |
+
0x40080000, 0x40004000, 0x00000010, 0x40084010,
|
507 |
+
0x00084010, 0x00000010, 0x00004000, 0x40000000,
|
508 |
+
0x00004010, 0x40084000, 0x00080000, 0x40000010,
|
509 |
+
0x00080010, 0x40004010, 0x40000010, 0x00080010,
|
510 |
+
0x00084000, 0x00000000, 0x40004000, 0x00004010,
|
511 |
+
0x40000000, 0x40080010, 0x40084010, 0x00084000
|
512 |
+
);
|
513 |
+
|
514 |
+
/**
|
515 |
+
* Pre-permuted S-box3
|
516 |
+
*
|
517 |
+
* @var Array
|
518 |
+
* @access private
|
519 |
+
*/
|
520 |
+
var $sbox3 = array(
|
521 |
+
0x00000104, 0x04010100, 0x00000000, 0x04010004,
|
522 |
+
0x04000100, 0x00000000, 0x00010104, 0x04000100,
|
523 |
+
0x00010004, 0x04000004, 0x04000004, 0x00010000,
|
524 |
+
0x04010104, 0x00010004, 0x04010000, 0x00000104,
|
525 |
+
0x04000000, 0x00000004, 0x04010100, 0x00000100,
|
526 |
+
0x00010100, 0x04010000, 0x04010004, 0x00010104,
|
527 |
+
0x04000104, 0x00010100, 0x00010000, 0x04000104,
|
528 |
+
0x00000004, 0x04010104, 0x00000100, 0x04000000,
|
529 |
+
0x04010100, 0x04000000, 0x00010004, 0x00000104,
|
530 |
+
0x00010000, 0x04010100, 0x04000100, 0x00000000,
|
531 |
+
0x00000100, 0x00010004, 0x04010104, 0x04000100,
|
532 |
+
0x04000004, 0x00000100, 0x00000000, 0x04010004,
|
533 |
+
0x04000104, 0x00010000, 0x04000000, 0x04010104,
|
534 |
+
0x00000004, 0x00010104, 0x00010100, 0x04000004,
|
535 |
+
0x04010000, 0x04000104, 0x00000104, 0x04010000,
|
536 |
+
0x00010104, 0x00000004, 0x04010004, 0x00010100
|
537 |
+
);
|
538 |
+
|
539 |
+
/**
|
540 |
+
* Pre-permuted S-box4
|
541 |
+
*
|
542 |
+
* @var Array
|
543 |
+
* @access private
|
544 |
+
*/
|
545 |
+
var $sbox4 = array(
|
546 |
+
0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
547 |
+
0x00401040, 0x80400040, 0x80400000, 0x80001000,
|
548 |
+
0x00000000, 0x00401000, 0x00401000, 0x80401040,
|
549 |
+
0x80000040, 0x00000000, 0x00400040, 0x80400000,
|
550 |
+
0x80000000, 0x00001000, 0x00400000, 0x80401000,
|
551 |
+
0x00000040, 0x00400000, 0x80001000, 0x00001040,
|
552 |
+
0x80400040, 0x80000000, 0x00001040, 0x00400040,
|
553 |
+
0x00001000, 0x00401040, 0x80401040, 0x80000040,
|
554 |
+
0x00400040, 0x80400000, 0x00401000, 0x80401040,
|
555 |
+
0x80000040, 0x00000000, 0x00000000, 0x00401000,
|
556 |
+
0x00001040, 0x00400040, 0x80400040, 0x80000000,
|
557 |
+
0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
558 |
+
0x80401040, 0x80000040, 0x80000000, 0x00001000,
|
559 |
+
0x80400000, 0x80001000, 0x00401040, 0x80400040,
|
560 |
+
0x80001000, 0x00001040, 0x00400000, 0x80401000,
|
561 |
+
0x00000040, 0x00400000, 0x00001000, 0x00401040
|
562 |
+
);
|
563 |
+
|
564 |
+
/**
|
565 |
+
* Pre-permuted S-box5
|
566 |
+
*
|
567 |
+
* @var Array
|
568 |
+
* @access private
|
569 |
+
*/
|
570 |
+
var $sbox5 = array(
|
571 |
+
0x00000080, 0x01040080, 0x01040000, 0x21000080,
|
572 |
+
0x00040000, 0x00000080, 0x20000000, 0x01040000,
|
573 |
+
0x20040080, 0x00040000, 0x01000080, 0x20040080,
|
574 |
+
0x21000080, 0x21040000, 0x00040080, 0x20000000,
|
575 |
+
0x01000000, 0x20040000, 0x20040000, 0x00000000,
|
576 |
+
0x20000080, 0x21040080, 0x21040080, 0x01000080,
|
577 |
+
0x21040000, 0x20000080, 0x00000000, 0x21000000,
|
578 |
+
0x01040080, 0x01000000, 0x21000000, 0x00040080,
|
579 |
+
0x00040000, 0x21000080, 0x00000080, 0x01000000,
|
580 |
+
0x20000000, 0x01040000, 0x21000080, 0x20040080,
|
581 |
+
0x01000080, 0x20000000, 0x21040000, 0x01040080,
|
582 |
+
0x20040080, 0x00000080, 0x01000000, 0x21040000,
|
583 |
+
0x21040080, 0x00040080, 0x21000000, 0x21040080,
|
584 |
+
0x01040000, 0x00000000, 0x20040000, 0x21000000,
|
585 |
+
0x00040080, 0x01000080, 0x20000080, 0x00040000,
|
586 |
+
0x00000000, 0x20040000, 0x01040080, 0x20000080
|
587 |
+
);
|
588 |
+
|
589 |
+
/**
|
590 |
+
* Pre-permuted S-box6
|
591 |
+
*
|
592 |
+
* @var Array
|
593 |
+
* @access private
|
594 |
+
*/
|
595 |
+
var $sbox6 = array(
|
596 |
+
0x10000008, 0x10200000, 0x00002000, 0x10202008,
|
597 |
+
0x10200000, 0x00000008, 0x10202008, 0x00200000,
|
598 |
+
0x10002000, 0x00202008, 0x00200000, 0x10000008,
|
599 |
+
0x00200008, 0x10002000, 0x10000000, 0x00002008,
|
600 |
+
0x00000000, 0x00200008, 0x10002008, 0x00002000,
|
601 |
+
0x00202000, 0x10002008, 0x00000008, 0x10200008,
|
602 |
+
0x10200008, 0x00000000, 0x00202008, 0x10202000,
|
603 |
+
0x00002008, 0x00202000, 0x10202000, 0x10000000,
|
604 |
+
0x10002000, 0x00000008, 0x10200008, 0x00202000,
|
605 |
+
0x10202008, 0x00200000, 0x00002008, 0x10000008,
|
606 |
+
0x00200000, 0x10002000, 0x10000000, 0x00002008,
|
607 |
+
0x10000008, 0x10202008, 0x00202000, 0x10200000,
|
608 |
+
0x00202008, 0x10202000, 0x00000000, 0x10200008,
|
609 |
+
0x00000008, 0x00002000, 0x10200000, 0x00202008,
|
610 |
+
0x00002000, 0x00200008, 0x10002008, 0x00000000,
|
611 |
+
0x10202000, 0x10000000, 0x00200008, 0x10002008
|
612 |
+
);
|
613 |
+
|
614 |
+
/**
|
615 |
+
* Pre-permuted S-box7
|
616 |
+
*
|
617 |
+
* @var Array
|
618 |
+
* @access private
|
619 |
+
*/
|
620 |
+
var $sbox7 = array(
|
621 |
+
0x00100000, 0x02100001, 0x02000401, 0x00000000,
|
622 |
+
0x00000400, 0x02000401, 0x00100401, 0x02100400,
|
623 |
+
0x02100401, 0x00100000, 0x00000000, 0x02000001,
|
624 |
+
0x00000001, 0x02000000, 0x02100001, 0x00000401,
|
625 |
+
0x02000400, 0x00100401, 0x00100001, 0x02000400,
|
626 |
+
0x02000001, 0x02100000, 0x02100400, 0x00100001,
|
627 |
+
0x02100000, 0x00000400, 0x00000401, 0x02100401,
|
628 |
+
0x00100400, 0x00000001, 0x02000000, 0x00100400,
|
629 |
+
0x02000000, 0x00100400, 0x00100000, 0x02000401,
|
630 |
+
0x02000401, 0x02100001, 0x02100001, 0x00000001,
|
631 |
+
0x00100001, 0x02000000, 0x02000400, 0x00100000,
|
632 |
+
0x02100400, 0x00000401, 0x00100401, 0x02100400,
|
633 |
+
0x00000401, 0x02000001, 0x02100401, 0x02100000,
|
634 |
+
0x00100400, 0x00000000, 0x00000001, 0x02100401,
|
635 |
+
0x00000000, 0x00100401, 0x02100000, 0x00000400,
|
636 |
+
0x02000001, 0x02000400, 0x00000400, 0x00100001
|
637 |
+
);
|
638 |
+
|
639 |
+
/**
|
640 |
+
* Pre-permuted S-box8
|
641 |
+
*
|
642 |
+
* @var Array
|
643 |
+
* @access private
|
644 |
+
*/
|
645 |
+
var $sbox8 = array(
|
646 |
+
0x08000820, 0x00000800, 0x00020000, 0x08020820,
|
647 |
+
0x08000000, 0x08000820, 0x00000020, 0x08000000,
|
648 |
+
0x00020020, 0x08020000, 0x08020820, 0x00020800,
|
649 |
+
0x08020800, 0x00020820, 0x00000800, 0x00000020,
|
650 |
+
0x08020000, 0x08000020, 0x08000800, 0x00000820,
|
651 |
+
0x00020800, 0x00020020, 0x08020020, 0x08020800,
|
652 |
+
0x00000820, 0x00000000, 0x00000000, 0x08020020,
|
653 |
+
0x08000020, 0x08000800, 0x00020820, 0x00020000,
|
654 |
+
0x00020820, 0x00020000, 0x08020800, 0x00000800,
|
655 |
+
0x00000020, 0x08020020, 0x00000800, 0x00020820,
|
656 |
+
0x08000800, 0x00000020, 0x08000020, 0x08020000,
|
657 |
+
0x08020020, 0x08000000, 0x00020000, 0x08000820,
|
658 |
+
0x00000000, 0x08020820, 0x00020020, 0x08000020,
|
659 |
+
0x08020000, 0x08000800, 0x08000820, 0x00000000,
|
660 |
+
0x08020820, 0x00020800, 0x00020800, 0x00000820,
|
661 |
+
0x00000820, 0x00020020, 0x08000000, 0x08020800
|
662 |
+
);
|
663 |
+
|
664 |
+
/**
|
665 |
+
* Sets the key.
|
666 |
+
*
|
667 |
+
* Keys can be of any length. DES, itself, uses 64-bit keys (eg. strlen($key) == 8), however, we
|
668 |
+
* only use the first eight, if $key has more then eight characters in it, and pad $key with the
|
669 |
+
* null byte if it is less then eight characters long.
|
670 |
+
*
|
671 |
+
* DES also requires that every eighth bit be a parity bit, however, we'll ignore that.
|
672 |
+
*
|
673 |
+
* If the key is not explicitly set, it'll be assumed to be all zero's.
|
674 |
+
*
|
675 |
+
* @see Crypt_Base::setKey()
|
676 |
+
* @access public
|
677 |
+
* @param String $key
|
678 |
+
*/
|
679 |
+
function setKey($key)
|
680 |
+
{
|
681 |
+
// We check/cut here only up to max length of the key.
|
682 |
+
// Key padding to the proper length will be done in _setupKey()
|
683 |
+
if (strlen($key) > $this->key_size_max) {
|
684 |
+
$key = substr($key, 0, $this->key_size_max);
|
685 |
+
}
|
686 |
+
|
687 |
+
// Sets the key
|
688 |
+
parent::setKey($key);
|
689 |
+
}
|
690 |
+
|
691 |
+
/**
|
692 |
+
* Encrypts a block
|
693 |
+
*
|
694 |
+
* @see Crypt_Base::_encryptBlock()
|
695 |
+
* @see Crypt_Base::encrypt()
|
696 |
+
* @see Crypt_DES::encrypt()
|
697 |
+
* @access private
|
698 |
+
* @param String $in
|
699 |
+
* @return String
|
700 |
+
*/
|
701 |
+
function _encryptBlock($in)
|
702 |
+
{
|
703 |
+
return $this->_processBlock($in, CRYPT_DES_ENCRYPT);
|
704 |
+
}
|
705 |
+
|
706 |
+
/**
|
707 |
+
* Decrypts a block
|
708 |
+
*
|
709 |
+
* @see Crypt_Base::_decryptBlock()
|
710 |
+
* @see Crypt_Base::decrypt()
|
711 |
+
* @see Crypt_DES::decrypt()
|
712 |
+
* @access private
|
713 |
+
* @param String $in
|
714 |
+
* @return String
|
715 |
+
*/
|
716 |
+
function _decryptBlock($in)
|
717 |
+
{
|
718 |
+
return $this->_processBlock($in, CRYPT_DES_DECRYPT);
|
719 |
+
}
|
720 |
+
|
721 |
+
/**
|
722 |
+
* Encrypts or decrypts a 64-bit block
|
723 |
+
*
|
724 |
+
* $mode should be either CRYPT_DES_ENCRYPT or CRYPT_DES_DECRYPT. See
|
725 |
+
* {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
|
726 |
+
* idea of what this function does.
|
727 |
+
*
|
728 |
+
* @see Crypt_DES::_encryptBlock()
|
729 |
+
* @see Crypt_DES::_decryptBlock()
|
730 |
+
* @access private
|
731 |
+
* @param String $block
|
732 |
+
* @param Integer $mode
|
733 |
+
* @return String
|
734 |
+
*/
|
735 |
+
function _processBlock($block, $mode)
|
736 |
+
{
|
737 |
+
static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
|
738 |
+
if (!$sbox1) {
|
739 |
+
$sbox1 = array_map("intval", $this->sbox1);
|
740 |
+
$sbox2 = array_map("intval", $this->sbox2);
|
741 |
+
$sbox3 = array_map("intval", $this->sbox3);
|
742 |
+
$sbox4 = array_map("intval", $this->sbox4);
|
743 |
+
$sbox5 = array_map("intval", $this->sbox5);
|
744 |
+
$sbox6 = array_map("intval", $this->sbox6);
|
745 |
+
$sbox7 = array_map("intval", $this->sbox7);
|
746 |
+
$sbox8 = array_map("intval", $this->sbox8);
|
747 |
+
/* Merge $shuffle with $[inv]ipmap */
|
748 |
+
for ($i = 0; $i < 256; ++$i) {
|
749 |
+
$shuffleip[] = $this->shuffle[$this->ipmap[$i]];
|
750 |
+
$shuffleinvip[] = $this->shuffle[$this->invipmap[$i]];
|
751 |
+
}
|
752 |
+
}
|
753 |
+
|
754 |
+
$keys = $this->keys[$mode];
|
755 |
+
$ki = -1;
|
756 |
+
|
757 |
+
// Do the initial IP permutation.
|
758 |
+
$t = unpack('Nl/Nr', $block);
|
759 |
+
list($l, $r) = array($t['l'], $t['r']);
|
760 |
+
$block = ($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
761 |
+
($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
762 |
+
($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
763 |
+
($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
764 |
+
($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
765 |
+
($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
766 |
+
($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
767 |
+
($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
|
768 |
+
|
769 |
+
// Extract L0 and R0.
|
770 |
+
$t = unpack('Nl/Nr', $block);
|
771 |
+
list($l, $r) = array($t['l'], $t['r']);
|
772 |
+
|
773 |
+
for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) {
|
774 |
+
// Perform the 16 steps.
|
775 |
+
for ($i = 0; $i < 16; $i++) {
|
776 |
+
// start of "the Feistel (F) function" - see the following URL:
|
777 |
+
// http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
|
778 |
+
// Merge key schedule.
|
779 |
+
$b1 = (($r >> 3) & 0x1FFFFFFF) ^ ($r << 29) ^ $keys[++$ki];
|
780 |
+
$b2 = (($r >> 31) & 0x00000001) ^ ($r << 1) ^ $keys[++$ki];
|
781 |
+
|
782 |
+
// S-box indexing.
|
783 |
+
$t = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
|
784 |
+
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
|
785 |
+
$sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
|
786 |
+
$sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ $l;
|
787 |
+
// end of "the Feistel (F) function"
|
788 |
+
|
789 |
+
$l = $r;
|
790 |
+
$r = $t;
|
791 |
+
}
|
792 |
+
|
793 |
+
// Last step should not permute L & R.
|
794 |
+
$t = $l;
|
795 |
+
$l = $r;
|
796 |
+
$r = $t;
|
797 |
+
}
|
798 |
+
|
799 |
+
// Perform the inverse IP permutation.
|
800 |
+
return ($shuffleinvip[($r >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
801 |
+
($shuffleinvip[($l >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
802 |
+
($shuffleinvip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
803 |
+
($shuffleinvip[($l >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
804 |
+
($shuffleinvip[($r >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
805 |
+
($shuffleinvip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
806 |
+
($shuffleinvip[ $r & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
807 |
+
($shuffleinvip[ $l & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
|
808 |
+
}
|
809 |
+
|
810 |
+
/**
|
811 |
+
* Creates the key schedule
|
812 |
+
*
|
813 |
+
* @see Crypt_Base::_setupKey()
|
814 |
+
* @access private
|
815 |
+
*/
|
816 |
+
function _setupKey()
|
817 |
+
{
|
818 |
+
if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->des_rounds === $this->kl['des_rounds']) {
|
819 |
+
// already expanded
|
820 |
+
return;
|
821 |
+
}
|
822 |
+
$this->kl = array('key' => $this->key, 'des_rounds' => $this->des_rounds);
|
823 |
+
|
824 |
+
static $shifts = array( // number of key bits shifted per round
|
825 |
+
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
|
826 |
+
);
|
827 |
+
|
828 |
+
static $pc1map = array(
|
829 |
+
0x00, 0x00, 0x08, 0x08, 0x04, 0x04, 0x0C, 0x0C,
|
830 |
+
0x02, 0x02, 0x0A, 0x0A, 0x06, 0x06, 0x0E, 0x0E,
|
831 |
+
0x10, 0x10, 0x18, 0x18, 0x14, 0x14, 0x1C, 0x1C,
|
832 |
+
0x12, 0x12, 0x1A, 0x1A, 0x16, 0x16, 0x1E, 0x1E,
|
833 |
+
0x20, 0x20, 0x28, 0x28, 0x24, 0x24, 0x2C, 0x2C,
|
834 |
+
0x22, 0x22, 0x2A, 0x2A, 0x26, 0x26, 0x2E, 0x2E,
|
835 |
+
0x30, 0x30, 0x38, 0x38, 0x34, 0x34, 0x3C, 0x3C,
|
836 |
+
0x32, 0x32, 0x3A, 0x3A, 0x36, 0x36, 0x3E, 0x3E,
|
837 |
+
0x40, 0x40, 0x48, 0x48, 0x44, 0x44, 0x4C, 0x4C,
|
838 |
+
0x42, 0x42, 0x4A, 0x4A, 0x46, 0x46, 0x4E, 0x4E,
|
839 |
+
0x50, 0x50, 0x58, 0x58, 0x54, 0x54, 0x5C, 0x5C,
|
840 |
+
0x52, 0x52, 0x5A, 0x5A, 0x56, 0x56, 0x5E, 0x5E,
|
841 |
+
0x60, 0x60, 0x68, 0x68, 0x64, 0x64, 0x6C, 0x6C,
|
842 |
+
0x62, 0x62, 0x6A, 0x6A, 0x66, 0x66, 0x6E, 0x6E,
|
843 |
+
0x70, 0x70, 0x78, 0x78, 0x74, 0x74, 0x7C, 0x7C,
|
844 |
+
0x72, 0x72, 0x7A, 0x7A, 0x76, 0x76, 0x7E, 0x7E,
|
845 |
+
0x80, 0x80, 0x88, 0x88, 0x84, 0x84, 0x8C, 0x8C,
|
846 |
+
0x82, 0x82, 0x8A, 0x8A, 0x86, 0x86, 0x8E, 0x8E,
|
847 |
+
0x90, 0x90, 0x98, 0x98, 0x94, 0x94, 0x9C, 0x9C,
|
848 |
+
0x92, 0x92, 0x9A, 0x9A, 0x96, 0x96, 0x9E, 0x9E,
|
849 |
+
0xA0, 0xA0, 0xA8, 0xA8, 0xA4, 0xA4, 0xAC, 0xAC,
|
850 |
+
0xA2, 0xA2, 0xAA, 0xAA, 0xA6, 0xA6, 0xAE, 0xAE,
|
851 |
+
0xB0, 0xB0, 0xB8, 0xB8, 0xB4, 0xB4, 0xBC, 0xBC,
|
852 |
+
0xB2, 0xB2, 0xBA, 0xBA, 0xB6, 0xB6, 0xBE, 0xBE,
|
853 |
+
0xC0, 0xC0, 0xC8, 0xC8, 0xC4, 0xC4, 0xCC, 0xCC,
|
854 |
+
0xC2, 0xC2, 0xCA, 0xCA, 0xC6, 0xC6, 0xCE, 0xCE,
|
855 |
+
0xD0, 0xD0, 0xD8, 0xD8, 0xD4, 0xD4, 0xDC, 0xDC,
|
856 |
+
0xD2, 0xD2, 0xDA, 0xDA, 0xD6, 0xD6, 0xDE, 0xDE,
|
857 |
+
0xE0, 0xE0, 0xE8, 0xE8, 0xE4, 0xE4, 0xEC, 0xEC,
|
858 |
+
0xE2, 0xE2, 0xEA, 0xEA, 0xE6, 0xE6, 0xEE, 0xEE,
|
859 |
+
0xF0, 0xF0, 0xF8, 0xF8, 0xF4, 0xF4, 0xFC, 0xFC,
|
860 |
+
0xF2, 0xF2, 0xFA, 0xFA, 0xF6, 0xF6, 0xFE, 0xFE
|
861 |
+
);
|
862 |
+
|
863 |
+
// Mapping tables for the PC-2 transformation.
|
864 |
+
static $pc2mapc1 = array(
|
865 |
+
0x00000000, 0x00000400, 0x00200000, 0x00200400,
|
866 |
+
0x00000001, 0x00000401, 0x00200001, 0x00200401,
|
867 |
+
0x02000000, 0x02000400, 0x02200000, 0x02200400,
|
868 |
+
0x02000001, 0x02000401, 0x02200001, 0x02200401
|
869 |
+
);
|
870 |
+
static $pc2mapc2 = array(
|
871 |
+
0x00000000, 0x00000800, 0x08000000, 0x08000800,
|
872 |
+
0x00010000, 0x00010800, 0x08010000, 0x08010800,
|
873 |
+
0x00000000, 0x00000800, 0x08000000, 0x08000800,
|
874 |
+
0x00010000, 0x00010800, 0x08010000, 0x08010800,
|
875 |
+
0x00000100, 0x00000900, 0x08000100, 0x08000900,
|
876 |
+
0x00010100, 0x00010900, 0x08010100, 0x08010900,
|
877 |
+
0x00000100, 0x00000900, 0x08000100, 0x08000900,
|
878 |
+
0x00010100, 0x00010900, 0x08010100, 0x08010900,
|
879 |
+
0x00000010, 0x00000810, 0x08000010, 0x08000810,
|
880 |
+
0x00010010, 0x00010810, 0x08010010, 0x08010810,
|
881 |
+
0x00000010, 0x00000810, 0x08000010, 0x08000810,
|
882 |
+
0x00010010, 0x00010810, 0x08010010, 0x08010810,
|
883 |
+
0x00000110, 0x00000910, 0x08000110, 0x08000910,
|
884 |
+
0x00010110, 0x00010910, 0x08010110, 0x08010910,
|
885 |
+
0x00000110, 0x00000910, 0x08000110, 0x08000910,
|
886 |
+
0x00010110, 0x00010910, 0x08010110, 0x08010910,
|
887 |
+
0x00040000, 0x00040800, 0x08040000, 0x08040800,
|
888 |
+
0x00050000, 0x00050800, 0x08050000, 0x08050800,
|
889 |
+
0x00040000, 0x00040800, 0x08040000, 0x08040800,
|
890 |
+
0x00050000, 0x00050800, 0x08050000, 0x08050800,
|
891 |
+
0x00040100, 0x00040900, 0x08040100, 0x08040900,
|
892 |
+
0x00050100, 0x00050900, 0x08050100, 0x08050900,
|
893 |
+
0x00040100, 0x00040900, 0x08040100, 0x08040900,
|
894 |
+
0x00050100, 0x00050900, 0x08050100, 0x08050900,
|
895 |
+
0x00040010, 0x00040810, 0x08040010, 0x08040810,
|
896 |
+
0x00050010, 0x00050810, 0x08050010, 0x08050810,
|
897 |
+
0x00040010, 0x00040810, 0x08040010, 0x08040810,
|
898 |
+
0x00050010, 0x00050810, 0x08050010, 0x08050810,
|
899 |
+
0x00040110, 0x00040910, 0x08040110, 0x08040910,
|
900 |
+
0x00050110, 0x00050910, 0x08050110, 0x08050910,
|
901 |
+
0x00040110, 0x00040910, 0x08040110, 0x08040910,
|
902 |
+
0x00050110, 0x00050910, 0x08050110, 0x08050910,
|
903 |
+
0x01000000, 0x01000800, 0x09000000, 0x09000800,
|
904 |
+
0x01010000, 0x01010800, 0x09010000, 0x09010800,
|
905 |
+
0x01000000, 0x01000800, 0x09000000, 0x09000800,
|
906 |
+
0x01010000, 0x01010800, 0x09010000, 0x09010800,
|
907 |
+
0x01000100, 0x01000900, 0x09000100, 0x09000900,
|
908 |
+
0x01010100, 0x01010900, 0x09010100, 0x09010900,
|
909 |
+
0x01000100, 0x01000900, 0x09000100, 0x09000900,
|
910 |
+
0x01010100, 0x01010900, 0x09010100, 0x09010900,
|
911 |
+
0x01000010, 0x01000810, 0x09000010, 0x09000810,
|
912 |
+
0x01010010, 0x01010810, 0x09010010, 0x09010810,
|
913 |
+
0x01000010, 0x01000810, 0x09000010, 0x09000810,
|
914 |
+
0x01010010, 0x01010810, 0x09010010, 0x09010810,
|
915 |
+
0x01000110, 0x01000910, 0x09000110, 0x09000910,
|
916 |
+
0x01010110, 0x01010910, 0x09010110, 0x09010910,
|
917 |
+
0x01000110, 0x01000910, 0x09000110, 0x09000910,
|
918 |
+
0x01010110, 0x01010910, 0x09010110, 0x09010910,
|
919 |
+
0x01040000, 0x01040800, 0x09040000, 0x09040800,
|
920 |
+
0x01050000, 0x01050800, 0x09050000, 0x09050800,
|
921 |
+
0x01040000, 0x01040800, 0x09040000, 0x09040800,
|
922 |
+
0x01050000, 0x01050800, 0x09050000, 0x09050800,
|
923 |
+
0x01040100, 0x01040900, 0x09040100, 0x09040900,
|
924 |
+
0x01050100, 0x01050900, 0x09050100, 0x09050900,
|
925 |
+
0x01040100, 0x01040900, 0x09040100, 0x09040900,
|
926 |
+
0x01050100, 0x01050900, 0x09050100, 0x09050900,
|
927 |
+
0x01040010, 0x01040810, 0x09040010, 0x09040810,
|
928 |
+
0x01050010, 0x01050810, 0x09050010, 0x09050810,
|
929 |
+
0x01040010, 0x01040810, 0x09040010, 0x09040810,
|
930 |
+
0x01050010, 0x01050810, 0x09050010, 0x09050810,
|
931 |
+
0x01040110, 0x01040910, 0x09040110, 0x09040910,
|
932 |
+
0x01050110, 0x01050910, 0x09050110, 0x09050910,
|
933 |
+
0x01040110, 0x01040910, 0x09040110, 0x09040910,
|
934 |
+
0x01050110, 0x01050910, 0x09050110, 0x09050910
|
935 |
+
);
|
936 |
+
static $pc2mapc3 = array(
|
937 |
+
0x00000000, 0x00000004, 0x00001000, 0x00001004,
|
938 |
+
0x00000000, 0x00000004, 0x00001000, 0x00001004,
|
939 |
+
0x10000000, 0x10000004, 0x10001000, 0x10001004,
|
940 |
+
0x10000000, 0x10000004, 0x10001000, 0x10001004,
|
941 |
+
0x00000020, 0x00000024, 0x00001020, 0x00001024,
|
942 |
+
0x00000020, 0x00000024, 0x00001020, 0x00001024,
|
943 |
+
0x10000020, 0x10000024, 0x10001020, 0x10001024,
|
944 |
+
0x10000020, 0x10000024, 0x10001020, 0x10001024,
|
945 |
+
0x00080000, 0x00080004, 0x00081000, 0x00081004,
|
946 |
+
0x00080000, 0x00080004, 0x00081000, 0x00081004,
|
947 |
+
0x10080000, 0x10080004, 0x10081000, 0x10081004,
|
948 |
+
0x10080000, 0x10080004, 0x10081000, 0x10081004,
|
949 |
+
0x00080020, 0x00080024, 0x00081020, 0x00081024,
|
950 |
+
0x00080020, 0x00080024, 0x00081020, 0x00081024,
|
951 |
+
0x10080020, 0x10080024, 0x10081020, 0x10081024,
|
952 |
+
0x10080020, 0x10080024, 0x10081020, 0x10081024,
|
953 |
+
0x20000000, 0x20000004, 0x20001000, 0x20001004,
|
954 |
+
0x20000000, 0x20000004, 0x20001000, 0x20001004,
|
955 |
+
0x30000000, 0x30000004, 0x30001000, 0x30001004,
|
956 |
+
0x30000000, 0x30000004, 0x30001000, 0x30001004,
|
957 |
+
0x20000020, 0x20000024, 0x20001020, 0x20001024,
|
958 |
+
0x20000020, 0x20000024, 0x20001020, 0x20001024,
|
959 |
+
0x30000020, 0x30000024, 0x30001020, 0x30001024,
|
960 |
+
0x30000020, 0x30000024, 0x30001020, 0x30001024,
|
961 |
+
0x20080000, 0x20080004, 0x20081000, 0x20081004,
|
962 |
+
0x20080000, 0x20080004, 0x20081000, 0x20081004,
|
963 |
+
0x30080000, 0x30080004, 0x30081000, 0x30081004,
|
964 |
+
0x30080000, 0x30080004, 0x30081000, 0x30081004,
|
965 |
+
0x20080020, 0x20080024, 0x20081020, 0x20081024,
|
966 |
+
0x20080020, 0x20080024, 0x20081020, 0x20081024,
|
967 |
+
0x30080020, 0x30080024, 0x30081020, 0x30081024,
|
968 |
+
0x30080020, 0x30080024, 0x30081020, 0x30081024,
|
969 |
+
0x00000002, 0x00000006, 0x00001002, 0x00001006,
|
970 |
+
0x00000002, 0x00000006, 0x00001002, 0x00001006,
|
971 |
+
0x10000002, 0x10000006, 0x10001002, 0x10001006,
|
972 |
+
0x10000002, 0x10000006, 0x10001002, 0x10001006,
|
973 |
+
0x00000022, 0x00000026, 0x00001022, 0x00001026,
|
974 |
+
0x00000022, 0x00000026, 0x00001022, 0x00001026,
|
975 |
+
0x10000022, 0x10000026, 0x10001022, 0x10001026,
|
976 |
+
0x10000022, 0x10000026, 0x10001022, 0x10001026,
|
977 |
+
0x00080002, 0x00080006, 0x00081002, 0x00081006,
|
978 |
+
0x00080002, 0x00080006, 0x00081002, 0x00081006,
|
979 |
+
0x10080002, 0x10080006, 0x10081002, 0x10081006,
|
980 |
+
0x10080002, 0x10080006, 0x10081002, 0x10081006,
|
981 |
+
0x00080022, 0x00080026, 0x00081022, 0x00081026,
|
982 |
+
0x00080022, 0x00080026, 0x00081022, 0x00081026,
|
983 |
+
0x10080022, 0x10080026, 0x10081022, 0x10081026,
|
984 |
+
0x10080022, 0x10080026, 0x10081022, 0x10081026,
|
985 |
+
0x20000002, 0x20000006, 0x20001002, 0x20001006,
|
986 |
+
0x20000002, 0x20000006, 0x20001002, 0x20001006,
|
987 |
+
0x30000002, 0x30000006, 0x30001002, 0x30001006,
|
988 |
+
0x30000002, 0x30000006, 0x30001002, 0x30001006,
|
989 |
+
0x20000022, 0x20000026, 0x20001022, 0x20001026,
|
990 |
+
0x20000022, 0x20000026, 0x20001022, 0x20001026,
|
991 |
+
0x30000022, 0x30000026, 0x30001022, 0x30001026,
|
992 |
+
0x30000022, 0x30000026, 0x30001022, 0x30001026,
|
993 |
+
0x20080002, 0x20080006, 0x20081002, 0x20081006,
|
994 |
+
0x20080002, 0x20080006, 0x20081002, 0x20081006,
|
995 |
+
0x30080002, 0x30080006, 0x30081002, 0x30081006,
|
996 |
+
0x30080002, 0x30080006, 0x30081002, 0x30081006,
|
997 |
+
0x20080022, 0x20080026, 0x20081022, 0x20081026,
|
998 |
+
0x20080022, 0x20080026, 0x20081022, 0x20081026,
|
999 |
+
0x30080022, 0x30080026, 0x30081022, 0x30081026,
|
1000 |
+
0x30080022, 0x30080026, 0x30081022, 0x30081026
|
1001 |
+
);
|
1002 |
+
static $pc2mapc4 = array(
|
1003 |
+
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1004 |
+
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1005 |
+
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1006 |
+
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1007 |
+
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1008 |
+
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1009 |
+
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1010 |
+
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1011 |
+
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1012 |
+
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1013 |
+
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1014 |
+
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1015 |
+
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1016 |
+
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1017 |
+
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1018 |
+
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1019 |
+
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1020 |
+
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1021 |
+
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1022 |
+
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1023 |
+
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1024 |
+
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1025 |
+
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1026 |
+
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1027 |
+
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1028 |
+
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1029 |
+
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1030 |
+
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1031 |
+
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1032 |
+
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1033 |
+
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1034 |
+
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1035 |
+
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1036 |
+
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1037 |
+
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1038 |
+
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1039 |
+
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1040 |
+
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1041 |
+
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1042 |
+
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1043 |
+
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1044 |
+
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1045 |
+
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1046 |
+
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1047 |
+
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1048 |
+
0x04022200, 0x04122200, 0x04022208, 0x04122208,
|
1049 |
+
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1050 |
+
0x04022200, 0x04122200, 0x04022208, 0x04122208,
|
1051 |
+
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1052 |
+
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1053 |
+
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1054 |
+
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1055 |
+
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1056 |
+
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1057 |
+
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1058 |
+
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1059 |
+
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1060 |
+
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1061 |
+
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1062 |
+
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1063 |
+
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1064 |
+
0x04022200, 0x04122200, 0x04022208, 0x04122208,
|
1065 |
+
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1066 |
+
0x04022200, 0x04122200, 0x04022208, 0x04122208
|
1067 |
+
);
|
1068 |
+
static $pc2mapd1 = array(
|
1069 |
+
0x00000000, 0x00000001, 0x08000000, 0x08000001,
|
1070 |
+
0x00200000, 0x00200001, 0x08200000, 0x08200001,
|
1071 |
+
0x00000002, 0x00000003, 0x08000002, 0x08000003,
|
1072 |
+
0x00200002, 0x00200003, 0x08200002, 0x08200003
|
1073 |
+
);
|
1074 |
+
static $pc2mapd2 = array(
|
1075 |
+
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1076 |
+
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1077 |
+
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1078 |
+
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1079 |
+
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1080 |
+
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1081 |
+
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1082 |
+
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1083 |
+
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1084 |
+
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1085 |
+
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1086 |
+
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1087 |
+
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1088 |
+
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1089 |
+
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1090 |
+
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1091 |
+
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1092 |
+
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1093 |
+
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1094 |
+
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1095 |
+
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1096 |
+
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1097 |
+
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1098 |
+
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1099 |
+
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1100 |
+
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1101 |
+
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1102 |
+
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1103 |
+
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1104 |
+
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1105 |
+
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1106 |
+
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1107 |
+
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1108 |
+
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1109 |
+
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1110 |
+
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1111 |
+
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1112 |
+
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1113 |
+
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1114 |
+
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1115 |
+
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1116 |
+
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1117 |
+
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1118 |
+
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1119 |
+
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1120 |
+
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1121 |
+
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1122 |
+
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1123 |
+
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1124 |
+
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1125 |
+
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1126 |
+
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1127 |
+
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1128 |
+
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1129 |
+
0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
|
1130 |
+
0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
|
1131 |
+
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1132 |
+
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1133 |
+
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1134 |
+
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1135 |
+
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1136 |
+
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1137 |
+
0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
|
1138 |
+
0x04020204, 0x04120204, 0x04020A04, 0x04120A04
|
1139 |
+
);
|
1140 |
+
static $pc2mapd3 = array(
|
1141 |
+
0x00000000, 0x00010000, 0x02000000, 0x02010000,
|
1142 |
+
0x00000020, 0x00010020, 0x02000020, 0x02010020,
|
1143 |
+
0x00040000, 0x00050000, 0x02040000, 0x02050000,
|
1144 |
+
0x00040020, 0x00050020, 0x02040020, 0x02050020,
|
1145 |
+
0x00002000, 0x00012000, 0x02002000, 0x02012000,
|
1146 |
+
0x00002020, 0x00012020, 0x02002020, 0x02012020,
|
1147 |
+
0x00042000, 0x00052000, 0x02042000, 0x02052000,
|
1148 |
+
0x00042020, 0x00052020, 0x02042020, 0x02052020,
|
1149 |
+
0x00000000, 0x00010000, 0x02000000, 0x02010000,
|
1150 |
+
0x00000020, 0x00010020, 0x02000020, 0x02010020,
|
1151 |
+
0x00040000, 0x00050000, 0x02040000, 0x02050000,
|
1152 |
+
0x00040020, 0x00050020, 0x02040020, 0x02050020,
|
1153 |
+
0x00002000, 0x00012000, 0x02002000, 0x02012000,
|
1154 |
+
0x00002020, 0x00012020, 0x02002020, 0x02012020,
|
1155 |
+
0x00042000, 0x00052000, 0x02042000, 0x02052000,
|
1156 |
+
0x00042020, 0x00052020, 0x02042020, 0x02052020,
|
1157 |
+
0x00000010, 0x00010010, 0x02000010, 0x02010010,
|
1158 |
+
0x00000030, 0x00010030, 0x02000030, 0x02010030,
|
1159 |
+
0x00040010, 0x00050010, 0x02040010, 0x02050010,
|
1160 |
+
0x00040030, 0x00050030, 0x02040030, 0x02050030,
|
1161 |
+
0x00002010, 0x00012010, 0x02002010, 0x02012010,
|
1162 |
+
0x00002030, 0x00012030, 0x02002030, 0x02012030,
|
1163 |
+
0x00042010, 0x00052010, 0x02042010, 0x02052010,
|
1164 |
+
0x00042030, 0x00052030, 0x02042030, 0x02052030,
|
1165 |
+
0x00000010, 0x00010010, 0x02000010, 0x02010010,
|
1166 |
+
0x00000030, 0x00010030, 0x02000030, 0x02010030,
|
1167 |
+
0x00040010, 0x00050010, 0x02040010, 0x02050010,
|
1168 |
+
0x00040030, 0x00050030, 0x02040030, 0x02050030,
|
1169 |
+
0x00002010, 0x00012010, 0x02002010, 0x02012010,
|
1170 |
+
0x00002030, 0x00012030, 0x02002030, 0x02012030,
|
1171 |
+
0x00042010, 0x00052010, 0x02042010, 0x02052010,
|
1172 |
+
0x00042030, 0x00052030, 0x02042030, 0x02052030,
|
1173 |
+
0x20000000, 0x20010000, 0x22000000, 0x22010000,
|
1174 |
+
0x20000020, 0x20010020, 0x22000020, 0x22010020,
|
1175 |
+
0x20040000, 0x20050000, 0x22040000, 0x22050000,
|
1176 |
+
0x20040020, 0x20050020, 0x22040020, 0x22050020,
|
1177 |
+
0x20002000, 0x20012000, 0x22002000, 0x22012000,
|
1178 |
+
0x20002020, 0x20012020, 0x22002020, 0x22012020,
|
1179 |
+
0x20042000, 0x20052000, 0x22042000, 0x22052000,
|
1180 |
+
0x20042020, 0x20052020, 0x22042020, 0x22052020,
|
1181 |
+
0x20000000, 0x20010000, 0x22000000, 0x22010000,
|
1182 |
+
0x20000020, 0x20010020, 0x22000020, 0x22010020,
|
1183 |
+
0x20040000, 0x20050000, 0x22040000, 0x22050000,
|
1184 |
+
0x20040020, 0x20050020, 0x22040020, 0x22050020,
|
1185 |
+
0x20002000, 0x20012000, 0x22002000, 0x22012000,
|
1186 |
+
0x20002020, 0x20012020, 0x22002020, 0x22012020,
|
1187 |
+
0x20042000, 0x20052000, 0x22042000, 0x22052000,
|
1188 |
+
0x20042020, 0x20052020, 0x22042020, 0x22052020,
|
1189 |
+
0x20000010, 0x20010010, 0x22000010, 0x22010010,
|
1190 |
+
0x20000030, 0x20010030, 0x22000030, 0x22010030,
|
1191 |
+
0x20040010, 0x20050010, 0x22040010, 0x22050010,
|
1192 |
+
0x20040030, 0x20050030, 0x22040030, 0x22050030,
|
1193 |
+
0x20002010, 0x20012010, 0x22002010, 0x22012010,
|
1194 |
+
0x20002030, 0x20012030, 0x22002030, 0x22012030,
|
1195 |
+
0x20042010, 0x20052010, 0x22042010, 0x22052010,
|
1196 |
+
0x20042030, 0x20052030, 0x22042030, 0x22052030,
|
1197 |
+
0x20000010, 0x20010010, 0x22000010, 0x22010010,
|
1198 |
+
0x20000030, 0x20010030, 0x22000030, 0x22010030,
|
1199 |
+
0x20040010, 0x20050010, 0x22040010, 0x22050010,
|
1200 |
+
0x20040030, 0x20050030, 0x22040030, 0x22050030,
|
1201 |
+
0x20002010, 0x20012010, 0x22002010, 0x22012010,
|
1202 |
+
0x20002030, 0x20012030, 0x22002030, 0x22012030,
|
1203 |
+
0x20042010, 0x20052010, 0x22042010, 0x22052010,
|
1204 |
+
0x20042030, 0x20052030, 0x22042030, 0x22052030
|
1205 |
+
);
|
1206 |
+
static $pc2mapd4 = array(
|
1207 |
+
0x00000000, 0x00000400, 0x01000000, 0x01000400,
|
1208 |
+
0x00000000, 0x00000400, 0x01000000, 0x01000400,
|
1209 |
+
0x00000100, 0x00000500, 0x01000100, 0x01000500,
|
1210 |
+
0x00000100, 0x00000500, 0x01000100, 0x01000500,
|
1211 |
+
0x10000000, 0x10000400, 0x11000000, 0x11000400,
|
1212 |
+
0x10000000, 0x10000400, 0x11000000, 0x11000400,
|
1213 |
+
0x10000100, 0x10000500, 0x11000100, 0x11000500,
|
1214 |
+
0x10000100, 0x10000500, 0x11000100, 0x11000500,
|
1215 |
+
0x00080000, 0x00080400, 0x01080000, 0x01080400,
|
1216 |
+
0x00080000, 0x00080400, 0x01080000, 0x01080400,
|
1217 |
+
0x00080100, 0x00080500, 0x01080100, 0x01080500,
|
1218 |
+
0x00080100, 0x00080500, 0x01080100, 0x01080500,
|
1219 |
+
0x10080000, 0x10080400, 0x11080000, 0x11080400,
|
1220 |
+
0x10080000, 0x10080400, 0x11080000, 0x11080400,
|
1221 |
+
0x10080100, 0x10080500, 0x11080100, 0x11080500,
|
1222 |
+
0x10080100, 0x10080500, 0x11080100, 0x11080500,
|
1223 |
+
0x00000008, 0x00000408, 0x01000008, 0x01000408,
|
1224 |
+
0x00000008, 0x00000408, 0x01000008, 0x01000408,
|
1225 |
+
0x00000108, 0x00000508, 0x01000108, 0x01000508,
|
1226 |
+
0x00000108, 0x00000508, 0x01000108, 0x01000508,
|
1227 |
+
0x10000008, 0x10000408, 0x11000008, 0x11000408,
|
1228 |
+
0x10000008, 0x10000408, 0x11000008, 0x11000408,
|
1229 |
+
0x10000108, 0x10000508, 0x11000108, 0x11000508,
|
1230 |
+
0x10000108, 0x10000508, 0x11000108, 0x11000508,
|
1231 |
+
0x00080008, 0x00080408, 0x01080008, 0x01080408,
|
1232 |
+
0x00080008, 0x00080408, 0x01080008, 0x01080408,
|
1233 |
+
0x00080108, 0x00080508, 0x01080108, 0x01080508,
|
1234 |
+
0x00080108, 0x00080508, 0x01080108, 0x01080508,
|
1235 |
+
0x10080008, 0x10080408, 0x11080008, 0x11080408,
|
1236 |
+
0x10080008, 0x10080408, 0x11080008, 0x11080408,
|
1237 |
+
0x10080108, 0x10080508, 0x11080108, 0x11080508,
|
1238 |
+
0x10080108, 0x10080508, 0x11080108, 0x11080508,
|
1239 |
+
0x00001000, 0x00001400, 0x01001000, 0x01001400,
|
1240 |
+
0x00001000, 0x00001400, 0x01001000, 0x01001400,
|
1241 |
+
0x00001100, 0x00001500, 0x01001100, 0x01001500,
|
1242 |
+
0x00001100, 0x00001500, 0x01001100, 0x01001500,
|
1243 |
+
0x10001000, 0x10001400, 0x11001000, 0x11001400,
|
1244 |
+
0x10001000, 0x10001400, 0x11001000, 0x11001400,
|
1245 |
+
0x10001100, 0x10001500, 0x11001100, 0x11001500,
|
1246 |
+
0x10001100, 0x10001500, 0x11001100, 0x11001500,
|
1247 |
+
0x00081000, 0x00081400, 0x01081000, 0x01081400,
|
1248 |
+
0x00081000, 0x00081400, 0x01081000, 0x01081400,
|
1249 |
+
0x00081100, 0x00081500, 0x01081100, 0x01081500,
|
1250 |
+
0x00081100, 0x00081500, 0x01081100, 0x01081500,
|
1251 |
+
0x10081000, 0x10081400, 0x11081000, 0x11081400,
|
1252 |
+
0x10081000, 0x10081400, 0x11081000, 0x11081400,
|
1253 |
+
0x10081100, 0x10081500, 0x11081100, 0x11081500,
|
1254 |
+
0x10081100, 0x10081500, 0x11081100, 0x11081500,
|
1255 |
+
0x00001008, 0x00001408, 0x01001008, 0x01001408,
|
1256 |
+
0x00001008, 0x00001408, 0x01001008, 0x01001408,
|
1257 |
+
0x00001108, 0x00001508, 0x01001108, 0x01001508,
|
1258 |
+
0x00001108, 0x00001508, 0x01001108, 0x01001508,
|
1259 |
+
0x10001008, 0x10001408, 0x11001008, 0x11001408,
|
1260 |
+
0x10001008, 0x10001408, 0x11001008, 0x11001408,
|
1261 |
+
0x10001108, 0x10001508, 0x11001108, 0x11001508,
|
1262 |
+
0x10001108, 0x10001508, 0x11001108, 0x11001508,
|
1263 |
+
0x00081008, 0x00081408, 0x01081008, 0x01081408,
|
1264 |
+
0x00081008, 0x00081408, 0x01081008, 0x01081408,
|
1265 |
+
0x00081108, 0x00081508, 0x01081108, 0x01081508,
|
1266 |
+
0x00081108, 0x00081508, 0x01081108, 0x01081508,
|
1267 |
+
0x10081008, 0x10081408, 0x11081008, 0x11081408,
|
1268 |
+
0x10081008, 0x10081408, 0x11081008, 0x11081408,
|
1269 |
+
0x10081108, 0x10081508, 0x11081108, 0x11081508,
|
1270 |
+
0x10081108, 0x10081508, 0x11081108, 0x11081508
|
1271 |
+
);
|
1272 |
+
|
1273 |
+
$keys = array();
|
1274 |
+
for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) {
|
1275 |
+
// pad the key and remove extra characters as appropriate.
|
1276 |
+
$key = str_pad(substr($this->key, $des_round * 8, 8), 8, "\0");
|
1277 |
+
|
1278 |
+
// Perform the PC/1 transformation and compute C and D.
|
1279 |
+
$t = unpack('Nl/Nr', $key);
|
1280 |
+
list($l, $r) = array($t['l'], $t['r']);
|
1281 |
+
$key = ($this->shuffle[$pc1map[ $r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") |
|
1282 |
+
($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") |
|
1283 |
+
($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") |
|
1284 |
+
($this->shuffle[$pc1map[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x00") |
|
1285 |
+
($this->shuffle[$pc1map[ $l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x00") |
|
1286 |
+
($this->shuffle[$pc1map[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x00") |
|
1287 |
+
($this->shuffle[$pc1map[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x00") |
|
1288 |
+
($this->shuffle[$pc1map[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x00");
|
1289 |
+
$key = unpack('Nc/Nd', $key);
|
1290 |
+
$c = ( $key['c'] >> 4) & 0x0FFFFFFF;
|
1291 |
+
$d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F);
|
1292 |
+
|
1293 |
+
$keys[$des_round] = array(
|
1294 |
+
CRYPT_DES_ENCRYPT => array(),
|
1295 |
+
CRYPT_DES_DECRYPT => array_fill(0, 32, 0)
|
1296 |
+
);
|
1297 |
+
for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) {
|
1298 |
+
$c <<= $shifts[$i];
|
1299 |
+
$c = ($c | ($c >> 28)) & 0x0FFFFFFF;
|
1300 |
+
$d <<= $shifts[$i];
|
1301 |
+
$d = ($d | ($d >> 28)) & 0x0FFFFFFF;
|
1302 |
+
|
1303 |
+
// Perform the PC-2 transformation.
|
1304 |
+
$cp = $pc2mapc1[ $c >> 24 ] | $pc2mapc2[($c >> 16) & 0xFF] |
|
1305 |
+
$pc2mapc3[($c >> 8) & 0xFF] | $pc2mapc4[ $c & 0xFF];
|
1306 |
+
$dp = $pc2mapd1[ $d >> 24 ] | $pc2mapd2[($d >> 16) & 0xFF] |
|
1307 |
+
$pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[ $d & 0xFF];
|
1308 |
+
|
1309 |
+
// Reorder: odd bytes/even bytes. Push the result in key schedule.
|
1310 |
+
$val1 = ( $cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) |
|
1311 |
+
(($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF);
|
1312 |
+
$val2 = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
|
1313 |
+
(($dp >> 8) & 0x0000FF00) | ( $dp & 0x000000FF);
|
1314 |
+
$keys[$des_round][CRYPT_DES_ENCRYPT][ ] = $val1;
|
1315 |
+
$keys[$des_round][CRYPT_DES_DECRYPT][$ki - 1] = $val1;
|
1316 |
+
$keys[$des_round][CRYPT_DES_ENCRYPT][ ] = $val2;
|
1317 |
+
$keys[$des_round][CRYPT_DES_DECRYPT][$ki ] = $val2;
|
1318 |
+
}
|
1319 |
+
}
|
1320 |
+
|
1321 |
+
switch ($this->des_rounds) {
|
1322 |
+
case 3: // 3DES keys
|
1323 |
+
$this->keys = array(
|
1324 |
+
CRYPT_DES_ENCRYPT => array_merge(
|
1325 |
+
$keys[0][CRYPT_DES_ENCRYPT],
|
1326 |
+
$keys[1][CRYPT_DES_DECRYPT],
|
1327 |
+
$keys[2][CRYPT_DES_ENCRYPT]
|
1328 |
+
),
|
1329 |
+
CRYPT_DES_DECRYPT => array_merge(
|
1330 |
+
$keys[2][CRYPT_DES_DECRYPT],
|
1331 |
+
$keys[1][CRYPT_DES_ENCRYPT],
|
1332 |
+
$keys[0][CRYPT_DES_DECRYPT]
|
1333 |
+
)
|
1334 |
+
);
|
1335 |
+
break;
|
1336 |
+
// case 1: // DES keys
|
1337 |
+
default:
|
1338 |
+
$this->keys = array(
|
1339 |
+
CRYPT_DES_ENCRYPT => $keys[0][CRYPT_DES_ENCRYPT],
|
1340 |
+
CRYPT_DES_DECRYPT => $keys[0][CRYPT_DES_DECRYPT]
|
1341 |
+
);
|
1342 |
+
}
|
1343 |
+
}
|
1344 |
+
|
1345 |
+
/**
|
1346 |
+
* Setup the performance-optimized function for de/encrypt()
|
1347 |
+
*
|
1348 |
+
* @see Crypt_Base::_setupInlineCrypt()
|
1349 |
+
* @access private
|
1350 |
+
*/
|
1351 |
+
function _setupInlineCrypt()
|
1352 |
+
{
|
1353 |
+
$lambda_functions =& Crypt_DES::_getLambdaFunctions();
|
1354 |
+
|
1355 |
+
// Engine configuration for:
|
1356 |
+
// - DES ($des_rounds == 1) or
|
1357 |
+
// - 3DES ($des_rounds == 3)
|
1358 |
+
$des_rounds = $this->des_rounds;
|
1359 |
+
|
1360 |
+
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
|
1361 |
+
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one
|
1362 |
+
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
|
1363 |
+
|
1364 |
+
// Generation of a uniqe hash for our generated code
|
1365 |
+
switch (true) {
|
1366 |
+
case $gen_hi_opt_code:
|
1367 |
+
// For hi-optimized code, we create for each combination of
|
1368 |
+
// $mode, $des_rounds and $this->key its own encrypt/decrypt function.
|
1369 |
+
$code_hash = md5(str_pad("Crypt_DES, $des_rounds, {$this->mode}, ", 32, "\0") . $this->key);
|
1370 |
+
break;
|
1371 |
+
default:
|
1372 |
+
// After max 10 hi-optimized functions, we create generic
|
1373 |
+
// (still very fast.. but not ultra) functions for each $mode/$des_rounds
|
1374 |
+
// Currently 2 * 5 generic functions will be then max. possible.
|
1375 |
+
$code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
// Is there a re-usable $lambda_functions in there? If not, we have to create it.
|
1379 |
+
if (!isset($lambda_functions[$code_hash])) {
|
1380 |
+
// Init code for both, encrypt and decrypt.
|
1381 |
+
$init_crypt = 'static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
|
1382 |
+
if (!$sbox1) {
|
1383 |
+
$sbox1 = array_map("intval", $self->sbox1);
|
1384 |
+
$sbox2 = array_map("intval", $self->sbox2);
|
1385 |
+
$sbox3 = array_map("intval", $self->sbox3);
|
1386 |
+
$sbox4 = array_map("intval", $self->sbox4);
|
1387 |
+
$sbox5 = array_map("intval", $self->sbox5);
|
1388 |
+
$sbox6 = array_map("intval", $self->sbox6);
|
1389 |
+
$sbox7 = array_map("intval", $self->sbox7);
|
1390 |
+
$sbox8 = array_map("intval", $self->sbox8);'
|
1391 |
+
/* Merge $shuffle with $[inv]ipmap */ . '
|
1392 |
+
for ($i = 0; $i < 256; ++$i) {
|
1393 |
+
$shuffleip[] = $self->shuffle[$self->ipmap[$i]];
|
1394 |
+
$shuffleinvip[] = $self->shuffle[$self->invipmap[$i]];
|
1395 |
+
}
|
1396 |
+
}
|
1397 |
+
';
|
1398 |
+
|
1399 |
+
switch (true) {
|
1400 |
+
case $gen_hi_opt_code:
|
1401 |
+
// In Hi-optimized code mode, we use our [3]DES key schedule as hardcoded integers.
|
1402 |
+
// No futher initialisation of the $keys schedule is necessary.
|
1403 |
+
// That is the extra performance boost.
|
1404 |
+
$k = array(
|
1405 |
+
CRYPT_DES_ENCRYPT => $this->keys[CRYPT_DES_ENCRYPT],
|
1406 |
+
CRYPT_DES_DECRYPT => $this->keys[CRYPT_DES_DECRYPT]
|
1407 |
+
);
|
1408 |
+
$init_encrypt = '';
|
1409 |
+
$init_decrypt = '';
|
1410 |
+
break;
|
1411 |
+
default:
|
1412 |
+
// In generic optimized code mode, we have to use, as the best compromise [currently],
|
1413 |
+
// our key schedule as $ke/$kd arrays. (with hardcoded indexes...)
|
1414 |
+
$k = array(
|
1415 |
+
CRYPT_DES_ENCRYPT => array(),
|
1416 |
+
CRYPT_DES_DECRYPT => array()
|
1417 |
+
);
|
1418 |
+
for ($i = 0, $c = count($this->keys[CRYPT_DES_ENCRYPT]); $i < $c; ++$i) {
|
1419 |
+
$k[CRYPT_DES_ENCRYPT][$i] = '$ke[' . $i . ']';
|
1420 |
+
$k[CRYPT_DES_DECRYPT][$i] = '$kd[' . $i . ']';
|
1421 |
+
}
|
1422 |
+
$init_encrypt = '$ke = $self->keys[CRYPT_DES_ENCRYPT];';
|
1423 |
+
$init_decrypt = '$kd = $self->keys[CRYPT_DES_DECRYPT];';
|
1424 |
+
break;
|
1425 |
+
}
|
1426 |
+
|
1427 |
+
// Creating code for en- and decryption.
|
1428 |
+
$crypt_block = array();
|
1429 |
+
foreach (array(CRYPT_DES_ENCRYPT, CRYPT_DES_DECRYPT) as $c) {
|
1430 |
+
|
1431 |
+
/* Do the initial IP permutation. */
|
1432 |
+
$crypt_block[$c] = '
|
1433 |
+
$in = unpack("N*", $in);
|
1434 |
+
$l = $in[1];
|
1435 |
+
$r = $in[2];
|
1436 |
+
$in = unpack("N*",
|
1437 |
+
($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
1438 |
+
($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
1439 |
+
($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
1440 |
+
($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
1441 |
+
($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
1442 |
+
($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
1443 |
+
($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
1444 |
+
($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01")
|
1445 |
+
);
|
1446 |
+
' . /* Extract L0 and R0 */ '
|
1447 |
+
$l = $in[1];
|
1448 |
+
$r = $in[2];
|
1449 |
+
';
|
1450 |
+
|
1451 |
+
$l = '$l';
|
1452 |
+
$r = '$r';
|
1453 |
+
|
1454 |
+
// Perform DES or 3DES.
|
1455 |
+
for ($ki = -1, $des_round = 0; $des_round < $des_rounds; ++$des_round) {
|
1456 |
+
// Perform the 16 steps.
|
1457 |
+
for ($i = 0; $i < 16; ++$i) {
|
1458 |
+
// start of "the Feistel (F) function" - see the following URL:
|
1459 |
+
// http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
|
1460 |
+
// Merge key schedule.
|
1461 |
+
$crypt_block[$c].= '
|
1462 |
+
$b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . ';
|
1463 |
+
$b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $k[$c][++$ki] . ';' .
|
1464 |
+
/* S-box indexing. */
|
1465 |
+
$l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
|
1466 |
+
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
|
1467 |
+
$sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
|
1468 |
+
$sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ ' . $l . ';
|
1469 |
+
';
|
1470 |
+
// end of "the Feistel (F) function"
|
1471 |
+
|
1472 |
+
// swap L & R
|
1473 |
+
list($l, $r) = array($r, $l);
|
1474 |
+
}
|
1475 |
+
list($l, $r) = array($r, $l);
|
1476 |
+
}
|
1477 |
+
|
1478 |
+
// Perform the inverse IP permutation.
|
1479 |
+
$crypt_block[$c].= '$in =
|
1480 |
+
($shuffleinvip[($l >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
1481 |
+
($shuffleinvip[($r >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
1482 |
+
($shuffleinvip[($l >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
1483 |
+
($shuffleinvip[($r >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
1484 |
+
($shuffleinvip[($l >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
1485 |
+
($shuffleinvip[($r >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
1486 |
+
($shuffleinvip[ $l & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
1487 |
+
($shuffleinvip[ $r & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
|
1488 |
+
';
|
1489 |
+
}
|
1490 |
+
|
1491 |
+
// Creates the inline-crypt function
|
1492 |
+
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
|
1493 |
+
array(
|
1494 |
+
'init_crypt' => $init_crypt,
|
1495 |
+
'init_encrypt' => $init_encrypt,
|
1496 |
+
'init_decrypt' => $init_decrypt,
|
1497 |
+
'encrypt_block' => $crypt_block[CRYPT_DES_ENCRYPT],
|
1498 |
+
'decrypt_block' => $crypt_block[CRYPT_DES_DECRYPT]
|
1499 |
+
)
|
1500 |
+
);
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
// Set the inline-crypt function as callback in: $this->inline_crypt
|
1504 |
+
$this->inline_crypt = $lambda_functions[$code_hash];
|
1505 |
+
}
|
1506 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Hash.php
ADDED
@@ -0,0 +1,841 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
|
5 |
+
*
|
6 |
+
* Uses hash() or mhash() if available and an internal implementation, otherwise. Currently supports the following:
|
7 |
+
*
|
8 |
+
* md2, md5, md5-96, sha1, sha1-96, sha256, sha256-96, sha384, and sha512, sha512-96
|
9 |
+
*
|
10 |
+
* If {@link Crypt_Hash::setKey() setKey()} is called, {@link Crypt_Hash::hash() hash()} will return the HMAC as opposed to
|
11 |
+
* the hash. If no valid algorithm is provided, sha1 will be used.
|
12 |
+
*
|
13 |
+
* PHP versions 4 and 5
|
14 |
+
*
|
15 |
+
* {@internal The variable names are the same as those in
|
16 |
+
* {@link http://tools.ietf.org/html/rfc2104#section-2 RFC2104}.}}
|
17 |
+
*
|
18 |
+
* Here's a short example of how to use this library:
|
19 |
+
* <code>
|
20 |
+
* <?php
|
21 |
+
* include 'Crypt/Hash.php';
|
22 |
+
*
|
23 |
+
* $hash = new Crypt_Hash('sha1');
|
24 |
+
*
|
25 |
+
* $hash->setKey('abcdefg');
|
26 |
+
*
|
27 |
+
* echo base64_encode($hash->hash('abcdefg'));
|
28 |
+
* ?>
|
29 |
+
* </code>
|
30 |
+
*
|
31 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
32 |
+
* of this software and associated documentation files (the "Software"), to deal
|
33 |
+
* in the Software without restriction, including without limitation the rights
|
34 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
35 |
+
* copies of the Software, and to permit persons to whom the Software is
|
36 |
+
* furnished to do so, subject to the following conditions:
|
37 |
+
*
|
38 |
+
* The above copyright notice and this permission notice shall be included in
|
39 |
+
* all copies or substantial portions of the Software.
|
40 |
+
*
|
41 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
42 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
43 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
44 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
45 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
46 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
47 |
+
* THE SOFTWARE.
|
48 |
+
*
|
49 |
+
* @category Crypt
|
50 |
+
* @package Crypt_Hash
|
51 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
52 |
+
* @copyright 2007 Jim Wigginton
|
53 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
54 |
+
* @link http://phpseclib.sourceforge.net
|
55 |
+
*/
|
56 |
+
|
57 |
+
/**#@+
|
58 |
+
* @access private
|
59 |
+
* @see Crypt_Hash::Crypt_Hash()
|
60 |
+
*/
|
61 |
+
/**
|
62 |
+
* Toggles the internal implementation
|
63 |
+
*/
|
64 |
+
define('CRYPT_HASH_MODE_INTERNAL', 1);
|
65 |
+
/**
|
66 |
+
* Toggles the mhash() implementation, which has been deprecated on PHP 5.3.0+.
|
67 |
+
*/
|
68 |
+
define('CRYPT_HASH_MODE_MHASH', 2);
|
69 |
+
/**
|
70 |
+
* Toggles the hash() implementation, which works on PHP 5.1.2+.
|
71 |
+
*/
|
72 |
+
define('CRYPT_HASH_MODE_HASH', 3);
|
73 |
+
/**#@-*/
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
|
77 |
+
*
|
78 |
+
* @package Crypt_Hash
|
79 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
80 |
+
* @access public
|
81 |
+
*/
|
82 |
+
class Crypt_Hash
|
83 |
+
{
|
84 |
+
/**
|
85 |
+
* Hash Parameter
|
86 |
+
*
|
87 |
+
* @see Crypt_Hash::setHash()
|
88 |
+
* @var Integer
|
89 |
+
* @access private
|
90 |
+
*/
|
91 |
+
var $hashParam;
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Byte-length of compression blocks / key (Internal HMAC)
|
95 |
+
*
|
96 |
+
* @see Crypt_Hash::setAlgorithm()
|
97 |
+
* @var Integer
|
98 |
+
* @access private
|
99 |
+
*/
|
100 |
+
var $b;
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Byte-length of hash output (Internal HMAC)
|
104 |
+
*
|
105 |
+
* @see Crypt_Hash::setHash()
|
106 |
+
* @var Integer
|
107 |
+
* @access private
|
108 |
+
*/
|
109 |
+
var $l = false;
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Hash Algorithm
|
113 |
+
*
|
114 |
+
* @see Crypt_Hash::setHash()
|
115 |
+
* @var String
|
116 |
+
* @access private
|
117 |
+
*/
|
118 |
+
var $hash;
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Key
|
122 |
+
*
|
123 |
+
* @see Crypt_Hash::setKey()
|
124 |
+
* @var String
|
125 |
+
* @access private
|
126 |
+
*/
|
127 |
+
var $key = false;
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Outer XOR (Internal HMAC)
|
131 |
+
*
|
132 |
+
* @see Crypt_Hash::setKey()
|
133 |
+
* @var String
|
134 |
+
* @access private
|
135 |
+
*/
|
136 |
+
var $opad;
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Inner XOR (Internal HMAC)
|
140 |
+
*
|
141 |
+
* @see Crypt_Hash::setKey()
|
142 |
+
* @var String
|
143 |
+
* @access private
|
144 |
+
*/
|
145 |
+
var $ipad;
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Default Constructor.
|
149 |
+
*
|
150 |
+
* @param optional String $hash
|
151 |
+
* @return Crypt_Hash
|
152 |
+
* @access public
|
153 |
+
*/
|
154 |
+
function Crypt_Hash($hash = 'sha1')
|
155 |
+
{
|
156 |
+
if ( !defined('CRYPT_HASH_MODE') ) {
|
157 |
+
switch (true) {
|
158 |
+
case extension_loaded('hash'):
|
159 |
+
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH);
|
160 |
+
break;
|
161 |
+
case extension_loaded('mhash'):
|
162 |
+
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_MHASH);
|
163 |
+
break;
|
164 |
+
default:
|
165 |
+
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL);
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
$this->setHash($hash);
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Sets the key for HMACs
|
174 |
+
*
|
175 |
+
* Keys can be of any length.
|
176 |
+
*
|
177 |
+
* @access public
|
178 |
+
* @param optional String $key
|
179 |
+
*/
|
180 |
+
function setKey($key = false)
|
181 |
+
{
|
182 |
+
$this->key = $key;
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Gets the hash function.
|
187 |
+
*
|
188 |
+
* As set by the constructor or by the setHash() method.
|
189 |
+
*
|
190 |
+
* @access public
|
191 |
+
* @return String
|
192 |
+
*/
|
193 |
+
function getHash()
|
194 |
+
{
|
195 |
+
return $this->hashParam;
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Sets the hash function.
|
200 |
+
*
|
201 |
+
* @access public
|
202 |
+
* @param String $hash
|
203 |
+
*/
|
204 |
+
function setHash($hash)
|
205 |
+
{
|
206 |
+
$this->hashParam = $hash = strtolower($hash);
|
207 |
+
switch ($hash) {
|
208 |
+
case 'md5-96':
|
209 |
+
case 'sha1-96':
|
210 |
+
case 'sha256-96':
|
211 |
+
case 'sha512-96':
|
212 |
+
$hash = substr($hash, 0, -3);
|
213 |
+
$this->l = 12; // 96 / 8 = 12
|
214 |
+
break;
|
215 |
+
case 'md2':
|
216 |
+
case 'md5':
|
217 |
+
$this->l = 16;
|
218 |
+
break;
|
219 |
+
case 'sha1':
|
220 |
+
$this->l = 20;
|
221 |
+
break;
|
222 |
+
case 'sha256':
|
223 |
+
$this->l = 32;
|
224 |
+
break;
|
225 |
+
case 'sha384':
|
226 |
+
$this->l = 48;
|
227 |
+
break;
|
228 |
+
case 'sha512':
|
229 |
+
$this->l = 64;
|
230 |
+
}
|
231 |
+
|
232 |
+
switch ($hash) {
|
233 |
+
case 'md2':
|
234 |
+
$mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ?
|
235 |
+
CRYPT_HASH_MODE_HASH : CRYPT_HASH_MODE_INTERNAL;
|
236 |
+
break;
|
237 |
+
case 'sha384':
|
238 |
+
case 'sha512':
|
239 |
+
$mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
|
240 |
+
break;
|
241 |
+
default:
|
242 |
+
$mode = CRYPT_HASH_MODE;
|
243 |
+
}
|
244 |
+
|
245 |
+
switch ( $mode ) {
|
246 |
+
case CRYPT_HASH_MODE_MHASH:
|
247 |
+
switch ($hash) {
|
248 |
+
case 'md5':
|
249 |
+
$this->hash = MHASH_MD5;
|
250 |
+
break;
|
251 |
+
case 'sha256':
|
252 |
+
$this->hash = MHASH_SHA256;
|
253 |
+
break;
|
254 |
+
case 'sha1':
|
255 |
+
default:
|
256 |
+
$this->hash = MHASH_SHA1;
|
257 |
+
}
|
258 |
+
return;
|
259 |
+
case CRYPT_HASH_MODE_HASH:
|
260 |
+
switch ($hash) {
|
261 |
+
case 'md5':
|
262 |
+
$this->hash = 'md5';
|
263 |
+
return;
|
264 |
+
case 'md2':
|
265 |
+
case 'sha256':
|
266 |
+
case 'sha384':
|
267 |
+
case 'sha512':
|
268 |
+
$this->hash = $hash;
|
269 |
+
return;
|
270 |
+
case 'sha1':
|
271 |
+
default:
|
272 |
+
$this->hash = 'sha1';
|
273 |
+
}
|
274 |
+
return;
|
275 |
+
}
|
276 |
+
|
277 |
+
switch ($hash) {
|
278 |
+
case 'md2':
|
279 |
+
$this->b = 16;
|
280 |
+
$this->hash = array($this, '_md2');
|
281 |
+
break;
|
282 |
+
case 'md5':
|
283 |
+
$this->b = 64;
|
284 |
+
$this->hash = array($this, '_md5');
|
285 |
+
break;
|
286 |
+
case 'sha256':
|
287 |
+
$this->b = 64;
|
288 |
+
$this->hash = array($this, '_sha256');
|
289 |
+
break;
|
290 |
+
case 'sha384':
|
291 |
+
case 'sha512':
|
292 |
+
$this->b = 128;
|
293 |
+
$this->hash = array($this, '_sha512');
|
294 |
+
break;
|
295 |
+
case 'sha1':
|
296 |
+
default:
|
297 |
+
$this->b = 64;
|
298 |
+
$this->hash = array($this, '_sha1');
|
299 |
+
}
|
300 |
+
|
301 |
+
$this->ipad = str_repeat(chr(0x36), $this->b);
|
302 |
+
$this->opad = str_repeat(chr(0x5C), $this->b);
|
303 |
+
}
|
304 |
+
|
305 |
+
/**
|
306 |
+
* Compute the HMAC.
|
307 |
+
*
|
308 |
+
* @access public
|
309 |
+
* @param String $text
|
310 |
+
* @return String
|
311 |
+
*/
|
312 |
+
function hash($text)
|
313 |
+
{
|
314 |
+
$mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
|
315 |
+
|
316 |
+
if (!empty($this->key) || is_string($this->key)) {
|
317 |
+
switch ( $mode ) {
|
318 |
+
case CRYPT_HASH_MODE_MHASH:
|
319 |
+
$output = mhash($this->hash, $text, $this->key);
|
320 |
+
break;
|
321 |
+
case CRYPT_HASH_MODE_HASH:
|
322 |
+
$output = hash_hmac($this->hash, $text, $this->key, true);
|
323 |
+
break;
|
324 |
+
case CRYPT_HASH_MODE_INTERNAL:
|
325 |
+
/* "Applications that use keys longer than B bytes will first hash the key using H and then use the
|
326 |
+
resultant L byte string as the actual key to HMAC."
|
327 |
+
|
328 |
+
-- http://tools.ietf.org/html/rfc2104#section-2 */
|
329 |
+
$key = strlen($this->key) > $this->b ? call_user_func($this->hash, $this->key) : $this->key;
|
330 |
+
|
331 |
+
$key = str_pad($key, $this->b, chr(0)); // step 1
|
332 |
+
$temp = $this->ipad ^ $key; // step 2
|
333 |
+
$temp .= $text; // step 3
|
334 |
+
$temp = call_user_func($this->hash, $temp); // step 4
|
335 |
+
$output = $this->opad ^ $key; // step 5
|
336 |
+
$output.= $temp; // step 6
|
337 |
+
$output = call_user_func($this->hash, $output); // step 7
|
338 |
+
}
|
339 |
+
} else {
|
340 |
+
switch ( $mode ) {
|
341 |
+
case CRYPT_HASH_MODE_MHASH:
|
342 |
+
$output = mhash($this->hash, $text);
|
343 |
+
break;
|
344 |
+
case CRYPT_HASH_MODE_HASH:
|
345 |
+
$output = hash($this->hash, $text, true);
|
346 |
+
break;
|
347 |
+
case CRYPT_HASH_MODE_INTERNAL:
|
348 |
+
$output = call_user_func($this->hash, $text);
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
return substr($output, 0, $this->l);
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Returns the hash length (in bytes)
|
357 |
+
*
|
358 |
+
* @access public
|
359 |
+
* @return Integer
|
360 |
+
*/
|
361 |
+
function getLength()
|
362 |
+
{
|
363 |
+
return $this->l;
|
364 |
+
}
|
365 |
+
|
366 |
+
/**
|
367 |
+
* Wrapper for MD5
|
368 |
+
*
|
369 |
+
* @access private
|
370 |
+
* @param String $m
|
371 |
+
*/
|
372 |
+
function _md5($m)
|
373 |
+
{
|
374 |
+
return pack('H*', md5($m));
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Wrapper for SHA1
|
379 |
+
*
|
380 |
+
* @access private
|
381 |
+
* @param String $m
|
382 |
+
*/
|
383 |
+
function _sha1($m)
|
384 |
+
{
|
385 |
+
return pack('H*', sha1($m));
|
386 |
+
}
|
387 |
+
|
388 |
+
/**
|
389 |
+
* Pure-PHP implementation of MD2
|
390 |
+
*
|
391 |
+
* See {@link http://tools.ietf.org/html/rfc1319 RFC1319}.
|
392 |
+
*
|
393 |
+
* @access private
|
394 |
+
* @param String $m
|
395 |
+
*/
|
396 |
+
function _md2($m)
|
397 |
+
{
|
398 |
+
static $s = array(
|
399 |
+
41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
|
400 |
+
19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
|
401 |
+
76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
|
402 |
+
138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
|
403 |
+
245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
|
404 |
+
148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
|
405 |
+
39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
|
406 |
+
181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
|
407 |
+
150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
|
408 |
+
112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
|
409 |
+
96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
|
410 |
+
85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
|
411 |
+
234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
|
412 |
+
129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
|
413 |
+
8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
|
414 |
+
203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
|
415 |
+
166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
|
416 |
+
31, 26, 219, 153, 141, 51, 159, 17, 131, 20
|
417 |
+
);
|
418 |
+
|
419 |
+
// Step 1. Append Padding Bytes
|
420 |
+
$pad = 16 - (strlen($m) & 0xF);
|
421 |
+
$m.= str_repeat(chr($pad), $pad);
|
422 |
+
|
423 |
+
$length = strlen($m);
|
424 |
+
|
425 |
+
// Step 2. Append Checksum
|
426 |
+
$c = str_repeat(chr(0), 16);
|
427 |
+
$l = chr(0);
|
428 |
+
for ($i = 0; $i < $length; $i+= 16) {
|
429 |
+
for ($j = 0; $j < 16; $j++) {
|
430 |
+
// RFC1319 incorrectly states that C[j] should be set to S[c xor L]
|
431 |
+
//$c[$j] = chr($s[ord($m[$i + $j] ^ $l)]);
|
432 |
+
// per <http://www.rfc-editor.org/errata_search.php?rfc=1319>, however, C[j] should be set to S[c xor L] xor C[j]
|
433 |
+
$c[$j] = chr($s[ord($m[$i + $j] ^ $l)] ^ ord($c[$j]));
|
434 |
+
$l = $c[$j];
|
435 |
+
}
|
436 |
+
}
|
437 |
+
$m.= $c;
|
438 |
+
|
439 |
+
$length+= 16;
|
440 |
+
|
441 |
+
// Step 3. Initialize MD Buffer
|
442 |
+
$x = str_repeat(chr(0), 48);
|
443 |
+
|
444 |
+
// Step 4. Process Message in 16-Byte Blocks
|
445 |
+
for ($i = 0; $i < $length; $i+= 16) {
|
446 |
+
for ($j = 0; $j < 16; $j++) {
|
447 |
+
$x[$j + 16] = $m[$i + $j];
|
448 |
+
$x[$j + 32] = $x[$j + 16] ^ $x[$j];
|
449 |
+
}
|
450 |
+
$t = chr(0);
|
451 |
+
for ($j = 0; $j < 18; $j++) {
|
452 |
+
for ($k = 0; $k < 48; $k++) {
|
453 |
+
$x[$k] = $t = $x[$k] ^ chr($s[ord($t)]);
|
454 |
+
//$t = $x[$k] = $x[$k] ^ chr($s[ord($t)]);
|
455 |
+
}
|
456 |
+
$t = chr(ord($t) + $j);
|
457 |
+
}
|
458 |
+
}
|
459 |
+
|
460 |
+
// Step 5. Output
|
461 |
+
return substr($x, 0, 16);
|
462 |
+
}
|
463 |
+
|
464 |
+
/**
|
465 |
+
* Pure-PHP implementation of SHA256
|
466 |
+
*
|
467 |
+
* See {@link http://en.wikipedia.org/wiki/SHA_hash_functions#SHA-256_.28a_SHA-2_variant.29_pseudocode SHA-256 (a SHA-2 variant) pseudocode - Wikipedia}.
|
468 |
+
*
|
469 |
+
* @access private
|
470 |
+
* @param String $m
|
471 |
+
*/
|
472 |
+
function _sha256($m)
|
473 |
+
{
|
474 |
+
if (extension_loaded('suhosin')) {
|
475 |
+
return pack('H*', sha256($m));
|
476 |
+
}
|
477 |
+
|
478 |
+
// Initialize variables
|
479 |
+
$hash = array(
|
480 |
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
481 |
+
);
|
482 |
+
// Initialize table of round constants
|
483 |
+
// (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
484 |
+
static $k = array(
|
485 |
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
486 |
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
487 |
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
488 |
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
489 |
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
490 |
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
491 |
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
492 |
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
493 |
+
);
|
494 |
+
|
495 |
+
// Pre-processing
|
496 |
+
$length = strlen($m);
|
497 |
+
// to round to nearest 56 mod 64, we'll add 64 - (length + (64 - 56)) % 64
|
498 |
+
$m.= str_repeat(chr(0), 64 - (($length + 8) & 0x3F));
|
499 |
+
$m[$length] = chr(0x80);
|
500 |
+
// we don't support hashing strings 512MB long
|
501 |
+
$m.= pack('N2', 0, $length << 3);
|
502 |
+
|
503 |
+
// Process the message in successive 512-bit chunks
|
504 |
+
$chunks = str_split($m, 64);
|
505 |
+
foreach ($chunks as $chunk) {
|
506 |
+
$w = array();
|
507 |
+
for ($i = 0; $i < 16; $i++) {
|
508 |
+
extract(unpack('Ntemp', $this->_string_shift($chunk, 4)));
|
509 |
+
$w[] = $temp;
|
510 |
+
}
|
511 |
+
|
512 |
+
// Extend the sixteen 32-bit words into sixty-four 32-bit words
|
513 |
+
for ($i = 16; $i < 64; $i++) {
|
514 |
+
$s0 = $this->_rightRotate($w[$i - 15], 7) ^
|
515 |
+
$this->_rightRotate($w[$i - 15], 18) ^
|
516 |
+
$this->_rightShift( $w[$i - 15], 3);
|
517 |
+
$s1 = $this->_rightRotate($w[$i - 2], 17) ^
|
518 |
+
$this->_rightRotate($w[$i - 2], 19) ^
|
519 |
+
$this->_rightShift( $w[$i - 2], 10);
|
520 |
+
$w[$i] = $this->_add($w[$i - 16], $s0, $w[$i - 7], $s1);
|
521 |
+
|
522 |
+
}
|
523 |
+
|
524 |
+
// Initialize hash value for this chunk
|
525 |
+
list($a, $b, $c, $d, $e, $f, $g, $h) = $hash;
|
526 |
+
|
527 |
+
// Main loop
|
528 |
+
for ($i = 0; $i < 64; $i++) {
|
529 |
+
$s0 = $this->_rightRotate($a, 2) ^
|
530 |
+
$this->_rightRotate($a, 13) ^
|
531 |
+
$this->_rightRotate($a, 22);
|
532 |
+
$maj = ($a & $b) ^
|
533 |
+
($a & $c) ^
|
534 |
+
($b & $c);
|
535 |
+
$t2 = $this->_add($s0, $maj);
|
536 |
+
|
537 |
+
$s1 = $this->_rightRotate($e, 6) ^
|
538 |
+
$this->_rightRotate($e, 11) ^
|
539 |
+
$this->_rightRotate($e, 25);
|
540 |
+
$ch = ($e & $f) ^
|
541 |
+
($this->_not($e) & $g);
|
542 |
+
$t1 = $this->_add($h, $s1, $ch, $k[$i], $w[$i]);
|
543 |
+
|
544 |
+
$h = $g;
|
545 |
+
$g = $f;
|
546 |
+
$f = $e;
|
547 |
+
$e = $this->_add($d, $t1);
|
548 |
+
$d = $c;
|
549 |
+
$c = $b;
|
550 |
+
$b = $a;
|
551 |
+
$a = $this->_add($t1, $t2);
|
552 |
+
}
|
553 |
+
|
554 |
+
// Add this chunk's hash to result so far
|
555 |
+
$hash = array(
|
556 |
+
$this->_add($hash[0], $a),
|
557 |
+
$this->_add($hash[1], $b),
|
558 |
+
$this->_add($hash[2], $c),
|
559 |
+
$this->_add($hash[3], $d),
|
560 |
+
$this->_add($hash[4], $e),
|
561 |
+
$this->_add($hash[5], $f),
|
562 |
+
$this->_add($hash[6], $g),
|
563 |
+
$this->_add($hash[7], $h)
|
564 |
+
);
|
565 |
+
}
|
566 |
+
|
567 |
+
// Produce the final hash value (big-endian)
|
568 |
+
return pack('N8', $hash[0], $hash[1], $hash[2], $hash[3], $hash[4], $hash[5], $hash[6], $hash[7]);
|
569 |
+
}
|
570 |
+
|
571 |
+
/**
|
572 |
+
* Pure-PHP implementation of SHA384 and SHA512
|
573 |
+
*
|
574 |
+
* @access private
|
575 |
+
* @param String $m
|
576 |
+
*/
|
577 |
+
function _sha512($m)
|
578 |
+
{
|
579 |
+
if (!class_exists('Math_BigInteger')) {
|
580 |
+
include_once 'Math/BigInteger.php';
|
581 |
+
}
|
582 |
+
|
583 |
+
static $init384, $init512, $k;
|
584 |
+
|
585 |
+
if (!isset($k)) {
|
586 |
+
// Initialize variables
|
587 |
+
$init384 = array( // initial values for SHA384
|
588 |
+
'cbbb9d5dc1059ed8', '629a292a367cd507', '9159015a3070dd17', '152fecd8f70e5939',
|
589 |
+
'67332667ffc00b31', '8eb44a8768581511', 'db0c2e0d64f98fa7', '47b5481dbefa4fa4'
|
590 |
+
);
|
591 |
+
$init512 = array( // initial values for SHA512
|
592 |
+
'6a09e667f3bcc908', 'bb67ae8584caa73b', '3c6ef372fe94f82b', 'a54ff53a5f1d36f1',
|
593 |
+
'510e527fade682d1', '9b05688c2b3e6c1f', '1f83d9abfb41bd6b', '5be0cd19137e2179'
|
594 |
+
);
|
595 |
+
|
596 |
+
for ($i = 0; $i < 8; $i++) {
|
597 |
+
$init384[$i] = new Math_BigInteger($init384[$i], 16);
|
598 |
+
$init384[$i]->setPrecision(64);
|
599 |
+
$init512[$i] = new Math_BigInteger($init512[$i], 16);
|
600 |
+
$init512[$i]->setPrecision(64);
|
601 |
+
}
|
602 |
+
|
603 |
+
// Initialize table of round constants
|
604 |
+
// (first 64 bits of the fractional parts of the cube roots of the first 80 primes 2..409)
|
605 |
+
$k = array(
|
606 |
+
'428a2f98d728ae22', '7137449123ef65cd', 'b5c0fbcfec4d3b2f', 'e9b5dba58189dbbc',
|
607 |
+
'3956c25bf348b538', '59f111f1b605d019', '923f82a4af194f9b', 'ab1c5ed5da6d8118',
|
608 |
+
'd807aa98a3030242', '12835b0145706fbe', '243185be4ee4b28c', '550c7dc3d5ffb4e2',
|
609 |
+
'72be5d74f27b896f', '80deb1fe3b1696b1', '9bdc06a725c71235', 'c19bf174cf692694',
|
610 |
+
'e49b69c19ef14ad2', 'efbe4786384f25e3', '0fc19dc68b8cd5b5', '240ca1cc77ac9c65',
|
611 |
+
'2de92c6f592b0275', '4a7484aa6ea6e483', '5cb0a9dcbd41fbd4', '76f988da831153b5',
|
612 |
+
'983e5152ee66dfab', 'a831c66d2db43210', 'b00327c898fb213f', 'bf597fc7beef0ee4',
|
613 |
+
'c6e00bf33da88fc2', 'd5a79147930aa725', '06ca6351e003826f', '142929670a0e6e70',
|
614 |
+
'27b70a8546d22ffc', '2e1b21385c26c926', '4d2c6dfc5ac42aed', '53380d139d95b3df',
|
615 |
+
'650a73548baf63de', '766a0abb3c77b2a8', '81c2c92e47edaee6', '92722c851482353b',
|
616 |
+
'a2bfe8a14cf10364', 'a81a664bbc423001', 'c24b8b70d0f89791', 'c76c51a30654be30',
|
617 |
+
'd192e819d6ef5218', 'd69906245565a910', 'f40e35855771202a', '106aa07032bbd1b8',
|
618 |
+
'19a4c116b8d2d0c8', '1e376c085141ab53', '2748774cdf8eeb99', '34b0bcb5e19b48a8',
|
619 |
+
'391c0cb3c5c95a63', '4ed8aa4ae3418acb', '5b9cca4f7763e373', '682e6ff3d6b2b8a3',
|
620 |
+
'748f82ee5defb2fc', '78a5636f43172f60', '84c87814a1f0ab72', '8cc702081a6439ec',
|
621 |
+
'90befffa23631e28', 'a4506cebde82bde9', 'bef9a3f7b2c67915', 'c67178f2e372532b',
|
622 |
+
'ca273eceea26619c', 'd186b8c721c0c207', 'eada7dd6cde0eb1e', 'f57d4f7fee6ed178',
|
623 |
+
'06f067aa72176fba', '0a637dc5a2c898a6', '113f9804bef90dae', '1b710b35131c471b',
|
624 |
+
'28db77f523047d84', '32caab7b40c72493', '3c9ebe0a15c9bebc', '431d67c49c100d4c',
|
625 |
+
'4cc5d4becb3e42b6', '597f299cfc657e2a', '5fcb6fab3ad6faec', '6c44198c4a475817'
|
626 |
+
);
|
627 |
+
|
628 |
+
for ($i = 0; $i < 80; $i++) {
|
629 |
+
$k[$i] = new Math_BigInteger($k[$i], 16);
|
630 |
+
}
|
631 |
+
}
|
632 |
+
|
633 |
+
$hash = $this->l == 48 ? $init384 : $init512;
|
634 |
+
|
635 |
+
// Pre-processing
|
636 |
+
$length = strlen($m);
|
637 |
+
// to round to nearest 112 mod 128, we'll add 128 - (length + (128 - 112)) % 128
|
638 |
+
$m.= str_repeat(chr(0), 128 - (($length + 16) & 0x7F));
|
639 |
+
$m[$length] = chr(0x80);
|
640 |
+
// we don't support hashing strings 512MB long
|
641 |
+
$m.= pack('N4', 0, 0, 0, $length << 3);
|
642 |
+
|
643 |
+
// Process the message in successive 1024-bit chunks
|
644 |
+
$chunks = str_split($m, 128);
|
645 |
+
foreach ($chunks as $chunk) {
|
646 |
+
$w = array();
|
647 |
+
for ($i = 0; $i < 16; $i++) {
|
648 |
+
$temp = new Math_BigInteger($this->_string_shift($chunk, 8), 256);
|
649 |
+
$temp->setPrecision(64);
|
650 |
+
$w[] = $temp;
|
651 |
+
}
|
652 |
+
|
653 |
+
// Extend the sixteen 32-bit words into eighty 32-bit words
|
654 |
+
for ($i = 16; $i < 80; $i++) {
|
655 |
+
$temp = array(
|
656 |
+
$w[$i - 15]->bitwise_rightRotate(1),
|
657 |
+
$w[$i - 15]->bitwise_rightRotate(8),
|
658 |
+
$w[$i - 15]->bitwise_rightShift(7)
|
659 |
+
);
|
660 |
+
$s0 = $temp[0]->bitwise_xor($temp[1]);
|
661 |
+
$s0 = $s0->bitwise_xor($temp[2]);
|
662 |
+
$temp = array(
|
663 |
+
$w[$i - 2]->bitwise_rightRotate(19),
|
664 |
+
$w[$i - 2]->bitwise_rightRotate(61),
|
665 |
+
$w[$i - 2]->bitwise_rightShift(6)
|
666 |
+
);
|
667 |
+
$s1 = $temp[0]->bitwise_xor($temp[1]);
|
668 |
+
$s1 = $s1->bitwise_xor($temp[2]);
|
669 |
+
$w[$i] = $w[$i - 16]->copy();
|
670 |
+
$w[$i] = $w[$i]->add($s0);
|
671 |
+
$w[$i] = $w[$i]->add($w[$i - 7]);
|
672 |
+
$w[$i] = $w[$i]->add($s1);
|
673 |
+
}
|
674 |
+
|
675 |
+
// Initialize hash value for this chunk
|
676 |
+
$a = $hash[0]->copy();
|
677 |
+
$b = $hash[1]->copy();
|
678 |
+
$c = $hash[2]->copy();
|
679 |
+
$d = $hash[3]->copy();
|
680 |
+
$e = $hash[4]->copy();
|
681 |
+
$f = $hash[5]->copy();
|
682 |
+
$g = $hash[6]->copy();
|
683 |
+
$h = $hash[7]->copy();
|
684 |
+
|
685 |
+
// Main loop
|
686 |
+
for ($i = 0; $i < 80; $i++) {
|
687 |
+
$temp = array(
|
688 |
+
$a->bitwise_rightRotate(28),
|
689 |
+
$a->bitwise_rightRotate(34),
|
690 |
+
$a->bitwise_rightRotate(39)
|
691 |
+
);
|
692 |
+
$s0 = $temp[0]->bitwise_xor($temp[1]);
|
693 |
+
$s0 = $s0->bitwise_xor($temp[2]);
|
694 |
+
$temp = array(
|
695 |
+
$a->bitwise_and($b),
|
696 |
+
$a->bitwise_and($c),
|
697 |
+
$b->bitwise_and($c)
|
698 |
+
);
|
699 |
+
$maj = $temp[0]->bitwise_xor($temp[1]);
|
700 |
+
$maj = $maj->bitwise_xor($temp[2]);
|
701 |
+
$t2 = $s0->add($maj);
|
702 |
+
|
703 |
+
$temp = array(
|
704 |
+
$e->bitwise_rightRotate(14),
|
705 |
+
$e->bitwise_rightRotate(18),
|
706 |
+
$e->bitwise_rightRotate(41)
|
707 |
+
);
|
708 |
+
$s1 = $temp[0]->bitwise_xor($temp[1]);
|
709 |
+
$s1 = $s1->bitwise_xor($temp[2]);
|
710 |
+
$temp = array(
|
711 |
+
$e->bitwise_and($f),
|
712 |
+
$g->bitwise_and($e->bitwise_not())
|
713 |
+
);
|
714 |
+
$ch = $temp[0]->bitwise_xor($temp[1]);
|
715 |
+
$t1 = $h->add($s1);
|
716 |
+
$t1 = $t1->add($ch);
|
717 |
+
$t1 = $t1->add($k[$i]);
|
718 |
+
$t1 = $t1->add($w[$i]);
|
719 |
+
|
720 |
+
$h = $g->copy();
|
721 |
+
$g = $f->copy();
|
722 |
+
$f = $e->copy();
|
723 |
+
$e = $d->add($t1);
|
724 |
+
$d = $c->copy();
|
725 |
+
$c = $b->copy();
|
726 |
+
$b = $a->copy();
|
727 |
+
$a = $t1->add($t2);
|
728 |
+
}
|
729 |
+
|
730 |
+
// Add this chunk's hash to result so far
|
731 |
+
$hash = array(
|
732 |
+
$hash[0]->add($a),
|
733 |
+
$hash[1]->add($b),
|
734 |
+
$hash[2]->add($c),
|
735 |
+
$hash[3]->add($d),
|
736 |
+
$hash[4]->add($e),
|
737 |
+
$hash[5]->add($f),
|
738 |
+
$hash[6]->add($g),
|
739 |
+
$hash[7]->add($h)
|
740 |
+
);
|
741 |
+
}
|
742 |
+
|
743 |
+
// Produce the final hash value (big-endian)
|
744 |
+
// (Crypt_Hash::hash() trims the output for hashes but not for HMACs. as such, we trim the output here)
|
745 |
+
$temp = $hash[0]->toBytes() . $hash[1]->toBytes() . $hash[2]->toBytes() . $hash[3]->toBytes() .
|
746 |
+
$hash[4]->toBytes() . $hash[5]->toBytes();
|
747 |
+
if ($this->l != 48) {
|
748 |
+
$temp.= $hash[6]->toBytes() . $hash[7]->toBytes();
|
749 |
+
}
|
750 |
+
|
751 |
+
return $temp;
|
752 |
+
}
|
753 |
+
|
754 |
+
/**
|
755 |
+
* Right Rotate
|
756 |
+
*
|
757 |
+
* @access private
|
758 |
+
* @param Integer $int
|
759 |
+
* @param Integer $amt
|
760 |
+
* @see _sha256()
|
761 |
+
* @return Integer
|
762 |
+
*/
|
763 |
+
function _rightRotate($int, $amt)
|
764 |
+
{
|
765 |
+
$invamt = 32 - $amt;
|
766 |
+
$mask = (1 << $invamt) - 1;
|
767 |
+
return (($int << $invamt) & 0xFFFFFFFF) | (($int >> $amt) & $mask);
|
768 |
+
}
|
769 |
+
|
770 |
+
/**
|
771 |
+
* Right Shift
|
772 |
+
*
|
773 |
+
* @access private
|
774 |
+
* @param Integer $int
|
775 |
+
* @param Integer $amt
|
776 |
+
* @see _sha256()
|
777 |
+
* @return Integer
|
778 |
+
*/
|
779 |
+
function _rightShift($int, $amt)
|
780 |
+
{
|
781 |
+
$mask = (1 << (32 - $amt)) - 1;
|
782 |
+
return ($int >> $amt) & $mask;
|
783 |
+
}
|
784 |
+
|
785 |
+
/**
|
786 |
+
* Not
|
787 |
+
*
|
788 |
+
* @access private
|
789 |
+
* @param Integer $int
|
790 |
+
* @see _sha256()
|
791 |
+
* @return Integer
|
792 |
+
*/
|
793 |
+
function _not($int)
|
794 |
+
{
|
795 |
+
return ~$int & 0xFFFFFFFF;
|
796 |
+
}
|
797 |
+
|
798 |
+
/**
|
799 |
+
* Add
|
800 |
+
*
|
801 |
+
* _sha256() adds multiple unsigned 32-bit integers. Since PHP doesn't support unsigned integers and since the
|
802 |
+
* possibility of overflow exists, care has to be taken. Math_BigInteger() could be used but this should be faster.
|
803 |
+
*
|
804 |
+
* @param Integer $...
|
805 |
+
* @return Integer
|
806 |
+
* @see _sha256()
|
807 |
+
* @access private
|
808 |
+
*/
|
809 |
+
function _add()
|
810 |
+
{
|
811 |
+
static $mod;
|
812 |
+
if (!isset($mod)) {
|
813 |
+
$mod = pow(2, 32);
|
814 |
+
}
|
815 |
+
|
816 |
+
$result = 0;
|
817 |
+
$arguments = func_get_args();
|
818 |
+
foreach ($arguments as $argument) {
|
819 |
+
$result+= $argument < 0 ? ($argument & 0x7FFFFFFF) + 0x80000000 : $argument;
|
820 |
+
}
|
821 |
+
|
822 |
+
return fmod($result, $mod);
|
823 |
+
}
|
824 |
+
|
825 |
+
/**
|
826 |
+
* String Shift
|
827 |
+
*
|
828 |
+
* Inspired by array_shift
|
829 |
+
*
|
830 |
+
* @param String $string
|
831 |
+
* @param optional Integer $index
|
832 |
+
* @return String
|
833 |
+
* @access private
|
834 |
+
*/
|
835 |
+
function _string_shift(&$string, $index = 1)
|
836 |
+
{
|
837 |
+
$substr = substr($string, 0, $index);
|
838 |
+
$string = substr($string, $index);
|
839 |
+
return $substr;
|
840 |
+
}
|
841 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/RC2.php
ADDED
@@ -0,0 +1,652 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of RC2.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* Useful resources are as follows:
|
11 |
+
*
|
12 |
+
* - {@link http://tools.ietf.org/html/rfc2268}
|
13 |
+
*
|
14 |
+
* Here's a short example of how to use this library:
|
15 |
+
* <code>
|
16 |
+
* <?php
|
17 |
+
* include 'Crypt/RC2.php';
|
18 |
+
*
|
19 |
+
* $rc2 = new Crypt_RC2();
|
20 |
+
*
|
21 |
+
* $rc2->setKey('abcdefgh');
|
22 |
+
*
|
23 |
+
* $plaintext = str_repeat('a', 1024);
|
24 |
+
*
|
25 |
+
* echo $rc2->decrypt($rc2->encrypt($plaintext));
|
26 |
+
* ?>
|
27 |
+
* </code>
|
28 |
+
*
|
29 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
30 |
+
* of this software and associated documentation files (the "Software"), to deal
|
31 |
+
* in the Software without restriction, including without limitation the rights
|
32 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
33 |
+
* copies of the Software, and to permit persons to whom the Software is
|
34 |
+
* furnished to do so, subject to the following conditions:
|
35 |
+
*
|
36 |
+
* The above copyright notice and this permission notice shall be included in
|
37 |
+
* all copies or substantial portions of the Software.
|
38 |
+
*
|
39 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
40 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
41 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
42 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
43 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
44 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
45 |
+
* THE SOFTWARE.
|
46 |
+
*
|
47 |
+
* @category Crypt
|
48 |
+
* @package Crypt_RC2
|
49 |
+
* @author Patrick Monnerat <pm@datasphere.ch>
|
50 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
51 |
+
* @link http://phpseclib.sourceforge.net
|
52 |
+
*/
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Include Crypt_Base
|
56 |
+
*
|
57 |
+
* Base cipher class
|
58 |
+
*/
|
59 |
+
if (!class_exists('Crypt_Base')) {
|
60 |
+
include_once 'Base.php';
|
61 |
+
}
|
62 |
+
|
63 |
+
/**#@+
|
64 |
+
* @access public
|
65 |
+
* @see Crypt_RC2::encrypt()
|
66 |
+
* @see Crypt_RC2::decrypt()
|
67 |
+
*/
|
68 |
+
/**
|
69 |
+
* Encrypt / decrypt using the Counter mode.
|
70 |
+
*
|
71 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
72 |
+
*
|
73 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
74 |
+
*/
|
75 |
+
define('CRYPT_RC2_MODE_CTR', CRYPT_MODE_CTR);
|
76 |
+
/**
|
77 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
78 |
+
*
|
79 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
80 |
+
*/
|
81 |
+
define('CRYPT_RC2_MODE_ECB', CRYPT_MODE_ECB);
|
82 |
+
/**
|
83 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
84 |
+
*
|
85 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
86 |
+
*/
|
87 |
+
define('CRYPT_RC2_MODE_CBC', CRYPT_MODE_CBC);
|
88 |
+
/**
|
89 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
90 |
+
*
|
91 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
92 |
+
*/
|
93 |
+
define('CRYPT_RC2_MODE_CFB', CRYPT_MODE_CFB);
|
94 |
+
/**
|
95 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
96 |
+
*
|
97 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
98 |
+
*/
|
99 |
+
define('CRYPT_RC2_MODE_OFB', CRYPT_MODE_OFB);
|
100 |
+
/**#@-*/
|
101 |
+
|
102 |
+
/**#@+
|
103 |
+
* @access private
|
104 |
+
* @see Crypt_RC2::Crypt_RC2()
|
105 |
+
*/
|
106 |
+
/**
|
107 |
+
* Toggles the internal implementation
|
108 |
+
*/
|
109 |
+
define('CRYPT_RC2_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
110 |
+
/**
|
111 |
+
* Toggles the mcrypt implementation
|
112 |
+
*/
|
113 |
+
define('CRYPT_RC2_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
114 |
+
/**#@-*/
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Pure-PHP implementation of RC2.
|
118 |
+
*
|
119 |
+
* @package Crypt_RC2
|
120 |
+
* @access public
|
121 |
+
*/
|
122 |
+
class Crypt_RC2 extends Crypt_Base
|
123 |
+
{
|
124 |
+
/**
|
125 |
+
* Block Length of the cipher
|
126 |
+
*
|
127 |
+
* @see Crypt_Base::block_size
|
128 |
+
* @var Integer
|
129 |
+
* @access private
|
130 |
+
*/
|
131 |
+
var $block_size = 8;
|
132 |
+
|
133 |
+
/**
|
134 |
+
* The Key
|
135 |
+
*
|
136 |
+
* @see Crypt_Base::key
|
137 |
+
* @see setKey()
|
138 |
+
* @var String
|
139 |
+
* @access private
|
140 |
+
*/
|
141 |
+
var $key = "\0";
|
142 |
+
|
143 |
+
/**
|
144 |
+
* The default password key_size used by setPassword()
|
145 |
+
*
|
146 |
+
* @see Crypt_Base::password_key_size
|
147 |
+
* @see Crypt_Base::setPassword()
|
148 |
+
* @var Integer
|
149 |
+
* @access private
|
150 |
+
*/
|
151 |
+
var $password_key_size = 16; // = 128 bits
|
152 |
+
|
153 |
+
/**
|
154 |
+
* The namespace used by the cipher for its constants.
|
155 |
+
*
|
156 |
+
* @see Crypt_Base::const_namespace
|
157 |
+
* @var String
|
158 |
+
* @access private
|
159 |
+
*/
|
160 |
+
var $const_namespace = 'RC2';
|
161 |
+
|
162 |
+
/**
|
163 |
+
* The mcrypt specific name of the cipher
|
164 |
+
*
|
165 |
+
* @see Crypt_Base::cipher_name_mcrypt
|
166 |
+
* @var String
|
167 |
+
* @access private
|
168 |
+
*/
|
169 |
+
var $cipher_name_mcrypt = 'rc2';
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Optimizing value while CFB-encrypting
|
173 |
+
*
|
174 |
+
* @see Crypt_Base::cfb_init_len
|
175 |
+
* @var Integer
|
176 |
+
* @access private
|
177 |
+
*/
|
178 |
+
var $cfb_init_len = 500;
|
179 |
+
|
180 |
+
/**
|
181 |
+
* The key length in bits.
|
182 |
+
*
|
183 |
+
* @see Crypt_RC2::setKeyLength()
|
184 |
+
* @see Crypt_RC2::setKey()
|
185 |
+
* @var Integer
|
186 |
+
* @access private
|
187 |
+
* @internal Should be in range [1..1024].
|
188 |
+
* @internal Changing this value after setting the key has no effect.
|
189 |
+
*/
|
190 |
+
var $default_key_length = 1024;
|
191 |
+
|
192 |
+
/**
|
193 |
+
* The Key Schedule
|
194 |
+
*
|
195 |
+
* @see Crypt_RC2::_setupKey()
|
196 |
+
* @var Array
|
197 |
+
* @access private
|
198 |
+
*/
|
199 |
+
var $keys;
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Key expansion randomization table.
|
203 |
+
* Twice the same 256-value sequence to save a modulus in key expansion.
|
204 |
+
*
|
205 |
+
* @see Crypt_RC2::setKey()
|
206 |
+
* @var Array
|
207 |
+
* @access private
|
208 |
+
*/
|
209 |
+
var $pitable = array(
|
210 |
+
0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED,
|
211 |
+
0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D,
|
212 |
+
0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E,
|
213 |
+
0x62, 0x4C, 0x64, 0x88, 0x44, 0x8B, 0xFB, 0xA2,
|
214 |
+
0x17, 0x9A, 0x59, 0xF5, 0x87, 0xB3, 0x4F, 0x13,
|
215 |
+
0x61, 0x45, 0x6D, 0x8D, 0x09, 0x81, 0x7D, 0x32,
|
216 |
+
0xBD, 0x8F, 0x40, 0xEB, 0x86, 0xB7, 0x7B, 0x0B,
|
217 |
+
0xF0, 0x95, 0x21, 0x22, 0x5C, 0x6B, 0x4E, 0x82,
|
218 |
+
0x54, 0xD6, 0x65, 0x93, 0xCE, 0x60, 0xB2, 0x1C,
|
219 |
+
0x73, 0x56, 0xC0, 0x14, 0xA7, 0x8C, 0xF1, 0xDC,
|
220 |
+
0x12, 0x75, 0xCA, 0x1F, 0x3B, 0xBE, 0xE4, 0xD1,
|
221 |
+
0x42, 0x3D, 0xD4, 0x30, 0xA3, 0x3C, 0xB6, 0x26,
|
222 |
+
0x6F, 0xBF, 0x0E, 0xDA, 0x46, 0x69, 0x07, 0x57,
|
223 |
+
0x27, 0xF2, 0x1D, 0x9B, 0xBC, 0x94, 0x43, 0x03,
|
224 |
+
0xF8, 0x11, 0xC7, 0xF6, 0x90, 0xEF, 0x3E, 0xE7,
|
225 |
+
0x06, 0xC3, 0xD5, 0x2F, 0xC8, 0x66, 0x1E, 0xD7,
|
226 |
+
0x08, 0xE8, 0xEA, 0xDE, 0x80, 0x52, 0xEE, 0xF7,
|
227 |
+
0x84, 0xAA, 0x72, 0xAC, 0x35, 0x4D, 0x6A, 0x2A,
|
228 |
+
0x96, 0x1A, 0xD2, 0x71, 0x5A, 0x15, 0x49, 0x74,
|
229 |
+
0x4B, 0x9F, 0xD0, 0x5E, 0x04, 0x18, 0xA4, 0xEC,
|
230 |
+
0xC2, 0xE0, 0x41, 0x6E, 0x0F, 0x51, 0xCB, 0xCC,
|
231 |
+
0x24, 0x91, 0xAF, 0x50, 0xA1, 0xF4, 0x70, 0x39,
|
232 |
+
0x99, 0x7C, 0x3A, 0x85, 0x23, 0xB8, 0xB4, 0x7A,
|
233 |
+
0xFC, 0x02, 0x36, 0x5B, 0x25, 0x55, 0x97, 0x31,
|
234 |
+
0x2D, 0x5D, 0xFA, 0x98, 0xE3, 0x8A, 0x92, 0xAE,
|
235 |
+
0x05, 0xDF, 0x29, 0x10, 0x67, 0x6C, 0xBA, 0xC9,
|
236 |
+
0xD3, 0x00, 0xE6, 0xCF, 0xE1, 0x9E, 0xA8, 0x2C,
|
237 |
+
0x63, 0x16, 0x01, 0x3F, 0x58, 0xE2, 0x89, 0xA9,
|
238 |
+
0x0D, 0x38, 0x34, 0x1B, 0xAB, 0x33, 0xFF, 0xB0,
|
239 |
+
0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E,
|
240 |
+
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77,
|
241 |
+
0x0A, 0xA6, 0x20, 0x68, 0xFE, 0x7F, 0xC1, 0xAD,
|
242 |
+
0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED,
|
243 |
+
0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D,
|
244 |
+
0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E,
|
245 |
+
0x62, 0x4C, 0x64, 0x88, 0x44, 0x8B, 0xFB, 0xA2,
|
246 |
+
0x17, 0x9A, 0x59, 0xF5, 0x87, 0xB3, 0x4F, 0x13,
|
247 |
+
0x61, 0x45, 0x6D, 0x8D, 0x09, 0x81, 0x7D, 0x32,
|
248 |
+
0xBD, 0x8F, 0x40, 0xEB, 0x86, 0xB7, 0x7B, 0x0B,
|
249 |
+
0xF0, 0x95, 0x21, 0x22, 0x5C, 0x6B, 0x4E, 0x82,
|
250 |
+
0x54, 0xD6, 0x65, 0x93, 0xCE, 0x60, 0xB2, 0x1C,
|
251 |
+
0x73, 0x56, 0xC0, 0x14, 0xA7, 0x8C, 0xF1, 0xDC,
|
252 |
+
0x12, 0x75, 0xCA, 0x1F, 0x3B, 0xBE, 0xE4, 0xD1,
|
253 |
+
0x42, 0x3D, 0xD4, 0x30, 0xA3, 0x3C, 0xB6, 0x26,
|
254 |
+
0x6F, 0xBF, 0x0E, 0xDA, 0x46, 0x69, 0x07, 0x57,
|
255 |
+
0x27, 0xF2, 0x1D, 0x9B, 0xBC, 0x94, 0x43, 0x03,
|
256 |
+
0xF8, 0x11, 0xC7, 0xF6, 0x90, 0xEF, 0x3E, 0xE7,
|
257 |
+
0x06, 0xC3, 0xD5, 0x2F, 0xC8, 0x66, 0x1E, 0xD7,
|
258 |
+
0x08, 0xE8, 0xEA, 0xDE, 0x80, 0x52, 0xEE, 0xF7,
|
259 |
+
0x84, 0xAA, 0x72, 0xAC, 0x35, 0x4D, 0x6A, 0x2A,
|
260 |
+
0x96, 0x1A, 0xD2, 0x71, 0x5A, 0x15, 0x49, 0x74,
|
261 |
+
0x4B, 0x9F, 0xD0, 0x5E, 0x04, 0x18, 0xA4, 0xEC,
|
262 |
+
0xC2, 0xE0, 0x41, 0x6E, 0x0F, 0x51, 0xCB, 0xCC,
|
263 |
+
0x24, 0x91, 0xAF, 0x50, 0xA1, 0xF4, 0x70, 0x39,
|
264 |
+
0x99, 0x7C, 0x3A, 0x85, 0x23, 0xB8, 0xB4, 0x7A,
|
265 |
+
0xFC, 0x02, 0x36, 0x5B, 0x25, 0x55, 0x97, 0x31,
|
266 |
+
0x2D, 0x5D, 0xFA, 0x98, 0xE3, 0x8A, 0x92, 0xAE,
|
267 |
+
0x05, 0xDF, 0x29, 0x10, 0x67, 0x6C, 0xBA, 0xC9,
|
268 |
+
0xD3, 0x00, 0xE6, 0xCF, 0xE1, 0x9E, 0xA8, 0x2C,
|
269 |
+
0x63, 0x16, 0x01, 0x3F, 0x58, 0xE2, 0x89, 0xA9,
|
270 |
+
0x0D, 0x38, 0x34, 0x1B, 0xAB, 0x33, 0xFF, 0xB0,
|
271 |
+
0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E,
|
272 |
+
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77,
|
273 |
+
0x0A, 0xA6, 0x20, 0x68, 0xFE, 0x7F, 0xC1, 0xAD
|
274 |
+
);
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Inverse key expansion randomization table.
|
278 |
+
*
|
279 |
+
* @see Crypt_RC2::setKey()
|
280 |
+
* @var Array
|
281 |
+
* @access private
|
282 |
+
*/
|
283 |
+
var $invpitable = array(
|
284 |
+
0xD1, 0xDA, 0xB9, 0x6F, 0x9C, 0xC8, 0x78, 0x66,
|
285 |
+
0x80, 0x2C, 0xF8, 0x37, 0xEA, 0xE0, 0x62, 0xA4,
|
286 |
+
0xCB, 0x71, 0x50, 0x27, 0x4B, 0x95, 0xD9, 0x20,
|
287 |
+
0x9D, 0x04, 0x91, 0xE3, 0x47, 0x6A, 0x7E, 0x53,
|
288 |
+
0xFA, 0x3A, 0x3B, 0xB4, 0xA8, 0xBC, 0x5F, 0x68,
|
289 |
+
0x08, 0xCA, 0x8F, 0x14, 0xD7, 0xC0, 0xEF, 0x7B,
|
290 |
+
0x5B, 0xBF, 0x2F, 0xE5, 0xE2, 0x8C, 0xBA, 0x12,
|
291 |
+
0xE1, 0xAF, 0xB2, 0x54, 0x5D, 0x59, 0x76, 0xDB,
|
292 |
+
0x32, 0xA2, 0x58, 0x6E, 0x1C, 0x29, 0x64, 0xF3,
|
293 |
+
0xE9, 0x96, 0x0C, 0x98, 0x19, 0x8D, 0x3E, 0x26,
|
294 |
+
0xAB, 0xA5, 0x85, 0x16, 0x40, 0xBD, 0x49, 0x67,
|
295 |
+
0xDC, 0x22, 0x94, 0xBB, 0x3C, 0xC1, 0x9B, 0xEB,
|
296 |
+
0x45, 0x28, 0x18, 0xD8, 0x1A, 0x42, 0x7D, 0xCC,
|
297 |
+
0xFB, 0x65, 0x8E, 0x3D, 0xCD, 0x2A, 0xA3, 0x60,
|
298 |
+
0xAE, 0x93, 0x8A, 0x48, 0x97, 0x51, 0x15, 0xF7,
|
299 |
+
0x01, 0x0B, 0xB7, 0x36, 0xB1, 0x2E, 0x11, 0xFD,
|
300 |
+
0x84, 0x2D, 0x3F, 0x13, 0x88, 0xB3, 0x34, 0x24,
|
301 |
+
0x1B, 0xDE, 0xC5, 0x1D, 0x4D, 0x2B, 0x17, 0x31,
|
302 |
+
0x74, 0xA9, 0xC6, 0x43, 0x6D, 0x39, 0x90, 0xBE,
|
303 |
+
0xC3, 0xB0, 0x21, 0x6B, 0xF6, 0x0F, 0xD5, 0x99,
|
304 |
+
0x0D, 0xAC, 0x1F, 0x5C, 0x9E, 0xF5, 0xF9, 0x4C,
|
305 |
+
0xD6, 0xDF, 0x89, 0xE4, 0x8B, 0xFF, 0xC7, 0xAA,
|
306 |
+
0xE7, 0xED, 0x46, 0x25, 0xB6, 0x06, 0x5E, 0x35,
|
307 |
+
0xB5, 0xEC, 0xCE, 0xE8, 0x6C, 0x30, 0x55, 0x61,
|
308 |
+
0x4A, 0xFE, 0xA0, 0x79, 0x03, 0xF0, 0x10, 0x72,
|
309 |
+
0x7C, 0xCF, 0x52, 0xA6, 0xA7, 0xEE, 0x44, 0xD3,
|
310 |
+
0x9A, 0x57, 0x92, 0xD0, 0x5A, 0x7A, 0x41, 0x7F,
|
311 |
+
0x0E, 0x00, 0x63, 0xF2, 0x4F, 0x05, 0x83, 0xC9,
|
312 |
+
0xA1, 0xD4, 0xDD, 0xC4, 0x56, 0xF4, 0xD2, 0x77,
|
313 |
+
0x81, 0x09, 0x82, 0x33, 0x9F, 0x07, 0x86, 0x75,
|
314 |
+
0x38, 0x4E, 0x69, 0xF1, 0xAD, 0x23, 0x73, 0x87,
|
315 |
+
0x70, 0x02, 0xC2, 0x1E, 0xB8, 0x0A, 0xFC, 0xE6
|
316 |
+
);
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Default Constructor.
|
320 |
+
*
|
321 |
+
* Determines whether or not the mcrypt extension should be used.
|
322 |
+
*
|
323 |
+
* $mode could be:
|
324 |
+
*
|
325 |
+
* - CRYPT_RC2_MODE_ECB
|
326 |
+
*
|
327 |
+
* - CRYPT_RC2_MODE_CBC
|
328 |
+
*
|
329 |
+
* - CRYPT_RC2_MODE_CTR
|
330 |
+
*
|
331 |
+
* - CRYPT_RC2_MODE_CFB
|
332 |
+
*
|
333 |
+
* - CRYPT_RC2_MODE_OFB
|
334 |
+
*
|
335 |
+
* If not explicitly set, CRYPT_RC2_MODE_CBC will be used.
|
336 |
+
*
|
337 |
+
* @see Crypt_Base::Crypt_Base()
|
338 |
+
* @param optional Integer $mode
|
339 |
+
* @access public
|
340 |
+
*/
|
341 |
+
function Crypt_RC2($mode = CRYPT_RC2_MODE_CBC)
|
342 |
+
{
|
343 |
+
parent::Crypt_Base($mode);
|
344 |
+
$this->setKey('');
|
345 |
+
}
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Sets the key length
|
349 |
+
*
|
350 |
+
* Valid key lengths are 1 to 1024.
|
351 |
+
* Calling this function after setting the key has no effect until the next
|
352 |
+
* Crypt_RC2::setKey() call.
|
353 |
+
*
|
354 |
+
* @access public
|
355 |
+
* @param Integer $length in bits
|
356 |
+
*/
|
357 |
+
function setKeyLength($length)
|
358 |
+
{
|
359 |
+
if ($length >= 1 && $length <= 1024) {
|
360 |
+
$this->default_key_length = $length;
|
361 |
+
}
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* Sets the key.
|
366 |
+
*
|
367 |
+
* Keys can be of any length. RC2, itself, uses 1 to 1024 bit keys (eg.
|
368 |
+
* strlen($key) <= 128), however, we only use the first 128 bytes if $key
|
369 |
+
* has more then 128 bytes in it, and set $key to a single null byte if
|
370 |
+
* it is empty.
|
371 |
+
*
|
372 |
+
* If the key is not explicitly set, it'll be assumed to be a single
|
373 |
+
* null byte.
|
374 |
+
*
|
375 |
+
* @see Crypt_Base::setKey()
|
376 |
+
* @access public
|
377 |
+
* @param String $key
|
378 |
+
* @param Integer $t1 optional Effective key length in bits.
|
379 |
+
*/
|
380 |
+
function setKey($key, $t1 = 0)
|
381 |
+
{
|
382 |
+
if ($t1 <= 0) {
|
383 |
+
$t1 = $this->default_key_length;
|
384 |
+
} else if ($t1 > 1024) {
|
385 |
+
$t1 = 1024;
|
386 |
+
}
|
387 |
+
// Key byte count should be 1..128.
|
388 |
+
$key = strlen($key) ? substr($key, 0, 128) : "\x00";
|
389 |
+
$t = strlen($key);
|
390 |
+
|
391 |
+
// The mcrypt RC2 implementation only supports effective key length
|
392 |
+
// of 1024 bits. It is however possible to handle effective key
|
393 |
+
// lengths in range 1..1024 by expanding the key and applying
|
394 |
+
// inverse pitable mapping to the first byte before submitting it
|
395 |
+
// to mcrypt.
|
396 |
+
|
397 |
+
// Key expansion.
|
398 |
+
$l = array_values(unpack('C*', $key));
|
399 |
+
$t8 = ($t1 + 7) >> 3;
|
400 |
+
$tm = 0xFF >> (8 * $t8 - $t1);
|
401 |
+
|
402 |
+
// Expand key.
|
403 |
+
$pitable = $this->pitable;
|
404 |
+
for ($i = $t; $i < 128; $i++) {
|
405 |
+
$l[$i] = $pitable[$l[$i - 1] + $l[$i - $t]];
|
406 |
+
}
|
407 |
+
$i = 128 - $t8;
|
408 |
+
$l[$i] = $pitable[$l[$i] & $tm];
|
409 |
+
while ($i--) {
|
410 |
+
$l[$i] = $pitable[$l[$i + 1] ^ $l[$i + $t8]];
|
411 |
+
}
|
412 |
+
|
413 |
+
// Prepare the key for mcrypt.
|
414 |
+
$l[0] = $this->invpitable[$l[0]];
|
415 |
+
array_unshift($l, 'C*');
|
416 |
+
parent::setKey(call_user_func_array('pack', $l));
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Encrypts a block
|
421 |
+
*
|
422 |
+
* @see Crypt_Base::_encryptBlock()
|
423 |
+
* @see Crypt_Base::encrypt()
|
424 |
+
* @access private
|
425 |
+
* @param String $in
|
426 |
+
* @return String
|
427 |
+
*/
|
428 |
+
function _encryptBlock($in)
|
429 |
+
{
|
430 |
+
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
|
431 |
+
$keys = $this->keys;
|
432 |
+
$limit = 20;
|
433 |
+
$actions = array($limit => 44, 44 => 64);
|
434 |
+
$j = 0;
|
435 |
+
|
436 |
+
for (;;) {
|
437 |
+
// Mixing round.
|
438 |
+
$r0 = (($r0 + $keys[$j++] + ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1;
|
439 |
+
$r0 |= $r0 >> 16;
|
440 |
+
$r1 = (($r1 + $keys[$j++] + ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF) << 2;
|
441 |
+
$r1 |= $r1 >> 16;
|
442 |
+
$r2 = (($r2 + $keys[$j++] + ((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF) << 3;
|
443 |
+
$r2 |= $r2 >> 16;
|
444 |
+
$r3 = (($r3 + $keys[$j++] + ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF) << 5;
|
445 |
+
$r3 |= $r3 >> 16;
|
446 |
+
|
447 |
+
if ($j === $limit) {
|
448 |
+
if ($limit === 64) {
|
449 |
+
break;
|
450 |
+
}
|
451 |
+
|
452 |
+
// Mashing round.
|
453 |
+
$r0 += $keys[$r3 & 0x3F];
|
454 |
+
$r1 += $keys[$r0 & 0x3F];
|
455 |
+
$r2 += $keys[$r1 & 0x3F];
|
456 |
+
$r3 += $keys[$r2 & 0x3F];
|
457 |
+
$limit = $actions[$limit];
|
458 |
+
}
|
459 |
+
}
|
460 |
+
|
461 |
+
return pack('vvvv', $r0, $r1, $r2, $r3);
|
462 |
+
}
|
463 |
+
|
464 |
+
/**
|
465 |
+
* Decrypts a block
|
466 |
+
*
|
467 |
+
* @see Crypt_Base::_decryptBlock()
|
468 |
+
* @see Crypt_Base::decrypt()
|
469 |
+
* @access private
|
470 |
+
* @param String $in
|
471 |
+
* @return String
|
472 |
+
*/
|
473 |
+
function _decryptBlock($in)
|
474 |
+
{
|
475 |
+
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
|
476 |
+
$keys = $this->keys;
|
477 |
+
$limit = 44;
|
478 |
+
$actions = array($limit => 20, 20 => 0);
|
479 |
+
$j = 64;
|
480 |
+
|
481 |
+
for (;;) {
|
482 |
+
// R-mixing round.
|
483 |
+
$r3 = ($r3 | ($r3 << 16)) >> 5;
|
484 |
+
$r3 = ($r3 - $keys[--$j] - ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF;
|
485 |
+
$r2 = ($r2 | ($r2 << 16)) >> 3;
|
486 |
+
$r2 = ($r2 - $keys[--$j] - ((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF;
|
487 |
+
$r1 = ($r1 | ($r1 << 16)) >> 2;
|
488 |
+
$r1 = ($r1 - $keys[--$j] - ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF;
|
489 |
+
$r0 = ($r0 | ($r0 << 16)) >> 1;
|
490 |
+
$r0 = ($r0 - $keys[--$j] - ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF;
|
491 |
+
|
492 |
+
if ($j === $limit) {
|
493 |
+
if ($limit === 0) {
|
494 |
+
break;
|
495 |
+
}
|
496 |
+
|
497 |
+
// R-mashing round.
|
498 |
+
$r3 = ($r3 - $keys[$r2 & 0x3F]) & 0xFFFF;
|
499 |
+
$r2 = ($r2 - $keys[$r1 & 0x3F]) & 0xFFFF;
|
500 |
+
$r1 = ($r1 - $keys[$r0 & 0x3F]) & 0xFFFF;
|
501 |
+
$r0 = ($r0 - $keys[$r3 & 0x3F]) & 0xFFFF;
|
502 |
+
$limit = $actions[$limit];
|
503 |
+
}
|
504 |
+
}
|
505 |
+
|
506 |
+
return pack('vvvv', $r0, $r1, $r2, $r3);
|
507 |
+
}
|
508 |
+
|
509 |
+
/**
|
510 |
+
* Creates the key schedule
|
511 |
+
*
|
512 |
+
* @see Crypt_Base::_setupKey()
|
513 |
+
* @access private
|
514 |
+
*/
|
515 |
+
function _setupKey()
|
516 |
+
{
|
517 |
+
// Key has already been expanded in Crypt_RC2::setKey():
|
518 |
+
// Only the first value must be altered.
|
519 |
+
$l = unpack('Ca/Cb/v*', $this->key);
|
520 |
+
array_unshift($l, $this->pitable[$l['a']] | ($l['b'] << 8));
|
521 |
+
unset($l['a']);
|
522 |
+
unset($l['b']);
|
523 |
+
$this->keys = $l;
|
524 |
+
}
|
525 |
+
|
526 |
+
/**
|
527 |
+
* Setup the performance-optimized function for de/encrypt()
|
528 |
+
*
|
529 |
+
* @see Crypt_Base::_setupInlineCrypt()
|
530 |
+
* @access private
|
531 |
+
*/
|
532 |
+
function _setupInlineCrypt()
|
533 |
+
{
|
534 |
+
$lambda_functions = &Crypt_RC2::_getLambdaFunctions();
|
535 |
+
|
536 |
+
// The first 10 generated $lambda_functions will use the $keys hardcoded as integers
|
537 |
+
// for the mixing rounds, for better inline crypt performance [~20% faster].
|
538 |
+
// But for memory reason we have to limit those ultra-optimized $lambda_functions to an amount of 10.
|
539 |
+
$keys = $this->keys;
|
540 |
+
if (count($lambda_functions) >= 10) {
|
541 |
+
foreach ($this->keys as $k => $v) {
|
542 |
+
$keys[$k] = '$keys[' . $k . ']';
|
543 |
+
}
|
544 |
+
}
|
545 |
+
|
546 |
+
$code_hash = md5(str_pad("Crypt_RC2, {$this->mode}, ", 32, "\0") . implode(',', $keys));
|
547 |
+
|
548 |
+
// Is there a re-usable $lambda_functions in there?
|
549 |
+
// If not, we have to create it.
|
550 |
+
if (!isset($lambda_functions[$code_hash])) {
|
551 |
+
// Init code for both, encrypt and decrypt.
|
552 |
+
$init_crypt = '$keys = $self->keys;';
|
553 |
+
|
554 |
+
// $in is the current 8 bytes block which has to be en/decrypt
|
555 |
+
$encrypt_block = $decrypt_block = '
|
556 |
+
$in = unpack("v4", $in);
|
557 |
+
$r0 = $in[1];
|
558 |
+
$r1 = $in[2];
|
559 |
+
$r2 = $in[3];
|
560 |
+
$r3 = $in[4];
|
561 |
+
';
|
562 |
+
|
563 |
+
// Create code for encryption.
|
564 |
+
$limit = 20;
|
565 |
+
$actions = array($limit => 44, 44 => 64);
|
566 |
+
$j = 0;
|
567 |
+
|
568 |
+
for (;;) {
|
569 |
+
// Mixing round.
|
570 |
+
$encrypt_block .= '
|
571 |
+
$r0 = (($r0 + ' . $keys[$j++] . ' +
|
572 |
+
((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1;
|
573 |
+
$r0 |= $r0 >> 16;
|
574 |
+
$r1 = (($r1 + ' . $keys[$j++] . ' +
|
575 |
+
((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF) << 2;
|
576 |
+
$r1 |= $r1 >> 16;
|
577 |
+
$r2 = (($r2 + ' . $keys[$j++] . ' +
|
578 |
+
((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF) << 3;
|
579 |
+
$r2 |= $r2 >> 16;
|
580 |
+
$r3 = (($r3 + ' . $keys[$j++] . ' +
|
581 |
+
((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF) << 5;
|
582 |
+
$r3 |= $r3 >> 16;';
|
583 |
+
|
584 |
+
if ($j === $limit) {
|
585 |
+
if ($limit === 64) {
|
586 |
+
break;
|
587 |
+
}
|
588 |
+
|
589 |
+
// Mashing round.
|
590 |
+
$encrypt_block .= '
|
591 |
+
$r0 += $keys[$r3 & 0x3F];
|
592 |
+
$r1 += $keys[$r0 & 0x3F];
|
593 |
+
$r2 += $keys[$r1 & 0x3F];
|
594 |
+
$r3 += $keys[$r2 & 0x3F];';
|
595 |
+
$limit = $actions[$limit];
|
596 |
+
}
|
597 |
+
}
|
598 |
+
|
599 |
+
$encrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);';
|
600 |
+
|
601 |
+
// Create code for decryption.
|
602 |
+
$limit = 44;
|
603 |
+
$actions = array($limit => 20, 20 => 0);
|
604 |
+
$j = 64;
|
605 |
+
|
606 |
+
for (;;) {
|
607 |
+
// R-mixing round.
|
608 |
+
$decrypt_block .= '
|
609 |
+
$r3 = ($r3 | ($r3 << 16)) >> 5;
|
610 |
+
$r3 = ($r3 - ' . $keys[--$j] . ' -
|
611 |
+
((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF;
|
612 |
+
$r2 = ($r2 | ($r2 << 16)) >> 3;
|
613 |
+
$r2 = ($r2 - ' . $keys[--$j] . ' -
|
614 |
+
((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF;
|
615 |
+
$r1 = ($r1 | ($r1 << 16)) >> 2;
|
616 |
+
$r1 = ($r1 - ' . $keys[--$j] . ' -
|
617 |
+
((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF;
|
618 |
+
$r0 = ($r0 | ($r0 << 16)) >> 1;
|
619 |
+
$r0 = ($r0 - ' . $keys[--$j] . ' -
|
620 |
+
((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF;';
|
621 |
+
|
622 |
+
if ($j === $limit) {
|
623 |
+
if ($limit === 0) {
|
624 |
+
break;
|
625 |
+
}
|
626 |
+
|
627 |
+
// R-mashing round.
|
628 |
+
$decrypt_block .= '
|
629 |
+
$r3 = ($r3 - $keys[$r2 & 0x3F]) & 0xFFFF;
|
630 |
+
$r2 = ($r2 - $keys[$r1 & 0x3F]) & 0xFFFF;
|
631 |
+
$r1 = ($r1 - $keys[$r0 & 0x3F]) & 0xFFFF;
|
632 |
+
$r0 = ($r0 - $keys[$r3 & 0x3F]) & 0xFFFF;';
|
633 |
+
$limit = $actions[$limit];
|
634 |
+
}
|
635 |
+
}
|
636 |
+
|
637 |
+
$decrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);';
|
638 |
+
|
639 |
+
// Creates the inline-crypt function
|
640 |
+
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
|
641 |
+
array(
|
642 |
+
'init_crypt' => $init_crypt,
|
643 |
+
'encrypt_block' => $encrypt_block,
|
644 |
+
'decrypt_block' => $decrypt_block
|
645 |
+
)
|
646 |
+
);
|
647 |
+
}
|
648 |
+
|
649 |
+
// Set the inline-crypt function as callback in: $this->inline_crypt
|
650 |
+
$this->inline_crypt = $lambda_functions[$code_hash];
|
651 |
+
}
|
652 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/RC4.php
ADDED
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of RC4.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* Useful resources are as follows:
|
11 |
+
*
|
12 |
+
* - {@link http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt ARCFOUR Algorithm}
|
13 |
+
* - {@link http://en.wikipedia.org/wiki/RC4 - Wikipedia: RC4}
|
14 |
+
*
|
15 |
+
* RC4 is also known as ARCFOUR or ARC4. The reason is elaborated upon at Wikipedia. This class is named RC4 and not
|
16 |
+
* ARCFOUR or ARC4 because RC4 is how it is referred to in the SSH1 specification.
|
17 |
+
*
|
18 |
+
* Here's a short example of how to use this library:
|
19 |
+
* <code>
|
20 |
+
* <?php
|
21 |
+
* include 'Crypt/RC4.php';
|
22 |
+
*
|
23 |
+
* $rc4 = new Crypt_RC4();
|
24 |
+
*
|
25 |
+
* $rc4->setKey('abcdefgh');
|
26 |
+
*
|
27 |
+
* $size = 10 * 1024;
|
28 |
+
* $plaintext = '';
|
29 |
+
* for ($i = 0; $i < $size; $i++) {
|
30 |
+
* $plaintext.= 'a';
|
31 |
+
* }
|
32 |
+
*
|
33 |
+
* echo $rc4->decrypt($rc4->encrypt($plaintext));
|
34 |
+
* ?>
|
35 |
+
* </code>
|
36 |
+
*
|
37 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
38 |
+
* of this software and associated documentation files (the "Software"), to deal
|
39 |
+
* in the Software without restriction, including without limitation the rights
|
40 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
41 |
+
* copies of the Software, and to permit persons to whom the Software is
|
42 |
+
* furnished to do so, subject to the following conditions:
|
43 |
+
*
|
44 |
+
* The above copyright notice and this permission notice shall be included in
|
45 |
+
* all copies or substantial portions of the Software.
|
46 |
+
*
|
47 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
48 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
49 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
50 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
51 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
52 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
53 |
+
* THE SOFTWARE.
|
54 |
+
*
|
55 |
+
* @category Crypt
|
56 |
+
* @package Crypt_RC4
|
57 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
58 |
+
* @copyright 2007 Jim Wigginton
|
59 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
60 |
+
* @link http://phpseclib.sourceforge.net
|
61 |
+
*/
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Include Crypt_Base
|
65 |
+
*
|
66 |
+
* Base cipher class
|
67 |
+
*/
|
68 |
+
if (!class_exists('Crypt_Base')) {
|
69 |
+
include_once 'Base.php';
|
70 |
+
}
|
71 |
+
|
72 |
+
/**#@+
|
73 |
+
* @access private
|
74 |
+
* @see Crypt_RC4::Crypt_RC4()
|
75 |
+
*/
|
76 |
+
/**
|
77 |
+
* Toggles the internal implementation
|
78 |
+
*/
|
79 |
+
define('CRYPT_RC4_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
80 |
+
/**
|
81 |
+
* Toggles the mcrypt implementation
|
82 |
+
*/
|
83 |
+
define('CRYPT_RC4_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
84 |
+
/**#@-*/
|
85 |
+
|
86 |
+
/**#@+
|
87 |
+
* @access private
|
88 |
+
* @see Crypt_RC4::_crypt()
|
89 |
+
*/
|
90 |
+
define('CRYPT_RC4_ENCRYPT', 0);
|
91 |
+
define('CRYPT_RC4_DECRYPT', 1);
|
92 |
+
/**#@-*/
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Pure-PHP implementation of RC4.
|
96 |
+
*
|
97 |
+
* @package Crypt_RC4
|
98 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
99 |
+
* @access public
|
100 |
+
*/
|
101 |
+
class Crypt_RC4 extends Crypt_Base
|
102 |
+
{
|
103 |
+
/**
|
104 |
+
* Block Length of the cipher
|
105 |
+
*
|
106 |
+
* RC4 is a stream cipher
|
107 |
+
* so we the block_size to 0
|
108 |
+
*
|
109 |
+
* @see Crypt_Base::block_size
|
110 |
+
* @var Integer
|
111 |
+
* @access private
|
112 |
+
*/
|
113 |
+
var $block_size = 0;
|
114 |
+
|
115 |
+
/**
|
116 |
+
* The default password key_size used by setPassword()
|
117 |
+
*
|
118 |
+
* @see Crypt_Base::password_key_size
|
119 |
+
* @see Crypt_Base::setPassword()
|
120 |
+
* @var Integer
|
121 |
+
* @access private
|
122 |
+
*/
|
123 |
+
var $password_key_size = 128; // = 1024 bits
|
124 |
+
|
125 |
+
/**
|
126 |
+
* The namespace used by the cipher for its constants.
|
127 |
+
*
|
128 |
+
* @see Crypt_Base::const_namespace
|
129 |
+
* @var String
|
130 |
+
* @access private
|
131 |
+
*/
|
132 |
+
var $const_namespace = 'RC4';
|
133 |
+
|
134 |
+
/**
|
135 |
+
* The mcrypt specific name of the cipher
|
136 |
+
*
|
137 |
+
* @see Crypt_Base::cipher_name_mcrypt
|
138 |
+
* @var String
|
139 |
+
* @access private
|
140 |
+
*/
|
141 |
+
var $cipher_name_mcrypt = 'arcfour';
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Holds whether performance-optimized $inline_crypt() can/should be used.
|
145 |
+
*
|
146 |
+
* @see Crypt_Base::inline_crypt
|
147 |
+
* @var mixed
|
148 |
+
* @access private
|
149 |
+
*/
|
150 |
+
var $use_inline_crypt = false; // currently not available
|
151 |
+
|
152 |
+
/**
|
153 |
+
* The Key
|
154 |
+
*
|
155 |
+
* @see Crypt_RC4::setKey()
|
156 |
+
* @var String
|
157 |
+
* @access private
|
158 |
+
*/
|
159 |
+
var $key = "\0";
|
160 |
+
|
161 |
+
/**
|
162 |
+
* The Key Stream for decryption and encryption
|
163 |
+
*
|
164 |
+
* @see Crypt_RC4::setKey()
|
165 |
+
* @var Array
|
166 |
+
* @access private
|
167 |
+
*/
|
168 |
+
var $stream;
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Default Constructor.
|
172 |
+
*
|
173 |
+
* Determines whether or not the mcrypt extension should be used.
|
174 |
+
*
|
175 |
+
* @see Crypt_Base::Crypt_Base()
|
176 |
+
* @return Crypt_RC4
|
177 |
+
* @access public
|
178 |
+
*/
|
179 |
+
function Crypt_RC4()
|
180 |
+
{
|
181 |
+
parent::Crypt_Base(CRYPT_MODE_STREAM);
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Dummy function.
|
186 |
+
*
|
187 |
+
* Some protocols, such as WEP, prepend an "initialization vector" to the key, effectively creating a new key [1].
|
188 |
+
* If you need to use an initialization vector in this manner, feel free to prepend it to the key, yourself, before
|
189 |
+
* calling setKey().
|
190 |
+
*
|
191 |
+
* [1] WEP's initialization vectors (IV's) are used in a somewhat insecure way. Since, in that protocol,
|
192 |
+
* the IV's are relatively easy to predict, an attack described by
|
193 |
+
* {@link http://www.drizzle.com/~aboba/IEEE/rc4_ksaproc.pdf Scott Fluhrer, Itsik Mantin, and Adi Shamir}
|
194 |
+
* can be used to quickly guess at the rest of the key. The following links elaborate:
|
195 |
+
*
|
196 |
+
* {@link http://www.rsa.com/rsalabs/node.asp?id=2009 http://www.rsa.com/rsalabs/node.asp?id=2009}
|
197 |
+
* {@link http://en.wikipedia.org/wiki/Related_key_attack http://en.wikipedia.org/wiki/Related_key_attack}
|
198 |
+
*
|
199 |
+
* @param String $iv
|
200 |
+
* @see Crypt_RC4::setKey()
|
201 |
+
* @access public
|
202 |
+
*/
|
203 |
+
function setIV($iv)
|
204 |
+
{
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Sets the key.
|
209 |
+
*
|
210 |
+
* Keys can be between 1 and 256 bytes long. If they are longer then 256 bytes, the first 256 bytes will
|
211 |
+
* be used. If no key is explicitly set, it'll be assumed to be a single null byte.
|
212 |
+
*
|
213 |
+
* @access public
|
214 |
+
* @see Crypt_Base::setKey()
|
215 |
+
* @param String $key
|
216 |
+
*/
|
217 |
+
function setKey($key)
|
218 |
+
{
|
219 |
+
parent::setKey(substr($key, 0, 256));
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Encrypts a message.
|
224 |
+
*
|
225 |
+
* @see Crypt_Base::decrypt()
|
226 |
+
* @see Crypt_RC4::_crypt()
|
227 |
+
* @access public
|
228 |
+
* @param String $plaintext
|
229 |
+
* @return String $ciphertext
|
230 |
+
*/
|
231 |
+
function encrypt($plaintext)
|
232 |
+
{
|
233 |
+
if ($this->engine == CRYPT_MODE_MCRYPT) {
|
234 |
+
return parent::encrypt($plaintext);
|
235 |
+
}
|
236 |
+
return $this->_crypt($plaintext, CRYPT_RC4_ENCRYPT);
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Decrypts a message.
|
241 |
+
*
|
242 |
+
* $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)).
|
243 |
+
* At least if the continuous buffer is disabled.
|
244 |
+
*
|
245 |
+
* @see Crypt_Base::encrypt()
|
246 |
+
* @see Crypt_RC4::_crypt()
|
247 |
+
* @access public
|
248 |
+
* @param String $ciphertext
|
249 |
+
* @return String $plaintext
|
250 |
+
*/
|
251 |
+
function decrypt($ciphertext)
|
252 |
+
{
|
253 |
+
if ($this->engine == CRYPT_MODE_MCRYPT) {
|
254 |
+
return parent::decrypt($ciphertext);
|
255 |
+
}
|
256 |
+
return $this->_crypt($ciphertext, CRYPT_RC4_DECRYPT);
|
257 |
+
}
|
258 |
+
|
259 |
+
|
260 |
+
/**
|
261 |
+
* Setup the key (expansion)
|
262 |
+
*
|
263 |
+
* @see Crypt_Base::_setupKey()
|
264 |
+
* @access private
|
265 |
+
*/
|
266 |
+
function _setupKey()
|
267 |
+
{
|
268 |
+
$key = $this->key;
|
269 |
+
$keyLength = strlen($key);
|
270 |
+
$keyStream = range(0, 255);
|
271 |
+
$j = 0;
|
272 |
+
for ($i = 0; $i < 256; $i++) {
|
273 |
+
$j = ($j + $keyStream[$i] + ord($key[$i % $keyLength])) & 255;
|
274 |
+
$temp = $keyStream[$i];
|
275 |
+
$keyStream[$i] = $keyStream[$j];
|
276 |
+
$keyStream[$j] = $temp;
|
277 |
+
}
|
278 |
+
|
279 |
+
$this->stream = array();
|
280 |
+
$this->stream[CRYPT_RC4_DECRYPT] = $this->stream[CRYPT_RC4_ENCRYPT] = array(
|
281 |
+
0, // index $i
|
282 |
+
0, // index $j
|
283 |
+
$keyStream
|
284 |
+
);
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Encrypts or decrypts a message.
|
289 |
+
*
|
290 |
+
* @see Crypt_RC4::encrypt()
|
291 |
+
* @see Crypt_RC4::decrypt()
|
292 |
+
* @access private
|
293 |
+
* @param String $text
|
294 |
+
* @param Integer $mode
|
295 |
+
* @return String $text
|
296 |
+
*/
|
297 |
+
function _crypt($text, $mode)
|
298 |
+
{
|
299 |
+
if ($this->changed) {
|
300 |
+
$this->_setup();
|
301 |
+
$this->changed = false;
|
302 |
+
}
|
303 |
+
|
304 |
+
$stream = &$this->stream[$mode];
|
305 |
+
if ($this->continuousBuffer) {
|
306 |
+
$i = &$stream[0];
|
307 |
+
$j = &$stream[1];
|
308 |
+
$keyStream = &$stream[2];
|
309 |
+
} else {
|
310 |
+
$i = $stream[0];
|
311 |
+
$j = $stream[1];
|
312 |
+
$keyStream = $stream[2];
|
313 |
+
}
|
314 |
+
|
315 |
+
$len = strlen($text);
|
316 |
+
for ($k = 0; $k < $len; ++$k) {
|
317 |
+
$i = ($i + 1) & 255;
|
318 |
+
$ksi = $keyStream[$i];
|
319 |
+
$j = ($j + $ksi) & 255;
|
320 |
+
$ksj = $keyStream[$j];
|
321 |
+
|
322 |
+
$keyStream[$i] = $ksj;
|
323 |
+
$keyStream[$j] = $ksi;
|
324 |
+
$text[$k] = $text[$k] ^ chr($keyStream[($ksj + $ksi) & 255]);
|
325 |
+
}
|
326 |
+
|
327 |
+
return $text;
|
328 |
+
}
|
329 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/RSA.php
ADDED
@@ -0,0 +1,2997 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP PKCS#1 (v2.1) compliant implementation of RSA.
|
5 |
+
*
|
6 |
+
* PHP versions 4 and 5
|
7 |
+
*
|
8 |
+
* Here's an example of how to encrypt and decrypt text with this library:
|
9 |
+
* <code>
|
10 |
+
* <?php
|
11 |
+
* include 'Crypt/RSA.php';
|
12 |
+
*
|
13 |
+
* $rsa = new Crypt_RSA();
|
14 |
+
* extract($rsa->createKey());
|
15 |
+
*
|
16 |
+
* $plaintext = 'terrafrost';
|
17 |
+
*
|
18 |
+
* $rsa->loadKey($privatekey);
|
19 |
+
* $ciphertext = $rsa->encrypt($plaintext);
|
20 |
+
*
|
21 |
+
* $rsa->loadKey($publickey);
|
22 |
+
* echo $rsa->decrypt($ciphertext);
|
23 |
+
* ?>
|
24 |
+
* </code>
|
25 |
+
*
|
26 |
+
* Here's an example of how to create signatures and verify signatures with this library:
|
27 |
+
* <code>
|
28 |
+
* <?php
|
29 |
+
* include 'Crypt/RSA.php';
|
30 |
+
*
|
31 |
+
* $rsa = new Crypt_RSA();
|
32 |
+
* extract($rsa->createKey());
|
33 |
+
*
|
34 |
+
* $plaintext = 'terrafrost';
|
35 |
+
*
|
36 |
+
* $rsa->loadKey($privatekey);
|
37 |
+
* $signature = $rsa->sign($plaintext);
|
38 |
+
*
|
39 |
+
* $rsa->loadKey($publickey);
|
40 |
+
* echo $rsa->verify($plaintext, $signature) ? 'verified' : 'unverified';
|
41 |
+
* ?>
|
42 |
+
* </code>
|
43 |
+
*
|
44 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
45 |
+
* of this software and associated documentation files (the "Software"), to deal
|
46 |
+
* in the Software without restriction, including without limitation the rights
|
47 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
48 |
+
* copies of the Software, and to permit persons to whom the Software is
|
49 |
+
* furnished to do so, subject to the following conditions:
|
50 |
+
*
|
51 |
+
* The above copyright notice and this permission notice shall be included in
|
52 |
+
* all copies or substantial portions of the Software.
|
53 |
+
*
|
54 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
55 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
56 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
57 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
58 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
59 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
60 |
+
* THE SOFTWARE.
|
61 |
+
*
|
62 |
+
* @category Crypt
|
63 |
+
* @package Crypt_RSA
|
64 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
65 |
+
* @copyright 2009 Jim Wigginton
|
66 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
67 |
+
* @link http://phpseclib.sourceforge.net
|
68 |
+
*/
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Include Crypt_Random
|
72 |
+
*/
|
73 |
+
// the class_exists() will only be called if the crypt_random_string function hasn't been defined and
|
74 |
+
// will trigger a call to __autoload() if you're wanting to auto-load classes
|
75 |
+
// call function_exists() a second time to stop the include_once from being called outside
|
76 |
+
// of the auto loader
|
77 |
+
if (!function_exists('crypt_random_string')) {
|
78 |
+
include_once 'Random.php';
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Include Crypt_Hash
|
83 |
+
*/
|
84 |
+
if (!class_exists('Crypt_Hash')) {
|
85 |
+
include_once 'Hash.php';
|
86 |
+
}
|
87 |
+
|
88 |
+
/**#@+
|
89 |
+
* @access public
|
90 |
+
* @see Crypt_RSA::encrypt()
|
91 |
+
* @see Crypt_RSA::decrypt()
|
92 |
+
*/
|
93 |
+
/**
|
94 |
+
* Use {@link http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding Optimal Asymmetric Encryption Padding}
|
95 |
+
* (OAEP) for encryption / decryption.
|
96 |
+
*
|
97 |
+
* Uses sha1 by default.
|
98 |
+
*
|
99 |
+
* @see Crypt_RSA::setHash()
|
100 |
+
* @see Crypt_RSA::setMGFHash()
|
101 |
+
*/
|
102 |
+
define('CRYPT_RSA_ENCRYPTION_OAEP', 1);
|
103 |
+
/**
|
104 |
+
* Use PKCS#1 padding.
|
105 |
+
*
|
106 |
+
* Although CRYPT_RSA_ENCRYPTION_OAEP offers more security, including PKCS#1 padding is necessary for purposes of backwards
|
107 |
+
* compatibility with protocols (like SSH-1) written before OAEP's introduction.
|
108 |
+
*/
|
109 |
+
define('CRYPT_RSA_ENCRYPTION_PKCS1', 2);
|
110 |
+
/**#@-*/
|
111 |
+
|
112 |
+
/**#@+
|
113 |
+
* @access public
|
114 |
+
* @see Crypt_RSA::sign()
|
115 |
+
* @see Crypt_RSA::verify()
|
116 |
+
* @see Crypt_RSA::setHash()
|
117 |
+
*/
|
118 |
+
/**
|
119 |
+
* Use the Probabilistic Signature Scheme for signing
|
120 |
+
*
|
121 |
+
* Uses sha1 by default.
|
122 |
+
*
|
123 |
+
* @see Crypt_RSA::setSaltLength()
|
124 |
+
* @see Crypt_RSA::setMGFHash()
|
125 |
+
*/
|
126 |
+
define('CRYPT_RSA_SIGNATURE_PSS', 1);
|
127 |
+
/**
|
128 |
+
* Use the PKCS#1 scheme by default.
|
129 |
+
*
|
130 |
+
* Although CRYPT_RSA_SIGNATURE_PSS offers more security, including PKCS#1 signing is necessary for purposes of backwards
|
131 |
+
* compatibility with protocols (like SSH-2) written before PSS's introduction.
|
132 |
+
*/
|
133 |
+
define('CRYPT_RSA_SIGNATURE_PKCS1', 2);
|
134 |
+
/**#@-*/
|
135 |
+
|
136 |
+
/**#@+
|
137 |
+
* @access private
|
138 |
+
* @see Crypt_RSA::createKey()
|
139 |
+
*/
|
140 |
+
/**
|
141 |
+
* ASN1 Integer
|
142 |
+
*/
|
143 |
+
define('CRYPT_RSA_ASN1_INTEGER', 2);
|
144 |
+
/**
|
145 |
+
* ASN1 Bit String
|
146 |
+
*/
|
147 |
+
define('CRYPT_RSA_ASN1_BITSTRING', 3);
|
148 |
+
/**
|
149 |
+
* ASN1 Octet String
|
150 |
+
*/
|
151 |
+
define('CRYPT_RSA_ASN1_OCTETSTRING', 4);
|
152 |
+
/**
|
153 |
+
* ASN1 Object Identifier
|
154 |
+
*/
|
155 |
+
define('CRYPT_RSA_ASN1_OBJECT', 6);
|
156 |
+
/**
|
157 |
+
* ASN1 Sequence (with the constucted bit set)
|
158 |
+
*/
|
159 |
+
define('CRYPT_RSA_ASN1_SEQUENCE', 48);
|
160 |
+
/**#@-*/
|
161 |
+
|
162 |
+
/**#@+
|
163 |
+
* @access private
|
164 |
+
* @see Crypt_RSA::Crypt_RSA()
|
165 |
+
*/
|
166 |
+
/**
|
167 |
+
* To use the pure-PHP implementation
|
168 |
+
*/
|
169 |
+
define('CRYPT_RSA_MODE_INTERNAL', 1);
|
170 |
+
/**
|
171 |
+
* To use the OpenSSL library
|
172 |
+
*
|
173 |
+
* (if enabled; otherwise, the internal implementation will be used)
|
174 |
+
*/
|
175 |
+
define('CRYPT_RSA_MODE_OPENSSL', 2);
|
176 |
+
/**#@-*/
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Default openSSL configuration file.
|
180 |
+
*/
|
181 |
+
define('CRYPT_RSA_OPENSSL_CONFIG', dirname(__FILE__) . '/../openssl.cnf');
|
182 |
+
|
183 |
+
/**#@+
|
184 |
+
* @access public
|
185 |
+
* @see Crypt_RSA::createKey()
|
186 |
+
* @see Crypt_RSA::setPrivateKeyFormat()
|
187 |
+
*/
|
188 |
+
/**
|
189 |
+
* PKCS#1 formatted private key
|
190 |
+
*
|
191 |
+
* Used by OpenSSH
|
192 |
+
*/
|
193 |
+
define('CRYPT_RSA_PRIVATE_FORMAT_PKCS1', 0);
|
194 |
+
/**
|
195 |
+
* PuTTY formatted private key
|
196 |
+
*/
|
197 |
+
define('CRYPT_RSA_PRIVATE_FORMAT_PUTTY', 1);
|
198 |
+
/**
|
199 |
+
* XML formatted private key
|
200 |
+
*/
|
201 |
+
define('CRYPT_RSA_PRIVATE_FORMAT_XML', 2);
|
202 |
+
/**
|
203 |
+
* PKCS#8 formatted private key
|
204 |
+
*/
|
205 |
+
define('CRYPT_RSA_PRIVATE_FORMAT_PKCS8', 3);
|
206 |
+
/**#@-*/
|
207 |
+
|
208 |
+
/**#@+
|
209 |
+
* @access public
|
210 |
+
* @see Crypt_RSA::createKey()
|
211 |
+
* @see Crypt_RSA::setPublicKeyFormat()
|
212 |
+
*/
|
213 |
+
/**
|
214 |
+
* Raw public key
|
215 |
+
*
|
216 |
+
* An array containing two Math_BigInteger objects.
|
217 |
+
*
|
218 |
+
* The exponent can be indexed with any of the following:
|
219 |
+
*
|
220 |
+
* 0, e, exponent, publicExponent
|
221 |
+
*
|
222 |
+
* The modulus can be indexed with any of the following:
|
223 |
+
*
|
224 |
+
* 1, n, modulo, modulus
|
225 |
+
*/
|
226 |
+
define('CRYPT_RSA_PUBLIC_FORMAT_RAW', 3);
|
227 |
+
/**
|
228 |
+
* PKCS#1 formatted public key (raw)
|
229 |
+
*
|
230 |
+
* Used by File/X509.php
|
231 |
+
*
|
232 |
+
* Has the following header:
|
233 |
+
*
|
234 |
+
* -----BEGIN RSA PUBLIC KEY-----
|
235 |
+
*
|
236 |
+
* Analogous to ssh-keygen's pem format (as specified by -m)
|
237 |
+
*/
|
238 |
+
define('CRYPT_RSA_PUBLIC_FORMAT_PKCS1', 4);
|
239 |
+
define('CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW', 4);
|
240 |
+
/**
|
241 |
+
* XML formatted public key
|
242 |
+
*/
|
243 |
+
define('CRYPT_RSA_PUBLIC_FORMAT_XML', 5);
|
244 |
+
/**
|
245 |
+
* OpenSSH formatted public key
|
246 |
+
*
|
247 |
+
* Place in $HOME/.ssh/authorized_keys
|
248 |
+
*/
|
249 |
+
define('CRYPT_RSA_PUBLIC_FORMAT_OPENSSH', 6);
|
250 |
+
/**
|
251 |
+
* PKCS#1 formatted public key (encapsulated)
|
252 |
+
*
|
253 |
+
* Used by PHP's openssl_public_encrypt() and openssl's rsautl (when -pubin is set)
|
254 |
+
*
|
255 |
+
* Has the following header:
|
256 |
+
*
|
257 |
+
* -----BEGIN PUBLIC KEY-----
|
258 |
+
*
|
259 |
+
* Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
|
260 |
+
* is specific to private keys it's basically creating a DER-encoded wrapper
|
261 |
+
* for keys. This just extends that same concept to public keys (much like ssh-keygen)
|
262 |
+
*/
|
263 |
+
define('CRYPT_RSA_PUBLIC_FORMAT_PKCS8', 7);
|
264 |
+
/**#@-*/
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Pure-PHP PKCS#1 compliant implementation of RSA.
|
268 |
+
*
|
269 |
+
* @package Crypt_RSA
|
270 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
271 |
+
* @access public
|
272 |
+
*/
|
273 |
+
class Crypt_RSA
|
274 |
+
{
|
275 |
+
/**
|
276 |
+
* Precomputed Zero
|
277 |
+
*
|
278 |
+
* @var Array
|
279 |
+
* @access private
|
280 |
+
*/
|
281 |
+
var $zero;
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Precomputed One
|
285 |
+
*
|
286 |
+
* @var Array
|
287 |
+
* @access private
|
288 |
+
*/
|
289 |
+
var $one;
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Private Key Format
|
293 |
+
*
|
294 |
+
* @var Integer
|
295 |
+
* @access private
|
296 |
+
*/
|
297 |
+
var $privateKeyFormat = CRYPT_RSA_PRIVATE_FORMAT_PKCS1;
|
298 |
+
|
299 |
+
/**
|
300 |
+
* Public Key Format
|
301 |
+
*
|
302 |
+
* @var Integer
|
303 |
+
* @access public
|
304 |
+
*/
|
305 |
+
var $publicKeyFormat = CRYPT_RSA_PUBLIC_FORMAT_PKCS8;
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Modulus (ie. n)
|
309 |
+
*
|
310 |
+
* @var Math_BigInteger
|
311 |
+
* @access private
|
312 |
+
*/
|
313 |
+
var $modulus;
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Modulus length
|
317 |
+
*
|
318 |
+
* @var Math_BigInteger
|
319 |
+
* @access private
|
320 |
+
*/
|
321 |
+
var $k;
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Exponent (ie. e or d)
|
325 |
+
*
|
326 |
+
* @var Math_BigInteger
|
327 |
+
* @access private
|
328 |
+
*/
|
329 |
+
var $exponent;
|
330 |
+
|
331 |
+
/**
|
332 |
+
* Primes for Chinese Remainder Theorem (ie. p and q)
|
333 |
+
*
|
334 |
+
* @var Array
|
335 |
+
* @access private
|
336 |
+
*/
|
337 |
+
var $primes;
|
338 |
+
|
339 |
+
/**
|
340 |
+
* Exponents for Chinese Remainder Theorem (ie. dP and dQ)
|
341 |
+
*
|
342 |
+
* @var Array
|
343 |
+
* @access private
|
344 |
+
*/
|
345 |
+
var $exponents;
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Coefficients for Chinese Remainder Theorem (ie. qInv)
|
349 |
+
*
|
350 |
+
* @var Array
|
351 |
+
* @access private
|
352 |
+
*/
|
353 |
+
var $coefficients;
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Hash name
|
357 |
+
*
|
358 |
+
* @var String
|
359 |
+
* @access private
|
360 |
+
*/
|
361 |
+
var $hashName;
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Hash function
|
365 |
+
*
|
366 |
+
* @var Crypt_Hash
|
367 |
+
* @access private
|
368 |
+
*/
|
369 |
+
var $hash;
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Length of hash function output
|
373 |
+
*
|
374 |
+
* @var Integer
|
375 |
+
* @access private
|
376 |
+
*/
|
377 |
+
var $hLen;
|
378 |
+
|
379 |
+
/**
|
380 |
+
* Length of salt
|
381 |
+
*
|
382 |
+
* @var Integer
|
383 |
+
* @access private
|
384 |
+
*/
|
385 |
+
var $sLen;
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Hash function for the Mask Generation Function
|
389 |
+
*
|
390 |
+
* @var Crypt_Hash
|
391 |
+
* @access private
|
392 |
+
*/
|
393 |
+
var $mgfHash;
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Length of MGF hash function output
|
397 |
+
*
|
398 |
+
* @var Integer
|
399 |
+
* @access private
|
400 |
+
*/
|
401 |
+
var $mgfHLen;
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Encryption mode
|
405 |
+
*
|
406 |
+
* @var Integer
|
407 |
+
* @access private
|
408 |
+
*/
|
409 |
+
var $encryptionMode = CRYPT_RSA_ENCRYPTION_OAEP;
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Signature mode
|
413 |
+
*
|
414 |
+
* @var Integer
|
415 |
+
* @access private
|
416 |
+
*/
|
417 |
+
var $signatureMode = CRYPT_RSA_SIGNATURE_PSS;
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Public Exponent
|
421 |
+
*
|
422 |
+
* @var Mixed
|
423 |
+
* @access private
|
424 |
+
*/
|
425 |
+
var $publicExponent = false;
|
426 |
+
|
427 |
+
/**
|
428 |
+
* Password
|
429 |
+
*
|
430 |
+
* @var String
|
431 |
+
* @access private
|
432 |
+
*/
|
433 |
+
var $password = false;
|
434 |
+
|
435 |
+
/**
|
436 |
+
* Components
|
437 |
+
*
|
438 |
+
* For use with parsing XML formatted keys. PHP's XML Parser functions use utilized - instead of PHP's DOM functions -
|
439 |
+
* because PHP's XML Parser functions work on PHP4 whereas PHP's DOM functions - although surperior - don't.
|
440 |
+
*
|
441 |
+
* @see Crypt_RSA::_start_element_handler()
|
442 |
+
* @var Array
|
443 |
+
* @access private
|
444 |
+
*/
|
445 |
+
var $components = array();
|
446 |
+
|
447 |
+
/**
|
448 |
+
* Current String
|
449 |
+
*
|
450 |
+
* For use with parsing XML formatted keys.
|
451 |
+
*
|
452 |
+
* @see Crypt_RSA::_character_handler()
|
453 |
+
* @see Crypt_RSA::_stop_element_handler()
|
454 |
+
* @var Mixed
|
455 |
+
* @access private
|
456 |
+
*/
|
457 |
+
var $current;
|
458 |
+
|
459 |
+
/**
|
460 |
+
* OpenSSL configuration file name.
|
461 |
+
*
|
462 |
+
* Set to null to use system configuration file.
|
463 |
+
* @see Crypt_RSA::createKey()
|
464 |
+
* @var Mixed
|
465 |
+
* @Access public
|
466 |
+
*/
|
467 |
+
var $configFile;
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Public key comment field.
|
471 |
+
*
|
472 |
+
* @var String
|
473 |
+
* @access private
|
474 |
+
*/
|
475 |
+
var $comment = 'phpseclib-generated-key';
|
476 |
+
|
477 |
+
/**
|
478 |
+
* The constructor
|
479 |
+
*
|
480 |
+
* If you want to make use of the openssl extension, you'll need to set the mode manually, yourself. The reason
|
481 |
+
* Crypt_RSA doesn't do it is because OpenSSL doesn't fail gracefully. openssl_pkey_new(), in particular, requires
|
482 |
+
* openssl.cnf be present somewhere and, unfortunately, the only real way to find out is too late.
|
483 |
+
*
|
484 |
+
* @return Crypt_RSA
|
485 |
+
* @access public
|
486 |
+
*/
|
487 |
+
function Crypt_RSA()
|
488 |
+
{
|
489 |
+
if (!class_exists('Math_BigInteger')) {
|
490 |
+
include_once 'Math/BigInteger.php';
|
491 |
+
}
|
492 |
+
|
493 |
+
$this->configFile = CRYPT_RSA_OPENSSL_CONFIG;
|
494 |
+
|
495 |
+
if ( !defined('CRYPT_RSA_MODE') ) {
|
496 |
+
switch (true) {
|
497 |
+
// Math/BigInteger's openssl requirements are a little less stringent than Crypt/RSA's. in particular,
|
498 |
+
// Math/BigInteger doesn't require an openssl.cfg file whereas Crypt/RSA does. so if Math/BigInteger
|
499 |
+
// can't use OpenSSL it can be pretty trivially assumed, then, that Crypt/RSA can't either.
|
500 |
+
case defined('MATH_BIGINTEGER_OPENSSL_DISABLE'):
|
501 |
+
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
|
502 |
+
break;
|
503 |
+
// openssl_pkey_get_details - which is used in the only place Crypt/RSA.php uses OpenSSL - was introduced in PHP 5.2.0
|
504 |
+
case !function_exists('openssl_pkey_get_details'):
|
505 |
+
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
|
506 |
+
break;
|
507 |
+
case extension_loaded('openssl') && version_compare(PHP_VERSION, '4.2.0', '>=') && file_exists($this->configFile):
|
508 |
+
// some versions of XAMPP have mismatched versions of OpenSSL which causes it not to work
|
509 |
+
ob_start();
|
510 |
+
@phpinfo();
|
511 |
+
$content = ob_get_contents();
|
512 |
+
ob_end_clean();
|
513 |
+
|
514 |
+
preg_match_all('#OpenSSL (Header|Library) Version(.*)#im', $content, $matches);
|
515 |
+
|
516 |
+
$versions = array();
|
517 |
+
if (!empty($matches[1])) {
|
518 |
+
for ($i = 0; $i < count($matches[1]); $i++) {
|
519 |
+
$fullVersion = trim(str_replace('=>', '', strip_tags($matches[2][$i])));
|
520 |
+
|
521 |
+
// Remove letter part in OpenSSL version
|
522 |
+
if (!preg_match('/(\d+\.\d+\.\d+)/i', $fullVersion, $m)) {
|
523 |
+
$versions[$matches[1][$i]] = $fullVersion;
|
524 |
+
} else {
|
525 |
+
$versions[$matches[1][$i]] = $m[0];
|
526 |
+
}
|
527 |
+
}
|
528 |
+
}
|
529 |
+
|
530 |
+
// it doesn't appear that OpenSSL versions were reported upon until PHP 5.3+
|
531 |
+
switch (true) {
|
532 |
+
case !isset($versions['Header']):
|
533 |
+
case !isset($versions['Library']):
|
534 |
+
case $versions['Header'] == $versions['Library']:
|
535 |
+
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_OPENSSL);
|
536 |
+
break;
|
537 |
+
default:
|
538 |
+
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
|
539 |
+
define('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
|
540 |
+
}
|
541 |
+
break;
|
542 |
+
default:
|
543 |
+
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
|
544 |
+
}
|
545 |
+
}
|
546 |
+
|
547 |
+
$this->zero = new Math_BigInteger();
|
548 |
+
$this->one = new Math_BigInteger(1);
|
549 |
+
|
550 |
+
$this->hash = new Crypt_Hash('sha1');
|
551 |
+
$this->hLen = $this->hash->getLength();
|
552 |
+
$this->hashName = 'sha1';
|
553 |
+
$this->mgfHash = new Crypt_Hash('sha1');
|
554 |
+
$this->mgfHLen = $this->mgfHash->getLength();
|
555 |
+
}
|
556 |
+
|
557 |
+
/**
|
558 |
+
* Create public / private key pair
|
559 |
+
*
|
560 |
+
* Returns an array with the following three elements:
|
561 |
+
* - 'privatekey': The private key.
|
562 |
+
* - 'publickey': The public key.
|
563 |
+
* - 'partialkey': A partially computed key (if the execution time exceeded $timeout).
|
564 |
+
* Will need to be passed back to Crypt_RSA::createKey() as the third parameter for further processing.
|
565 |
+
*
|
566 |
+
* @access public
|
567 |
+
* @param optional Integer $bits
|
568 |
+
* @param optional Integer $timeout
|
569 |
+
* @param optional Math_BigInteger $p
|
570 |
+
*/
|
571 |
+
function createKey($bits = 1024, $timeout = false, $partial = array())
|
572 |
+
{
|
573 |
+
if (!defined('CRYPT_RSA_EXPONENT')) {
|
574 |
+
// http://en.wikipedia.org/wiki/65537_%28number%29
|
575 |
+
define('CRYPT_RSA_EXPONENT', '65537');
|
576 |
+
}
|
577 |
+
// per <http://cseweb.ucsd.edu/~hovav/dist/survey.pdf#page=5>, this number ought not result in primes smaller
|
578 |
+
// than 256 bits. as a consequence if the key you're trying to create is 1024 bits and you've set CRYPT_RSA_SMALLEST_PRIME
|
579 |
+
// to 384 bits then you're going to get a 384 bit prime and a 640 bit prime (384 + 1024 % 384). at least if
|
580 |
+
// CRYPT_RSA_MODE is set to CRYPT_RSA_MODE_INTERNAL. if CRYPT_RSA_MODE is set to CRYPT_RSA_MODE_OPENSSL then
|
581 |
+
// CRYPT_RSA_SMALLEST_PRIME is ignored (ie. multi-prime RSA support is more intended as a way to speed up RSA key
|
582 |
+
// generation when there's a chance neither gmp nor OpenSSL are installed)
|
583 |
+
if (!defined('CRYPT_RSA_SMALLEST_PRIME')) {
|
584 |
+
define('CRYPT_RSA_SMALLEST_PRIME', 4096);
|
585 |
+
}
|
586 |
+
|
587 |
+
// OpenSSL uses 65537 as the exponent and requires RSA keys be 384 bits minimum
|
588 |
+
if ( CRYPT_RSA_MODE == CRYPT_RSA_MODE_OPENSSL && $bits >= 384 && CRYPT_RSA_EXPONENT == 65537) {
|
589 |
+
$config = array();
|
590 |
+
if (isset($this->configFile)) {
|
591 |
+
$config['config'] = $this->configFile;
|
592 |
+
}
|
593 |
+
$rsa = openssl_pkey_new(array('private_key_bits' => $bits) + $config);
|
594 |
+
openssl_pkey_export($rsa, $privatekey, null, $config);
|
595 |
+
$publickey = openssl_pkey_get_details($rsa);
|
596 |
+
$publickey = $publickey['key'];
|
597 |
+
|
598 |
+
$privatekey = call_user_func_array(array($this, '_convertPrivateKey'), array_values($this->_parseKey($privatekey, CRYPT_RSA_PRIVATE_FORMAT_PKCS1)));
|
599 |
+
$publickey = call_user_func_array(array($this, '_convertPublicKey'), array_values($this->_parseKey($publickey, CRYPT_RSA_PUBLIC_FORMAT_PKCS1)));
|
600 |
+
|
601 |
+
// clear the buffer of error strings stemming from a minimalistic openssl.cnf
|
602 |
+
while (openssl_error_string() !== false);
|
603 |
+
|
604 |
+
return array(
|
605 |
+
'privatekey' => $privatekey,
|
606 |
+
'publickey' => $publickey,
|
607 |
+
'partialkey' => false
|
608 |
+
);
|
609 |
+
}
|
610 |
+
|
611 |
+
static $e;
|
612 |
+
if (!isset($e)) {
|
613 |
+
$e = new Math_BigInteger(CRYPT_RSA_EXPONENT);
|
614 |
+
}
|
615 |
+
|
616 |
+
extract($this->_generateMinMax($bits));
|
617 |
+
$absoluteMin = $min;
|
618 |
+
$temp = $bits >> 1; // divide by two to see how many bits P and Q would be
|
619 |
+
if ($temp > CRYPT_RSA_SMALLEST_PRIME) {
|
620 |
+
$num_primes = floor($bits / CRYPT_RSA_SMALLEST_PRIME);
|
621 |
+
$temp = CRYPT_RSA_SMALLEST_PRIME;
|
622 |
+
} else {
|
623 |
+
$num_primes = 2;
|
624 |
+
}
|
625 |
+
extract($this->_generateMinMax($temp + $bits % $temp));
|
626 |
+
$finalMax = $max;
|
627 |
+
extract($this->_generateMinMax($temp));
|
628 |
+
|
629 |
+
$generator = new Math_BigInteger();
|
630 |
+
|
631 |
+
$n = $this->one->copy();
|
632 |
+
if (!empty($partial)) {
|
633 |
+
extract(unserialize($partial));
|
634 |
+
} else {
|
635 |
+
$exponents = $coefficients = $primes = array();
|
636 |
+
$lcm = array(
|
637 |
+
'top' => $this->one->copy(),
|
638 |
+
'bottom' => false
|
639 |
+
);
|
640 |
+
}
|
641 |
+
|
642 |
+
$start = time();
|
643 |
+
$i0 = count($primes) + 1;
|
644 |
+
|
645 |
+
do {
|
646 |
+
for ($i = $i0; $i <= $num_primes; $i++) {
|
647 |
+
if ($timeout !== false) {
|
648 |
+
$timeout-= time() - $start;
|
649 |
+
$start = time();
|
650 |
+
if ($timeout <= 0) {
|
651 |
+
return array(
|
652 |
+
'privatekey' => '',
|
653 |
+
'publickey' => '',
|
654 |
+
'partialkey' => serialize(array(
|
655 |
+
'primes' => $primes,
|
656 |
+
'coefficients' => $coefficients,
|
657 |
+
'lcm' => $lcm,
|
658 |
+
'exponents' => $exponents
|
659 |
+
))
|
660 |
+
);
|
661 |
+
}
|
662 |
+
}
|
663 |
+
|
664 |
+
if ($i == $num_primes) {
|
665 |
+
list($min, $temp) = $absoluteMin->divide($n);
|
666 |
+
if (!$temp->equals($this->zero)) {
|
667 |
+
$min = $min->add($this->one); // ie. ceil()
|
668 |
+
}
|
669 |
+
$primes[$i] = $generator->randomPrime($min, $finalMax, $timeout);
|
670 |
+
} else {
|
671 |
+
$primes[$i] = $generator->randomPrime($min, $max, $timeout);
|
672 |
+
}
|
673 |
+
|
674 |
+
if ($primes[$i] === false) { // if we've reached the timeout
|
675 |
+
if (count($primes) > 1) {
|
676 |
+
$partialkey = '';
|
677 |
+
} else {
|
678 |
+
array_pop($primes);
|
679 |
+
$partialkey = serialize(array(
|
680 |
+
'primes' => $primes,
|
681 |
+
'coefficients' => $coefficients,
|
682 |
+
'lcm' => $lcm,
|
683 |
+
'exponents' => $exponents
|
684 |
+
));
|
685 |
+
}
|
686 |
+
|
687 |
+
return array(
|
688 |
+
'privatekey' => '',
|
689 |
+
'publickey' => '',
|
690 |
+
'partialkey' => $partialkey
|
691 |
+
);
|
692 |
+
}
|
693 |
+
|
694 |
+
// the first coefficient is calculated differently from the rest
|
695 |
+
// ie. instead of being $primes[1]->modInverse($primes[2]), it's $primes[2]->modInverse($primes[1])
|
696 |
+
if ($i > 2) {
|
697 |
+
$coefficients[$i] = $n->modInverse($primes[$i]);
|
698 |
+
}
|
699 |
+
|
700 |
+
$n = $n->multiply($primes[$i]);
|
701 |
+
|
702 |
+
$temp = $primes[$i]->subtract($this->one);
|
703 |
+
|
704 |
+
// textbook RSA implementations use Euler's totient function instead of the least common multiple.
|
705 |
+
// see http://en.wikipedia.org/wiki/Euler%27s_totient_function
|
706 |
+
$lcm['top'] = $lcm['top']->multiply($temp);
|
707 |
+
$lcm['bottom'] = $lcm['bottom'] === false ? $temp : $lcm['bottom']->gcd($temp);
|
708 |
+
|
709 |
+
$exponents[$i] = $e->modInverse($temp);
|
710 |
+
}
|
711 |
+
|
712 |
+
list($temp) = $lcm['top']->divide($lcm['bottom']);
|
713 |
+
$gcd = $temp->gcd($e);
|
714 |
+
$i0 = 1;
|
715 |
+
} while (!$gcd->equals($this->one));
|
716 |
+
|
717 |
+
$d = $e->modInverse($temp);
|
718 |
+
|
719 |
+
$coefficients[2] = $primes[2]->modInverse($primes[1]);
|
720 |
+
|
721 |
+
// from <http://tools.ietf.org/html/rfc3447#appendix-A.1.2>:
|
722 |
+
// RSAPrivateKey ::= SEQUENCE {
|
723 |
+
// version Version,
|
724 |
+
// modulus INTEGER, -- n
|
725 |
+
// publicExponent INTEGER, -- e
|
726 |
+
// privateExponent INTEGER, -- d
|
727 |
+
// prime1 INTEGER, -- p
|
728 |
+
// prime2 INTEGER, -- q
|
729 |
+
// exponent1 INTEGER, -- d mod (p-1)
|
730 |
+
// exponent2 INTEGER, -- d mod (q-1)
|
731 |
+
// coefficient INTEGER, -- (inverse of q) mod p
|
732 |
+
// otherPrimeInfos OtherPrimeInfos OPTIONAL
|
733 |
+
// }
|
734 |
+
|
735 |
+
return array(
|
736 |
+
'privatekey' => $this->_convertPrivateKey($n, $e, $d, $primes, $exponents, $coefficients),
|
737 |
+
'publickey' => $this->_convertPublicKey($n, $e),
|
738 |
+
'partialkey' => false
|
739 |
+
);
|
740 |
+
}
|
741 |
+
|
742 |
+
/**
|
743 |
+
* Convert a private key to the appropriate format.
|
744 |
+
*
|
745 |
+
* @access private
|
746 |
+
* @see setPrivateKeyFormat()
|
747 |
+
* @param String $RSAPrivateKey
|
748 |
+
* @return String
|
749 |
+
*/
|
750 |
+
function _convertPrivateKey($n, $e, $d, $primes, $exponents, $coefficients)
|
751 |
+
{
|
752 |
+
$signed = $this->privateKeyFormat != CRYPT_RSA_PRIVATE_FORMAT_XML;
|
753 |
+
$num_primes = count($primes);
|
754 |
+
$raw = array(
|
755 |
+
'version' => $num_primes == 2 ? chr(0) : chr(1), // two-prime vs. multi
|
756 |
+
'modulus' => $n->toBytes($signed),
|
757 |
+
'publicExponent' => $e->toBytes($signed),
|
758 |
+
'privateExponent' => $d->toBytes($signed),
|
759 |
+
'prime1' => $primes[1]->toBytes($signed),
|
760 |
+
'prime2' => $primes[2]->toBytes($signed),
|
761 |
+
'exponent1' => $exponents[1]->toBytes($signed),
|
762 |
+
'exponent2' => $exponents[2]->toBytes($signed),
|
763 |
+
'coefficient' => $coefficients[2]->toBytes($signed)
|
764 |
+
);
|
765 |
+
|
766 |
+
// if the format in question does not support multi-prime rsa and multi-prime rsa was used,
|
767 |
+
// call _convertPublicKey() instead.
|
768 |
+
switch ($this->privateKeyFormat) {
|
769 |
+
case CRYPT_RSA_PRIVATE_FORMAT_XML:
|
770 |
+
if ($num_primes != 2) {
|
771 |
+
return false;
|
772 |
+
}
|
773 |
+
return "<RSAKeyValue>\r\n" .
|
774 |
+
' <Modulus>' . base64_encode($raw['modulus']) . "</Modulus>\r\n" .
|
775 |
+
' <Exponent>' . base64_encode($raw['publicExponent']) . "</Exponent>\r\n" .
|
776 |
+
' <P>' . base64_encode($raw['prime1']) . "</P>\r\n" .
|
777 |
+
' <Q>' . base64_encode($raw['prime2']) . "</Q>\r\n" .
|
778 |
+
' <DP>' . base64_encode($raw['exponent1']) . "</DP>\r\n" .
|
779 |
+
' <DQ>' . base64_encode($raw['exponent2']) . "</DQ>\r\n" .
|
780 |
+
' <InverseQ>' . base64_encode($raw['coefficient']) . "</InverseQ>\r\n" .
|
781 |
+
' <D>' . base64_encode($raw['privateExponent']) . "</D>\r\n" .
|
782 |
+
'</RSAKeyValue>';
|
783 |
+
break;
|
784 |
+
case CRYPT_RSA_PRIVATE_FORMAT_PUTTY:
|
785 |
+
if ($num_primes != 2) {
|
786 |
+
return false;
|
787 |
+
}
|
788 |
+
$key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
|
789 |
+
$encryption = (!empty($this->password) || is_string($this->password)) ? 'aes256-cbc' : 'none';
|
790 |
+
$key.= $encryption;
|
791 |
+
$key.= "\r\nComment: " . $this->comment . "\r\n";
|
792 |
+
$public = pack('Na*Na*Na*',
|
793 |
+
strlen('ssh-rsa'), 'ssh-rsa', strlen($raw['publicExponent']), $raw['publicExponent'], strlen($raw['modulus']), $raw['modulus']
|
794 |
+
);
|
795 |
+
$source = pack('Na*Na*Na*Na*',
|
796 |
+
strlen('ssh-rsa'), 'ssh-rsa', strlen($encryption), $encryption,
|
797 |
+
strlen($this->comment), $this->comment, strlen($public), $public
|
798 |
+
);
|
799 |
+
$public = base64_encode($public);
|
800 |
+
$key.= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n";
|
801 |
+
$key.= chunk_split($public, 64);
|
802 |
+
$private = pack('Na*Na*Na*Na*',
|
803 |
+
strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'],
|
804 |
+
strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient']
|
805 |
+
);
|
806 |
+
if (empty($this->password) && !is_string($this->password)) {
|
807 |
+
$source.= pack('Na*', strlen($private), $private);
|
808 |
+
$hashkey = 'putty-private-key-file-mac-key';
|
809 |
+
} else {
|
810 |
+
$private.= crypt_random_string(16 - (strlen($private) & 15));
|
811 |
+
$source.= pack('Na*', strlen($private), $private);
|
812 |
+
if (!class_exists('Crypt_AES')) {
|
813 |
+
include_once 'Crypt/AES.php';
|
814 |
+
}
|
815 |
+
$sequence = 0;
|
816 |
+
$symkey = '';
|
817 |
+
while (strlen($symkey) < 32) {
|
818 |
+
$temp = pack('Na*', $sequence++, $this->password);
|
819 |
+
$symkey.= pack('H*', sha1($temp));
|
820 |
+
}
|
821 |
+
$symkey = substr($symkey, 0, 32);
|
822 |
+
$crypto = new Crypt_AES();
|
823 |
+
|
824 |
+
$crypto->setKey($symkey);
|
825 |
+
$crypto->disablePadding();
|
826 |
+
$private = $crypto->encrypt($private);
|
827 |
+
$hashkey = 'putty-private-key-file-mac-key' . $this->password;
|
828 |
+
}
|
829 |
+
|
830 |
+
$private = base64_encode($private);
|
831 |
+
$key.= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
|
832 |
+
$key.= chunk_split($private, 64);
|
833 |
+
if (!class_exists('Crypt_Hash')) {
|
834 |
+
include_once 'Crypt/Hash.php';
|
835 |
+
}
|
836 |
+
$hash = new Crypt_Hash('sha1');
|
837 |
+
$hash->setKey(pack('H*', sha1($hashkey)));
|
838 |
+
$key.= 'Private-MAC: ' . bin2hex($hash->hash($source)) . "\r\n";
|
839 |
+
|
840 |
+
return $key;
|
841 |
+
default: // eg. CRYPT_RSA_PRIVATE_FORMAT_PKCS1
|
842 |
+
$components = array();
|
843 |
+
foreach ($raw as $name => $value) {
|
844 |
+
$components[$name] = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($value)), $value);
|
845 |
+
}
|
846 |
+
|
847 |
+
$RSAPrivateKey = implode('', $components);
|
848 |
+
|
849 |
+
if ($num_primes > 2) {
|
850 |
+
$OtherPrimeInfos = '';
|
851 |
+
for ($i = 3; $i <= $num_primes; $i++) {
|
852 |
+
// OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo
|
853 |
+
//
|
854 |
+
// OtherPrimeInfo ::= SEQUENCE {
|
855 |
+
// prime INTEGER, -- ri
|
856 |
+
// exponent INTEGER, -- di
|
857 |
+
// coefficient INTEGER -- ti
|
858 |
+
// }
|
859 |
+
$OtherPrimeInfo = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($primes[$i]->toBytes(true))), $primes[$i]->toBytes(true));
|
860 |
+
$OtherPrimeInfo.= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true));
|
861 |
+
$OtherPrimeInfo.= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true));
|
862 |
+
$OtherPrimeInfos.= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo);
|
863 |
+
}
|
864 |
+
$RSAPrivateKey.= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos);
|
865 |
+
}
|
866 |
+
|
867 |
+
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
|
868 |
+
|
869 |
+
if ($this->privateKeyFormat == CRYPT_RSA_PRIVATE_FORMAT_PKCS8) {
|
870 |
+
$rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
|
871 |
+
$RSAPrivateKey = pack('Ca*a*Ca*a*',
|
872 |
+
CRYPT_RSA_ASN1_INTEGER, "\01\00", $rsaOID, 4, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey
|
873 |
+
);
|
874 |
+
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
|
875 |
+
if (!empty($this->password) || is_string($this->password)) {
|
876 |
+
$salt = crypt_random_string(8);
|
877 |
+
$iterationCount = 2048;
|
878 |
+
|
879 |
+
if (!class_exists('Crypt_DES')) {
|
880 |
+
include_once 'Crypt/DES.php';
|
881 |
+
}
|
882 |
+
$crypto = new Crypt_DES();
|
883 |
+
$crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount);
|
884 |
+
$RSAPrivateKey = $crypto->encrypt($RSAPrivateKey);
|
885 |
+
|
886 |
+
$parameters = pack('Ca*a*Ca*N',
|
887 |
+
CRYPT_RSA_ASN1_OCTETSTRING, $this->_encodeLength(strlen($salt)), $salt,
|
888 |
+
CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(4), $iterationCount
|
889 |
+
);
|
890 |
+
$pbeWithMD5AndDES_CBC = "\x2a\x86\x48\x86\xf7\x0d\x01\x05\x03";
|
891 |
+
|
892 |
+
$encryptionAlgorithm = pack('Ca*a*Ca*a*',
|
893 |
+
CRYPT_RSA_ASN1_OBJECT, $this->_encodeLength(strlen($pbeWithMD5AndDES_CBC)), $pbeWithMD5AndDES_CBC,
|
894 |
+
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($parameters)), $parameters
|
895 |
+
);
|
896 |
+
|
897 |
+
$RSAPrivateKey = pack('Ca*a*Ca*a*',
|
898 |
+
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($encryptionAlgorithm)), $encryptionAlgorithm,
|
899 |
+
CRYPT_RSA_ASN1_OCTETSTRING, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey
|
900 |
+
);
|
901 |
+
|
902 |
+
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
|
903 |
+
|
904 |
+
$RSAPrivateKey = "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" .
|
905 |
+
chunk_split(base64_encode($RSAPrivateKey), 64) .
|
906 |
+
'-----END ENCRYPTED PRIVATE KEY-----';
|
907 |
+
} else {
|
908 |
+
$RSAPrivateKey = "-----BEGIN PRIVATE KEY-----\r\n" .
|
909 |
+
chunk_split(base64_encode($RSAPrivateKey), 64) .
|
910 |
+
'-----END PRIVATE KEY-----';
|
911 |
+
}
|
912 |
+
return $RSAPrivateKey;
|
913 |
+
}
|
914 |
+
|
915 |
+
if (!empty($this->password) || is_string($this->password)) {
|
916 |
+
$iv = crypt_random_string(8);
|
917 |
+
$symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key
|
918 |
+
$symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
|
919 |
+
if (!class_exists('Crypt_TripleDES')) {
|
920 |
+
include_once 'Crypt/TripleDES.php';
|
921 |
+
}
|
922 |
+
$des = new Crypt_TripleDES();
|
923 |
+
$des->setKey($symkey);
|
924 |
+
$des->setIV($iv);
|
925 |
+
$iv = strtoupper(bin2hex($iv));
|
926 |
+
$RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" .
|
927 |
+
"Proc-Type: 4,ENCRYPTED\r\n" .
|
928 |
+
"DEK-Info: DES-EDE3-CBC,$iv\r\n" .
|
929 |
+
"\r\n" .
|
930 |
+
chunk_split(base64_encode($des->encrypt($RSAPrivateKey)), 64) .
|
931 |
+
'-----END RSA PRIVATE KEY-----';
|
932 |
+
} else {
|
933 |
+
$RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" .
|
934 |
+
chunk_split(base64_encode($RSAPrivateKey), 64) .
|
935 |
+
'-----END RSA PRIVATE KEY-----';
|
936 |
+
}
|
937 |
+
|
938 |
+
return $RSAPrivateKey;
|
939 |
+
}
|
940 |
+
}
|
941 |
+
|
942 |
+
/**
|
943 |
+
* Convert a public key to the appropriate format
|
944 |
+
*
|
945 |
+
* @access private
|
946 |
+
* @see setPublicKeyFormat()
|
947 |
+
* @param String $RSAPrivateKey
|
948 |
+
* @return String
|
949 |
+
*/
|
950 |
+
function _convertPublicKey($n, $e)
|
951 |
+
{
|
952 |
+
$signed = $this->publicKeyFormat != CRYPT_RSA_PUBLIC_FORMAT_XML;
|
953 |
+
|
954 |
+
$modulus = $n->toBytes($signed);
|
955 |
+
$publicExponent = $e->toBytes($signed);
|
956 |
+
|
957 |
+
switch ($this->publicKeyFormat) {
|
958 |
+
case CRYPT_RSA_PUBLIC_FORMAT_RAW:
|
959 |
+
return array('e' => $e->copy(), 'n' => $n->copy());
|
960 |
+
case CRYPT_RSA_PUBLIC_FORMAT_XML:
|
961 |
+
return "<RSAKeyValue>\r\n" .
|
962 |
+
' <Modulus>' . base64_encode($modulus) . "</Modulus>\r\n" .
|
963 |
+
' <Exponent>' . base64_encode($publicExponent) . "</Exponent>\r\n" .
|
964 |
+
'</RSAKeyValue>';
|
965 |
+
break;
|
966 |
+
case CRYPT_RSA_PUBLIC_FORMAT_OPENSSH:
|
967 |
+
// from <http://tools.ietf.org/html/rfc4253#page-15>:
|
968 |
+
// string "ssh-rsa"
|
969 |
+
// mpint e
|
970 |
+
// mpint n
|
971 |
+
$RSAPublicKey = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($publicExponent), $publicExponent, strlen($modulus), $modulus);
|
972 |
+
$RSAPublicKey = 'ssh-rsa ' . base64_encode($RSAPublicKey) . ' ' . $this->comment;
|
973 |
+
|
974 |
+
return $RSAPublicKey;
|
975 |
+
default: // eg. CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW or CRYPT_RSA_PUBLIC_FORMAT_PKCS1
|
976 |
+
// from <http://tools.ietf.org/html/rfc3447#appendix-A.1.1>:
|
977 |
+
// RSAPublicKey ::= SEQUENCE {
|
978 |
+
// modulus INTEGER, -- n
|
979 |
+
// publicExponent INTEGER -- e
|
980 |
+
// }
|
981 |
+
$components = array(
|
982 |
+
'modulus' => pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($modulus)), $modulus),
|
983 |
+
'publicExponent' => pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($publicExponent)), $publicExponent)
|
984 |
+
);
|
985 |
+
|
986 |
+
$RSAPublicKey = pack('Ca*a*a*',
|
987 |
+
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])),
|
988 |
+
$components['modulus'], $components['publicExponent']
|
989 |
+
);
|
990 |
+
|
991 |
+
if ($this->publicKeyFormat == CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW) {
|
992 |
+
$RSAPublicKey = "-----BEGIN RSA PUBLIC KEY-----\r\n" .
|
993 |
+
chunk_split(base64_encode($RSAPublicKey), 64) .
|
994 |
+
'-----END RSA PUBLIC KEY-----';
|
995 |
+
} else {
|
996 |
+
// sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.
|
997 |
+
$rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
|
998 |
+
$RSAPublicKey = chr(0) . $RSAPublicKey;
|
999 |
+
$RSAPublicKey = chr(3) . $this->_encodeLength(strlen($RSAPublicKey)) . $RSAPublicKey;
|
1000 |
+
|
1001 |
+
$RSAPublicKey = pack('Ca*a*',
|
1002 |
+
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($rsaOID . $RSAPublicKey)), $rsaOID . $RSAPublicKey
|
1003 |
+
);
|
1004 |
+
|
1005 |
+
$RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
|
1006 |
+
chunk_split(base64_encode($RSAPublicKey), 64) .
|
1007 |
+
'-----END PUBLIC KEY-----';
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
return $RSAPublicKey;
|
1011 |
+
}
|
1012 |
+
}
|
1013 |
+
|
1014 |
+
/**
|
1015 |
+
* Break a public or private key down into its constituant components
|
1016 |
+
*
|
1017 |
+
* @access private
|
1018 |
+
* @see _convertPublicKey()
|
1019 |
+
* @see _convertPrivateKey()
|
1020 |
+
* @param String $key
|
1021 |
+
* @param Integer $type
|
1022 |
+
* @return Array
|
1023 |
+
*/
|
1024 |
+
function _parseKey($key, $type)
|
1025 |
+
{
|
1026 |
+
if ($type != CRYPT_RSA_PUBLIC_FORMAT_RAW && !is_string($key)) {
|
1027 |
+
return false;
|
1028 |
+
}
|
1029 |
+
|
1030 |
+
switch ($type) {
|
1031 |
+
case CRYPT_RSA_PUBLIC_FORMAT_RAW:
|
1032 |
+
if (!is_array($key)) {
|
1033 |
+
return false;
|
1034 |
+
}
|
1035 |
+
$components = array();
|
1036 |
+
switch (true) {
|
1037 |
+
case isset($key['e']):
|
1038 |
+
$components['publicExponent'] = $key['e']->copy();
|
1039 |
+
break;
|
1040 |
+
case isset($key['exponent']):
|
1041 |
+
$components['publicExponent'] = $key['exponent']->copy();
|
1042 |
+
break;
|
1043 |
+
case isset($key['publicExponent']):
|
1044 |
+
$components['publicExponent'] = $key['publicExponent']->copy();
|
1045 |
+
break;
|
1046 |
+
case isset($key[0]):
|
1047 |
+
$components['publicExponent'] = $key[0]->copy();
|
1048 |
+
}
|
1049 |
+
switch (true) {
|
1050 |
+
case isset($key['n']):
|
1051 |
+
$components['modulus'] = $key['n']->copy();
|
1052 |
+
break;
|
1053 |
+
case isset($key['modulo']):
|
1054 |
+
$components['modulus'] = $key['modulo']->copy();
|
1055 |
+
break;
|
1056 |
+
case isset($key['modulus']):
|
1057 |
+
$components['modulus'] = $key['modulus']->copy();
|
1058 |
+
break;
|
1059 |
+
case isset($key[1]):
|
1060 |
+
$components['modulus'] = $key[1]->copy();
|
1061 |
+
}
|
1062 |
+
return isset($components['modulus']) && isset($components['publicExponent']) ? $components : false;
|
1063 |
+
case CRYPT_RSA_PRIVATE_FORMAT_PKCS1:
|
1064 |
+
case CRYPT_RSA_PRIVATE_FORMAT_PKCS8:
|
1065 |
+
case CRYPT_RSA_PUBLIC_FORMAT_PKCS1:
|
1066 |
+
/* Although PKCS#1 proposes a format that public and private keys can use, encrypting them is
|
1067 |
+
"outside the scope" of PKCS#1. PKCS#1 then refers you to PKCS#12 and PKCS#15 if you're wanting to
|
1068 |
+
protect private keys, however, that's not what OpenSSL* does. OpenSSL protects private keys by adding
|
1069 |
+
two new "fields" to the key - DEK-Info and Proc-Type. These fields are discussed here:
|
1070 |
+
|
1071 |
+
http://tools.ietf.org/html/rfc1421#section-4.6.1.1
|
1072 |
+
http://tools.ietf.org/html/rfc1421#section-4.6.1.3
|
1073 |
+
|
1074 |
+
DES-EDE3-CBC as an algorithm, however, is not discussed anywhere, near as I can tell.
|
1075 |
+
DES-CBC and DES-EDE are discussed in RFC1423, however, DES-EDE3-CBC isn't, nor is its key derivation
|
1076 |
+
function. As is, the definitive authority on this encoding scheme isn't the IETF but rather OpenSSL's
|
1077 |
+
own implementation. ie. the implementation *is* the standard and any bugs that may exist in that
|
1078 |
+
implementation are part of the standard, as well.
|
1079 |
+
|
1080 |
+
* OpenSSL is the de facto standard. It's utilized by OpenSSH and other projects */
|
1081 |
+
if (preg_match('#DEK-Info: (.+),(.+)#', $key, $matches)) {
|
1082 |
+
$iv = pack('H*', trim($matches[2]));
|
1083 |
+
$symkey = pack('H*', md5($this->password . substr($iv, 0, 8))); // symkey is short for symmetric key
|
1084 |
+
$symkey.= pack('H*', md5($symkey . $this->password . substr($iv, 0, 8)));
|
1085 |
+
// remove the Proc-Type / DEK-Info sections as they're no longer needed
|
1086 |
+
$key = preg_replace('#^(?:Proc-Type|DEK-Info): .*#m', '', $key);
|
1087 |
+
$ciphertext = $this->_extractBER($key);
|
1088 |
+
if ($ciphertext === false) {
|
1089 |
+
$ciphertext = $key;
|
1090 |
+
}
|
1091 |
+
switch ($matches[1]) {
|
1092 |
+
case 'AES-256-CBC':
|
1093 |
+
if (!class_exists('Crypt_AES')) {
|
1094 |
+
include_once 'Crypt/AES.php';
|
1095 |
+
}
|
1096 |
+
$crypto = new Crypt_AES();
|
1097 |
+
break;
|
1098 |
+
case 'AES-128-CBC':
|
1099 |
+
if (!class_exists('Crypt_AES')) {
|
1100 |
+
include_once 'Crypt/AES.php';
|
1101 |
+
}
|
1102 |
+
$symkey = substr($symkey, 0, 16);
|
1103 |
+
$crypto = new Crypt_AES();
|
1104 |
+
break;
|
1105 |
+
case 'DES-EDE3-CFB':
|
1106 |
+
if (!class_exists('Crypt_TripleDES')) {
|
1107 |
+
include_once 'Crypt/TripleDES.php';
|
1108 |
+
}
|
1109 |
+
$crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
|
1110 |
+
break;
|
1111 |
+
case 'DES-EDE3-CBC':
|
1112 |
+
if (!class_exists('Crypt_TripleDES')) {
|
1113 |
+
include_once 'Crypt/TripleDES.php';
|
1114 |
+
}
|
1115 |
+
$symkey = substr($symkey, 0, 24);
|
1116 |
+
$crypto = new Crypt_TripleDES();
|
1117 |
+
break;
|
1118 |
+
case 'DES-CBC':
|
1119 |
+
if (!class_exists('Crypt_DES')) {
|
1120 |
+
include_once 'Crypt/DES.php';
|
1121 |
+
}
|
1122 |
+
$crypto = new Crypt_DES();
|
1123 |
+
break;
|
1124 |
+
default:
|
1125 |
+
return false;
|
1126 |
+
}
|
1127 |
+
$crypto->setKey($symkey);
|
1128 |
+
$crypto->setIV($iv);
|
1129 |
+
$decoded = $crypto->decrypt($ciphertext);
|
1130 |
+
} else {
|
1131 |
+
$decoded = $this->_extractBER($key);
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
if ($decoded !== false) {
|
1135 |
+
$key = $decoded;
|
1136 |
+
}
|
1137 |
+
|
1138 |
+
$components = array();
|
1139 |
+
|
1140 |
+
if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
|
1141 |
+
return false;
|
1142 |
+
}
|
1143 |
+
if ($this->_decodeLength($key) != strlen($key)) {
|
1144 |
+
return false;
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
$tag = ord($this->_string_shift($key));
|
1148 |
+
/* intended for keys for which OpenSSL's asn1parse returns the following:
|
1149 |
+
|
1150 |
+
0:d=0 hl=4 l= 631 cons: SEQUENCE
|
1151 |
+
4:d=1 hl=2 l= 1 prim: INTEGER :00
|
1152 |
+
7:d=1 hl=2 l= 13 cons: SEQUENCE
|
1153 |
+
9:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
|
1154 |
+
20:d=2 hl=2 l= 0 prim: NULL
|
1155 |
+
22:d=1 hl=4 l= 609 prim: OCTET STRING
|
1156 |
+
|
1157 |
+
ie. PKCS8 keys*/
|
1158 |
+
|
1159 |
+
if ($tag == CRYPT_RSA_ASN1_INTEGER && substr($key, 0, 3) == "\x01\x00\x30") {
|
1160 |
+
$this->_string_shift($key, 3);
|
1161 |
+
$tag = CRYPT_RSA_ASN1_SEQUENCE;
|
1162 |
+
}
|
1163 |
+
|
1164 |
+
if ($tag == CRYPT_RSA_ASN1_SEQUENCE) {
|
1165 |
+
$temp = $this->_string_shift($key, $this->_decodeLength($key));
|
1166 |
+
if (ord($this->_string_shift($temp)) != CRYPT_RSA_ASN1_OBJECT) {
|
1167 |
+
return false;
|
1168 |
+
}
|
1169 |
+
$length = $this->_decodeLength($temp);
|
1170 |
+
switch ($this->_string_shift($temp, $length)) {
|
1171 |
+
case "\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01": // rsaEncryption
|
1172 |
+
break;
|
1173 |
+
case "\x2a\x86\x48\x86\xf7\x0d\x01\x05\x03": // pbeWithMD5AndDES-CBC
|
1174 |
+
/*
|
1175 |
+
PBEParameter ::= SEQUENCE {
|
1176 |
+
salt OCTET STRING (SIZE(8)),
|
1177 |
+
iterationCount INTEGER }
|
1178 |
+
*/
|
1179 |
+
if (ord($this->_string_shift($temp)) != CRYPT_RSA_ASN1_SEQUENCE) {
|
1180 |
+
return false;
|
1181 |
+
}
|
1182 |
+
if ($this->_decodeLength($temp) != strlen($temp)) {
|
1183 |
+
return false;
|
1184 |
+
}
|
1185 |
+
$this->_string_shift($temp); // assume it's an octet string
|
1186 |
+
$salt = $this->_string_shift($temp, $this->_decodeLength($temp));
|
1187 |
+
if (ord($this->_string_shift($temp)) != CRYPT_RSA_ASN1_INTEGER) {
|
1188 |
+
return false;
|
1189 |
+
}
|
1190 |
+
$this->_decodeLength($temp);
|
1191 |
+
list(, $iterationCount) = unpack('N', str_pad($temp, 4, chr(0), STR_PAD_LEFT));
|
1192 |
+
$this->_string_shift($key); // assume it's an octet string
|
1193 |
+
$length = $this->_decodeLength($key);
|
1194 |
+
if (strlen($key) != $length) {
|
1195 |
+
return false;
|
1196 |
+
}
|
1197 |
+
|
1198 |
+
if (!class_exists('Crypt_DES')) {
|
1199 |
+
include_once 'Crypt/DES.php';
|
1200 |
+
}
|
1201 |
+
$crypto = new Crypt_DES();
|
1202 |
+
$crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount);
|
1203 |
+
$key = $crypto->decrypt($key);
|
1204 |
+
if ($key === false) {
|
1205 |
+
return false;
|
1206 |
+
}
|
1207 |
+
return $this->_parseKey($key, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
|
1208 |
+
default:
|
1209 |
+
return false;
|
1210 |
+
}
|
1211 |
+
/* intended for keys for which OpenSSL's asn1parse returns the following:
|
1212 |
+
|
1213 |
+
0:d=0 hl=4 l= 290 cons: SEQUENCE
|
1214 |
+
4:d=1 hl=2 l= 13 cons: SEQUENCE
|
1215 |
+
6:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
|
1216 |
+
17:d=2 hl=2 l= 0 prim: NULL
|
1217 |
+
19:d=1 hl=4 l= 271 prim: BIT STRING */
|
1218 |
+
$tag = ord($this->_string_shift($key)); // skip over the BIT STRING / OCTET STRING tag
|
1219 |
+
$this->_decodeLength($key); // skip over the BIT STRING / OCTET STRING length
|
1220 |
+
// "The initial octet shall encode, as an unsigned binary integer wtih bit 1 as the least significant bit, the number of
|
1221 |
+
// unused bits in the final subsequent octet. The number shall be in the range zero to seven."
|
1222 |
+
// -- http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf (section 8.6.2.2)
|
1223 |
+
if ($tag == CRYPT_RSA_ASN1_BITSTRING) {
|
1224 |
+
$this->_string_shift($key);
|
1225 |
+
}
|
1226 |
+
if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
|
1227 |
+
return false;
|
1228 |
+
}
|
1229 |
+
if ($this->_decodeLength($key) != strlen($key)) {
|
1230 |
+
return false;
|
1231 |
+
}
|
1232 |
+
$tag = ord($this->_string_shift($key));
|
1233 |
+
}
|
1234 |
+
if ($tag != CRYPT_RSA_ASN1_INTEGER) {
|
1235 |
+
return false;
|
1236 |
+
}
|
1237 |
+
|
1238 |
+
$length = $this->_decodeLength($key);
|
1239 |
+
$temp = $this->_string_shift($key, $length);
|
1240 |
+
if (strlen($temp) != 1 || ord($temp) > 2) {
|
1241 |
+
$components['modulus'] = new Math_BigInteger($temp, 256);
|
1242 |
+
$this->_string_shift($key); // skip over CRYPT_RSA_ASN1_INTEGER
|
1243 |
+
$length = $this->_decodeLength($key);
|
1244 |
+
$components[$type == CRYPT_RSA_PUBLIC_FORMAT_PKCS1 ? 'publicExponent' : 'privateExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1245 |
+
|
1246 |
+
return $components;
|
1247 |
+
}
|
1248 |
+
if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_INTEGER) {
|
1249 |
+
return false;
|
1250 |
+
}
|
1251 |
+
$length = $this->_decodeLength($key);
|
1252 |
+
$components['modulus'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1253 |
+
$this->_string_shift($key);
|
1254 |
+
$length = $this->_decodeLength($key);
|
1255 |
+
$components['publicExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1256 |
+
$this->_string_shift($key);
|
1257 |
+
$length = $this->_decodeLength($key);
|
1258 |
+
$components['privateExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1259 |
+
$this->_string_shift($key);
|
1260 |
+
$length = $this->_decodeLength($key);
|
1261 |
+
$components['primes'] = array(1 => new Math_BigInteger($this->_string_shift($key, $length), 256));
|
1262 |
+
$this->_string_shift($key);
|
1263 |
+
$length = $this->_decodeLength($key);
|
1264 |
+
$components['primes'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1265 |
+
$this->_string_shift($key);
|
1266 |
+
$length = $this->_decodeLength($key);
|
1267 |
+
$components['exponents'] = array(1 => new Math_BigInteger($this->_string_shift($key, $length), 256));
|
1268 |
+
$this->_string_shift($key);
|
1269 |
+
$length = $this->_decodeLength($key);
|
1270 |
+
$components['exponents'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1271 |
+
$this->_string_shift($key);
|
1272 |
+
$length = $this->_decodeLength($key);
|
1273 |
+
$components['coefficients'] = array(2 => new Math_BigInteger($this->_string_shift($key, $length), 256));
|
1274 |
+
|
1275 |
+
if (!empty($key)) {
|
1276 |
+
if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
|
1277 |
+
return false;
|
1278 |
+
}
|
1279 |
+
$this->_decodeLength($key);
|
1280 |
+
while (!empty($key)) {
|
1281 |
+
if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
|
1282 |
+
return false;
|
1283 |
+
}
|
1284 |
+
$this->_decodeLength($key);
|
1285 |
+
$key = substr($key, 1);
|
1286 |
+
$length = $this->_decodeLength($key);
|
1287 |
+
$components['primes'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1288 |
+
$this->_string_shift($key);
|
1289 |
+
$length = $this->_decodeLength($key);
|
1290 |
+
$components['exponents'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1291 |
+
$this->_string_shift($key);
|
1292 |
+
$length = $this->_decodeLength($key);
|
1293 |
+
$components['coefficients'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
|
1294 |
+
}
|
1295 |
+
}
|
1296 |
+
|
1297 |
+
return $components;
|
1298 |
+
case CRYPT_RSA_PUBLIC_FORMAT_OPENSSH:
|
1299 |
+
$parts = explode(' ', $key, 3);
|
1300 |
+
|
1301 |
+
$key = isset($parts[1]) ? base64_decode($parts[1]) : false;
|
1302 |
+
if ($key === false) {
|
1303 |
+
return false;
|
1304 |
+
}
|
1305 |
+
|
1306 |
+
$comment = isset($parts[2]) ? $parts[2] : false;
|
1307 |
+
|
1308 |
+
$cleanup = substr($key, 0, 11) == "\0\0\0\7ssh-rsa";
|
1309 |
+
|
1310 |
+
if (strlen($key) <= 4) {
|
1311 |
+
return false;
|
1312 |
+
}
|
1313 |
+
extract(unpack('Nlength', $this->_string_shift($key, 4)));
|
1314 |
+
$publicExponent = new Math_BigInteger($this->_string_shift($key, $length), -256);
|
1315 |
+
if (strlen($key) <= 4) {
|
1316 |
+
return false;
|
1317 |
+
}
|
1318 |
+
extract(unpack('Nlength', $this->_string_shift($key, 4)));
|
1319 |
+
$modulus = new Math_BigInteger($this->_string_shift($key, $length), -256);
|
1320 |
+
|
1321 |
+
if ($cleanup && strlen($key)) {
|
1322 |
+
if (strlen($key) <= 4) {
|
1323 |
+
return false;
|
1324 |
+
}
|
1325 |
+
extract(unpack('Nlength', $this->_string_shift($key, 4)));
|
1326 |
+
$realModulus = new Math_BigInteger($this->_string_shift($key, $length), -256);
|
1327 |
+
return strlen($key) ? false : array(
|
1328 |
+
'modulus' => $realModulus,
|
1329 |
+
'publicExponent' => $modulus,
|
1330 |
+
'comment' => $comment
|
1331 |
+
);
|
1332 |
+
} else {
|
1333 |
+
return strlen($key) ? false : array(
|
1334 |
+
'modulus' => $modulus,
|
1335 |
+
'publicExponent' => $publicExponent,
|
1336 |
+
'comment' => $comment
|
1337 |
+
);
|
1338 |
+
}
|
1339 |
+
// http://www.w3.org/TR/xmldsig-core/#sec-RSAKeyValue
|
1340 |
+
// http://en.wikipedia.org/wiki/XML_Signature
|
1341 |
+
case CRYPT_RSA_PRIVATE_FORMAT_XML:
|
1342 |
+
case CRYPT_RSA_PUBLIC_FORMAT_XML:
|
1343 |
+
$this->components = array();
|
1344 |
+
|
1345 |
+
$xml = xml_parser_create('UTF-8');
|
1346 |
+
xml_set_object($xml, $this);
|
1347 |
+
xml_set_element_handler($xml, '_start_element_handler', '_stop_element_handler');
|
1348 |
+
xml_set_character_data_handler($xml, '_data_handler');
|
1349 |
+
// add <xml></xml> to account for "dangling" tags like <BitStrength>...</BitStrength> that are sometimes added
|
1350 |
+
if (!xml_parse($xml, '<xml>' . $key . '</xml>')) {
|
1351 |
+
return false;
|
1352 |
+
}
|
1353 |
+
|
1354 |
+
return isset($this->components['modulus']) && isset($this->components['publicExponent']) ? $this->components : false;
|
1355 |
+
// from PuTTY's SSHPUBK.C
|
1356 |
+
case CRYPT_RSA_PRIVATE_FORMAT_PUTTY:
|
1357 |
+
$components = array();
|
1358 |
+
$key = preg_split('#\r\n|\r|\n#', $key);
|
1359 |
+
$type = trim(preg_replace('#PuTTY-User-Key-File-2: (.+)#', '$1', $key[0]));
|
1360 |
+
if ($type != 'ssh-rsa') {
|
1361 |
+
return false;
|
1362 |
+
}
|
1363 |
+
$encryption = trim(preg_replace('#Encryption: (.+)#', '$1', $key[1]));
|
1364 |
+
$comment = trim(preg_replace('#Comment: (.+)#', '$1', $key[2]));
|
1365 |
+
|
1366 |
+
$publicLength = trim(preg_replace('#Public-Lines: (\d+)#', '$1', $key[3]));
|
1367 |
+
$public = base64_decode(implode('', array_map('trim', array_slice($key, 4, $publicLength))));
|
1368 |
+
$public = substr($public, 11);
|
1369 |
+
extract(unpack('Nlength', $this->_string_shift($public, 4)));
|
1370 |
+
$components['publicExponent'] = new Math_BigInteger($this->_string_shift($public, $length), -256);
|
1371 |
+
extract(unpack('Nlength', $this->_string_shift($public, 4)));
|
1372 |
+
$components['modulus'] = new Math_BigInteger($this->_string_shift($public, $length), -256);
|
1373 |
+
|
1374 |
+
$privateLength = trim(preg_replace('#Private-Lines: (\d+)#', '$1', $key[$publicLength + 4]));
|
1375 |
+
$private = base64_decode(implode('', array_map('trim', array_slice($key, $publicLength + 5, $privateLength))));
|
1376 |
+
|
1377 |
+
switch ($encryption) {
|
1378 |
+
case 'aes256-cbc':
|
1379 |
+
if (!class_exists('Crypt_AES')) {
|
1380 |
+
include_once 'Crypt/AES.php';
|
1381 |
+
}
|
1382 |
+
$symkey = '';
|
1383 |
+
$sequence = 0;
|
1384 |
+
while (strlen($symkey) < 32) {
|
1385 |
+
$temp = pack('Na*', $sequence++, $this->password);
|
1386 |
+
$symkey.= pack('H*', sha1($temp));
|
1387 |
+
}
|
1388 |
+
$symkey = substr($symkey, 0, 32);
|
1389 |
+
$crypto = new Crypt_AES();
|
1390 |
+
}
|
1391 |
+
|
1392 |
+
if ($encryption != 'none') {
|
1393 |
+
$crypto->setKey($symkey);
|
1394 |
+
$crypto->disablePadding();
|
1395 |
+
$private = $crypto->decrypt($private);
|
1396 |
+
if ($private === false) {
|
1397 |
+
return false;
|
1398 |
+
}
|
1399 |
+
}
|
1400 |
+
|
1401 |
+
extract(unpack('Nlength', $this->_string_shift($private, 4)));
|
1402 |
+
if (strlen($private) < $length) {
|
1403 |
+
return false;
|
1404 |
+
}
|
1405 |
+
$components['privateExponent'] = new Math_BigInteger($this->_string_shift($private, $length), -256);
|
1406 |
+
extract(unpack('Nlength', $this->_string_shift($private, 4)));
|
1407 |
+
if (strlen($private) < $length) {
|
1408 |
+
return false;
|
1409 |
+
}
|
1410 |
+
$components['primes'] = array(1 => new Math_BigInteger($this->_string_shift($private, $length), -256));
|
1411 |
+
extract(unpack('Nlength', $this->_string_shift($private, 4)));
|
1412 |
+
if (strlen($private) < $length) {
|
1413 |
+
return false;
|
1414 |
+
}
|
1415 |
+
$components['primes'][] = new Math_BigInteger($this->_string_shift($private, $length), -256);
|
1416 |
+
|
1417 |
+
$temp = $components['primes'][1]->subtract($this->one);
|
1418 |
+
$components['exponents'] = array(1 => $components['publicExponent']->modInverse($temp));
|
1419 |
+
$temp = $components['primes'][2]->subtract($this->one);
|
1420 |
+
$components['exponents'][] = $components['publicExponent']->modInverse($temp);
|
1421 |
+
|
1422 |
+
extract(unpack('Nlength', $this->_string_shift($private, 4)));
|
1423 |
+
if (strlen($private) < $length) {
|
1424 |
+
return false;
|
1425 |
+
}
|
1426 |
+
$components['coefficients'] = array(2 => new Math_BigInteger($this->_string_shift($private, $length), -256));
|
1427 |
+
|
1428 |
+
return $components;
|
1429 |
+
}
|
1430 |
+
}
|
1431 |
+
|
1432 |
+
/**
|
1433 |
+
* Returns the key size
|
1434 |
+
*
|
1435 |
+
* More specifically, this returns the size of the modulo in bits.
|
1436 |
+
*
|
1437 |
+
* @access public
|
1438 |
+
* @return Integer
|
1439 |
+
*/
|
1440 |
+
function getSize()
|
1441 |
+
{
|
1442 |
+
return !isset($this->modulus) ? 0 : strlen($this->modulus->toBits());
|
1443 |
+
}
|
1444 |
+
|
1445 |
+
/**
|
1446 |
+
* Start Element Handler
|
1447 |
+
*
|
1448 |
+
* Called by xml_set_element_handler()
|
1449 |
+
*
|
1450 |
+
* @access private
|
1451 |
+
* @param Resource $parser
|
1452 |
+
* @param String $name
|
1453 |
+
* @param Array $attribs
|
1454 |
+
*/
|
1455 |
+
function _start_element_handler($parser, $name, $attribs)
|
1456 |
+
{
|
1457 |
+
//$name = strtoupper($name);
|
1458 |
+
switch ($name) {
|
1459 |
+
case 'MODULUS':
|
1460 |
+
$this->current = &$this->components['modulus'];
|
1461 |
+
break;
|
1462 |
+
case 'EXPONENT':
|
1463 |
+
$this->current = &$this->components['publicExponent'];
|
1464 |
+
break;
|
1465 |
+
case 'P':
|
1466 |
+
$this->current = &$this->components['primes'][1];
|
1467 |
+
break;
|
1468 |
+
case 'Q':
|
1469 |
+
$this->current = &$this->components['primes'][2];
|
1470 |
+
break;
|
1471 |
+
case 'DP':
|
1472 |
+
$this->current = &$this->components['exponents'][1];
|
1473 |
+
break;
|
1474 |
+
case 'DQ':
|
1475 |
+
$this->current = &$this->components['exponents'][2];
|
1476 |
+
break;
|
1477 |
+
case 'INVERSEQ':
|
1478 |
+
$this->current = &$this->components['coefficients'][2];
|
1479 |
+
break;
|
1480 |
+
case 'D':
|
1481 |
+
$this->current = &$this->components['privateExponent'];
|
1482 |
+
}
|
1483 |
+
$this->current = '';
|
1484 |
+
}
|
1485 |
+
|
1486 |
+
/**
|
1487 |
+
* Stop Element Handler
|
1488 |
+
*
|
1489 |
+
* Called by xml_set_element_handler()
|
1490 |
+
*
|
1491 |
+
* @access private
|
1492 |
+
* @param Resource $parser
|
1493 |
+
* @param String $name
|
1494 |
+
*/
|
1495 |
+
function _stop_element_handler($parser, $name)
|
1496 |
+
{
|
1497 |
+
if (isset($this->current)) {
|
1498 |
+
$this->current = new Math_BigInteger(base64_decode($this->current), 256);
|
1499 |
+
unset($this->current);
|
1500 |
+
}
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
/**
|
1504 |
+
* Data Handler
|
1505 |
+
*
|
1506 |
+
* Called by xml_set_character_data_handler()
|
1507 |
+
*
|
1508 |
+
* @access private
|
1509 |
+
* @param Resource $parser
|
1510 |
+
* @param String $data
|
1511 |
+
*/
|
1512 |
+
function _data_handler($parser, $data)
|
1513 |
+
{
|
1514 |
+
if (!isset($this->current) || is_object($this->current)) {
|
1515 |
+
return;
|
1516 |
+
}
|
1517 |
+
$this->current.= trim($data);
|
1518 |
+
}
|
1519 |
+
|
1520 |
+
/**
|
1521 |
+
* Loads a public or private key
|
1522 |
+
*
|
1523 |
+
* Returns true on success and false on failure (ie. an incorrect password was provided or the key was malformed)
|
1524 |
+
*
|
1525 |
+
* @access public
|
1526 |
+
* @param String $key
|
1527 |
+
* @param Integer $type optional
|
1528 |
+
*/
|
1529 |
+
function loadKey($key, $type = false)
|
1530 |
+
{
|
1531 |
+
if (is_object($key) && strtolower(get_class($key)) == 'crypt_rsa') {
|
1532 |
+
$this->privateKeyFormat = $key->privateKeyFormat;
|
1533 |
+
$this->publicKeyFormat = $key->publicKeyFormat;
|
1534 |
+
$this->k = $key->k;
|
1535 |
+
$this->hLen = $key->hLen;
|
1536 |
+
$this->sLen = $key->sLen;
|
1537 |
+
$this->mgfHLen = $key->mgfHLen;
|
1538 |
+
$this->encryptionMode = $key->encryptionMode;
|
1539 |
+
$this->signatureMode = $key->signatureMode;
|
1540 |
+
$this->password = $key->password;
|
1541 |
+
$this->configFile = $key->configFile;
|
1542 |
+
$this->comment = $key->comment;
|
1543 |
+
|
1544 |
+
if (is_object($key->hash)) {
|
1545 |
+
$this->hash = new Crypt_Hash($key->hash->getHash());
|
1546 |
+
}
|
1547 |
+
if (is_object($key->mgfHash)) {
|
1548 |
+
$this->mgfHash = new Crypt_Hash($key->mgfHash->getHash());
|
1549 |
+
}
|
1550 |
+
|
1551 |
+
if (is_object($key->modulus)) {
|
1552 |
+
$this->modulus = $key->modulus->copy();
|
1553 |
+
}
|
1554 |
+
if (is_object($key->exponent)) {
|
1555 |
+
$this->exponent = $key->exponent->copy();
|
1556 |
+
}
|
1557 |
+
if (is_object($key->publicExponent)) {
|
1558 |
+
$this->publicExponent = $key->publicExponent->copy();
|
1559 |
+
}
|
1560 |
+
|
1561 |
+
$this->primes = array();
|
1562 |
+
$this->exponents = array();
|
1563 |
+
$this->coefficients = array();
|
1564 |
+
|
1565 |
+
foreach ($this->primes as $prime) {
|
1566 |
+
$this->primes[] = $prime->copy();
|
1567 |
+
}
|
1568 |
+
foreach ($this->exponents as $exponent) {
|
1569 |
+
$this->exponents[] = $exponent->copy();
|
1570 |
+
}
|
1571 |
+
foreach ($this->coefficients as $coefficient) {
|
1572 |
+
$this->coefficients[] = $coefficient->copy();
|
1573 |
+
}
|
1574 |
+
|
1575 |
+
return true;
|
1576 |
+
}
|
1577 |
+
|
1578 |
+
if ($type === false) {
|
1579 |
+
$types = array(
|
1580 |
+
CRYPT_RSA_PUBLIC_FORMAT_RAW,
|
1581 |
+
CRYPT_RSA_PRIVATE_FORMAT_PKCS1,
|
1582 |
+
CRYPT_RSA_PRIVATE_FORMAT_XML,
|
1583 |
+
CRYPT_RSA_PRIVATE_FORMAT_PUTTY,
|
1584 |
+
CRYPT_RSA_PUBLIC_FORMAT_OPENSSH
|
1585 |
+
);
|
1586 |
+
foreach ($types as $type) {
|
1587 |
+
$components = $this->_parseKey($key, $type);
|
1588 |
+
if ($components !== false) {
|
1589 |
+
break;
|
1590 |
+
}
|
1591 |
+
}
|
1592 |
+
|
1593 |
+
} else {
|
1594 |
+
$components = $this->_parseKey($key, $type);
|
1595 |
+
}
|
1596 |
+
|
1597 |
+
if ($components === false) {
|
1598 |
+
return false;
|
1599 |
+
}
|
1600 |
+
|
1601 |
+
if (isset($components['comment']) && $components['comment'] !== false) {
|
1602 |
+
$this->comment = $components['comment'];
|
1603 |
+
}
|
1604 |
+
$this->modulus = $components['modulus'];
|
1605 |
+
$this->k = strlen($this->modulus->toBytes());
|
1606 |
+
$this->exponent = isset($components['privateExponent']) ? $components['privateExponent'] : $components['publicExponent'];
|
1607 |
+
if (isset($components['primes'])) {
|
1608 |
+
$this->primes = $components['primes'];
|
1609 |
+
$this->exponents = $components['exponents'];
|
1610 |
+
$this->coefficients = $components['coefficients'];
|
1611 |
+
$this->publicExponent = $components['publicExponent'];
|
1612 |
+
} else {
|
1613 |
+
$this->primes = array();
|
1614 |
+
$this->exponents = array();
|
1615 |
+
$this->coefficients = array();
|
1616 |
+
$this->publicExponent = false;
|
1617 |
+
}
|
1618 |
+
|
1619 |
+
switch ($type) {
|
1620 |
+
case CRYPT_RSA_PUBLIC_FORMAT_OPENSSH:
|
1621 |
+
case CRYPT_RSA_PUBLIC_FORMAT_RAW:
|
1622 |
+
$this->setPublicKey();
|
1623 |
+
break;
|
1624 |
+
case CRYPT_RSA_PRIVATE_FORMAT_PKCS1:
|
1625 |
+
switch (true) {
|
1626 |
+
case strpos($key, '-BEGIN PUBLIC KEY-') !== false:
|
1627 |
+
case strpos($key, '-BEGIN RSA PUBLIC KEY-') !== false:
|
1628 |
+
$this->setPublicKey();
|
1629 |
+
}
|
1630 |
+
}
|
1631 |
+
|
1632 |
+
return true;
|
1633 |
+
}
|
1634 |
+
|
1635 |
+
/**
|
1636 |
+
* Sets the password
|
1637 |
+
*
|
1638 |
+
* Private keys can be encrypted with a password. To unset the password, pass in the empty string or false.
|
1639 |
+
* Or rather, pass in $password such that empty($password) && !is_string($password) is true.
|
1640 |
+
*
|
1641 |
+
* @see createKey()
|
1642 |
+
* @see loadKey()
|
1643 |
+
* @access public
|
1644 |
+
* @param String $password
|
1645 |
+
*/
|
1646 |
+
function setPassword($password = false)
|
1647 |
+
{
|
1648 |
+
$this->password = $password;
|
1649 |
+
}
|
1650 |
+
|
1651 |
+
/**
|
1652 |
+
* Defines the public key
|
1653 |
+
*
|
1654 |
+
* Some private key formats define the public exponent and some don't. Those that don't define it are problematic when
|
1655 |
+
* used in certain contexts. For example, in SSH-2, RSA authentication works by sending the public key along with a
|
1656 |
+
* message signed by the private key to the server. The SSH-2 server looks the public key up in an index of public keys
|
1657 |
+
* and if it's present then proceeds to verify the signature. Problem is, if your private key doesn't include the public
|
1658 |
+
* exponent this won't work unless you manually add the public exponent. phpseclib tries to guess if the key being used
|
1659 |
+
* is the public key but in the event that it guesses incorrectly you might still want to explicitly set the key as being
|
1660 |
+
* public.
|
1661 |
+
*
|
1662 |
+
* Do note that when a new key is loaded the index will be cleared.
|
1663 |
+
*
|
1664 |
+
* Returns true on success, false on failure
|
1665 |
+
*
|
1666 |
+
* @see getPublicKey()
|
1667 |
+
* @access public
|
1668 |
+
* @param String $key optional
|
1669 |
+
* @param Integer $type optional
|
1670 |
+
* @return Boolean
|
1671 |
+
*/
|
1672 |
+
function setPublicKey($key = false, $type = false)
|
1673 |
+
{
|
1674 |
+
// if a public key has already been loaded return false
|
1675 |
+
if (!empty($this->publicExponent)) {
|
1676 |
+
return false;
|
1677 |
+
}
|
1678 |
+
|
1679 |
+
if ($key === false && !empty($this->modulus)) {
|
1680 |
+
$this->publicExponent = $this->exponent;
|
1681 |
+
return true;
|
1682 |
+
}
|
1683 |
+
|
1684 |
+
if ($type === false) {
|
1685 |
+
$types = array(
|
1686 |
+
CRYPT_RSA_PUBLIC_FORMAT_RAW,
|
1687 |
+
CRYPT_RSA_PUBLIC_FORMAT_PKCS1,
|
1688 |
+
CRYPT_RSA_PUBLIC_FORMAT_XML,
|
1689 |
+
CRYPT_RSA_PUBLIC_FORMAT_OPENSSH
|
1690 |
+
);
|
1691 |
+
foreach ($types as $type) {
|
1692 |
+
$components = $this->_parseKey($key, $type);
|
1693 |
+
if ($components !== false) {
|
1694 |
+
break;
|
1695 |
+
}
|
1696 |
+
}
|
1697 |
+
} else {
|
1698 |
+
$components = $this->_parseKey($key, $type);
|
1699 |
+
}
|
1700 |
+
|
1701 |
+
if ($components === false) {
|
1702 |
+
return false;
|
1703 |
+
}
|
1704 |
+
|
1705 |
+
if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
|
1706 |
+
$this->modulus = $components['modulus'];
|
1707 |
+
$this->exponent = $this->publicExponent = $components['publicExponent'];
|
1708 |
+
return true;
|
1709 |
+
}
|
1710 |
+
|
1711 |
+
$this->publicExponent = $components['publicExponent'];
|
1712 |
+
|
1713 |
+
return true;
|
1714 |
+
}
|
1715 |
+
|
1716 |
+
/**
|
1717 |
+
* Defines the private key
|
1718 |
+
*
|
1719 |
+
* If phpseclib guessed a private key was a public key and loaded it as such it might be desirable to force
|
1720 |
+
* phpseclib to treat the key as a private key. This function will do that.
|
1721 |
+
*
|
1722 |
+
* Do note that when a new key is loaded the index will be cleared.
|
1723 |
+
*
|
1724 |
+
* Returns true on success, false on failure
|
1725 |
+
*
|
1726 |
+
* @see getPublicKey()
|
1727 |
+
* @access public
|
1728 |
+
* @param String $key optional
|
1729 |
+
* @param Integer $type optional
|
1730 |
+
* @return Boolean
|
1731 |
+
*/
|
1732 |
+
function setPrivateKey($key = false, $type = false)
|
1733 |
+
{
|
1734 |
+
if ($key === false && !empty($this->publicExponent)) {
|
1735 |
+
unset($this->publicExponent);
|
1736 |
+
return true;
|
1737 |
+
}
|
1738 |
+
|
1739 |
+
$rsa = new Crypt_RSA();
|
1740 |
+
if (!$rsa->loadKey($key, $type)) {
|
1741 |
+
return false;
|
1742 |
+
}
|
1743 |
+
unset($rsa->publicExponent);
|
1744 |
+
|
1745 |
+
// don't overwrite the old key if the new key is invalid
|
1746 |
+
$this->loadKey($rsa);
|
1747 |
+
return true;
|
1748 |
+
}
|
1749 |
+
|
1750 |
+
/**
|
1751 |
+
* Returns the public key
|
1752 |
+
*
|
1753 |
+
* The public key is only returned under two circumstances - if the private key had the public key embedded within it
|
1754 |
+
* or if the public key was set via setPublicKey(). If the currently loaded key is supposed to be the public key this
|
1755 |
+
* function won't return it since this library, for the most part, doesn't distinguish between public and private keys.
|
1756 |
+
*
|
1757 |
+
* @see getPublicKey()
|
1758 |
+
* @access public
|
1759 |
+
* @param String $key
|
1760 |
+
* @param Integer $type optional
|
1761 |
+
*/
|
1762 |
+
function getPublicKey($type = CRYPT_RSA_PUBLIC_FORMAT_PKCS8)
|
1763 |
+
{
|
1764 |
+
if (empty($this->modulus) || empty($this->publicExponent)) {
|
1765 |
+
return false;
|
1766 |
+
}
|
1767 |
+
|
1768 |
+
$oldFormat = $this->publicKeyFormat;
|
1769 |
+
$this->publicKeyFormat = $type;
|
1770 |
+
$temp = $this->_convertPublicKey($this->modulus, $this->publicExponent);
|
1771 |
+
$this->publicKeyFormat = $oldFormat;
|
1772 |
+
return $temp;
|
1773 |
+
}
|
1774 |
+
|
1775 |
+
/**
|
1776 |
+
* Returns the private key
|
1777 |
+
*
|
1778 |
+
* The private key is only returned if the currently loaded key contains the constituent prime numbers.
|
1779 |
+
*
|
1780 |
+
* @see getPublicKey()
|
1781 |
+
* @access public
|
1782 |
+
* @param String $key
|
1783 |
+
* @param Integer $type optional
|
1784 |
+
*/
|
1785 |
+
function getPrivateKey($type = CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
|
1786 |
+
{
|
1787 |
+
if (empty($this->primes)) {
|
1788 |
+
return false;
|
1789 |
+
}
|
1790 |
+
|
1791 |
+
$oldFormat = $this->privateKeyFormat;
|
1792 |
+
$this->privateKeyFormat = $type;
|
1793 |
+
$temp = $this->_convertPrivateKey($this->modulus, $this->publicExponent, $this->exponent, $this->primes, $this->exponents, $this->coefficients);
|
1794 |
+
$this->privateKeyFormat = $oldFormat;
|
1795 |
+
return $temp;
|
1796 |
+
}
|
1797 |
+
|
1798 |
+
/**
|
1799 |
+
* Returns a minimalistic private key
|
1800 |
+
*
|
1801 |
+
* Returns the private key without the prime number constituants. Structurally identical to a public key that
|
1802 |
+
* hasn't been set as the public key
|
1803 |
+
*
|
1804 |
+
* @see getPrivateKey()
|
1805 |
+
* @access private
|
1806 |
+
* @param String $key
|
1807 |
+
* @param Integer $type optional
|
1808 |
+
*/
|
1809 |
+
function _getPrivatePublicKey($mode = CRYPT_RSA_PUBLIC_FORMAT_PKCS8)
|
1810 |
+
{
|
1811 |
+
if (empty($this->modulus) || empty($this->exponent)) {
|
1812 |
+
return false;
|
1813 |
+
}
|
1814 |
+
|
1815 |
+
$oldFormat = $this->publicKeyFormat;
|
1816 |
+
$this->publicKeyFormat = $mode;
|
1817 |
+
$temp = $this->_convertPublicKey($this->modulus, $this->exponent);
|
1818 |
+
$this->publicKeyFormat = $oldFormat;
|
1819 |
+
return $temp;
|
1820 |
+
}
|
1821 |
+
|
1822 |
+
/**
|
1823 |
+
* __toString() magic method
|
1824 |
+
*
|
1825 |
+
* @access public
|
1826 |
+
*/
|
1827 |
+
function __toString()
|
1828 |
+
{
|
1829 |
+
$key = $this->getPrivateKey($this->privateKeyFormat);
|
1830 |
+
if ($key !== false) {
|
1831 |
+
return $key;
|
1832 |
+
}
|
1833 |
+
$key = $this->_getPrivatePublicKey($this->publicKeyFormat);
|
1834 |
+
return $key !== false ? $key : '';
|
1835 |
+
}
|
1836 |
+
|
1837 |
+
/**
|
1838 |
+
* __clone() magic method
|
1839 |
+
*
|
1840 |
+
* @access public
|
1841 |
+
*/
|
1842 |
+
function __clone()
|
1843 |
+
{
|
1844 |
+
$key = new Crypt_RSA();
|
1845 |
+
$key->loadKey($this);
|
1846 |
+
return $key;
|
1847 |
+
}
|
1848 |
+
|
1849 |
+
/**
|
1850 |
+
* Generates the smallest and largest numbers requiring $bits bits
|
1851 |
+
*
|
1852 |
+
* @access private
|
1853 |
+
* @param Integer $bits
|
1854 |
+
* @return Array
|
1855 |
+
*/
|
1856 |
+
function _generateMinMax($bits)
|
1857 |
+
{
|
1858 |
+
$bytes = $bits >> 3;
|
1859 |
+
$min = str_repeat(chr(0), $bytes);
|
1860 |
+
$max = str_repeat(chr(0xFF), $bytes);
|
1861 |
+
$msb = $bits & 7;
|
1862 |
+
if ($msb) {
|
1863 |
+
$min = chr(1 << ($msb - 1)) . $min;
|
1864 |
+
$max = chr((1 << $msb) - 1) . $max;
|
1865 |
+
} else {
|
1866 |
+
$min[0] = chr(0x80);
|
1867 |
+
}
|
1868 |
+
|
1869 |
+
return array(
|
1870 |
+
'min' => new Math_BigInteger($min, 256),
|
1871 |
+
'max' => new Math_BigInteger($max, 256)
|
1872 |
+
);
|
1873 |
+
}
|
1874 |
+
|
1875 |
+
/**
|
1876 |
+
* DER-decode the length
|
1877 |
+
*
|
1878 |
+
* DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
|
1879 |
+
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
|
1880 |
+
*
|
1881 |
+
* @access private
|
1882 |
+
* @param String $string
|
1883 |
+
* @return Integer
|
1884 |
+
*/
|
1885 |
+
function _decodeLength(&$string)
|
1886 |
+
{
|
1887 |
+
$length = ord($this->_string_shift($string));
|
1888 |
+
if ( $length & 0x80 ) { // definite length, long form
|
1889 |
+
$length&= 0x7F;
|
1890 |
+
$temp = $this->_string_shift($string, $length);
|
1891 |
+
list(, $length) = unpack('N', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4));
|
1892 |
+
}
|
1893 |
+
return $length;
|
1894 |
+
}
|
1895 |
+
|
1896 |
+
/**
|
1897 |
+
* DER-encode the length
|
1898 |
+
*
|
1899 |
+
* DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
|
1900 |
+
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
|
1901 |
+
*
|
1902 |
+
* @access private
|
1903 |
+
* @param Integer $length
|
1904 |
+
* @return String
|
1905 |
+
*/
|
1906 |
+
function _encodeLength($length)
|
1907 |
+
{
|
1908 |
+
if ($length <= 0x7F) {
|
1909 |
+
return chr($length);
|
1910 |
+
}
|
1911 |
+
|
1912 |
+
$temp = ltrim(pack('N', $length), chr(0));
|
1913 |
+
return pack('Ca*', 0x80 | strlen($temp), $temp);
|
1914 |
+
}
|
1915 |
+
|
1916 |
+
/**
|
1917 |
+
* String Shift
|
1918 |
+
*
|
1919 |
+
* Inspired by array_shift
|
1920 |
+
*
|
1921 |
+
* @param String $string
|
1922 |
+
* @param optional Integer $index
|
1923 |
+
* @return String
|
1924 |
+
* @access private
|
1925 |
+
*/
|
1926 |
+
function _string_shift(&$string, $index = 1)
|
1927 |
+
{
|
1928 |
+
$substr = substr($string, 0, $index);
|
1929 |
+
$string = substr($string, $index);
|
1930 |
+
return $substr;
|
1931 |
+
}
|
1932 |
+
|
1933 |
+
/**
|
1934 |
+
* Determines the private key format
|
1935 |
+
*
|
1936 |
+
* @see createKey()
|
1937 |
+
* @access public
|
1938 |
+
* @param Integer $format
|
1939 |
+
*/
|
1940 |
+
function setPrivateKeyFormat($format)
|
1941 |
+
{
|
1942 |
+
$this->privateKeyFormat = $format;
|
1943 |
+
}
|
1944 |
+
|
1945 |
+
/**
|
1946 |
+
* Determines the public key format
|
1947 |
+
*
|
1948 |
+
* @see createKey()
|
1949 |
+
* @access public
|
1950 |
+
* @param Integer $format
|
1951 |
+
*/
|
1952 |
+
function setPublicKeyFormat($format)
|
1953 |
+
{
|
1954 |
+
$this->publicKeyFormat = $format;
|
1955 |
+
}
|
1956 |
+
|
1957 |
+
/**
|
1958 |
+
* Determines which hashing function should be used
|
1959 |
+
*
|
1960 |
+
* Used with signature production / verification and (if the encryption mode is CRYPT_RSA_ENCRYPTION_OAEP) encryption and
|
1961 |
+
* decryption. If $hash isn't supported, sha1 is used.
|
1962 |
+
*
|
1963 |
+
* @access public
|
1964 |
+
* @param String $hash
|
1965 |
+
*/
|
1966 |
+
function setHash($hash)
|
1967 |
+
{
|
1968 |
+
// Crypt_Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
|
1969 |
+
switch ($hash) {
|
1970 |
+
case 'md2':
|
1971 |
+
case 'md5':
|
1972 |
+
case 'sha1':
|
1973 |
+
case 'sha256':
|
1974 |
+
case 'sha384':
|
1975 |
+
case 'sha512':
|
1976 |
+
$this->hash = new Crypt_Hash($hash);
|
1977 |
+
$this->hashName = $hash;
|
1978 |
+
break;
|
1979 |
+
default:
|
1980 |
+
$this->hash = new Crypt_Hash('sha1');
|
1981 |
+
$this->hashName = 'sha1';
|
1982 |
+
}
|
1983 |
+
$this->hLen = $this->hash->getLength();
|
1984 |
+
}
|
1985 |
+
|
1986 |
+
/**
|
1987 |
+
* Determines which hashing function should be used for the mask generation function
|
1988 |
+
*
|
1989 |
+
* The mask generation function is used by CRYPT_RSA_ENCRYPTION_OAEP and CRYPT_RSA_SIGNATURE_PSS and although it's
|
1990 |
+
* best if Hash and MGFHash are set to the same thing this is not a requirement.
|
1991 |
+
*
|
1992 |
+
* @access public
|
1993 |
+
* @param String $hash
|
1994 |
+
*/
|
1995 |
+
function setMGFHash($hash)
|
1996 |
+
{
|
1997 |
+
// Crypt_Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
|
1998 |
+
switch ($hash) {
|
1999 |
+
case 'md2':
|
2000 |
+
case 'md5':
|
2001 |
+
case 'sha1':
|
2002 |
+
case 'sha256':
|
2003 |
+
case 'sha384':
|
2004 |
+
case 'sha512':
|
2005 |
+
$this->mgfHash = new Crypt_Hash($hash);
|
2006 |
+
break;
|
2007 |
+
default:
|
2008 |
+
$this->mgfHash = new Crypt_Hash('sha1');
|
2009 |
+
}
|
2010 |
+
$this->mgfHLen = $this->mgfHash->getLength();
|
2011 |
+
}
|
2012 |
+
|
2013 |
+
/**
|
2014 |
+
* Determines the salt length
|
2015 |
+
*
|
2016 |
+
* To quote from {@link http://tools.ietf.org/html/rfc3447#page-38 RFC3447#page-38}:
|
2017 |
+
*
|
2018 |
+
* Typical salt lengths in octets are hLen (the length of the output
|
2019 |
+
* of the hash function Hash) and 0.
|
2020 |
+
*
|
2021 |
+
* @access public
|
2022 |
+
* @param Integer $format
|
2023 |
+
*/
|
2024 |
+
function setSaltLength($sLen)
|
2025 |
+
{
|
2026 |
+
$this->sLen = $sLen;
|
2027 |
+
}
|
2028 |
+
|
2029 |
+
/**
|
2030 |
+
* Integer-to-Octet-String primitive
|
2031 |
+
*
|
2032 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-4.1 RFC3447#section-4.1}.
|
2033 |
+
*
|
2034 |
+
* @access private
|
2035 |
+
* @param Math_BigInteger $x
|
2036 |
+
* @param Integer $xLen
|
2037 |
+
* @return String
|
2038 |
+
*/
|
2039 |
+
function _i2osp($x, $xLen)
|
2040 |
+
{
|
2041 |
+
$x = $x->toBytes();
|
2042 |
+
if (strlen($x) > $xLen) {
|
2043 |
+
user_error('Integer too large');
|
2044 |
+
return false;
|
2045 |
+
}
|
2046 |
+
return str_pad($x, $xLen, chr(0), STR_PAD_LEFT);
|
2047 |
+
}
|
2048 |
+
|
2049 |
+
/**
|
2050 |
+
* Octet-String-to-Integer primitive
|
2051 |
+
*
|
2052 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-4.2 RFC3447#section-4.2}.
|
2053 |
+
*
|
2054 |
+
* @access private
|
2055 |
+
* @param String $x
|
2056 |
+
* @return Math_BigInteger
|
2057 |
+
*/
|
2058 |
+
function _os2ip($x)
|
2059 |
+
{
|
2060 |
+
return new Math_BigInteger($x, 256);
|
2061 |
+
}
|
2062 |
+
|
2063 |
+
/**
|
2064 |
+
* Exponentiate with or without Chinese Remainder Theorem
|
2065 |
+
*
|
2066 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.2}.
|
2067 |
+
*
|
2068 |
+
* @access private
|
2069 |
+
* @param Math_BigInteger $x
|
2070 |
+
* @return Math_BigInteger
|
2071 |
+
*/
|
2072 |
+
function _exponentiate($x)
|
2073 |
+
{
|
2074 |
+
if (empty($this->primes) || empty($this->coefficients) || empty($this->exponents)) {
|
2075 |
+
return $x->modPow($this->exponent, $this->modulus);
|
2076 |
+
}
|
2077 |
+
|
2078 |
+
$num_primes = count($this->primes);
|
2079 |
+
|
2080 |
+
if (defined('CRYPT_RSA_DISABLE_BLINDING')) {
|
2081 |
+
$m_i = array(
|
2082 |
+
1 => $x->modPow($this->exponents[1], $this->primes[1]),
|
2083 |
+
2 => $x->modPow($this->exponents[2], $this->primes[2])
|
2084 |
+
);
|
2085 |
+
$h = $m_i[1]->subtract($m_i[2]);
|
2086 |
+
$h = $h->multiply($this->coefficients[2]);
|
2087 |
+
list(, $h) = $h->divide($this->primes[1]);
|
2088 |
+
$m = $m_i[2]->add($h->multiply($this->primes[2]));
|
2089 |
+
|
2090 |
+
$r = $this->primes[1];
|
2091 |
+
for ($i = 3; $i <= $num_primes; $i++) {
|
2092 |
+
$m_i = $x->modPow($this->exponents[$i], $this->primes[$i]);
|
2093 |
+
|
2094 |
+
$r = $r->multiply($this->primes[$i - 1]);
|
2095 |
+
|
2096 |
+
$h = $m_i->subtract($m);
|
2097 |
+
$h = $h->multiply($this->coefficients[$i]);
|
2098 |
+
list(, $h) = $h->divide($this->primes[$i]);
|
2099 |
+
|
2100 |
+
$m = $m->add($r->multiply($h));
|
2101 |
+
}
|
2102 |
+
} else {
|
2103 |
+
$smallest = $this->primes[1];
|
2104 |
+
for ($i = 2; $i <= $num_primes; $i++) {
|
2105 |
+
if ($smallest->compare($this->primes[$i]) > 0) {
|
2106 |
+
$smallest = $this->primes[$i];
|
2107 |
+
}
|
2108 |
+
}
|
2109 |
+
|
2110 |
+
$one = new Math_BigInteger(1);
|
2111 |
+
|
2112 |
+
$r = $one->random($one, $smallest->subtract($one));
|
2113 |
+
|
2114 |
+
$m_i = array(
|
2115 |
+
1 => $this->_blind($x, $r, 1),
|
2116 |
+
2 => $this->_blind($x, $r, 2)
|
2117 |
+
);
|
2118 |
+
$h = $m_i[1]->subtract($m_i[2]);
|
2119 |
+
$h = $h->multiply($this->coefficients[2]);
|
2120 |
+
list(, $h) = $h->divide($this->primes[1]);
|
2121 |
+
$m = $m_i[2]->add($h->multiply($this->primes[2]));
|
2122 |
+
|
2123 |
+
$r = $this->primes[1];
|
2124 |
+
for ($i = 3; $i <= $num_primes; $i++) {
|
2125 |
+
$m_i = $this->_blind($x, $r, $i);
|
2126 |
+
|
2127 |
+
$r = $r->multiply($this->primes[$i - 1]);
|
2128 |
+
|
2129 |
+
$h = $m_i->subtract($m);
|
2130 |
+
$h = $h->multiply($this->coefficients[$i]);
|
2131 |
+
list(, $h) = $h->divide($this->primes[$i]);
|
2132 |
+
|
2133 |
+
$m = $m->add($r->multiply($h));
|
2134 |
+
}
|
2135 |
+
}
|
2136 |
+
|
2137 |
+
return $m;
|
2138 |
+
}
|
2139 |
+
|
2140 |
+
/**
|
2141 |
+
* Performs RSA Blinding
|
2142 |
+
*
|
2143 |
+
* Protects against timing attacks by employing RSA Blinding.
|
2144 |
+
* Returns $x->modPow($this->exponents[$i], $this->primes[$i])
|
2145 |
+
*
|
2146 |
+
* @access private
|
2147 |
+
* @param Math_BigInteger $x
|
2148 |
+
* @param Math_BigInteger $r
|
2149 |
+
* @param Integer $i
|
2150 |
+
* @return Math_BigInteger
|
2151 |
+
*/
|
2152 |
+
function _blind($x, $r, $i)
|
2153 |
+
{
|
2154 |
+
$x = $x->multiply($r->modPow($this->publicExponent, $this->primes[$i]));
|
2155 |
+
$x = $x->modPow($this->exponents[$i], $this->primes[$i]);
|
2156 |
+
|
2157 |
+
$r = $r->modInverse($this->primes[$i]);
|
2158 |
+
$x = $x->multiply($r);
|
2159 |
+
list(, $x) = $x->divide($this->primes[$i]);
|
2160 |
+
|
2161 |
+
return $x;
|
2162 |
+
}
|
2163 |
+
|
2164 |
+
/**
|
2165 |
+
* Performs blinded RSA equality testing
|
2166 |
+
*
|
2167 |
+
* Protects against a particular type of timing attack described.
|
2168 |
+
*
|
2169 |
+
* See {@link http://codahale.com/a-lesson-in-timing-attacks/ A Lesson In Timing Attacks (or, Don't use MessageDigest.isEquals)}
|
2170 |
+
*
|
2171 |
+
* Thanks for the heads up singpolyma!
|
2172 |
+
*
|
2173 |
+
* @access private
|
2174 |
+
* @param String $x
|
2175 |
+
* @param String $y
|
2176 |
+
* @return Boolean
|
2177 |
+
*/
|
2178 |
+
function _equals($x, $y)
|
2179 |
+
{
|
2180 |
+
if (strlen($x) != strlen($y)) {
|
2181 |
+
return false;
|
2182 |
+
}
|
2183 |
+
|
2184 |
+
$result = 0;
|
2185 |
+
for ($i = 0; $i < strlen($x); $i++) {
|
2186 |
+
$result |= ord($x[$i]) ^ ord($y[$i]);
|
2187 |
+
}
|
2188 |
+
|
2189 |
+
return $result == 0;
|
2190 |
+
}
|
2191 |
+
|
2192 |
+
/**
|
2193 |
+
* RSAEP
|
2194 |
+
*
|
2195 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.1}.
|
2196 |
+
*
|
2197 |
+
* @access private
|
2198 |
+
* @param Math_BigInteger $m
|
2199 |
+
* @return Math_BigInteger
|
2200 |
+
*/
|
2201 |
+
function _rsaep($m)
|
2202 |
+
{
|
2203 |
+
if ($m->compare($this->zero) < 0 || $m->compare($this->modulus) > 0) {
|
2204 |
+
user_error('Message representative out of range');
|
2205 |
+
return false;
|
2206 |
+
}
|
2207 |
+
return $this->_exponentiate($m);
|
2208 |
+
}
|
2209 |
+
|
2210 |
+
/**
|
2211 |
+
* RSADP
|
2212 |
+
*
|
2213 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-5.1.2 RFC3447#section-5.1.2}.
|
2214 |
+
*
|
2215 |
+
* @access private
|
2216 |
+
* @param Math_BigInteger $c
|
2217 |
+
* @return Math_BigInteger
|
2218 |
+
*/
|
2219 |
+
function _rsadp($c)
|
2220 |
+
{
|
2221 |
+
if ($c->compare($this->zero) < 0 || $c->compare($this->modulus) > 0) {
|
2222 |
+
user_error('Ciphertext representative out of range');
|
2223 |
+
return false;
|
2224 |
+
}
|
2225 |
+
return $this->_exponentiate($c);
|
2226 |
+
}
|
2227 |
+
|
2228 |
+
/**
|
2229 |
+
* RSASP1
|
2230 |
+
*
|
2231 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-5.2.1 RFC3447#section-5.2.1}.
|
2232 |
+
*
|
2233 |
+
* @access private
|
2234 |
+
* @param Math_BigInteger $m
|
2235 |
+
* @return Math_BigInteger
|
2236 |
+
*/
|
2237 |
+
function _rsasp1($m)
|
2238 |
+
{
|
2239 |
+
if ($m->compare($this->zero) < 0 || $m->compare($this->modulus) > 0) {
|
2240 |
+
user_error('Message representative out of range');
|
2241 |
+
return false;
|
2242 |
+
}
|
2243 |
+
return $this->_exponentiate($m);
|
2244 |
+
}
|
2245 |
+
|
2246 |
+
/**
|
2247 |
+
* RSAVP1
|
2248 |
+
*
|
2249 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-5.2.2 RFC3447#section-5.2.2}.
|
2250 |
+
*
|
2251 |
+
* @access private
|
2252 |
+
* @param Math_BigInteger $s
|
2253 |
+
* @return Math_BigInteger
|
2254 |
+
*/
|
2255 |
+
function _rsavp1($s)
|
2256 |
+
{
|
2257 |
+
if ($s->compare($this->zero) < 0 || $s->compare($this->modulus) > 0) {
|
2258 |
+
user_error('Signature representative out of range');
|
2259 |
+
return false;
|
2260 |
+
}
|
2261 |
+
return $this->_exponentiate($s);
|
2262 |
+
}
|
2263 |
+
|
2264 |
+
/**
|
2265 |
+
* MGF1
|
2266 |
+
*
|
2267 |
+
* See {@link http://tools.ietf.org/html/rfc3447#appendix-B.2.1 RFC3447#appendix-B.2.1}.
|
2268 |
+
*
|
2269 |
+
* @access private
|
2270 |
+
* @param String $mgfSeed
|
2271 |
+
* @param Integer $mgfLen
|
2272 |
+
* @return String
|
2273 |
+
*/
|
2274 |
+
function _mgf1($mgfSeed, $maskLen)
|
2275 |
+
{
|
2276 |
+
// if $maskLen would yield strings larger than 4GB, PKCS#1 suggests a "Mask too long" error be output.
|
2277 |
+
|
2278 |
+
$t = '';
|
2279 |
+
$count = ceil($maskLen / $this->mgfHLen);
|
2280 |
+
for ($i = 0; $i < $count; $i++) {
|
2281 |
+
$c = pack('N', $i);
|
2282 |
+
$t.= $this->mgfHash->hash($mgfSeed . $c);
|
2283 |
+
}
|
2284 |
+
|
2285 |
+
return substr($t, 0, $maskLen);
|
2286 |
+
}
|
2287 |
+
|
2288 |
+
/**
|
2289 |
+
* RSAES-OAEP-ENCRYPT
|
2290 |
+
*
|
2291 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-7.1.1 RFC3447#section-7.1.1} and
|
2292 |
+
* {http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding OAES}.
|
2293 |
+
*
|
2294 |
+
* @access private
|
2295 |
+
* @param String $m
|
2296 |
+
* @param String $l
|
2297 |
+
* @return String
|
2298 |
+
*/
|
2299 |
+
function _rsaes_oaep_encrypt($m, $l = '')
|
2300 |
+
{
|
2301 |
+
$mLen = strlen($m);
|
2302 |
+
|
2303 |
+
// Length checking
|
2304 |
+
|
2305 |
+
// if $l is larger than two million terrabytes and you're using sha1, PKCS#1 suggests a "Label too long" error
|
2306 |
+
// be output.
|
2307 |
+
|
2308 |
+
if ($mLen > $this->k - 2 * $this->hLen - 2) {
|
2309 |
+
user_error('Message too long');
|
2310 |
+
return false;
|
2311 |
+
}
|
2312 |
+
|
2313 |
+
// EME-OAEP encoding
|
2314 |
+
|
2315 |
+
$lHash = $this->hash->hash($l);
|
2316 |
+
$ps = str_repeat(chr(0), $this->k - $mLen - 2 * $this->hLen - 2);
|
2317 |
+
$db = $lHash . $ps . chr(1) . $m;
|
2318 |
+
$seed = crypt_random_string($this->hLen);
|
2319 |
+
$dbMask = $this->_mgf1($seed, $this->k - $this->hLen - 1);
|
2320 |
+
$maskedDB = $db ^ $dbMask;
|
2321 |
+
$seedMask = $this->_mgf1($maskedDB, $this->hLen);
|
2322 |
+
$maskedSeed = $seed ^ $seedMask;
|
2323 |
+
$em = chr(0) . $maskedSeed . $maskedDB;
|
2324 |
+
|
2325 |
+
// RSA encryption
|
2326 |
+
|
2327 |
+
$m = $this->_os2ip($em);
|
2328 |
+
$c = $this->_rsaep($m);
|
2329 |
+
$c = $this->_i2osp($c, $this->k);
|
2330 |
+
|
2331 |
+
// Output the ciphertext C
|
2332 |
+
|
2333 |
+
return $c;
|
2334 |
+
}
|
2335 |
+
|
2336 |
+
/**
|
2337 |
+
* RSAES-OAEP-DECRYPT
|
2338 |
+
*
|
2339 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-7.1.2 RFC3447#section-7.1.2}. The fact that the error
|
2340 |
+
* messages aren't distinguishable from one another hinders debugging, but, to quote from RFC3447#section-7.1.2:
|
2341 |
+
*
|
2342 |
+
* Note. Care must be taken to ensure that an opponent cannot
|
2343 |
+
* distinguish the different error conditions in Step 3.g, whether by
|
2344 |
+
* error message or timing, or, more generally, learn partial
|
2345 |
+
* information about the encoded message EM. Otherwise an opponent may
|
2346 |
+
* be able to obtain useful information about the decryption of the
|
2347 |
+
* ciphertext C, leading to a chosen-ciphertext attack such as the one
|
2348 |
+
* observed by Manger [36].
|
2349 |
+
*
|
2350 |
+
* As for $l... to quote from {@link http://tools.ietf.org/html/rfc3447#page-17 RFC3447#page-17}:
|
2351 |
+
*
|
2352 |
+
* Both the encryption and the decryption operations of RSAES-OAEP take
|
2353 |
+
* the value of a label L as input. In this version of PKCS #1, L is
|
2354 |
+
* the empty string; other uses of the label are outside the scope of
|
2355 |
+
* this document.
|
2356 |
+
*
|
2357 |
+
* @access private
|
2358 |
+
* @param String $c
|
2359 |
+
* @param String $l
|
2360 |
+
* @return String
|
2361 |
+
*/
|
2362 |
+
function _rsaes_oaep_decrypt($c, $l = '')
|
2363 |
+
{
|
2364 |
+
// Length checking
|
2365 |
+
|
2366 |
+
// if $l is larger than two million terrabytes and you're using sha1, PKCS#1 suggests a "Label too long" error
|
2367 |
+
// be output.
|
2368 |
+
|
2369 |
+
if (strlen($c) != $this->k || $this->k < 2 * $this->hLen + 2) {
|
2370 |
+
user_error('Decryption error');
|
2371 |
+
return false;
|
2372 |
+
}
|
2373 |
+
|
2374 |
+
// RSA decryption
|
2375 |
+
|
2376 |
+
$c = $this->_os2ip($c);
|
2377 |
+
$m = $this->_rsadp($c);
|
2378 |
+
if ($m === false) {
|
2379 |
+
user_error('Decryption error');
|
2380 |
+
return false;
|
2381 |
+
}
|
2382 |
+
$em = $this->_i2osp($m, $this->k);
|
2383 |
+
|
2384 |
+
// EME-OAEP decoding
|
2385 |
+
|
2386 |
+
$lHash = $this->hash->hash($l);
|
2387 |
+
$y = ord($em[0]);
|
2388 |
+
$maskedSeed = substr($em, 1, $this->hLen);
|
2389 |
+
$maskedDB = substr($em, $this->hLen + 1);
|
2390 |
+
$seedMask = $this->_mgf1($maskedDB, $this->hLen);
|
2391 |
+
$seed = $maskedSeed ^ $seedMask;
|
2392 |
+
$dbMask = $this->_mgf1($seed, $this->k - $this->hLen - 1);
|
2393 |
+
$db = $maskedDB ^ $dbMask;
|
2394 |
+
$lHash2 = substr($db, 0, $this->hLen);
|
2395 |
+
$m = substr($db, $this->hLen);
|
2396 |
+
if ($lHash != $lHash2) {
|
2397 |
+
user_error('Decryption error');
|
2398 |
+
return false;
|
2399 |
+
}
|
2400 |
+
$m = ltrim($m, chr(0));
|
2401 |
+
if (ord($m[0]) != 1) {
|
2402 |
+
user_error('Decryption error');
|
2403 |
+
return false;
|
2404 |
+
}
|
2405 |
+
|
2406 |
+
// Output the message M
|
2407 |
+
|
2408 |
+
return substr($m, 1);
|
2409 |
+
}
|
2410 |
+
|
2411 |
+
/**
|
2412 |
+
* RSAES-PKCS1-V1_5-ENCRYPT
|
2413 |
+
*
|
2414 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-7.2.1 RFC3447#section-7.2.1}.
|
2415 |
+
*
|
2416 |
+
* @access private
|
2417 |
+
* @param String $m
|
2418 |
+
* @return String
|
2419 |
+
*/
|
2420 |
+
function _rsaes_pkcs1_v1_5_encrypt($m)
|
2421 |
+
{
|
2422 |
+
$mLen = strlen($m);
|
2423 |
+
|
2424 |
+
// Length checking
|
2425 |
+
|
2426 |
+
if ($mLen > $this->k - 11) {
|
2427 |
+
user_error('Message too long');
|
2428 |
+
return false;
|
2429 |
+
}
|
2430 |
+
|
2431 |
+
// EME-PKCS1-v1_5 encoding
|
2432 |
+
|
2433 |
+
$psLen = $this->k - $mLen - 3;
|
2434 |
+
$ps = '';
|
2435 |
+
while (strlen($ps) != $psLen) {
|
2436 |
+
$temp = crypt_random_string($psLen - strlen($ps));
|
2437 |
+
$temp = str_replace("\x00", '', $temp);
|
2438 |
+
$ps.= $temp;
|
2439 |
+
}
|
2440 |
+
$type = 2;
|
2441 |
+
// see the comments of _rsaes_pkcs1_v1_5_decrypt() to understand why this is being done
|
2442 |
+
if (defined('CRYPT_RSA_PKCS15_COMPAT') && (!isset($this->publicExponent) || $this->exponent !== $this->publicExponent)) {
|
2443 |
+
$type = 1;
|
2444 |
+
// "The padding string PS shall consist of k-3-||D|| octets. ... for block type 01, they shall have value FF"
|
2445 |
+
$ps = str_repeat("\xFF", $psLen);
|
2446 |
+
}
|
2447 |
+
$em = chr(0) . chr($type) . $ps . chr(0) . $m;
|
2448 |
+
|
2449 |
+
// RSA encryption
|
2450 |
+
$m = $this->_os2ip($em);
|
2451 |
+
$c = $this->_rsaep($m);
|
2452 |
+
$c = $this->_i2osp($c, $this->k);
|
2453 |
+
|
2454 |
+
// Output the ciphertext C
|
2455 |
+
|
2456 |
+
return $c;
|
2457 |
+
}
|
2458 |
+
|
2459 |
+
/**
|
2460 |
+
* RSAES-PKCS1-V1_5-DECRYPT
|
2461 |
+
*
|
2462 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-7.2.2 RFC3447#section-7.2.2}.
|
2463 |
+
*
|
2464 |
+
* For compatibility purposes, this function departs slightly from the description given in RFC3447.
|
2465 |
+
* The reason being that RFC2313#section-8.1 (PKCS#1 v1.5) states that ciphertext's encrypted by the
|
2466 |
+
* private key should have the second byte set to either 0 or 1 and that ciphertext's encrypted by the
|
2467 |
+
* public key should have the second byte set to 2. In RFC3447 (PKCS#1 v2.1), the second byte is supposed
|
2468 |
+
* to be 2 regardless of which key is used. For compatibility purposes, we'll just check to make sure the
|
2469 |
+
* second byte is 2 or less. If it is, we'll accept the decrypted string as valid.
|
2470 |
+
*
|
2471 |
+
* As a consequence of this, a private key encrypted ciphertext produced with Crypt_RSA may not decrypt
|
2472 |
+
* with a strictly PKCS#1 v1.5 compliant RSA implementation. Public key encrypted ciphertext's should but
|
2473 |
+
* not private key encrypted ciphertext's.
|
2474 |
+
*
|
2475 |
+
* @access private
|
2476 |
+
* @param String $c
|
2477 |
+
* @return String
|
2478 |
+
*/
|
2479 |
+
function _rsaes_pkcs1_v1_5_decrypt($c)
|
2480 |
+
{
|
2481 |
+
// Length checking
|
2482 |
+
|
2483 |
+
if (strlen($c) != $this->k) { // or if k < 11
|
2484 |
+
user_error('Decryption error');
|
2485 |
+
return false;
|
2486 |
+
}
|
2487 |
+
|
2488 |
+
// RSA decryption
|
2489 |
+
|
2490 |
+
$c = $this->_os2ip($c);
|
2491 |
+
$m = $this->_rsadp($c);
|
2492 |
+
|
2493 |
+
if ($m === false) {
|
2494 |
+
user_error('Decryption error');
|
2495 |
+
return false;
|
2496 |
+
}
|
2497 |
+
$em = $this->_i2osp($m, $this->k);
|
2498 |
+
|
2499 |
+
// EME-PKCS1-v1_5 decoding
|
2500 |
+
|
2501 |
+
if (ord($em[0]) != 0 || ord($em[1]) > 2) {
|
2502 |
+
user_error('Decryption error');
|
2503 |
+
return false;
|
2504 |
+
}
|
2505 |
+
|
2506 |
+
$ps = substr($em, 2, strpos($em, chr(0), 2) - 2);
|
2507 |
+
$m = substr($em, strlen($ps) + 3);
|
2508 |
+
|
2509 |
+
if (strlen($ps) < 8) {
|
2510 |
+
user_error('Decryption error');
|
2511 |
+
return false;
|
2512 |
+
}
|
2513 |
+
|
2514 |
+
// Output M
|
2515 |
+
|
2516 |
+
return $m;
|
2517 |
+
}
|
2518 |
+
|
2519 |
+
/**
|
2520 |
+
* EMSA-PSS-ENCODE
|
2521 |
+
*
|
2522 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-9.1.1 RFC3447#section-9.1.1}.
|
2523 |
+
*
|
2524 |
+
* @access private
|
2525 |
+
* @param String $m
|
2526 |
+
* @param Integer $emBits
|
2527 |
+
*/
|
2528 |
+
function _emsa_pss_encode($m, $emBits)
|
2529 |
+
{
|
2530 |
+
// if $m is larger than two million terrabytes and you're using sha1, PKCS#1 suggests a "Label too long" error
|
2531 |
+
// be output.
|
2532 |
+
|
2533 |
+
$emLen = ($emBits + 1) >> 3; // ie. ceil($emBits / 8)
|
2534 |
+
$sLen = $this->sLen == false ? $this->hLen : $this->sLen;
|
2535 |
+
|
2536 |
+
$mHash = $this->hash->hash($m);
|
2537 |
+
if ($emLen < $this->hLen + $sLen + 2) {
|
2538 |
+
user_error('Encoding error');
|
2539 |
+
return false;
|
2540 |
+
}
|
2541 |
+
|
2542 |
+
$salt = crypt_random_string($sLen);
|
2543 |
+
$m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt;
|
2544 |
+
$h = $this->hash->hash($m2);
|
2545 |
+
$ps = str_repeat(chr(0), $emLen - $sLen - $this->hLen - 2);
|
2546 |
+
$db = $ps . chr(1) . $salt;
|
2547 |
+
$dbMask = $this->_mgf1($h, $emLen - $this->hLen - 1);
|
2548 |
+
$maskedDB = $db ^ $dbMask;
|
2549 |
+
$maskedDB[0] = ~chr(0xFF << ($emBits & 7)) & $maskedDB[0];
|
2550 |
+
$em = $maskedDB . $h . chr(0xBC);
|
2551 |
+
|
2552 |
+
return $em;
|
2553 |
+
}
|
2554 |
+
|
2555 |
+
/**
|
2556 |
+
* EMSA-PSS-VERIFY
|
2557 |
+
*
|
2558 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-9.1.2 RFC3447#section-9.1.2}.
|
2559 |
+
*
|
2560 |
+
* @access private
|
2561 |
+
* @param String $m
|
2562 |
+
* @param String $em
|
2563 |
+
* @param Integer $emBits
|
2564 |
+
* @return String
|
2565 |
+
*/
|
2566 |
+
function _emsa_pss_verify($m, $em, $emBits)
|
2567 |
+
{
|
2568 |
+
// if $m is larger than two million terrabytes and you're using sha1, PKCS#1 suggests a "Label too long" error
|
2569 |
+
// be output.
|
2570 |
+
|
2571 |
+
$emLen = ($emBits + 1) >> 3; // ie. ceil($emBits / 8);
|
2572 |
+
$sLen = $this->sLen == false ? $this->hLen : $this->sLen;
|
2573 |
+
|
2574 |
+
$mHash = $this->hash->hash($m);
|
2575 |
+
if ($emLen < $this->hLen + $sLen + 2) {
|
2576 |
+
return false;
|
2577 |
+
}
|
2578 |
+
|
2579 |
+
if ($em[strlen($em) - 1] != chr(0xBC)) {
|
2580 |
+
return false;
|
2581 |
+
}
|
2582 |
+
|
2583 |
+
$maskedDB = substr($em, 0, -$this->hLen - 1);
|
2584 |
+
$h = substr($em, -$this->hLen - 1, $this->hLen);
|
2585 |
+
$temp = chr(0xFF << ($emBits & 7));
|
2586 |
+
if ((~$maskedDB[0] & $temp) != $temp) {
|
2587 |
+
return false;
|
2588 |
+
}
|
2589 |
+
$dbMask = $this->_mgf1($h, $emLen - $this->hLen - 1);
|
2590 |
+
$db = $maskedDB ^ $dbMask;
|
2591 |
+
$db[0] = ~chr(0xFF << ($emBits & 7)) & $db[0];
|
2592 |
+
$temp = $emLen - $this->hLen - $sLen - 2;
|
2593 |
+
if (substr($db, 0, $temp) != str_repeat(chr(0), $temp) || ord($db[$temp]) != 1) {
|
2594 |
+
return false;
|
2595 |
+
}
|
2596 |
+
$salt = substr($db, $temp + 1); // should be $sLen long
|
2597 |
+
$m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt;
|
2598 |
+
$h2 = $this->hash->hash($m2);
|
2599 |
+
return $this->_equals($h, $h2);
|
2600 |
+
}
|
2601 |
+
|
2602 |
+
/**
|
2603 |
+
* RSASSA-PSS-SIGN
|
2604 |
+
*
|
2605 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-8.1.1 RFC3447#section-8.1.1}.
|
2606 |
+
*
|
2607 |
+
* @access private
|
2608 |
+
* @param String $m
|
2609 |
+
* @return String
|
2610 |
+
*/
|
2611 |
+
function _rsassa_pss_sign($m)
|
2612 |
+
{
|
2613 |
+
// EMSA-PSS encoding
|
2614 |
+
|
2615 |
+
$em = $this->_emsa_pss_encode($m, 8 * $this->k - 1);
|
2616 |
+
|
2617 |
+
// RSA signature
|
2618 |
+
|
2619 |
+
$m = $this->_os2ip($em);
|
2620 |
+
$s = $this->_rsasp1($m);
|
2621 |
+
$s = $this->_i2osp($s, $this->k);
|
2622 |
+
|
2623 |
+
// Output the signature S
|
2624 |
+
|
2625 |
+
return $s;
|
2626 |
+
}
|
2627 |
+
|
2628 |
+
/**
|
2629 |
+
* RSASSA-PSS-VERIFY
|
2630 |
+
*
|
2631 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-8.1.2 RFC3447#section-8.1.2}.
|
2632 |
+
*
|
2633 |
+
* @access private
|
2634 |
+
* @param String $m
|
2635 |
+
* @param String $s
|
2636 |
+
* @return String
|
2637 |
+
*/
|
2638 |
+
function _rsassa_pss_verify($m, $s)
|
2639 |
+
{
|
2640 |
+
// Length checking
|
2641 |
+
|
2642 |
+
if (strlen($s) != $this->k) {
|
2643 |
+
user_error('Invalid signature');
|
2644 |
+
return false;
|
2645 |
+
}
|
2646 |
+
|
2647 |
+
// RSA verification
|
2648 |
+
|
2649 |
+
$modBits = 8 * $this->k;
|
2650 |
+
|
2651 |
+
$s2 = $this->_os2ip($s);
|
2652 |
+
$m2 = $this->_rsavp1($s2);
|
2653 |
+
if ($m2 === false) {
|
2654 |
+
user_error('Invalid signature');
|
2655 |
+
return false;
|
2656 |
+
}
|
2657 |
+
$em = $this->_i2osp($m2, $modBits >> 3);
|
2658 |
+
if ($em === false) {
|
2659 |
+
user_error('Invalid signature');
|
2660 |
+
return false;
|
2661 |
+
}
|
2662 |
+
|
2663 |
+
// EMSA-PSS verification
|
2664 |
+
|
2665 |
+
return $this->_emsa_pss_verify($m, $em, $modBits - 1);
|
2666 |
+
}
|
2667 |
+
|
2668 |
+
/**
|
2669 |
+
* EMSA-PKCS1-V1_5-ENCODE
|
2670 |
+
*
|
2671 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-9.2 RFC3447#section-9.2}.
|
2672 |
+
*
|
2673 |
+
* @access private
|
2674 |
+
* @param String $m
|
2675 |
+
* @param Integer $emLen
|
2676 |
+
* @return String
|
2677 |
+
*/
|
2678 |
+
function _emsa_pkcs1_v1_5_encode($m, $emLen)
|
2679 |
+
{
|
2680 |
+
$h = $this->hash->hash($m);
|
2681 |
+
if ($h === false) {
|
2682 |
+
return false;
|
2683 |
+
}
|
2684 |
+
|
2685 |
+
// see http://tools.ietf.org/html/rfc3447#page-43
|
2686 |
+
switch ($this->hashName) {
|
2687 |
+
case 'md2':
|
2688 |
+
$t = pack('H*', '3020300c06082a864886f70d020205000410');
|
2689 |
+
break;
|
2690 |
+
case 'md5':
|
2691 |
+
$t = pack('H*', '3020300c06082a864886f70d020505000410');
|
2692 |
+
break;
|
2693 |
+
case 'sha1':
|
2694 |
+
$t = pack('H*', '3021300906052b0e03021a05000414');
|
2695 |
+
break;
|
2696 |
+
case 'sha256':
|
2697 |
+
$t = pack('H*', '3031300d060960864801650304020105000420');
|
2698 |
+
break;
|
2699 |
+
case 'sha384':
|
2700 |
+
$t = pack('H*', '3041300d060960864801650304020205000430');
|
2701 |
+
break;
|
2702 |
+
case 'sha512':
|
2703 |
+
$t = pack('H*', '3051300d060960864801650304020305000440');
|
2704 |
+
}
|
2705 |
+
$t.= $h;
|
2706 |
+
$tLen = strlen($t);
|
2707 |
+
|
2708 |
+
if ($emLen < $tLen + 11) {
|
2709 |
+
user_error('Intended encoded message length too short');
|
2710 |
+
return false;
|
2711 |
+
}
|
2712 |
+
|
2713 |
+
$ps = str_repeat(chr(0xFF), $emLen - $tLen - 3);
|
2714 |
+
|
2715 |
+
$em = "\0\1$ps\0$t";
|
2716 |
+
|
2717 |
+
return $em;
|
2718 |
+
}
|
2719 |
+
|
2720 |
+
/**
|
2721 |
+
* RSASSA-PKCS1-V1_5-SIGN
|
2722 |
+
*
|
2723 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-8.2.1 RFC3447#section-8.2.1}.
|
2724 |
+
*
|
2725 |
+
* @access private
|
2726 |
+
* @param String $m
|
2727 |
+
* @return String
|
2728 |
+
*/
|
2729 |
+
function _rsassa_pkcs1_v1_5_sign($m)
|
2730 |
+
{
|
2731 |
+
// EMSA-PKCS1-v1_5 encoding
|
2732 |
+
|
2733 |
+
$em = $this->_emsa_pkcs1_v1_5_encode($m, $this->k);
|
2734 |
+
if ($em === false) {
|
2735 |
+
user_error('RSA modulus too short');
|
2736 |
+
return false;
|
2737 |
+
}
|
2738 |
+
|
2739 |
+
// RSA signature
|
2740 |
+
|
2741 |
+
$m = $this->_os2ip($em);
|
2742 |
+
$s = $this->_rsasp1($m);
|
2743 |
+
$s = $this->_i2osp($s, $this->k);
|
2744 |
+
|
2745 |
+
// Output the signature S
|
2746 |
+
|
2747 |
+
return $s;
|
2748 |
+
}
|
2749 |
+
|
2750 |
+
/**
|
2751 |
+
* RSASSA-PKCS1-V1_5-VERIFY
|
2752 |
+
*
|
2753 |
+
* See {@link http://tools.ietf.org/html/rfc3447#section-8.2.2 RFC3447#section-8.2.2}.
|
2754 |
+
*
|
2755 |
+
* @access private
|
2756 |
+
* @param String $m
|
2757 |
+
* @return String
|
2758 |
+
*/
|
2759 |
+
function _rsassa_pkcs1_v1_5_verify($m, $s)
|
2760 |
+
{
|
2761 |
+
// Length checking
|
2762 |
+
|
2763 |
+
if (strlen($s) != $this->k) {
|
2764 |
+
user_error('Invalid signature');
|
2765 |
+
return false;
|
2766 |
+
}
|
2767 |
+
|
2768 |
+
// RSA verification
|
2769 |
+
|
2770 |
+
$s = $this->_os2ip($s);
|
2771 |
+
$m2 = $this->_rsavp1($s);
|
2772 |
+
if ($m2 === false) {
|
2773 |
+
user_error('Invalid signature');
|
2774 |
+
return false;
|
2775 |
+
}
|
2776 |
+
$em = $this->_i2osp($m2, $this->k);
|
2777 |
+
if ($em === false) {
|
2778 |
+
user_error('Invalid signature');
|
2779 |
+
return false;
|
2780 |
+
}
|
2781 |
+
|
2782 |
+
// EMSA-PKCS1-v1_5 encoding
|
2783 |
+
|
2784 |
+
$em2 = $this->_emsa_pkcs1_v1_5_encode($m, $this->k);
|
2785 |
+
if ($em2 === false) {
|
2786 |
+
user_error('RSA modulus too short');
|
2787 |
+
return false;
|
2788 |
+
}
|
2789 |
+
|
2790 |
+
// Compare
|
2791 |
+
return $this->_equals($em, $em2);
|
2792 |
+
}
|
2793 |
+
|
2794 |
+
/**
|
2795 |
+
* Set Encryption Mode
|
2796 |
+
*
|
2797 |
+
* Valid values include CRYPT_RSA_ENCRYPTION_OAEP and CRYPT_RSA_ENCRYPTION_PKCS1.
|
2798 |
+
*
|
2799 |
+
* @access public
|
2800 |
+
* @param Integer $mode
|
2801 |
+
*/
|
2802 |
+
function setEncryptionMode($mode)
|
2803 |
+
{
|
2804 |
+
$this->encryptionMode = $mode;
|
2805 |
+
}
|
2806 |
+
|
2807 |
+
/**
|
2808 |
+
* Set Signature Mode
|
2809 |
+
*
|
2810 |
+
* Valid values include CRYPT_RSA_SIGNATURE_PSS and CRYPT_RSA_SIGNATURE_PKCS1
|
2811 |
+
*
|
2812 |
+
* @access public
|
2813 |
+
* @param Integer $mode
|
2814 |
+
*/
|
2815 |
+
function setSignatureMode($mode)
|
2816 |
+
{
|
2817 |
+
$this->signatureMode = $mode;
|
2818 |
+
}
|
2819 |
+
|
2820 |
+
/**
|
2821 |
+
* Set public key comment.
|
2822 |
+
*
|
2823 |
+
* @access public
|
2824 |
+
* @param String $comment
|
2825 |
+
*/
|
2826 |
+
function setComment($comment)
|
2827 |
+
{
|
2828 |
+
$this->comment = $comment;
|
2829 |
+
}
|
2830 |
+
|
2831 |
+
/**
|
2832 |
+
* Get public key comment.
|
2833 |
+
*
|
2834 |
+
* @access public
|
2835 |
+
* @return String
|
2836 |
+
*/
|
2837 |
+
function getComment()
|
2838 |
+
{
|
2839 |
+
return $this->comment;
|
2840 |
+
}
|
2841 |
+
|
2842 |
+
/**
|
2843 |
+
* Encryption
|
2844 |
+
*
|
2845 |
+
* Both CRYPT_RSA_ENCRYPTION_OAEP and CRYPT_RSA_ENCRYPTION_PKCS1 both place limits on how long $plaintext can be.
|
2846 |
+
* If $plaintext exceeds those limits it will be broken up so that it does and the resultant ciphertext's will
|
2847 |
+
* be concatenated together.
|
2848 |
+
*
|
2849 |
+
* @see decrypt()
|
2850 |
+
* @access public
|
2851 |
+
* @param String $plaintext
|
2852 |
+
* @return String
|
2853 |
+
*/
|
2854 |
+
function encrypt($plaintext)
|
2855 |
+
{
|
2856 |
+
switch ($this->encryptionMode) {
|
2857 |
+
case CRYPT_RSA_ENCRYPTION_PKCS1:
|
2858 |
+
$length = $this->k - 11;
|
2859 |
+
if ($length <= 0) {
|
2860 |
+
return false;
|
2861 |
+
}
|
2862 |
+
|
2863 |
+
$plaintext = str_split($plaintext, $length);
|
2864 |
+
$ciphertext = '';
|
2865 |
+
foreach ($plaintext as $m) {
|
2866 |
+
$ciphertext.= $this->_rsaes_pkcs1_v1_5_encrypt($m);
|
2867 |
+
}
|
2868 |
+
return $ciphertext;
|
2869 |
+
//case CRYPT_RSA_ENCRYPTION_OAEP:
|
2870 |
+
default:
|
2871 |
+
$length = $this->k - 2 * $this->hLen - 2;
|
2872 |
+
if ($length <= 0) {
|
2873 |
+
return false;
|
2874 |
+
}
|
2875 |
+
|
2876 |
+
$plaintext = str_split($plaintext, $length);
|
2877 |
+
$ciphertext = '';
|
2878 |
+
foreach ($plaintext as $m) {
|
2879 |
+
$ciphertext.= $this->_rsaes_oaep_encrypt($m);
|
2880 |
+
}
|
2881 |
+
return $ciphertext;
|
2882 |
+
}
|
2883 |
+
}
|
2884 |
+
|
2885 |
+
/**
|
2886 |
+
* Decryption
|
2887 |
+
*
|
2888 |
+
* @see encrypt()
|
2889 |
+
* @access public
|
2890 |
+
* @param String $plaintext
|
2891 |
+
* @return String
|
2892 |
+
*/
|
2893 |
+
function decrypt($ciphertext)
|
2894 |
+
{
|
2895 |
+
if ($this->k <= 0) {
|
2896 |
+
return false;
|
2897 |
+
}
|
2898 |
+
|
2899 |
+
$ciphertext = str_split($ciphertext, $this->k);
|
2900 |
+
$ciphertext[count($ciphertext) - 1] = str_pad($ciphertext[count($ciphertext) - 1], $this->k, chr(0), STR_PAD_LEFT);
|
2901 |
+
|
2902 |
+
$plaintext = '';
|
2903 |
+
|
2904 |
+
switch ($this->encryptionMode) {
|
2905 |
+
case CRYPT_RSA_ENCRYPTION_PKCS1:
|
2906 |
+
$decrypt = '_rsaes_pkcs1_v1_5_decrypt';
|
2907 |
+
break;
|
2908 |
+
//case CRYPT_RSA_ENCRYPTION_OAEP:
|
2909 |
+
default:
|
2910 |
+
$decrypt = '_rsaes_oaep_decrypt';
|
2911 |
+
}
|
2912 |
+
|
2913 |
+
foreach ($ciphertext as $c) {
|
2914 |
+
$temp = $this->$decrypt($c);
|
2915 |
+
if ($temp === false) {
|
2916 |
+
return false;
|
2917 |
+
}
|
2918 |
+
$plaintext.= $temp;
|
2919 |
+
}
|
2920 |
+
|
2921 |
+
return $plaintext;
|
2922 |
+
}
|
2923 |
+
|
2924 |
+
/**
|
2925 |
+
* Create a signature
|
2926 |
+
*
|
2927 |
+
* @see verify()
|
2928 |
+
* @access public
|
2929 |
+
* @param String $message
|
2930 |
+
* @return String
|
2931 |
+
*/
|
2932 |
+
function sign($message)
|
2933 |
+
{
|
2934 |
+
if (empty($this->modulus) || empty($this->exponent)) {
|
2935 |
+
return false;
|
2936 |
+
}
|
2937 |
+
|
2938 |
+
switch ($this->signatureMode) {
|
2939 |
+
case CRYPT_RSA_SIGNATURE_PKCS1:
|
2940 |
+
return $this->_rsassa_pkcs1_v1_5_sign($message);
|
2941 |
+
//case CRYPT_RSA_SIGNATURE_PSS:
|
2942 |
+
default:
|
2943 |
+
return $this->_rsassa_pss_sign($message);
|
2944 |
+
}
|
2945 |
+
}
|
2946 |
+
|
2947 |
+
/**
|
2948 |
+
* Verifies a signature
|
2949 |
+
*
|
2950 |
+
* @see sign()
|
2951 |
+
* @access public
|
2952 |
+
* @param String $message
|
2953 |
+
* @param String $signature
|
2954 |
+
* @return Boolean
|
2955 |
+
*/
|
2956 |
+
function verify($message, $signature)
|
2957 |
+
{
|
2958 |
+
if (empty($this->modulus) || empty($this->exponent)) {
|
2959 |
+
return false;
|
2960 |
+
}
|
2961 |
+
|
2962 |
+
switch ($this->signatureMode) {
|
2963 |
+
case CRYPT_RSA_SIGNATURE_PKCS1:
|
2964 |
+
return $this->_rsassa_pkcs1_v1_5_verify($message, $signature);
|
2965 |
+
//case CRYPT_RSA_SIGNATURE_PSS:
|
2966 |
+
default:
|
2967 |
+
return $this->_rsassa_pss_verify($message, $signature);
|
2968 |
+
}
|
2969 |
+
}
|
2970 |
+
|
2971 |
+
/**
|
2972 |
+
* Extract raw BER from Base64 encoding
|
2973 |
+
*
|
2974 |
+
* @access private
|
2975 |
+
* @param String $str
|
2976 |
+
* @return String
|
2977 |
+
*/
|
2978 |
+
function _extractBER($str)
|
2979 |
+
{
|
2980 |
+
/* X.509 certs are assumed to be base64 encoded but sometimes they'll have additional things in them
|
2981 |
+
* above and beyond the ceritificate.
|
2982 |
+
* ie. some may have the following preceding the -----BEGIN CERTIFICATE----- line:
|
2983 |
+
*
|
2984 |
+
* Bag Attributes
|
2985 |
+
* localKeyID: 01 00 00 00
|
2986 |
+
* subject=/O=organization/OU=org unit/CN=common name
|
2987 |
+
* issuer=/O=organization/CN=common name
|
2988 |
+
*/
|
2989 |
+
$temp = preg_replace('#.*?^-+[^-]+-+#ms', '', $str, 1);
|
2990 |
+
// remove the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- stuff
|
2991 |
+
$temp = preg_replace('#-+[^-]+-+#', '', $temp);
|
2992 |
+
// remove new lines
|
2993 |
+
$temp = str_replace(array("\r", "\n", ' '), '', $temp);
|
2994 |
+
$temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false;
|
2995 |
+
return $temp != false ? $temp : $str;
|
2996 |
+
}
|
2997 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Random.php
ADDED
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Random Number Generator
|
5 |
+
*
|
6 |
+
* The idea behind this function is that it can be easily replaced with your own crypt_random_string()
|
7 |
+
* function. eg. maybe you have a better source of entropy for creating the initial states or whatever.
|
8 |
+
*
|
9 |
+
* PHP versions 4 and 5
|
10 |
+
*
|
11 |
+
* Here's a short example of how to use this library:
|
12 |
+
* <code>
|
13 |
+
* <?php
|
14 |
+
* include 'Crypt/Random.php';
|
15 |
+
*
|
16 |
+
* echo bin2hex(crypt_random_string(8));
|
17 |
+
* ?>
|
18 |
+
* </code>
|
19 |
+
*
|
20 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
21 |
+
* of this software and associated documentation files (the "Software"), to deal
|
22 |
+
* in the Software without restriction, including without limitation the rights
|
23 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
24 |
+
* copies of the Software, and to permit persons to whom the Software is
|
25 |
+
* furnished to do so, subject to the following conditions:
|
26 |
+
*
|
27 |
+
* The above copyright notice and this permission notice shall be included in
|
28 |
+
* all copies or substantial portions of the Software.
|
29 |
+
*
|
30 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
31 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
32 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
33 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
34 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
35 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
36 |
+
* THE SOFTWARE.
|
37 |
+
*
|
38 |
+
* @category Crypt
|
39 |
+
* @package Crypt_Random
|
40 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
41 |
+
* @copyright 2007 Jim Wigginton
|
42 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
43 |
+
* @link http://phpseclib.sourceforge.net
|
44 |
+
*/
|
45 |
+
|
46 |
+
// laravel is a PHP framework that utilizes phpseclib. laravel workbenches may, independently,
|
47 |
+
// have phpseclib as a requirement as well. if you're developing such a program you may encounter
|
48 |
+
// a "Cannot redeclare crypt_random_string()" error.
|
49 |
+
if (!function_exists('crypt_random_string')) {
|
50 |
+
/**
|
51 |
+
* "Is Windows" test
|
52 |
+
*
|
53 |
+
* @access private
|
54 |
+
*/
|
55 |
+
define('CRYPT_RANDOM_IS_WINDOWS', strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Generate a random string.
|
59 |
+
*
|
60 |
+
* Although microoptimizations are generally discouraged as they impair readability this function is ripe with
|
61 |
+
* microoptimizations because this function has the potential of being called a huge number of times.
|
62 |
+
* eg. for RSA key generation.
|
63 |
+
*
|
64 |
+
* @param Integer $length
|
65 |
+
* @return String
|
66 |
+
* @access public
|
67 |
+
*/
|
68 |
+
function crypt_random_string($length)
|
69 |
+
{
|
70 |
+
if (CRYPT_RANDOM_IS_WINDOWS) {
|
71 |
+
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call.
|
72 |
+
// ie. class_alias is a function that was introduced in PHP 5.3
|
73 |
+
if (function_exists('mcrypt_create_iv') && function_exists('class_alias')) {
|
74 |
+
return mcrypt_create_iv($length);
|
75 |
+
}
|
76 |
+
// method 2. openssl_random_pseudo_bytes was introduced in PHP 5.3.0 but prior to PHP 5.3.4 there was,
|
77 |
+
// to quote <http://php.net/ChangeLog-5.php#5.3.4>, "possible blocking behavior". as of 5.3.4
|
78 |
+
// openssl_random_pseudo_bytes and mcrypt_create_iv do the exact same thing on Windows. ie. they both
|
79 |
+
// call php_win32_get_random_bytes():
|
80 |
+
//
|
81 |
+
// https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/openssl/openssl.c#L5008
|
82 |
+
// https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/mcrypt/mcrypt.c#L1392
|
83 |
+
//
|
84 |
+
// php_win32_get_random_bytes() is defined thusly:
|
85 |
+
//
|
86 |
+
// https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/win32/winutil.c#L80
|
87 |
+
//
|
88 |
+
// we're calling it, all the same, in the off chance that the mcrypt extension is not available
|
89 |
+
if (function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>=')) {
|
90 |
+
return openssl_random_pseudo_bytes($length);
|
91 |
+
}
|
92 |
+
} else {
|
93 |
+
// method 1. the fastest
|
94 |
+
if (function_exists('openssl_random_pseudo_bytes')) {
|
95 |
+
return openssl_random_pseudo_bytes($length);
|
96 |
+
}
|
97 |
+
// method 2
|
98 |
+
static $fp = true;
|
99 |
+
if ($fp === true) {
|
100 |
+
// warning's will be output unles the error suppression operator is used. errors such as
|
101 |
+
// "open_basedir restriction in effect", "Permission denied", "No such file or directory", etc.
|
102 |
+
$fp = @fopen('/dev/urandom', 'rb');
|
103 |
+
}
|
104 |
+
if ($fp !== true && $fp !== false) { // surprisingly faster than !is_bool() or is_resource()
|
105 |
+
return fread($fp, $length);
|
106 |
+
}
|
107 |
+
// method 3. pretty much does the same thing as method 2 per the following url:
|
108 |
+
// https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/mcrypt/mcrypt.c#L1391
|
109 |
+
// surprisingly slower than method 2. maybe that's because mcrypt_create_iv does a bunch of error checking that we're
|
110 |
+
// not doing. regardless, this'll only be called if this PHP script couldn't open /dev/urandom due to open_basedir
|
111 |
+
// restrictions or some such
|
112 |
+
if (function_exists('mcrypt_create_iv')) {
|
113 |
+
return mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
|
114 |
+
}
|
115 |
+
}
|
116 |
+
// at this point we have no choice but to use a pure-PHP CSPRNG
|
117 |
+
|
118 |
+
// cascade entropy across multiple PHP instances by fixing the session and collecting all
|
119 |
+
// environmental variables, including the previous session data and the current session
|
120 |
+
// data.
|
121 |
+
//
|
122 |
+
// mt_rand seeds itself by looking at the PID and the time, both of which are (relatively)
|
123 |
+
// easy to guess at. linux uses mouse clicks, keyboard timings, etc, as entropy sources, but
|
124 |
+
// PHP isn't low level to be able to use those as sources and on a web server there's not likely
|
125 |
+
// going to be a ton of keyboard or mouse action. web servers do have one thing that we can use
|
126 |
+
// however, a ton of people visiting the website. obviously you don't want to base your seeding
|
127 |
+
// soley on parameters a potential attacker sends but (1) not everything in $_SERVER is controlled
|
128 |
+
// by the user and (2) this isn't just looking at the data sent by the current user - it's based
|
129 |
+
// on the data sent by all users. one user requests the page and a hash of their info is saved.
|
130 |
+
// another user visits the page and the serialization of their data is utilized along with the
|
131 |
+
// server envirnment stuff and a hash of the previous http request data (which itself utilizes
|
132 |
+
// a hash of the session data before that). certainly an attacker should be assumed to have
|
133 |
+
// full control over his own http requests. he, however, is not going to have control over
|
134 |
+
// everyone's http requests.
|
135 |
+
static $crypto = false, $v;
|
136 |
+
if ($crypto === false) {
|
137 |
+
// save old session data
|
138 |
+
$old_session_id = session_id();
|
139 |
+
$old_use_cookies = ini_get('session.use_cookies');
|
140 |
+
$old_session_cache_limiter = session_cache_limiter();
|
141 |
+
$_OLD_SESSION = isset($_SESSION) ? $_SESSION : false;
|
142 |
+
if ($old_session_id != '') {
|
143 |
+
session_write_close();
|
144 |
+
}
|
145 |
+
|
146 |
+
session_id(1);
|
147 |
+
ini_set('session.use_cookies', 0);
|
148 |
+
session_cache_limiter('');
|
149 |
+
session_start();
|
150 |
+
|
151 |
+
$v = $seed = $_SESSION['seed'] = pack('H*', sha1(
|
152 |
+
serialize($_SERVER) .
|
153 |
+
serialize($_POST) .
|
154 |
+
serialize($_GET) .
|
155 |
+
serialize($_COOKIE) .
|
156 |
+
serialize($GLOBALS) .
|
157 |
+
serialize($_SESSION) .
|
158 |
+
serialize($_OLD_SESSION)
|
159 |
+
));
|
160 |
+
if (!isset($_SESSION['count'])) {
|
161 |
+
$_SESSION['count'] = 0;
|
162 |
+
}
|
163 |
+
$_SESSION['count']++;
|
164 |
+
|
165 |
+
session_write_close();
|
166 |
+
|
167 |
+
// restore old session data
|
168 |
+
if ($old_session_id != '') {
|
169 |
+
session_id($old_session_id);
|
170 |
+
session_start();
|
171 |
+
ini_set('session.use_cookies', $old_use_cookies);
|
172 |
+
session_cache_limiter($old_session_cache_limiter);
|
173 |
+
} else {
|
174 |
+
if ($_OLD_SESSION !== false) {
|
175 |
+
$_SESSION = $_OLD_SESSION;
|
176 |
+
unset($_OLD_SESSION);
|
177 |
+
} else {
|
178 |
+
unset($_SESSION);
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
// in SSH2 a shared secret and an exchange hash are generated through the key exchange process.
|
183 |
+
// the IV client to server is the hash of that "nonce" with the letter A and for the encryption key it's the letter C.
|
184 |
+
// if the hash doesn't produce enough a key or an IV that's long enough concat successive hashes of the
|
185 |
+
// original hash and the current hash. we'll be emulating that. for more info see the following URL:
|
186 |
+
//
|
187 |
+
// http://tools.ietf.org/html/rfc4253#section-7.2
|
188 |
+
//
|
189 |
+
// see the is_string($crypto) part for an example of how to expand the keys
|
190 |
+
$key = pack('H*', sha1($seed . 'A'));
|
191 |
+
$iv = pack('H*', sha1($seed . 'C'));
|
192 |
+
|
193 |
+
// ciphers are used as per the nist.gov link below. also, see this link:
|
194 |
+
//
|
195 |
+
// http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Designs_based_on_cryptographic_primitives
|
196 |
+
switch (true) {
|
197 |
+
case phpseclib_resolve_include_path('Crypt/AES.php'):
|
198 |
+
if (!class_exists('Crypt_AES')) {
|
199 |
+
include_once 'AES.php';
|
200 |
+
}
|
201 |
+
$crypto = new Crypt_AES(CRYPT_AES_MODE_CTR);
|
202 |
+
break;
|
203 |
+
case phpseclib_resolve_include_path('Crypt/Twofish.php'):
|
204 |
+
if (!class_exists('Crypt_Twofish')) {
|
205 |
+
include_once 'Twofish.php';
|
206 |
+
}
|
207 |
+
$crypto = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
|
208 |
+
break;
|
209 |
+
case phpseclib_resolve_include_path('Crypt/Blowfish.php'):
|
210 |
+
if (!class_exists('Crypt_Blowfish')) {
|
211 |
+
include_once 'Blowfish.php';
|
212 |
+
}
|
213 |
+
$crypto = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
|
214 |
+
break;
|
215 |
+
case phpseclib_resolve_include_path('Crypt/TripleDES.php'):
|
216 |
+
if (!class_exists('Crypt_TripleDES')) {
|
217 |
+
include_once 'TripleDES.php';
|
218 |
+
}
|
219 |
+
$crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
|
220 |
+
break;
|
221 |
+
case phpseclib_resolve_include_path('Crypt/DES.php'):
|
222 |
+
if (!class_exists('Crypt_DES')) {
|
223 |
+
include_once 'DES.php';
|
224 |
+
}
|
225 |
+
$crypto = new Crypt_DES(CRYPT_DES_MODE_CTR);
|
226 |
+
break;
|
227 |
+
case phpseclib_resolve_include_path('Crypt/RC4.php'):
|
228 |
+
if (!class_exists('Crypt_RC4')) {
|
229 |
+
include_once 'RC4.php';
|
230 |
+
}
|
231 |
+
$crypto = new Crypt_RC4();
|
232 |
+
break;
|
233 |
+
default:
|
234 |
+
user_error('crypt_random_string requires at least one symmetric cipher be loaded');
|
235 |
+
return false;
|
236 |
+
}
|
237 |
+
|
238 |
+
$crypto->setKey($key);
|
239 |
+
$crypto->setIV($iv);
|
240 |
+
$crypto->enableContinuousBuffer();
|
241 |
+
}
|
242 |
+
|
243 |
+
//return $crypto->encrypt(str_repeat("\0", $length));
|
244 |
+
|
245 |
+
// the following is based off of ANSI X9.31:
|
246 |
+
//
|
247 |
+
// http://csrc.nist.gov/groups/STM/cavp/documents/rng/931rngext.pdf
|
248 |
+
//
|
249 |
+
// OpenSSL uses that same standard for it's random numbers:
|
250 |
+
//
|
251 |
+
// http://www.opensource.apple.com/source/OpenSSL/OpenSSL-38/openssl/fips-1.0/rand/fips_rand.c
|
252 |
+
// (do a search for "ANS X9.31 A.2.4")
|
253 |
+
$result = '';
|
254 |
+
while (strlen($result) < $length) {
|
255 |
+
$i = $crypto->encrypt(microtime()); // strlen(microtime()) == 21
|
256 |
+
$r = $crypto->encrypt($i ^ $v); // strlen($v) == 20
|
257 |
+
$v = $crypto->encrypt($r ^ $i); // strlen($r) == 20
|
258 |
+
$result.= $r;
|
259 |
+
}
|
260 |
+
return substr($result, 0, $length);
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
if (!function_exists('phpseclib_resolve_include_path')) {
|
265 |
+
/**
|
266 |
+
* Resolve filename against the include path.
|
267 |
+
*
|
268 |
+
* Wrapper around stream_resolve_include_path() (which was introduced in
|
269 |
+
* PHP 5.3.2) with fallback implementation for earlier PHP versions.
|
270 |
+
*
|
271 |
+
* @param string $filename
|
272 |
+
* @return mixed Filename (string) on success, false otherwise.
|
273 |
+
* @access public
|
274 |
+
*/
|
275 |
+
function phpseclib_resolve_include_path($filename)
|
276 |
+
{
|
277 |
+
if (function_exists('stream_resolve_include_path')) {
|
278 |
+
return stream_resolve_include_path($filename);
|
279 |
+
}
|
280 |
+
|
281 |
+
// handle non-relative paths
|
282 |
+
if (file_exists($filename)) {
|
283 |
+
return realpath($filename);
|
284 |
+
}
|
285 |
+
|
286 |
+
$paths = PATH_SEPARATOR == ':' ?
|
287 |
+
preg_split('#(?<!phar):#', get_include_path()) :
|
288 |
+
explode(PATH_SEPARATOR, get_include_path());
|
289 |
+
foreach ($paths as $prefix) {
|
290 |
+
// path's specified in include_path don't always end in /
|
291 |
+
$ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
|
292 |
+
$file = $prefix . $ds . $filename;
|
293 |
+
if (file_exists($file)) {
|
294 |
+
return realpath($file);
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
return false;
|
299 |
+
}
|
300 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Rijndael.php
ADDED
@@ -0,0 +1,1348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of Rijndael.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available/possible, and an internal implementation, otherwise.
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* If {@link Crypt_Rijndael::setBlockLength() setBlockLength()} isn't called, it'll be assumed to be 128 bits. If
|
11 |
+
* {@link Crypt_Rijndael::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
|
12 |
+
* {@link Crypt_Rijndael::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's
|
13 |
+
* 136-bits it'll be null-padded to 192-bits and 192 bits will be the key length until
|
14 |
+
* {@link Crypt_Rijndael::setKey() setKey()} is called, again, at which point, it'll be recalculated.
|
15 |
+
*
|
16 |
+
* Not all Rijndael implementations may support 160-bits or 224-bits as the block length / key length. mcrypt, for example,
|
17 |
+
* does not. AES, itself, only supports block lengths of 128 and key lengths of 128, 192, and 256.
|
18 |
+
* {@link http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=10 Rijndael-ammended.pdf#page=10} defines the
|
19 |
+
* algorithm for block lengths of 192 and 256 but not for block lengths / key lengths of 160 and 224. Indeed, 160 and 224
|
20 |
+
* are first defined as valid key / block lengths in
|
21 |
+
* {@link http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=44 Rijndael-ammended.pdf#page=44}:
|
22 |
+
* Extensions: Other block and Cipher Key lengths.
|
23 |
+
* Note: Use of 160/224-bit Keys must be explicitly set by setKeyLength(160) respectively setKeyLength(224).
|
24 |
+
*
|
25 |
+
* {@internal The variable names are the same as those in
|
26 |
+
* {@link http://www.csrc.nist.gov/publications/fips/fips197/fips-197.pdf#page=10 fips-197.pdf#page=10}.}}
|
27 |
+
*
|
28 |
+
* Here's a short example of how to use this library:
|
29 |
+
* <code>
|
30 |
+
* <?php
|
31 |
+
* include 'Crypt/Rijndael.php';
|
32 |
+
*
|
33 |
+
* $rijndael = new Crypt_Rijndael();
|
34 |
+
*
|
35 |
+
* $rijndael->setKey('abcdefghijklmnop');
|
36 |
+
*
|
37 |
+
* $size = 10 * 1024;
|
38 |
+
* $plaintext = '';
|
39 |
+
* for ($i = 0; $i < $size; $i++) {
|
40 |
+
* $plaintext.= 'a';
|
41 |
+
* }
|
42 |
+
*
|
43 |
+
* echo $rijndael->decrypt($rijndael->encrypt($plaintext));
|
44 |
+
* ?>
|
45 |
+
* </code>
|
46 |
+
*
|
47 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
48 |
+
* of this software and associated documentation files (the "Software"), to deal
|
49 |
+
* in the Software without restriction, including without limitation the rights
|
50 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
51 |
+
* copies of the Software, and to permit persons to whom the Software is
|
52 |
+
* furnished to do so, subject to the following conditions:
|
53 |
+
*
|
54 |
+
* The above copyright notice and this permission notice shall be included in
|
55 |
+
* all copies or substantial portions of the Software.
|
56 |
+
*
|
57 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
58 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
59 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
60 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
61 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
62 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
63 |
+
* THE SOFTWARE.
|
64 |
+
*
|
65 |
+
* @category Crypt
|
66 |
+
* @package Crypt_Rijndael
|
67 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
68 |
+
* @copyright 2008 Jim Wigginton
|
69 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
70 |
+
* @link http://phpseclib.sourceforge.net
|
71 |
+
*/
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Include Crypt_Base
|
75 |
+
*
|
76 |
+
* Base cipher class
|
77 |
+
*/
|
78 |
+
if (!class_exists('Crypt_Base')) {
|
79 |
+
include_once 'Base.php';
|
80 |
+
}
|
81 |
+
|
82 |
+
/**#@+
|
83 |
+
* @access public
|
84 |
+
* @see Crypt_Rijndael::encrypt()
|
85 |
+
* @see Crypt_Rijndael::decrypt()
|
86 |
+
*/
|
87 |
+
/**
|
88 |
+
* Encrypt / decrypt using the Counter mode.
|
89 |
+
*
|
90 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
91 |
+
*
|
92 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
93 |
+
*/
|
94 |
+
define('CRYPT_RIJNDAEL_MODE_CTR', CRYPT_MODE_CTR);
|
95 |
+
/**
|
96 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
97 |
+
*
|
98 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
99 |
+
*/
|
100 |
+
define('CRYPT_RIJNDAEL_MODE_ECB', CRYPT_MODE_ECB);
|
101 |
+
/**
|
102 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
103 |
+
*
|
104 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
105 |
+
*/
|
106 |
+
define('CRYPT_RIJNDAEL_MODE_CBC', CRYPT_MODE_CBC);
|
107 |
+
/**
|
108 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
109 |
+
*
|
110 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
111 |
+
*/
|
112 |
+
define('CRYPT_RIJNDAEL_MODE_CFB', CRYPT_MODE_CFB);
|
113 |
+
/**
|
114 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
115 |
+
*
|
116 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
117 |
+
*/
|
118 |
+
define('CRYPT_RIJNDAEL_MODE_OFB', CRYPT_MODE_OFB);
|
119 |
+
/**#@-*/
|
120 |
+
|
121 |
+
/**#@+
|
122 |
+
* @access private
|
123 |
+
* @see Crypt_Base::Crypt_Base()
|
124 |
+
*/
|
125 |
+
/**
|
126 |
+
* Toggles the internal implementation
|
127 |
+
*/
|
128 |
+
define('CRYPT_RIJNDAEL_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
129 |
+
/**
|
130 |
+
* Toggles the mcrypt implementation
|
131 |
+
*/
|
132 |
+
define('CRYPT_RIJNDAEL_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
133 |
+
/**#@-*/
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Pure-PHP implementation of Rijndael.
|
137 |
+
*
|
138 |
+
* @package Crypt_Rijndael
|
139 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
140 |
+
* @access public
|
141 |
+
*/
|
142 |
+
class Crypt_Rijndael extends Crypt_Base
|
143 |
+
{
|
144 |
+
/**
|
145 |
+
* The default password key_size used by setPassword()
|
146 |
+
*
|
147 |
+
* @see Crypt_Base::password_key_size
|
148 |
+
* @see Crypt_Base::setPassword()
|
149 |
+
* @var Integer
|
150 |
+
* @access private
|
151 |
+
*/
|
152 |
+
var $password_key_size = 16;
|
153 |
+
|
154 |
+
/**
|
155 |
+
* The namespace used by the cipher for its constants.
|
156 |
+
*
|
157 |
+
* @see Crypt_Base::const_namespace
|
158 |
+
* @var String
|
159 |
+
* @access private
|
160 |
+
*/
|
161 |
+
var $const_namespace = 'RIJNDAEL';
|
162 |
+
|
163 |
+
/**
|
164 |
+
* The mcrypt specific name of the cipher
|
165 |
+
*
|
166 |
+
* Mcrypt is useable for 128/192/256-bit $block_size/$key_size. For 160/224 not.
|
167 |
+
* Crypt_Rijndael determines automatically whether mcrypt is useable
|
168 |
+
* or not for the current $block_size/$key_size.
|
169 |
+
* In case of, $cipher_name_mcrypt will be set dynamically at run time accordingly.
|
170 |
+
*
|
171 |
+
* @see Crypt_Base::cipher_name_mcrypt
|
172 |
+
* @see Crypt_Base::engine
|
173 |
+
* @see _setupEngine()
|
174 |
+
* @var String
|
175 |
+
* @access private
|
176 |
+
*/
|
177 |
+
var $cipher_name_mcrypt = 'rijndael-128';
|
178 |
+
|
179 |
+
/**
|
180 |
+
* The default salt used by setPassword()
|
181 |
+
*
|
182 |
+
* @see Crypt_Base::password_default_salt
|
183 |
+
* @see Crypt_Base::setPassword()
|
184 |
+
* @var String
|
185 |
+
* @access private
|
186 |
+
*/
|
187 |
+
var $password_default_salt = 'phpseclib';
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Has the key length explicitly been set or should it be derived from the key, itself?
|
191 |
+
*
|
192 |
+
* @see setKeyLength()
|
193 |
+
* @var Boolean
|
194 |
+
* @access private
|
195 |
+
*/
|
196 |
+
var $explicit_key_length = false;
|
197 |
+
|
198 |
+
/**
|
199 |
+
* The Key Schedule
|
200 |
+
*
|
201 |
+
* @see _setup()
|
202 |
+
* @var Array
|
203 |
+
* @access private
|
204 |
+
*/
|
205 |
+
var $w;
|
206 |
+
|
207 |
+
/**
|
208 |
+
* The Inverse Key Schedule
|
209 |
+
*
|
210 |
+
* @see _setup()
|
211 |
+
* @var Array
|
212 |
+
* @access private
|
213 |
+
*/
|
214 |
+
var $dw;
|
215 |
+
|
216 |
+
/**
|
217 |
+
* The Block Length divided by 32
|
218 |
+
*
|
219 |
+
* @see setBlockLength()
|
220 |
+
* @var Integer
|
221 |
+
* @access private
|
222 |
+
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4. Exists in conjunction with $block_size
|
223 |
+
* because the encryption / decryption / key schedule creation requires this number and not $block_size. We could
|
224 |
+
* derive this from $block_size or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
|
225 |
+
* of that, we'll just precompute it once.
|
226 |
+
*
|
227 |
+
*/
|
228 |
+
var $Nb = 4;
|
229 |
+
|
230 |
+
/**
|
231 |
+
* The Key Length
|
232 |
+
*
|
233 |
+
* @see setKeyLength()
|
234 |
+
* @var Integer
|
235 |
+
* @access private
|
236 |
+
* @internal The max value is 256 / 8 = 32, the min value is 128 / 8 = 16. Exists in conjunction with $Nk
|
237 |
+
* because the encryption / decryption / key schedule creation requires this number and not $key_size. We could
|
238 |
+
* derive this from $key_size or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
|
239 |
+
* of that, we'll just precompute it once.
|
240 |
+
*/
|
241 |
+
var $key_size = 16;
|
242 |
+
|
243 |
+
/**
|
244 |
+
* The Key Length divided by 32
|
245 |
+
*
|
246 |
+
* @see setKeyLength()
|
247 |
+
* @var Integer
|
248 |
+
* @access private
|
249 |
+
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4
|
250 |
+
*/
|
251 |
+
var $Nk = 4;
|
252 |
+
|
253 |
+
/**
|
254 |
+
* The Number of Rounds
|
255 |
+
*
|
256 |
+
* @var Integer
|
257 |
+
* @access private
|
258 |
+
* @internal The max value is 14, the min value is 10.
|
259 |
+
*/
|
260 |
+
var $Nr;
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Shift offsets
|
264 |
+
*
|
265 |
+
* @var Array
|
266 |
+
* @access private
|
267 |
+
*/
|
268 |
+
var $c;
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Holds the last used key- and block_size information
|
272 |
+
*
|
273 |
+
* @var Array
|
274 |
+
* @access private
|
275 |
+
*/
|
276 |
+
var $kl;
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Precomputed mixColumns table
|
280 |
+
*
|
281 |
+
* According to <http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=19> (section 5.2.1),
|
282 |
+
* precomputed tables can be used in the mixColumns phase. in that example, they're assigned t0...t3, so
|
283 |
+
* those are the names we'll use.
|
284 |
+
*
|
285 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
286 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
287 |
+
* @var Array
|
288 |
+
* @access private
|
289 |
+
*/
|
290 |
+
var $t0 = array(
|
291 |
+
0xC66363A5, 0xF87C7C84, 0xEE777799, 0xF67B7B8D, 0xFFF2F20D, 0xD66B6BBD, 0xDE6F6FB1, 0x91C5C554,
|
292 |
+
0x60303050, 0x02010103, 0xCE6767A9, 0x562B2B7D, 0xE7FEFE19, 0xB5D7D762, 0x4DABABE6, 0xEC76769A,
|
293 |
+
0x8FCACA45, 0x1F82829D, 0x89C9C940, 0xFA7D7D87, 0xEFFAFA15, 0xB25959EB, 0x8E4747C9, 0xFBF0F00B,
|
294 |
+
0x41ADADEC, 0xB3D4D467, 0x5FA2A2FD, 0x45AFAFEA, 0x239C9CBF, 0x53A4A4F7, 0xE4727296, 0x9BC0C05B,
|
295 |
+
0x75B7B7C2, 0xE1FDFD1C, 0x3D9393AE, 0x4C26266A, 0x6C36365A, 0x7E3F3F41, 0xF5F7F702, 0x83CCCC4F,
|
296 |
+
0x6834345C, 0x51A5A5F4, 0xD1E5E534, 0xF9F1F108, 0xE2717193, 0xABD8D873, 0x62313153, 0x2A15153F,
|
297 |
+
0x0804040C, 0x95C7C752, 0x46232365, 0x9DC3C35E, 0x30181828, 0x379696A1, 0x0A05050F, 0x2F9A9AB5,
|
298 |
+
0x0E070709, 0x24121236, 0x1B80809B, 0xDFE2E23D, 0xCDEBEB26, 0x4E272769, 0x7FB2B2CD, 0xEA75759F,
|
299 |
+
0x1209091B, 0x1D83839E, 0x582C2C74, 0x341A1A2E, 0x361B1B2D, 0xDC6E6EB2, 0xB45A5AEE, 0x5BA0A0FB,
|
300 |
+
0xA45252F6, 0x763B3B4D, 0xB7D6D661, 0x7DB3B3CE, 0x5229297B, 0xDDE3E33E, 0x5E2F2F71, 0x13848497,
|
301 |
+
0xA65353F5, 0xB9D1D168, 0x00000000, 0xC1EDED2C, 0x40202060, 0xE3FCFC1F, 0x79B1B1C8, 0xB65B5BED,
|
302 |
+
0xD46A6ABE, 0x8DCBCB46, 0x67BEBED9, 0x7239394B, 0x944A4ADE, 0x984C4CD4, 0xB05858E8, 0x85CFCF4A,
|
303 |
+
0xBBD0D06B, 0xC5EFEF2A, 0x4FAAAAE5, 0xEDFBFB16, 0x864343C5, 0x9A4D4DD7, 0x66333355, 0x11858594,
|
304 |
+
0x8A4545CF, 0xE9F9F910, 0x04020206, 0xFE7F7F81, 0xA05050F0, 0x783C3C44, 0x259F9FBA, 0x4BA8A8E3,
|
305 |
+
0xA25151F3, 0x5DA3A3FE, 0x804040C0, 0x058F8F8A, 0x3F9292AD, 0x219D9DBC, 0x70383848, 0xF1F5F504,
|
306 |
+
0x63BCBCDF, 0x77B6B6C1, 0xAFDADA75, 0x42212163, 0x20101030, 0xE5FFFF1A, 0xFDF3F30E, 0xBFD2D26D,
|
307 |
+
0x81CDCD4C, 0x180C0C14, 0x26131335, 0xC3ECEC2F, 0xBE5F5FE1, 0x359797A2, 0x884444CC, 0x2E171739,
|
308 |
+
0x93C4C457, 0x55A7A7F2, 0xFC7E7E82, 0x7A3D3D47, 0xC86464AC, 0xBA5D5DE7, 0x3219192B, 0xE6737395,
|
309 |
+
0xC06060A0, 0x19818198, 0x9E4F4FD1, 0xA3DCDC7F, 0x44222266, 0x542A2A7E, 0x3B9090AB, 0x0B888883,
|
310 |
+
0x8C4646CA, 0xC7EEEE29, 0x6BB8B8D3, 0x2814143C, 0xA7DEDE79, 0xBC5E5EE2, 0x160B0B1D, 0xADDBDB76,
|
311 |
+
0xDBE0E03B, 0x64323256, 0x743A3A4E, 0x140A0A1E, 0x924949DB, 0x0C06060A, 0x4824246C, 0xB85C5CE4,
|
312 |
+
0x9FC2C25D, 0xBDD3D36E, 0x43ACACEF, 0xC46262A6, 0x399191A8, 0x319595A4, 0xD3E4E437, 0xF279798B,
|
313 |
+
0xD5E7E732, 0x8BC8C843, 0x6E373759, 0xDA6D6DB7, 0x018D8D8C, 0xB1D5D564, 0x9C4E4ED2, 0x49A9A9E0,
|
314 |
+
0xD86C6CB4, 0xAC5656FA, 0xF3F4F407, 0xCFEAEA25, 0xCA6565AF, 0xF47A7A8E, 0x47AEAEE9, 0x10080818,
|
315 |
+
0x6FBABAD5, 0xF0787888, 0x4A25256F, 0x5C2E2E72, 0x381C1C24, 0x57A6A6F1, 0x73B4B4C7, 0x97C6C651,
|
316 |
+
0xCBE8E823, 0xA1DDDD7C, 0xE874749C, 0x3E1F1F21, 0x964B4BDD, 0x61BDBDDC, 0x0D8B8B86, 0x0F8A8A85,
|
317 |
+
0xE0707090, 0x7C3E3E42, 0x71B5B5C4, 0xCC6666AA, 0x904848D8, 0x06030305, 0xF7F6F601, 0x1C0E0E12,
|
318 |
+
0xC26161A3, 0x6A35355F, 0xAE5757F9, 0x69B9B9D0, 0x17868691, 0x99C1C158, 0x3A1D1D27, 0x279E9EB9,
|
319 |
+
0xD9E1E138, 0xEBF8F813, 0x2B9898B3, 0x22111133, 0xD26969BB, 0xA9D9D970, 0x078E8E89, 0x339494A7,
|
320 |
+
0x2D9B9BB6, 0x3C1E1E22, 0x15878792, 0xC9E9E920, 0x87CECE49, 0xAA5555FF, 0x50282878, 0xA5DFDF7A,
|
321 |
+
0x038C8C8F, 0x59A1A1F8, 0x09898980, 0x1A0D0D17, 0x65BFBFDA, 0xD7E6E631, 0x844242C6, 0xD06868B8,
|
322 |
+
0x824141C3, 0x299999B0, 0x5A2D2D77, 0x1E0F0F11, 0x7BB0B0CB, 0xA85454FC, 0x6DBBBBD6, 0x2C16163A
|
323 |
+
);
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Precomputed mixColumns table
|
327 |
+
*
|
328 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
329 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
330 |
+
* @var Array
|
331 |
+
* @access private
|
332 |
+
*/
|
333 |
+
var $t1 = array(
|
334 |
+
0xA5C66363, 0x84F87C7C, 0x99EE7777, 0x8DF67B7B, 0x0DFFF2F2, 0xBDD66B6B, 0xB1DE6F6F, 0x5491C5C5,
|
335 |
+
0x50603030, 0x03020101, 0xA9CE6767, 0x7D562B2B, 0x19E7FEFE, 0x62B5D7D7, 0xE64DABAB, 0x9AEC7676,
|
336 |
+
0x458FCACA, 0x9D1F8282, 0x4089C9C9, 0x87FA7D7D, 0x15EFFAFA, 0xEBB25959, 0xC98E4747, 0x0BFBF0F0,
|
337 |
+
0xEC41ADAD, 0x67B3D4D4, 0xFD5FA2A2, 0xEA45AFAF, 0xBF239C9C, 0xF753A4A4, 0x96E47272, 0x5B9BC0C0,
|
338 |
+
0xC275B7B7, 0x1CE1FDFD, 0xAE3D9393, 0x6A4C2626, 0x5A6C3636, 0x417E3F3F, 0x02F5F7F7, 0x4F83CCCC,
|
339 |
+
0x5C683434, 0xF451A5A5, 0x34D1E5E5, 0x08F9F1F1, 0x93E27171, 0x73ABD8D8, 0x53623131, 0x3F2A1515,
|
340 |
+
0x0C080404, 0x5295C7C7, 0x65462323, 0x5E9DC3C3, 0x28301818, 0xA1379696, 0x0F0A0505, 0xB52F9A9A,
|
341 |
+
0x090E0707, 0x36241212, 0x9B1B8080, 0x3DDFE2E2, 0x26CDEBEB, 0x694E2727, 0xCD7FB2B2, 0x9FEA7575,
|
342 |
+
0x1B120909, 0x9E1D8383, 0x74582C2C, 0x2E341A1A, 0x2D361B1B, 0xB2DC6E6E, 0xEEB45A5A, 0xFB5BA0A0,
|
343 |
+
0xF6A45252, 0x4D763B3B, 0x61B7D6D6, 0xCE7DB3B3, 0x7B522929, 0x3EDDE3E3, 0x715E2F2F, 0x97138484,
|
344 |
+
0xF5A65353, 0x68B9D1D1, 0x00000000, 0x2CC1EDED, 0x60402020, 0x1FE3FCFC, 0xC879B1B1, 0xEDB65B5B,
|
345 |
+
0xBED46A6A, 0x468DCBCB, 0xD967BEBE, 0x4B723939, 0xDE944A4A, 0xD4984C4C, 0xE8B05858, 0x4A85CFCF,
|
346 |
+
0x6BBBD0D0, 0x2AC5EFEF, 0xE54FAAAA, 0x16EDFBFB, 0xC5864343, 0xD79A4D4D, 0x55663333, 0x94118585,
|
347 |
+
0xCF8A4545, 0x10E9F9F9, 0x06040202, 0x81FE7F7F, 0xF0A05050, 0x44783C3C, 0xBA259F9F, 0xE34BA8A8,
|
348 |
+
0xF3A25151, 0xFE5DA3A3, 0xC0804040, 0x8A058F8F, 0xAD3F9292, 0xBC219D9D, 0x48703838, 0x04F1F5F5,
|
349 |
+
0xDF63BCBC, 0xC177B6B6, 0x75AFDADA, 0x63422121, 0x30201010, 0x1AE5FFFF, 0x0EFDF3F3, 0x6DBFD2D2,
|
350 |
+
0x4C81CDCD, 0x14180C0C, 0x35261313, 0x2FC3ECEC, 0xE1BE5F5F, 0xA2359797, 0xCC884444, 0x392E1717,
|
351 |
+
0x5793C4C4, 0xF255A7A7, 0x82FC7E7E, 0x477A3D3D, 0xACC86464, 0xE7BA5D5D, 0x2B321919, 0x95E67373,
|
352 |
+
0xA0C06060, 0x98198181, 0xD19E4F4F, 0x7FA3DCDC, 0x66442222, 0x7E542A2A, 0xAB3B9090, 0x830B8888,
|
353 |
+
0xCA8C4646, 0x29C7EEEE, 0xD36BB8B8, 0x3C281414, 0x79A7DEDE, 0xE2BC5E5E, 0x1D160B0B, 0x76ADDBDB,
|
354 |
+
0x3BDBE0E0, 0x56643232, 0x4E743A3A, 0x1E140A0A, 0xDB924949, 0x0A0C0606, 0x6C482424, 0xE4B85C5C,
|
355 |
+
0x5D9FC2C2, 0x6EBDD3D3, 0xEF43ACAC, 0xA6C46262, 0xA8399191, 0xA4319595, 0x37D3E4E4, 0x8BF27979,
|
356 |
+
0x32D5E7E7, 0x438BC8C8, 0x596E3737, 0xB7DA6D6D, 0x8C018D8D, 0x64B1D5D5, 0xD29C4E4E, 0xE049A9A9,
|
357 |
+
0xB4D86C6C, 0xFAAC5656, 0x07F3F4F4, 0x25CFEAEA, 0xAFCA6565, 0x8EF47A7A, 0xE947AEAE, 0x18100808,
|
358 |
+
0xD56FBABA, 0x88F07878, 0x6F4A2525, 0x725C2E2E, 0x24381C1C, 0xF157A6A6, 0xC773B4B4, 0x5197C6C6,
|
359 |
+
0x23CBE8E8, 0x7CA1DDDD, 0x9CE87474, 0x213E1F1F, 0xDD964B4B, 0xDC61BDBD, 0x860D8B8B, 0x850F8A8A,
|
360 |
+
0x90E07070, 0x427C3E3E, 0xC471B5B5, 0xAACC6666, 0xD8904848, 0x05060303, 0x01F7F6F6, 0x121C0E0E,
|
361 |
+
0xA3C26161, 0x5F6A3535, 0xF9AE5757, 0xD069B9B9, 0x91178686, 0x5899C1C1, 0x273A1D1D, 0xB9279E9E,
|
362 |
+
0x38D9E1E1, 0x13EBF8F8, 0xB32B9898, 0x33221111, 0xBBD26969, 0x70A9D9D9, 0x89078E8E, 0xA7339494,
|
363 |
+
0xB62D9B9B, 0x223C1E1E, 0x92158787, 0x20C9E9E9, 0x4987CECE, 0xFFAA5555, 0x78502828, 0x7AA5DFDF,
|
364 |
+
0x8F038C8C, 0xF859A1A1, 0x80098989, 0x171A0D0D, 0xDA65BFBF, 0x31D7E6E6, 0xC6844242, 0xB8D06868,
|
365 |
+
0xC3824141, 0xB0299999, 0x775A2D2D, 0x111E0F0F, 0xCB7BB0B0, 0xFCA85454, 0xD66DBBBB, 0x3A2C1616
|
366 |
+
);
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Precomputed mixColumns table
|
370 |
+
*
|
371 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
372 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
373 |
+
* @var Array
|
374 |
+
* @access private
|
375 |
+
*/
|
376 |
+
var $t2 = array(
|
377 |
+
0x63A5C663, 0x7C84F87C, 0x7799EE77, 0x7B8DF67B, 0xF20DFFF2, 0x6BBDD66B, 0x6FB1DE6F, 0xC55491C5,
|
378 |
+
0x30506030, 0x01030201, 0x67A9CE67, 0x2B7D562B, 0xFE19E7FE, 0xD762B5D7, 0xABE64DAB, 0x769AEC76,
|
379 |
+
0xCA458FCA, 0x829D1F82, 0xC94089C9, 0x7D87FA7D, 0xFA15EFFA, 0x59EBB259, 0x47C98E47, 0xF00BFBF0,
|
380 |
+
0xADEC41AD, 0xD467B3D4, 0xA2FD5FA2, 0xAFEA45AF, 0x9CBF239C, 0xA4F753A4, 0x7296E472, 0xC05B9BC0,
|
381 |
+
0xB7C275B7, 0xFD1CE1FD, 0x93AE3D93, 0x266A4C26, 0x365A6C36, 0x3F417E3F, 0xF702F5F7, 0xCC4F83CC,
|
382 |
+
0x345C6834, 0xA5F451A5, 0xE534D1E5, 0xF108F9F1, 0x7193E271, 0xD873ABD8, 0x31536231, 0x153F2A15,
|
383 |
+
0x040C0804, 0xC75295C7, 0x23654623, 0xC35E9DC3, 0x18283018, 0x96A13796, 0x050F0A05, 0x9AB52F9A,
|
384 |
+
0x07090E07, 0x12362412, 0x809B1B80, 0xE23DDFE2, 0xEB26CDEB, 0x27694E27, 0xB2CD7FB2, 0x759FEA75,
|
385 |
+
0x091B1209, 0x839E1D83, 0x2C74582C, 0x1A2E341A, 0x1B2D361B, 0x6EB2DC6E, 0x5AEEB45A, 0xA0FB5BA0,
|
386 |
+
0x52F6A452, 0x3B4D763B, 0xD661B7D6, 0xB3CE7DB3, 0x297B5229, 0xE33EDDE3, 0x2F715E2F, 0x84971384,
|
387 |
+
0x53F5A653, 0xD168B9D1, 0x00000000, 0xED2CC1ED, 0x20604020, 0xFC1FE3FC, 0xB1C879B1, 0x5BEDB65B,
|
388 |
+
0x6ABED46A, 0xCB468DCB, 0xBED967BE, 0x394B7239, 0x4ADE944A, 0x4CD4984C, 0x58E8B058, 0xCF4A85CF,
|
389 |
+
0xD06BBBD0, 0xEF2AC5EF, 0xAAE54FAA, 0xFB16EDFB, 0x43C58643, 0x4DD79A4D, 0x33556633, 0x85941185,
|
390 |
+
0x45CF8A45, 0xF910E9F9, 0x02060402, 0x7F81FE7F, 0x50F0A050, 0x3C44783C, 0x9FBA259F, 0xA8E34BA8,
|
391 |
+
0x51F3A251, 0xA3FE5DA3, 0x40C08040, 0x8F8A058F, 0x92AD3F92, 0x9DBC219D, 0x38487038, 0xF504F1F5,
|
392 |
+
0xBCDF63BC, 0xB6C177B6, 0xDA75AFDA, 0x21634221, 0x10302010, 0xFF1AE5FF, 0xF30EFDF3, 0xD26DBFD2,
|
393 |
+
0xCD4C81CD, 0x0C14180C, 0x13352613, 0xEC2FC3EC, 0x5FE1BE5F, 0x97A23597, 0x44CC8844, 0x17392E17,
|
394 |
+
0xC45793C4, 0xA7F255A7, 0x7E82FC7E, 0x3D477A3D, 0x64ACC864, 0x5DE7BA5D, 0x192B3219, 0x7395E673,
|
395 |
+
0x60A0C060, 0x81981981, 0x4FD19E4F, 0xDC7FA3DC, 0x22664422, 0x2A7E542A, 0x90AB3B90, 0x88830B88,
|
396 |
+
0x46CA8C46, 0xEE29C7EE, 0xB8D36BB8, 0x143C2814, 0xDE79A7DE, 0x5EE2BC5E, 0x0B1D160B, 0xDB76ADDB,
|
397 |
+
0xE03BDBE0, 0x32566432, 0x3A4E743A, 0x0A1E140A, 0x49DB9249, 0x060A0C06, 0x246C4824, 0x5CE4B85C,
|
398 |
+
0xC25D9FC2, 0xD36EBDD3, 0xACEF43AC, 0x62A6C462, 0x91A83991, 0x95A43195, 0xE437D3E4, 0x798BF279,
|
399 |
+
0xE732D5E7, 0xC8438BC8, 0x37596E37, 0x6DB7DA6D, 0x8D8C018D, 0xD564B1D5, 0x4ED29C4E, 0xA9E049A9,
|
400 |
+
0x6CB4D86C, 0x56FAAC56, 0xF407F3F4, 0xEA25CFEA, 0x65AFCA65, 0x7A8EF47A, 0xAEE947AE, 0x08181008,
|
401 |
+
0xBAD56FBA, 0x7888F078, 0x256F4A25, 0x2E725C2E, 0x1C24381C, 0xA6F157A6, 0xB4C773B4, 0xC65197C6,
|
402 |
+
0xE823CBE8, 0xDD7CA1DD, 0x749CE874, 0x1F213E1F, 0x4BDD964B, 0xBDDC61BD, 0x8B860D8B, 0x8A850F8A,
|
403 |
+
0x7090E070, 0x3E427C3E, 0xB5C471B5, 0x66AACC66, 0x48D89048, 0x03050603, 0xF601F7F6, 0x0E121C0E,
|
404 |
+
0x61A3C261, 0x355F6A35, 0x57F9AE57, 0xB9D069B9, 0x86911786, 0xC15899C1, 0x1D273A1D, 0x9EB9279E,
|
405 |
+
0xE138D9E1, 0xF813EBF8, 0x98B32B98, 0x11332211, 0x69BBD269, 0xD970A9D9, 0x8E89078E, 0x94A73394,
|
406 |
+
0x9BB62D9B, 0x1E223C1E, 0x87921587, 0xE920C9E9, 0xCE4987CE, 0x55FFAA55, 0x28785028, 0xDF7AA5DF,
|
407 |
+
0x8C8F038C, 0xA1F859A1, 0x89800989, 0x0D171A0D, 0xBFDA65BF, 0xE631D7E6, 0x42C68442, 0x68B8D068,
|
408 |
+
0x41C38241, 0x99B02999, 0x2D775A2D, 0x0F111E0F, 0xB0CB7BB0, 0x54FCA854, 0xBBD66DBB, 0x163A2C16
|
409 |
+
);
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Precomputed mixColumns table
|
413 |
+
*
|
414 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
415 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
416 |
+
* @var Array
|
417 |
+
* @access private
|
418 |
+
*/
|
419 |
+
var $t3 = array(
|
420 |
+
0x6363A5C6, 0x7C7C84F8, 0x777799EE, 0x7B7B8DF6, 0xF2F20DFF, 0x6B6BBDD6, 0x6F6FB1DE, 0xC5C55491,
|
421 |
+
0x30305060, 0x01010302, 0x6767A9CE, 0x2B2B7D56, 0xFEFE19E7, 0xD7D762B5, 0xABABE64D, 0x76769AEC,
|
422 |
+
0xCACA458F, 0x82829D1F, 0xC9C94089, 0x7D7D87FA, 0xFAFA15EF, 0x5959EBB2, 0x4747C98E, 0xF0F00BFB,
|
423 |
+
0xADADEC41, 0xD4D467B3, 0xA2A2FD5F, 0xAFAFEA45, 0x9C9CBF23, 0xA4A4F753, 0x727296E4, 0xC0C05B9B,
|
424 |
+
0xB7B7C275, 0xFDFD1CE1, 0x9393AE3D, 0x26266A4C, 0x36365A6C, 0x3F3F417E, 0xF7F702F5, 0xCCCC4F83,
|
425 |
+
0x34345C68, 0xA5A5F451, 0xE5E534D1, 0xF1F108F9, 0x717193E2, 0xD8D873AB, 0x31315362, 0x15153F2A,
|
426 |
+
0x04040C08, 0xC7C75295, 0x23236546, 0xC3C35E9D, 0x18182830, 0x9696A137, 0x05050F0A, 0x9A9AB52F,
|
427 |
+
0x0707090E, 0x12123624, 0x80809B1B, 0xE2E23DDF, 0xEBEB26CD, 0x2727694E, 0xB2B2CD7F, 0x75759FEA,
|
428 |
+
0x09091B12, 0x83839E1D, 0x2C2C7458, 0x1A1A2E34, 0x1B1B2D36, 0x6E6EB2DC, 0x5A5AEEB4, 0xA0A0FB5B,
|
429 |
+
0x5252F6A4, 0x3B3B4D76, 0xD6D661B7, 0xB3B3CE7D, 0x29297B52, 0xE3E33EDD, 0x2F2F715E, 0x84849713,
|
430 |
+
0x5353F5A6, 0xD1D168B9, 0x00000000, 0xEDED2CC1, 0x20206040, 0xFCFC1FE3, 0xB1B1C879, 0x5B5BEDB6,
|
431 |
+
0x6A6ABED4, 0xCBCB468D, 0xBEBED967, 0x39394B72, 0x4A4ADE94, 0x4C4CD498, 0x5858E8B0, 0xCFCF4A85,
|
432 |
+
0xD0D06BBB, 0xEFEF2AC5, 0xAAAAE54F, 0xFBFB16ED, 0x4343C586, 0x4D4DD79A, 0x33335566, 0x85859411,
|
433 |
+
0x4545CF8A, 0xF9F910E9, 0x02020604, 0x7F7F81FE, 0x5050F0A0, 0x3C3C4478, 0x9F9FBA25, 0xA8A8E34B,
|
434 |
+
0x5151F3A2, 0xA3A3FE5D, 0x4040C080, 0x8F8F8A05, 0x9292AD3F, 0x9D9DBC21, 0x38384870, 0xF5F504F1,
|
435 |
+
0xBCBCDF63, 0xB6B6C177, 0xDADA75AF, 0x21216342, 0x10103020, 0xFFFF1AE5, 0xF3F30EFD, 0xD2D26DBF,
|
436 |
+
0xCDCD4C81, 0x0C0C1418, 0x13133526, 0xECEC2FC3, 0x5F5FE1BE, 0x9797A235, 0x4444CC88, 0x1717392E,
|
437 |
+
0xC4C45793, 0xA7A7F255, 0x7E7E82FC, 0x3D3D477A, 0x6464ACC8, 0x5D5DE7BA, 0x19192B32, 0x737395E6,
|
438 |
+
0x6060A0C0, 0x81819819, 0x4F4FD19E, 0xDCDC7FA3, 0x22226644, 0x2A2A7E54, 0x9090AB3B, 0x8888830B,
|
439 |
+
0x4646CA8C, 0xEEEE29C7, 0xB8B8D36B, 0x14143C28, 0xDEDE79A7, 0x5E5EE2BC, 0x0B0B1D16, 0xDBDB76AD,
|
440 |
+
0xE0E03BDB, 0x32325664, 0x3A3A4E74, 0x0A0A1E14, 0x4949DB92, 0x06060A0C, 0x24246C48, 0x5C5CE4B8,
|
441 |
+
0xC2C25D9F, 0xD3D36EBD, 0xACACEF43, 0x6262A6C4, 0x9191A839, 0x9595A431, 0xE4E437D3, 0x79798BF2,
|
442 |
+
0xE7E732D5, 0xC8C8438B, 0x3737596E, 0x6D6DB7DA, 0x8D8D8C01, 0xD5D564B1, 0x4E4ED29C, 0xA9A9E049,
|
443 |
+
0x6C6CB4D8, 0x5656FAAC, 0xF4F407F3, 0xEAEA25CF, 0x6565AFCA, 0x7A7A8EF4, 0xAEAEE947, 0x08081810,
|
444 |
+
0xBABAD56F, 0x787888F0, 0x25256F4A, 0x2E2E725C, 0x1C1C2438, 0xA6A6F157, 0xB4B4C773, 0xC6C65197,
|
445 |
+
0xE8E823CB, 0xDDDD7CA1, 0x74749CE8, 0x1F1F213E, 0x4B4BDD96, 0xBDBDDC61, 0x8B8B860D, 0x8A8A850F,
|
446 |
+
0x707090E0, 0x3E3E427C, 0xB5B5C471, 0x6666AACC, 0x4848D890, 0x03030506, 0xF6F601F7, 0x0E0E121C,
|
447 |
+
0x6161A3C2, 0x35355F6A, 0x5757F9AE, 0xB9B9D069, 0x86869117, 0xC1C15899, 0x1D1D273A, 0x9E9EB927,
|
448 |
+
0xE1E138D9, 0xF8F813EB, 0x9898B32B, 0x11113322, 0x6969BBD2, 0xD9D970A9, 0x8E8E8907, 0x9494A733,
|
449 |
+
0x9B9BB62D, 0x1E1E223C, 0x87879215, 0xE9E920C9, 0xCECE4987, 0x5555FFAA, 0x28287850, 0xDFDF7AA5,
|
450 |
+
0x8C8C8F03, 0xA1A1F859, 0x89898009, 0x0D0D171A, 0xBFBFDA65, 0xE6E631D7, 0x4242C684, 0x6868B8D0,
|
451 |
+
0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C
|
452 |
+
);
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Precomputed invMixColumns table
|
456 |
+
*
|
457 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
458 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
459 |
+
* @var Array
|
460 |
+
* @access private
|
461 |
+
*/
|
462 |
+
var $dt0 = array(
|
463 |
+
0x51F4A750, 0x7E416553, 0x1A17A4C3, 0x3A275E96, 0x3BAB6BCB, 0x1F9D45F1, 0xACFA58AB, 0x4BE30393,
|
464 |
+
0x2030FA55, 0xAD766DF6, 0x88CC7691, 0xF5024C25, 0x4FE5D7FC, 0xC52ACBD7, 0x26354480, 0xB562A38F,
|
465 |
+
0xDEB15A49, 0x25BA1B67, 0x45EA0E98, 0x5DFEC0E1, 0xC32F7502, 0x814CF012, 0x8D4697A3, 0x6BD3F9C6,
|
466 |
+
0x038F5FE7, 0x15929C95, 0xBF6D7AEB, 0x955259DA, 0xD4BE832D, 0x587421D3, 0x49E06929, 0x8EC9C844,
|
467 |
+
0x75C2896A, 0xF48E7978, 0x99583E6B, 0x27B971DD, 0xBEE14FB6, 0xF088AD17, 0xC920AC66, 0x7DCE3AB4,
|
468 |
+
0x63DF4A18, 0xE51A3182, 0x97513360, 0x62537F45, 0xB16477E0, 0xBB6BAE84, 0xFE81A01C, 0xF9082B94,
|
469 |
+
0x70486858, 0x8F45FD19, 0x94DE6C87, 0x527BF8B7, 0xAB73D323, 0x724B02E2, 0xE31F8F57, 0x6655AB2A,
|
470 |
+
0xB2EB2807, 0x2FB5C203, 0x86C57B9A, 0xD33708A5, 0x302887F2, 0x23BFA5B2, 0x02036ABA, 0xED16825C,
|
471 |
+
0x8ACF1C2B, 0xA779B492, 0xF307F2F0, 0x4E69E2A1, 0x65DAF4CD, 0x0605BED5, 0xD134621F, 0xC4A6FE8A,
|
472 |
+
0x342E539D, 0xA2F355A0, 0x058AE132, 0xA4F6EB75, 0x0B83EC39, 0x4060EFAA, 0x5E719F06, 0xBD6E1051,
|
473 |
+
0x3E218AF9, 0x96DD063D, 0xDD3E05AE, 0x4DE6BD46, 0x91548DB5, 0x71C45D05, 0x0406D46F, 0x605015FF,
|
474 |
+
0x1998FB24, 0xD6BDE997, 0x894043CC, 0x67D99E77, 0xB0E842BD, 0x07898B88, 0xE7195B38, 0x79C8EEDB,
|
475 |
+
0xA17C0A47, 0x7C420FE9, 0xF8841EC9, 0x00000000, 0x09808683, 0x322BED48, 0x1E1170AC, 0x6C5A724E,
|
476 |
+
0xFD0EFFFB, 0x0F853856, 0x3DAED51E, 0x362D3927, 0x0A0FD964, 0x685CA621, 0x9B5B54D1, 0x24362E3A,
|
477 |
+
0x0C0A67B1, 0x9357E70F, 0xB4EE96D2, 0x1B9B919E, 0x80C0C54F, 0x61DC20A2, 0x5A774B69, 0x1C121A16,
|
478 |
+
0xE293BA0A, 0xC0A02AE5, 0x3C22E043, 0x121B171D, 0x0E090D0B, 0xF28BC7AD, 0x2DB6A8B9, 0x141EA9C8,
|
479 |
+
0x57F11985, 0xAF75074C, 0xEE99DDBB, 0xA37F60FD, 0xF701269F, 0x5C72F5BC, 0x44663BC5, 0x5BFB7E34,
|
480 |
+
0x8B432976, 0xCB23C6DC, 0xB6EDFC68, 0xB8E4F163, 0xD731DCCA, 0x42638510, 0x13972240, 0x84C61120,
|
481 |
+
0x854A247D, 0xD2BB3DF8, 0xAEF93211, 0xC729A16D, 0x1D9E2F4B, 0xDCB230F3, 0x0D8652EC, 0x77C1E3D0,
|
482 |
+
0x2BB3166C, 0xA970B999, 0x119448FA, 0x47E96422, 0xA8FC8CC4, 0xA0F03F1A, 0x567D2CD8, 0x223390EF,
|
483 |
+
0x87494EC7, 0xD938D1C1, 0x8CCAA2FE, 0x98D40B36, 0xA6F581CF, 0xA57ADE28, 0xDAB78E26, 0x3FADBFA4,
|
484 |
+
0x2C3A9DE4, 0x5078920D, 0x6A5FCC9B, 0x547E4662, 0xF68D13C2, 0x90D8B8E8, 0x2E39F75E, 0x82C3AFF5,
|
485 |
+
0x9F5D80BE, 0x69D0937C, 0x6FD52DA9, 0xCF2512B3, 0xC8AC993B, 0x10187DA7, 0xE89C636E, 0xDB3BBB7B,
|
486 |
+
0xCD267809, 0x6E5918F4, 0xEC9AB701, 0x834F9AA8, 0xE6956E65, 0xAAFFE67E, 0x21BCCF08, 0xEF15E8E6,
|
487 |
+
0xBAE79BD9, 0x4A6F36CE, 0xEA9F09D4, 0x29B07CD6, 0x31A4B2AF, 0x2A3F2331, 0xC6A59430, 0x35A266C0,
|
488 |
+
0x744EBC37, 0xFC82CAA6, 0xE090D0B0, 0x33A7D815, 0xF104984A, 0x41ECDAF7, 0x7FCD500E, 0x1791F62F,
|
489 |
+
0x764DD68D, 0x43EFB04D, 0xCCAA4D54, 0xE49604DF, 0x9ED1B5E3, 0x4C6A881B, 0xC12C1FB8, 0x4665517F,
|
490 |
+
0x9D5EEA04, 0x018C355D, 0xFA877473, 0xFB0B412E, 0xB3671D5A, 0x92DBD252, 0xE9105633, 0x6DD64713,
|
491 |
+
0x9AD7618C, 0x37A10C7A, 0x59F8148E, 0xEB133C89, 0xCEA927EE, 0xB761C935, 0xE11CE5ED, 0x7A47B13C,
|
492 |
+
0x9CD2DF59, 0x55F2733F, 0x1814CE79, 0x73C737BF, 0x53F7CDEA, 0x5FFDAA5B, 0xDF3D6F14, 0x7844DB86,
|
493 |
+
0xCAAFF381, 0xB968C43E, 0x3824342C, 0xC2A3405F, 0x161DC372, 0xBCE2250C, 0x283C498B, 0xFF0D9541,
|
494 |
+
0x39A80171, 0x080CB3DE, 0xD8B4E49C, 0x6456C190, 0x7BCB8461, 0xD532B670, 0x486C5C74, 0xD0B85742
|
495 |
+
);
|
496 |
+
|
497 |
+
/**
|
498 |
+
* Precomputed invMixColumns table
|
499 |
+
*
|
500 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
501 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
502 |
+
* @var Array
|
503 |
+
* @access private
|
504 |
+
*/
|
505 |
+
var $dt1 = array(
|
506 |
+
0x5051F4A7, 0x537E4165, 0xC31A17A4, 0x963A275E, 0xCB3BAB6B, 0xF11F9D45, 0xABACFA58, 0x934BE303,
|
507 |
+
0x552030FA, 0xF6AD766D, 0x9188CC76, 0x25F5024C, 0xFC4FE5D7, 0xD7C52ACB, 0x80263544, 0x8FB562A3,
|
508 |
+
0x49DEB15A, 0x6725BA1B, 0x9845EA0E, 0xE15DFEC0, 0x02C32F75, 0x12814CF0, 0xA38D4697, 0xC66BD3F9,
|
509 |
+
0xE7038F5F, 0x9515929C, 0xEBBF6D7A, 0xDA955259, 0x2DD4BE83, 0xD3587421, 0x2949E069, 0x448EC9C8,
|
510 |
+
0x6A75C289, 0x78F48E79, 0x6B99583E, 0xDD27B971, 0xB6BEE14F, 0x17F088AD, 0x66C920AC, 0xB47DCE3A,
|
511 |
+
0x1863DF4A, 0x82E51A31, 0x60975133, 0x4562537F, 0xE0B16477, 0x84BB6BAE, 0x1CFE81A0, 0x94F9082B,
|
512 |
+
0x58704868, 0x198F45FD, 0x8794DE6C, 0xB7527BF8, 0x23AB73D3, 0xE2724B02, 0x57E31F8F, 0x2A6655AB,
|
513 |
+
0x07B2EB28, 0x032FB5C2, 0x9A86C57B, 0xA5D33708, 0xF2302887, 0xB223BFA5, 0xBA02036A, 0x5CED1682,
|
514 |
+
0x2B8ACF1C, 0x92A779B4, 0xF0F307F2, 0xA14E69E2, 0xCD65DAF4, 0xD50605BE, 0x1FD13462, 0x8AC4A6FE,
|
515 |
+
0x9D342E53, 0xA0A2F355, 0x32058AE1, 0x75A4F6EB, 0x390B83EC, 0xAA4060EF, 0x065E719F, 0x51BD6E10,
|
516 |
+
0xF93E218A, 0x3D96DD06, 0xAEDD3E05, 0x464DE6BD, 0xB591548D, 0x0571C45D, 0x6F0406D4, 0xFF605015,
|
517 |
+
0x241998FB, 0x97D6BDE9, 0xCC894043, 0x7767D99E, 0xBDB0E842, 0x8807898B, 0x38E7195B, 0xDB79C8EE,
|
518 |
+
0x47A17C0A, 0xE97C420F, 0xC9F8841E, 0x00000000, 0x83098086, 0x48322BED, 0xAC1E1170, 0x4E6C5A72,
|
519 |
+
0xFBFD0EFF, 0x560F8538, 0x1E3DAED5, 0x27362D39, 0x640A0FD9, 0x21685CA6, 0xD19B5B54, 0x3A24362E,
|
520 |
+
0xB10C0A67, 0x0F9357E7, 0xD2B4EE96, 0x9E1B9B91, 0x4F80C0C5, 0xA261DC20, 0x695A774B, 0x161C121A,
|
521 |
+
0x0AE293BA, 0xE5C0A02A, 0x433C22E0, 0x1D121B17, 0x0B0E090D, 0xADF28BC7, 0xB92DB6A8, 0xC8141EA9,
|
522 |
+
0x8557F119, 0x4CAF7507, 0xBBEE99DD, 0xFDA37F60, 0x9FF70126, 0xBC5C72F5, 0xC544663B, 0x345BFB7E,
|
523 |
+
0x768B4329, 0xDCCB23C6, 0x68B6EDFC, 0x63B8E4F1, 0xCAD731DC, 0x10426385, 0x40139722, 0x2084C611,
|
524 |
+
0x7D854A24, 0xF8D2BB3D, 0x11AEF932, 0x6DC729A1, 0x4B1D9E2F, 0xF3DCB230, 0xEC0D8652, 0xD077C1E3,
|
525 |
+
0x6C2BB316, 0x99A970B9, 0xFA119448, 0x2247E964, 0xC4A8FC8C, 0x1AA0F03F, 0xD8567D2C, 0xEF223390,
|
526 |
+
0xC787494E, 0xC1D938D1, 0xFE8CCAA2, 0x3698D40B, 0xCFA6F581, 0x28A57ADE, 0x26DAB78E, 0xA43FADBF,
|
527 |
+
0xE42C3A9D, 0x0D507892, 0x9B6A5FCC, 0x62547E46, 0xC2F68D13, 0xE890D8B8, 0x5E2E39F7, 0xF582C3AF,
|
528 |
+
0xBE9F5D80, 0x7C69D093, 0xA96FD52D, 0xB3CF2512, 0x3BC8AC99, 0xA710187D, 0x6EE89C63, 0x7BDB3BBB,
|
529 |
+
0x09CD2678, 0xF46E5918, 0x01EC9AB7, 0xA8834F9A, 0x65E6956E, 0x7EAAFFE6, 0x0821BCCF, 0xE6EF15E8,
|
530 |
+
0xD9BAE79B, 0xCE4A6F36, 0xD4EA9F09, 0xD629B07C, 0xAF31A4B2, 0x312A3F23, 0x30C6A594, 0xC035A266,
|
531 |
+
0x37744EBC, 0xA6FC82CA, 0xB0E090D0, 0x1533A7D8, 0x4AF10498, 0xF741ECDA, 0x0E7FCD50, 0x2F1791F6,
|
532 |
+
0x8D764DD6, 0x4D43EFB0, 0x54CCAA4D, 0xDFE49604, 0xE39ED1B5, 0x1B4C6A88, 0xB8C12C1F, 0x7F466551,
|
533 |
+
0x049D5EEA, 0x5D018C35, 0x73FA8774, 0x2EFB0B41, 0x5AB3671D, 0x5292DBD2, 0x33E91056, 0x136DD647,
|
534 |
+
0x8C9AD761, 0x7A37A10C, 0x8E59F814, 0x89EB133C, 0xEECEA927, 0x35B761C9, 0xEDE11CE5, 0x3C7A47B1,
|
535 |
+
0x599CD2DF, 0x3F55F273, 0x791814CE, 0xBF73C737, 0xEA53F7CD, 0x5B5FFDAA, 0x14DF3D6F, 0x867844DB,
|
536 |
+
0x81CAAFF3, 0x3EB968C4, 0x2C382434, 0x5FC2A340, 0x72161DC3, 0x0CBCE225, 0x8B283C49, 0x41FF0D95,
|
537 |
+
0x7139A801, 0xDE080CB3, 0x9CD8B4E4, 0x906456C1, 0x617BCB84, 0x70D532B6, 0x74486C5C, 0x42D0B857
|
538 |
+
);
|
539 |
+
|
540 |
+
/**
|
541 |
+
* Precomputed invMixColumns table
|
542 |
+
*
|
543 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
544 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
545 |
+
* @var Array
|
546 |
+
* @access private
|
547 |
+
*/
|
548 |
+
var $dt2 = array(
|
549 |
+
0xA75051F4, 0x65537E41, 0xA4C31A17, 0x5E963A27, 0x6BCB3BAB, 0x45F11F9D, 0x58ABACFA, 0x03934BE3,
|
550 |
+
0xFA552030, 0x6DF6AD76, 0x769188CC, 0x4C25F502, 0xD7FC4FE5, 0xCBD7C52A, 0x44802635, 0xA38FB562,
|
551 |
+
0x5A49DEB1, 0x1B6725BA, 0x0E9845EA, 0xC0E15DFE, 0x7502C32F, 0xF012814C, 0x97A38D46, 0xF9C66BD3,
|
552 |
+
0x5FE7038F, 0x9C951592, 0x7AEBBF6D, 0x59DA9552, 0x832DD4BE, 0x21D35874, 0x692949E0, 0xC8448EC9,
|
553 |
+
0x896A75C2, 0x7978F48E, 0x3E6B9958, 0x71DD27B9, 0x4FB6BEE1, 0xAD17F088, 0xAC66C920, 0x3AB47DCE,
|
554 |
+
0x4A1863DF, 0x3182E51A, 0x33609751, 0x7F456253, 0x77E0B164, 0xAE84BB6B, 0xA01CFE81, 0x2B94F908,
|
555 |
+
0x68587048, 0xFD198F45, 0x6C8794DE, 0xF8B7527B, 0xD323AB73, 0x02E2724B, 0x8F57E31F, 0xAB2A6655,
|
556 |
+
0x2807B2EB, 0xC2032FB5, 0x7B9A86C5, 0x08A5D337, 0x87F23028, 0xA5B223BF, 0x6ABA0203, 0x825CED16,
|
557 |
+
0x1C2B8ACF, 0xB492A779, 0xF2F0F307, 0xE2A14E69, 0xF4CD65DA, 0xBED50605, 0x621FD134, 0xFE8AC4A6,
|
558 |
+
0x539D342E, 0x55A0A2F3, 0xE132058A, 0xEB75A4F6, 0xEC390B83, 0xEFAA4060, 0x9F065E71, 0x1051BD6E,
|
559 |
+
0x8AF93E21, 0x063D96DD, 0x05AEDD3E, 0xBD464DE6, 0x8DB59154, 0x5D0571C4, 0xD46F0406, 0x15FF6050,
|
560 |
+
0xFB241998, 0xE997D6BD, 0x43CC8940, 0x9E7767D9, 0x42BDB0E8, 0x8B880789, 0x5B38E719, 0xEEDB79C8,
|
561 |
+
0x0A47A17C, 0x0FE97C42, 0x1EC9F884, 0x00000000, 0x86830980, 0xED48322B, 0x70AC1E11, 0x724E6C5A,
|
562 |
+
0xFFFBFD0E, 0x38560F85, 0xD51E3DAE, 0x3927362D, 0xD9640A0F, 0xA621685C, 0x54D19B5B, 0x2E3A2436,
|
563 |
+
0x67B10C0A, 0xE70F9357, 0x96D2B4EE, 0x919E1B9B, 0xC54F80C0, 0x20A261DC, 0x4B695A77, 0x1A161C12,
|
564 |
+
0xBA0AE293, 0x2AE5C0A0, 0xE0433C22, 0x171D121B, 0x0D0B0E09, 0xC7ADF28B, 0xA8B92DB6, 0xA9C8141E,
|
565 |
+
0x198557F1, 0x074CAF75, 0xDDBBEE99, 0x60FDA37F, 0x269FF701, 0xF5BC5C72, 0x3BC54466, 0x7E345BFB,
|
566 |
+
0x29768B43, 0xC6DCCB23, 0xFC68B6ED, 0xF163B8E4, 0xDCCAD731, 0x85104263, 0x22401397, 0x112084C6,
|
567 |
+
0x247D854A, 0x3DF8D2BB, 0x3211AEF9, 0xA16DC729, 0x2F4B1D9E, 0x30F3DCB2, 0x52EC0D86, 0xE3D077C1,
|
568 |
+
0x166C2BB3, 0xB999A970, 0x48FA1194, 0x642247E9, 0x8CC4A8FC, 0x3F1AA0F0, 0x2CD8567D, 0x90EF2233,
|
569 |
+
0x4EC78749, 0xD1C1D938, 0xA2FE8CCA, 0x0B3698D4, 0x81CFA6F5, 0xDE28A57A, 0x8E26DAB7, 0xBFA43FAD,
|
570 |
+
0x9DE42C3A, 0x920D5078, 0xCC9B6A5F, 0x4662547E, 0x13C2F68D, 0xB8E890D8, 0xF75E2E39, 0xAFF582C3,
|
571 |
+
0x80BE9F5D, 0x937C69D0, 0x2DA96FD5, 0x12B3CF25, 0x993BC8AC, 0x7DA71018, 0x636EE89C, 0xBB7BDB3B,
|
572 |
+
0x7809CD26, 0x18F46E59, 0xB701EC9A, 0x9AA8834F, 0x6E65E695, 0xE67EAAFF, 0xCF0821BC, 0xE8E6EF15,
|
573 |
+
0x9BD9BAE7, 0x36CE4A6F, 0x09D4EA9F, 0x7CD629B0, 0xB2AF31A4, 0x23312A3F, 0x9430C6A5, 0x66C035A2,
|
574 |
+
0xBC37744E, 0xCAA6FC82, 0xD0B0E090, 0xD81533A7, 0x984AF104, 0xDAF741EC, 0x500E7FCD, 0xF62F1791,
|
575 |
+
0xD68D764D, 0xB04D43EF, 0x4D54CCAA, 0x04DFE496, 0xB5E39ED1, 0x881B4C6A, 0x1FB8C12C, 0x517F4665,
|
576 |
+
0xEA049D5E, 0x355D018C, 0x7473FA87, 0x412EFB0B, 0x1D5AB367, 0xD25292DB, 0x5633E910, 0x47136DD6,
|
577 |
+
0x618C9AD7, 0x0C7A37A1, 0x148E59F8, 0x3C89EB13, 0x27EECEA9, 0xC935B761, 0xE5EDE11C, 0xB13C7A47,
|
578 |
+
0xDF599CD2, 0x733F55F2, 0xCE791814, 0x37BF73C7, 0xCDEA53F7, 0xAA5B5FFD, 0x6F14DF3D, 0xDB867844,
|
579 |
+
0xF381CAAF, 0xC43EB968, 0x342C3824, 0x405FC2A3, 0xC372161D, 0x250CBCE2, 0x498B283C, 0x9541FF0D,
|
580 |
+
0x017139A8, 0xB3DE080C, 0xE49CD8B4, 0xC1906456, 0x84617BCB, 0xB670D532, 0x5C74486C, 0x5742D0B8
|
581 |
+
);
|
582 |
+
|
583 |
+
/**
|
584 |
+
* Precomputed invMixColumns table
|
585 |
+
*
|
586 |
+
* @see Crypt_Rijndael:_encryptBlock()
|
587 |
+
* @see Crypt_Rijndael:_decryptBlock()
|
588 |
+
* @var Array
|
589 |
+
* @access private
|
590 |
+
*/
|
591 |
+
var $dt3 = array(
|
592 |
+
0xF4A75051, 0x4165537E, 0x17A4C31A, 0x275E963A, 0xAB6BCB3B, 0x9D45F11F, 0xFA58ABAC, 0xE303934B,
|
593 |
+
0x30FA5520, 0x766DF6AD, 0xCC769188, 0x024C25F5, 0xE5D7FC4F, 0x2ACBD7C5, 0x35448026, 0x62A38FB5,
|
594 |
+
0xB15A49DE, 0xBA1B6725, 0xEA0E9845, 0xFEC0E15D, 0x2F7502C3, 0x4CF01281, 0x4697A38D, 0xD3F9C66B,
|
595 |
+
0x8F5FE703, 0x929C9515, 0x6D7AEBBF, 0x5259DA95, 0xBE832DD4, 0x7421D358, 0xE0692949, 0xC9C8448E,
|
596 |
+
0xC2896A75, 0x8E7978F4, 0x583E6B99, 0xB971DD27, 0xE14FB6BE, 0x88AD17F0, 0x20AC66C9, 0xCE3AB47D,
|
597 |
+
0xDF4A1863, 0x1A3182E5, 0x51336097, 0x537F4562, 0x6477E0B1, 0x6BAE84BB, 0x81A01CFE, 0x082B94F9,
|
598 |
+
0x48685870, 0x45FD198F, 0xDE6C8794, 0x7BF8B752, 0x73D323AB, 0x4B02E272, 0x1F8F57E3, 0x55AB2A66,
|
599 |
+
0xEB2807B2, 0xB5C2032F, 0xC57B9A86, 0x3708A5D3, 0x2887F230, 0xBFA5B223, 0x036ABA02, 0x16825CED,
|
600 |
+
0xCF1C2B8A, 0x79B492A7, 0x07F2F0F3, 0x69E2A14E, 0xDAF4CD65, 0x05BED506, 0x34621FD1, 0xA6FE8AC4,
|
601 |
+
0x2E539D34, 0xF355A0A2, 0x8AE13205, 0xF6EB75A4, 0x83EC390B, 0x60EFAA40, 0x719F065E, 0x6E1051BD,
|
602 |
+
0x218AF93E, 0xDD063D96, 0x3E05AEDD, 0xE6BD464D, 0x548DB591, 0xC45D0571, 0x06D46F04, 0x5015FF60,
|
603 |
+
0x98FB2419, 0xBDE997D6, 0x4043CC89, 0xD99E7767, 0xE842BDB0, 0x898B8807, 0x195B38E7, 0xC8EEDB79,
|
604 |
+
0x7C0A47A1, 0x420FE97C, 0x841EC9F8, 0x00000000, 0x80868309, 0x2BED4832, 0x1170AC1E, 0x5A724E6C,
|
605 |
+
0x0EFFFBFD, 0x8538560F, 0xAED51E3D, 0x2D392736, 0x0FD9640A, 0x5CA62168, 0x5B54D19B, 0x362E3A24,
|
606 |
+
0x0A67B10C, 0x57E70F93, 0xEE96D2B4, 0x9B919E1B, 0xC0C54F80, 0xDC20A261, 0x774B695A, 0x121A161C,
|
607 |
+
0x93BA0AE2, 0xA02AE5C0, 0x22E0433C, 0x1B171D12, 0x090D0B0E, 0x8BC7ADF2, 0xB6A8B92D, 0x1EA9C814,
|
608 |
+
0xF1198557, 0x75074CAF, 0x99DDBBEE, 0x7F60FDA3, 0x01269FF7, 0x72F5BC5C, 0x663BC544, 0xFB7E345B,
|
609 |
+
0x4329768B, 0x23C6DCCB, 0xEDFC68B6, 0xE4F163B8, 0x31DCCAD7, 0x63851042, 0x97224013, 0xC6112084,
|
610 |
+
0x4A247D85, 0xBB3DF8D2, 0xF93211AE, 0x29A16DC7, 0x9E2F4B1D, 0xB230F3DC, 0x8652EC0D, 0xC1E3D077,
|
611 |
+
0xB3166C2B, 0x70B999A9, 0x9448FA11, 0xE9642247, 0xFC8CC4A8, 0xF03F1AA0, 0x7D2CD856, 0x3390EF22,
|
612 |
+
0x494EC787, 0x38D1C1D9, 0xCAA2FE8C, 0xD40B3698, 0xF581CFA6, 0x7ADE28A5, 0xB78E26DA, 0xADBFA43F,
|
613 |
+
0x3A9DE42C, 0x78920D50, 0x5FCC9B6A, 0x7E466254, 0x8D13C2F6, 0xD8B8E890, 0x39F75E2E, 0xC3AFF582,
|
614 |
+
0x5D80BE9F, 0xD0937C69, 0xD52DA96F, 0x2512B3CF, 0xAC993BC8, 0x187DA710, 0x9C636EE8, 0x3BBB7BDB,
|
615 |
+
0x267809CD, 0x5918F46E, 0x9AB701EC, 0x4F9AA883, 0x956E65E6, 0xFFE67EAA, 0xBCCF0821, 0x15E8E6EF,
|
616 |
+
0xE79BD9BA, 0x6F36CE4A, 0x9F09D4EA, 0xB07CD629, 0xA4B2AF31, 0x3F23312A, 0xA59430C6, 0xA266C035,
|
617 |
+
0x4EBC3774, 0x82CAA6FC, 0x90D0B0E0, 0xA7D81533, 0x04984AF1, 0xECDAF741, 0xCD500E7F, 0x91F62F17,
|
618 |
+
0x4DD68D76, 0xEFB04D43, 0xAA4D54CC, 0x9604DFE4, 0xD1B5E39E, 0x6A881B4C, 0x2C1FB8C1, 0x65517F46,
|
619 |
+
0x5EEA049D, 0x8C355D01, 0x877473FA, 0x0B412EFB, 0x671D5AB3, 0xDBD25292, 0x105633E9, 0xD647136D,
|
620 |
+
0xD7618C9A, 0xA10C7A37, 0xF8148E59, 0x133C89EB, 0xA927EECE, 0x61C935B7, 0x1CE5EDE1, 0x47B13C7A,
|
621 |
+
0xD2DF599C, 0xF2733F55, 0x14CE7918, 0xC737BF73, 0xF7CDEA53, 0xFDAA5B5F, 0x3D6F14DF, 0x44DB8678,
|
622 |
+
0xAFF381CA, 0x68C43EB9, 0x24342C38, 0xA3405FC2, 0x1DC37216, 0xE2250CBC, 0x3C498B28, 0x0D9541FF,
|
623 |
+
0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0
|
624 |
+
);
|
625 |
+
|
626 |
+
/**
|
627 |
+
* The SubByte S-Box
|
628 |
+
*
|
629 |
+
* @see Crypt_Rijndael::_encryptBlock()
|
630 |
+
* @var Array
|
631 |
+
* @access private
|
632 |
+
*/
|
633 |
+
var $sbox = array(
|
634 |
+
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
|
635 |
+
0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
|
636 |
+
0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
|
637 |
+
0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
|
638 |
+
0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
|
639 |
+
0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
|
640 |
+
0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
|
641 |
+
0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
|
642 |
+
0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
|
643 |
+
0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
|
644 |
+
0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
|
645 |
+
0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
|
646 |
+
0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
|
647 |
+
0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
|
648 |
+
0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
|
649 |
+
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
|
650 |
+
);
|
651 |
+
|
652 |
+
/**
|
653 |
+
* The inverse SubByte S-Box
|
654 |
+
*
|
655 |
+
* @see Crypt_Rijndael::_decryptBlock()
|
656 |
+
* @var Array
|
657 |
+
* @access private
|
658 |
+
*/
|
659 |
+
var $isbox = array(
|
660 |
+
0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
|
661 |
+
0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
|
662 |
+
0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
|
663 |
+
0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
|
664 |
+
0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
|
665 |
+
0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
|
666 |
+
0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
|
667 |
+
0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
|
668 |
+
0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
|
669 |
+
0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
|
670 |
+
0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
|
671 |
+
0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
|
672 |
+
0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
|
673 |
+
0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
|
674 |
+
0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
|
675 |
+
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
|
676 |
+
);
|
677 |
+
|
678 |
+
/**
|
679 |
+
* Sets the key.
|
680 |
+
*
|
681 |
+
* Keys can be of any length. Rijndael, itself, requires the use of a key that's between 128-bits and 256-bits long and
|
682 |
+
* whose length is a multiple of 32. If the key is less than 256-bits and the key length isn't set, we round the length
|
683 |
+
* up to the closest valid key length, padding $key with null bytes. If the key is more than 256-bits, we trim the
|
684 |
+
* excess bits.
|
685 |
+
*
|
686 |
+
* If the key is not explicitly set, it'll be assumed to be all null bytes.
|
687 |
+
*
|
688 |
+
* Note: 160/224-bit keys must explicitly set by setKeyLength(), otherwise they will be round/pad up to 192/256 bits.
|
689 |
+
*
|
690 |
+
* @see Crypt_Base:setKey()
|
691 |
+
* @see setKeyLength()
|
692 |
+
* @access public
|
693 |
+
* @param String $key
|
694 |
+
*/
|
695 |
+
function setKey($key)
|
696 |
+
{
|
697 |
+
parent::setKey($key);
|
698 |
+
|
699 |
+
if (!$this->explicit_key_length) {
|
700 |
+
$length = strlen($key);
|
701 |
+
switch (true) {
|
702 |
+
case $length <= 16:
|
703 |
+
$this->key_size = 16;
|
704 |
+
break;
|
705 |
+
case $length <= 20:
|
706 |
+
$this->key_size = 20;
|
707 |
+
break;
|
708 |
+
case $length <= 24:
|
709 |
+
$this->key_size = 24;
|
710 |
+
break;
|
711 |
+
case $length <= 28:
|
712 |
+
$this->key_size = 28;
|
713 |
+
break;
|
714 |
+
default:
|
715 |
+
$this->key_size = 32;
|
716 |
+
}
|
717 |
+
$this->_setupEngine();
|
718 |
+
}
|
719 |
+
}
|
720 |
+
|
721 |
+
/**
|
722 |
+
* Sets the key length
|
723 |
+
*
|
724 |
+
* Valid key lengths are 128, 160, 192, 224, and 256. If the length is less than 128, it will be rounded up to
|
725 |
+
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
|
726 |
+
*
|
727 |
+
* Note: phpseclib extends Rijndael (and AES) for using 160- and 224-bit keys but they are officially not defined
|
728 |
+
* and the most (if not all) implementations are not able using 160/224-bit keys but round/pad them up to
|
729 |
+
* 192/256 bits as, for example, mcrypt will do.
|
730 |
+
*
|
731 |
+
* That said, if you want be compatible with other Rijndael and AES implementations,
|
732 |
+
* you should not setKeyLength(160) or setKeyLength(224).
|
733 |
+
*
|
734 |
+
* Additional: In case of 160- and 224-bit keys, phpseclib will/can, for that reason, not use
|
735 |
+
* the mcrypt php extension, even if available.
|
736 |
+
* This results then in slower encryption.
|
737 |
+
*
|
738 |
+
* @access public
|
739 |
+
* @param Integer $length
|
740 |
+
*/
|
741 |
+
function setKeyLength($length)
|
742 |
+
{
|
743 |
+
switch (true) {
|
744 |
+
case $length == 160:
|
745 |
+
$this->key_size = 20;
|
746 |
+
break;
|
747 |
+
case $length == 224:
|
748 |
+
$this->key_size = 28;
|
749 |
+
break;
|
750 |
+
case $length <= 128:
|
751 |
+
$this->key_size = 16;
|
752 |
+
break;
|
753 |
+
case $length <= 192:
|
754 |
+
$this->key_size = 24;
|
755 |
+
break;
|
756 |
+
default:
|
757 |
+
$this->key_size = 32;
|
758 |
+
}
|
759 |
+
|
760 |
+
$this->explicit_key_length = true;
|
761 |
+
$this->changed = true;
|
762 |
+
$this->_setupEngine();
|
763 |
+
}
|
764 |
+
|
765 |
+
/**
|
766 |
+
* Sets the block length
|
767 |
+
*
|
768 |
+
* Valid block lengths are 128, 160, 192, 224, and 256. If the length is less than 128, it will be rounded up to
|
769 |
+
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
|
770 |
+
*
|
771 |
+
* @access public
|
772 |
+
* @param Integer $length
|
773 |
+
*/
|
774 |
+
function setBlockLength($length)
|
775 |
+
{
|
776 |
+
$length >>= 5;
|
777 |
+
if ($length > 8) {
|
778 |
+
$length = 8;
|
779 |
+
} else if ($length < 4) {
|
780 |
+
$length = 4;
|
781 |
+
}
|
782 |
+
$this->Nb = $length;
|
783 |
+
$this->block_size = $length << 2;
|
784 |
+
$this->changed = true;
|
785 |
+
$this->_setupEngine();
|
786 |
+
}
|
787 |
+
|
788 |
+
/**
|
789 |
+
* Setup the fastest possible $engine
|
790 |
+
*
|
791 |
+
* Determines if the mcrypt (MODE_MCRYPT) $engine available
|
792 |
+
* and usable for the current $block_size and $key_size.
|
793 |
+
*
|
794 |
+
* If not, the slower MODE_INTERNAL $engine will be set.
|
795 |
+
*
|
796 |
+
* @see setKey()
|
797 |
+
* @see setKeyLength()
|
798 |
+
* @see setBlockLength()
|
799 |
+
* @access private
|
800 |
+
*/
|
801 |
+
function _setupEngine()
|
802 |
+
{
|
803 |
+
if (constant('CRYPT_' . $this->const_namespace . '_MODE') == CRYPT_MODE_INTERNAL) {
|
804 |
+
// No mcrypt support at all for rijndael
|
805 |
+
return;
|
806 |
+
}
|
807 |
+
|
808 |
+
// The required mcrypt module name for the current $block_size of rijndael
|
809 |
+
$cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3);
|
810 |
+
|
811 |
+
// Determining the availibility/usability of $cipher_name_mcrypt
|
812 |
+
switch (true) {
|
813 |
+
case $this->key_size % 8: // mcrypt is not usable for 160/224-bit keys, only for 128/192/256-bit keys
|
814 |
+
case !in_array($cipher_name_mcrypt, mcrypt_list_algorithms()): // $cipher_name_mcrypt is not available for the current $block_size
|
815 |
+
$engine = CRYPT_MODE_INTERNAL;
|
816 |
+
break;
|
817 |
+
default:
|
818 |
+
$engine = CRYPT_MODE_MCRYPT;
|
819 |
+
}
|
820 |
+
|
821 |
+
if ($this->engine == $engine && $this->cipher_name_mcrypt == $cipher_name_mcrypt) {
|
822 |
+
// allready set, so we not unnecessary close $this->enmcrypt/demcrypt/ecb
|
823 |
+
return;
|
824 |
+
}
|
825 |
+
|
826 |
+
// Set the $engine
|
827 |
+
$this->engine = $engine;
|
828 |
+
$this->cipher_name_mcrypt = $cipher_name_mcrypt;
|
829 |
+
|
830 |
+
if ($this->enmcrypt) {
|
831 |
+
// Closing the current mcrypt resource(s). _mcryptSetup() will, if needed,
|
832 |
+
// (re)open them with the module named in $this->cipher_name_mcrypt
|
833 |
+
mcrypt_module_close($this->enmcrypt);
|
834 |
+
mcrypt_module_close($this->demcrypt);
|
835 |
+
$this->enmcrypt = null;
|
836 |
+
$this->demcrypt = null;
|
837 |
+
|
838 |
+
if ($this->ecb) {
|
839 |
+
mcrypt_module_close($this->ecb);
|
840 |
+
$this->ecb = null;
|
841 |
+
}
|
842 |
+
}
|
843 |
+
}
|
844 |
+
|
845 |
+
/**
|
846 |
+
* Setup the CRYPT_MODE_MCRYPT $engine
|
847 |
+
*
|
848 |
+
* @see Crypt_Base::_setupMcrypt()
|
849 |
+
* @access private
|
850 |
+
*/
|
851 |
+
function _setupMcrypt()
|
852 |
+
{
|
853 |
+
$this->key = str_pad(substr($this->key, 0, $this->key_size), $this->key_size, "\0");
|
854 |
+
parent::_setupMcrypt();
|
855 |
+
}
|
856 |
+
|
857 |
+
/**
|
858 |
+
* Encrypts a block
|
859 |
+
*
|
860 |
+
* @access private
|
861 |
+
* @param String $in
|
862 |
+
* @return String
|
863 |
+
*/
|
864 |
+
function _encryptBlock($in)
|
865 |
+
{
|
866 |
+
static $t0, $t1, $t2, $t3, $sbox;
|
867 |
+
if (!$t0) {
|
868 |
+
for ($i = 0; $i < 256; ++$i) {
|
869 |
+
$t0[] = (int)$this->t0[$i];
|
870 |
+
$t1[] = (int)$this->t1[$i];
|
871 |
+
$t2[] = (int)$this->t2[$i];
|
872 |
+
$t3[] = (int)$this->t3[$i];
|
873 |
+
$sbox[] = (int)$this->sbox[$i];
|
874 |
+
}
|
875 |
+
}
|
876 |
+
|
877 |
+
$state = array();
|
878 |
+
$words = unpack('N*', $in);
|
879 |
+
|
880 |
+
$c = $this->c;
|
881 |
+
$w = $this->w;
|
882 |
+
$Nb = $this->Nb;
|
883 |
+
$Nr = $this->Nr;
|
884 |
+
|
885 |
+
// addRoundKey
|
886 |
+
$i = -1;
|
887 |
+
foreach ($words as $word) {
|
888 |
+
$state[] = $word ^ $w[0][++$i];
|
889 |
+
}
|
890 |
+
|
891 |
+
// fips-197.pdf#page=19, "Figure 5. Pseudo Code for the Cipher", states that this loop has four components -
|
892 |
+
// subBytes, shiftRows, mixColumns, and addRoundKey. fips-197.pdf#page=30, "Implementation Suggestions Regarding
|
893 |
+
// Various Platforms" suggests that performs enhanced implementations are described in Rijndael-ammended.pdf.
|
894 |
+
// Rijndael-ammended.pdf#page=20, "Implementation aspects / 32-bit processor", discusses such an optimization.
|
895 |
+
// Unfortunately, the description given there is not quite correct. Per aes.spec.v316.pdf#page=19 [1],
|
896 |
+
// equation (7.4.7) is supposed to use addition instead of subtraction, so we'll do that here, as well.
|
897 |
+
|
898 |
+
// [1] http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.v316.pdf
|
899 |
+
$temp = array();
|
900 |
+
for ($round = 1; $round < $Nr; ++$round) {
|
901 |
+
$i = 0; // $c[0] == 0
|
902 |
+
$j = $c[1];
|
903 |
+
$k = $c[2];
|
904 |
+
$l = $c[3];
|
905 |
+
|
906 |
+
while ($i < $Nb) {
|
907 |
+
$temp[$i] = $t0[$state[$i] >> 24 & 0x000000FF] ^
|
908 |
+
$t1[$state[$j] >> 16 & 0x000000FF] ^
|
909 |
+
$t2[$state[$k] >> 8 & 0x000000FF] ^
|
910 |
+
$t3[$state[$l] & 0x000000FF] ^
|
911 |
+
$w[$round][$i];
|
912 |
+
++$i;
|
913 |
+
$j = ($j + 1) % $Nb;
|
914 |
+
$k = ($k + 1) % $Nb;
|
915 |
+
$l = ($l + 1) % $Nb;
|
916 |
+
}
|
917 |
+
$state = $temp;
|
918 |
+
}
|
919 |
+
|
920 |
+
// subWord
|
921 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
922 |
+
$state[$i] = $sbox[$state[$i] & 0x000000FF] |
|
923 |
+
($sbox[$state[$i] >> 8 & 0x000000FF] << 8) |
|
924 |
+
($sbox[$state[$i] >> 16 & 0x000000FF] << 16) |
|
925 |
+
($sbox[$state[$i] >> 24 & 0x000000FF] << 24);
|
926 |
+
}
|
927 |
+
|
928 |
+
// shiftRows + addRoundKey
|
929 |
+
$i = 0; // $c[0] == 0
|
930 |
+
$j = $c[1];
|
931 |
+
$k = $c[2];
|
932 |
+
$l = $c[3];
|
933 |
+
while ($i < $Nb) {
|
934 |
+
$temp[$i] = ($state[$i] & 0xFF000000) ^
|
935 |
+
($state[$j] & 0x00FF0000) ^
|
936 |
+
($state[$k] & 0x0000FF00) ^
|
937 |
+
($state[$l] & 0x000000FF) ^
|
938 |
+
$w[$Nr][$i];
|
939 |
+
++$i;
|
940 |
+
$j = ($j + 1) % $Nb;
|
941 |
+
$k = ($k + 1) % $Nb;
|
942 |
+
$l = ($l + 1) % $Nb;
|
943 |
+
}
|
944 |
+
|
945 |
+
switch ($Nb) {
|
946 |
+
case 8:
|
947 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6], $temp[7]);
|
948 |
+
case 7:
|
949 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6]);
|
950 |
+
case 6:
|
951 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5]);
|
952 |
+
case 5:
|
953 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4]);
|
954 |
+
default:
|
955 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3]);
|
956 |
+
}
|
957 |
+
}
|
958 |
+
|
959 |
+
/**
|
960 |
+
* Decrypts a block
|
961 |
+
*
|
962 |
+
* @access private
|
963 |
+
* @param String $in
|
964 |
+
* @return String
|
965 |
+
*/
|
966 |
+
function _decryptBlock($in)
|
967 |
+
{
|
968 |
+
static $dt0, $dt1, $dt2, $dt3, $isbox;
|
969 |
+
if (!$dt0) {
|
970 |
+
for ($i = 0; $i < 256; ++$i) {
|
971 |
+
$dt0[] = (int)$this->dt0[$i];
|
972 |
+
$dt1[] = (int)$this->dt1[$i];
|
973 |
+
$dt2[] = (int)$this->dt2[$i];
|
974 |
+
$dt3[] = (int)$this->dt3[$i];
|
975 |
+
$isbox[] = (int)$this->isbox[$i];
|
976 |
+
}
|
977 |
+
}
|
978 |
+
|
979 |
+
$state = array();
|
980 |
+
$words = unpack('N*', $in);
|
981 |
+
|
982 |
+
$c = $this->c;
|
983 |
+
$dw = $this->dw;
|
984 |
+
$Nb = $this->Nb;
|
985 |
+
$Nr = $this->Nr;
|
986 |
+
|
987 |
+
// addRoundKey
|
988 |
+
$i = -1;
|
989 |
+
foreach ($words as $word) {
|
990 |
+
$state[] = $word ^ $dw[$Nr][++$i];
|
991 |
+
}
|
992 |
+
|
993 |
+
$temp = array();
|
994 |
+
for ($round = $Nr - 1; $round > 0; --$round) {
|
995 |
+
$i = 0; // $c[0] == 0
|
996 |
+
$j = $Nb - $c[1];
|
997 |
+
$k = $Nb - $c[2];
|
998 |
+
$l = $Nb - $c[3];
|
999 |
+
|
1000 |
+
while ($i < $Nb) {
|
1001 |
+
$temp[$i] = $dt0[$state[$i] >> 24 & 0x000000FF] ^
|
1002 |
+
$dt1[$state[$j] >> 16 & 0x000000FF] ^
|
1003 |
+
$dt2[$state[$k] >> 8 & 0x000000FF] ^
|
1004 |
+
$dt3[$state[$l] & 0x000000FF] ^
|
1005 |
+
$dw[$round][$i];
|
1006 |
+
++$i;
|
1007 |
+
$j = ($j + 1) % $Nb;
|
1008 |
+
$k = ($k + 1) % $Nb;
|
1009 |
+
$l = ($l + 1) % $Nb;
|
1010 |
+
}
|
1011 |
+
$state = $temp;
|
1012 |
+
}
|
1013 |
+
|
1014 |
+
// invShiftRows + invSubWord + addRoundKey
|
1015 |
+
$i = 0; // $c[0] == 0
|
1016 |
+
$j = $Nb - $c[1];
|
1017 |
+
$k = $Nb - $c[2];
|
1018 |
+
$l = $Nb - $c[3];
|
1019 |
+
|
1020 |
+
while ($i < $Nb) {
|
1021 |
+
$word = ($state[$i] & 0xFF000000) |
|
1022 |
+
($state[$j] & 0x00FF0000) |
|
1023 |
+
($state[$k] & 0x0000FF00) |
|
1024 |
+
($state[$l] & 0x000000FF);
|
1025 |
+
|
1026 |
+
$temp[$i] = $dw[0][$i] ^ ($isbox[$word & 0x000000FF] |
|
1027 |
+
($isbox[$word >> 8 & 0x000000FF] << 8) |
|
1028 |
+
($isbox[$word >> 16 & 0x000000FF] << 16) |
|
1029 |
+
($isbox[$word >> 24 & 0x000000FF] << 24));
|
1030 |
+
++$i;
|
1031 |
+
$j = ($j + 1) % $Nb;
|
1032 |
+
$k = ($k + 1) % $Nb;
|
1033 |
+
$l = ($l + 1) % $Nb;
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
switch ($Nb) {
|
1037 |
+
case 8:
|
1038 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6], $temp[7]);
|
1039 |
+
case 7:
|
1040 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6]);
|
1041 |
+
case 6:
|
1042 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5]);
|
1043 |
+
case 5:
|
1044 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4]);
|
1045 |
+
default:
|
1046 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3]);
|
1047 |
+
}
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
/**
|
1051 |
+
* Setup the key (expansion)
|
1052 |
+
*
|
1053 |
+
* @see Crypt_Base::_setupKey()
|
1054 |
+
* @access private
|
1055 |
+
*/
|
1056 |
+
function _setupKey()
|
1057 |
+
{
|
1058 |
+
// Each number in $rcon is equal to the previous number multiplied by two in Rijndael's finite field.
|
1059 |
+
// See http://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplicative_inverse
|
1060 |
+
static $rcon = array(0,
|
1061 |
+
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
|
1062 |
+
0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
|
1063 |
+
0x6C000000, 0xD8000000, 0xAB000000, 0x4D000000, 0x9A000000,
|
1064 |
+
0x2F000000, 0x5E000000, 0xBC000000, 0x63000000, 0xC6000000,
|
1065 |
+
0x97000000, 0x35000000, 0x6A000000, 0xD4000000, 0xB3000000,
|
1066 |
+
0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000
|
1067 |
+
);
|
1068 |
+
|
1069 |
+
$this->key = str_pad(substr($this->key, 0, $this->key_size), $this->key_size, "\0");
|
1070 |
+
|
1071 |
+
if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_size === $this->kl['key_size'] && $this->block_size === $this->kl['block_size']) {
|
1072 |
+
// already expanded
|
1073 |
+
return;
|
1074 |
+
}
|
1075 |
+
$this->kl = array('key' => $this->key, 'key_size' => $this->key_size, 'block_size' => $this->block_size);
|
1076 |
+
|
1077 |
+
$this->Nk = $this->key_size >> 2;
|
1078 |
+
// see Rijndael-ammended.pdf#page=44
|
1079 |
+
$this->Nr = max($this->Nk, $this->Nb) + 6;
|
1080 |
+
|
1081 |
+
// shift offsets for Nb = 5, 7 are defined in Rijndael-ammended.pdf#page=44,
|
1082 |
+
// "Table 8: Shift offsets in Shiftrow for the alternative block lengths"
|
1083 |
+
// shift offsets for Nb = 4, 6, 8 are defined in Rijndael-ammended.pdf#page=14,
|
1084 |
+
// "Table 2: Shift offsets for different block lengths"
|
1085 |
+
switch ($this->Nb) {
|
1086 |
+
case 4:
|
1087 |
+
case 5:
|
1088 |
+
case 6:
|
1089 |
+
$this->c = array(0, 1, 2, 3);
|
1090 |
+
break;
|
1091 |
+
case 7:
|
1092 |
+
$this->c = array(0, 1, 2, 4);
|
1093 |
+
break;
|
1094 |
+
case 8:
|
1095 |
+
$this->c = array(0, 1, 3, 4);
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
$w = array_values(unpack('N*words', $this->key));
|
1099 |
+
|
1100 |
+
$length = $this->Nb * ($this->Nr + 1);
|
1101 |
+
for ($i = $this->Nk; $i < $length; $i++) {
|
1102 |
+
$temp = $w[$i - 1];
|
1103 |
+
if ($i % $this->Nk == 0) {
|
1104 |
+
// according to <http://php.net/language.types.integer>, "the size of an integer is platform-dependent".
|
1105 |
+
// on a 32-bit machine, it's 32-bits, and on a 64-bit machine, it's 64-bits. on a 32-bit machine,
|
1106 |
+
// 0xFFFFFFFF << 8 == 0xFFFFFF00, but on a 64-bit machine, it equals 0xFFFFFFFF00. as such, doing 'and'
|
1107 |
+
// with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is.
|
1108 |
+
$temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord
|
1109 |
+
$temp = $this->_subWord($temp) ^ $rcon[$i / $this->Nk];
|
1110 |
+
} else if ($this->Nk > 6 && $i % $this->Nk == 4) {
|
1111 |
+
$temp = $this->_subWord($temp);
|
1112 |
+
}
|
1113 |
+
$w[$i] = $w[$i - $this->Nk] ^ $temp;
|
1114 |
+
}
|
1115 |
+
|
1116 |
+
// convert the key schedule from a vector of $Nb * ($Nr + 1) length to a matrix with $Nr + 1 rows and $Nb columns
|
1117 |
+
// and generate the inverse key schedule. more specifically,
|
1118 |
+
// according to <http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=23> (section 5.3.3),
|
1119 |
+
// "The key expansion for the Inverse Cipher is defined as follows:
|
1120 |
+
// 1. Apply the Key Expansion.
|
1121 |
+
// 2. Apply InvMixColumn to all Round Keys except the first and the last one."
|
1122 |
+
// also, see fips-197.pdf#page=27, "5.3.5 Equivalent Inverse Cipher"
|
1123 |
+
$temp = $this->w = $this->dw = array();
|
1124 |
+
for ($i = $row = $col = 0; $i < $length; $i++, $col++) {
|
1125 |
+
if ($col == $this->Nb) {
|
1126 |
+
if ($row == 0) {
|
1127 |
+
$this->dw[0] = $this->w[0];
|
1128 |
+
} else {
|
1129 |
+
// subWord + invMixColumn + invSubWord = invMixColumn
|
1130 |
+
$j = 0;
|
1131 |
+
while ($j < $this->Nb) {
|
1132 |
+
$dw = $this->_subWord($this->w[$row][$j]);
|
1133 |
+
$temp[$j] = $this->dt0[$dw >> 24 & 0x000000FF] ^
|
1134 |
+
$this->dt1[$dw >> 16 & 0x000000FF] ^
|
1135 |
+
$this->dt2[$dw >> 8 & 0x000000FF] ^
|
1136 |
+
$this->dt3[$dw & 0x000000FF];
|
1137 |
+
$j++;
|
1138 |
+
}
|
1139 |
+
$this->dw[$row] = $temp;
|
1140 |
+
}
|
1141 |
+
|
1142 |
+
$col = 0;
|
1143 |
+
$row++;
|
1144 |
+
}
|
1145 |
+
$this->w[$row][$col] = $w[$i];
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
$this->dw[$row] = $this->w[$row];
|
1149 |
+
|
1150 |
+
// In case of $this->use_inline_crypt === true we have to use 1-dim key arrays (both ascending)
|
1151 |
+
if ($this->use_inline_crypt) {
|
1152 |
+
$this->dw = array_reverse($this->dw);
|
1153 |
+
$w = array_pop($this->w);
|
1154 |
+
$dw = array_pop($this->dw);
|
1155 |
+
foreach ($this->w as $r => $wr) {
|
1156 |
+
foreach ($wr as $c => $wc) {
|
1157 |
+
$w[] = $wc;
|
1158 |
+
$dw[] = $this->dw[$r][$c];
|
1159 |
+
}
|
1160 |
+
}
|
1161 |
+
$this->w = $w;
|
1162 |
+
$this->dw = $dw;
|
1163 |
+
}
|
1164 |
+
}
|
1165 |
+
|
1166 |
+
/**
|
1167 |
+
* Performs S-Box substitutions
|
1168 |
+
*
|
1169 |
+
* @access private
|
1170 |
+
* @param Integer $word
|
1171 |
+
*/
|
1172 |
+
function _subWord($word)
|
1173 |
+
{
|
1174 |
+
$sbox = $this->sbox;
|
1175 |
+
|
1176 |
+
return $sbox[$word & 0x000000FF] |
|
1177 |
+
($sbox[$word >> 8 & 0x000000FF] << 8) |
|
1178 |
+
($sbox[$word >> 16 & 0x000000FF] << 16) |
|
1179 |
+
($sbox[$word >> 24 & 0x000000FF] << 24);
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
/**
|
1183 |
+
* Setup the performance-optimized function for de/encrypt()
|
1184 |
+
*
|
1185 |
+
* @see Crypt_Base::_setupInlineCrypt()
|
1186 |
+
* @access private
|
1187 |
+
*/
|
1188 |
+
function _setupInlineCrypt()
|
1189 |
+
{
|
1190 |
+
// Note: _setupInlineCrypt() will be called only if $this->changed === true
|
1191 |
+
// So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt().
|
1192 |
+
// However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible.
|
1193 |
+
|
1194 |
+
$lambda_functions =& Crypt_Rijndael::_getLambdaFunctions();
|
1195 |
+
|
1196 |
+
// The first 10 generated $lambda_functions will use the key-words hardcoded for better performance.
|
1197 |
+
// For memory reason we limit those ultra-optimized functions.
|
1198 |
+
// After that, we use pure (extracted) integer vars for the key-words which is faster than accessing them via array.
|
1199 |
+
if (count($lambda_functions) < 10) {
|
1200 |
+
$w = $this->w;
|
1201 |
+
$dw = $this->dw;
|
1202 |
+
$init_encrypt = '';
|
1203 |
+
$init_decrypt = '';
|
1204 |
+
} else {
|
1205 |
+
for ($i = 0, $cw = count($this->w); $i < $cw; ++$i) {
|
1206 |
+
$w[] = '$w[' . $i . ']';
|
1207 |
+
$dw[] = '$dw[' . $i . ']';
|
1208 |
+
}
|
1209 |
+
$init_encrypt = '$w = $self->w;';
|
1210 |
+
$init_decrypt = '$dw = $self->dw;';
|
1211 |
+
}
|
1212 |
+
|
1213 |
+
$code_hash = md5(str_pad("Crypt_Rijndael, {$this->mode}, {$this->block_size}, ", 32, "\0") . implode(',', $w));
|
1214 |
+
|
1215 |
+
if (!isset($lambda_functions[$code_hash])) {
|
1216 |
+
$Nr = $this->Nr;
|
1217 |
+
$Nb = $this->Nb;
|
1218 |
+
$c = $this->c;
|
1219 |
+
|
1220 |
+
// Generating encrypt code:
|
1221 |
+
$init_encrypt.= '
|
1222 |
+
static $t0, $t1, $t2, $t3, $sbox;
|
1223 |
+
if (!$t0) {
|
1224 |
+
for ($i = 0; $i < 256; ++$i) {
|
1225 |
+
$t0[$i] = (int)$self->t0[$i];
|
1226 |
+
$t1[$i] = (int)$self->t1[$i];
|
1227 |
+
$t2[$i] = (int)$self->t2[$i];
|
1228 |
+
$t3[$i] = (int)$self->t3[$i];
|
1229 |
+
$sbox[$i] = (int)$self->sbox[$i];
|
1230 |
+
}
|
1231 |
+
}
|
1232 |
+
';
|
1233 |
+
|
1234 |
+
$s = 'e';
|
1235 |
+
$e = 's';
|
1236 |
+
$wc = $Nb - 1;
|
1237 |
+
|
1238 |
+
// Preround: addRoundKey
|
1239 |
+
$encrypt_block = '$in = unpack("N*", $in);'."\n";
|
1240 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1241 |
+
$encrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$w[++$wc].";\n";
|
1242 |
+
}
|
1243 |
+
|
1244 |
+
// Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
|
1245 |
+
for ($round = 1; $round < $Nr; ++$round) {
|
1246 |
+
list($s, $e) = array($e, $s);
|
1247 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1248 |
+
$encrypt_block.=
|
1249 |
+
'$'.$e.$i.' =
|
1250 |
+
$t0[($'.$s.$i .' >> 24) & 0xff] ^
|
1251 |
+
$t1[($'.$s.(($i + $c[1]) % $Nb).' >> 16) & 0xff] ^
|
1252 |
+
$t2[($'.$s.(($i + $c[2]) % $Nb).' >> 8) & 0xff] ^
|
1253 |
+
$t3[ $'.$s.(($i + $c[3]) % $Nb).' & 0xff] ^
|
1254 |
+
'.$w[++$wc].";\n";
|
1255 |
+
}
|
1256 |
+
}
|
1257 |
+
|
1258 |
+
// Finalround: subWord + shiftRows + addRoundKey
|
1259 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1260 |
+
$encrypt_block.=
|
1261 |
+
'$'.$e.$i.' =
|
1262 |
+
$sbox[ $'.$e.$i.' & 0xff] |
|
1263 |
+
($sbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
|
1264 |
+
($sbox[($'.$e.$i.' >> 16) & 0xff] << 16) |
|
1265 |
+
($sbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n";
|
1266 |
+
}
|
1267 |
+
$encrypt_block .= '$in = pack("N*"'."\n";
|
1268 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1269 |
+
$encrypt_block.= ',
|
1270 |
+
($'.$e.$i .' & 0xFF000000) ^
|
1271 |
+
($'.$e.(($i + $c[1]) % $Nb).' & 0x00FF0000) ^
|
1272 |
+
($'.$e.(($i + $c[2]) % $Nb).' & 0x0000FF00) ^
|
1273 |
+
($'.$e.(($i + $c[3]) % $Nb).' & 0x000000FF) ^
|
1274 |
+
'.$w[$i]."\n";
|
1275 |
+
}
|
1276 |
+
$encrypt_block .= ');';
|
1277 |
+
|
1278 |
+
// Generating decrypt code:
|
1279 |
+
$init_decrypt.= '
|
1280 |
+
static $dt0, $dt1, $dt2, $dt3, $isbox;
|
1281 |
+
if (!$dt0) {
|
1282 |
+
for ($i = 0; $i < 256; ++$i) {
|
1283 |
+
$dt0[$i] = (int)$self->dt0[$i];
|
1284 |
+
$dt1[$i] = (int)$self->dt1[$i];
|
1285 |
+
$dt2[$i] = (int)$self->dt2[$i];
|
1286 |
+
$dt3[$i] = (int)$self->dt3[$i];
|
1287 |
+
$isbox[$i] = (int)$self->isbox[$i];
|
1288 |
+
}
|
1289 |
+
}
|
1290 |
+
';
|
1291 |
+
|
1292 |
+
$s = 'e';
|
1293 |
+
$e = 's';
|
1294 |
+
$wc = $Nb - 1;
|
1295 |
+
|
1296 |
+
// Preround: addRoundKey
|
1297 |
+
$decrypt_block = '$in = unpack("N*", $in);'."\n";
|
1298 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1299 |
+
$decrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$dw[++$wc].';'."\n";
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
// Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
|
1303 |
+
for ($round = 1; $round < $Nr; ++$round) {
|
1304 |
+
list($s, $e) = array($e, $s);
|
1305 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1306 |
+
$decrypt_block.=
|
1307 |
+
'$'.$e.$i.' =
|
1308 |
+
$dt0[($'.$s.$i .' >> 24) & 0xff] ^
|
1309 |
+
$dt1[($'.$s.(($Nb + $i - $c[1]) % $Nb).' >> 16) & 0xff] ^
|
1310 |
+
$dt2[($'.$s.(($Nb + $i - $c[2]) % $Nb).' >> 8) & 0xff] ^
|
1311 |
+
$dt3[ $'.$s.(($Nb + $i - $c[3]) % $Nb).' & 0xff] ^
|
1312 |
+
'.$dw[++$wc].";\n";
|
1313 |
+
}
|
1314 |
+
}
|
1315 |
+
|
1316 |
+
// Finalround: subWord + shiftRows + addRoundKey
|
1317 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1318 |
+
$decrypt_block.=
|
1319 |
+
'$'.$e.$i.' =
|
1320 |
+
$isbox[ $'.$e.$i.' & 0xff] |
|
1321 |
+
($isbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
|
1322 |
+
($isbox[($'.$e.$i.' >> 16) & 0xff] << 16) |
|
1323 |
+
($isbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n";
|
1324 |
+
}
|
1325 |
+
$decrypt_block .= '$in = pack("N*"'."\n";
|
1326 |
+
for ($i = 0; $i < $Nb; ++$i) {
|
1327 |
+
$decrypt_block.= ',
|
1328 |
+
($'.$e.$i. ' & 0xFF000000) ^
|
1329 |
+
($'.$e.(($Nb + $i - $c[1]) % $Nb).' & 0x00FF0000) ^
|
1330 |
+
($'.$e.(($Nb + $i - $c[2]) % $Nb).' & 0x0000FF00) ^
|
1331 |
+
($'.$e.(($Nb + $i - $c[3]) % $Nb).' & 0x000000FF) ^
|
1332 |
+
'.$dw[$i]."\n";
|
1333 |
+
}
|
1334 |
+
$decrypt_block .= ');';
|
1335 |
+
|
1336 |
+
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
|
1337 |
+
array(
|
1338 |
+
'init_crypt' => '',
|
1339 |
+
'init_encrypt' => $init_encrypt,
|
1340 |
+
'init_decrypt' => $init_decrypt,
|
1341 |
+
'encrypt_block' => $encrypt_block,
|
1342 |
+
'decrypt_block' => $decrypt_block
|
1343 |
+
)
|
1344 |
+
);
|
1345 |
+
}
|
1346 |
+
$this->inline_crypt = $lambda_functions[$code_hash];
|
1347 |
+
}
|
1348 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/TripleDES.php
ADDED
@@ -0,0 +1,428 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of Triple DES.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise. Operates in the EDE3 mode (encrypt-decrypt-encrypt).
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* Here's a short example of how to use this library:
|
11 |
+
* <code>
|
12 |
+
* <?php
|
13 |
+
* include 'Crypt/TripleDES.php';
|
14 |
+
*
|
15 |
+
* $des = new Crypt_TripleDES();
|
16 |
+
*
|
17 |
+
* $des->setKey('abcdefghijklmnopqrstuvwx');
|
18 |
+
*
|
19 |
+
* $size = 10 * 1024;
|
20 |
+
* $plaintext = '';
|
21 |
+
* for ($i = 0; $i < $size; $i++) {
|
22 |
+
* $plaintext.= 'a';
|
23 |
+
* }
|
24 |
+
*
|
25 |
+
* echo $des->decrypt($des->encrypt($plaintext));
|
26 |
+
* ?>
|
27 |
+
* </code>
|
28 |
+
*
|
29 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
30 |
+
* of this software and associated documentation files (the "Software"), to deal
|
31 |
+
* in the Software without restriction, including without limitation the rights
|
32 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
33 |
+
* copies of the Software, and to permit persons to whom the Software is
|
34 |
+
* furnished to do so, subject to the following conditions:
|
35 |
+
*
|
36 |
+
* The above copyright notice and this permission notice shall be included in
|
37 |
+
* all copies or substantial portions of the Software.
|
38 |
+
*
|
39 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
40 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
41 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
42 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
43 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
44 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
45 |
+
* THE SOFTWARE.
|
46 |
+
*
|
47 |
+
* @category Crypt
|
48 |
+
* @package Crypt_TripleDES
|
49 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
50 |
+
* @copyright 2007 Jim Wigginton
|
51 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
52 |
+
* @link http://phpseclib.sourceforge.net
|
53 |
+
*/
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Include Crypt_DES
|
57 |
+
*/
|
58 |
+
if (!class_exists('Crypt_DES')) {
|
59 |
+
include_once 'DES.php';
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Encrypt / decrypt using inner chaining
|
64 |
+
*
|
65 |
+
* Inner chaining is used by SSH-1 and is generally considered to be less secure then outer chaining (CRYPT_DES_MODE_CBC3).
|
66 |
+
*/
|
67 |
+
define('CRYPT_DES_MODE_3CBC', -2);
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Encrypt / decrypt using outer chaining
|
71 |
+
*
|
72 |
+
* Outer chaining is used by SSH-2 and when the mode is set to CRYPT_DES_MODE_CBC.
|
73 |
+
*/
|
74 |
+
define('CRYPT_DES_MODE_CBC3', CRYPT_DES_MODE_CBC);
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Pure-PHP implementation of Triple DES.
|
78 |
+
*
|
79 |
+
* @package Crypt_TripleDES
|
80 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
81 |
+
* @access public
|
82 |
+
*/
|
83 |
+
class Crypt_TripleDES extends Crypt_DES
|
84 |
+
{
|
85 |
+
/**
|
86 |
+
* The default password key_size used by setPassword()
|
87 |
+
*
|
88 |
+
* @see Crypt_DES::password_key_size
|
89 |
+
* @see Crypt_Base::password_key_size
|
90 |
+
* @see Crypt_Base::setPassword()
|
91 |
+
* @var Integer
|
92 |
+
* @access private
|
93 |
+
*/
|
94 |
+
var $password_key_size = 24;
|
95 |
+
|
96 |
+
/**
|
97 |
+
* The default salt used by setPassword()
|
98 |
+
*
|
99 |
+
* @see Crypt_Base::password_default_salt
|
100 |
+
* @see Crypt_Base::setPassword()
|
101 |
+
* @var String
|
102 |
+
* @access private
|
103 |
+
*/
|
104 |
+
var $password_default_salt = 'phpseclib';
|
105 |
+
|
106 |
+
/**
|
107 |
+
* The namespace used by the cipher for its constants.
|
108 |
+
*
|
109 |
+
* @see Crypt_DES::const_namespace
|
110 |
+
* @see Crypt_Base::const_namespace
|
111 |
+
* @var String
|
112 |
+
* @access private
|
113 |
+
*/
|
114 |
+
var $const_namespace = 'DES';
|
115 |
+
|
116 |
+
/**
|
117 |
+
* The mcrypt specific name of the cipher
|
118 |
+
*
|
119 |
+
* @see Crypt_DES::cipher_name_mcrypt
|
120 |
+
* @see Crypt_Base::cipher_name_mcrypt
|
121 |
+
* @var String
|
122 |
+
* @access private
|
123 |
+
*/
|
124 |
+
var $cipher_name_mcrypt = 'tripledes';
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Optimizing value while CFB-encrypting
|
128 |
+
*
|
129 |
+
* @see Crypt_Base::cfb_init_len
|
130 |
+
* @var Integer
|
131 |
+
* @access private
|
132 |
+
*/
|
133 |
+
var $cfb_init_len = 750;
|
134 |
+
|
135 |
+
/**
|
136 |
+
* max possible size of $key
|
137 |
+
*
|
138 |
+
* @see Crypt_TripleDES::setKey()
|
139 |
+
* @see Crypt_DES::setKey()
|
140 |
+
* @var String
|
141 |
+
* @access private
|
142 |
+
*/
|
143 |
+
var $key_size_max = 24;
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Internal flag whether using CRYPT_DES_MODE_3CBC or not
|
147 |
+
*
|
148 |
+
* @var Boolean
|
149 |
+
* @access private
|
150 |
+
*/
|
151 |
+
var $mode_3cbc;
|
152 |
+
|
153 |
+
/**
|
154 |
+
* The Crypt_DES objects
|
155 |
+
*
|
156 |
+
* Used only if $mode_3cbc === true
|
157 |
+
*
|
158 |
+
* @var Array
|
159 |
+
* @access private
|
160 |
+
*/
|
161 |
+
var $des;
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Default Constructor.
|
165 |
+
*
|
166 |
+
* Determines whether or not the mcrypt extension should be used.
|
167 |
+
*
|
168 |
+
* $mode could be:
|
169 |
+
*
|
170 |
+
* - CRYPT_DES_MODE_ECB
|
171 |
+
*
|
172 |
+
* - CRYPT_DES_MODE_CBC
|
173 |
+
*
|
174 |
+
* - CRYPT_DES_MODE_CTR
|
175 |
+
*
|
176 |
+
* - CRYPT_DES_MODE_CFB
|
177 |
+
*
|
178 |
+
* - CRYPT_DES_MODE_OFB
|
179 |
+
*
|
180 |
+
* - CRYPT_DES_MODE_3CBC
|
181 |
+
*
|
182 |
+
* If not explicitly set, CRYPT_DES_MODE_CBC will be used.
|
183 |
+
*
|
184 |
+
* @see Crypt_DES::Crypt_DES()
|
185 |
+
* @see Crypt_Base::Crypt_Base()
|
186 |
+
* @param optional Integer $mode
|
187 |
+
* @access public
|
188 |
+
*/
|
189 |
+
function Crypt_TripleDES($mode = CRYPT_DES_MODE_CBC)
|
190 |
+
{
|
191 |
+
switch ($mode) {
|
192 |
+
// In case of CRYPT_DES_MODE_3CBC, we init as CRYPT_DES_MODE_CBC
|
193 |
+
// and additional flag us internally as 3CBC
|
194 |
+
case CRYPT_DES_MODE_3CBC:
|
195 |
+
parent::Crypt_Base(CRYPT_DES_MODE_CBC);
|
196 |
+
$this->mode_3cbc = true;
|
197 |
+
|
198 |
+
// This three $des'es will do the 3CBC work (if $key > 64bits)
|
199 |
+
$this->des = array(
|
200 |
+
new Crypt_DES(CRYPT_DES_MODE_CBC),
|
201 |
+
new Crypt_DES(CRYPT_DES_MODE_CBC),
|
202 |
+
new Crypt_DES(CRYPT_DES_MODE_CBC),
|
203 |
+
);
|
204 |
+
|
205 |
+
// we're going to be doing the padding, ourselves, so disable it in the Crypt_DES objects
|
206 |
+
$this->des[0]->disablePadding();
|
207 |
+
$this->des[1]->disablePadding();
|
208 |
+
$this->des[2]->disablePadding();
|
209 |
+
break;
|
210 |
+
// If not 3CBC, we init as usual
|
211 |
+
default:
|
212 |
+
parent::Crypt_Base($mode);
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Sets the initialization vector. (optional)
|
218 |
+
*
|
219 |
+
* SetIV is not required when CRYPT_DES_MODE_ECB is being used. If not explicitly set, it'll be assumed
|
220 |
+
* to be all zero's.
|
221 |
+
*
|
222 |
+
* @see Crypt_Base::setIV()
|
223 |
+
* @access public
|
224 |
+
* @param String $iv
|
225 |
+
*/
|
226 |
+
function setIV($iv)
|
227 |
+
{
|
228 |
+
parent::setIV($iv);
|
229 |
+
if ($this->mode_3cbc) {
|
230 |
+
$this->des[0]->setIV($iv);
|
231 |
+
$this->des[1]->setIV($iv);
|
232 |
+
$this->des[2]->setIV($iv);
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Sets the key.
|
238 |
+
*
|
239 |
+
* Keys can be of any length. Triple DES, itself, can use 128-bit (eg. strlen($key) == 16) or
|
240 |
+
* 192-bit (eg. strlen($key) == 24) keys. This function pads and truncates $key as appropriate.
|
241 |
+
*
|
242 |
+
* DES also requires that every eighth bit be a parity bit, however, we'll ignore that.
|
243 |
+
*
|
244 |
+
* If the key is not explicitly set, it'll be assumed to be all null bytes.
|
245 |
+
*
|
246 |
+
* @access public
|
247 |
+
* @see Crypt_DES::setKey()
|
248 |
+
* @see Crypt_Base::setKey()
|
249 |
+
* @param String $key
|
250 |
+
*/
|
251 |
+
function setKey($key)
|
252 |
+
{
|
253 |
+
$length = strlen($key);
|
254 |
+
if ($length > 8) {
|
255 |
+
$key = str_pad(substr($key, 0, 24), 24, chr(0));
|
256 |
+
// if $key is between 64 and 128-bits, use the first 64-bits as the last, per this:
|
257 |
+
// http://php.net/function.mcrypt-encrypt#47973
|
258 |
+
//$key = $length <= 16 ? substr_replace($key, substr($key, 0, 8), 16) : substr($key, 0, 24);
|
259 |
+
} else {
|
260 |
+
$key = str_pad($key, 8, chr(0));
|
261 |
+
}
|
262 |
+
parent::setKey($key);
|
263 |
+
|
264 |
+
// And in case of CRYPT_DES_MODE_3CBC:
|
265 |
+
// if key <= 64bits we not need the 3 $des to work,
|
266 |
+
// because we will then act as regular DES-CBC with just a <= 64bit key.
|
267 |
+
// So only if the key > 64bits (> 8 bytes) we will call setKey() for the 3 $des.
|
268 |
+
if ($this->mode_3cbc && $length > 8) {
|
269 |
+
$this->des[0]->setKey(substr($key, 0, 8));
|
270 |
+
$this->des[1]->setKey(substr($key, 8, 8));
|
271 |
+
$this->des[2]->setKey(substr($key, 16, 8));
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Encrypts a message.
|
277 |
+
*
|
278 |
+
* @see Crypt_Base::encrypt()
|
279 |
+
* @access public
|
280 |
+
* @param String $plaintext
|
281 |
+
* @return String $cipertext
|
282 |
+
*/
|
283 |
+
function encrypt($plaintext)
|
284 |
+
{
|
285 |
+
// parent::en/decrypt() is able to do all the work for all modes and keylengths,
|
286 |
+
// except for: CRYPT_DES_MODE_3CBC (inner chaining CBC) with a key > 64bits
|
287 |
+
|
288 |
+
// if the key is smaller then 8, do what we'd normally do
|
289 |
+
if ($this->mode_3cbc && strlen($this->key) > 8) {
|
290 |
+
return $this->des[2]->encrypt(
|
291 |
+
$this->des[1]->decrypt(
|
292 |
+
$this->des[0]->encrypt(
|
293 |
+
$this->_pad($plaintext)
|
294 |
+
)
|
295 |
+
)
|
296 |
+
);
|
297 |
+
}
|
298 |
+
|
299 |
+
return parent::encrypt($plaintext);
|
300 |
+
}
|
301 |
+
|
302 |
+
/**
|
303 |
+
* Decrypts a message.
|
304 |
+
*
|
305 |
+
* @see Crypt_Base::decrypt()
|
306 |
+
* @access public
|
307 |
+
* @param String $ciphertext
|
308 |
+
* @return String $plaintext
|
309 |
+
*/
|
310 |
+
function decrypt($ciphertext)
|
311 |
+
{
|
312 |
+
if ($this->mode_3cbc && strlen($this->key) > 8) {
|
313 |
+
return $this->_unpad(
|
314 |
+
$this->des[0]->decrypt(
|
315 |
+
$this->des[1]->encrypt(
|
316 |
+
$this->des[2]->decrypt(
|
317 |
+
str_pad($ciphertext, (strlen($ciphertext) + 7) & 0xFFFFFFF8, "\0")
|
318 |
+
)
|
319 |
+
)
|
320 |
+
)
|
321 |
+
);
|
322 |
+
}
|
323 |
+
|
324 |
+
return parent::decrypt($ciphertext);
|
325 |
+
}
|
326 |
+
|
327 |
+
/**
|
328 |
+
* Treat consecutive "packets" as if they are a continuous buffer.
|
329 |
+
*
|
330 |
+
* Say you have a 16-byte plaintext $plaintext. Using the default behavior, the two following code snippets
|
331 |
+
* will yield different outputs:
|
332 |
+
*
|
333 |
+
* <code>
|
334 |
+
* echo $des->encrypt(substr($plaintext, 0, 8));
|
335 |
+
* echo $des->encrypt(substr($plaintext, 8, 8));
|
336 |
+
* </code>
|
337 |
+
* <code>
|
338 |
+
* echo $des->encrypt($plaintext);
|
339 |
+
* </code>
|
340 |
+
*
|
341 |
+
* The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates
|
342 |
+
* another, as demonstrated with the following:
|
343 |
+
*
|
344 |
+
* <code>
|
345 |
+
* $des->encrypt(substr($plaintext, 0, 8));
|
346 |
+
* echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8)));
|
347 |
+
* </code>
|
348 |
+
* <code>
|
349 |
+
* echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8)));
|
350 |
+
* </code>
|
351 |
+
*
|
352 |
+
* With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different
|
353 |
+
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
|
354 |
+
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
|
355 |
+
*
|
356 |
+
* Put another way, when the continuous buffer is enabled, the state of the Crypt_DES() object changes after each
|
357 |
+
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
|
358 |
+
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
|
359 |
+
* however, they are also less intuitive and more likely to cause you problems.
|
360 |
+
*
|
361 |
+
* @see Crypt_Base::enableContinuousBuffer()
|
362 |
+
* @see Crypt_TripleDES::disableContinuousBuffer()
|
363 |
+
* @access public
|
364 |
+
*/
|
365 |
+
function enableContinuousBuffer()
|
366 |
+
{
|
367 |
+
parent::enableContinuousBuffer();
|
368 |
+
if ($this->mode_3cbc) {
|
369 |
+
$this->des[0]->enableContinuousBuffer();
|
370 |
+
$this->des[1]->enableContinuousBuffer();
|
371 |
+
$this->des[2]->enableContinuousBuffer();
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
/**
|
376 |
+
* Treat consecutive packets as if they are a discontinuous buffer.
|
377 |
+
*
|
378 |
+
* The default behavior.
|
379 |
+
*
|
380 |
+
* @see Crypt_Base::disableContinuousBuffer()
|
381 |
+
* @see Crypt_TripleDES::enableContinuousBuffer()
|
382 |
+
* @access public
|
383 |
+
*/
|
384 |
+
function disableContinuousBuffer()
|
385 |
+
{
|
386 |
+
parent::disableContinuousBuffer();
|
387 |
+
if ($this->mode_3cbc) {
|
388 |
+
$this->des[0]->disableContinuousBuffer();
|
389 |
+
$this->des[1]->disableContinuousBuffer();
|
390 |
+
$this->des[2]->disableContinuousBuffer();
|
391 |
+
}
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Creates the key schedule
|
396 |
+
*
|
397 |
+
* @see Crypt_DES::_setupKey()
|
398 |
+
* @see Crypt_Base::_setupKey()
|
399 |
+
* @access private
|
400 |
+
*/
|
401 |
+
function _setupKey()
|
402 |
+
{
|
403 |
+
switch (true) {
|
404 |
+
// if $key <= 64bits we configure our internal pure-php cipher engine
|
405 |
+
// to act as regular [1]DES, not as 3DES. mcrypt.so::tripledes does the same.
|
406 |
+
case strlen($this->key) <= 8:
|
407 |
+
$this->des_rounds = 1;
|
408 |
+
break;
|
409 |
+
|
410 |
+
// otherwise, if $key > 64bits, we configure our engine to work as 3DES.
|
411 |
+
default:
|
412 |
+
$this->des_rounds = 3;
|
413 |
+
|
414 |
+
// (only) if 3CBC is used we have, of course, to setup the $des[0-2] keys also separately.
|
415 |
+
if ($this->mode_3cbc) {
|
416 |
+
$this->des[0]->_setupKey();
|
417 |
+
$this->des[1]->_setupKey();
|
418 |
+
$this->des[2]->_setupKey();
|
419 |
+
|
420 |
+
// because $des[0-2] will, now, do all the work we can return here
|
421 |
+
// not need unnecessary stress parent::_setupKey() with our, now unused, $key.
|
422 |
+
return;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
// setup our key
|
426 |
+
parent::_setupKey();
|
427 |
+
}
|
428 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/Crypt/Twofish.php
ADDED
@@ -0,0 +1,895 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP implementation of Twofish.
|
5 |
+
*
|
6 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
7 |
+
*
|
8 |
+
* PHP versions 4 and 5
|
9 |
+
*
|
10 |
+
* Useful resources are as follows:
|
11 |
+
*
|
12 |
+
* - {@link http://en.wikipedia.org/wiki/Twofish Wikipedia description of Twofish}
|
13 |
+
*
|
14 |
+
* Here's a short example of how to use this library:
|
15 |
+
* <code>
|
16 |
+
* <?php
|
17 |
+
* include 'Crypt/Twofish.php';
|
18 |
+
*
|
19 |
+
* $twofish = new Crypt_Twofish();
|
20 |
+
*
|
21 |
+
* $twofish->setKey('12345678901234567890123456789012');
|
22 |
+
*
|
23 |
+
* $plaintext = str_repeat('a', 1024);
|
24 |
+
*
|
25 |
+
* echo $twofish->decrypt($twofish->encrypt($plaintext));
|
26 |
+
* ?>
|
27 |
+
* </code>
|
28 |
+
*
|
29 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
30 |
+
* of this software and associated documentation files (the "Software"), to deal
|
31 |
+
* in the Software without restriction, including without limitation the rights
|
32 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
33 |
+
* copies of the Software, and to permit persons to whom the Software is
|
34 |
+
* furnished to do so, subject to the following conditions:
|
35 |
+
*
|
36 |
+
* The above copyright notice and this permission notice shall be included in
|
37 |
+
* all copies or substantial portions of the Software.
|
38 |
+
*
|
39 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
40 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
41 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
42 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
43 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
44 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
45 |
+
* THE SOFTWARE.
|
46 |
+
*
|
47 |
+
* @category Crypt
|
48 |
+
* @package Crypt_Twofish
|
49 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
50 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
51 |
+
* @copyright 2007 Jim Wigginton
|
52 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
53 |
+
* @link http://phpseclib.sourceforge.net
|
54 |
+
*/
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Include Crypt_Base
|
58 |
+
*
|
59 |
+
* Base cipher class
|
60 |
+
*/
|
61 |
+
if (!class_exists('Crypt_Base')) {
|
62 |
+
include_once 'Base.php';
|
63 |
+
}
|
64 |
+
|
65 |
+
/**#@+
|
66 |
+
* @access public
|
67 |
+
* @see Crypt_Twofish::encrypt()
|
68 |
+
* @see Crypt_Twofish::decrypt()
|
69 |
+
*/
|
70 |
+
/**
|
71 |
+
* Encrypt / decrypt using the Counter mode.
|
72 |
+
*
|
73 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
74 |
+
*
|
75 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
76 |
+
*/
|
77 |
+
define('CRYPT_TWOFISH_MODE_CTR', CRYPT_MODE_CTR);
|
78 |
+
/**
|
79 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
80 |
+
*
|
81 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
82 |
+
*/
|
83 |
+
define('CRYPT_TWOFISH_MODE_ECB', CRYPT_MODE_ECB);
|
84 |
+
/**
|
85 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
86 |
+
*
|
87 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
88 |
+
*/
|
89 |
+
define('CRYPT_TWOFISH_MODE_CBC', CRYPT_MODE_CBC);
|
90 |
+
/**
|
91 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
92 |
+
*
|
93 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
94 |
+
*/
|
95 |
+
define('CRYPT_TWOFISH_MODE_CFB', CRYPT_MODE_CFB);
|
96 |
+
/**
|
97 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
98 |
+
*
|
99 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
100 |
+
*/
|
101 |
+
define('CRYPT_TWOFISH_MODE_OFB', CRYPT_MODE_OFB);
|
102 |
+
/**#@-*/
|
103 |
+
|
104 |
+
/**#@+
|
105 |
+
* @access private
|
106 |
+
* @see Crypt_Base::Crypt_Base()
|
107 |
+
*/
|
108 |
+
/**
|
109 |
+
* Toggles the internal implementation
|
110 |
+
*/
|
111 |
+
define('CRYPT_TWOFISH_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
112 |
+
/**
|
113 |
+
* Toggles the mcrypt implementation
|
114 |
+
*/
|
115 |
+
define('CRYPT_TWOFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
116 |
+
/**#@-*/
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Pure-PHP implementation of Twofish.
|
120 |
+
*
|
121 |
+
* @package Crypt_Twofish
|
122 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
123 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
124 |
+
* @access public
|
125 |
+
*/
|
126 |
+
class Crypt_Twofish extends Crypt_Base
|
127 |
+
{
|
128 |
+
/**
|
129 |
+
* The namespace used by the cipher for its constants.
|
130 |
+
*
|
131 |
+
* @see Crypt_Base::const_namespace
|
132 |
+
* @var String
|
133 |
+
* @access private
|
134 |
+
*/
|
135 |
+
var $const_namespace = 'TWOFISH';
|
136 |
+
|
137 |
+
/**
|
138 |
+
* The mcrypt specific name of the cipher
|
139 |
+
*
|
140 |
+
* @see Crypt_Base::cipher_name_mcrypt
|
141 |
+
* @var String
|
142 |
+
* @access private
|
143 |
+
*/
|
144 |
+
var $cipher_name_mcrypt = 'twofish';
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Optimizing value while CFB-encrypting
|
148 |
+
*
|
149 |
+
* @see Crypt_Base::cfb_init_len
|
150 |
+
* @var Integer
|
151 |
+
* @access private
|
152 |
+
*/
|
153 |
+
var $cfb_init_len = 800;
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Q-Table
|
157 |
+
*
|
158 |
+
* @var Array
|
159 |
+
* @access private
|
160 |
+
*/
|
161 |
+
var $q0 = array (
|
162 |
+
0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76,
|
163 |
+
0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38,
|
164 |
+
0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
|
165 |
+
0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48,
|
166 |
+
0xF2, 0xD0, 0x8B, 0x30, 0x84, 0x54, 0xDF, 0x23,
|
167 |
+
0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82,
|
168 |
+
0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C,
|
169 |
+
0xA6, 0xEB, 0xA5, 0xBE, 0x16, 0x0C, 0xE3, 0x61,
|
170 |
+
0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B,
|
171 |
+
0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1,
|
172 |
+
0xE1, 0xE6, 0xBD, 0x45, 0xE2, 0xF4, 0xB6, 0x66,
|
173 |
+
0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7,
|
174 |
+
0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA,
|
175 |
+
0xEA, 0x77, 0x39, 0xAF, 0x33, 0xC9, 0x62, 0x71,
|
176 |
+
0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8,
|
177 |
+
0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7,
|
178 |
+
0xA1, 0x1D, 0xAA, 0xED, 0x06, 0x70, 0xB2, 0xD2,
|
179 |
+
0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90,
|
180 |
+
0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB,
|
181 |
+
0x9E, 0x9C, 0x52, 0x1B, 0x5F, 0x93, 0x0A, 0xEF,
|
182 |
+
0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B,
|
183 |
+
0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64,
|
184 |
+
0x2A, 0xCE, 0xCB, 0x2F, 0xFC, 0x97, 0x05, 0x7A,
|
185 |
+
0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A,
|
186 |
+
0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02,
|
187 |
+
0xB8, 0xDA, 0xB0, 0x17, 0x55, 0x1F, 0x8A, 0x7D,
|
188 |
+
0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72,
|
189 |
+
0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34,
|
190 |
+
0x6E, 0x50, 0xDE, 0x68, 0x65, 0xBC, 0xDB, 0xF8,
|
191 |
+
0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
|
192 |
+
0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00,
|
193 |
+
0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0
|
194 |
+
);
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Q-Table
|
198 |
+
*
|
199 |
+
* @var Array
|
200 |
+
* @access private
|
201 |
+
*/
|
202 |
+
var $q1 = array (
|
203 |
+
0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8,
|
204 |
+
0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B,
|
205 |
+
0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
|
206 |
+
0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F,
|
207 |
+
0x5E, 0xBA, 0xAE, 0x5B, 0x8A, 0x00, 0xBC, 0x9D,
|
208 |
+
0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5,
|
209 |
+
0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3,
|
210 |
+
0xB2, 0x73, 0x4C, 0x54, 0x92, 0x74, 0x36, 0x51,
|
211 |
+
0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96,
|
212 |
+
0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C,
|
213 |
+
0x13, 0x95, 0x9C, 0xC7, 0x24, 0x46, 0x3B, 0x70,
|
214 |
+
0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8,
|
215 |
+
0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC,
|
216 |
+
0x03, 0x6F, 0x08, 0xBF, 0x40, 0xE7, 0x2B, 0xE2,
|
217 |
+
0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9,
|
218 |
+
0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17,
|
219 |
+
0x66, 0x94, 0xA1, 0x1D, 0x3D, 0xF0, 0xDE, 0xB3,
|
220 |
+
0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E,
|
221 |
+
0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49,
|
222 |
+
0x81, 0x88, 0xEE, 0x21, 0xC4, 0x1A, 0xEB, 0xD9,
|
223 |
+
0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01,
|
224 |
+
0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48,
|
225 |
+
0x4F, 0xF2, 0x65, 0x8E, 0x78, 0x5C, 0x58, 0x19,
|
226 |
+
0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64,
|
227 |
+
0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5,
|
228 |
+
0xCE, 0xE9, 0x68, 0x44, 0xE0, 0x4D, 0x43, 0x69,
|
229 |
+
0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E,
|
230 |
+
0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC,
|
231 |
+
0x22, 0xC9, 0xC0, 0x9B, 0x89, 0xD4, 0xED, 0xAB,
|
232 |
+
0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
|
233 |
+
0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2,
|
234 |
+
0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91
|
235 |
+
);
|
236 |
+
|
237 |
+
/**
|
238 |
+
* M-Table
|
239 |
+
*
|
240 |
+
* @var Array
|
241 |
+
* @access private
|
242 |
+
*/
|
243 |
+
var $m0 = array (
|
244 |
+
0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8,
|
245 |
+
0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B,
|
246 |
+
0x3C3C57D6, 0x93938A32, 0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1,
|
247 |
+
0x24243C30, 0x5151E20F, 0xBABAC6F8, 0x4A4AF31B, 0xBFBF4887, 0x0D0D70FA, 0xB0B0B306, 0x7575DE3F,
|
248 |
+
0xD2D2FD5E, 0x7D7D20BA, 0x666631AE, 0x3A3AA35B, 0x59591C8A, 0x00000000, 0xCDCD93BC, 0x1A1AE09D,
|
249 |
+
0xAEAE2C6D, 0x7F7FABC1, 0x2B2BC7B1, 0xBEBEB90E, 0xE0E0A080, 0x8A8A105D, 0x3B3B52D2, 0x6464BAD5,
|
250 |
+
0xD8D888A0, 0xE7E7A584, 0x5F5FE807, 0x1B1B1114, 0x2C2CC2B5, 0xFCFCB490, 0x3131272C, 0x808065A3,
|
251 |
+
0x73732AB2, 0x0C0C8173, 0x79795F4C, 0x6B6B4154, 0x4B4B0292, 0x53536974, 0x94948F36, 0x83831F51,
|
252 |
+
0x2A2A3638, 0xC4C49CB0, 0x2222C8BD, 0xD5D5F85A, 0xBDBDC3FC, 0x48487860, 0xFFFFCE62, 0x4C4C0796,
|
253 |
+
0x4141776C, 0xC7C7E642, 0xEBEB24F7, 0x1C1C1410, 0x5D5D637C, 0x36362228, 0x6767C027, 0xE9E9AF8C,
|
254 |
+
0x4444F913, 0x1414EA95, 0xF5F5BB9C, 0xCFCF18C7, 0x3F3F2D24, 0xC0C0E346, 0x7272DB3B, 0x54546C70,
|
255 |
+
0x29294CCA, 0xF0F035E3, 0x0808FE85, 0xC6C617CB, 0xF3F34F11, 0x8C8CE4D0, 0xA4A45993, 0xCACA96B8,
|
256 |
+
0x68683BA6, 0xB8B84D83, 0x38382820, 0xE5E52EFF, 0xADAD569F, 0x0B0B8477, 0xC8C81DC3, 0x9999FFCC,
|
257 |
+
0x5858ED03, 0x19199A6F, 0x0E0E0A08, 0x95957EBF, 0x70705040, 0xF7F730E7, 0x6E6ECF2B, 0x1F1F6EE2,
|
258 |
+
0xB5B53D79, 0x09090F0C, 0x616134AA, 0x57571682, 0x9F9F0B41, 0x9D9D803A, 0x111164EA, 0x2525CDB9,
|
259 |
+
0xAFAFDDE4, 0x4545089A, 0xDFDF8DA4, 0xA3A35C97, 0xEAEAD57E, 0x353558DA, 0xEDEDD07A, 0x4343FC17,
|
260 |
+
0xF8F8CB66, 0xFBFBB194, 0x3737D3A1, 0xFAFA401D, 0xC2C2683D, 0xB4B4CCF0, 0x32325DDE, 0x9C9C71B3,
|
261 |
+
0x5656E70B, 0xE3E3DA72, 0x878760A7, 0x15151B1C, 0xF9F93AEF, 0x6363BFD1, 0x3434A953, 0x9A9A853E,
|
262 |
+
0xB1B1428F, 0x7C7CD133, 0x88889B26, 0x3D3DA65F, 0xA1A1D7EC, 0xE4E4DF76, 0x8181942A, 0x91910149,
|
263 |
+
0x0F0FFB81, 0xEEEEAA88, 0x161661EE, 0xD7D77321, 0x9797F5C4, 0xA5A5A81A, 0xFEFE3FEB, 0x6D6DB5D9,
|
264 |
+
0x7878AEC5, 0xC5C56D39, 0x1D1DE599, 0x7676A4CD, 0x3E3EDCAD, 0xCBCB6731, 0xB6B6478B, 0xEFEF5B01,
|
265 |
+
0x12121E18, 0x6060C523, 0x6A6AB0DD, 0x4D4DF61F, 0xCECEE94E, 0xDEDE7C2D, 0x55559DF9, 0x7E7E5A48,
|
266 |
+
0x2121B24F, 0x03037AF2, 0xA0A02665, 0x5E5E198E, 0x5A5A6678, 0x65654B5C, 0x62624E58, 0xFDFD4519,
|
267 |
+
0x0606F48D, 0x404086E5, 0xF2F2BE98, 0x3333AC57, 0x17179067, 0x05058E7F, 0xE8E85E05, 0x4F4F7D64,
|
268 |
+
0x89896AAF, 0x10109563, 0x74742FB6, 0x0A0A75FE, 0x5C5C92F5, 0x9B9B74B7, 0x2D2D333C, 0x3030D6A5,
|
269 |
+
0x2E2E49CE, 0x494989E9, 0x46467268, 0x77775544, 0xA8A8D8E0, 0x9696044D, 0x2828BD43, 0xA9A92969,
|
270 |
+
0xD9D97929, 0x8686912E, 0xD1D187AC, 0xF4F44A15, 0x8D8D1559, 0xD6D682A8, 0xB9B9BC0A, 0x42420D9E,
|
271 |
+
0xF6F6C16E, 0x2F2FB847, 0xDDDD06DF, 0x23233934, 0xCCCC6235, 0xF1F1C46A, 0xC1C112CF, 0x8585EBDC,
|
272 |
+
0x8F8F9E22, 0x7171A1C9, 0x9090F0C0, 0xAAAA539B, 0x0101F189, 0x8B8BE1D4, 0x4E4E8CED, 0x8E8E6FAB,
|
273 |
+
0xABABA212, 0x6F6F3EA2, 0xE6E6540D, 0xDBDBF252, 0x92927BBB, 0xB7B7B602, 0x6969CA2F, 0x3939D9A9,
|
274 |
+
0xD3D30CD7, 0xA7A72361, 0xA2A2AD1E, 0xC3C399B4, 0x6C6C4450, 0x07070504, 0x04047FF6, 0x272746C2,
|
275 |
+
0xACACA716, 0xD0D07625, 0x50501386, 0xDCDCF756, 0x84841A55, 0xE1E15109, 0x7A7A25BE, 0x1313EF91
|
276 |
+
);
|
277 |
+
|
278 |
+
/**
|
279 |
+
* M-Table
|
280 |
+
*
|
281 |
+
* @var Array
|
282 |
+
* @access private
|
283 |
+
*/
|
284 |
+
var $m1 = array (
|
285 |
+
0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4,
|
286 |
+
0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A,
|
287 |
+
0x0D54E6E6, 0xC6432020, 0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141,
|
288 |
+
0x43BD2828, 0x7532BCBC, 0x37D47B7B, 0x269B8888, 0xFA700D0D, 0x13F94444, 0x94B1FBFB, 0x485A7E7E,
|
289 |
+
0xF27A0303, 0xD0E48C8C, 0x8B47B6B6, 0x303C2424, 0x84A5E7E7, 0x54416B6B, 0xDF06DDDD, 0x23C56060,
|
290 |
+
0x1945FDFD, 0x5BA33A3A, 0x3D68C2C2, 0x59158D8D, 0xF321ECEC, 0xAE316666, 0xA23E6F6F, 0x82165757,
|
291 |
+
0x63951010, 0x015BEFEF, 0x834DB8B8, 0x2E918686, 0xD9B56D6D, 0x511F8383, 0x9B53AAAA, 0x7C635D5D,
|
292 |
+
0xA63B6868, 0xEB3FFEFE, 0xA5D63030, 0xBE257A7A, 0x16A7ACAC, 0x0C0F0909, 0xE335F0F0, 0x6123A7A7,
|
293 |
+
0xC0F09090, 0x8CAFE9E9, 0x3A809D9D, 0xF5925C5C, 0x73810C0C, 0x2C273131, 0x2576D0D0, 0x0BE75656,
|
294 |
+
0xBB7B9292, 0x4EE9CECE, 0x89F10101, 0x6B9F1E1E, 0x53A93434, 0x6AC4F1F1, 0xB499C3C3, 0xF1975B5B,
|
295 |
+
0xE1834747, 0xE66B1818, 0xBDC82222, 0x450E9898, 0xE26E1F1F, 0xF4C9B3B3, 0xB62F7474, 0x66CBF8F8,
|
296 |
+
0xCCFF9999, 0x95EA1414, 0x03ED5858, 0x56F7DCDC, 0xD4E18B8B, 0x1C1B1515, 0x1EADA2A2, 0xD70CD3D3,
|
297 |
+
0xFB2BE2E2, 0xC31DC8C8, 0x8E195E5E, 0xB5C22C2C, 0xE9894949, 0xCF12C1C1, 0xBF7E9595, 0xBA207D7D,
|
298 |
+
0xEA641111, 0x77840B0B, 0x396DC5C5, 0xAF6A8989, 0x33D17C7C, 0xC9A17171, 0x62CEFFFF, 0x7137BBBB,
|
299 |
+
0x81FB0F0F, 0x793DB5B5, 0x0951E1E1, 0xADDC3E3E, 0x242D3F3F, 0xCDA47676, 0xF99D5555, 0xD8EE8282,
|
300 |
+
0xE5864040, 0xC5AE7878, 0xB9CD2525, 0x4D049696, 0x44557777, 0x080A0E0E, 0x86135050, 0xE730F7F7,
|
301 |
+
0xA1D33737, 0x1D40FAFA, 0xAA346161, 0xED8C4E4E, 0x06B3B0B0, 0x706C5454, 0xB22A7373, 0xD2523B3B,
|
302 |
+
0x410B9F9F, 0x7B8B0202, 0xA088D8D8, 0x114FF3F3, 0x3167CBCB, 0xC2462727, 0x27C06767, 0x90B4FCFC,
|
303 |
+
0x20283838, 0xF67F0404, 0x60784848, 0xFF2EE5E5, 0x96074C4C, 0x5C4B6565, 0xB1C72B2B, 0xAB6F8E8E,
|
304 |
+
0x9E0D4242, 0x9CBBF5F5, 0x52F2DBDB, 0x1BF34A4A, 0x5FA63D3D, 0x9359A4A4, 0x0ABCB9B9, 0xEF3AF9F9,
|
305 |
+
0x91EF1313, 0x85FE0808, 0x49019191, 0xEE611616, 0x2D7CDEDE, 0x4FB22121, 0x8F42B1B1, 0x3BDB7272,
|
306 |
+
0x47B82F2F, 0x8748BFBF, 0x6D2CAEAE, 0x46E3C0C0, 0xD6573C3C, 0x3E859A9A, 0x6929A9A9, 0x647D4F4F,
|
307 |
+
0x2A948181, 0xCE492E2E, 0xCB17C6C6, 0x2FCA6969, 0xFCC3BDBD, 0x975CA3A3, 0x055EE8E8, 0x7AD0EDED,
|
308 |
+
0xAC87D1D1, 0x7F8E0505, 0xD5BA6464, 0x1AA8A5A5, 0x4BB72626, 0x0EB9BEBE, 0xA7608787, 0x5AF8D5D5,
|
309 |
+
0x28223636, 0x14111B1B, 0x3FDE7575, 0x2979D9D9, 0x88AAEEEE, 0x3C332D2D, 0x4C5F7979, 0x02B6B7B7,
|
310 |
+
0xB896CACA, 0xDA583535, 0xB09CC4C4, 0x17FC4343, 0x551A8484, 0x1FF64D4D, 0x8A1C5959, 0x7D38B2B2,
|
311 |
+
0x57AC3333, 0xC718CFCF, 0x8DF40606, 0x74695353, 0xB7749B9B, 0xC4F59797, 0x9F56ADAD, 0x72DAE3E3,
|
312 |
+
0x7ED5EAEA, 0x154AF4F4, 0x229E8F8F, 0x12A2ABAB, 0x584E6262, 0x07E85F5F, 0x99E51D1D, 0x34392323,
|
313 |
+
0x6EC1F6F6, 0x50446C6C, 0xDE5D3232, 0x68724646, 0x6526A0A0, 0xBC93CDCD, 0xDB03DADA, 0xF8C6BABA,
|
314 |
+
0xC8FA9E9E, 0xA882D6D6, 0x2BCF6E6E, 0x40507070, 0xDCEB8585, 0xFE750A0A, 0x328A9393, 0xA48DDFDF,
|
315 |
+
0xCA4C2929, 0x10141C1C, 0x2173D7D7, 0xF0CCB4B4, 0xD309D4D4, 0x5D108A8A, 0x0FE25151, 0x00000000,
|
316 |
+
0x6F9A1919, 0x9DE01A1A, 0x368F9494, 0x42E6C7C7, 0x4AECC9C9, 0x5EFDD2D2, 0xC1AB7F7F, 0xE0D8A8A8
|
317 |
+
);
|
318 |
+
|
319 |
+
/**
|
320 |
+
* M-Table
|
321 |
+
*
|
322 |
+
* @var Array
|
323 |
+
* @access private
|
324 |
+
*/
|
325 |
+
var $m2 = array (
|
326 |
+
0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA,
|
327 |
+
0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7,
|
328 |
+
0x3CD63C57, 0x9332938A, 0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783,
|
329 |
+
0x2430243C, 0x510F51E2, 0xBAF8BAC6, 0x4A1B4AF3, 0xBF87BF48, 0x0DFA0D70, 0xB006B0B3, 0x753F75DE,
|
330 |
+
0xD25ED2FD, 0x7DBA7D20, 0x66AE6631, 0x3A5B3AA3, 0x598A591C, 0x00000000, 0xCDBCCD93, 0x1A9D1AE0,
|
331 |
+
0xAE6DAE2C, 0x7FC17FAB, 0x2BB12BC7, 0xBE0EBEB9, 0xE080E0A0, 0x8A5D8A10, 0x3BD23B52, 0x64D564BA,
|
332 |
+
0xD8A0D888, 0xE784E7A5, 0x5F075FE8, 0x1B141B11, 0x2CB52CC2, 0xFC90FCB4, 0x312C3127, 0x80A38065,
|
333 |
+
0x73B2732A, 0x0C730C81, 0x794C795F, 0x6B546B41, 0x4B924B02, 0x53745369, 0x9436948F, 0x8351831F,
|
334 |
+
0x2A382A36, 0xC4B0C49C, 0x22BD22C8, 0xD55AD5F8, 0xBDFCBDC3, 0x48604878, 0xFF62FFCE, 0x4C964C07,
|
335 |
+
0x416C4177, 0xC742C7E6, 0xEBF7EB24, 0x1C101C14, 0x5D7C5D63, 0x36283622, 0x672767C0, 0xE98CE9AF,
|
336 |
+
0x441344F9, 0x149514EA, 0xF59CF5BB, 0xCFC7CF18, 0x3F243F2D, 0xC046C0E3, 0x723B72DB, 0x5470546C,
|
337 |
+
0x29CA294C, 0xF0E3F035, 0x088508FE, 0xC6CBC617, 0xF311F34F, 0x8CD08CE4, 0xA493A459, 0xCAB8CA96,
|
338 |
+
0x68A6683B, 0xB883B84D, 0x38203828, 0xE5FFE52E, 0xAD9FAD56, 0x0B770B84, 0xC8C3C81D, 0x99CC99FF,
|
339 |
+
0x580358ED, 0x196F199A, 0x0E080E0A, 0x95BF957E, 0x70407050, 0xF7E7F730, 0x6E2B6ECF, 0x1FE21F6E,
|
340 |
+
0xB579B53D, 0x090C090F, 0x61AA6134, 0x57825716, 0x9F419F0B, 0x9D3A9D80, 0x11EA1164, 0x25B925CD,
|
341 |
+
0xAFE4AFDD, 0x459A4508, 0xDFA4DF8D, 0xA397A35C, 0xEA7EEAD5, 0x35DA3558, 0xED7AEDD0, 0x431743FC,
|
342 |
+
0xF866F8CB, 0xFB94FBB1, 0x37A137D3, 0xFA1DFA40, 0xC23DC268, 0xB4F0B4CC, 0x32DE325D, 0x9CB39C71,
|
343 |
+
0x560B56E7, 0xE372E3DA, 0x87A78760, 0x151C151B, 0xF9EFF93A, 0x63D163BF, 0x345334A9, 0x9A3E9A85,
|
344 |
+
0xB18FB142, 0x7C337CD1, 0x8826889B, 0x3D5F3DA6, 0xA1ECA1D7, 0xE476E4DF, 0x812A8194, 0x91499101,
|
345 |
+
0x0F810FFB, 0xEE88EEAA, 0x16EE1661, 0xD721D773, 0x97C497F5, 0xA51AA5A8, 0xFEEBFE3F, 0x6DD96DB5,
|
346 |
+
0x78C578AE, 0xC539C56D, 0x1D991DE5, 0x76CD76A4, 0x3EAD3EDC, 0xCB31CB67, 0xB68BB647, 0xEF01EF5B,
|
347 |
+
0x1218121E, 0x602360C5, 0x6ADD6AB0, 0x4D1F4DF6, 0xCE4ECEE9, 0xDE2DDE7C, 0x55F9559D, 0x7E487E5A,
|
348 |
+
0x214F21B2, 0x03F2037A, 0xA065A026, 0x5E8E5E19, 0x5A785A66, 0x655C654B, 0x6258624E, 0xFD19FD45,
|
349 |
+
0x068D06F4, 0x40E54086, 0xF298F2BE, 0x335733AC, 0x17671790, 0x057F058E, 0xE805E85E, 0x4F644F7D,
|
350 |
+
0x89AF896A, 0x10631095, 0x74B6742F, 0x0AFE0A75, 0x5CF55C92, 0x9BB79B74, 0x2D3C2D33, 0x30A530D6,
|
351 |
+
0x2ECE2E49, 0x49E94989, 0x46684672, 0x77447755, 0xA8E0A8D8, 0x964D9604, 0x284328BD, 0xA969A929,
|
352 |
+
0xD929D979, 0x862E8691, 0xD1ACD187, 0xF415F44A, 0x8D598D15, 0xD6A8D682, 0xB90AB9BC, 0x429E420D,
|
353 |
+
0xF66EF6C1, 0x2F472FB8, 0xDDDFDD06, 0x23342339, 0xCC35CC62, 0xF16AF1C4, 0xC1CFC112, 0x85DC85EB,
|
354 |
+
0x8F228F9E, 0x71C971A1, 0x90C090F0, 0xAA9BAA53, 0x018901F1, 0x8BD48BE1, 0x4EED4E8C, 0x8EAB8E6F,
|
355 |
+
0xAB12ABA2, 0x6FA26F3E, 0xE60DE654, 0xDB52DBF2, 0x92BB927B, 0xB702B7B6, 0x692F69CA, 0x39A939D9,
|
356 |
+
0xD3D7D30C, 0xA761A723, 0xA21EA2AD, 0xC3B4C399, 0x6C506C44, 0x07040705, 0x04F6047F, 0x27C22746,
|
357 |
+
0xAC16ACA7, 0xD025D076, 0x50865013, 0xDC56DCF7, 0x8455841A, 0xE109E151, 0x7ABE7A25, 0x139113EF
|
358 |
+
);
|
359 |
+
|
360 |
+
/**
|
361 |
+
* M-Table
|
362 |
+
*
|
363 |
+
* @var Array
|
364 |
+
* @access private
|
365 |
+
*/
|
366 |
+
var $m3 = array (
|
367 |
+
0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF,
|
368 |
+
0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836,
|
369 |
+
0x54E60D54, 0x4320C643, 0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77,
|
370 |
+
0xBD2843BD, 0x32BC7532, 0xD47B37D4, 0x9B88269B, 0x700DFA70, 0xF94413F9, 0xB1FB94B1, 0x5A7E485A,
|
371 |
+
0x7A03F27A, 0xE48CD0E4, 0x47B68B47, 0x3C24303C, 0xA5E784A5, 0x416B5441, 0x06DDDF06, 0xC56023C5,
|
372 |
+
0x45FD1945, 0xA33A5BA3, 0x68C23D68, 0x158D5915, 0x21ECF321, 0x3166AE31, 0x3E6FA23E, 0x16578216,
|
373 |
+
0x95106395, 0x5BEF015B, 0x4DB8834D, 0x91862E91, 0xB56DD9B5, 0x1F83511F, 0x53AA9B53, 0x635D7C63,
|
374 |
+
0x3B68A63B, 0x3FFEEB3F, 0xD630A5D6, 0x257ABE25, 0xA7AC16A7, 0x0F090C0F, 0x35F0E335, 0x23A76123,
|
375 |
+
0xF090C0F0, 0xAFE98CAF, 0x809D3A80, 0x925CF592, 0x810C7381, 0x27312C27, 0x76D02576, 0xE7560BE7,
|
376 |
+
0x7B92BB7B, 0xE9CE4EE9, 0xF10189F1, 0x9F1E6B9F, 0xA93453A9, 0xC4F16AC4, 0x99C3B499, 0x975BF197,
|
377 |
+
0x8347E183, 0x6B18E66B, 0xC822BDC8, 0x0E98450E, 0x6E1FE26E, 0xC9B3F4C9, 0x2F74B62F, 0xCBF866CB,
|
378 |
+
0xFF99CCFF, 0xEA1495EA, 0xED5803ED, 0xF7DC56F7, 0xE18BD4E1, 0x1B151C1B, 0xADA21EAD, 0x0CD3D70C,
|
379 |
+
0x2BE2FB2B, 0x1DC8C31D, 0x195E8E19, 0xC22CB5C2, 0x8949E989, 0x12C1CF12, 0x7E95BF7E, 0x207DBA20,
|
380 |
+
0x6411EA64, 0x840B7784, 0x6DC5396D, 0x6A89AF6A, 0xD17C33D1, 0xA171C9A1, 0xCEFF62CE, 0x37BB7137,
|
381 |
+
0xFB0F81FB, 0x3DB5793D, 0x51E10951, 0xDC3EADDC, 0x2D3F242D, 0xA476CDA4, 0x9D55F99D, 0xEE82D8EE,
|
382 |
+
0x8640E586, 0xAE78C5AE, 0xCD25B9CD, 0x04964D04, 0x55774455, 0x0A0E080A, 0x13508613, 0x30F7E730,
|
383 |
+
0xD337A1D3, 0x40FA1D40, 0x3461AA34, 0x8C4EED8C, 0xB3B006B3, 0x6C54706C, 0x2A73B22A, 0x523BD252,
|
384 |
+
0x0B9F410B, 0x8B027B8B, 0x88D8A088, 0x4FF3114F, 0x67CB3167, 0x4627C246, 0xC06727C0, 0xB4FC90B4,
|
385 |
+
0x28382028, 0x7F04F67F, 0x78486078, 0x2EE5FF2E, 0x074C9607, 0x4B655C4B, 0xC72BB1C7, 0x6F8EAB6F,
|
386 |
+
0x0D429E0D, 0xBBF59CBB, 0xF2DB52F2, 0xF34A1BF3, 0xA63D5FA6, 0x59A49359, 0xBCB90ABC, 0x3AF9EF3A,
|
387 |
+
0xEF1391EF, 0xFE0885FE, 0x01914901, 0x6116EE61, 0x7CDE2D7C, 0xB2214FB2, 0x42B18F42, 0xDB723BDB,
|
388 |
+
0xB82F47B8, 0x48BF8748, 0x2CAE6D2C, 0xE3C046E3, 0x573CD657, 0x859A3E85, 0x29A96929, 0x7D4F647D,
|
389 |
+
0x94812A94, 0x492ECE49, 0x17C6CB17, 0xCA692FCA, 0xC3BDFCC3, 0x5CA3975C, 0x5EE8055E, 0xD0ED7AD0,
|
390 |
+
0x87D1AC87, 0x8E057F8E, 0xBA64D5BA, 0xA8A51AA8, 0xB7264BB7, 0xB9BE0EB9, 0x6087A760, 0xF8D55AF8,
|
391 |
+
0x22362822, 0x111B1411, 0xDE753FDE, 0x79D92979, 0xAAEE88AA, 0x332D3C33, 0x5F794C5F, 0xB6B702B6,
|
392 |
+
0x96CAB896, 0x5835DA58, 0x9CC4B09C, 0xFC4317FC, 0x1A84551A, 0xF64D1FF6, 0x1C598A1C, 0x38B27D38,
|
393 |
+
0xAC3357AC, 0x18CFC718, 0xF4068DF4, 0x69537469, 0x749BB774, 0xF597C4F5, 0x56AD9F56, 0xDAE372DA,
|
394 |
+
0xD5EA7ED5, 0x4AF4154A, 0x9E8F229E, 0xA2AB12A2, 0x4E62584E, 0xE85F07E8, 0xE51D99E5, 0x39233439,
|
395 |
+
0xC1F66EC1, 0x446C5044, 0x5D32DE5D, 0x72466872, 0x26A06526, 0x93CDBC93, 0x03DADB03, 0xC6BAF8C6,
|
396 |
+
0xFA9EC8FA, 0x82D6A882, 0xCF6E2BCF, 0x50704050, 0xEB85DCEB, 0x750AFE75, 0x8A93328A, 0x8DDFA48D,
|
397 |
+
0x4C29CA4C, 0x141C1014, 0x73D72173, 0xCCB4F0CC, 0x09D4D309, 0x108A5D10, 0xE2510FE2, 0x00000000,
|
398 |
+
0x9A196F9A, 0xE01A9DE0, 0x8F94368F, 0xE6C742E6, 0xECC94AEC, 0xFDD25EFD, 0xAB7FC1AB, 0xD8A8E0D8
|
399 |
+
);
|
400 |
+
|
401 |
+
/**
|
402 |
+
* The Key Schedule Array
|
403 |
+
*
|
404 |
+
* @var Array
|
405 |
+
* @access private
|
406 |
+
*/
|
407 |
+
var $K = array();
|
408 |
+
|
409 |
+
/**
|
410 |
+
* The Key depended S-Table 0
|
411 |
+
*
|
412 |
+
* @var Array
|
413 |
+
* @access private
|
414 |
+
*/
|
415 |
+
var $S0 = array();
|
416 |
+
|
417 |
+
/**
|
418 |
+
* The Key depended S-Table 1
|
419 |
+
*
|
420 |
+
* @var Array
|
421 |
+
* @access private
|
422 |
+
*/
|
423 |
+
var $S1 = array();
|
424 |
+
|
425 |
+
/**
|
426 |
+
* The Key depended S-Table 2
|
427 |
+
*
|
428 |
+
* @var Array
|
429 |
+
* @access private
|
430 |
+
*/
|
431 |
+
var $S2 = array();
|
432 |
+
|
433 |
+
/**
|
434 |
+
* The Key depended S-Table 3
|
435 |
+
*
|
436 |
+
* @var Array
|
437 |
+
* @access private
|
438 |
+
*/
|
439 |
+
var $S3 = array();
|
440 |
+
|
441 |
+
/**
|
442 |
+
* Holds the last used key
|
443 |
+
*
|
444 |
+
* @var Array
|
445 |
+
* @access private
|
446 |
+
*/
|
447 |
+
var $kl;
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Sets the key.
|
451 |
+
*
|
452 |
+
* Keys can be of any length. Twofish, itself, requires the use of a key that's 128, 192 or 256-bits long.
|
453 |
+
* If the key is less than 256-bits we round the length up to the closest valid key length,
|
454 |
+
* padding $key with null bytes. If the key is more than 256-bits, we trim the excess bits.
|
455 |
+
*
|
456 |
+
* If the key is not explicitly set, it'll be assumed a 128 bits key to be all null bytes.
|
457 |
+
*
|
458 |
+
* @access public
|
459 |
+
* @see Crypt_Base::setKey()
|
460 |
+
* @param String $key
|
461 |
+
*/
|
462 |
+
function setKey($key)
|
463 |
+
{
|
464 |
+
$keylength = strlen($key);
|
465 |
+
switch (true) {
|
466 |
+
case $keylength <= 16:
|
467 |
+
$key = str_pad($key, 16, "\0");
|
468 |
+
break;
|
469 |
+
case $keylength <= 24:
|
470 |
+
$key = str_pad($key, 24, "\0");
|
471 |
+
break;
|
472 |
+
case $keylength < 32:
|
473 |
+
$key = str_pad($key, 32, "\0");
|
474 |
+
break;
|
475 |
+
case $keylength > 32:
|
476 |
+
$key = substr($key, 0, 32);
|
477 |
+
}
|
478 |
+
parent::setKey($key);
|
479 |
+
}
|
480 |
+
|
481 |
+
/**
|
482 |
+
* Setup the key (expansion)
|
483 |
+
*
|
484 |
+
* @see Crypt_Base::_setupKey()
|
485 |
+
* @access private
|
486 |
+
*/
|
487 |
+
function _setupKey()
|
488 |
+
{
|
489 |
+
if (isset($this->kl['key']) && $this->key === $this->kl['key']) {
|
490 |
+
// already expanded
|
491 |
+
return;
|
492 |
+
}
|
493 |
+
$this->kl = array('key' => $this->key);
|
494 |
+
|
495 |
+
/* Key expanding and generating the key-depended s-boxes */
|
496 |
+
$le_longs = unpack('V*', $this->key);
|
497 |
+
$key = unpack('C*', $this->key);
|
498 |
+
$m0 = $this->m0;
|
499 |
+
$m1 = $this->m1;
|
500 |
+
$m2 = $this->m2;
|
501 |
+
$m3 = $this->m3;
|
502 |
+
$q0 = $this->q0;
|
503 |
+
$q1 = $this->q1;
|
504 |
+
|
505 |
+
$K = $S0 = $S1 = $S2 = $S3 = array();
|
506 |
+
|
507 |
+
switch (strlen($this->key)) {
|
508 |
+
case 16:
|
509 |
+
list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]);
|
510 |
+
list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]);
|
511 |
+
for ($i = 0, $j = 1; $i < 40; $i+= 2,$j+= 2) {
|
512 |
+
$A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^
|
513 |
+
$m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^
|
514 |
+
$m2[$q1[$q0[$i] ^ $key[11]] ^ $key[3]] ^
|
515 |
+
$m3[$q1[$q1[$i] ^ $key[12]] ^ $key[4]];
|
516 |
+
$B = $m0[$q0[$q0[$j] ^ $key[13]] ^ $key[5]] ^
|
517 |
+
$m1[$q0[$q1[$j] ^ $key[14]] ^ $key[6]] ^
|
518 |
+
$m2[$q1[$q0[$j] ^ $key[15]] ^ $key[7]] ^
|
519 |
+
$m3[$q1[$q1[$j] ^ $key[16]] ^ $key[8]];
|
520 |
+
$B = ($B << 8) | ($B >> 24 & 0xff);
|
521 |
+
$K[] = $A+= $B;
|
522 |
+
$K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff);
|
523 |
+
}
|
524 |
+
for ($i = 0; $i < 256; ++$i) {
|
525 |
+
$S0[$i] = $m0[$q0[$q0[$i] ^ $s4] ^ $s0];
|
526 |
+
$S1[$i] = $m1[$q0[$q1[$i] ^ $s5] ^ $s1];
|
527 |
+
$S2[$i] = $m2[$q1[$q0[$i] ^ $s6] ^ $s2];
|
528 |
+
$S3[$i] = $m3[$q1[$q1[$i] ^ $s7] ^ $s3];
|
529 |
+
}
|
530 |
+
break;
|
531 |
+
case 24:
|
532 |
+
list ($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]);
|
533 |
+
list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]);
|
534 |
+
list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]);
|
535 |
+
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
|
536 |
+
$A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^
|
537 |
+
$m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^
|
538 |
+
$m2[$q1[$q0[$q0[$i] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^
|
539 |
+
$m3[$q1[$q1[$q0[$i] ^ $key[20]] ^ $key[12]] ^ $key[4]];
|
540 |
+
$B = $m0[$q0[$q0[$q1[$j] ^ $key[21]] ^ $key[13]] ^ $key[5]] ^
|
541 |
+
$m1[$q0[$q1[$q1[$j] ^ $key[22]] ^ $key[14]] ^ $key[6]] ^
|
542 |
+
$m2[$q1[$q0[$q0[$j] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^
|
543 |
+
$m3[$q1[$q1[$q0[$j] ^ $key[24]] ^ $key[16]] ^ $key[8]];
|
544 |
+
$B = ($B << 8) | ($B >> 24 & 0xff);
|
545 |
+
$K[] = $A+= $B;
|
546 |
+
$K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff);
|
547 |
+
}
|
548 |
+
for ($i = 0; $i < 256; ++$i) {
|
549 |
+
$S0[$i] = $m0[$q0[$q0[$q1[$i] ^ $s8] ^ $s4] ^ $s0];
|
550 |
+
$S1[$i] = $m1[$q0[$q1[$q1[$i] ^ $s9] ^ $s5] ^ $s1];
|
551 |
+
$S2[$i] = $m2[$q1[$q0[$q0[$i] ^ $sa] ^ $s6] ^ $s2];
|
552 |
+
$S3[$i] = $m3[$q1[$q1[$q0[$i] ^ $sb] ^ $s7] ^ $s3];
|
553 |
+
}
|
554 |
+
break;
|
555 |
+
default: // 32
|
556 |
+
list ($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]);
|
557 |
+
list ($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]);
|
558 |
+
list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]);
|
559 |
+
list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]);
|
560 |
+
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
|
561 |
+
$A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^
|
562 |
+
$m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^
|
563 |
+
$m2[$q1[$q0[$q0[$q0[$i] ^ $key[27]] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^
|
564 |
+
$m3[$q1[$q1[$q0[$q1[$i] ^ $key[28]] ^ $key[20]] ^ $key[12]] ^ $key[4]];
|
565 |
+
$B = $m0[$q0[$q0[$q1[$q1[$j] ^ $key[29]] ^ $key[21]] ^ $key[13]] ^ $key[5]] ^
|
566 |
+
$m1[$q0[$q1[$q1[$q0[$j] ^ $key[30]] ^ $key[22]] ^ $key[14]] ^ $key[6]] ^
|
567 |
+
$m2[$q1[$q0[$q0[$q0[$j] ^ $key[31]] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^
|
568 |
+
$m3[$q1[$q1[$q0[$q1[$j] ^ $key[32]] ^ $key[24]] ^ $key[16]] ^ $key[8]];
|
569 |
+
$B = ($B << 8) | ($B >> 24 & 0xff);
|
570 |
+
$K[] = $A+= $B;
|
571 |
+
$K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff);
|
572 |
+
}
|
573 |
+
for ($i = 0; $i < 256; ++$i) {
|
574 |
+
$S0[$i] = $m0[$q0[$q0[$q1[$q1[$i] ^ $sc] ^ $s8] ^ $s4] ^ $s0];
|
575 |
+
$S1[$i] = $m1[$q0[$q1[$q1[$q0[$i] ^ $sd] ^ $s9] ^ $s5] ^ $s1];
|
576 |
+
$S2[$i] = $m2[$q1[$q0[$q0[$q0[$i] ^ $se] ^ $sa] ^ $s6] ^ $s2];
|
577 |
+
$S3[$i] = $m3[$q1[$q1[$q0[$q1[$i] ^ $sf] ^ $sb] ^ $s7] ^ $s3];
|
578 |
+
}
|
579 |
+
}
|
580 |
+
|
581 |
+
$this->K = $K;
|
582 |
+
$this->S0 = $S0;
|
583 |
+
$this->S1 = $S1;
|
584 |
+
$this->S2 = $S2;
|
585 |
+
$this->S3 = $S3;
|
586 |
+
}
|
587 |
+
|
588 |
+
/**
|
589 |
+
* _mdsrem function using by the twofish cipher algorithm
|
590 |
+
*
|
591 |
+
* @access private
|
592 |
+
* @param String $A
|
593 |
+
* @param String $B
|
594 |
+
* @return Array
|
595 |
+
*/
|
596 |
+
function _mdsrem($A, $B)
|
597 |
+
{
|
598 |
+
// No gain by unrolling this loop.
|
599 |
+
for ($i = 0; $i < 8; ++$i) {
|
600 |
+
// Get most significant coefficient.
|
601 |
+
$t = 0xff & ($B >> 24);
|
602 |
+
|
603 |
+
// Shift the others up.
|
604 |
+
$B = ($B << 8) | (0xff & ($A >> 24));
|
605 |
+
$A<<= 8;
|
606 |
+
|
607 |
+
$u = $t << 1;
|
608 |
+
|
609 |
+
// Subtract the modular polynomial on overflow.
|
610 |
+
if ($t & 0x80) {
|
611 |
+
$u^= 0x14d;
|
612 |
+
}
|
613 |
+
|
614 |
+
// Remove t * (a * x^2 + 1).
|
615 |
+
$B ^= $t ^ ($u << 16);
|
616 |
+
|
617 |
+
// Form u = a*t + t/a = t*(a + 1/a).
|
618 |
+
$u^= 0x7fffffff & ($t >> 1);
|
619 |
+
|
620 |
+
// Add the modular polynomial on underflow.
|
621 |
+
if ($t & 0x01) $u^= 0xa6 ;
|
622 |
+
|
623 |
+
// Remove t * (a + 1/a) * (x^3 + x).
|
624 |
+
$B^= ($u << 24) | ($u << 8);
|
625 |
+
}
|
626 |
+
|
627 |
+
return array(
|
628 |
+
0xff & $B >> 24,
|
629 |
+
0xff & $B >> 16,
|
630 |
+
0xff & $B >> 8,
|
631 |
+
0xff & $B);
|
632 |
+
}
|
633 |
+
|
634 |
+
/**
|
635 |
+
* Encrypts a block
|
636 |
+
*
|
637 |
+
* @access private
|
638 |
+
* @param String $in
|
639 |
+
* @return String
|
640 |
+
*/
|
641 |
+
function _encryptBlock($in)
|
642 |
+
{
|
643 |
+
$S0 = $this->S0;
|
644 |
+
$S1 = $this->S1;
|
645 |
+
$S2 = $this->S2;
|
646 |
+
$S3 = $this->S3;
|
647 |
+
$K = $this->K;
|
648 |
+
|
649 |
+
$in = unpack("V4", $in);
|
650 |
+
$R0 = $K[0] ^ $in[1];
|
651 |
+
$R1 = $K[1] ^ $in[2];
|
652 |
+
$R2 = $K[2] ^ $in[3];
|
653 |
+
$R3 = $K[3] ^ $in[4];
|
654 |
+
|
655 |
+
$ki = 7;
|
656 |
+
while ($ki < 39) {
|
657 |
+
$t0 = $S0[ $R0 & 0xff] ^
|
658 |
+
$S1[($R0 >> 8) & 0xff] ^
|
659 |
+
$S2[($R0 >> 16) & 0xff] ^
|
660 |
+
$S3[($R0 >> 24) & 0xff];
|
661 |
+
$t1 = $S0[($R1 >> 24) & 0xff] ^
|
662 |
+
$S1[ $R1 & 0xff] ^
|
663 |
+
$S2[($R1 >> 8) & 0xff] ^
|
664 |
+
$S3[($R1 >> 16) & 0xff];
|
665 |
+
$R2^= $t0 + $t1 + $K[++$ki];
|
666 |
+
$R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31);
|
667 |
+
$R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]);
|
668 |
+
|
669 |
+
$t0 = $S0[ $R2 & 0xff] ^
|
670 |
+
$S1[($R2 >> 8) & 0xff] ^
|
671 |
+
$S2[($R2 >> 16) & 0xff] ^
|
672 |
+
$S3[($R2 >> 24) & 0xff];
|
673 |
+
$t1 = $S0[($R3 >> 24) & 0xff] ^
|
674 |
+
$S1[ $R3 & 0xff] ^
|
675 |
+
$S2[($R3 >> 8) & 0xff] ^
|
676 |
+
$S3[($R3 >> 16) & 0xff];
|
677 |
+
$R0^= ($t0 + $t1 + $K[++$ki]);
|
678 |
+
$R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31);
|
679 |
+
$R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]);
|
680 |
+
}
|
681 |
+
|
682 |
+
// @codingStandardsIgnoreStart
|
683 |
+
return pack("V4", $K[4] ^ $R2,
|
684 |
+
$K[5] ^ $R3,
|
685 |
+
$K[6] ^ $R0,
|
686 |
+
$K[7] ^ $R1);
|
687 |
+
// @codingStandardsIgnoreEnd
|
688 |
+
}
|
689 |
+
|
690 |
+
/**
|
691 |
+
* Decrypts a block
|
692 |
+
*
|
693 |
+
* @access private
|
694 |
+
* @param String $in
|
695 |
+
* @return String
|
696 |
+
*/
|
697 |
+
function _decryptBlock($in)
|
698 |
+
{
|
699 |
+
$S0 = $this->S0;
|
700 |
+
$S1 = $this->S1;
|
701 |
+
$S2 = $this->S2;
|
702 |
+
$S3 = $this->S3;
|
703 |
+
$K = $this->K;
|
704 |
+
|
705 |
+
$in = unpack("V4", $in);
|
706 |
+
$R0 = $K[4] ^ $in[1];
|
707 |
+
$R1 = $K[5] ^ $in[2];
|
708 |
+
$R2 = $K[6] ^ $in[3];
|
709 |
+
$R3 = $K[7] ^ $in[4];
|
710 |
+
|
711 |
+
$ki = 40;
|
712 |
+
while ($ki > 8) {
|
713 |
+
$t0 = $S0[$R0 & 0xff] ^
|
714 |
+
$S1[$R0 >> 8 & 0xff] ^
|
715 |
+
$S2[$R0 >> 16 & 0xff] ^
|
716 |
+
$S3[$R0 >> 24 & 0xff];
|
717 |
+
$t1 = $S0[$R1 >> 24 & 0xff] ^
|
718 |
+
$S1[$R1 & 0xff] ^
|
719 |
+
$S2[$R1 >> 8 & 0xff] ^
|
720 |
+
$S3[$R1 >> 16 & 0xff];
|
721 |
+
$R3^= $t0 + ($t1 << 1) + $K[--$ki];
|
722 |
+
$R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31;
|
723 |
+
$R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + $K[--$ki]);
|
724 |
+
|
725 |
+
$t0 = $S0[$R2 & 0xff] ^
|
726 |
+
$S1[$R2 >> 8 & 0xff] ^
|
727 |
+
$S2[$R2 >> 16 & 0xff] ^
|
728 |
+
$S3[$R2 >> 24 & 0xff];
|
729 |
+
$t1 = $S0[$R3 >> 24 & 0xff] ^
|
730 |
+
$S1[$R3 & 0xff] ^
|
731 |
+
$S2[$R3 >> 8 & 0xff] ^
|
732 |
+
$S3[$R3 >> 16 & 0xff];
|
733 |
+
$R1^= $t0 + ($t1 << 1) + $K[--$ki];
|
734 |
+
$R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31;
|
735 |
+
$R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + $K[--$ki]);
|
736 |
+
}
|
737 |
+
|
738 |
+
// @codingStandardsIgnoreStart
|
739 |
+
return pack("V4", $K[0] ^ $R2,
|
740 |
+
$K[1] ^ $R3,
|
741 |
+
$K[2] ^ $R0,
|
742 |
+
$K[3] ^ $R1);
|
743 |
+
// @codingStandardsIgnoreEnd
|
744 |
+
}
|
745 |
+
|
746 |
+
/**
|
747 |
+
* Setup the performance-optimized function for de/encrypt()
|
748 |
+
*
|
749 |
+
* @see Crypt_Base::_setupInlineCrypt()
|
750 |
+
* @access private
|
751 |
+
*/
|
752 |
+
function _setupInlineCrypt()
|
753 |
+
{
|
754 |
+
$lambda_functions =& Crypt_Twofish::_getLambdaFunctions();
|
755 |
+
|
756 |
+
// Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one.
|
757 |
+
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
|
758 |
+
|
759 |
+
switch (true) {
|
760 |
+
case $gen_hi_opt_code:
|
761 |
+
$code_hash = md5(str_pad("Crypt_Twofish, {$this->mode}, ", 32, "\0") . $this->key);
|
762 |
+
break;
|
763 |
+
default:
|
764 |
+
$code_hash = "Crypt_Twofish, {$this->mode}";
|
765 |
+
}
|
766 |
+
|
767 |
+
if (!isset($lambda_functions[$code_hash])) {
|
768 |
+
switch (true) {
|
769 |
+
case $gen_hi_opt_code:
|
770 |
+
$K = $this->K;
|
771 |
+
|
772 |
+
$init_crypt = '
|
773 |
+
static $S0, $S1, $S2, $S3;
|
774 |
+
if (!$S0) {
|
775 |
+
for ($i = 0; $i < 256; ++$i) {
|
776 |
+
$S0[] = (int)$self->S0[$i];
|
777 |
+
$S1[] = (int)$self->S1[$i];
|
778 |
+
$S2[] = (int)$self->S2[$i];
|
779 |
+
$S3[] = (int)$self->S3[$i];
|
780 |
+
}
|
781 |
+
}
|
782 |
+
';
|
783 |
+
break;
|
784 |
+
default:
|
785 |
+
$K = array();
|
786 |
+
for ($i = 0; $i < 40; ++$i) {
|
787 |
+
$K[] = '$K_' . $i;
|
788 |
+
}
|
789 |
+
|
790 |
+
$init_crypt = '
|
791 |
+
$S0 = $self->S0;
|
792 |
+
$S1 = $self->S1;
|
793 |
+
$S2 = $self->S2;
|
794 |
+
$S3 = $self->S3;
|
795 |
+
list(' . implode(',', $K) . ') = $self->K;
|
796 |
+
';
|
797 |
+
}
|
798 |
+
|
799 |
+
// Generating encrypt code:
|
800 |
+
$encrypt_block = '
|
801 |
+
$in = unpack("V4", $in);
|
802 |
+
$R0 = '.$K[0].' ^ $in[1];
|
803 |
+
$R1 = '.$K[1].' ^ $in[2];
|
804 |
+
$R2 = '.$K[2].' ^ $in[3];
|
805 |
+
$R3 = '.$K[3].' ^ $in[4];
|
806 |
+
';
|
807 |
+
for ($ki = 7, $i = 0; $i < 8; ++$i) {
|
808 |
+
$encrypt_block.= '
|
809 |
+
$t0 = $S0[ $R0 & 0xff] ^
|
810 |
+
$S1[($R0 >> 8) & 0xff] ^
|
811 |
+
$S2[($R0 >> 16) & 0xff] ^
|
812 |
+
$S3[($R0 >> 24) & 0xff];
|
813 |
+
$t1 = $S0[($R1 >> 24) & 0xff] ^
|
814 |
+
$S1[ $R1 & 0xff] ^
|
815 |
+
$S2[($R1 >> 8) & 0xff] ^
|
816 |
+
$S3[($R1 >> 16) & 0xff];
|
817 |
+
$R2^= ($t0 + $t1 + '.$K[++$ki].');
|
818 |
+
$R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31);
|
819 |
+
$R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].');
|
820 |
+
|
821 |
+
$t0 = $S0[ $R2 & 0xff] ^
|
822 |
+
$S1[($R2 >> 8) & 0xff] ^
|
823 |
+
$S2[($R2 >> 16) & 0xff] ^
|
824 |
+
$S3[($R2 >> 24) & 0xff];
|
825 |
+
$t1 = $S0[($R3 >> 24) & 0xff] ^
|
826 |
+
$S1[ $R3 & 0xff] ^
|
827 |
+
$S2[($R3 >> 8) & 0xff] ^
|
828 |
+
$S3[($R3 >> 16) & 0xff];
|
829 |
+
$R0^= ($t0 + $t1 + '.$K[++$ki].');
|
830 |
+
$R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31);
|
831 |
+
$R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].');
|
832 |
+
';
|
833 |
+
}
|
834 |
+
$encrypt_block.= '
|
835 |
+
$in = pack("V4", '.$K[4].' ^ $R2,
|
836 |
+
'.$K[5].' ^ $R3,
|
837 |
+
'.$K[6].' ^ $R0,
|
838 |
+
'.$K[7].' ^ $R1);
|
839 |
+
';
|
840 |
+
|
841 |
+
// Generating decrypt code:
|
842 |
+
$decrypt_block = '
|
843 |
+
$in = unpack("V4", $in);
|
844 |
+
$R0 = '.$K[4].' ^ $in[1];
|
845 |
+
$R1 = '.$K[5].' ^ $in[2];
|
846 |
+
$R2 = '.$K[6].' ^ $in[3];
|
847 |
+
$R3 = '.$K[7].' ^ $in[4];
|
848 |
+
';
|
849 |
+
for ($ki = 40, $i = 0; $i < 8; ++$i) {
|
850 |
+
$decrypt_block.= '
|
851 |
+
$t0 = $S0[$R0 & 0xff] ^
|
852 |
+
$S1[$R0 >> 8 & 0xff] ^
|
853 |
+
$S2[$R0 >> 16 & 0xff] ^
|
854 |
+
$S3[$R0 >> 24 & 0xff];
|
855 |
+
$t1 = $S0[$R1 >> 24 & 0xff] ^
|
856 |
+
$S1[$R1 & 0xff] ^
|
857 |
+
$S2[$R1 >> 8 & 0xff] ^
|
858 |
+
$S3[$R1 >> 16 & 0xff];
|
859 |
+
$R3^= $t0 + ($t1 << 1) + '.$K[--$ki].';
|
860 |
+
$R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31;
|
861 |
+
$R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + '.$K[--$ki].');
|
862 |
+
|
863 |
+
$t0 = $S0[$R2 & 0xff] ^
|
864 |
+
$S1[$R2 >> 8 & 0xff] ^
|
865 |
+
$S2[$R2 >> 16 & 0xff] ^
|
866 |
+
$S3[$R2 >> 24 & 0xff];
|
867 |
+
$t1 = $S0[$R3 >> 24 & 0xff] ^
|
868 |
+
$S1[$R3 & 0xff] ^
|
869 |
+
$S2[$R3 >> 8 & 0xff] ^
|
870 |
+
$S3[$R3 >> 16 & 0xff];
|
871 |
+
$R1^= $t0 + ($t1 << 1) + '.$K[--$ki].';
|
872 |
+
$R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31;
|
873 |
+
$R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + '.$K[--$ki].');
|
874 |
+
';
|
875 |
+
}
|
876 |
+
$decrypt_block.= '
|
877 |
+
$in = pack("V4", '.$K[0].' ^ $R2,
|
878 |
+
'.$K[1].' ^ $R3,
|
879 |
+
'.$K[2].' ^ $R0,
|
880 |
+
'.$K[3].' ^ $R1);
|
881 |
+
';
|
882 |
+
|
883 |
+
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
|
884 |
+
array(
|
885 |
+
'init_crypt' => $init_crypt,
|
886 |
+
'init_encrypt' => '',
|
887 |
+
'init_decrypt' => '',
|
888 |
+
'encrypt_block' => $encrypt_block,
|
889 |
+
'decrypt_block' => $decrypt_block
|
890 |
+
)
|
891 |
+
);
|
892 |
+
}
|
893 |
+
$this->inline_crypt = $lambda_functions[$code_hash];
|
894 |
+
}
|
895 |
+
}
|
2.0/includes/vendor/MchCrypt/PhpSecLib-0.3.10/File/ANSI.php
ADDED
@@ -0,0 +1,559 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Pure-PHP ANSI Decoder
|
5 |
+
*
|
6 |
+
* PHP versions 4 and 5
|
7 |
+
*
|
8 |
+
* If you call read() in Net_SSH2 you may get {@link http://en.wikipedia.org/wiki/ANSI_escape_code ANSI escape codes} back.
|
9 |
+
* They'd look like chr(0x1B) . '[00m' or whatever (0x1B = ESC). They tell a
|
10 |
+
* {@link http://en.wikipedia.org/wiki/Terminal_emulator terminal emulator} how to format the characters, what
|
11 |
+
* color to display them in, etc. File_ANSI is a {@link http://en.wikipedia.org/wiki/VT100 VT100} terminal emulator.
|
12 |
+
*
|
13 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
14 |
+
* of this software and associated documentation files (the "Software"), to deal
|
15 |
+
* in the Software without restriction, including without limitation the rights
|
16 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17 |
+
* copies of the Software, and to permit persons to whom the Software is
|
18 |
+
* furnished to do so, subject to the following conditions:
|
19 |
+
*
|
20 |
+
* The above copyright notice and this permission notice shall be included in
|
21 |
+
* all copies or substantial portions of the Software.
|
22 |
+
*
|
23 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
29 |
+
* THE SOFTWARE.
|
30 |
+
*
|
31 |
+
* @category File
|
32 |
+
* @package File_ANSI
|
33 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
34 |
+
* @copyright 2012 Jim Wigginton
|
35 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
36 |
+
* @link http://phpseclib.sourceforge.net
|
37 |
+
*/
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Pure-PHP ANSI Decoder
|
41 |
+
*
|
42 |
+
* @package File_ANSI
|
43 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
44 |
+
* @access public
|
45 |
+
*/
|
46 |
+
class File_ANSI
|
47 |
+
{
|
48 |
+
/**
|
49 |
+
* Max Width
|
50 |
+
*
|
51 |
+
* @var Integer
|
52 |
+
* @access private
|
53 |
+
*/
|
54 |
+
var $max_x;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Max Height
|
58 |
+
*
|
59 |
+
* @var Integer
|
60 |
+
* @access private
|
61 |
+
*/
|
62 |
+
var $max_y;
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Max History
|
66 |
+
*
|
67 |
+
* @var Integer
|
68 |
+
* @access private
|
69 |
+
*/
|
70 |
+
var $max_history;
|
71 |
+
|
72 |
+
/**
|
73 |
+
* History
|
74 |
+
*
|
75 |
+
* @var Array
|
76 |
+
* @access private
|
77 |
+
*/
|
78 |
+
var $history;
|
79 |
+
|
80 |
+
/**
|
81 |
+
* History Attributes
|
82 |
+
*
|
83 |
+
* @var Array
|
84 |
+
* @access private
|
85 |
+
*/
|
86 |
+
var $history_attrs;
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Current Column
|
90 |
+
*
|
91 |
+
* @var Integer
|
92 |
+
* @access private
|
93 |
+
*/
|
94 |
+
var $x;
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Current Row
|
98 |
+
*
|
99 |
+
* @var Integer
|
100 |
+
* @access private
|
101 |
+
*/
|
102 |
+
var $y;
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Old Column
|
106 |
+
*
|
107 |
+
* @var Integer
|
108 |
+
* @access private
|
109 |
+
*/
|
110 |
+
var $old_x;
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Old Row
|
114 |
+
*
|
115 |
+
* @var Integer
|
116 |
+
* @access private
|
117 |
+
*/
|
118 |
+
var $old_y;
|
119 |
+
|
120 |
+
/**
|
121 |
+
* An empty attribute row
|
122 |
+
*
|
123 |
+
* @var Array
|
124 |
+
* @access private
|
125 |
+
*/
|
126 |
+
var $attr_row;
|
127 |
+
|
128 |
+
/**
|
129 |
+
* The current screen text
|
130 |
+
*
|
131 |
+
* @var Array
|
132 |
+
* @access private
|
133 |
+
*/
|
134 |
+
var $screen;
|
135 |
+
|
136 |
+
/**
|
137 |
+
* The current screen attributes
|
138 |
+
*
|
139 |
+
* @var Array
|
140 |
+
* @access private
|
141 |
+
*/
|
142 |
+
var $attrs;
|
143 |
+
|
144 |
+
/**
|
145 |
+
* The current foreground color
|
146 |
+
*
|
147 |
+
* @var String
|
148 |
+
* @access private
|
149 |
+
*/
|
150 |
+
var $foreground;
|
151 |
+
|
152 |
+
/**
|