Example #1
0
function display_log($logname)
{
    global $lang_viewlog_php, $folder_icon, $delete_all_icon, $delete_this_icon, $view_icon, $LINEBREAK;
    echo <<<EOT
            <tr>
                    <td class="tableb" align="center">
                            <button type="button" class="button" name="dall" value="{$lang_viewlog_php['delete_all']}" id="dall" onclick="window.location='viewlog.php?action=dall';">{$delete_all_icon}{$lang_viewlog_php['delete_all']}</button>
                            <button type="button" class="button" value="{$lang_viewlog_php['view_logs']}" name="back1" id="back1" onclick="window.location='viewlog.php';">{$view_icon}{$lang_viewlog_php['view_logs']}</button>
                            <button type="button" class="button" value="{$lang_viewlog_php['delete_this']}" name="dthis1" id="dthis1" onclick="window.location='viewlog.php?action=dthis&amp;log={$logname}';">{$delete_this_icon}{$lang_viewlog_php['delete_this']}</button>
                    </td>
            </tr>
            <tr>
                    <td class="tableb">
                            <ul>
EOT;
    $log_array = explode('---', log_read($logname));
    foreach ($log_array as $log_entry) {
        if ($log_entry != '' && $log_entry != $LINEBREAK) {
            echo '<li>' . nl2br(htmlspecialchars(trim($log_entry))) . '</li>' . $LINEBREAK;
        }
    }
    echo <<<EOT
                            </ul>
                    </td>
            </tr>
            <tr>
                    <td class="tableb" align="center">
                            <button class="button" type="button" value="{$lang_viewlog_php['delete_all']}" name="dall2" id="dall2" onclick="window.location='viewlog.php?action=dall';">{$delete_all_icon}{$lang_viewlog_php['delete_all']}</button>
                            <button class="button" type="button" value="{$lang_viewlog_php['view_logs']}" name="back2" id="back2" onclick="window.location='viewlog.php';">{$view_icon}{$lang_viewlog_php['view_logs']}</button>
                            <button class="button" type="button" value="{$lang_viewlog_php['delete_this']}" name="dthis2" id="dthis2" onclick="window.location='viewlog.php?action=dthis&amp;log={$logname}';">{$delete_this_icon}{$lang_viewlog_php['delete_this']}</button>
                    </td>
            </tr>

EOT;
}
Example #2
0
function display_log($logname)
{
    global $lang_viewlog_php;
    echo <<<EOT
\t\t\t\t<tr>
\t\t\t\t\t\t<td class="tableb" align="center">
\t\t\t\t\t\t\t\t<input class="button" type="button" value="{$lang_viewlog_php['delete_all']}" name="dall1" id="dall1" onclick="window.location='viewlog.php?action=dall';" />
\t\t\t\t\t\t\t\t<input class="button" type="button" value="{$lang_viewlog_php['view_logs']}" name="back1" id="back1" onclick="window.location='viewlog.php';" />
\t\t\t\t\t\t\t\t<input class="button" type="button" value="{$lang_viewlog_php['delete_this']}" name="dthis1" id="dthis1" onclick="window.location='viewlog.php?action=dthis&amp;log={$logname}';" />
\t\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t\t<tr>
\t\t\t\t\t\t<td class="tableb">
\t\t\t\t\t\t\t\t<pre>
EOT;
    log_read($logname);
    echo <<<EOT
\t\t\t\t\t\t\t\t</pre>
\t\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t\t<tr>
\t\t\t\t\t\t<td class="tableb" align="center">
\t\t\t\t\t\t\t\t<input class="button" type="button" value="{$lang_viewlog_php['delete_all']}" name="dall2" id="dall2" onclick="window.location='viewlog.php?action=dall';" />
\t\t\t\t\t\t\t\t<input class="button" type="button" value="{$lang_viewlog_php['view_logs']}" name="back2" id="back2" onclick="window.location='viewlog.php';" />
\t\t\t\t\t\t\t\t<input class="button" type="button" value="{$lang_viewlog_php['delete_this']}" name="dthis2" id="dthis2" onclick="window.location='viewlog.php?action=dthis&amp;log={$logname}';" />
\t\t\t\t\t\t</td>
\t\t\t\t</tr>

EOT;
}
Example #3
0
function log_write($game, $entry)
{
    $folder = get_game_folder($game);
    $log = $folder . '/log.json';
    $data = log_read($game);
    $data[] = $entry;
    file_put_contents($log, json_encode($data));
}
Example #4
0
<?php

require_once __DIR__ . '/../lib/functions.php';
if ($_REQUEST['command'] == 'push') {
    log_write($_REQUEST['game'], json_decode($_REQUEST['entry'], true));
}
if ($_REQUEST['command'] == 'get') {
    $skip = empty($_REQUEST['skip']) ? 0 : $_REQUEST['skip'];
    $log = log_read($_REQUEST['game']);
    if (is_array($log)) {
        $log = array_slice($log, $skip);
        header('Content-type: application/json');
        echo json_encode($log);
    }
}
Example #5
0
<?php

require_once '../../includes/initialize.php';
if (!$session->is_logged_in()) {
    redirect_to("login.php");
}
if (isset($_GET['clear'])) {
    if ($_GET['clear'] == 'true') {
        log_clear();
        log_action('Log', 'log was cleared.');
        redirect_to('logfile.php');
    }
}
?>

<?php 
include_layout_template('admin_header.php');
?>
    <div id="menu">
        <h2>Log file</h2>
        <a href="logfile.php?clear=true">Clear log file.</a>
    </div>
<?php 
echo nl2br(log_read());
include_layout_template('admin_footer.php');
Example #6
0
function log_update($kind, $filename, $key, $mustkey, $data)
{
    $log_data = log_read($filename);
    $_key = explode(':', $key);
    $name = log::set_fieldname($kind);
    $put = false;
    for ($i = 0; $i < count($log_data); $i++) {
        $fld = log::line2field($log_data[$i], $name);
        $sw_update = true;
        foreach ($_key as $idx) {
            if (isset($data[$idx]) && isset($fld[$idx]) && $data[$idx] != $fld[$idx]) {
                $sw_update = false;
                break;
            }
            /*
            if (empty($data[$idx]) || empty($fld[$idx])) {
            	$sw_update = false;
            	break;
            }
            if ($data[$idx] != $fld[$idx]) {
            	$sw_update = false;
            	break;
            }
            */
        }
        if ($sw_update) {
            $log_data[$i] = log::array2table($data);
            $put = true;
            break;
        }
    }
    // Add
    if (!$put) {
        if ($mustkey) {
            if (log_mustkey_check($_key, $data)) {
                $log_data[] = log::array2table($data);
                $put = true;
            }
        } else {
            $log_data[] = log::array2table($data);
            $put = true;
        }
    }
    if (!$put) {
        return '';
    }
    $fp = @fopen($filename, 'wb');
    if ($fp == false) {
        return '';
    }
    @flock($fp, LOCK_SH);
    foreach ($log_data as $_log_data) {
        fputs($fp, $_log_data);
    }
    @flock($fp, LOCK_UN);
    @fclose($fp);
}
 function indexAction()
 {
     $log = explode("\n", log_read());
     $data = PagerHelper::arrayPage('admin/log/index', 50, $log);
     return $this->view('log', $data);
 }
Example #8
0
/**
 * Open log file with a condition and use yield
 */
function log_read($name, $fileName = 'dummy.log')
{
    $handle = fopen($fileName, 'r');
    if ($handle) {
        while ($buffer = fgets($handle)) {
            if (strpos($buffer, $name) !== false) {
                // This is the heart of generator. Very simple !
                (yield $buffer);
            }
        }
        if (!feof($handle)) {
            echo "Error: unexpected fgets() faiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiil";
        }
        fclose($handle);
    }
}
$randomNames = array('Khanh', 'Son', 'Bang', 'Viet');
$nameToFind = 'Viet';
// Firstly we write about 1 million lines of text to a file
log_write($randomNames);
// And then open the file and find the lines that contain 'Viet'
$lines = log_read($nameToFind);
foreach ($lines as $key => $line) {
    echo $line, '<br/>';
    if ($key == 10) {
        break;
    }
}