Subversion Repositories oidplus

Rev

Rev 148 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. if (!defined('IN_OIDPLUS')) die();
  21.  
  22. class OIDplusPagePublicRaInfo extends OIDplusPagePlugin {
  23.         public function type() {
  24.                 return 'public';
  25.         }
  26.  
  27.         public function priority() {
  28.                 return 93;
  29.         }
  30.  
  31.         public function action(&$handled) {
  32.         }
  33.  
  34.         public function init($html=true) {
  35.         }
  36.  
  37.         public function cfgSetValue($name, $value) {
  38.         }
  39.  
  40.         public function gui($id, &$out, &$handled) {
  41.                 if (explode('$',$id)[0] == 'oidplus:rainfo') {
  42.                         $handled = true;
  43.  
  44.                         $ra_email = explode('$',$id)[1];
  45.                         $ra_email = str_replace('&', '@', $ra_email);
  46.  
  47.                         $out['title'] = 'Registration Authority Information'; // TODO: email addresse reinschreiben? aber wie vor anti spam schützen?
  48.                         $out['icon'] = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/rainfo_big.png';
  49.  
  50.                         if (empty($ra_email)) {
  51.                                 $out['text'] = '<p>Following object roots have an undefined Registration Authority:</p>';
  52.                         } else {
  53.                                 $out['text'] = $this->showRAInfo($ra_email);
  54.                         }
  55.  
  56.                         $out['text'] .= '<br><br>';
  57.  
  58.                         foreach (OIDplusObject::getRaRoots($ra_email) as $loc_root) {
  59.                                 $ico = $loc_root->getIcon();
  60.                                 $icon = !is_null($ico) ? $ico : 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon_link.png';
  61.                                 $out['text'] .= '<p><a '.oidplus_link($loc_root->nodeId()).'><img src="'.$icon.'"> Jump to RA root '.$loc_root->objectTypeTitleShort().' '.$loc_root->crudShowId(OIDplusObject::parse($loc_root::root())).'</a></p>';
  62.                         }
  63.  
  64.                         if (!empty($ra_email)) {
  65.                                 if (OIDplus::authUtils()::isRALoggedIn($ra_email)) {
  66.                                         $out['text'] .= '<br><p><a '.oidplus_link('oidplus:edit_ra$'.$ra_email).'>Edit contact info</a></p>';
  67.                                 }
  68.  
  69.                                 if (OIDplus::authUtils()::isAdminLoggedIn()) {
  70.                                         $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($ra_email));
  71.                                         if (OIDplus::db()->num_rows($res) > 0) {
  72.                                                 if (class_exists("OIDplusPageAdminListRAs")) {
  73.                                                         $out['text'] .= '<br><p><a href="#" onclick="return deleteRa('.js_escape($ra_email).','.js_escape('oidplus:list_ra').')">Delete this RA</a></p>';
  74.                                                 } else {
  75.                                                         $out['text'] .= '<br><p><a href="#" onclick="return deleteRa('.js_escape($ra_email).','.js_escape('oidplus:system').')">Delete this RA</a></p>';
  76.                                                 }
  77.                                         }
  78.                                 }
  79.  
  80.                                 if (OIDplus::authUtils()::isRALoggedIn($ra_email) || OIDplus::authUtils()::isAdminLoggedIn()) {
  81.                                         $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event from ".OIDPLUS_TABLENAME_PREFIX."log lo ".
  82.                                                                     "left join ".OIDPLUS_TABLENAME_PREFIX."log_user lu on lu.log_id = lo.id ".
  83.                                                                     "where lu.user = ? " .
  84.                                                                     "order by lo.unix_ts desc", array($ra_email));
  85.                                         $out['text'] .= '<h2>Log messages for RA '.htmlentities($ra_email).'</h2>';
  86.                                         if (OIDplus::db()->num_rows($res) > 0) {
  87.                                                 $out['text'] .= '<pre>';
  88.                                                 while ($row = OIDplus::db()->fetch_array($res)) {
  89.                                                         $addr = empty($row['addr']) ? 'no address' : $row['addr'];
  90.  
  91.                                                         $out['text'] .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")\n";
  92.                                                 }
  93.                                                 $out['text'] .= '</pre>';
  94.  
  95.                                                 // TODO: List logs in a table instead of a <pre> text
  96.                                                 // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
  97.                                         } else {
  98.                                                 $out['text'] .= '<p>Currently there are no log entries</p>';
  99.                                         }
  100.                                 }
  101.                         }
  102.                 }
  103.         }
  104.  
  105.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  106.                 return false;
  107.         }
  108.  
  109.         public static function showRAInfo($email) {
  110.                 $out = '';
  111.  
  112.                 if (empty($email)) {
  113.                         $out = '<p>The superior RA did not define a RA for this OID.</p>';
  114.                         return $out;
  115.                 }
  116.  
  117.                 $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($email));
  118.                 if (OIDplus::db()->num_rows($res) === 0) {
  119.                         $out = '<p>The RA <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a> is not registered in the database.</p>';
  120.  
  121.                 } else {
  122.                         $row = OIDplus::db()->fetch_array($res);
  123.                         $out = '<b>'.htmlentities($row['ra_name']).'</b><br>';
  124.                         $out .= 'E-Mail: <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a><br>';
  125.                         if (trim($row['personal_name']) !== '') $out .= htmlentities($row['personal_name']).'<br>';
  126.                         if (trim($row['organization']) !== '') $out .= htmlentities($row['organization']).'<br>';
  127.                         if (trim($row['office']) !== '') $out .= htmlentities($row['office']).'<br>';
  128.                         if ($row['privacy']) {
  129.                                 // TODO: meldung nur anzeigen, wenn benutzer überhaupt straße, adresse etc hat
  130.                                 // TODO: aber der admin soll es sehen, und der user selbst (mit anmerkung, dass es privat ist)
  131.                                 $out .= '<p>The RA does not want to publish their personal information.</p>';
  132.                         } else {
  133.                                 if (trim($row['street']) !== '') $out .= htmlentities($row['street']).'<br>';
  134.                                 if (trim($row['zip_town']) !== '') $out .= htmlentities($row['zip_town']).'<br>';
  135.                                 if (trim($row['country']) !== '') $out .= htmlentities($row['country']).'<br>';
  136.                                 $out .= '<br>';
  137.                                 if (trim($row['phone']) !== '') $out .= htmlentities($row['phone']).'<br>';
  138.                                 if (trim($row['fax']) !== '') $out .= htmlentities($row['fax']).'<br>';
  139.                                 if (trim($row['mobile']) !== '') $out .= htmlentities($row['mobile']).'<br>';
  140.                                 $out .= '<br>';
  141.                         }
  142.                 }
  143.  
  144.                 return trim_br($out);
  145.         }
  146.  
  147.         public function tree_search($request) {
  148.                 return false;
  149.         }
  150. }
  151.  
  152. OIDplus::registerPagePlugin(new OIDplusPagePublicRaInfo());
  153.