function checkDBFilesForChanges()
 {
     global $parm;
     $this->LogStage("Checking spec files for changes");
     $changed = false;
     $checksums = array();
     $specboot = $parm["SPEC_BOOT"] . ".add";
     $checksums[] = array('file' => $specboot, 'md5' => md5_file($parm['DIR_PUB'] . "lib/" . $specboot), 'fullpath' => $parm['DIR_PUB'] . "lib/" . $specboot);
     if (isset($parm['INST'])) {
         $app = str_replace('_' . $parm['INST'], '', $parm['APP']);
     } else {
         $app = $parm['APP'];
     }
     if ($parm["SPEC_LIST"] != "") {
         $speclist = explode(",", $parm["SPEC_LIST"]);
         foreach ($speclist as $spec) {
             if (substr($spec, -5) != '.yaml') {
                 $file = $spec . ".add";
             } else {
                 $file = $spec;
             }
             $checksums[] = array('file' => $file, 'md5' => md5_file($parm["DIR_PUB"] . "application/" . $file), 'fullpath' => $parm["DIR_PUB"] . "application/" . $file);
         }
     }
     $checkqry = "SELECT relname FROM pg_class WHERE relname='instance_spec_checksums'";
     $checkrslts = SQL_AllRows($checkqry);
     if (count($checkrslts) == 0) {
         $this->LogEntry("Instance tracking table doesnt exist yet...ignoring until next build");
         return true;
     }
     foreach ($checksums as $checksum) {
         $query = "SELECT checksum,skey FROM " . ddTable_idResolve('instance_spec_checksums') . " WHERE \n            application=" . SQLFC($app) . " AND spec_name=" . SQLFC($checksum['file']) . (isset($parm['INST']) ? " AND instance=" . SQLFC($parm['INST']) : '');
         $row = SQL_OneRow($query);
         if ($row) {
             $this->LogEntry('Entry for ' . $checksum['file'] . ' file found');
             if ($row['checksum'] != $checksum['md5']) {
                 $this->LogEntry("Spec File Changed: " . $checksum['file']);
                 $changed = true;
                 $checksum_update = array('skey' => $row['skey'], 'checksum' => md5_file($checksum['fullpath']));
                 SQLX_Update('instance_spec_checksums', $checksum_update);
                 $this->LogEntry("Updating Entry");
             }
         } else {
             $this->LogEntry('Entry for ' . $checksum['file'] . ' not found');
             $checksum_entry = array('application' => $app, 'instance' => isset($parm['INST']) ? $parm['INST'] : '', 'spec_name' => $checksum['file'], 'checksum' => md5_file($checksum['fullpath']));
             SQLX_Insert('instance_spec_checksums', $checksum_entry);
             $this->LogEntry("Spec File Changed: " . $checksum['file']);
             $changed = true;
         }
     }
     if ($changed) {
         $this->LogEntry('One or more spec files have changed: Proceeding with full build');
     } else {
         $this->LogEntry('Spec files have not changed: Proceeding with mini build');
     }
     return $changed;
 }
 function instaSave()
 {
     $val = trim(urldecode(gp('value')));
     $row = array('skey' => gp('skey'), gp('column') => $val);
     SQLX_Update('configuser', $row);
     configWrite('user');
 }
Exemple #3
0
 /**
  * The user has requested that we download the latest 
  * version of each application from its respective
  * 
  *
  */
 function mainPull()
 {
     x_echoFlush('<pre>');
     x_EchoFlush('<h2>Looking For Andromeda Version</h2>');
     x_EchoFlush("");
     // First take care of where we are pulling version
     // information from
     $def = "http://andro.svn.sourceforge.net/svnroot/andro/releases/";
     $row = SQL_OneRow("Select * from applications where application='andro'");
     if (!isset($row['svn_url'])) {
         x_EchoFlush("-- This looks like the first time this node has");
         x_EchoFlush("   been upgraded from Subversion.  Using default");
         x_echoFlush("   URL to look for releases:");
         x_EchoFlush("   " . $def);
         $url = $def;
     } else {
         if (is_null($row['svn_url']) || trim($row['svn_url']) == '') {
             x_EchoFlush("-- Setting the Subversion URL to default:");
             x_EchoFlush("   " . $def);
             $url = $def;
             $row['svn_url'] = $def;
             SQLX_Update('applications', $row);
         } else {
             $url = trim($row['svn_url']);
             x_EchoFlush("-- Using the following URL for Subversion:");
             x_EchoFlush("   " . $url);
         }
     }
     // Find out what the latest version is
     x_EchoFlush("");
     x_EchoFlush("-- Querying for latest version...");
     $command = 'svn list ' . $url;
     x_EchoFlush("   Command is: " . $command);
     $rawtext = `{$command}`;
     if ($rawtext == '') {
         x_EchoFlush("-- NO VERSIONS RETRIEVED!");
         x_EchoFlush("   It may be that the Sourceforge site is down?");
         x_EchoFlush("");
         x_echoFlush(" ---- Stopped Unexpectedly --- ");
         return;
     }
     $rawtext = str_replace("\r", "", $rawtext);
     $lines = explode("\n", $rawtext);
     // Pop off empty entry at end, then get latest version
     array_pop($lines);
     $latest = array_pop($lines);
     if (substr($latest, -1) == '/') {
         $latest = substr($latest, 0, strlen($latest) - 1);
     }
     x_EchoFlush("   Latest published version: " . $latest);
     // now find out what version we have
     x_EchoFlush(" ");
     x_EchoFlush("-- Finding out what version the node manager is at");
     $file = $GLOBALS['AG']['dirs']['application'] . '_andro_version_.txt';
     x_EchoFlush("   Looking at file: {$file}");
     if (!file_exists($file)) {
         x_EchoFlush("   File not found, it appears this is the first time");
         x_EchoFlush("   this node has been upgraded this way. Will proceed");
         x_EchoFlush("   to get latest version.");
     } else {
         $version = file_get_contents($file);
         x_EchoFlush("   Current version is " . $version);
         if ($version == $latest) {
             x_echoFlush("   This node is current!  Nothing to do!");
             x_EchoFlush("");
             x_echoFlush(" ---- Processing completed normally ---- ");
             return;
         } else {
             x_echoFlush("   Newer version available, will get latest.");
         }
     }
     // now get the latest code
     $dir = $GLOBALS['AG']['dirs']['root'];
     $command = 'svn export --force ' . $url . $latest . ' ' . $dir;
     x_EchoFlush("");
     x_EchoFlush("-- Overwriting Node Manager now");
     x_echoFlush("   Command is " . $command);
     `{$command}`;
     x_echoFlush("");
     file_put_contents($file, $latest);
     x_EchoFlush(" ---- Processing completed normally ---- ");
 }
Exemple #4
0
 /**
  * Execute an skey-based update
  *
  */
 function update()
 {
     $row = aFromGP('x4v_');
     $skey = 0;
     $table_id = $this->dd['table_id'];
     # KFD 6/12/08, allow functions to modify or prevent a write
     $tbefore = $table_id . "_writeBefore";
     $tafter = $table_id . "_writeAfter";
     if (function_exists($tbefore)) {
         $message = $tbefore($row);
         if ($message != '') {
             x4Error($message);
             return;
         }
     }
     # KFD 6/28/08, a non-empty date must be valid
     $errors = false;
     foreach ($row as $col => $value) {
         if (!isset($this->dd['flat'][$col])) {
             unset($row[$col]);
             continue;
         }
         $ermsg = "Invalid date format for " . $this->dd['flat'][$col]['description'];
         $ermsg2 = "Invalid date value for " . $this->dd['flat'][$col]['description'];
         if ($this->dd['flat'][$col]['type_id'] == 'date') {
             if (trim($value) == '') {
                 continue;
             }
             if (strpos($value, '/') === false && strpos($value, '-') === false) {
                 x4Error($ermsg);
                 $errors = true;
                 continue;
             }
             if (strpos($value, '/') !== false) {
                 $parsed = explode('/', $value);
                 if (count($parsed) != 3) {
                     $errors = true;
                     x4Error($ermsg);
                     continue;
                 }
                 if (!checkdate($parsed[0], $parsed[1], $parsed[2])) {
                     x4Error($ermsg2);
                     $errors = true;
                     continue;
                 }
             }
             if (strpos($value, '-') !== false) {
                 $parsed = explode('-', $value);
                 if (count($parsed) != 3) {
                     $errors = true;
                     x4Error($ermsg);
                     continue;
                 }
                 if (!checkdate($parsed[1], $parsed[2], $parsed[0])) {
                     x4Error($ermsg2);
                     $errors = true;
                     continue;
                 }
             }
         }
     }
     if ($errors) {
         return;
     }
     if ($row['skey'] == 0 || !isset($row['skey'])) {
         unset($row['skey']);
         $skey = SQLX_Insert($this->dd, $row);
         if (!errors()) {
             $row = SQL_OneRow("Select * FROM {$this->view_id} WHERE skey = {$skey}");
         }
         x4Data('row', $row);
     } else {
         SQLX_Update($this->dd, $row);
         if (!errors()) {
             $skey = $row['skey'];
             $row = SQL_OneRow("Select * FROM {$this->view_id} WHERE skey = {$skey}");
             x4Data('row', $row);
         }
     }
     # KFD 6/12/08, allow functions to modify or prevent a write
     if (Errors()) {
         return;
     }
     if (function_exists($tafter)) {
         $message = $tafter($row);
         if ($message != '') {
             x4Error($message);
             return;
         }
     }
 }
Exemple #5
0
 function processSubmit()
 {
     // Get the submitted data
     $table = gp('gp_table_upd', '');
     // Get the flat table def
     $table_dd = dd_TableRef($table);
     $tabflat = ArraySafe($table_dd, 'flat');
     //hprint_r($table);
     $row = aFromGP('gp_upd_');
     //hprint_r($row);
     //hprint_r($row);
     // Build a WHERE clause
     $where = array();
     foreach ($row as $col => $val) {
         if (ArraySafe($tabflat[$col], 'primary_key', 'N') != 'Y') {
             continue;
         }
         $where[] = $col . " = '" . $val . "'";
     }
     //hprint_r($where);
     $where = implode(' AND ', $where);
     // Build a SELECT
     $sql = "SELECT skey\n                 FROM " . ddTable_IDResolve($table) . "\n                WHERE " . $where;
     //hprint_r($sql);
     $records = SQL_AllRows($sql);
     if (count($records) != 1) {
         echo "Invalid or non-unique key supplied\n<br>";
         return;
     }
     // Well, we haven't failed yet, let's add the skey before the update, just to be safe.
     $row['skey'] = $records[0]['skey'];
     $skey = $records[0]['skey'];
     //hprint_r($row);
     SQLX_Update($table_dd, $row);
     if (Errors()) {
         echo hErrors();
     } else {
         echo "Update Successful.  <a href=\"?gp_page={$table}&gp_skey={$skey}\">View Record</a> <br>\n";
     }
 }
Exemple #6
0
function scDBUpdateOrInsert($table, $colvals)
{
    $table_id = $table["table_id"];
    $tabflat =& $table["flat"];
    // First query for the pk value.  If not found we will
    // just do an insert
    //
    $abort = false;
    $a_pk = explode(',', $table['pks']);
    $s_where = '';
    foreach ($a_pk as $colname) {
        if (!isset($colvals[$colname])) {
            $abort = true;
            break;
        }
        $a_where[] = $colname . ' = ' . SQL_Format($tabflat[$colname]['type_id'], $colvals[$colname]);
    }
    if ($abort) {
        $skey = false;
    } else {
        $s_where = implode(' AND ', $a_where);
        $sql = 'SELECT skey FROM ' . DDTable_IDResolve($table_id) . ' WHERE ' . $s_where;
        $skey = SQL_OneValue('skey', $sql);
    }
    // STD says on 12/15/2006 that this routine should not put errors on screen
    //if (Errors()) echo HTMLX_Errors();
    if (!$skey) {
        //echo "insert into ".$table_id."\n";
        $retval = SQLX_Insert($table, $colvals, false);
        if (Errors()) {
            // STD says on 12/15/2006 that this routine should not put errors on screen
            //echo HTMLX_Errors();
            //echo $sql;
            $retval = 0;
        }
    } else {
        //echo "update ".$table_id." on $skey\n";
        $colvals['skey'] = $skey;
        $retval = -$skey;
        SQLX_Update($table, $colvals);
        if (Errors()) {
            // STD says on 12/15/2006 that this routine should not put errors on screen
            //echo HTMLX_Errors();
            //echo $sql;
            $retval = 0;
        }
    }
    return $retval;
}
Exemple #7
0
 function PW_ForgotPage1()
 {
     // KFD 11/13/06.  Heavily modified for new system, threw out
     //   the older code entirely, now that all apps have a users
     //   table built into them.
     $eml = trim(gp('txt_email'));
     $seml = SQLFC(strtolower($eml));
     $heml = hx($eml);
     $ueml = urlencode($eml);
     //$leml= MakeUserId(strtolower($eml));
     $db2 = scDBConn_Push('usermaint');
     $sq = "Select skey,user_id,member_password,email FROM users " . " where LOWER(email)={$seml}";
     $member = SQL_AllRows($sq);
     // Nothing of any kind is a bummer, we can't do anything
     if (count($member) == 0) {
         ErrorAdd('There are no active accounts with that email address');
     } else {
         $leml = MakeUserID($eml);
         $member = $member[0];
         // If we know who they are, send a password and allow them to change it
         $user_pwkey = md5($member['member_password'] . $leml . time());
         //$ref=$_SERVER['HTTP_REFERER'];
         $http = httpWebSite() . "/";
         $row = array('skey' => $member['skey'], 'user_pwkey' => $user_pwkey);
         $UID = $member['user_id'];
         $PWD = $member['member_password'];
         // KFD 12/21/06.  Done for medinfo originally.  If UID looks like
         //  the email, send the email instead
         $emailUID = $member['email'];
         $table_dd = DD_Tableref('users');
         SQLX_Update($table_dd, $row);
         $emailuser_id = OptionGet('EMAIL_USERID', 'N') == 'Y' ? $emailUID : $leml;
         $text_email = "\nYour username and password are: {$emailuser_id} and {$PWD}.\n   \nIf you would like to change your password, click here:\n<{$http}?gp_page=x_password&gpp=2&eml={$ueml}&hash={$user_pwkey}>\n";
         scDBConn_Pop();
         //echo $text_email;
         EmailSend($eml, 'System Access Request', $text_email);
         ?>
         <b>Email Has Been Sent</b>.  An email has been sent to you with information
         needed to access the system.
         <?php 
         gpSet('gpp', 'X');
     }
 }
Exemple #8
0
 function save()
 {
     $table_id = gp('x6page');
     $dd = ddTable($table_id);
     $row0 = aFromGP('x6v_');
     $row1 = aFromgp('x6inp_' . $table_id . '_');
     $row = array_merge($row0, $row1);
     if (arr($row, 'skey', 0) == 0) {
         unset($row['skey']);
     }
     # KFD 12/20/08, prevent ui saves if dd does not allow them
     if (!isset($row['skey'])) {
         $perm = $this->uiPerm(gp('x6page'), 'ins');
         if (!$perm) {
             x6Error("Inserts not allowed from this screen");
             return;
         }
     } else {
         $perm = $this->uiPerm(gp('x6page'), 'upd');
         if (!$perm) {
             x6Error("Updates not allowed from this screen");
             return;
         }
     }
     # Add in values from parent
     if (gp('tableIdPar', false)) {
         $vals2 = $this->fetchParent();
         $row = array_merge($row, $vals2);
     }
     # KFD 12/8/08, More generalized code to allow for
     #              inserts before or after a row.
     #
     # an skeyAfter value means we must find the queuepos
     # column in this table, and save a value of that
     # column equal to +1 of the value in row skeyAfter
     if (gp('queuepos', '') != '') {
         $queuepos = gp('queuepos');
         $skeyBefore = gp('skeyBefore');
         $skeyAfter = gp('skeyAfter');
         $skey = 0;
         if ($skeyBefore != -1) {
             $skey = $skeyBefore;
         }
         if ($skeyAfter != -1) {
             $skey = $skeyAfter;
         }
         if ($skey == 0) {
             $row[$queuepos] = 1;
         } else {
             $qpvalue = SQL_OneValue($queuepos, "Select {$queuepos} from {$dd['viewname']}\n                    where skey = " . sqlfc($skey));
             if ($skey == $skeyAfter) {
                 $qpvalue++;
             } else {
                 $qpvalue--;
             }
             $row[$queuepos] = $qpvalue;
         }
     }
     # KFD 6/28/08, a non-empty date must be valid
     $errors = false;
     foreach ($row as $col => $value) {
         if (!isset($dd['flat'][$col])) {
             unset($row[$col]);
             continue;
         }
         $ermsg = "Invalid date format for " . $dd['flat'][$col]['description'];
         $ermsg2 = "Invalid date value for " . $dd['flat'][$col]['description'];
         if ($dd['flat'][$col]['type_id'] == 'date') {
             if (trim($value) == '') {
                 continue;
             }
             if (strpos($value, '/') === false && strpos($value, '-') === false) {
                 x6Error($ermsg);
                 $errors = true;
                 continue;
             }
             if (strpos($value, '/') !== false) {
                 $parsed = explode('/', $value);
                 if (count($parsed) != 3) {
                     $errors = true;
                     x6Error($ermsg);
                     continue;
                 }
                 if (!checkdate($parsed[0], $parsed[1], $parsed[2])) {
                     x6Error($ermsg2);
                     $errors = true;
                     continue;
                 }
             }
             if (strpos($value, '-') !== false) {
                 $parsed = explode('-', $value);
                 if (count($parsed) != 3) {
                     $errors = true;
                     x6Error($ermsg);
                     continue;
                 }
                 if (!checkdate($parsed[1], $parsed[2], $parsed[0])) {
                     x6Error($ermsg2);
                     $errors = true;
                     continue;
                 }
             }
         }
     }
     if ($errors) {
         return;
     }
     if (!isset($row['skey'])) {
         # KFD 5/26/09 Google Feature #23, hook inserts
         $method = $table_id . "_before_insert";
         if (method_exists($this, $method)) {
             $row = $this->{$method}($row);
         }
         # KFD 6/8/09 Google #30, no action if returns false
         if ($row) {
             $skey = SQLX_Insert($dd, $row);
             if (!errors()) {
                 $row = SQL_OneRow("Select * FROM {$dd['viewname']} WHERE skey = {$skey}");
                 # KFD 5/26/09 Google Feature #23, hook inserts
                 $method = $table_id . "_after_insert";
                 if (method_exists($this, $method)) {
                     $row = $this->{$method}($row);
                 }
                 x6Data('row', $row);
             }
         }
     } else {
         # KFD 5/26/09 Google Feature #23, hook updates
         $method = $table_id . "_before_update";
         if (method_exists($this, $method)) {
             $row = $this->{$method}($row);
         }
         # KFD 6/8/09 Google #30, no action if returns false
         if ($row) {
             SQLX_Update($dd, $row);
             if (!errors()) {
                 $skey = $row['skey'];
                 $row = SQL_OneRow("Select * FROM {$dd['viewname']} WHERE skey = {$skey}");
                 # KFD 5/26/09 Google Feature #23, hook updates
                 $method = $table_id . "_after_update";
                 if (method_exists($this, $method)) {
                     $row = $this->{$method}($row);
                 }
                 x6Data('row', $row);
             }
         }
     }
     if (vgfGet('x6') == true) {
         if ($table_id == 'configinst') {
             configWrite('inst');
         }
         if ($table_id == 'configapp') {
             configWrite('app');
         }
     }
 }
function index_hidden_ajaxsql()
{
    switch (gp('gp_ajaxsql')) {
        case 'update':
            $row = aFromgp('txt_');
            foreach ($row as $key => $value) {
                if ($value == 'b:true') {
                    $row[$key] = 'Y';
                }
                if ($value == 'b:false') {
                    $row[$key] = 'N';
                }
            }
            $table_id = gp('gp_table');
            SQLX_Update($table_id, $row);
            break;
        case 'insert':
            $row = aFromgp('txt_');
            $table_id = gp('gp_table');
            // XDB
            SQLX_Insert($table_id, $row);
            break;
    }
    if (Errors()) {
        echo 'echo|' . hErrors();
    }
}