Example #1
0
 public function parseSysLog()
 {
     /*
      * For parsing the syslog looking for sensord entries
      * POTENTIALLY BUGGY -- only tested on debian/ubuntu flavored syslogs
      * Also slow as balls as it parses the entire syslog instead of
      * using something like tail
      */
     $file = '/var/log/syslog';
     if (!is_file($file) || !is_readable($file)) {
         return array();
     }
     $devices = array();
     foreach (getLines($file) as $line) {
         if (preg_match('/\\w+\\s*\\d+ \\d{2}:\\d{2}:\\d{2} \\w+ sensord:\\s*(.+):\\s*(.+)/i', trim($line), $match) == 1) {
             // Replace current record of dev with updated temp
             $devices[$match[1]] = $match[2];
         }
     }
     $return = array();
     foreach ($devices as $dev => $stat) {
         $return[] = array('path' => 'N/A', 'name' => $dev, 'temp' => $stat, 'unit' => '');
     }
     return $return;
 }
Example #2
0
function getDataForList($input)
{
    global $headers, $curr_line, $lines;
    getLines($input, array());
    $output = array();
    $output['headers'] = $headers;
    $output['lines'] = $lines;
    return $output;
}
Example #3
0
 private function parseSysLogData()
 {
     $file = '/var/log/syslog';
     if (!is_file($file) || !is_readable($file)) {
         return array();
     }
     $devices = array();
     foreach (getLines($file) as $line) {
         if (preg_match('/\\w+\\s*\\d+ \\d{2}:\\d{2}:\\d{2} \\w+ hddtemp\\[\\d+\\]: (.+): (.+): (\\d+) ([CF])/i', trim($line), $match) == 1) {
             // Replace current record of dev with updated temp
             $devices[$match[1]] = array($match[2], $match[3], $match[4]);
         }
     }
     $return = array();
     foreach ($devices as $dev => $stat) {
         $return[] = array('path' => $dev, 'name' => $stat[0], 'temp' => $stat[1], 'unit' => strtoupper($stat[2]));
     }
     return $return;
 }
try {
    $db = new PDO($db, $user, $pass);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo 'Error establishing Connection';
    exit;
}
if (isset($_POST['submit'])) {
    $user = $_POST['user'];
    $pass = $_POST['pass'];
    $_SESSION['user'] = $user;
}
if (verify($user, $pass)) {
    echo 'success';
    $_SESSION['user'] = $user;
    $_SESSION['lines'] = (int) getLines($user);
    $_SESSION['hands'] = (int) getHands($user);
    $_SESSION['cups'] = (int) getCoffee($user);
    $_SESSION['seconds'] = (int) getSeconds($user);
    $_SESSION['money'] = (int) getMoney($user);
    header('Location: menu.php');
} else {
    echo 'incorrect username or password';
}
function verify($username, $password)
{
    global $db;
    $stmt = $db->prepare("SELECT password FROM users WHERE username='******';");
    $stmt->execute();
    $hash = $stmt->fetchColumn();
    return password_verify($password, $hash);
Example #5
0
function setDownloadHtml($requests, $root)
{
    $rqsts = $requests;
    $pagetype = 'main';
    $csvroot = $root . 'items\\csv\\books.csv';
    //return $root;
    /*下面用于判断请求页的类型*/
    if (isset($rqsts[1])) {
        if (preg_match('/^main$/', $rqsts[1])) {
            $pagetype = 'main';
        } else {
            if (preg_match('/^list[\\d]*$/', $rqsts[1])) {
                $pagetype = 'list';
            } else {
                if (preg_match('/^item[\\d]*$/', $rqsts[1]) || preg_match('/^[\\d]+$/', $rqsts[1])) {
                    //return 'item';
                    $pagetype = 'item';
                    //return $pagetype;
                } else {
                    $pagetype = 'main';
                }
            }
        }
    } else {
        $pagetype = 'main';
    }
    /*下面来拉接主页的html*/
    if ($pagetype == 'main') {
        $rqsts[1] = 'list1';
        return setDownloadHtml($rqsts, $root);
    } else {
        if ($pagetype == 'list') {
            $listpage = str_replace('list', '', $rqsts[1]);
            if ($listpage <= 0) {
                $listpage = 1;
            }
            $fp = new SplFileObject($csvroot, 'r');
            $fp_lines = getLines($fp);
            //得到总行数,由于数组从0开始,所以只要显示1到$fp_lines即可(第0行是表头)
            //$fp->fgetcsv(',','')
            //$fp->fg
            $html = setlistNav($listpage);
            $html .= setItemslist($fp_lines, $listpage, $fp, $root);
            $html .= setlistNav($listpage);
            return $html;
        } else {
            if ($pagetype == 'item') {
                //$itemnum = preg_split('item', $rqsts[1])[0];
                $itemnum = $rqsts[1];
                $file = fopen($csvroot, 'r');
                while (!feof($file)) {
                    $iteminfos = explode(',', trim(fgets($file)));
                    if ($iteminfos[0] == $itemnum) {
                        break;
                    }
                }
                $item_exist = !feof($file);
                fclose($file);
                if ($item_exist) {
                    //把各个参数设置
                    $itemid = isset($iteminfos[0]) ? $iteminfos[0] : '';
                    //物品ID
                    $itemtitle = isset($iteminfos[1]) ? $iteminfos[1] : '';
                    //数目标题
                    $itemchntitle = isset($iteminfos[2]) ? $iteminfos[2] : '';
                    //中文标题
                    $itempic = isset($iteminfos[3]) ? $iteminfos[3] : '';
                    //物品图片文件名
                    //if(!file_exists($root.'items\imgs\\'.$itempic))$itempic='abc';
                    $itempic = file_exists($root . 'items/imgs/' . $itempic) ? $root . 'items/imgs/' . $itempic : $root . 'items/imgs/NoPic.gif';
                    $itempublisher = isset($iteminfos[4]) ? $iteminfos[4] : '';
                    //出版商
                    $itemauthor = isset($iteminfos[5]) ? $iteminfos[5] : '';
                    //作者
                    $itempages = isset($iteminfos[6]) ? $iteminfos[6] : '';
                    //页码数
                    $itemisbn = isset($iteminfos[7]) ? $iteminfos[7] : '';
                    //isbn
                    $itemtag_string = isset($iteminfos[8]) ? $iteminfos[8] : '';
                    //标签原始字符串用"|"分割
                    $itemurl_string = isset($iteminfos[9]) ? $iteminfos[9] : '';
                    //下载链接原始字符串用"|"分割
                    $itemtags = explode('|', $itemtag_string);
                    $itemurls = explode('|', $itemurl_string);
                    $adver1 = '<script type="text/javascript">var sogou_ad_id=60486;var sogou_ad_height=60;var sogou_ad_width=640;</script><script language="JavaScript" type="text/javascript" src="http://images.sohu.com/cs/jsfile/js/c.js"></script>';
                    $html = '<TABLE class="allinfo" cellSpacing="0" cellPadding="0" width="700">' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD class="pictd" rowSpan="4">' . "\n";
                    $html .= '<DIV>' . "\n";
                    $html .= '<CENTER>' . "\n";
                    $html .= '<IMG title="' . $itemtitle . '" alt="' . $itemtitle . '" src="' . $itempic . '">' . "\n";
                    $html .= '</CENTER>' . "\n";
                    $html .= '</DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '<TD style="width: 580px;">' . "\n";
                    $html .= '<DIV class="title">' . $itemtitle . '</DIV>' . "\n";
                    $html .= '<DIV class="chinesetitle">中文书名:' . $itemchntitle . '</DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD><SPAN class="author">作者:</SPAN><SPAN class="author">' . $itemauthor . '</SPAN></TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD><SPAN>出版社:</SPAN><SPAN>' . $itempublisher . '</SPAN></TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD style="text-align: left; color: rgb(50, 124, 142); font-size: 13px;">资料标签:';
                    for ($i = 0; isset($itemtags[$i]); $i++) {
                        $html .= $itemtags[$i] . ' ';
                    }
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD style="text-align: left; color: rgb(50, 124, 142); font-size: 13px;" colSpan="2">' . "\n";
                    $html .= '<TABLE cellSpacing="0" cellPadding="0">' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD style="width: 100px; text-align: center; vertical-align: middle;">' . "\n";
                    $html .= '<DIV style="float: left;" class="downloadtext">下载链接:</DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '<TD>' . "\n";
                    $html .= '<DIV class="downloadtext1">第一次下载请务必了解<A href="#ins">下载说明</A>。</DIV>' . "\n";
                    $html .= '<DIV><!-- 广告位 -->' . $adver1 . '</DIV>' . "\n";
                    $html .= '<SPAN class="downlink">' . "\n";
                    for ($i = 0; isset($itemurls[$i]); $i++) {
                        $html .= '<A href="' . $itemurls[$i] . '"target="_blank">下载地址' . ($i + 1) . '</A> ' . "\n";
                    }
                    $html .= '</SPAN>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '</TABLE>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD colSpan="2">' . "\n";
                    $html .= '<DIV style="margin: 20px; padding: 20px; border: 2px solid rgb(192, 192, 192);">' . "\n";
                    $html .= '<P>&nbsp;</P>' . "\n";
                    $html .= '<DIV id="ins">下载说明:</DIV>' . "\n";
                    $html .= '<P>1、 如果发现有资料不能下载请<A href="#" target="_blank">联系我们</A>。</P></DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '</TABLE>' . "\n";
                    return $html;
                } else {
                    return '没有找到';
                }
            }
        }
    }
}
Example #6
0
/**
 * Determines if we have a valid buffer for optimising.
 *
 * Has to be G1s all round with no Z movements, and either all extrusions or all movements.
 *
 * The extrusions also have to be the same mm^3/mm along the path.
 *
 * They also have to describe a circle
 * @param  SplQueue $buffer The buffer
 * @return Boolean          Whether the buffer is valid
 */
function bufferValid($buffer)
{
    global $debug;
    global $pos_error;
    for ($buffer->rewind(); $buffer->valid(); $buffer->next()) {
        if (substr($buffer->current(), 0, 2) !== "G1") {
            $buffer->rewind();
            return false;
        } else {
            if (strpos($buffer->current(), "Z") !== FALSE) {
                $buffer->rewind();
                return false;
            }
        }
    }
    $lines = getLines($buffer);
    $allE = false;
    $allF = false;
    if (!is_null($lines[0]['E'])) {
        $allE = true;
    }
    if (!is_null($lines[0]['F'])) {
        $allF = true;
    }
    foreach ($lines as $num => $line) {
        $allE = $allE && is_null($line['F']) && !is_null($line['E']);
        $allF = $allF && is_null($line['E']) && !is_null($line['F']);
    }
    if (!($allE || $allF)) {
        $buffer->rewind();
        return false;
    }
    if ($allE) {
        $extrusions = getExtrusionLengths($lines);
        $eerror = calculateExtrusionError($extrusions);
        if (calculateExtrusionError($extrusions) === false) {
            $buffer->rewind();
            return false;
        }
    }
    $lines->rewind();
    $circle = getCircle($lines);
    if ($circle === false) {
        $buffer->rewind();
        return false;
    }
    if (max($circle['errors']) > $pos_error) {
        return false;
    }
    $buffer->rewind();
    return $circle;
}
Example #7
0
            fprintf($hndAc, " [ERROR | FN] ");
        }
        if ($rankSO > 0 and $rankStars < 30) {
            $FP++;
            fprintf($hndAc, " [ERROR | FP] ");
        }
        $boc++;
    }
    print ">> SO: {$rankSO} | Stars: {$rankStars} <<\n";
    fprintf($hndAc, " -> SO: {$rankSO} | Stars: {$rankStars} \n");
    print "\n";
}
unset($ar1);
$fc = $hff;
fprintf($hndAc, "\nOpiniones Positivas de Entrenamiento: " . getLines("train_sets.lst") / 2);
fprintf($hndAc, "\nOpiniones Negativas de Entrenamiento: " . getLines("train_sets.lst") / 2);
print "\nTotal: " . $fc;
fprintf($hndAc, "\nTotal: " . ($fc - 1));
print "\nCorrectos: " . $rightOnes;
fprintf($hndAc, "\nCorrectos: " . $rightOnes);
$perc = $rightOnes * 100 / $hff;
$nf = number_format($perc, 2);
print "\nEfectividad: " . $nf . "%";
fprintf($hndAc, "\nEfectividad: " . $nf . "%%");
print "\nTP = {$TP}, TN = {$TN}, FP = {$FP}, FN = {$FN}";
fprintf($hndAc, "\nTP = {$TP}, TN = {$TN}, FP = {$FP}, FN = {$FN}");
$Accr = ($TP + $TN) / ($TP + $TN + $FP + $FN);
$Prec = $TP / ($TP + $FP);
$Recl = $TP / ($TP + $FN);
$F1 = 2 * $Prec * $Recl / $Prec + $Recl;
print "\nPrecision: " . $Prec;
Example #8
0
<table class="table table-striped">
  <tbody>
    <?php 
if (isset($_GET['path'])) {
    $line = $_GET['line'];
    $poids = recupData($line, $_GET['path'], $bdd);
} else {
    if (isset($_GET['line'])) {
        $path = getPaths($bdd, $_GET['line']);
        viewPath($path, $_GET['line']);
    } else {
        $lines = getLines($bdd);
        viewLines2($lines);
    }
}
?>
  </tbody>
</table>
Example #9
0
        $this->key++;
    }
    public function rewind()
    {
        fseek($this->f, 0);
        $this->data = fgets($this->f);
        $this->key = 0;
    }
    public function valid()
    {
        return false !== $this->data;
    }
}
foreach (new FileIterator('data.txt') as $line) {
    echo "{$line}\n";
}
/* Чтение данных из файла с помощью генератора*/
function getLines($file)
{
    $f = fopen($file, 'r');
    if (!$f) {
        throw new Exception();
    }
    while ($line = fgets($f)) {
        (yield $line);
    }
    fclose($f);
}
foreach (getLines('data.txt') as $line) {
    echo "{$line}\n";
}
Example #10
0
if (isset($args[1])) {
    $count = 0;
    $path = $args[1];
    if (is_file($path)) {
        $iterator = [$path];
    } elseif (is_dir($path)) {
        $iterator = new CallbackFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)), function ($file, $key, $iterator) {
            return !$file->isDir() && !$iterator->isDot();
        });
    } else {
        echo "Path {$path} not found.\n";
        die(1);
    }
    foreach ($iterator as $file) {
        echo $file;
        $count += $lines = iterator_count(getLines($file));
        echo " {$lines}\n";
    }
    echo "Total lines of files: {$count}";
} else {
    echo "\n\t\tCounter lines\n\t\t----------------------------\n\t\tUsage: {$args[0]} [<directory> | <file>]\n\t\t";
    die(1);
}
function getLines($file)
{
    $f = fopen($file, 'r');
    // read each line of the file without loading the whole file to memory
    try {
        while ($line = fgets($f)) {
            (yield $line);
        }
Example #11
0
/**
 * @deprecated
 * @param  [type] $buffer [description]
 * @param  string $id     [description]
 * @return [type]         [description]
 */
function processBuffer($buffer, $id = 'gcodeview')
{
    global $pos_error;
    global $debug;
    $lines = getLines($buffer);
    $circle = getCircle($lines);
    if ($circle == false) {
        return false;
    }
    if (max($circle['errors']) < $pos_error) {
        return $circle;
    } else {
        return false;
    }
    //print_r($lines);
}