function getTableNameOptions()
 {
     $options = array();
     $stmts = sqlStatement("SHOW TABLES");
     for ($iter = 0; $row = sqlFetchArray($stmts); $iter++) {
         foreach ($row as $key => $value) {
             array_push($options, array("id" => out($value), "label" => out(xl($value))));
         }
     }
     return $options;
 }
Ejemplo n.º 2
0
/**
 * Render the div full of chat messages.
 * @param $chatlength Essentially the limit on the number of messages.
**/
function render_chat_messages($chatlength, $show_elipsis = null)
{
    // Eventually there might be a reason to abstract out get_chats();
    $sql = new DBAccess();
    $sql->Query("SELECT sender_id, uname, message, age(now(), date) as ago FROM chat join players on chat.sender_id = player_id ORDER BY chat_id DESC LIMIT {$chatlength}");
    // Pull messages
    $chats = $sql->fetchAll();
    $message_rows = '';
    $messageCount = $sql->QueryItem("select count(*) from chat");
    if (!isset($show_elipsis) && $messageCount > $chatlength) {
        $show_elipsis = true;
    }
    $res = "<div class='chatMessages'>";
    $previous_date = null;
    $skip_interval = 3;
    // minutes
    foreach ($chats as $messageData) {
        $l_ago = time_ago($messageData['ago'], $previous_date);
        $message_rows .= "<li>&lt;<a href='player.php?player_id={$messageData['sender_id']}'\n\t\t     target='main'>{$messageData['uname']}</a>&gt; " . out($messageData['message']) . " <span class='chat-time'>{$l_ago}</span></li>";
        $previous_date = $messageData['ago'];
        // Store just prior date.
    }
    $res .= $message_rows;
    if ($show_elipsis) {
        // to indicate there are more chats available
        $res .= ".<br>.<br>.<br>";
    }
    $res .= "</div>";
    return $res;
}
Ejemplo n.º 3
0
 function __destruct()
 {
     out($this->Comment);
     // this line doesn't crash PHP
     out("\n<!-- End Section: " . $this->Comment . "-->");
     // this line
 }
Ejemplo n.º 4
0
 public function uninstall()
 {
     out(_("Removing Settings table"));
     $sql = "DROP TABLE IF EXISTS miscdests";
     $q = $this->db->prepare($sql);
     $q->execute();
 }
Ejemplo n.º 5
0
function generic_error($error = 'unspecified')
{
    global $session;
    header('503 Unavailable');
    $session->log(sprintf('JSON API error: "%s"', print_r($error, true)));
    out(array('error' => $error));
}
Ejemplo n.º 6
0
function showHelp()
{
    global $argv;
    out("USAGE:");
    out("  " . $argv[0] . " --create|delete --exten <extension> [optional parameters]");
    out("");
    out("OPERATIONS (exactly one must be specified):");
    out("  --create, -c");
    out("      Create a new extension");
    out("  --modify, -m");
    out("      Modify an existing extension, the extension must exist and all values execept");
    out("      those specified will remain the same");
    out("  --delete, -d");
    out("      Delete an extension");
    out("PARAMETERS:");
    out("  --exten extension_number");
    out("      Extension number to create or delete. Must be specified.");
    out("OPTIONAL PARAMETERS:");
    out("  --name name");
    out("      Display Name, defaults to specified extension number.");
    out("  --outboundcid cid_number");
    out("      Outbound CID Number, defaults to specified extension number.");
    out("  --directdid did_number");
    out("      Direct DID Number, defaults to extension number.");
    out("  --vm-password password");
    out("      Voicemail Password, defaults to specified extension number.");
    out("  --sip-secret secret");
    out("      SIP Secret, defaults to md5 hash of specified extension number.");
    out("  --debug");
    out("      Display debug messages.");
    out("  --no-warnings");
    out("      Do Not display warning messages.");
    out("  --help, -h, -?           Show this help");
}
Ejemplo n.º 7
0
function install($rootFolder)
{
    out('Installing');
    chdir("{$rootFolder}/htdocs");
    getFile("{$rootFolder}/htdocs/dashboard.php", "https://raw.github.com/gist/1512137/dashboard.php");
    return true;
}
Ejemplo n.º 8
0
function need_user()
{
    if (!$_SESSION['user'] && !$_SESSION['extension']) {
        echo out(array("success" => false, "message" => "User is undefined"));
        exit;
    }
}
Ejemplo n.º 9
0
 private function log($message)
 {
     if ($this->output) {
         $this->output->writeln($message);
     } else {
         out($message);
     }
 }
Ejemplo n.º 10
0
function renderFileName($fN)
{
    global $input;
    $f = pathinfo($input . $fN);
    out($f['basename'], "Rendered", "Rendering", "\r");
    renderFile($f['basename']);
    out($f['basename'] . ' as ' . $f['filename'] . '.html', "Rendered");
}
Ejemplo n.º 11
0
 protected function out($data=array(),$code=0,$msg='',$type=0,$outType='',$out=true)
 {
     if(!$outType)
     {
         $outType = $this->DEFAULT_OUT_TYPE;
     }
     out($data,$code,$msg,$type,$outType,$out);
 }
Ejemplo n.º 12
0
function getListOptions($list_id)
{
    $options = array();
    $sql = sqlStatement("SELECT option_id, title from list_options WHERE list_id = ?", array($list_id));
    for ($iter = 0; $row = sqlFetchArray($sql); $iter++) {
        $options[] = new Option(out($row['option_id']), out(xl_list_label($row['title'])));
    }
    return $options;
}
Ejemplo n.º 13
0
function framework_print_errors($src, $dst, $errors)
{
    out("error copying files:");
    out(sprintf(_("'cp -rf' from src: '%s' to dst: '%s'...details follow"), $src, $dst));
    freepbx_log(FPBX_LOG_ERROR, sprintf(_("framework couldn't copy file to %s"), $dst));
    foreach ($errors as $error) {
        out("{$error}");
        freepbx_log(FPBX_LOG_ERROR, _("cp error output: {$error}"));
    }
}
Ejemplo n.º 14
0
function setDestination()
{
    $destNo = $_POST['Destination'];
    out($dest);
    $list = array('1' => array('name' => 'village', 'hazards' => 2), '2' => array('name' => 'town', 'hazards' => 4), '3' => array('name' => 'city', 'hazards' => 6));
    $dest = $list[$destNo];
    $_SESSION["destination"] = $dest;
    $_SESSION["hazards"] = $dest['hazards'];
    $_SESSION["step"]++;
}
Ejemplo n.º 15
0
 function show_error()
 {
     if ($msg = mysql_error()) {
         out("<div style='background:#dadada'>");
         out($msg);
         out("</div>");
         return true;
     }
     return false;
 }
Ejemplo n.º 16
0
/**
 * Basic install script for XHGui2.
 *
 * Does the following things.
 *
 * - Downloads composer.
 * - Installs dependencies.
 */
function out($out)
{
    if (is_string($out)) {
        echo $out . "\n";
    }
    if (is_array($out)) {
        foreach ($out as $line) {
            out($line);
        }
    }
}
Ejemplo n.º 17
0
function install($rootFolder)
{
    out('Installing');
    chdir("{$rootFolder}/");
    $phar = new Phar("{$rootFolder}/dashboard.phar");
    $phar->extractTo("{$rootFolder}/tmp/", null, true);
    system("mv {$rootFolder}/tmp/src/Hoborg/Dashboard/Resources/htdocs/index-phar.php {$rootFolder}/htdocs/index.php");
    system("mv {$rootFolder}/tmp/src/Hoborg/Dashboard/Resources/htdocs/static {$rootFolder}/htdocs/static");
    system("mv {$rootFolder}/tmp/src/Hoborg/Dashboard/Resources/htdocs/images {$rootFolder}/htdocs/images");
    system("rm -rf {$rootFolder}/tmp");
    return true;
}
Ejemplo n.º 18
0
/**
 * 数据还原函数
 * @param unknown $data
 * @return string unknown
 */
function out($data) {
    if (is_string($data)) {
        return $data = stripslashes($data);
    } else if (is_array($data)) {
        foreach ($data as $key => $value) {
            $data[$key] = out($value);
        }
        return $data;
    } else {
        return $data;
    }
}
Ejemplo n.º 19
0
function go_back($param = false)
{
    if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') {
        out();
    }
    $url = $_SERVER['HTTP_REFERER'];
    if ($param != false) {
        $url .= mb_strpos($url, '?') === false ? '?' : '&';
        $url .= $param;
    }
    go($url);
}
Ejemplo n.º 20
0
function processString($c)
{
    $tokens = array();
    $start = microtime(true);
    $c = str_replace("\r", "", $c);
    foreach (token_get_all($c) as $i) {
        if (is_string($i)) {
            $name = $i;
            $chars = $i;
        } else {
            if (is_int($i[0])) {
                $name = token_name($i[0]);
                $chars = $i[1];
            } else {
                $name = $i[0];
                $chars = $i[1];
            }
        }
        if (!$name) {
            $name = $i[1];
        }
        $tokens[] = str_replace(array("\r", "\n"), array('\\r', '\\n'), $chars) . ' ' . $name;
    }
    $phpTime = microtime(true) - $start;
    var_dump($tokens);
    $out = array();
    $start = microtime(true);
    exec("php-parser --print-tokens --code " . escapeshellarg($c), $out, $ret);
    $parserTime = microtime(true) - $start;
    if ($ret != 0) {
        echo "php-parser failed\n";
        exit(255);
    }
    unset($out[0]);
    //remove "Parsing file ..."
    array_pop($out);
    //remove "successfully parsed"
    array_pop($out);
    //remove "end of file"
    $diff = array_diff($tokens, $out);
    if (!$diff || count($tokens) != count($out)) {
        echo "code correctly tokenized ({$parserTime} / {$phpTime})...\n";
    } else {
        echo "******* parser output:\n";
        out($out);
        echo "******* expected:\n";
        out($tokens);
        echo "******* differences in code:\n";
        out($diff);
        exit(255);
    }
}
Ejemplo n.º 21
0
 public function install()
 {
     $status = $this->validVersion();
     if ($status !== true) {
         out($status);
         throw new \Exception($status);
     }
     $sql = "CREATE TABLE IF NOT EXISTS `webrtc_clients` (\n\t\t\t\t\t\t`user` VARCHAR( 255 ) NOT NULL UNIQUE,\n\t\t\t\t\t\t`device` VARCHAR( 255 ) NOT NULL UNIQUE ,\n\t\t\t\t\t\t`realm` varchar(80) NOT NULL,\n\t\t\t\t\t\t`username` varchar(80) NOT NULL,\n\t\t\t\t\t\t`sipuri` varchar(80) NOT NULL,\n\t\t\t\t\t\t`password` varchar(80) NOT NULL,\n\t\t\t\t\t\t`websocket` varchar(80) NOT NULL,\n\t\t\t\t\t\t`breaker` varchar(80) NOT NULL,\n\t\t\t\t\t\t`cid` varchar(80) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t\t\t`certid` int(11) NULL\n\t\t\t\t\t)";
     $sth = $this->db->prepare($sql);
     $sth->execute();
     //Remove Old Link if need be
     if (file_exists($this->freepbx->Config->get('ASTETCDIR') . '/http.conf') && is_link($this->freepbx->Config->get('ASTETCDIR') . '/http.conf') && readlink($this->freepbx->Config->get('ASTETCDIR') . '/http.conf') == dirname(__FILE__) . '/etc/httpd.conf') {
         unlink($this->freepbx->Config->get('ASTETCDIR') . '/http.conf');
     }
     if (!$this->db->sql('SHOW COLUMNS FROM webrtc_clients WHERE FIELD = "certid"', 'getAll')) {
         $this->db->query("ALTER TABLE `webrtc_clients` ADD COLUMN `certid` int(11) NULL");
     }
     if ($this->freepbx->Config->conf_setting_exists('HTTPENABLED')) {
         $this->freepbx->Config->set_conf_values(array('HTTPENABLED' => true), true);
     }
     try {
         $sql = "SELECT * FROM webrtc_settings";
         $sth = $this->db->prepare($sql);
         $sth->execute();
         $settings = $sth->fetchAll(\PDO::FETCH_ASSOC);
         if (!empty($settings)) {
             foreach ($settings as $setting) {
                 $this->setConfig($setting['key'], $setting['value']);
             }
         }
         $sql = "DROP TABLE IF EXISTS `webrtc_settings`";
         $sth = $this->db->prepare($sql);
         $sth->execute();
     } catch (\Exception $e) {
     }
     $prefix = $this->getConfig('prefix');
     if (empty($prefix)) {
         $this->setConfig('prefix', '99');
     }
     /*
     try {
     	$stunaddr = $this->freepbx->Sipsettings->getConfig("stunaddr");
     } catch(\Exception $e) {
     	$stunaddr = "";
     }
     if(empty($stunaddr)) {
     	out("<strong style='color:red'>"._("The STUN Server address is blank. In many cases this can cause issues. Please define a valid server in the Asterisk SIP Settings module")."</strong>");
     }
     */
     return true;
 }
Ejemplo n.º 22
0
function test($a)
{
    $a ? out('?a') : out(':a');
    $a ? out('+a') : 0;
    $a ? 0 : out('-a');
    $a && out('&&a');
    $a || out('||a');
    $a and out('and a');
    $a or out('or a');
    $b = $c = 0;
    $a || ($b = 5) + ($c = 6);
    out($b);
    out($c);
}
Ejemplo n.º 23
0
function handleException($e)
{
    $msg = $e->getMessage();
    if (preg_match('/table(.+)not found/i', $msg)) {
        out(0, 'Your database does not appear to be properly configured. ' . 'Please see Extensible > examples > server > README.md. Details: ' . $msg);
    } else {
        if (preg_match('/can\'t connect/i', $msg)) {
            out(0, 'Cannot connect to the database. Please ensure that the database is started ' . 'and configured per Extensible > examples > server > README.md. Details: ' . $msg);
        } else {
            out(0, $msg);
        }
    }
    die;
}
Ejemplo n.º 24
0
function click_to_call($caller, $called, $site, $callthrough_time)
{
    $command = "click_to_call {$caller} {$called} {$site} {$callthrough_time}";
    $socket = new SocketConn();
    if ($socket->error == "") {
        $obj = array("success" => true);
        $socket->command($command);
        $sql = "insert into actionlogs (date,performer,log,ip) values (" . time() . ",\"{$_SESSION['extension']}\",\"{$command}\", \"{$_SERVER['REMOTE_ADDR']}\")";
        query($sql);
    } else {
        $obj = array("success" => false);
        $obj['message'] = "Can't make call. Please contact your system administrator.";
        echo out($obj);
    }
}
Ejemplo n.º 25
0
/**
 * Reassign edits from one user to another
 *
 * @param $from User to take edits from
 * @param $to User to assign edits to
 * @param $rc Update the recent changes table
 * @param $report Don't change things; just echo numbers
 * @return integer Number of entries changed, or that would be changed
 */
function reassignEdits(&$from, &$to, $rc = false, $report = false)
{
    $dbw = wfGetDB(DB_MASTER);
    $dbw->immediateBegin();
    $fname = 'reassignEdits';
    # Count things
    out("Checking current edits...");
    $res = $dbw->select('revision', 'COUNT(*) AS count', userConditions($from, 'rev_user', 'rev_user_text'), $fname);
    $row = $dbw->fetchObject($res);
    $cur = $row->count;
    out("found {$cur}.\n");
    out("Checking deleted edits...");
    $res = $dbw->select('archive', 'COUNT(*) AS count', userConditions($from, 'ar_user', 'ar_user_text'), $fname);
    $row = $dbw->fetchObject($res);
    $del = $row->count;
    out("found {$del}.\n");
    # Don't count recent changes if we're not supposed to
    if ($rc) {
        out("Checking recent changes...");
        $res = $dbw->select('recentchanges', 'COUNT(*) AS count', userConditions($from, 'rc_user', 'rc_user_text'), $fname);
        $row = $dbw->fetchObject($res);
        $rec = $row->count;
        out("found {$rec}.\n");
    } else {
        $rec = 0;
    }
    $total = $cur + $del + $rec;
    out("\nTotal entries to change: {$total}\n");
    if (!$report) {
        if ($total) {
            # Reassign edits
            out("\nReassigning current edits...");
            $res = $dbw->update('revision', userSpecification($to, 'rev_user', 'rev_user_text'), userConditions($from, 'rev_user', 'rev_user_text'), $fname);
            out("done.\nReassigning deleted edits...");
            $res = $dbw->update('archive', userSpecification($to, 'ar_user', 'ar_user_text'), userConditions($from, 'ar_user', 'ar_user_text'), $fname);
            out("done.\n");
            # Update recent changes if required
            if ($rc) {
                out("Updating recent changes...");
                $res = $dbw->update('recentchanges', userSpecification($to, 'rc_user', 'rc_user_text'), userConditions($from, 'rc_user', 'rc_user_text'), $fname);
                out("done.\n");
            }
        }
    }
    $dbw->immediateCommit();
    return (int) $total;
}
Ejemplo n.º 26
0
function close_country($servers)
{
    global $fallback;
    if (count($servers) == 0) {
        out('\'' . $fallback . "',\n");
    } else {
        if (count($servers) == 1) {
            out('\'' . $servers[0] . "',\n");
        } else {
            out("array(\n");
            foreach ($servers as $server) {
                out('		\'' . $server . "',\n");
            }
            out("\t),\n");
        }
    }
}
Ejemplo n.º 27
0
function render_current_enemies($enemy_list)
{
    $enemy_section = '';
    if (!is_array($enemy_list)) {
        return $enemy_section;
    }
    $enemy_list = array_map('expand_enemy_info', $enemy_list);
    // Turn id into enemy info.
    uasort($enemy_list, 'compare_enemy_order');
    // Resort by health, level.
    foreach ($enemy_list as $loop_enemy_id => $loop_enemy) {
        $action = $loop_enemy['health'] > 0 ? 'Attack' : 'View';
        $status_class = $loop_enemy['health'] > 0 ? '' : 'enemy-dead';
        $enemy_section .= "<li class='{$status_class}'>\n            <a href='enemies.php?remove_enemy={$loop_enemy_id}'><img src='" . IMAGE_ROOT . "icons/delete.png' alt='remove'></a>\n             {$action} <a href='player.php?player_id={$loop_enemy_id}'>" . out($loop_enemy['uname']) . "</a>\n              ({$loop_enemy['health']} health)</li>";
        // TODO: Turn this into a template render.
    }
    return $enemy_section;
}
Ejemplo n.º 28
0
function dumpNode(\SamIT\ExpressionManager\Nodes\Node $n, $indent = 0)
{
    switch (get_class($n)) {
        case \SamIT\ExpressionManager\Nodes\FunctionNode::class:
            out($n->getName() . "\n", $indent);
            dumpNode($n->getOperand(), $indent + 4);
            break;
        case \SamIT\ExpressionManager\Nodes\ListNode::class:
            out("List: [\n", $indent);
            for ($i = 0; $i < $n->length(); $i++) {
                dumpNode($n->item($i), $indent + 4);
            }
            out("]\n", $indent);
            break;
        case \SamIT\ExpressionManager\Nodes\BinaryNode::class:
            out($n->getOperator() . "\n", $indent);
            out("Left:\n", $indent);
            dumpNode($n->getOperand1(), $indent + 4);
            out("Right:\n", $indent);
            dumpNode($n->getOperand2(), $indent + 4);
            break;
        case \SamIT\ExpressionManager\Nodes\UnaryNode::class:
            out($n->getOperator() . "\n", $indent);
            out("Operand:\n", $indent);
            break;
        case \SamIT\ExpressionManager\Nodes\VariableNode::class:
            out("Variable `{$n->getName()}`\n", $indent);
            break;
        case \SamIT\ExpressionManager\Nodes\ValueNode::class:
            if (is_int($n->getValue())) {
                out("(int) {$n->getValue()}\n", $indent);
            } elseif (is_float($n->getValue())) {
                out("(float) {$n->getValue()}\n", $indent);
            } elseif (is_string($n->getValue())) {
                out("(string) {$n->getValue()}\n", $indent);
            }
            break;
        case \SamIT\ExpressionManager\Nodes\Token::class:
            out($n . "\n", $indent);
            break;
        default:
            var_dump($n);
    }
}
Ejemplo n.º 29
0
 public function install()
 {
     $dbh = $this->db;
     $sql = "CREATE TABLE IF NOT EXISTS manager (\n\t\t\t`manager_id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,\n\t\t\t`name` VARCHAR( 15 ) NOT NULL ,\n\t\t\t`secret` VARCHAR( 50 ) ,\n\t\t\t`deny` VARCHAR( 255 ) ,\n\t\t\t`permit` VARCHAR( 255 ) ,\n\t\t\t`read` VARCHAR( 255 ) ,\n\t\t\t`write` VARCHAR( 255 )\n\t\t)";
     $stmt = $dbh->prepare($sql);
     $stmt->execute();
     \outn(_("Increasing read field size if needed.."));
     $sql = "ALTER TABLE `manager` CHANGE `read` `read` VARCHAR( 255 )";
     $stmt = $dbh->prepare($sql);
     try {
         $stmt->execute();
         \out(_("ok"));
     } catch (\PDOException $e) {
         \out(_("error encountered, not altered"));
     }
     outn(_("Increasing write field size if needed.."));
     $sql = "ALTER TABLE `manager` CHANGE `write` `write` VARCHAR( 255 )";
     $stmt = $dbh->prepare($sql);
     try {
         $stmt->execute();
         \out(_("ok"));
     } catch (\PDOException $e) {
         \out(_("error encountered, not altered"));
     }
     outn(_("Adding write timeout.."));
     $sql = "ALTER TABLE manager ADD writetimeout INT";
     $stmt = $dbh->prepare($sql);
     try {
         $stmt->execute();
         \out(_("ok"));
     } catch (\PDOException $e) {
         //We are ok with 42S21 because we are trying to add a column and it says that column is present.
         if ($e->getCode() == '42S21') {
             \out(_("Column present"));
         } else {
             //All other exceptions are bad mmmk
             \out($e->getMessage());
             throw $e;
         }
     }
 }
Ejemplo n.º 30
0
function encrypt_passwords()
{
    global $db;
    out("Updating passwords..");
    $sql = "SELECT * FROM ampusers";
    $users = $db->getAll($sql, NULL, DB_FETCHMODE_ASSOC);
    if (DB::IsError($users)) {
        // Error while getting the users list to update... bad
        die($users->getMessage());
    } else {
        outn("(" . count($users) . " accounts) ");
        foreach ($users as $index => $ufields) {
            $sql = "UPDATE ampusers SET password_sha1='" . sha1($ufields['password']) . "' WHERE username='******'username'] . "'";
            $result = $db->query($sql);
            if (DB::IsError($result)) {
                outn("Error while updating account: " . $ufields['username'] . " (" . $result->getMessage . ")");
            }
        }
    }
    out("Done.");
}