/** * The user has requested that we download the latest * version of each application from its respective * * */ function mainPull() { # Don't hold up the system Session_write_close(); $rows = svnVersions(); $dir = fsDirTop() . 'pkg-apps/'; x_echoFlush('<pre>'); x_EchoFlush('<h2>Pulling Software Updates From SVN</h2>'); // Loop through the apps. foreach ($rows as $row) { x_EchoFlush(""); x_echoFlush("<b>Application: " . $row['application'] . "</b>"); if ($row['svn_url'] == '') { x_echoFlush(" No SVN repository, skipping."); continue; } # Add a trailing slash to svn_url $row['svn_url'] = AddSlash(trim($row['svn_url'])); # If there is a username and password both, use those $urlDisplay = $row['svn_url']; $url = $row['svn_url']; if ($row['svn_uid'] != '' && $row['svn_pwd'] != '') { list($proto, $urlstub) = explode("//", $url); $uid = $row['svn_uid']; $pwd = $row['svn_pwd']; $url = "{$proto}//{$uid}:{$pwd}@{$urlstub}"; $urlDisplay = "{$proto}//{$uid}:*****@{$urlstub}"; } x_echoFlush(" Complete URL: " . $urlDisplay); # Now pull the list of versions x_echoFlush(" Querying for latest version"); $rawtext = @file_get_contents($url); if ($rawtext) { $matches = array(); preg_match_all('!\\<li\\>\\<a.*\\>(.*)\\</a\\>\\</li\\>!U', $rawtext, $matches); $versions = $matches[1]; foreach ($versions as $key => $version) { if ($version == '..') { unset($versions[$key]); } } if (count($versions) == 0) { x_EchoFlush(" No versions listed, nothing to pull."); continue; } } else { x_EchoFlush("Unable to get a release list from the svn server."); continue; } # Work out what the latest was and report it $latest = array_pop($versions); if (substr($latest, -1) == '/') { $latest = substr($latest, 0, strlen($latest) - 1); } x_echoFlush(" Latest version is: " . $latest); x_EchoFlush(" Local version is: " . $row['local']); # Decide if we need to continue if ($latest == $row['local']) { x_EchoFlush(" Local version is latest, nothing do to."); continue; } # Determine some stub values and pass processing to # the recursive file puller. If no uid & pwd, use subversion x_EchoFlush(" Local version is out of date, pulling latest"); $dirv = $dir . trim($row['application']) . '-VER-' . $latest . '/'; if ($row['svn_uid'] != '' && $row['svn_pwd'] != '') { mkdir($dirv); $this->svnWalk("{$url}/{$latest}/", $dirv); } else { $command = "svn export {$url}{$latest} {$dirv}"; x_echoFlush(" Pulling code now, this make take a minute or three..."); x_EchoFlush($command); `{$command}`; x_echoFlush(" Code pulled, finished with this application."); } x_echoFlush(" Copying files into application directory"); $basedir = str_replace('andro/', '', fsDirTop()); if (isWindows()) { $command = 'xcopy /y /e /c /k /o ' . $dirv . '* ' . $basedir . trim($row['application']) . '/'; } else { $command2 = 'cp -Rf ' . $dirv . '* ' . $basedir . trim($row['application']) . '/'; } echo $command2; `{$command2}`; } x_echoFlush("<hr/>"); x_EchoFlush("<h3>Processing Complete</h3>"); $this->flag_buffer = false; }
function RunTests($pagename, $testtypes, $tests) { if (count($testtypes) == 0) { return ''; } if (count($tests) == 0) { return ''; } // If there are tests to run, do them now $hError = ''; $hTests = ''; foreach ($tests as $test) { // Explode parameters and build a function call $parms = explode(',', $test); if (count($parms) != count($testtypes)) { $hError = "\n\n''There was a column count error in the\n in-line test declarations for this function''\n"; } else { // Turn some of the values into quotes values foreach ($parms as $index => $parm) { if ($testtypes[$index] == 'char') { $parms[$index] = "'" . $parm . "'"; } } // We actually add the evaluated output back onto the // parms array. This lets us then call hTRFromArray, // that's the only reason we do it. $str = 'echo ' . $pagename . "(" . implode(',', $parms) . ");"; ob_start(); eval($str); $result = ob_get_clean(); // Eval again and show this time x_echoFlusH("Test command: {$str}"); eval($str); x_echoFlush(""); x_EchoFlush("Result was {$result}"); $parms[] = $result; $hTests .= "\n" . hTrFromArray('', $parms); } } if ($hTests) { foreach ($testtypes as $index => $testtype) { $htitles[] = 'Parm ' . ($index + 1); } $htitles[] = 'Output'; $hTests = "\n\n==Test output==\n\n" . $hError . "<table border=1>" . hTRFromArray('', $htitles) . $hTests . "\n</table>\n\n"; } return $hTests; }
function DBB_LoadYAMLFile($filename, &$retarr) { // KFD 12/8/07 New pre-scan, try to prevent known // syntax errors that will not be reported by spyc // if (!$this->DBB_LoadYAMLFile_PreScan($filename)) { return false; } // Now convert to YAML and dump include_once "spyc.php"; $parser = new Spyc(); $temparray = $parser->load($filename); #$temparray=Spyc::YAMLLoad($filename); if (count($parser->errors) > 0) { x_echoFlush(" >>> "); x_echoFlush(" >>> Parse errors in the YAML File"); x_echoFlush(" >>> "); foreach ($parser->errors as $idx => $err) { $idx = str_pad($idx + 1, 4, ' ', STR_PAD_LEFT); x_EchoFlush("{$idx}) {$err}"); } return false; } $this->YAMLError = false; $this->YAMLPrevious = array("no entries yet, look at top of file"); $this->YAMLStack = array(); $this->YAMLContent = array(); $retarr['data'] = $this->YAMLWalk($temparray); $retarr['content'] = $this->YAMLContent; return !$this->YAMLError; }
function fbProcInner($fi, $t) { x_EchoFlush("BEGIN FILE PROCESSING"); $FILE = fopen($fi['uname'], 'r'); if (!$FILE) { x_EchoFlush("Trouble opening local uploaded file."); x_EchoFlush("ABORT WITH ERROR"); return 0; } // Make sure first line is ok $line1 = fsGets($FILE); if (strlen($line1) == 0) { x_EchoFlush("Failed reading first line, file is empty?"); x_EchoFlush("ABORT WITH ERROR"); return 0; } if (strlen($line1) > 4998) { x_EchoFlush("First line is > 4998 bytes, this cannot be right."); x_EchoFlush("ABORT WITH ERROR"); return 0; } // Now convert the first line into the list of columns $acols = explode('|', $line1); x_echoFlush("COLUMNS IN FILE:"); foreach ($acols as $acol) { x_EchoFlush($acol); } // Retrieve maps $mapcols = SQL_AllRows("SELECT column_id,COALESCE(column_id_src,'') as src\n FROM importmapcolumns\n WHERE table_id=" . SQLFC($t['table_id']) . "\n AND importmap=" . SQLFC(gp('gp_map')), 'column_id'); echo "<hr>"; echo "<h2>Map is as follows: " . gp('gp_map') . "</h2>"; hprint_r($mapcols); echo "<hr>"; // Now convert each line as we go $linenum = 0; $linesok = 0; while (($oneline = fsGets($FILE)) !== false) { $linenum++; // Give the user something to believe in if ($linenum % 100 == 0) { x_EchoFlush("Line: {$linenum} processing"); } // Pull the line $data = explode('|', $oneline); // Maybe a problem? if (count($data) != count($acols)) { x_EchoFlush("ERROR LINE {$linenum}"); x_EchoFlush("Too many or too few values"); hprint_r($data); continue; } // No problem yet, attempt the insert ErrorsClear(); // Assign first-row column names to incoming data $row = array_combine($acols, $data); // Match the values from the map $rowi = array(); foreach ($mapcols as $mapcol => $info) { if ($info['src'] != '') { if (isset($row[$info['src']])) { $rowi[$mapcol] = $row[$info['src']]; } } } $mixed = array($t['table_id'] => array($rowi)); SQLX_Cleanup($mixed); SQLX_insert($t, $mixed[$t['table_id']][0]); // Complaints? Problems? Report them! if (Errors() && strpos(hErrors(), 'Duplicate Value') === false) { x_EchoFlush('------------------------------------------------'); x_EchoFlush("ERROR LINE {$linenum} when attempting to insert"); x_EchoFlush(hErrors()); x_EchoFlush('------------------------------------------------'); continue; } $linesok++; } return array($linenum, $linesok); }
/** * 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 ---- "); }
function PullCodeApp($row) { $app = trim($row['application']); $sApp = SQLFC($app); $ver = $row['version']; $sVer = SQLFC($ver); x_echoFlush(""); x_EchoFlush("*** Application: " . $row['application']); x_EchoFlush(" Authoritative Node is: " . $row['node']); x_EchoFlush(" Current Local Version: " . $ver); // Get version from remote node $remote = $this->CURL($row['node_url'], "select max(version) as version\n FROM appversions\n WHERE application={$sApp}"); if (count($remote) == 0) { x_EchoFlush("The remote server says it's got nothing for us!"); } else { $vremote = $remote[0]['version']; x_EchoFlush(" Remote server has version: {$vremote}"); if ($vremote == $ver) { x_EchoFlush("Local version is up-to-date, nothing to do here."); } elseif ($vremote < $ver) { x_EchoFlush("Local version is more recent."); x_EchoFlush(" --> this should not normally happen, perhaps"); x_EchoFlush(" somebody published code on this machine?"); } else { x_EchoFlush("Local version out of date, pulling latest"); $this->VersionPull($app, $vremote, $row); $table_dd = DD_TableRef('appversions'); $row = array('application' => $app, 'version' => $vremote); SQLX_Insert($table_dd, $row); echo hERrors(); } } }