Example #1
0
File: api.php Project: xtha/salt
     }
     usePreparedInsertBlade('Dictionary', array('chapter_id' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value']));
     sendAPIResponse(array(), array('message' => 'dictionary entry added successfully', 'chapter_no' => $_REQUEST['chapter_no']));
     break;
     // delete an entry from a chapter
     //    UI equivalent: /index.php?page=chapter&module=redirect&op=del&dict_key=50228&tab=edit&chapter_no=10007
     //    UI handler: tableHandler()
 // delete an entry from a chapter
 //    UI equivalent: /index.php?page=chapter&module=redirect&op=del&dict_key=50228&tab=edit&chapter_no=10007
 //    UI handler: tableHandler()
 case 'delete_chapter_entry':
     require_once 'inc/init.php';
     assertUIntArg('chapter_no', TRUE);
     assertStringArg('dict_value', TRUE);
     // make sure the chapter exists
     $chapters = getChapterList();
     if (!isset($chapters[$_REQUEST['chapter_no']])) {
         throw new InvalidArgException('chapter_no', $_REQUEST['chapter_no'], "invalid argument: no such chapter");
     }
     // make sure the entry exists in this chapter
     $words = readChapter($_REQUEST['chapter_no'], 'o');
     if (!in_array($_REQUEST['dict_value'], $words)) {
         throw new InvalidArgException('dict_value', $_REQUEST['dict_value'], "invalid argument: no such value in chapter ID " . $_REQUEST['chapter_no']);
     }
     usePreparedDeleteBlade('Dictionary', array('chapter_id' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value']));
     sendAPIResponse(array(), array('message' => 'dictionary entry deleted successfully', 'chapter_no' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value']));
     break;
     // perform a generic search
     //    UI equivalent: /index.php?page=search
     //    UI handler: searchEntitiesByText()
 // perform a generic search
Example #2
0
function dynamic_title_decoder($path_position)
{
    global $sic, $page_by_realm;
    static $net_id;
    try {
        switch ($path_position) {
            case 'index':
                return array('name' => '/' . getConfigVar('enterprise'), 'params' => array());
            case 'chapter':
                $chapter_no = assertUIntArg('chapter_no');
                $chapters = getChapterList();
                $chapter_name = isset($chapters[$chapter_no]) ? $chapters[$chapter_no]['name'] : 'N/A';
                return array('name' => "Chapter '{$chapter_name}'", 'params' => array('chapter_no' => $chapter_no));
            case 'user':
                $userinfo = spotEntity('user', assertUIntArg('user_id'));
                return array('name' => "Local user '" . $userinfo['user_name'] . "'", 'params' => array('user_id' => $userinfo['user_id']));
            case 'ipv4rspool':
                $pool_info = spotEntity('ipv4rspool', assertUIntArg('pool_id'));
                return array('name' => !strlen($pool_info['name']) ? 'ANONYMOUS' : $pool_info['name'], 'params' => array('pool_id' => $pool_info['id']));
            case 'ipv4vs':
                $vs_info = spotEntity('ipv4vs', assertUIntArg('vs_id'));
                return array('name' => $vs_info['dname'], 'params' => array('vs_id' => $vs_info['id']));
            case 'ipvs':
                $vs_info = spotEntity('ipvs', assertUIntArg('vs_id'));
                return array('name' => $vs_info['name'], 'params' => array('vs_id' => $vs_info['id']));
            case 'object':
                $object = spotEntity('object', assertUIntArg('object_id'));
                return array('name' => $object['dname'], 'params' => array('object_id' => $object['id']));
            case 'location':
                $location = spotEntity('location', assertUIntArg('location_id'));
                return array('name' => $location['name'], 'params' => array('location_id' => $location['id']));
            case 'row':
                global $pageno;
                switch ($pageno) {
                    case 'rack':
                        $rack = spotEntity('rack', assertUIntArg('rack_id'));
                        return array('name' => $rack['row_name'], 'params' => array('row_id' => $rack['row_id'], 'location_id' => $rack['location_id']));
                    case 'row':
                        $row_info = getRowInfo(assertUIntArg('row_id'));
                        return array('name' => $row_info['name'], 'params' => array('row_id' => $row_info['id'], 'location_id' => $row_info['location_id']));
                    default:
                        break;
                }
            case 'rack':
                $rack_info = spotEntity('rack', assertUIntArg('rack_id'));
                return array('name' => $rack_info['name'], 'params' => array('rack_id' => $rack_info['id']));
            case 'search':
                if (isset($_REQUEST['q'])) {
                    return array('name' => "search results for '{$_REQUEST['q']}'", 'params' => array('q' => $_REQUEST['q']));
                } else {
                    return array('name' => 'search results', 'params' => array());
                }
            case 'file':
                $file = spotEntity('file', assertUIntArg('file_id'));
                return array('name' => niftyString($file['name'], 30, FALSE), 'params' => array('file_id' => $_REQUEST['file_id']));
            case 'ipaddress':
                $address = getIPAddress(ip_parse($_REQUEST['ip']));
                return array('name' => niftyString($address['ip'] . ($address['name'] != '' ? ' (' . $address['name'] . ')' : ''), 50, FALSE), 'params' => array('ip' => $address['ip']));
            case 'ipv4net':
            case 'ipv6net':
                global $pageno;
                switch ($pageno) {
                    case 'ipaddress':
                        $net = spotNetworkByIP(ip_parse($_REQUEST['ip']));
                        $ret = array('name' => $net['ip'] . '/' . $net['mask'], 'params' => array('id' => $net['id'], 'page' => $net['realm'], 'hl_ip' => $_REQUEST['ip']));
                        return $ret;
                    default:
                        $net = spotEntity($path_position, assertUIntArg('id'));
                        return array('name' => $net['ip'] . '/' . $net['mask'], 'params' => array('id' => $net['id']));
                }
                break;
            case 'ipv4space':
            case 'ipv6space':
                global $pageno;
                switch ($pageno) {
                    case 'ipaddress':
                        $net_id = getIPAddressNetworkId(ip_parse($_REQUEST['ip']));
                        break;
                    case 'ipv4net':
                    case 'ipv6net':
                        $net_id = $_REQUEST['id'];
                        break;
                    default:
                        $net_id = NULL;
                }
                $params = array();
                if (isset($net_id)) {
                    $params = array('eid' => $net_id, 'hl_net' => 1, 'clear-cf' => '');
                }
                unset($net_id);
                $ip_ver = preg_replace('/[^\\d]*/', '', $path_position);
                return array('name' => "IPv{$ip_ver} space", 'params' => $params);
            case 'vlandomain':
                global $pageno;
                switch ($pageno) {
                    case 'vlandomain':
                        $vdom_id = $_REQUEST['vdom_id'];
                        break;
                    case 'vlan':
                        list($vdom_id, $dummy) = decodeVLANCK($_REQUEST['vlan_ck']);
                        break;
                    default:
                        break;
                }
                $vdlist = getVLANDomainOptions();
                if (!array_key_exists($vdom_id, $vdlist)) {
                    throw new EntityNotFoundException('VLAN domain', $vdom_id);
                }
                return array('name' => niftyString("domain '" . $vdlist[$vdom_id] . "'", 20, FALSE), 'params' => array('vdom_id' => $vdom_id));
            case 'vlan':
                return array('name' => formatVLANAsPlainText(getVLANInfo($sic['vlan_ck'])), 'params' => array('vlan_ck' => $sic['vlan_ck']));
            case 'vst':
                $vst = spotEntity('vst', $sic['vst_id']);
                return array('name' => niftyString("template '" . $vst['description'] . "'", 50, FALSE), 'params' => array('vst_id' => $sic['vst_id']));
            case 'dqueue':
                global $dqtitle;
                return array('name' => 'queue "' . $dqtitle[$sic['dqcode']] . '"', 'params' => array('qcode' => $sic['dqcode']));
            default:
                break;
        }
        // default behaviour is throwing an exception
        throw new RackTablesError('dynamic_title decoding error', RackTablesError::INTERNAL);
    } catch (RackTablesError $e) {
        return array('name' => __FUNCTION__ . '() failure', 'params' => array());
    }
}
function renderChaptersEditor()
{
    function printNewItemTR()
    {
        printOpFormIntro('add');
        echo '<tr><td>';
        printImageHREF('create', 'Add new', TRUE);
        echo "</td><td><input type=text name=chapter_name></td><td>&nbsp;</td><td>";
        printImageHREF('create', 'Add new', TRUE);
        echo '</td></tr></form>';
    }
    $dict = getChapterList();
    foreach (array_keys($dict) as $chapter_no) {
        $dict[$chapter_no]['mapped'] = FALSE;
    }
    foreach (getAttrMap() as $attrinfo) {
        if ($attrinfo['type'] == 'dict') {
            foreach ($attrinfo['application'] as $app) {
                $dict[$app['chapter_no']]['mapped'] = TRUE;
            }
        }
    }
    echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
    echo '<tr><th>&nbsp;</th><th>Chapter name</th><th>Words</th><th>&nbsp;</th></tr>';
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItemTR();
    }
    foreach ($dict as $chapter_id => $chapter) {
        $wordcount = $chapter['wordc'];
        $sticky = $chapter['sticky'] == 'yes';
        printOpFormIntro('upd', array('chapter_no' => $chapter_id));
        echo '<tr>';
        echo '<td>';
        if ($sticky) {
            printImageHREF('nodestroy', 'system chapter');
        } elseif ($wordcount > 0) {
            printImageHREF('nodestroy', 'contains ' . $wordcount . ' word(s)');
        } elseif ($chapter['mapped']) {
            printImageHREF('nodestroy', 'used in attribute map');
        } else {
            echo getOpLink(array('op' => 'del', 'chapter_no' => $chapter_id), '', 'destroy', 'Remove chapter');
        }
        echo '</td>';
        echo "<td><input type=text name=chapter_name value='{$chapter['name']}'" . ($sticky ? ' disabled' : '') . "></td>";
        echo "<td class=tdleft>{$wordcount}</td><td>";
        if ($sticky) {
            echo '&nbsp;';
        } else {
            printImageHREF('save', 'Save changes', TRUE);
        }
        echo '</td></tr>';
        echo '</form>';
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR();
    }
    echo "</table>\n";
}