Exemplo n.º 1
0
function ShowModifications(&$p, $db_table, $db_id)
{
    global $database;
    $m_mod = new Modification($database);
    $m_auth = new Auth($database);
    $mods = $m_mod->byTableID($db_table, $db_id);
    if (!false_or_null($mods)) {
        $data = array();
        foreach ($mods as $mod) {
            $user = $m_auth->Get($mod['r_Auth']);
            $what = '';
            $w = json_decode($mod['What'], true);
            foreach ($w as $dataset) {
                foreach ($dataset as $table => $change) {
                    $what .= $table . ' #' . $change['I'] . '\'s ' . $change['F'] . (isset($change['E']) ? ' » ' . $change['E'] : '');
                }
            }
            $data[] = array($user['username'], $what, $mod['Message'], human_datetime(intval($mod['Timestamp'])));
        }
        $table = new TableHelper(array('table' => "table wide", 'thead' => "tablehead", 'th' => "tablehead", 'td' => "tablecell", 'headings' => array('Who', 'What', ' ', 'When'), 'data' => $data));
        $p->HTML('<div class="formgroup">');
        $p->HTML('<h4>Recent Activity</h4>');
        $p->Table($table);
        $p->HTML('</div>');
    }
}
Exemplo n.º 2
0
function AutoLockCheck($table, $id)
{
    plog("AutoLockCheck: Start");
    global $database, $auth, $auth_model;
    $m = new AutoRowLock($database);
    // Expire old locks
    $m->Delete('Timestamp < ' . strtotime('-10 minutes'));
    $locks = $m->Select(array('I' => $ID, 'T' => $Table));
    if (!false_or_null($locks) && count($locks) > 0) {
        $found = false;
        $others = 0;
        foreach ($locks as $lock) {
            if ($m->Expired($lock)) {
                $m->Delete(array('ID' => $lock['ID']));
            } else {
                if ($m->LockedByMe($lock)) {
                    if ($found === true) {
                        $m->Delete(array('ID' => $lock['ID']));
                    } else {
                        $m->RefreshLock($lock);
                        $found = true;
                    }
                } else {
                    $others++;
                }
            }
        }
        return $found === true || $others === 0;
    }
    plog("AutoLockCheck: End");
    return FALSE;
}
Exemplo n.º 3
0
Arquivo: File.php Projeto: h3rb/page
 public function LatestTotals($id, $byType = FALSE)
 {
     $ordering = ' ';
     if ($byType === FALSE) {
         $result = $this->Select('Uploader = ' . $id . $ordering);
     } else {
         if (matches($byType, 'stl')) {
             $result = $this->Select('Type LIKE "%stl%"' . $ordering);
         } else {
             if (matches($byType, 'images')) {
                 $result = $this->Select('Type LIKE "image%"' . $ordering);
             } else {
                 if (matches($byType, 'configs')) {
                     $result = $this->Select('Type LIKE "text/plain"' . $ordering);
                 } else {
                     if (matches($byType, 'wav')) {
                         $result = $this->Select('Type LIKE "audio/wav"' . $ordering);
                     } else {
                         if (matches($byType, 'flac')) {
                             $result = $this->Select('Type LIKE "audio/flac"' . $ordering);
                         } else {
                             if (matches($byType, 'f3xb')) {
                                 $result = $this->Select('Type LIKE "font/3d-extruded-binary"' . $ordering);
                             } else {
                                 $result = $this->Select('ORDER BY ID DESC');
                             }
                         }
                     }
                 }
             }
         }
     }
     return false_or_null($result) ? 0 : count($result);
 }
Exemplo n.º 4
0
Arquivo: Auth.php Projeto: h3rb/page
 function ExpirePassword($auth)
 {
     if (!false_or_null($auth)) {
         $this->Set($auth['ID'], array($auth['password_expiry'] => strtotime('now')));
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 5
0
 public function Latest()
 {
     $settings = $this->Select(' ORDER BY ID LIMIT 1 DESC');
     if (false_or_null($settings)) {
         // Defaults
         return array();
     } else {
         return json_decode($settings['JSON'], true);
     }
 }
Exemplo n.º 6
0
 public function LockedTo($lock)
 {
     if (false_or_null($lock)) {
         return FALSE;
     }
     global $database;
     $a_model = new Auth($database);
     $user = $a_model->Get($lock['r_Auth']);
     if (false_or_null($user)) {
         return FALSE;
     }
     return $user['username'];
 }
Exemplo n.º 7
0
Arquivo: Locks.php Projeto: h3rb/page
function LockCheck($table, $id)
{
    if (matches($table, "Modified")) {
        return FALSE;
    }
    global $database;
    $m = new RowLock($database);
    $locks = $m->Select(array('I' => $table, 'T' => $id));
    if (!false_or_null($locks) && count($locks) > 0) {
        return TRUE;
    }
    return FALSE;
}
Exemplo n.º 8
0
if (!isset($getpost['I']) || !isset($getpost['T'])) {
    die;
}
$ID = $getpost['I'];
$Table = $getpost['T'];
if (!Auth::ACL('edit-' . $Table) && !Auth::ACL('edit-' . $Table . '-' . $Field) && !Auth::ACL('su')) {
    echo json_encode(array("message" => 'Read Only', "unlocked" => 0));
    exit;
}
global $auth_database, $auth, $auth_model;
$m = new AutoRowLock($auth_database);
$m->Delete('Timestamp < ' . strtotime('-10 minutes'));
// Expire old locks
$locks = $m->Select(array('I' => $ID, 'T' => $Table));
// Find existing locks
if (!false_or_null($locks) && count($locks) > 0) {
    $found = false;
    $others = 0;
    foreach ($locks as $lock) {
        if ($m->Expired($lock)) {
            $m->Delete(array('ID' => $lock['ID']));
        } else {
            if ($m->LockedByMe($lock)) {
                if ($found === true) {
                    $m->Delete(array('ID' => $lock['ID']));
                } else {
                    $m->RefreshLock($lock);
                    $found = true;
                }
            } else {
                $others++;
Exemplo n.º 9
0
                            if (!false_or_null($f)) {
                                $tname = $files->ThumbName($f);
                                $result[$i++] = array(0 => intval($s['ID']), 1 => $f['Name'] . ' #' . $f['ID'] . ' ' . $s['Width'] . 'x' . $s['Height'], 2 => $files->ThumbName($f), 3 => $f['ID'], 4 => '<img src="' . $tname . '"><div>' . $f['Name'] . ' (#' . $item['ID'] . ')</div><div class="json-stat-image">' . $stats . '</div>');
                            }
                        }
                    }
                    echo json_encode($result);
                    exit;
                } else {
                    // Catch-all generic response for table
                    if (file_exists('model/' . $getpost['R'] . '.php')) {
                        $classname = $getpost['R'];
                        $result = array();
                        $model = new $classname($database);
                        $rows = $model->All();
                        $i = 1;
                        $result[0] = array(0 => '0', 1 => 'None', 2 => 'None');
                        if (!false_or_null($rows)) {
                            foreach ($rows as $s) {
                                $result[$i++] = array(0 => intval($s['ID']), 1 => $s['Name'], 2 => $s['Name'] . ' #' . $s['ID']);
                            }
                        }
                        echo json_encode($result);
                        exit;
                    }
                }
            }
        }
    }
}
echo '{"result":"error"}';
Exemplo n.º 10
0
plog("New page!");
$p = new Page();
if (!$p->ajax) {
    $p->HTML('header.html', array("###MENU###" => Dropdown_menu($p)));
}
$p->title = "Your Website";
$p->CSS("main.css");
$p->Jquery();
$getpost = getpost();
$p->HTML('<BR>');
global $auth_database;
plog("Get mods!");
$m = new Modification($auth_database);
$mods = $m->All('ORDER BY Timestamp DESC');
$m_auth = new Auth($auth_database);
if (!false_or_null($mods)) {
    $datatemp = array();
    foreach ($mods as $mod) {
        $user = $m_auth->Get($mod['r_Auth']);
        if (!isset($datatemp[$user['username']])) {
            $datatemp[$user['username']] = 1;
        } else {
            $datatemp[$user['username']] += 1;
        }
    }
    $datapoints = array();
    foreach ($datatemp as $username => $events) {
        $datapoints[] = array("value" => $events, "color" => "#FFAAAA", "highlight" => "5AD3D1", "label" => $username);
    }
    $chart = Pie($p, 400, 400, $datapoints);
    //  $p->CSS('.'.$chart.' { }');
Exemplo n.º 11
0
Arquivo: model.php Projeto: h3rb/page
 public function Duplicate($ID, $prev_field = NULL)
 {
     $source = $this->Get($ID);
     if (false_or_null($source)) {
         return FALSE;
     }
     if (!false_or_null($prev_field)) {
         $source[$prev_field] = $ID;
     }
     unset($source['ID']);
     return $this->Insert($source);
 }
Exemplo n.º 12
0
function AjaxImageSelector(&$p, $image_name, $table, $table_row_id, $field, $value, $length = 20, $none = TRUE)
{
    global $ajax_image_selector_id;
    $ajax_image_selector_id++;
    $a_id = $ajax_image_selector_id;
    global $database;
    $fileimage_model = new FileImage($database);
    $p->HTML('<div class="formemphasis2 wide">');
    $p->HTML('<table width="100%"><tr class="no-hover"><td width="300" class="no-hover" id="ajax-image-preview' . $a_id . '">');
    $p->HTML('<h3>' . $image_name . '</h3>');
    $icon = NULL;
    if (intval($value) > 0) {
        $icon = $fileimage_model->GetAll($value);
    }
    if (false_or_null($icon)) {
        $p->HTML('No image.');
    } else {
        $p->HTML('<img src="' . $fileimage_model->ThumbName($icon, 256) . '"><BR>' . $icon['File']['Name']);
    }
    $p->HTML('</td><td class="no-hover" width="*">');
    AJAXSelector($p, 1, $length, "ajax_image_preview_" . $a_id);
    $p->HTML('</td></tr></table>');
    $p->HTML('</div>');
    $p->JS('
  function ajax_image_preview_' . $a_id . '( fileimage_id ) {
       $.ajax({
        dataType: "html",
        url: "ajax.bound",
        data: {T:"' . $table . '",F:"' . $field . '",V:fileimage_id,I:' . $table_row_id . '},
        success: function(d) {
        }
       });
       $.ajax({
        dataType: "html",
        url: "ajax.html.stat",
        data: {T:"FileImage",I:fileimage_id,X:256},
        success: function(d) {
         $("#ajax-image-preview' . $a_id . '").html("<h3>' . $image_name . '</h3>"+d); }
       });
  }
');
    if ($none === TRUE) {
        $p->HTML('<button id="image-remove-' . $a_id . '" class="buttonlink"><span class="fa fa-sign-out"></span> Remove Image</button>');
        $p->JQ(' $("#image-remove-' . $a_id . '").on("click",function(e){ajax_image_preview_' . $a_id . '(0);}); ');
    }
}
Exemplo n.º 13
0
 public function Prepare()
 {
     $jq = '';
     $js = '';
     $html = '<div id="' . $this->rap . '_invis" style="display:none;"></div>';
     foreach ($this->element as $e) {
         $js .= $e->js;
         $jq .= $e->jq;
         $html .= $e->html . PHP_EOL;
     }
     $submit = NULL;
     $this->map = array();
     foreach ($this->element as &$e) {
         if (is_null($submit) && get_class($e) == 'FormSubmit') {
             $submit =& $e;
         } else {
             if (get_class($e) == 'FormInsert') {
                 continue;
             } else {
                 if (!false_or_null($e->field)) {
                     $this->map[] = $this->rap . '__' . $e->name . '|' . $e->field;
                 }
             }
         }
     }
     if (!is_null($submit)) {
         global $ajax_unique;
         $ajax_unique++;
         $serialized = '"&ajax=1&u=' . $ajax_unique . '"' . PHP_EOL;
         $serialized .= ' +"&rap=' . FormHelper::Encode($this->rap) . '"' . PHP_EOL;
         if (count($this->map) > 0) {
             $serialized .= ' +"&map=' . FormHelper::Encode(json_encode($this->map)) . '"' . PHP_EOL;
         }
         if ($this->dbid !== NULL) {
             $serialized .= ' +"&dbid=' . FormHelper::Encode($this->dbid) . '"' . PHP_EOL;
         }
         if (strlen($this->table) > 0) {
             $serialized .= ' +"&table=' . FormHelper::Encode($this->table) . '"' . PHP_EOL;
         }
         if ($this->signal !== NULL) {
             $serialized .= ' +"&signal=' . FormHelper::Encode(json_encode($this->signal)) . '"' . PHP_EOL;
         }
         foreach ($this->element as &$e) {
             if ($e != $submit && get_class($e) !== 'FormInsert') {
                 $serialized .= ' +"&' . $this->rap . '__' . $e->name . '="+encodeURIComponent(btoa(' . $e->Data() . '))' . PHP_EOL;
             }
         }
         $jq .= '$("#' . $submit->name . '").click(function(){' . PHP_EOL . 'var url="' . $this->url . '"; $.ajax({' . PHP_EOL . 'type: "POST", url: url, dataType: "html", data: ' . $serialized . ', success: function (r) { $("#' . $this->rap . '_invis").html(r); }' . PHP_EOL . ' });' . PHP_EOL . '});' . PHP_EOL;
     }
     $this->jq = $jq;
     $this->js = $js;
     $this->html = '<!--form: ' . $this->uid . '--><div id="' . $this->rap . '"><FORM id="' . $this->name . '" name="' . $this->rap . '">' . PHP_EOL . $html . '</FORM></div><!--form: ' . $this->uid . '-->' . PHP_EOL;
 }
Exemplo n.º 14
0
Arquivo: Charts.php Projeto: h3rb/page
function Radar(&$p, $w = 400, $h = 400, $labels, $datasets, $options = NULL)
{
    global $_chartsjs_included;
    if ($_chartsjs_included === FALSE) {
        $_chartsjs_included = TRUE;
        $p->JS('Chart.min.js');
    }
    $labels = json_encode($labels);
    $datasets = json_encode($datasets);
    if (false_or_null($options)) {
        $options = json_encode(array());
    } else {
        $options = json_encode($options);
    }
    global $_cradars;
    $_cradars++;
    global $_chartsjs;
    $_chartsjs++;
    $id = "RadarChart" . $_cradars;
    $js = "";
    $js .= 'var ' . $id . '_data={ labels:' . json_encode($labels) . ', datasets:' . json_encode($datasets) . ' };
';
    $js .= 'var ' . $id . '_opts={ ' . $options . ' };
';
    $js .= "var {$id}=new Chart(" . '$("#' . $id . '").get(0).getContext("2d")).Radar(' . $id . '_data' . ',' . $id . '_opts);
';
    $p->JQ($js);
    $p->HTML("<canvas id='{$id}' width='{$w}' height='{$h}'></canvas>");
    return $id;
}
Exemplo n.º 15
0
Arquivo: Page.php Projeto: h3rb/page
 public function HTML($html, $replacements = FALSE, $body = TRUE)
 {
     if (isfile($html, 'html/', FALSE)) {
         $html = file_get_contents('html/' . $html);
     }
     $out = '';
     if (false_or_null($replacements) === TRUE) {
         if (is_array($html)) {
             foreach ($html as $h) {
                 $out .= $h;
             }
         } else {
             $out = $html;
         }
     } else {
         if (is_array($replacements)) {
             if (is_array($html)) {
                 foreach ($html as $h) {
                     if (isfile($h, 'html/', FALSE)) {
                         $replaced = file_get_contents('html/' . $h);
                     } else {
                         $replaced = $h;
                     }
                     foreach ($replacements as $string => $replace) {
                         $replaced = str_replace($string, $replace, $replaced);
                     }
                     $out .= $replaced;
                 }
             } else {
                 if (isfile($html, 'html/', FALSE)) {
                     $replaced = file_get_contents($html);
                 } else {
                     $replaced = $html;
                 }
                 foreach ($replacements as $string => $replace) {
                     $replaced = str_replace($string, $replace, $replaced);
                 }
                 $out = $replaced;
             }
         } else {
             error('Page:HTML(`' . $html . '`,`' . $replacements . '`', 'replacements provided was not array');
         }
     }
     if ($body === TRUE) {
         $this->body[] = $out;
     } else {
         $this->head[] = $out;
     }
     return $out;
 }
Exemplo n.º 16
0
 public function __construct()
 {
     $this->list = array();
     $this->security = contains(file_get_contents('/offline/hamachi.login.txt'), "not have permission");
     $h = explode("\n", file_get_contents('/offline/hamachi.txt'));
     $l = explode("\n", file_get_contents('/offline/hamachi.list.txt'));
     $network = NULL;
     if (!$this->security) {
         foreach ($l as $line) {
             if (strpos($line, " * [") === 0) {
                 // active network
                 $network = new HamachiNetwork($line);
                 $this->list[] =& $network;
             } else {
                 if (!false_or_null($network) && strlen(trim($line)) > 0) {
                     $network->Add($line);
                 }
             }
         }
         foreach ($h as &$k) {
             if (strlen(trim($k)) > 0) {
                 $k = explode(": ", $k);
                 $k = trim($k[1]);
             }
         }
         $this->version = $h[0];
         $this->pid = $h[1];
         $this->status = $h[2];
         $this->client_id = $h[3];
         $address = explode(" ", $h[4]);
         $this->ip = $address[0];
         $this->ipv6 = $address[1];
         $this->nickname = $h[5];
         $this->lmi = $h[6];
     }
 }
Exemplo n.º 17
0
 public function Join($values, $tableA, $tableB, $order_by = FALSE, $columns = '*', $limit = FALSE, $offset = 0, $where = FALSE, $type = 'INNER', $on_or_using = "ON")
 {
     if (is_array($tableA)) {
         $tableA = implode(',', $tableA);
     }
     if (is_array($tableB)) {
         $tableB = implode(',', $tableB);
     }
     if (is_array($values)) {
         $value = array();
         foreach ($values as $a => $b) {
             $value[] = $a . '=' . $b;
         }
         $value = implode(',', $value);
     } else {
         $value = $values;
     }
     $ending = '';
     if (!false_or_null($where)) {
         if (is_array($where)) {
             $ending .= $this->where;
         } else {
             $ending .= ' WHERE (' . $where . ')';
         }
     }
     if (!false_or_null($order_by) && strlen($order_by) > 0) {
         $ending .= ' ORDER BY ' . $order_by;
     }
     if (!false_or_null($limit)) {
         $limit = intval($limit);
         $ending .= ' LIMIT ' . $limit;
         if ($offset > 0) {
             $ending .= ' OFFSET ' . $offset;
         }
     }
     $query = 'SELECT ' . $columns . ' FROM ' . $tableA . ' ' . $type . ' JOIN ' . $tableB . ' ' . $on_or_using . ' ' . $value . $ending . ';';
     $result = $this->Run($query);
     if (false_or_null($result)) {
         return array();
     }
     if (count($result) == 1) {
         return array_shift($result);
     }
     return $result;
 }
Exemplo n.º 18
0
    Page::Redirect('dash');
}
if (isset($getpost['new'])) {
    $p->JS('notifier.js');
    $p->JS('Notifier.info("Editing new Item");');
}
$p->HTML('<BR>');
global $auth_database;
$profile_model = new Profile($auth_database);
$auth_model = new Auth($auth_database);
$a = $auth_model->Get($getpost['ID']);
if (false_or_null($a)) {
    Page::Redirect('profiles');
}
$pro = $profile_model->Get($a['r_Profile']);
if (false_or_null($pro)) {
    Page::Redirect('profiles');
}
$p->HTML('<span class="breadcrumbs">Editing Profile #' . $pro['ID'] . ' and Auth #' . $a['ID'] . '</span>');
$p->HTML('<span class="breadcrumbs-link"><a href="profiles" class="bare">&larr; Profiles</a></span>');
$p->Bind_LoadPlugins();
$p->HTML('<div class="formboundary">');
$p->HTML('<div class="formgroup wide">');
$p->HTML('Username');
$p->BindString("Auth", $a['ID'], "username", $a['username'], "Enter username", FALSE, "texty");
$p->HTML('</div>');
$p->HTML('<div class="formgroup wide">');
$p->HTML('First');
$p->BindString("Profile", $pro['ID'], "first_name", $pro['first_name'], "Enter first", FALSE, "texty");
$p->HTML('Last');
$p->BindString("Profile", $pro['ID'], "last_name", $pro['last_name'], "Enter first", FALSE, "texty");
Exemplo n.º 19
0
 private function check_cookie($report = false)
 {
     if ($report === true) {
         plog('check_cookie(): ');
     }
     // Check for the session variable or the appropriate cookie information.
     if (!isset($_SESSION['username']) || is_null($_SESSION['username']) || strlen(trim($_SESSION['username'])) == 0) {
         $ID = base64_decode($_COOKIE['session']);
         $username = base64_decode($_COOKIE['username']);
     } else {
         $username = base64_decode($_SESSION['username']);
         $ID = base64_decode($_SESSION['session']);
     }
     if ($report === true) {
         $this->print_debug_info();
     }
     // Determine if the session should has expired this page load.
     global $expired;
     $expired = false;
     // This is an expired session.
     if (strlen($ID) == 0 || strlen($username) == 0) {
         $expired = true;
         return FALSE;
     }
     // Garner the valid session information.
     global $session_id;
     $session_id = $ID;
     global $session;
     $session = $session_model->Get($ID);
     plog('check_cookie: session=' . var_export($session, true));
     // Invalid or expired session
     if (false_or_null($session) || !is_array($session)) {
         $expired = true;
         return FALSE;
     }
     // Test for inactivity timeout.
     if ($this->Timedout($session)) {
         $this->Logout();
         $expired = true;
         return FALSE;
     }
     // Did we already log out?
     if ($this->LoggedOut($session)) {
         $expired = true;
         return FALSE;
     }
     $this->Refresh($session);
     global $auth_model;
     global $auth;
     $auth = $auth_model->Get(intval($session['r_Auth']));
     // If we delete the user's Auth record, the session is terminated.
     if (false_or_null($auth)) {
         $this->Logout();
         $expired = true;
         return FALSE;
     }
     // Grab the ancillary user profile information based on the session and auth pair.
     global $profile_model;
     global $user;
     $user = $profile_model->Get($auth['r_Profile']);
     // Talk if we're debugging.
     if ($report === true) {
         $this->print_debug_info();
     }
     if ($report === true) {
         plog('check_cookie(): (end)');
     }
     return TRUE;
 }