Example #1
0
function connectDB()
{
    global $con, $_DB;
    $con = mysql_connect($_DB['server'], $_DB['username'], $_DB['password']);
    $source = mysql_select_db($_DB['source'], $con);
    if (!$con) {
        debugMsg("db connection error");
    } else {
        debugMsg("db connected");
    }
    if (!$source) {
        debugMsg("source connection error");
    } else {
        debugMsg("source connected");
    }
}
Example #2
0
 /**
  * Concrete classes must use this method to read the file header
  * @return bool True if reading the file was successful, false if an error occured or we reached end of archive
  */
 protected function readFileHeader()
 {
     // If the current part is over, proceed to the next part please
     if ($this->isEOF(true)) {
         $this->nextFile();
     }
     if ($this->expectDataDescriptor) {
         // The last file had bit 3 of the general purpose bit flag set. This means that we have a
         // 12 byte data descriptor we need to skip. To make things worse, there might also be a 4
         // byte optional data descriptor header (0x08074b50).
         $junk = @fread($this->fp, 4);
         $junk = unpack('Vsig', $junk);
         if ($junk['sig'] == 0x8074b50) {
             // Yes, there was a signature
             $junk = @fread($this->fp, 12);
             if (defined('KSDEBUG')) {
                 debugMsg('Data descriptor (w/ header) skipped at ' . (ftell($this->fp) - 12));
             }
         } else {
             // No, there was no signature, just read another 8 bytes
             $junk = @fread($this->fp, 8);
             if (defined('KSDEBUG')) {
                 debugMsg('Data descriptor (w/out header) skipped at ' . (ftell($this->fp) - 8));
             }
         }
         // And check for EOF, too
         if ($this->isEOF(true)) {
             if (defined('KSDEBUG')) {
                 debugMsg('EOF before reading header');
             }
             $this->nextFile();
         }
     }
     // Get and decode Local File Header
     $headerBinary = fread($this->fp, 30);
     $headerData = unpack('Vsig/C2ver/vbitflag/vcompmethod/vlastmodtime/vlastmoddate/Vcrc/Vcompsize/Vuncomp/vfnamelen/veflen', $headerBinary);
     // Check signature
     if (!($headerData['sig'] == 0x4034b50)) {
         if (defined('KSDEBUG')) {
             debugMsg('Not a file signature at ' . (ftell($this->fp) - 4));
         }
         // The signature is not the one used for files. Is this a central directory record (i.e. we're done)?
         if ($headerData['sig'] == 0x2014b50) {
             if (defined('KSDEBUG')) {
                 debugMsg('EOCD signature at ' . (ftell($this->fp) - 4));
             }
             // End of ZIP file detected. We'll just skip to the end of file...
             while ($this->nextFile()) {
             }
             @fseek($this->fp, 0, SEEK_END);
             // Go to EOF
             return false;
         } else {
             if (defined('KSDEBUG')) {
                 debugMsg('Invalid signature ' . dechex($headerData['sig']) . ' at ' . ftell($this->fp));
             }
             $this->setError(AKText::_('ERR_CORRUPT_ARCHIVE'));
             return false;
         }
     }
     // If bit 3 of the bitflag is set, expectDataDescriptor is true
     $this->expectDataDescriptor = ($headerData['bitflag'] & 4) == 4;
     $this->fileHeader = new stdClass();
     $this->fileHeader->timestamp = 0;
     // Read the last modified data and time
     $lastmodtime = $headerData['lastmodtime'];
     $lastmoddate = $headerData['lastmoddate'];
     if ($lastmoddate && $lastmodtime) {
         // ----- Extract time
         $v_hour = ($lastmodtime & 0xf800) >> 11;
         $v_minute = ($lastmodtime & 0x7e0) >> 5;
         $v_seconde = ($lastmodtime & 0x1f) * 2;
         // ----- Extract date
         $v_year = (($lastmoddate & 0xfe00) >> 9) + 1980;
         $v_month = ($lastmoddate & 0x1e0) >> 5;
         $v_day = $lastmoddate & 0x1f;
         // ----- Get UNIX date format
         $this->fileHeader->timestamp = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
     }
     $isBannedFile = false;
     $this->fileHeader->compressed = $headerData['compsize'];
     $this->fileHeader->uncompressed = $headerData['uncomp'];
     $nameFieldLength = $headerData['fnamelen'];
     $extraFieldLength = $headerData['eflen'];
     // Read filename field
     $this->fileHeader->file = fread($this->fp, $nameFieldLength);
     // Handle file renaming
     $isRenamed = false;
     if (is_array($this->renameFiles) && count($this->renameFiles) > 0) {
         if (array_key_exists($this->fileHeader->file, $this->renameFiles)) {
             $this->fileHeader->file = $this->renameFiles[$this->fileHeader->file];
             $isRenamed = true;
         }
     }
     // Handle directory renaming
     $isDirRenamed = false;
     if (is_array($this->renameDirs) && count($this->renameDirs) > 0) {
         if (array_key_exists(dirname($file), $this->renameDirs)) {
             $file = rtrim($this->renameDirs[dirname($file)], '/') . '/' . basename($file);
             $isRenamed = true;
             $isDirRenamed = true;
         }
     }
     // Read extra field if present
     if ($extraFieldLength > 0) {
         $extrafield = fread($this->fp, $extraFieldLength);
     }
     if (defined('KSDEBUG')) {
         debugMsg('*' . ftell($this->fp) . ' IS START OF ' . $this->fileHeader->file . ' (' . $this->fileHeader->compressed . ' bytes)');
     }
     // Decide filetype -- Check for directories
     $this->fileHeader->type = 'file';
     if (strrpos($this->fileHeader->file, '/') == strlen($this->fileHeader->file) - 1) {
         $this->fileHeader->type = 'dir';
     }
     // Decide filetype -- Check for symbolic links
     if ($headerData['ver1'] == 10 && $headerData['ver2'] == 3) {
         $this->fileHeader->type = 'link';
     }
     switch ($headerData['compmethod']) {
         case 0:
             $this->fileHeader->compression = 'none';
             break;
         case 8:
             $this->fileHeader->compression = 'gzip';
             break;
     }
     // Find hard-coded banned files
     if (basename($this->fileHeader->file) == "." || basename($this->fileHeader->file) == "..") {
         $isBannedFile = true;
     }
     // Also try to find banned files passed in class configuration
     if (count($this->skipFiles) > 0 && !$isRenamed) {
         if (in_array($this->fileHeader->file, $this->skipFiles)) {
             $isBannedFile = true;
         }
     }
     // If we have a banned file, let's skip it
     if ($isBannedFile) {
         // Advance the file pointer, skipping exactly the size of the compressed data
         $seekleft = $this->fileHeader->compressed;
         while ($seekleft > 0) {
             // Ensure that we can seek past archive part boundaries
             $curSize = @filesize($this->archiveList[$this->currentPartNumber]);
             $curPos = @ftell($this->fp);
             $canSeek = $curSize - $curPos;
             if ($canSeek > $seekleft) {
                 $canSeek = $seekleft;
             }
             @fseek($this->fp, $canSeek, SEEK_CUR);
             $seekleft -= $canSeek;
             if ($seekleft) {
                 $this->nextFile();
             }
         }
         $this->currentPartOffset = @ftell($this->fp);
         $this->runState = AK_STATE_DONE;
         return true;
     }
     // Last chance to prepend a path to the filename
     if (!empty($this->addPath) && !$isDirRenamed) {
         $this->fileHeader->file = $this->addPath . $this->fileHeader->file;
     }
     // Get the translated path name
     if ($this->fileHeader->type == 'file') {
         $this->fileHeader->realFile = $this->postProcEngine->processFilename($this->fileHeader->file);
     } elseif ($this->fileHeader->type == 'dir') {
         $this->fileHeader->timestamp = 0;
         $dir = $this->fileHeader->file;
         $this->postProcEngine->createDirRecursive($this->fileHeader->file, 0755);
         $this->postProcEngine->processFilename(null);
     } else {
         // Symlink; do not post-process
         $this->fileHeader->timestamp = 0;
         $this->postProcEngine->processFilename(null);
     }
     $this->createDirectory();
     // Header is read
     $this->runState = AK_STATE_HEADER;
     return true;
 }
Example #3
0
 * 
 */
include_once "header.php";
$classid = $_REQUEST['classid'];
$leconid = $_REQUEST['lecon'];
echo $leconid;
echo "<br>";
echo $classid;
// Get Lecture List for class
$sql_str = "SELECT ID\r\n\t\t\tFROM lecturetable\r\n\t\t\tWHERE classid = {$classid}";
$lec_result = mysql_query($sql_str);
debugMsg($sql_str);
// Update Lecture Details
while ($row = mysql_fetch_array($lec_result)) {
    $lecid = $row['ID'];
    $lecpw = $_REQUEST["lecpw_{$lecid}"];
    if ($leconid == $lecid) {
        $lecon = 1;
    } else {
        $lecon = 0;
    }
    debugMsg("lecid = {$lecid}; lecpw = {$lecpw} ; lecon = {$lecon};");
    $sql_str = "UPDATE lecturetable SET Password='******', \r\n\t\t\t\tActive='{$lecon}' WHERE ID = {$lecid}";
    debugMsg($sql_str);
    if ($result = mysql_query($sql_str)) {
        debugMsg("DB UPDATE OK");
    } else {
        debugMsg("DB UPDATE ERROR");
    }
}
redirect("displayclass.php?classid={$classid}");
function getTopCreators2($dbw, $cutoff, $start)
{
    global $table, $join, $where, $cond, $andcond;
    $result = "<ol>";
    $sql = "select nap_page from newarticlepatrol left join page on nap_page = page_id where page_namespace = 0\n\t\t\tand nap_timestamp > '{$cutoff}' and nap_timestamp < '{$start}'; ";
    wfDebug("Dashboard top creators: {$sql}\n");
    debugMsg("getting nap {$nap} ");
    $res = $dbw->query($sql, __METHOD__);
    $pages = array();
    $revisions = array();
    while ($row = $dbw->fetchObject($res)) {
        $pages[] = $row->nap_page;
    }
    debugMsg("getting min revisions on pages " . sizeof($pages) . " pages ");
    $count = 0;
    foreach ($pages as $page_id) {
        $revisions[$page_id] = selectField($table, array("min(rev_id)"), array("rev_page" => $page_id));
        $count++;
        if ($count % 100 == 0) {
            debugMsg("done {$count}");
        }
    }
    $users = array();
    debugMsg("getting users on newly created pages " . sizeof($revisions) . " revisions ");
    $count = 0;
    foreach ($revisions as $page_id => $rev_id) {
        if (empty($rev_id)) {
            #echo "<!---uh oh: {$page_id} has no min rev!-->";
            continue;
        }
        $u = selectField($dbw, "select rev_user_text from {$table} where rev_id={$rev_id}");
        if (!isset($users[$u])) {
            $users[$u] = 1;
        } else {
            $users[$u]++;
        }
        $count++;
        if ($count % 100 == 0) {
            debugMsg("done {$count}");
        }
    }
    debugMsg("sorting " . sizeof($users) . " users");
    asort($users, SORT_NUMERIC);
    $users = array_reverse($users);
    array_splice($users, 20);
    $yy = 0;
    debugMsg("outputting all of this now " . sizeof($users) . " users");
    foreach ($users as $u => $c) {
        $x = User::newFromName($u);
        $c = nf($c);
        if (!$x) {
            $result .= "<li>{$u} - {$c} new articles created</li>\n";
        } else {
            $result .= "<li> " . getUserLink($x) . " - {$c} new articles created" . getUserToolLinks($x) . "</li>\n";
        }
        $yy++;
        if ($yy == 20) {
            break;
        }
    }
    $result .= "</ol>";
    return $result;
}
Example #5
0
function hasArrived($pickup, $taxi, $client)
{
    debugMsg("HAS ARIVED");
    //TODO Pickup update, cleanup
    $time = time();
    $stime = date("Y-M-d H:i:s");
    $sqlStmnt3 = "update pickups set status = 1 completedTime = " . $stime . " where pickupId = " . $pickupId;
    debugMsg($sqlStmnt3);
    //$result2 = mysql_query($sqlStmnt3,$conn);
    createMessage($client, "PICKARR" . $pickup);
    createMessage($taxi, "PICKARR" . $pickup);
    //Write app first
    //notify client
    //update pickups as success
}
Example #6
0
 public function urlimport($params)
 {
     $this->params = $params;
     // Fetch data
     $filename = $this->getParam('file');
     $frag = $this->getParam('frag', -1);
     $totalSize = $this->getParam('totalSize', -1);
     $doneSize = $this->getParam('doneSize', -1);
     debugMsg('Importing from URL');
     debugMsg('  file      : ' . $filename);
     debugMsg('  frag      : ' . $frag);
     debugMsg('  totalSize : ' . $totalSize);
     debugMsg('  doneSize  : ' . $doneSize);
     // Init retArray
     $retArray = array("status" => true, "error" => '', "frag" => $frag, "totalSize" => $totalSize, "doneSize" => $doneSize, "percent" => 0);
     try {
         AKFactory::set('kickstart.tuning.max_exec_time', '5');
         AKFactory::set('kickstart.tuning.run_time_bias', '75');
         $timer = new AKCoreTimer();
         $start = $timer->getRunningTime();
         // Mark the start of this download
         $break = false;
         // Don't break the step
         while ($timer->getTimeLeft() > 0 && !$break) {
             // Figure out where on Earth to put that file
             $local_file = KSROOTDIR . '/' . basename($filename);
             debugMsg("- Importing from {$filename}");
             // Do we have to initialize the file?
             if ($frag == -1) {
                 debugMsg("-- First frag, killing local file");
                 // Currently downloaded size
                 $doneSize = 0;
                 // Delete and touch the output file
                 @unlink($local_file);
                 $fp = @fopen($local_file, 'wb');
                 if ($fp !== false) {
                     @fclose($fp);
                 }
                 // Init
                 $frag = 0;
             }
             // Calculate from and length
             $length = 1048576;
             $from = $frag * $length;
             $to = $length + $from - 1;
             //if($from == 0) $from = 1;
             // Try to download the first frag
             $temp_file = $local_file . '.tmp';
             @unlink($temp_file);
             $required_time = 1.0;
             debugMsg("-- Importing frag {$frag}, byte position from/to: {$from} / {$to}");
             $filesize = 0;
             try {
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $filename);
                 curl_setopt($ch, CURLOPT_RANGE, "{$from}-{$to}");
                 curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                 $result = curl_exec($ch);
                 $errno = curl_errno($ch);
                 $errmsg = curl_error($ch);
                 $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                 if ($result === false) {
                     $error = "cURL error {$errno}: {$errmsg}";
                 } elseif ($http_status > 299) {
                     $result = false;
                     $error = "HTTP status {$http_status}";
                 } else {
                     $result = file_put_contents($temp_file, $result);
                     if ($result === false) {
                         $error = "Could not open temporary file {$temp_file} for writing";
                     }
                 }
                 curl_close($ch);
             } catch (Exception $e) {
                 $error = $e->getMessage();
             }
             if (!$result) {
                 @unlink($temp_file);
                 // Failed download
                 if ($frag == 0) {
                     // Failure to download first frag = failure to download. Period.
                     $retArray['status'] = false;
                     $retArray['error'] = $error;
                     debugMsg("-- Download FAILED");
                     return $retArray;
                 } else {
                     // Since this is a staggered download, consider this normal and finish
                     $frag = -1;
                     debugMsg("-- Import complete");
                     $doneSize = $totalSize;
                     $break = true;
                     continue;
                 }
             }
             // Add the currently downloaded frag to the total size of downloaded files
             if ($result) {
                 clearstatcache();
                 $filesize = (int) @filesize($temp_file);
                 debugMsg("-- Successful download of {$filesize} bytes");
                 $doneSize += $filesize;
                 // Append the file
                 $fp = @fopen($local_file, 'ab');
                 if ($fp === false) {
                     debugMsg("-- Can't open local file for writing");
                     // Can't open the file for writing
                     @unlink($temp_file);
                     $retArray['status'] = false;
                     $retArray['error'] = 'Can\'t write to the local file';
                     return false;
                 }
                 $tf = fopen($temp_file, 'rb');
                 while (!feof($tf)) {
                     $data = fread($tf, 262144);
                     fwrite($fp, $data);
                 }
                 fclose($tf);
                 fclose($fp);
                 @unlink($temp_file);
                 debugMsg("-- Temporary file merged and removed");
                 if ($filesize > $length) {
                     debugMsg("-- Read more data than the requested length. I assume this file is complete.");
                     $frag = -1;
                 } else {
                     $frag++;
                     debugMsg("-- Proceeding to next fragment, frag {$frag}");
                 }
             }
             // Advance the frag pointer and mark the end
             $end = $timer->getRunningTime();
             // Do we predict that we have enough time?
             $required_time = max(1.1 * ($end - $start), $required_time);
             if ($required_time > 10 - $end + $start) {
                 $break = true;
             }
             $start = $end;
         }
         if ($frag == -1) {
             $percent = 100;
         } elseif ($doneSize <= 0) {
             $percent = 0;
         } else {
             if ($totalSize > 0) {
                 $percent = 100 * ($doneSize / $totalSize);
             } else {
                 $percent = 0;
             }
         }
         // Update $retArray
         $retArray = array("status" => true, "error" => '', "frag" => $frag, "totalSize" => $totalSize, "doneSize" => $doneSize, "percent" => $percent);
     } catch (Exception $e) {
         debugMsg("EXCEPTION RAISED:");
         debugMsg($e->getMessage());
         $retArray['status'] = false;
         $retArray['error'] = $e->getMessage();
     }
     return $retArray;
 }
Example #7
0
function run_tripwire($dir = false)
{
    global $config, $filelist;
    // If no Directory Specified, Default to the Root of the Site the script is executed under
    if (!$dir) {
        $dir = $_SERVER['DOCUMENT_ROOT'];
    }
    // If last character is a slash, strip it off the end
    if (substr($dir, -1) == '/') {
        $dir = substr($dir, 0, -1);
    }
    // If the supplied variable is not a Directory, terminate
    if (!is_dir($dir)) {
        debugMsg("Directory '{$dir}' does not exist.\n");
        return false;
    }
    debugMsg("Checking directory '{$dir}'\n");
    $temp = array();
    $d = dir($dir);
    if ($d) {
        // Loop through the files
        while (false !== ($entry = $d->read())) {
            // Full Entry (including Directory)
            $entry_full = $dir . '/' . $entry;
            // Debugging
            debugMsg("<tr><th align='left'>{$entry_full}</th>");
            // Symbolic Link - Excluded
            if (@is_link($entry)) {
                debugMsg("<td><em>Symbolic Link</em></td></tr>\n");
                continue;
            }
            // Excluded File/Folder
            if ($f1 = in_array($entry, $config['exclude']['files']) || in_array($entry_full, $config['exclude']['files'])) {
                debugMsg("<td><em>Excluded File/Folder (" . array_search(isset($f1) && $f1 ? $entry : $entry_full, $config['exclude']['files']) . ")</em></td></tr>\n");
                continue;
            }
            // Excluded File Extension
            if (in_array(pathinfo($entry, PATHINFO_EXTENSION), $config['exclude']['extensions'])) {
                debugMsg("<td><em>Excluded File Extension (" . array_search(pathinfo($entry, PATHINFO_EXTENSION), $config['exclude']['extensions']) . ")</em></td></tr>\n");
                continue;
            }
            if (is_dir($dir . '/' . $entry)) {
                // Recurse
                debugMsg("<td>Directory - Recursing</td></tr>\n");
                $temp = array_merge($temp, run_tripwire($dir . '/' . $entry));
            } else {
                $md5 = @md5_file($dir . '/' . $entry);
                debugMsg("<td>{$md5}</td></tr>\n");
                if (!$md5) {
                    debugMsg("<td><strong>Unreadable. Adding to Unreadable List.</strong></td></tr>\n");
                    file_put_contents('tripwire_unreadable.txt', "{$dir}/{$entry} - Unreadable\n", FILE_APPEND);
                } else {
                    $temp[$dir . '/' . $entry] = $md5;
                }
            }
        }
    }
    if ($d) {
        $d->close();
    }
    return $temp;
}