IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42202


Ignore:
Timestamp:
May 17, 2022, 3:21:12 PM (4 years ago)
Author:
eugene
Message:

PHP 7 compatibility: ensure strings are protected with single quotes; use isset() instead of implicit check; add PDO database interface as option

Location:
branches/eam_branches/ipp-20220316/ippMonitor/raw
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/Login.php

    r25308 r42202  
    33include 'ipp.php';
    44
    5 if (($_SERVER[REQUEST_METHOD] != 'POST') && ($_SERVER[REQUEST_METHOD] != 'GET')) {
     5if (($_SERVER['REQUEST_METHOD'] != 'POST') && ($_SERVER['REQUEST_METHOD'] != 'GET')) {
    66  menu ('ipp.menu.dat', 'Login', 'ipp.css', '', '');
    77  echo "Invalid Client Request<br>\n";
     
    1010}
    1111
    12 if ($_SERVER[REQUEST_METHOD] == 'GET') {
     12if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    1313
    1414  $ID = checkID ();
     
    2929}
    3030
    31 if ($_SERVER[REQUEST_METHOD] == 'POST') {
    32   if (key_exists (login, $_POST)) {
     31if ($_SERVER['REQUEST_METHOD'] == 'POST') {
     32  if (key_exists ('login', $_POST)) {
    3333
    3434    $ID = checkLogin ();
     
    4040  }
    4141
    42   if (key_exists (logout, $_POST)) {
     42  if (key_exists ('logout', $_POST)) {
    4343    menu ('ipp.menu.dat', 'Login', 'ipp.css', '', '');
    4444    echo "You are now logged out<br>\n";
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/SelectProject.php

    r9439 r42202  
    33include 'ipp.php';
    44
    5 if (($_SERVER[REQUEST_METHOD] != 'POST') && ($_SERVER[REQUEST_METHOD] != 'GET')) {
     5if (($_SERVER['REQUEST_METHOD'] != 'POST') && ($_SERVER['REQUEST_METHOD'] != 'GET')) {
    66  menu ('ipp.menu.dat', 'Select Project', 'ipp.css', '', '');
    77  echo "Invalid Client Request<br>\n";
     
    1212$ID = checkID ();
    1313
    14 if ($_SERVER[REQUEST_METHOD] == 'GET') {
     14if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    1515  projectform ($ID);
    1616}
    1717
    18 if ($_SERVER[REQUEST_METHOD] == 'POST') {
     18if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    1919
    2020  if (key_exists (project, $_POST)) {
    21     $myProj = $_POST[proj];
     21    $myProj = $_POST['proj'];
    2222    $ID['proj'] = $myProj;
    2323    // validate the existence of the project
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/czartool_getplot.php

    r40840 r42202  
    88
    99### we must have been past arguments with GET:
    10 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     10if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    1111    exit ();
    1212}
    1313
    14 $mode = $_GET[mode];
    15 $type = $_GET[type];
    16 $label = $_GET[label];
    17 $stage = $_GET[stage];
    18 $plottype = $_GET[plottype];
     14$mode = $_GET['mode'];
     15$type = $_GET['type'];
     16$label = $_GET['label'];
     17$stage = $_GET['stage'];
     18$plottype = $_GET['plottype'];
    1919
    20 $proj = $_GET[proj];
     20$proj = $_GET['proj'];
    2121
    2222$path = $CZARPLOTDIR;
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/getlog.php

    r41730 r42202  
    99// load an image file from the image directory
    1010// validate request
    11 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     11if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    1212  exit ();
    1313}
     
    2020
    2121# $basename may contain filename@filerule
    22 $basename = strtok($_GET[name],"@");
     22$basename = strtok($_GET['name'],"@");
    2323$filerule = strtok("@");
    2424
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/ipp.php

    r41730 r42202  
    2626
    2727  menu ('ipp.menu.dat', 'Select Project', 'ipp.css', $ID['link'], $ID['proj']);
    28   if ($_GET['new'] && $_GET['proj']) {
     28  if (isset($_GET['new']) && isset($_GET['proj'])) {
    2929    echo "<p> Project is now <b>" . $_GET['proj'] . "</b></p>\n";
    3030  }
     
    6666  global $DBI;
    6767
     68  if ($DBI == "PDO") {
     69    $result = $qry->fetch();
     70    if ($result == NULL) {
     71      $success = 0;
     72    } else {
     73      $success = 1;
     74    }
     75  }
    6876  if ($DBI == "MDB2") {
    6977    $result = $qry->fetchRow();
     
    9098  global $CZARDBHOST;
    9199
     100  // define the DSN strings. NOTE: PDO uses a different format from DB or MDB2
     101  if ($database == $CZARDBNAME) {
     102    $dsn_pdo = "mysql:host=$DBHOST;dbname=$database";
     103    $dsn = "mysql://$DBUSER:$DBPASS@$CZARDBHOST/$database";
     104    $dsnerr = "mysql://$DBUSER:XXX@$CZARDBHOST/$database"; // only used to report the error
     105  } else {
     106    $dsn_pdo = "mysql:host=$CZARDBHOST;dbname=$database"; // note this is case sensitive
     107    $dsn = "mysql://$DBUSER:$DBPASS@$DBHOST/$database";
     108    $dsnerr = "mysql://$DBUSER:XXX@$DBHOST/$database"; // only used to report the error
     109  }
     110
     111  // PDO has a different error handling method initially (throw exception)
     112  // but after construction can be set to match DB & MDB2
     113  if ($DBI == "PDO") {
     114    try {
     115      $db = new PDO($dsn_pdo, $DBUSER, $DBPASS);
     116      $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     117    } catch (PDOException $dberr) {
     118      dbconnectFailure($dberr, $dsnerr);
     119    }
     120    return $db;
     121  }
     122
    92123  $success = 0;
    93124  if ($DBI == "MDB2") {
     
    104135  }
    105136
    106   // connect to the database
    107   if ($database == $CZARDBNAME) {
    108     $dsn = "mysql://$DBUSER:$DBPASS@$CZARDBHOST/$database";
    109     $dsnerr = "mysql://$DBUSER:XXX@$CZARDBHOST/$database"; // only used to report the error
    110   } else {
    111     $dsn = "mysql://$DBUSER:$DBPASS@$DBHOST/$database";
    112     $dsnerr = "mysql://$DBUSER:XXX@$DBHOST/$database"; // only used to report the error
    113   }
    114137  if ($DBI == "DB") {
    115138    $db = DB::connect($dsn);
     
    118141    $db = MDB2::connect($dsn);
    119142  }
    120 
    121143  if (dberror($db)) {
    122     echo "<b>error accessing database</b><br>\n";
    123     echo "<b>tried $dsnerr</b><br>\n";
    124     $result = $db->getMessage();
    125     echo "$result<br>";
    126     menu_end();
     144    dbconnectFailure($db, $dsnerr);
    127145  }
    128146  return $db;
    129147}
    130148
     149function dbconnectFailure($db, $dsnerr) {
     150  echo "<b>error accessing database</b><br>\n";
     151  echo "<b>tried $dsnerr</b><br>\n";
     152  $result = $db->getMessage();
     153  echo "$result<br>";
     154  menu_end();
     155}
     156
     157# return true/false for an error
    131158function dberror ($db) {
    132159  global $DBI;
     
    137164  if ($DBI == "DB") {
    138165    $dberr = DB::isError($db);
     166  }
     167  if ($DBI == "PDO") {
     168    if ($db == null) {
     169      $dberr = 1;
     170    } else {
     171      $dberr = 0;
     172    }
    139173  }
    140174
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/plotHistogram.php

    r41730 r42202  
    1212
    1313### we must have been past arguments with GET:
    14 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     14if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    1515  exit ();
    1616}
     
    4343}
    4444
    45 $infile  = $_GET[input];
    46 $outfile = $_GET[output];
    47 $title = $_GET[title];
     45$infile  = $_GET['input'];
     46$outfile = $_GET['output'];
     47$title = $_GET['title'];
    4848
    4949if ($debug) {
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/scatterPlot.php

    r41730 r42202  
    1212
    1313### we must have been past arguments with GET:
    14 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     14if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    1515  exit ();
    1616}
     
    4343}
    4444
    45 $infile  = $_GET[input];
    46 $outfile = $_GET[output];
    47 $title = $_GET[title];
     45$infile  = $_GET['input'];
     46$outfile = $_GET['output'];
     47$title = $_GET['title'];
    4848
    4949$title = preg_replace("/'/", "", $title);
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/show_and_delete_image.php

    r28433 r42202  
    22
    33### we must have been past arguments with GET:
    4 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     4if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    55  exit ();
    66}
    77
    8 $filename = $_GET[file];
     8$filename = $_GET['file'];
    99
    1010$file = fopen ($filename, "r");
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/show_log.php

    r41730 r42202  
    55include 'site.php';
    66
    7 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     7if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    88  exit ();
    99}
     
    1313putenv("PATH=$WWWBIN:$BINDIR:$PATH");
    1414
    15 $basename = $_GET[basename];
     15$basename = $_GET['basename'];
    1616$basename = escapeshellarg($basename);
    1717
    18 $state = $_GET[state];
     18$state = $_GET['state'];
    1919$state = escapeshellarg($state);
    2020if (!$state) $state = 'new';
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/showimage.php

    r27054 r42202  
    1111// load an image file from the image directory
    1212// validate request
    13 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     13if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    1414  exit ();
    1515}
     
    2020
    2121# $basename may contain filename@filerule
    22 $basename = $_GET[name];
    23 $filerule = $_GET[rule];
    24 $camera   = $_GET[camera];
    25 $class_id = $_GET[class_id];
     22$basename = $_GET['name'];
     23$filerule = $_GET['rule'];
     24$camera   = $_GET['camera'];
     25$class_id = $_GET['class_id'];
    2626
    2727$title = $basename;
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/skycellplot.php

    r41730 r42202  
    1313
    1414### we must have been past arguments with GET:
    15 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     15if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    1616  exit ();
    1717}
     
    4444}
    4545
    46 $infile  = $_GET[input];
    47 $outfile = $_GET[output];
     46$infile  = $_GET['input'];
     47$outfile = $_GET['output'];
    4848
    4949$output = shell_exec("skycellplot.dvo $infile $outfile");//, $output, $status);
  • branches/eam_branches/ipp-20220316/ippMonitor/raw/skyplot.php

    r41730 r42202  
    2323
    2424### we must have been passed arguments with GET:
    25 if ($_SERVER[REQUEST_METHOD] != 'GET') {
     25if ($_SERVER['REQUEST_METHOD'] != 'GET') {
    2626  exit ();
    2727}
     
    5454}
    5555
    56 $infile  = $_GET[input];
    57 $outfile = $_GET[output];
     56$infile  = $_GET['input'];
     57$outfile = $_GET['output'];
    5858
    5959// $output = shell_exec("skyplot.dvo $infile $outfile");//, $output, $status);
Note: See TracChangeset for help on using the changeset viewer.