Ejemplo n.º 1
0
 function mainDiff($quiet = false)
 {
     $app = gp('gp_app');
     $file = gp('gpfile');
     $d1 = AppDir($app);
     $f1 = $d1 . $file;
     $f2 = $d1 . '/ref/' . $file;
     $diff = shell_exec("diff -u {$f2} {$f1}");
     if ($quiet) {
         return $diff;
     }
     // If not in quiet mode, they want to view the diff
     x_EchoFlush("<h1>File Diff</h1>");
     x_EchoFlush("Application {$app}");
     x_EchoFlush("Local file is: {$f1}");
     x_EchoFlush("Reference file is: {$f2}");
     echo "<pre>";
     echo htmlentities($diff);
     echo "</pre>";
 }
Ejemplo n.º 2
0
 function ehProcessData()
 {
     x_EchoFlush("Processing Tables");
     $this->PageUpdate('Tables', '', 'Data Dictionary');
     x_EchoFlush("Processing Modules");
     $this->PageUpdate('Modules', '', 'Data Dictionary');
     x_EchoFlush("Processing Groups");
     $this->PageUpdate('Groups', '', 'Data Dictionary');
     x_EchoFlush("Processing Column Definitions");
     $this->PageUpdate('Column Definitions', '', 'Data Dictionary');
     x_EchoFlush("Processing Spec Files");
     $this->PageUpdate('Spec Files', '', 'Data Dictionary');
     // Build the top page, which is a bunch of links to other pages
     $this->ProcessData_Top();
     $this->ProcessData_Columns();
     $this->ProcessData_Modules();
     $this->ProcessData_Groups();
     $this->ProcessData_SpecFiles();
     $this->ProcessData_Tables();
     echo hErrors();
 }
Ejemplo n.º 3
0
 function svnWalk($url, $dirv)
 {
     x_EchoFlush("    Directory: " . $dirv);
     # pull the URL, which is expected to be a list
     # of directories and files, and process each
     # accordingly
     #
     $raw = file_get_contents($url);
     $matches = array();
     preg_match_all('!\\<li\\>\\<a.*\\>(.*)\\</a\\>\\</li\\>!U', $raw, $matches);
     $files = $matches[1];
     #  A trailing backslash means a directory, make the
     #  directory and recurse.  Otherwise write the file
     foreach ($files as $file) {
         if ($file == '..') {
             continue;
         }
         if (substr($file, -1) == '/') {
             mkdir($dirv . $file);
             $this->svnWalk($url . "/{$file}", $dirv . $file);
         } else {
             $fileText = file_get_contents($url . $file);
             file_put_contents($dirv . $file, $fileText);
         }
     }
 }
Ejemplo n.º 4
0
 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 &gt; 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);
 }
Ejemplo n.º 5
0
 function LogEntry($logText = "", $Split80 = false)
 {
     if (!$Split80 || strlen($logText) < 75) {
         if (!$GLOBALS["log_flush"]) {
             echo $logText . "\n";
         } else {
             // THIS IS NOT A MISTAKE!  If this function exists,
             // it will be in u_dispatch.php, and is not part of
             // an object.
             x_EchoFlush($logText);
         }
         if ($GLOBALS["log_file"] != "") {
             file_put_contents($GLOBALS['log_file'], $logText . "\n", FILE_APPEND);
             //$cmd = "echo \"$logText\" >> ".$GLOBALS["log_file"];
             //`$cmd`;
         }
     } else {
         $prefix = "";
         while (strlen($logText) > 75) {
             $x = min(75, strlen($logText));
             while ($x >= 0) {
                 $x--;
                 if (substr($logText, $x, 1) == " " || substr($logText, $x, 1) == ",") {
                     break;
                 }
             }
             $this->LogEntry($prefix . substr($logText, 0, $x + 1));
             if ($prefix == "") {
                 $prefix = "   ";
             }
             $logText = substr($logText, $x + 1);
         }
         $this->LogEntry($prefix . $logText);
     }
 }
Ejemplo n.º 6
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 ---- ");
 }
Ejemplo n.º 7
0
 function mainPR_DirFiles($v, $r2, $root, $dirname, $dirpath)
 {
     // Put together three segments of directories to begin looping
     $dir = AddSlash($root);
     $dir = AddSlash($dir . $dirname);
     $dir = AddSlash($dir . $dirpath);
     $d2 = AddSlash($r2);
     $d2 = AddSlash($d2 . $dirname);
     $d2 = AddSlash($d2 . $dirpath);
     if (!file_exists($d2)) {
         mkdir($d2);
     }
     x_EchoFlush("");
     x_EchoFlush("Begin scan of directory: {$dir}");
     $DIR = opendir($dir);
     while (false !== ($file = readdir($DIR))) {
         // no . or ..
         if ($file == '.') {
             continue;
         }
         if ($file == '..') {
             continue;
         }
         // Get formatted name of dir + file;
         $fn = AddSlash($dirpath) . $file;
         // This is a directory, maybe recurse
         if (is_dir($dir . $file)) {
             $this->mainPR_DirFiles($v, $r2, $root, $dirname, $fn);
         } else {
             $filecnts = file_get_contents($dir . $file);
             $row = array('version' => $v, 'application' => $this->app, 'filename' => $fn, 'dirname' => $dirname, 'filecnts' => '', 'filets' => filemtime($dir . $file), 'filemd5' => md5($filecnts), 'filesize' => strlen($filecnts));
             x_EchoFlush("Loading file {$fn}, size: " . strlen($filecnts));
             //SQLX_Insert($this->tlf,$row);
             copy($dir . $file, $d2 . $file);
         }
     }
     x_EchoFlush("");
     x_EchoFlush("End scan of directory: {$dir}");
 }
Ejemplo n.º 8
0
 function VersionPull($app, $vremote, $appinfo)
 {
     $url = $appinfo['node_url'];
     $filename = $app . '-' . $vremote . '.tgz';
     // Set up the parms of the array
     $parms = "?gp_uid=" . SessionGet('UID') . "&gp_pwd=" . SessionGet('PWD') . "&gp_page=a_codexfer" . "&gp_action=pull" . "&gp_file=" . $filename;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "http://{$url}/andro/{$parms}");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     $retval = curl_exec($ch);
     curl_close($ch);
     //echo $retval;
     file_put_contents($GLOBALS['AG']['dirs']['root'] . "pkg-apps/{$filename}", $retval);
     chdir($GLOBALS['AG']['dirs']['root'] . "pkg-apps/");
     $command = "tar xzvf " . $filename;
     x_EchoFlush("Unpacking with this command: {$command}");
     `{$command}`;
 }
Ejemplo n.º 9
0
    function main()
    {
        $x_app = trim(gp('txt_application'));
        session_write_close();
        ob_start();
        echo "<h1>Build in progress</h1>";
        echo "<hr>";
        echo "<p>The system is now building the application: <b>" . $x_app . "</b>.</p>";
        echo "<p>If you are testing and expect to build several times in a row, do not ";
        echo "close this window, just hit REFRESH and the build will start again.</p>";
        echo "<p>All information below this line is from the build log.</p>";
        echo "<hr>";
        // Get everything we need from the database, use it to build
        // a "do" program.
        //
        $GLOBALS["x_password"] = trim(gp("supassword"));
        $tsql = 'SELECT * from applications ' . ' WHERE application = ' . SQL_Format('char', $x_app);
        $row_a = SQL_OneRow($tsql);
        $tsql = 'SELECT * from webpaths ' . ' WHERE webpath = ' . SQL_Format('char', $row_a['webpath']);
        $row_n = SQL_OneRow($tsql);
        $dirws = trim($row_n["dir_pub"]);
        if (substr($dirws, -1, 1) != "/") {
            $dirws .= "/";
        }
        $row["webserver_dir_pub"] = $dirws;
        $string = '
<?php
   // To run this program from the command line, you must
   // be logged in as a user that has superuser priveleges, such
   // as root or postgres.  When running from the web app,
   // the current user\'s priveleges are used.
	
   $GLOBALS["parm"] = array(
   "DBSERVER_URL"=>"localhost"
   ,"UID"=>"' . SessionGet('UID') . '"
   ,"DIR_PUBLIC"=>"' . trim($row_n["dir_pub"]) . '"
	,"DIR_PUBLIC_APP"=>"' . $x_app . '"
   ,"LOCALHOST_SUFFIX"=>"' . ArraySafe($row_n, 'dir_local', '') . '"
   ,"APP"=>"' . $x_app . '"
   ,"APPDSC"=>"' . trim($row_a["description"]) . '"
   ,"XDIRS"=>"' . trim($row_a['xdirs']) . '"
   ,"ROLE_LOGIN"=>"' . ArraySafe($row_a, 'flag_rolelogin', 'Y') . '"
   ,"FLAG_PWMD5"=>"' . ArraySafe($row_a, 'flag_pwmd5', 'N') . '"
   ,"TEMPLATE"=>"' . trim($row_a['template']) . '"
   ,"SPEC_BOOT"=>"' . trim($row_a["appspec_boot"]) . '"
   ,"SPEC_LIB"=>"' . trim($row_a["appspec_lib"]) . '"
   ,"SPEC_LIST"=>"' . trim($row_a["appspec"]) . '");

	include("androBuild.php");  
?>
';
        $t = pathinfo(__FILE__);
        $dircur = AddSlash($t["dirname"]) . "../tmp/";
        $file = $dircur . "do" . $x_app . ".php";
        $FILE = fopen($file, "w");
        fwrite($FILE, $string);
        fclose($FILE);
        x_EchoFlush("");
        include $file;
        echo ob_get_clean();
    }
Ejemplo n.º 10
0
 function ProcessWalk($dir, $f_tmp, $f_org, $stack = array())
 {
     x_EchoFlush("Processing: " . $dir . $f_tmp);
     // If we've been handed a directory, recurse the directory
     // Note there is an early return here, if we recurse we don't
     // do the rest of the code in this routine.
     //
     if (is_dir($dir . $f_tmp)) {
         $stack[] = $f_tmp;
         x_EchoFlush("This is a directory, will walk through it.");
         $DIR = opendir($dir . $f_tmp);
         while (false !== ($file = readdir($DIR))) {
             if ($file == "." || $file == "..") {
                 continue;
             }
             $this->ProcessWalk($dir . $f_tmp . "/", $file, $file, $stack);
             rmdir($dir . $f_tmp);
         }
         return;
     }
     if (count($stack) == 0) {
         $dird = "";
     } else {
         $dird = $stack[count($stack) - 1];
     }
     // If it's not a dir, check for mime-type that we recognize
     $mime = trim(mime_content_type($dir . $f_tmp));
     switch ($mime) {
         case "application/x-gzip":
             x_EchoFlush("Recognized mime type: {$mime}");
             $f_new = $f_tmp . ".unzipped";
             x_EchoFlush("Will unzip to file " . $f_new);
             $cmd = "gunzip -c " . $dir . $f_tmp . " > " . $dir . $f_new;
             x_EchoFlush("Command is: {$cmd}");
             `{$cmd}`;
             x_EchoFlush("Will now attempt to process the unzipped file");
             $this->ProcessWalk($dir, $f_new, $f_org);
             break;
         case "application/x-tar":
             x_EchoFlush("Recognized mime type: {$mime}");
             $f_new = $f_tmp . ".dir/";
             mkdir($dir . $f_new);
             $cmd = "tar xf " . $dir . $f_tmp . " --directory=" . $dir . $f_new;
             x_EchoFlush("The untar command is: " . $cmd);
             `{$cmd}`;
             $this->ProcessWalk($dir, $f_new, $f_org);
             break;
         default:
             $this->LoadFile($dir, $f_tmp, $dird);
     }
     unlink($dir . $f_tmp);
 }