Beispiel #1
0
function addOpenID()
{
    global $openid_list;
    $context = Model_Context::getInstance();
    if (empty($_GET['openid_identifier']) || strstr($_GET['openid_identifier'], ".") === false) {
        exitWithError(_t('오픈아이디를 입력하지 않았거나, 도메인 없는 오픈아이디를 입력하였습니다.'));
    }
    $currentOpenID = Acl::getIdentity('openid_temp');
    $fc = new OpenIDConsumer();
    $claimedOpenID = $fc->fetch($_GET['openid_identifier']);
    if (in_array($claimedOpenID, $openid_list)) {
        exitWithError(_t('이미 연결된 오픈아이디 입니다') . " : " . $claimedOpenID);
    }
    if ($_GET['authenticated'] === "0") {
        header("Location: " . $context->getProperty('uri.blog') . "/owner/setting/account");
        exit(0);
    }
    if (empty($currentOpenID) || $claimedOpenID != $currentOpenID) {
        loginOpenIDforAdding($claimedOpenID);
        return;
    }
    if (!in_array($currentOpenID, $openid_list)) {
        for ($i = 0; $i < OPENID_REGISTERS; $i++) {
            $openid = Setting::getUserSetting("openid." . $i, null, true);
            if (empty($openid)) {
                Setting::setUserSetting("openid." . $i, $currentOpenID, true);
                break;
            }
        }
    }
    echo "<html><head><script type=\"text/javascript\">//<![CDATA[" . CRLF . "alert('" . _t('연결하였습니다.') . " : " . $currentOpenID . "'); document.location.href='" . $context->getProperty('uri.blog') . "/owner/setting/account'; //]]></script></head></html>";
}
Beispiel #2
0
function loginCheck($f_bAct = false)
{
    global $db;
    // session
    if (empty($_SESSION[SESSION_NAME])) {
        return exitWithError($f_bAct, "Invalid session!");
    }
    $arrSession = $_SESSION[SESSION_NAME];
    // variables
    if (!is_array($arrSession) || !isset($arrSession['uid'], $arrSession['ip'], $arrSession['hash'])) {
        return exitWithError($f_bAct, "Invalid session!");
    }
    // ip check
    if (empty($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] !== $arrSession['ip']) {
        return exitWithError($f_bAct, "Invalid session!");
    }
    // user check in db
    $arrUser = db_select(TABLE_PLAYERS, "id = '" . $arrSession['uid'] . "' AND hash = '" . $arrSession['hash'] . "'");
    if (1 != count($arrUser)) {
        return exitWithError($f_bAct, "Invalid session!");
    }
    // update online time
    db_update(TABLE_PLAYERS, array('last_online' => time()), 'id = ' . (int) $arrSession['uid']);
    if (!defined('USER_ID')) {
        define('USER_ID', (int) $arrSession['uid']);
    }
    return true;
}
     }
     break;
 case "get":
     if (!isset($_POST["id"])) {
         exitWithError("ID not set.");
     }
     if (!is_numeric($_POST["id"])) {
         exitWithError("ID not an integer.");
     }
     $recordId = $_POST["id"];
     $stmt = $mysqli->prepare("SELECT `data`, `fileName` FROM `schematics_tempholder` WHERE id=?");
     $stmt->bind_param('i', $recordId);
     $stmt->execute();
     $stmt->bind_result($fileContents, $fileName);
     if (!$stmt->fetch()) {
         exitWithError("No record found with ID {$recordId}.");
     }
     $stmt->close();
     $fileSize = strlen($fileContents);
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=' . $fileName . '.schematic');
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-Length: ' . $fileSize);
     echo $fileContents;
     //Delete the record:
     $stmt = $mysqli->prepare("DELETE FROM `schematics_tempholder` WHERE id=?");
     $stmt->bind_param('i', $recordId);
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $proc = proc_open($cmd, $descriptorspec, $pipes);
    fwrite($pipes[0], $data);
    fclose($pipes[0]);
    $stdout = stream_get_contents($pipes[1]);
    $stderr = stream_get_contents($pipes[2]);
    fclose($pipes[1]);
    $return = proc_close($proc);
    if ($return == 1) {
        exitWithError("FAILED: cmd: {$cmd}, return code: {$return}, stdout: {$stdout}, stderr: {$stderr}");
    } elseif ($return == 2 || $return == 0) {
        $regex = '/info from server: "processed: (\\d+); failed: (\\d+); total: (\\d+); seconds spent: (\\d+\\.\\d+)"/';
        $processed = 0;
        $failed = 0;
        $total = 0;
        $secondsSpent = 0.0;
        foreach (explode("\n", $stdout) as $line) {
            if (preg_match($regex, $line, $matches)) {
                $processed += (int) $matches[1];
                $total += (int) $matches[3];
                $secondsSpent += (double) $matches[4];
            }
        }
        echo "OK [{$processed}/{$total} processed in {$secondsSpent}]\n";
        /*echo $cmd . "\n";
        		echo "stdout: {$stdout}, stderr: {$stderr}\n";
        		echo "data: " . print_r($data, true);*/
    } else {
        exitWithError("Unknown return code {$return}");
    }
}
/**
 * Validate a course's existence (and proper integer) based on its courseId value.
 * Optionally, validate that the current user has proper access for this given course
 * (the given course must be within the nodes subtree that the current user belongs to).
 *
 * @param int     $courseId - The course's id
 * @param boolean $checkOwn - Optional validation (if true) of current user's node access
 */
function validateCourseNodes($courseId, $checkOwn)
{
    global $tool_content, $head_content, $tree, $course, $user, $uid, $langBack, $langNotAllowed;
    $notallowed = "<div class='alert alert-danger'>{$langNotAllowed}</div><p class='pull-right'><a href='{$_SERVER['PHP_SELF']}'>" . $langBack . "</a></p>";
    if ($courseId <= 0) {
        exitWithError($notallowed);
    }
    $deps = $course->getDepartmentIds(intval($courseId));
    if (empty($deps)) {
        exitWithError($notallowed);
    }
    if ($checkOwn) {
        $atleastone = false;
        $subtrees = $tree->buildSubtrees($user->getDepartmentIds($uid));
        foreach ($deps as $depId) {
            if (in_array($depId, $subtrees)) {
                $atleastone = true;
            }
        }
        if (!$atleastone) {
            exitWithError($notallowed);
        }
    }
}
Beispiel #6
0
        if (false === $fh) {
            exitWithError("Failed to open the hosts file.");
        }
        fwrite($fh, $startToken . PHP_EOL);
        foreach ($siteList as $site) {
            fwrite($fh, "127.0.0.1\t{$site}" . PHP_EOL);
            fwrite($fh, "127.0.0.1\twww.{$site}" . PHP_EOL);
        }
        fwrite($fh, $endToken . PHP_EOL);
        fclose($fh);
        shell_exec($restartNetworkingCommand);
        break;
    case 'play':
        $hostContents = file($hostsFile);
        if (false === $hostContents) {
            exitWithError("Failed to open the hosts file.");
        }
        $startIndex = -1;
        for ($i = 0; $i < count($hostContents); $i++) {
            if (trim($hostContents[$i]) == $startToken) {
                $startIndex = $i;
            }
        }
        if ($startIndex > -1) {
            $hostContents = array_slice($hostContents, 0, $startIndex);
            file_put_contents($hostsFile, $hostContents);
            shell_exec($restartNetworkingCommand);
        }
        break;
}
function exitWithError($error)
Beispiel #7
0
$strSchemaFile = $objDOM->getElementsByTagName('pages')->item(0)->getAttribute('xsi:noNamespaceSchemaLocation');
if (true === empty($strSchemaFile)) {
    exitWithError('config-file has no schema associated; do not worry, you probably only need to upgrade its ' . 'structure. This can be done automatically. ' . '<a href="../upgrade/index.php?config=' . $strConfigSuffix . '">Click here to upgrade</a>');
}
$intConfigurationVersion = $objDOM->getElementsByTagName('pages')->item(0)->getAttribute('lib_version');
if ($intConfigurationVersion < LIBRARY_VERSION) {
    exitWithError('Your configuration is not suited for the current version of the library/editor; ' . ' do not worry, you only need to upgrade its structure. This can be done automatically. ' . '<a href="../upgrade/index.php?config=' . $strConfigSuffix . '">Click here to upgrade</a>');
}
$strSchemaFilename = sprintf(SCHEMA_FILENAME, $strSchemaFile);
if ('.xsd' !== substr($strSchemaFilename, -4)) {
    exitWithError('schema-filename of config-file is not compliant \'' . $strSchemaFilename . '\'.');
}
// .. as a fully qualified filename
$strSchemaFQFilename = realpath(simplifyPath($strConfigPath . ($isDemo ? 'demo/' : '') . $strSchemaFilename));
if (false === is_readable($strSchemaFQFilename)) {
    exitWithError('schema-file of config-file does not exist \'' . $strSchemaFQFilename . '\' (\'' . $strSchemaFilename . '\').');
}
// disable output of validator
ob_start();
// validate the configuration
$boolValid = $objDOM->schemaValidate($strSchemaFQFilename);
// and flush the validators output
ob_end_clean();
if (true === $boolValid) {
    // everything is good
    header('Location: editor.html?config=' . $strConfigSuffix . ($isDemo ? '&demo=true' : ''));
    exit;
} else {
    // not everything is good, have check_config look at it.
    header('Location: ../check_config.php?config=' . $strConfigSuffix);
    exit;
        break;
    case 'play':
        $hostContents = file($hostsFile);
        if (false === $hostContents) {
            exitWithError("Failed to open the hosts file.");
        }
        $startIndex = -1;
        for ($i = 0; $i < count($hostContents); $i++) {
            if (trim($hostContents[$i]) == $startToken) {
                $startIndex = $i;
            }
        }
        if ($startIndex > -1) {
            $hostContents = array_slice($hostContents, 0, $startIndex);
            file_put_contents($hostsFile, $hostContents);
            shell_exec($restartNetworkingCommand);
        }
        break;
    default:
        exitWithError("usage: " . $argv[0] . " [work | play]");
}
function exitWithError($error)
{
    fwrite(STDERR, $error . PHP_EOL);
    exit(1);
}
function iniToArray($iniFile)
{
    $iniContents = parse_ini_file($iniFile);
    return array_map('trim', explode(',', $iniContents["sites"]));
}
Beispiel #9
0
    $streamJson = json_decode($matches[1]);
    if (!$streamJson) {
        exitWithError("No proper json received");
    }
    if ($streamJson->success) {
        $streamUrlWithHash = $streamJson->stream;
        if (DEBUG) {
            echo "Stream URL received: " . $streamUrlWithHash . "\n";
        }
    }
    // Increase iteration number
    $i++;
}
if (!$streamUrlWithHash) {
    exitWithError("No URL could be retrieved in " . MAX_TRIES . " tries");
}
// Now retrieve the actual URL
$url = $streamUrlWithHash . "&callback=finalMethod&_=" . mktime() * 1000;
$finalJs = file_get_contents($url);
if (!preg_match("/\"(.+)\"/", $finalJs, $matches)) {
    exitWithError("No proper response from stream URL with hash");
}
$finalUrl = json_decode($matches[0]);
if (DEBUG) {
    echo "Final URL: ";
}
// Store final URL
$channelData["stream"] = $finalUrl;
$channelData["success"] = true;
echo json_encode($channelData);
echo "\n";