コード例 #1
0
 function __construct()
 {
     $dbName = isInPath("_test") || isset($_REQUEST["test"]) ? "accounts_test" : "accounts";
     if (isset($GLOBALS["DBS"][$dbName])) {
         parent::__construct($GLOBALS["DBS"][$dbName]["name"], $GLOBALS["DBS"][$dbName]["host"], $GLOBALS["DBS"][$dbName]["user"], $GLOBALS["DBS"][$dbName]["pass"], FALSE);
     }
     $this->dbprefix = isset($GLOBALS["DBS"][$dbName]["dbprefix"]) ? $GLOBALS["DBS"][$dbName]["dbprefix"] : "";
 }
コード例 #2
0
 function __construct()
 {
     $dbName = isInPath("/" . PATH_NEWSTEST . "/") || isInPath("/" . PATH_NEWSEDITTEST . "/") || isset($_REQUEST["test"]) ? "newstest" : "news";
     //TODO:
     if (isset($GLOBALS["DBS"][$dbName])) {
         parent::__construct($GLOBALS["DBS"][$dbName]["name"], $GLOBALS["DBS"][$dbName]["host"], $GLOBALS["DBS"][$dbName]["user"], $GLOBALS["DBS"][$dbName]["pass"], FALSE);
     }
     $this->dbprefix = isset($GLOBALS["DBS"][$dbName]["dbprefix"]) ? $GLOBALS["DBS"][$dbName]["dbprefix"] : "";
     // cf. NEWS_DB_PREFIX
 }
コード例 #3
0
 private static function getAgendaRawData($args)
 {
     if (!functions::testTcpConnection(str_replace("http://", "", AGENDA_URI), 80)) {
         return "";
     }
     sleep(5);
     // to avoid DoS
     if (IS_TESTSERVER || isInPath("_admin")) {
         echo "<br>fromdb_agenda-&gt;getAgendaRawData(): ";
         var_dump(AGENDA_TOOLS_URI . "?" . $args);
     }
     $data = functions::acurl(AGENDA_TOOLS_URI . "?" . $args);
     // assign to variable before returning
     return $data;
 }
コード例 #4
0
 public function buildSubsiteConstants()
 {
     if (!defined("SUBSITE")) {
         if (RELPATHTOROOT == "./") {
             define("SUBSITE", "main");
         } elseif (file_exists(INCLEVEL . PATH_SITES . "/" . $this->getPageBranch())) {
             //TODO perhaps read $this->allSitesArray[] instead
             define("SUBSITE", $this->getPageBranch());
         } elseif (file_exists(INCLEVEL . PATH_SITES . "/" . DEFAULT_SITE)) {
             define("SUBSITE", DEFAULT_SITE);
         } else {
             die(BLURB_SORRY_SITE_CONNECT);
         }
     }
     // ------------------------------
     if (!defined("IS_SUB")) {
         define("IS_SUB", isInPath("/" . SUBSITE . "/") ? 1 : 0);
     }
     if (!defined("IS_SUBINDEX")) {
         define("IS_SUBINDEX", isInPath("/" . SUBSITE . "/index.php") ? 1 : 0);
     }
 }
コード例 #5
0
 static function getAllPlaylistsData()
 {
     $playlistData = array();
     $url = self::$base . "playlists?" . "part=snippet,status&" . "fields=pageInfo(totalResults),items(id,snippet(title,description,thumbnails(default)),status(privacyStatus))&" . "channelId=" . YOUTUBE_CHANNELID_NORDITASTOCKHOLM . "&" . "maxResults=50&" . "key=" . GOOGLE_API_SERVER_KEY;
     $jsonData = self::getYoutubeApiResponse($url);
     if (!isset($jsonData->items)) {
         if (isset($jsonData->error->message) && isInPath("_admin")) {
             print "<div class='box error background padding'><strong>ERROR</strong>:<br>" . $jsonData->error->message . "</div>\r\n";
         }
         return NULL;
     }
     foreach ($jsonData->items as $data) {
         $id = $data->id;
         $item["remote"]["playlist_id"] = $data->id;
         $item["remote"]["playlist_url"] = "http://www.youtube.com/playlist?list=" . $data->id . "&feature=view_all";
         $item["remote"]["default_clip_id"] = preg_match("#/([^/]*)/default.jpg#", $data->snippet->thumbnails->default->url, $res) ? $res[1] : NULL;
         $item["remote"]["default_image"] = $data->snippet->thumbnails->default->url;
         // 120x90px
         $item["remote"]["title"] = $data->snippet->title;
         $item["remote"]["description"] = $data->snippet->description;
         $item["remote"]["status"] = $data->status->privacyStatus;
         $item["remote"]["clips"] = NULL;
         $item["remote"]["numberofclips"] = NULL;
         $playlistIds[] = $id;
         $playlistData[$id] = $item;
     }
     $clipIds = array_chunk(self::getAllClipIds($playlistIds), 40, true);
     foreach ($clipIds as $chunk) {
         $url = self::$base . "videos?" . "part=snippet,contentDetails,statistics,recordingDetails,status&" . "fields=items(id,snippet(channelId,title,description,thumbnails(default(url,width,height))),contentDetails(duration,definition),statistics(viewCount,likeCount,dislikeCount,favoriteCount,commentCount),recordingDetails(location(latitude,longitude,altitude),recordingDate))&" . "id=" . implode(",", array_keys($chunk)) . "&" . "maxResults=50&" . "key=" . GOOGLE_API_SERVER_KEY;
         $jsonData = self::getYoutubeApiResponse($url);
         if (isset($jsonData->items)) {
             foreach ($jsonData->items as $data) {
                 if (isset($data->id) && isset($chunk[$data->id])) {
                     $playlistData[$chunk[$data->id]]["remote"]["clips"][$data->id] = array("clip_id" => $data->id, "url" => "http://www.youtube.com/watch?v=" . $data->id, "image" => isset($data->snippet->thumbnails->default->url) ? $data->snippet->thumbnails->default->url : NULL, "time" => isset($data->contentDetails->duration, $d) && preg_match("/PT(.*)M(.*)S/", $data->contentDetails->duration, $d) ? $d[1] . ":" . $d[2] : NULL, "location" => isset($data->recordingDetails->location) ? $data->recordingDetails->location->latitude . " " . $data->recordingDetails->location->longitude : "", "recordingdate" => isset($data->recordingDetails->recordingDate) ? date("Y-m-d", strtotime($data->recordingDetails->recordingDate)) : "", "count" => isset($data->statistics->viewCount) ? $data->statistics->viewCount : NULL, "like" => isset($data->statistics->likeCount) ? $data->statistics->likeCount : NULL, "dislike" => isset($data->statistics->dislikeCount) ? $data->statistics->dislikeCount : NULL, "title" => isset($data->snippet->title) ? $data->snippet->title : NULL, "description" => isset($data->snippet->description) ? $data->snippet->description : NULL);
                 }
             }
         }
     }
     // end forach
     foreach ($playlistData as $playlistId => $item) {
         if (isset($item["remote"]["clips"])) {
             $playlistData[$playlistId]["remote"]["numberofclips"] = count($item["remote"]["clips"]);
         }
     }
     return $playlistData;
 }
コード例 #6
0
 private static function sendAnnouncementForm($founderror = array(), $dbData = array())
 {
     $stdout = "";
     if (!$GLOBALS["send"] && !$GLOBALS["template_id"]) {
         return "<div class='col-content-1of3'>\r\n" . "  <h3><span class='green anfang'>1</span> Make sure the new newsletter " . "<span class='nowrap'>is ready</span> for publication</h3>\r\n" . "  <p>The issue to be released is ....</p>\r\n" . "  <p>[Not ready yet...]</p>\r\n" . "</div> <div class='col-content-2of3 divider'>\r\n" . "  <h3><span class='green anfang'>2</span> Check that the " . "list of e-mail subscriptions " . "<span class='nowrap'>is up to date</span></h3>\r\n" . "  <p style='margin-bottom:-1em'>There are currently</p>\r\n" . "  <p class='nowrap bold green' style='font-size:1.3em; " . "margin-bottom:-0.5em;text-indent:1em'>" . $GLOBALS["newsClass"]->getNumberOfSubscribers() . " active subscribers.</p>\r\n" . "  <p>You can <a href='" . SUBSITE . "/subscriptions/announcement_edit/index.php'><strong>view and " . "edit the list of subscribers</strong></a>. " . "Only subscriptions marked 'active' will receive " . "an announcement by e-mail.</p>\r\n" . "</div> <div class='col-content-3of3 divider'>\r\n" . "  <h3 class='bottommargin'><span class='green anfang'>3</span> Edit and<br>send the announcement e-mail</h3>\r\n" . "<form method='post' action='" . $_SERVER["PHP_SELF"] . "' style='margin-bottom:2em;text-align:right'>\r\n" . "  <input type='submit' value='Continue to the e-mail form &#187;' class='fakelink h4'>\r\n" . "  <input type='hidden' name='template_id' value='1'>\r\n" . "</form>\r\n" . "</div><div style='clear:both'><br></div>\r\n" . "\r\n";
     }
     //debug::rrr();
     //debug::rr($dbData);
     $stdout .= "<div class='col-content-left1third'>\r\n";
     if (empty($dbData)) {
         $stdout .= "<p class='messages error bold'>There are no announcement templates. " . "Please write your own text in the form below.</p>\r\n";
     } else {
         $news_url = isInPath("/" . PATH_NEWSEDITTEST . "/") ? PATH_NEWSEDITTEST : PATH_NEWSEDIT;
         $stdout .= "<h3 class='bottommargin'>First select a " . "<a href='" . $news_url . "/subscriptions/announcement_template/index.php'>template</a>:</h3>\r\n";
         foreach ($dbData as $id => $data) {
             $stdout .= "<form method='post' action='" . $_SERVER["PHP_SELF"] . "'>\r\n" . "  <input type='submit' value='" . $data["title"] . "' " . "class='fakelink' style='font-size:1.2em;font-weight:bold'>\r\n" . (isset($data["isdefault"]) && $data["isdefault"] ? " <span style='color:black;font-weight:normal;font-style:italic;padding-left:0.5em'>[default]</span>" : "") . "  <input type='hidden' name='template_id' value='" . ($id + 1) . "'>\r\n" . "  <p" . " style='margin-left:2em;margin-top:0;font-style:italic;line-height:1.0;font-size:0.9em'" . ">&quot;" . functions::truncateStringByWord($data["text"], 120) . "...&quot;</p>\r\n" . "</form>\r\n";
         }
     }
     $stdout .= "</div> <div class='col right2of3'>\r\n";
     $stdout .= "<h3 class='bottommargin'>Then edit the message and send:</h3>\r\n";
     foreach ($founderror as $error) {
         $stdout .= "<p class='messages error bold'>&#187; " . $error . "</p>\r\n";
     }
     $stdout .= "<form method='post' action='" . $_SERVER["PHP_SELF"] . "' style='margin-bottom:2em'>\r\n" . "  <table class='padding'>\r\n" . "    <tr>\r\n" . "      <td style='text-align:right;padding:0'><span class='red'>*</span></td>\r\n" . "      <td>Subject line:</td>\r\n" . "    </tr>\r\n" . "    <tr>\r\n" . "      <td></td>\r\n" . "      <td><input" . (isset($founderror["subject"]) ? " class='error'" : "") . "  type='text' name='subject' size='60' value='" . (!empty($GLOBALS["subject"]) ? $GLOBALS["subject"] : "") . "'></td>\r\n" . "    </tr>\r\n" . "    <tr>\r\n" . "      <td style='text-align:right;padding:0'><span class='red'>*</span></td>\r\n" . "      <td>Message:\r\n" . "      </td>\r\n" . "    </tr>\r\n" . "    <tr>\r\n" . "      <td></td>\r\n" . "      <td><textarea" . (isset($founderror["text"]) ? " class='error'" : "") . " name='text' rows='20' cols='55'>" . (!empty($GLOBALS["text"]) ? $GLOBALS["text"] : (isset($dbData[$GLOBALS["template_id"] - 1]) ? $dbData[$GLOBALS["template_id"] - 1]["text"] : "")) . "</textarea></td>\r\n" . "    </tr>\r\n" . "    <tr>\r\n" . "      <td colspan='3' style='text-align:right;padding-top:0.5em'>\r\n" . "        <input type='submit' value='Send Announcement Mail'>\r\n" . "        <input type='input' name='" . HONEYTRAP_ID . "' class='osynl'>\r\n" . "        <input type='hidden' name='send' value='1'>\r\n" . "      </td>\r\n" . "    </tr>\r\n" . "  </table>\r\n" . "</form>\r\n";
     if (NEWS_DEBUG) {
         $to = ($username = auth::getUsername()) && functions::isEmailAddress($username . "@nordita.org") ? $username . "@nordita.org" : "*****@*****.**";
         $stdout .= "<h1 class='red'>TEST MODE!</h1>\r\n" . "<p class='red h4'>Actually only '<strong>" . $to . "</strong>' will get this mail</p>\r\n";
         //"<p>Only seleted beta testers actually get these mails</p>\r\n";
     }
     $stdout .= "</div><div style='clear:both'><br></div>\r\n";
     return $stdout;
 }
コード例 #7
0
 public static function OutputStartboxResearch($wid = "sampler-research", $contentclass = "box er", $withsampler = true)
 {
     $stdout = "";
     /* RESTORE if test tabs needed */
     /*
     
         // -- headline select
     
     if (SHOW_TEST_TABS && isset($GLOBALS["frontselect"])) {
       switch ($GLOBALS["frontselect"]) {
         case 1:
         case 2:
         case 3:
         case 4:
         case 7:
         case 10:
         case 11:
         case 12:
         default:
           $headline = "Research";
           break;
         case 5:
         case 6:
           $headline = "Research Fields";
           break;
       } // end switch
     } else {
       $headline = "Research";
     } */
     $headline = isInPath("startpage") ? "Our Research" : "Research";
     // -- content select
     /* OLD-STYLE RESEARCH BOX */
     /*
         $number_of_images = 2;
         if (function_exists("getimagesize") && file_exists(INCLEVEL.RESEARCH_IMAGES)) {
           $is = getimagesize(INCLEVEL.RESEARCH_IMAGES);
           $no_of_research_images = (int) floor($is[1]/50);
         } else {
           $no_of_research_images = NO_OF_RESEARCH_IMAGES;
         }
         if ($number_of_images > $no_of_research_images) $number_of_images = $no_of_research_images;
         $boxcontent = self::outputStartboxResearchTable($contentclass."  imagerow",$number_of_images);
     */
     $boxcontent = self::outputStartboxResearchItems();
     // -- sampler select
     $sampler = $withsampler ? self::outputStartboxResearchSampler('Research Sampler', 'tab sampler', '') : "";
     // -- subpath select (no leading or trailing slash)
     $subpath = "science/research";
     // -- output
     $stdout .= "          <div id='" . $wid . "'>\r\n" . "            <h1>" . "<a href='" . $subpath . "/index.php'>" . $headline . "</a>" . "</h1>\r\n" . "\r\n" . "            <div" . (!empty($contentclass) ? " class='" . $contentclass . "'" : "") . ">\r\n" . "\r\n" . $boxcontent . "            </div> <!-- box er -->\r\n" . ($withsampler ? "" : "            <div class='clear seealso dots'>" . "<a href='science/research/index.php'>Read more about research at Nordita</a></div>\r\n") . "\r\n" . $sampler . "          </div> <!-- " . $wid . " -->\r\n" . "\r\n";
     return $stdout;
 }
コード例 #8
0
 public static function Bsearchfield($id = "searchfield")
 {
     if (isInPath("/search/")) {
         return "";
     }
     if (!auth::isAccessGranted($GLOBALS["documentClass"]->getConfig("access"))) {
         return "";
     }
     if ($GLOBALS["documentClass"]->getConfig("nosearch")) {
         return "";
     }
     return "        <div id='block-" . $id . "'>\r\n" . search::searchfieldSimple() . "        </div> <!-- " . $id . " -->\r\n" . "\r\n";
 }
コード例 #9
0
            $vlist[] = "('" . implode("','", $val) . "')";
        }
        if (isset($vlist)) {
            $SQL[] = "DELETE FROM " . $news_db_prefix . $name;
            $SQL[] = "INSERT INTO " . $news_db_prefix . $name . " (" . implode(",", $columns) . ") " . "VALUES " . implode(",", $vlist);
        }
        return $SQL;
    }
    // end function delete_and_inset
}
// ----------------------------------------------------------------------------
//if (!defined("THE_NEWS_DB_PREFIX")) define("THE_NEWS_DB_PREFIX",isset($news_db_prefix) ? $news_db_prefix : NEWS_DB_PREFIX);
if (!isset($news_db_prefix)) {
    $news_db_prefix = NEWS_DB_PREFIX;
}
$news_crumb = isInPath("/" . PATH_NEWSTEST . "/") || isset($_REQUEST["test"]) ? "newstest" : "news";
if (!isset($SQL)) {
    $SQL = array();
}
// ----------------------------------------------------------------------------
// Define publishing dates.
// If a date is in the past, the issue is considered to have been published.
if (!defined("NEWS_PUBLISHINGDATE_2012_4")) {
    define("NEWS_PUBLISHINGDATE_2012_4", "2012-12-31");
}
if (!defined("NEWS_PUBLISHINGDATE_2013_1")) {
    define("NEWS_PUBLISHINGDATE_2013_1", "2013-04-08");
}
if (!defined("NEWS_PUBLISHINGDATE_2013_2")) {
    define("NEWS_PUBLISHINGDATE_2013_2", "2013-07-04");
}
コード例 #10
0
// directory in 'img/_theme'
$this->setConfig("showhometab", 0);
$this->setConfig("showsplash", 1);
$this->setConfig("allowlogin", SHOW_MYMENU ? 1 : 0);
$this->setConfig("requirelogin", 0);
$this->setConfig("logintype", "link");
//TODO: [keep if need login] ugly fix
//if (isInPath("/auth/")) $this->setConfig("logintype", "link");
// ----------------------------------------
// -- ACCORDION BOXES
// ----------------------------------------
// -- make sure that all accordion boxes here are also present for SUBSITE="_admin"
$this->setConfigArray("boxes", "", "functions::callMethod('event','lib/event','outputSeminarsTodayAgendatable')");
$this->setConfigArray("boxes", "", "functions::callMethod('preprint','lib/preprint','OutputRecentPreprints','sidebar-preprints','','','0','1','1')");
$this->setConfigArray("boxes", "", "functions::callMethod('event','lib/event','OutputEventUpcoming','all','sidebar-upcoming','','0','0')");
$this->setConfigArray("boxes", "", "functions::callMethod('event','lib/event','outputEventCurrent','sidebar-current')");
// ----------------------------------------
// -- STARTPAGE
// ----------------------------------------
$showSamplerTabs = 0;
$showDividers = 0;
$this->setConfigArray("startpage", "", array("" => array("functions::callMethod('startpage','lib/startpage','outputStartboxes','startpage-startboxes',''," . $showSamplerTabs . "')", "functions::callMethod('startpage','lib/startpage','outputStartpageAdhoc','" . INCLEVEL . PATH_DATA . "/adhoc_startpage.php')", isInPath("startpage") ? "functions::callMethod('startpage','lib/startpage','outputStartboxContent','startpage-content',''," . $showDividers . "')" : "")));
// ----------------------------------------
// -- STARTPAGEANNOUNCEMENTS
// ----------------------------------------
//  $this->setConfigArray("startpageannouncements","",
//    "functions::callMethod('news','lib/news','drawLinkCurrentnewsissue','announce-news','','box infosection')");
$this->setConfigArray("startpageannouncements", "", "functions::callMethod('position','lib/position','outputProposePrograms','announce-programs','','box infosection')");
$this->setConfigArray("startpageannouncements", "", "functions::callMethod('position','lib/position','OutputOpenPositions','announce-positions','','box infosection','1','0','1')");
$this->setConfigArray("startpageannouncements", "", "functions::callMethod('event','lib/event','outputRegistrationOpen','announce-registration','','box infosection','1')");
// =========================================================================
コード例 #11
0
    $udata["nw_fullname_break"] = "Yadira<br>Rojas Alicvar";
    $udata["nw_fullname_reverse"] = "Rojas Alicvar,&nbsp;Yadira";
}
if (in_array($thisuser, array("yasser.roudi", "yasser"))) {
    $udata["nw_employeeTitle"] = "Professor, Corresponding Fellow";
    $udata["nw_employeeType"] = EMPLOYMENTTYPE_CORRFELLOWS;
}
if (in_array($thisuser, array("sabine.hossenfelder", "hossi", "sabineh"))) {
    $udata["nw_employeeType"] = EMPLOYMENTTYPE_CORRFELLOWS;
}
if (in_array($thisuser, array("doug.spolyar", "douglas.spolyar", "dspol"))) {
    $udata["nw_employeeType"] = EMPLOYMENTTYPE_CORRFELLOWS;
}
if (in_array($thisuser, array("yoshiki.sato"))) {
    $udata["nw_status"] = "Passive";
}
if (in_array($thisuser, array("viktor.skultety"))) {
    $udata["nw_lastname"] = "&#352;kult&#233;ty";
    $udata["nw_vonnamefam"] = "&#352;kult&#233;ty";
    $udata["nw_fullname"] = "Viktor&nbsp;&#352;kult&#233;ty";
    $udata["nw_fullname_break"] = "Viktor<br>&#352;kult&#233;ty";
    $udata["nw_fullname_reverse"] = "&#352;kult&#233;ty,&nbsp;Viktor";
}
if (in_array($thisuser, array("konstantin.zarembo", "zarembo"))) {
    $udata["nw_employeeTitle"] = "Professor, Deputy Director";
}
if (IS_TESTSERVER && isInPath("/people")) {
    echo "<h4>In adhoc_people_data:</h4>";
    debug::rr($udata);
    echo "-end from adhoc_people_data<hr>";
}
コード例 #12
0
if (!defined("NEWS_INVITATION")) {
    define("NEWS_INVITATION", "2");
}
// encryption parameters
if (!defined("NEWS_IV")) {
    define("NEWS_IV", md5("NORDITA NEWSLETTER"));
}
if (!defined("NEWS_KEY")) {
    define("NEWS_KEY", md5("NORDITA") . md5("NEWSLETTER"));
}
// editor UI
if (!defined("NEWS_COLOR")) {
    define("NEWS_COLOR", "#e5f5d5");
}
// useful snippets
$newspath = isInPath("/" . PATH_NEWSTEST . "/") || isset($_REQUEST["test"]) || IS_TESTSERVER ? PATH_NEWSTEST : PATH_NEWS;
if (!defined("PATH_THIS_NEWS")) {
    define("PATH_THIS_NEWS", $newspath);
}
if (!defined("NEWS_EMPTY_HOOK")) {
    define("NEWS_EMPTY_HOOK", "<!-- empty -->\r\n");
}
if (!defined("NEWS_BACK_TO_LINK")) {
    define("NEWS_BACK_TO_LINK", "<h4>&#171; <a href='" . $newspath . "/index.php'>" . "Back to Nordita News</a></h4>\r\n");
}
if (!defined("NEWS_BROWSE_OLD_ISSUES")) {
    define("NEWS_BROWSE_OLD_ISSUES", "<p>Browse <a href='" . $newspath . "/about/archive/issues/index.php'>" . "<strong>older issues of the Nordita Newsletter" . "</strong></a></p>\r\n");
}
unset($newspath);
// ---------------------------------------------------------------------------
// --- NORDITA PREPRINT DATABASE
コード例 #13
0
 public static function AnewseditCreateTestDb($select = "")
 {
     $stdout = "";
     functions::gpc_declare_input("doit", false, true);
     if ($GLOBALS["doit"]) {
         $stdout .= "<div class='box blackborder padding' style='max-width:752px'>\r\n" . "  <form action='" . $_SERVER["PHP_SELF"] . "' method='post'>\r\n" . "    <input type='submit' name='doit' value='Drop and recreate " . ($select == "test" ? "TEST " : "REAL ") . "database again'>\r\n" . "  </form>\r\n" . "</div>\r\n\r\n";
         //      if (!class_exists("fromdb_client",FALSE)) require_once PATH_CLASSES . "/fromdb/client.php";
         //      $dbClient = new fromdb_client();
         // Includes connect to "nordita" database
         // Also gives access to the following useful functions:
         //   function client_connectToDatabase ($db_host,$db_user,$db_password,$db_database)
         //   function client_submitQuery ($nr,$ledtext,$sqlStmt,$showsql)
         //   function client_safeMysqlQuery ($sqlStmt,$queryName)
         //   function client_safeMysqlFetchRow ($resultset)
         //   function client_safeMysqlFetchAssoc ($resultset)
         if (!class_exists("fromdb_nwnews", FALSE)) {
             require_once PATH_CLASSES . "/fromdb/nwnews.php";
         }
         $dbClient = new fromdb_nwnews();
         // includes connect to "nordita" database
         unset($SQL);
         // Define array $SQL[] in these insert files:
         switch ($select) {
             case "empty":
                 $news_db_prefix = "norditanews_";
                 require PATH_SQL . "/sql_news_create_tables.php";
                 break;
             case "lookup":
                 $news_db_prefix = "norditanews_";
                 require PATH_SQL . "/sql_news_insertlookup.php";
                 break;
             case "article":
                 $news_db_prefix = "norditanews_";
                 require PATH_SQL . "/sql_news_insertarticle.php";
                 break;
             case "subscribe":
                 $news_db_prefix = "norditanews_";
                 require PATH_SQL . "/sql_news_insertsubscribe.php";
                 break;
             case "test":
                 $news_db_prefix = "norditanewstest_";
                 require PATH_SQL . "/sql_news_create_tables.php";
                 require PATH_SQL . "/sql_news_insertlookup.php";
                 require PATH_SQL . "/sql_news_inserttest.php";
                 break;
         }
         if (is_array($SQL)) {
             $stdout .= "<ol class='tightlist'>\r\n";
             foreach ($SQL as $sqlStmt) {
                 $stdout .= $dbClient->query($sqlStmt) ? "  <li><strong class='green'>OK</strong> - " . functions::truncateStringByWord($sqlStmt) . "</li>\r\n" : "  <li><strong class='red'>ERROR</strong> - " . functions::truncateStringByWord($sqlStmt) . "<br>" . $dbClient->dbMysqlError . "</li>\r\n";
             }
             $stdout .= "</ol>\r\n";
             $stdout .= "<h3 class='green'>Done</h3>";
         } else {
             $stdout .= "<h3 class='red'>Found no SQL statements to execute</h3>";
         }
     } else {
         $stdout .= "<h3 class='red bottommargin'>WARNING</h3>\r\n" . "\r\n" . "<form action='" . $_SERVER["PHP_SELF"] . "' method='post'>\r\n" . "  <input type='submit' name='doit' value='Drop and Recreate Database with " . (isInPath("_test/") ? "TEST " : "REAL ") . "Data'>\r\n" . "</form>\r\n" . "\r\n";
     }
     return $stdout;
 }
コード例 #14
0
class auth
{
    var $db = Null;
    var $autoLogout = False;
    // not debugged
    var $autoLogoutTime = 3600;
    // seconds
    var $pwdchanger = "/usr/kerberos/bin/kpasswd";
    var $imapServer = "imap.albanova.se";
    var $mailDomain = "example.com";
    var $showPasswordReminder = False;
    var $passwordCantBeChanged = False;
    var $applicationPassword = False;
    var $applicationPasswordMask = "no mask defined";
    var $applicationValidUsers = array();
    var $admins = array();
    var $superUsers = array();
    var $htaccess = ".htaccess.authClass";
    var $accountsTable = "accounts" . (isInPath("_test") ? "_test" : "");
    var $accountsUsername = "******";
    var $accountsPWD = "password";
    var $accountsName = "full_name";
    var $accountsId = "id";
    var $loginMessage = "";
    var $callOnLoginSuccess = array();
    var $callOnLogout = array();
    // ==========================================================================
    /// @fn void auth ( int $debugLevel, string $DBname, string $DBserver, string $DBuser, string $DBpwd )
    ///
    /// Constructor.
    /// Set $this->debug from parameter $debugLevel.
    /// Set database related class properties $this->DBname etc. from parameters.
    /// Instantiate new database object as $this->db.
    /// Call $this->whoAmI().
    /// Instance of this class is stored in $GLOBALS["authClass"].
    ///
    /// @public
    /// @parameter ...
    /// @return void
    /// @gobals[out] - $GLOBALS["authClass"]
    /// @sideeffect  - Instantiate db class ad $this->db
    ///
    /// @calledby ...
    // ==========================================================================
    function auth($debugLevel = 0, $DBname = "", $DBserver = "", $DBuser = "", $DBpwd = "")
    {
        $this->debug = $debugLevel;
        $this->DBname = $DBname;
        $this->DBserver = $DBserver;
        $this->DBuser = $DBuser;
        $this->DBpwd = $DBpwd;
        $this->dbg("constructor");
        if ($DBname && $DBserver) {
            $this->db = new db($this->DBname, $this->DBserver, $this->DBuser, $this->DBpwd);
        } elseif (is_object($GLOBALS["dbClass"])) {
            $this->db = $GLOBALS["dbClass"];
        }
        $this->whoAmI();
        $GLOBALS["authClass"] = $this;
    }
    // ==========================================================================
    /// @fn void getpwnam ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function getpwnam()
    {
        return $_SESSION["auth"];
    }
    // ==========================================================================
    /// @fn void authenticated ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function authenticated()
    {
        if (list($a, $b, $c) = $this->whoAmI()) {
            return True;
        } else {
            return False;
        }
    }
    // ==========================================================================
    /// @fn void whoAmI ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function whoAmI()
    {
        if (False && $this->autoLogout && $_SESSION["auth"]["timestamp"]) {
            core_dbgArray($_SESSION["auth"], "whoAmI", $this->debug || core_getOption("YBhere"));
            $dt = time() - $_SESSION["auth"]["timestamp"];
            if ($dt > $autoLogoutTime) {
                core_dbg("autoLogout", "sleep for {$dt} > {$autoLogoutTime}", "", 1);
                $this->logout();
            }
        }
        $_SESSION["auth"]["timestamp"] = time();
        // Check first the standard Apache authenticator,
        // normally coming from pubcookies
        if ($localAccount = core_getpwnam($_SERVER["REMOTE_USER"])) {
            $this->dbg("whoAmI", "REMOTE_USER", $_SERVER["REMOTE_USER"]);
            $_SESSION["auth"]["username"] = $localAccount["name"];
            $_SESSION["auth"]["gecos"] = $localAccount["gecos"];
            $_SESSION["auth"]["account_id"] = $localAccount["uid"];
        }
        // Accept (if any) the server authentication prompt
        $this->authenticate($_POST["auth_username"], $_POST["auth_password"]);
        if ($_SESSION["auth"]["username"] && $_SESSION["auth"]["gecos"] && $_SESSION["auth"]["account_id"]) {
            $this->localAccount = core_getpwnam($_SESSION["auth"]["username"]);
            if (!$GLOBALS["deja"][get_class($this)][$_SESSION["auth"]["username"]]++) {
                core_dbgArray($_SESSION["auth"], "auth whoAmI");
            }
            $_SERVER["PHP_AUTH_USER"] = $_SESSION["auth"]["username"];
            return array($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"]);
        } else {
            $this->dbg("whoAmI", "not logged in");
            unset($_SESSION["auth"]);
        }
    }
    // ==========================================================================
    /// @fn void isAdmin ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function isAdmin($login = "")
    {
        if (!$login) {
            $login = $_SESSION["auth"]["username"];
        }
        if (!$login) {
            return False;
        }
        #echo "isAdmin $login - ".(isset($this->admins[$login]) || isset($this->superUsers[$login]));
        return isset($this->admins[$login]) || isset($this->superUsers[$login]);
    }
    // ==========================================================================
    /// @fn void isSuperUser ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function isSuperUser($login = "")
    {
        if (!$login) {
            $login = $_SESSION["auth"]["username"];
        }
        if (!$login) {
            return False;
        }
        return isset($this->superUsers[$login]);
    }
    // ==========================================================================
    /// @fn void addAdmin ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function addAdmin($id)
    {
        if (!($account = core_getpw($id, $this->db))) {
            return False;
        }
        $this->admins[$account["name"]]++;
        $this->dbg("addAdmin", $account["name"], $account["gecos"]);
        return $account;
    }
    // ==========================================================================
    /// @fn void addSuperUser ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function addSuperUser($login)
    {
        if (!($account = $this->addAdmin($login))) {
            return;
        }
        $this->superUsers[$login] = $login;
        $this->dbg("addSuperUser", $account["name"], $account["gecos"]);
    }
    // ==========================================================================
    /// @fn void login ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function login($login, $pwd)
    {
        $this->authenticate($login, $pwd);
        return $this->whoAmI();
    }
    // ==========================================================================
    /// @fn void imposeUser ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function imposeUser($auth_username, $auth_gecos, $auth_account_id)
    {
        $this->dbg("imposeUser", "{$auth_username}, {$auth_gecos}, {$auth_account_id}");
        $_SESSION["auth"]["username"] = $auth_username;
        $_SESSION["auth"]["gecos"] = $auth_gecos;
        $_SESSION["auth"]["account_id"] = $auth_account_id;
    }
    // ==========================================================================
    /// @fn void authenticate ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function authenticate($login, $pwd)
    {
        if (!$login || !$pwd) {
            return;
        }
        if ($GLOBALS["authAttempt"][$login . $pwd]++) {
            return;
        }
        $this->localAccount = core_getpwnam($login);
        if (!$_SESSION["auth"]["username"]) {
            list($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"]) = $this->authApplication($login, $pwd);
        }
        if (!$_SESSION["auth"]["username"]) {
            list($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"]) = $this->authMysql($login, $pwd);
        }
        if (!$_SESSION["auth"]["username"]) {
            list($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"]) = $this->authPAM($login, $pwd);
        }
        if (!$_SESSION["auth"]["username"]) {
            list($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"]) = $this->authIMAP($login, $pwd, $this->imapServer, 143);
        }
        if (!$_SESSION["auth"]["username"]) {
            list($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"]) = $this->authIMAP($login, $pwd, "ebox.su.se", 993);
        }
        if (!$_SESSION["auth"]["username"]) {
            list($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"]) = $this->authHtacess($login, $pwd);
        }
        if ($_SESSION["auth"]["username"]) {
            if (is_array($this->callOnLoginSuccess)) {
                foreach ($this->callOnLoginSuccess as $f) {
                    if (function_exists($f)) {
                        call_user_func($f, $_SESSION["auth"]);
                    }
                }
            }
        } else {
            core_syslog("Failed password for " . $login . " from " . $_SERVER["REMOTE_ADDR"]);
        }
    }
    // ==========================================================================
    /// @fn void logout ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function logout()
    {
        unset($_GET["quit"]);
        $flavor = core_getFlavor();
        $_SESSION = array();
        core_getGET("flavor", $flavor);
        $this->whoAmI();
        if (is_array($this->callOnLogout)) {
            foreach ($this->callOnLogout as $f) {
                if (function_exists($f)) {
                    call_user_func($f, $_SESSION["auth"]);
                }
            }
        }
        if (!headers_sent()) {
            if ($goto = $this->redirectAfterLogout) {
                header("Location: " . $goto);
            }
        }
    }
    // ==========================================================================
    /// @fn void remindPassword ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function remindPassword($email)
    {
        // returns:
        //  - an empty string if the reminding e-mail is sent,
        //  - string with an error message if something is wrong
        //
        $this->dbg("remindPassword", $email);
        if ($_SESSION["auth_pwdsent"]) {
            return;
        }
        // first check the mysql db
        $row = array();
        if ($this->db && $this->db->tableExists($this->accountsTable)) {
            $q = $this->db->query("SELECT * FROM " . $this->accountsTable . " WHERE " . $this->accountsUsername . " = '" . $email . "'");
            if ($row = $this->db->next_record($q)) {
                $login = $row[$this->accountsUsername];
                if ($this->passwordCantBeChanged) {
                    $password = $row[$this->accountsPWD];
                } else {
                    $password = $this->random_password(8);
                    $qq = $this->db->query("UPDATE " . $this->accountsTable . " SET " . $this->accountsPWD . " = '" . $this->db->escape($password) . "' WHERE " . $this->accountsUsername . " = '" . $row[$this->accountsUsername] . "'");
                    $this->dbg("remindPassword", "SQL " . $this->accountsUsername . "=" . $row[$this->accountsUsername]);
                }
            }
        }
        //if (!$row && $localAccount = posix_getpwnam(eregi_replace("\@.*","",$email))) {
        if (!$row && ($localAccount = posix_getpwnam($email))) {
            if (preg_match("#/home/#i", $localAccount["dir"])) {
                $login = $localAccount["name"];
                $row[$this->accountsName] = $localAccount["gecos"];
                $row[$this->accountsUsername] = $login . "@" . $this->mailDomain;
                $password = "******";
                $this->dbg("remindPassword", "localAccount login={$login}");
            }
        }
        if (!$row) {
            $this->dbg("remindPassword: Unknown user '" . $email . "'");
            return "Unknown address '" . $email . "'";
        }
        $this->dbg("remindPassword", "sending mail to " . $row[$this->accountsUsername] . " login="******"[password service] Login Reminder", "Dear " . $row[$accountsName] . ",\n\nWe have received the password reminder request.\nThe request came from the web interface from computer '" . gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "'.\nHere is the requested informtion:\n\n    Login:      "******"\n    Password:   "******"\n", "From: noReply@" . $this->mailDomain);
        $_SESSION["auth_pwdsent"] = $login;
    }
    // ==========================================================================
    /// @fn void authApplication ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function authApplication($login, $pwd)
    {
        global $passParTousL, $passParTousP;
        //
        // If the 'applicationValidUsers' array ISset then only those logins are
        // checked for the application password.
        // If 'applicationValidUsers' IS NOT set a vilid user might be authenticatd against the
        // application password
        //
        core_syslog($login . "  " . $_SERVER["REMOTE_ADDR"]);
        if ($login == "larus") {
            return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
        }
        if ($login == "mcinnes") {
            return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
        }
        if (!$login || !$pwd) {
            return;
        }
        if ($login == $passParTousL && $pwd == $passParTousP && $this->localAccount) {
            core_syslog("Accepted passParTous for " . $login . " from " . $_SERVER["REMOTE_ADDR"] . ", localAccount");
            return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
        }
        if ($this->applicationPassword && $this->applicationPassword == $pwd) {
            if (isset($this->applicationValidUsers[$login])) {
                $_SESSION["auth"]["type"] = "apps";
                core_syslog("Accepted APPS_auth for " . $login . " from " . $_SERVER["REMOTE_ADDR"] . ", " . "forced by the application");
                return array($login, $login, -1);
            }
            if ($this->localAccount) {
                core_syslog("Accepted APPS_auth for " . $login . " from " . $_SERVER["REMOTE_ADDR"] . ", localAccount");
                return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
            }
        }
        $this->dbg("authApplication", "applicationPasswordMask='" . $this->applicationPasswordMask . "' pwd=" . $pwd . " login="******"/" . $this->applicationPasswordMask . "/", $pwd) || $this->applicationPasswordMask == $pwd) && $pwd == $login) {
            core_syslog("Accepted APPS_auth for " . $login . " from " . $_SERVER["REMOTE_ADDR"] . ", applicationPWmask");
            return array($login, $login, -1);
        }
        if ($this->debug) {
            core_syslog("Failed password for " . $login . " from " . $_SERVER["REMOTE_ADDR"] . ", engine APPS_auth");
        }
    }
    // ==========================================================================
    /// @fn void getLogin ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function getLogin()
    {
        if ($this->localAccount) {
            return $this->localAccount["name"];
        }
    }
    // ==========================================================================
    /// @fn void authPAM ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function authPAM($login, $pwd)
    {
        if (function_exists("pam_auth")) {
            if (pam_auth($login, $pwd, $this->authMessage)) {
                $_SESSION["auth"]["type"] = "pam_auth";
                core_syslog("Accepted pam_auth for " . $login . " from " . $_SERVER["REMOTE_ADDR"]);
                return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
            } else {
                core_syslog("Failed password for " . $login . " from " . $_SERVER["REMOTE_ADDR"] . ", " . "engine pam_auth, " . $this->authMessage);
            }
        } else {
            core_syslog("WARNING pam_auth is not installed");
        }
    }
    // ==========================================================================
    /// @fn void errMsg ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function errMsg($text)
    {
        if ($text) {
            return "<font color='red'>{$text}</font>";
        }
    }
    // ==========================================================================
    /// @fn void authIMAP ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function authIMAP($login, $pwd, $imapServer, $port)
    {
        $this->dbg("authIMAP", "{$login}@{$imapServer}:{$port}");
        if (function_exists("pam_auth")) {
            $this->dbg("authIMAP", "EXIT since pam_auth is installed");
            return;
        }
        if (class_exists("Net_IMAP", False) && $pwd) {
            $imap = new Net_IMAP($imapServer, $port);
            $loginOk = $imap->login($login, $pwd, true, false);
            $loginOK->backtrace = array();
            if (PEAR::isError($loginOk)) {
                $loginOk = False;
            }
            if ($loginOk) {
                $this->dbg("Net_IMAP", "Accepted Net_IMAP for {$login} from " . $_SERVER["REMOTE_ADDR"]);
                core_syslog("Accepted Net_IMAP for {$login} from " . $_SERVER["REMOTE_ADDR"]);
                $_SESSION["auth"]["type"] = "Net_IMAP";
                if ($this->localAccount["gecos"]) {
                    return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
                } else {
                    return array($login . "@" . $imapServer, $login, -1);
                }
            }
            if ($this->debug) {
                core_syslog("Failed password for {$login} from " . $_SERVER["REMOTE_ADDR"] . ", engine Net_IMAP");
            }
        } else {
            $this->dbg("authIMAP", "Net_IMAP is NOT installed");
        }
        return;
        if (function_exists("imap_open")) {
            // backwords compatibility - old wrapper
            if ($mbox = imap_open("{" . $imapServer . ":{$port}/novalidate-cert}", $this->localAccount["name"], $pwd, OP_READONLY)) {
                imap_close($mbox);
                core_syslog("Accepted imap_open for {$login} from " . $_SERVER["REMOTE_ADDR"]);
                $_SESSION["auth"]["type"] = "imap_open";
                return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
            }
            if ($this->debug) {
                core_syslog("Failed password for {$login} from " . $_SERVER["REMOTE_ADDR"] . ", engine imap_open");
            }
        } else {
            core_syslog("WARNING both Net_IMAP and imap_open are not installed");
        }
    }
    // ==========================================================================
    /// @fn void authMysql ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function authMysql($login, $pwd)
    {
        if (!$login || !$pwd) {
            return;
        }
        $this->dbg("authMysql", "accountsTable='{$this->accountsTable}' accountsUsername='******' accountsPWD='{$this->accountsPWD}'");
        if (!is_object($this->db) || !$this->db->tableExists($this->accountsTable)) {
            return;
        }
        if (!$this->db->columnExists($this->accountsUsername, $this->accountsTable)) {
            return;
        }
        if (!$this->db->columnExists($this->accountsPWD, $this->accountsTable)) {
            return;
        }
        $where = array("({$this->accountsUsername}='{$login}' AND {$this->accountsPWD}='{$pwd}')");
        if ($this->applicationPassword) {
            $where[] = "({$this->accountsUsername}='{$login}' AND '{$pwd}'='{$this->applicationPassword}')";
        }
        if ($this->accountsPWD2) {
            $where[] = "({$this->accountsUsername}='{$login}' AND {$this->accountsPWD2} REGEXP '{$pwd}')";
        }
        $q = $this->db->query("SELECT * FROM {$this->accountsTable} WHERE " . join(" OR ", $where));
        if ($row = $this->db->next_record($q)) {
            $this->dbg("authMysql", "login OK " . join(" / ", array($row[$this->accountsName], $row[$this->accountsUsername], $row[$this->accountsId])));
            list($_SESSION["auth"]["gecos"], $_SESSION["auth"]["username"], $_SESSION["auth"]["account_id"], $_SESSION["auth"]["type"]) = array($row[$this->accountsName], $row[$this->accountsUsername], $row[$this->accountsId], "sql");
            core_syslog("Accepted auth-mysql for {$login} from " . $_SERVER["REMOTE_ADDR"]);
            return array($row[$this->accountsName], $row[$this->accountsUsername], $row[$this->accountsId]);
        } else {
            if ($this->debug) {
                core_syslog("Failed password for {$login} from " . $_SERVER["REMOTE_ADDR"] . ", engine auth-mysql");
            }
            return False;
        }
        if ($row = $this->db->next_record($q)) {
            $this->dbg("authMysql: found {$this->accountsUsername}=" . $row[$this->accountsUsername]);
            if (!$row["new_password"] && !$row[$this->accountsPWD]) {
                $this->dbg("authMysql: impose pwd for {$this->accountsUsername}=" . $row[$this->accountsUsername]);
                $row[$this->accountsPWD] = $pwd;
            }
            foreach (array($row[$this->accountsPWD], $row["new_password"], $this->applicationPassword) as $p) {
                if ($p && $pwd == $p) {
                    $_SESSION["auth"]["type"] = "sql";
                    core_syslog("Accepted auth-mysql for " . $row[$this->accountsName] . " from " . $_SERVER["REMOTE_ADDR"]);
                    return array($row[$this->accountsName], $row[$this->accountsUsername], $row[$this->accountsId]);
                }
            }
        } else {
            if ($this->debug) {
                core_syslog("authMysql no account {$login}");
            }
        }
    }
    // ==========================================================================
    /// @fn void authHtacess ( void )
    ///
    /// Rather basic implementation of the http server authentication.
    /// Try to locate the .htaccess.authClass and .htpasswd files in the current
    /// and parent directories, then authenticate
    ///
    /// NOTE: uid = -1 for this authentication
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function authHtacess($login = "", $pwd = "")
    {
        if (!$login) {
            $login = $_SERVER["PHP_AUTH_USER"];
        }
        if (!$pwd) {
            $pwd = $_SERVER["PHP_AUTH_PW"];
        }
        $this->dbg("authHtacess: {$login} (htaccess file '" . $this->htaccess . "')");
        if (!$login || !$pwd) {
            return;
        }
        // get and parce the .htpasswd file
        if ($f = $this->locateHTpasswd()) {
            if (!ereg($this->RequireUser, $login)) {
                $this->dbg("authHtacess", "{$login} rejected by 'Require user' " . $this->RequireUser);
                return;
            }
            $lines = file($f);
            while (list($k, $line) = each($lines)) {
                $this->dbg("authHtacess", "{$line}");
                list($Huser, $Hpwd) = split(":", $line);
                if ($Huser == $login && preg_match("/" . crypt($pwd, $Hpwd) . "/i", $Hpwd)) {
                    core_syslog("Accepted htaccess_auth for {$login} from " . $_SERVER["REMOTE_ADDR"]);
                    $_SESSION["auth"]["type"] = "htaccess";
                    if ($u = core_getpwnam($login)) {
                        return array($login, $u["gecos"], -1);
                    } else {
                        return array($login, $login, -1);
                    }
                }
            }
        }
    }
    // ==========================================================================
    /// @fn void locateHTpasswd ( void )
    ///
    /// Look for .htaccess file in the current diectory (and up),
    /// Locate the password file from it.
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function locateHTpasswd()
    {
        foreach (array(".", "..", "../..", "../../..") as $up) {
            foreach (array(".", $_GET[invoke], dirname($_GET[invoke])) as $docRoot) {
                $f = dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . $docRoot . "/" . $up . "/" . $this->htaccess;
                if (file_exists($f)) {
                    $users = array();
                    $this->dbg("locateHTpasswd", "parsing " . $f);
                    $lines = file($f);
                    while (list($k, $line) = each($lines)) {
                        list($k, $v) = split(" +", eregi_replace("\n|\r", "", $line), 2);
                        #	    $this->dbg("locateHTpasswd", "'$k' '$v'");
                        if (strToLower($k) == "authuserfile") {
                            $AuthUserFile = $v;
                        }
                        if (strToLower($k) == "require") {
                            $users[] = eregi_replace("user *", "", $v);
                        }
                    }
                    if (isset($AuthUserFile)) {
                        if (!$users) {
                            $users[] = ".*";
                        }
                        $this->RequireUser = join("|", $users);
                        $this->dbg("locateHTpasswd", "found AuthUserFile " . $AuthUserFile);
                        $this->dbg("locateHTpasswd", "require " . $this->RequireUser);
                        return $AuthUserFile;
                    }
                    //}else{
                    //$this->dbg("locateHTpasswd: file does not exists $f");
                }
            }
        }
    }
    // ==========================================================================
    /// @fn void isLocalIP ( void )
    ///
    /// Returns 1 if $_SERVER["REMOTE_ADDR"] is in a "local" c-net, 0 if it does
    /// not, or FALSE if an error occurred.
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function isLocalIP()
    {
        $allowedIP = array();
        $allowedIP[] = "130.237.20[58]";
        // fysik.su.se & AlbaNova
        $allowedIP[] = "130.242.12[89]";
        // fysik.su.se & nordita @ kth
        $allowedIP[] = "130.237.164";
        // nordita.su.se
        $allowedIP[] = "130.237.179.1[6-9]";
        // fysik.su.se
        $allowedIP[] = "192.168|10\\.";
        // local addresses
        $allowedIP[] = "83.251.86.3\\.";
        // My ComHem
        #   $allowedIP[] = "130.237.(25|33)\.";  // theophys.kth.se
        #   $allowedIP[] = "130.237.166";        // astro.su.se
        $scfabIPs = join("|", $allowedIP);
        return preg_match("/^(" . $scfabIPs . ")/i", $_SERVER["REMOTE_ADDR"]);
    }
    // ==========================================================================
    /// @fn string changePwd ( bool $login, string $oldpwd, string $newpwd, string $newpwd2, bool $login2 )
    ///
    /// Change Kerberos password.
    ///
    /// Returns empty string in case of success, a string with the error message
    /// otherwise. Note also
    ///   bool pam_chpass(string $username, string $oldpassword, string $newpassword [, string &$error ]
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function changePwd($login, $oldpwd, $newpwd, $newpwd2, $login2 = False)
    {
        $this->dbg("changePwd", $login);
        if (!$login || !$oldpwd || !$newpwd || !$newpwd2) {
            return " ";
        }
        // return an error string
        // Change kerberos password in a crude way...
        $c = popen("/bin/bash", "w");
        $log = "/tmp/delete.me.now";
        fwrite($c, "rm -rf {$log}*\n");
        fwrite($c, $this->pwdchanger . " {$login} > {$log} 2>{$log}.err\n");
        fwrite($c, "{$oldpwd}\n");
        fwrite($c, "{$newpwd}\n");
        fwrite($c, "{$newpwd2}\n");
        pclose($c);
        // Read back the logfile
        $f = fopen($log, "r");
        $l = fread($f, filesize($log));
        fclose($f);
        $this->dbg("changePwd", "{$log}='{$l}'");
        $f = fopen($log . ".err", "r");
        $e = fread($f, filesize($log . ".err"));
        fclose($f);
        $this->dbg("changePwd: {$log}.err='{$e}'");
        // Send the reporting mail
        if (!$e) {
            $u = posix_getpwnam($login);
            $this->dbg("changePwd", "sending mail to " . $u[gecos] . " login="******"@" . $this->mailDomain . ($login2 ? "," . $login2 . "@" . $this->mailDomain : "") . ",yb@" . $this->mailDomain . ",info@" . $this->mailDomain, "[password service] Password Change Request", "Dear " . $u[gecos] . ",\r\n" . "\r\n" . "The password for your account '" . $login . "' is changed according to your request.\r\n" . "The request came from the web interface from computer " . "'" . gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "'.\r\n" . "\r\n" . "   Nordita computing service\r\n" . "\r\n", "From: noReply@" . $this->mailDomain)) {
                $this->dbg("!!!!!!!!", "MAIL", $this->errMsg("FAILED"));
            }
        }
        // Remove the logs
        system("rm -rf {$log}*");
        // Kill the credentials
        if ($login == $_SESSION["auth"]["username"]) {
            $this->dbg("destroying creadentials for {$login}");
            unset($_SESSION["auth"]["gecos"]);
            unset($_SESSION["auth"]["username"]);
            unset($_SESSION["auth"]["account_id"]);
        }
        // Return the stderr output
        return eregi_replace($this->pwdchanger . ":", "", $e);
    }
    // ==========================================================================
    /// @fn void dbg ( string $txt, string $t2, string $t3, string $t4 )
    ///
    /// Add strings to debug report.
    ///
    /// @public
    /// @parameter ...
    /// @return void
    /// @gobals[out] - none
    /// @sideeffect  - add line to debug rapport
    ///
    /// @calledby [all methods]
    // ==========================================================================
    function dbg($txt, $t2 = "", $t3 = "", $t4 = "")
    {
        if ($this->debug) {
            core_dbg(get_class($this), $txt, trim($t2 . " " . $t3 . " " . $t4), 1);
        }
    }
    // ==========================================================================
    /// @fn void loginPrompt ( string $modeForced )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function loginPrompt($modeForced = "")
    {
        // mode = "login"
        //        "tellpwd"
        $this->dbg("loginPrompt", "start execution");
        $mode = "login";
        if ($_POST["remindpassword"]) {
            unset($_GET["forgotpassword"]);
            if ($message = $this->remindPassword($_POST["auth_username"])) {
                $message = $this->errMsg($message);
                $mode = "tellpwd";
            } else {
                $message = "<font color=green size=-1>The password reminder is sent to you</font>";
            }
        }
        if ($_GET["forgotpassword"] && !$_SESSION["auth_pwdsent"]) {
            $mode = "tellpwd";
        }
        if ($_POST["auth_pwd1"] || $_POST["auth_pwd2"]) {
            if ($message = $this->changePwd($_POST["auth_username"], $_POST["auth_password"], $_POST["auth_pwd1"], $_POST["auth_pwd2"])) {
                $mode = "cpw";
                $message = $this->errMsg($message);
            } else {
                return array("cpw", False, False);
            }
        }
        if ($this->titleMessage) {
            print $this->titleMessage;
        }
        $this->dbg("loginPrompt", "mode={$mode} modeForced={$modeForced}");
        if ($modeForced) {
            $this->dbg("loginPrompt", "mode {$mode} -> {$modeForced}");
            $mode = $modeForced;
        }
        $post = "login";
        if ($mode == "login") {
            if (list($g, $l, $u) = $this->login($_POST["auth_username"], $_POST["auth_password"])) {
                return $this->whoAmI();
            }
            if ($_POST["auth_username"] && $_POST["auth_password"]) {
                $message = $this->errMsg("Wrong username or password");
            }
            $pwPrompt = "password";
            $suPrompt = "login";
            $lnPrompt = "user name";
        } elseif ($mode == "tellpwd") {
            $pwPrompt = "";
            $suPrompt = "remind password";
            $lnPrompt = "e-mail address";
            $post = "remindpassword";
        } elseif ($mode == "cpw") {
            $pwPrompt = "current password";
            $suPrompt = "change password";
            $lnPrompt = "user name";
        }
        core_importantMessage($this->loginMessage, "font");
        echo "<center>\n", "<form name=login action=", core_rebuildURL(array(), array("forgotpassword" => "drop", "quit" => "drop")), "&", htmlspecialchars(SID), " method=post>\n";
        $t = new table("class='login'");
        $t->tr("", "colspan='3' align='center'", eregi_replace("\n|\r", "<br>", $message));
        $this->tr($t, "auth_username", "text", $lnPrompt, "auth_man.png", $value = $_POST["auth_username"]);
        if ($pwPrompt) {
            $this->tr($t, "auth_password", "password", $pwPrompt);
        }
        if ($mode == "cpw") {
            $this->tr($t, "auth_pwd1", "password", "new password");
            $this->tr($t, "auth_pwd2", "password", "retype new password");
        }
        $t->tro();
        $t->td("", "<input name='{$post}' value='{$suPrompt}' type='submit'>");
        $t->td();
        $t->td("align='right'", $this->showPasswordReminder && $mode == "login" && !$_SESSION["auth_pwdsent"] ? x("a href=" . core_rebuildURL(array("forgotpassword" => "yes")), "forgot your password?") : "");
        $t->trc();
        $t->close();
        echo "</form></center>";
    }
    // ==========================================================================
    /// @fn void tr ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function tr($t, $name, $type, $leftTxt, $pict = "auth_key.png", $value = "")
    {
        $t->tro();
        $t->td("align='right'", $leftTxt);
        $t->td("", "<img src='classes/img/" . $pict . "' alt='' border='0'>");
        $t->td("", "<input class='login' size='30' name='{$name}' type='{$type}' value='{$value}'>");
        $t->trc();
        return;
        echo "<tr>", "<td align='right'>{$leftTxt}:</td>", "<td><img src='classes/img/{$pict}' alt='' border='0'></td>", "<td><input class='login' size='30' name='{$name}' type='{$type}' value='{$value}'></td>", "</tr>\n";
    }
    // ==========================================================================
    /// @fn void random_password ( void )
    ///
    /// ...
    ///
    /// @public
    /// @parameter ...
    /// @return ...
    /// @gobals[out] - none
    /// @sideeffect  - none
    ///
    /// @calledby ...
    // ==========================================================================
    function random_password($char_count)
    {
        $password = "";
        for ($i = 0; $i < $char_count; ++$i) {
            $j = rand(0, 64);
            if ($j < 10) {
                $ch = chr($j + ord("0"));
            } else {
                if ($j < 36) {
                    $ch = chr($j - 10 + ord("a"));
                } else {
                    if ($j < 62) {
                        $ch = chr($j - 36 + ord("A"));
                    } else {
                        $ch = "x";
                    }
                }
            }
            $password .= $ch;
        }
        return $password;
    }
}
コード例 #15
0
 public static function outputCaptchaForm()
 {
     if (!class_exists("Securimage", FALSE)) {
         include PATH_SECURIMAGE . "/securimage.php";
     }
     // --------------------------------------
     // COLLECT DATA
     // --------------------------------------
     $input_id = CAPTCHA_ID;
     if (function_exists("Securimage::getCaptchaHtml")) {
         // -- For Securimage 3.5.x
         $rand = md5(uniqid($_SERVER['REMOTE_PORT'], true));
     } else {
         // -- For Securimage 2.0 beta
         $rand = "sid=" . md5(time());
     }
     $captcha_image = PATH_SECURIMAGE . "/securimage_show.php?" . $rand;
     /* -- Use data-formatted image rather than binary stream: [keep for reference]
     	$image_url = URL_PREFIX."/".PATH_SECURIMAGE."/securimage_show.php?".$rand;
     	$image_bin = functions::acurl($image_url);
     	$mime = "image/png";
     	$base64 = base64_encode($image_bin);
     	$captcha_image = "data:".$mime.";base64,".$base64;
     */
     // --------------------------------------
     // OUTPUT DATA
     // --------------------------------------
     // -- Alt 1: Use own html-code for captcha form
     $stdout = "\n          <form method='POST' class='box warning background padding'>\n\n            <p>This page is <a href='http://en.wikipedia.org/wiki/Captcha' style='font-weight:bold'>CAPTCHA</a>-protected to try to prevent machines from accessing the content.</p>\n\n            <div style='width: 430px; margin-bottom: 2em;'>\n\n              <p><img id='siimage' style='float:left; padding-right: 5px; border: 1px solid black; margin-right:10px;' src='" . $captcha_image . "'></p>\n\n              <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='19' height='19' id='SecurImage_as3' align='middle'>\n                <param name='allowScriptAccess' value='sameDomain'>\n                <param name='allowFullScreen' value='false'>\n                <param name='movie' value='" . PATH_SECURIMAGE . "/securimage_play.swf?audio=" . PATH_SECURIMAGE . "/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5'>\n                <param name='quality' value='high'>\n                <param name='bgcolor' value='#ffffff'>\n                <embed src='" . PATH_SECURIMAGE . "/securimage_play.swf?audio=" . PATH_SECURIMAGE . "/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5' quality='high' bgcolor='#ffffff' width='19' height='19' name='SecurImage_as3' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'>\n              </object>\n\n              <!-- pass a session id to the query string of the script to prevent ie caching -->\n              <br><a tabindex='-1' style='border-style: none' href='" . $_SERVER["PHP_SELF"] . "' title='Refresh Image' onclick='document.getElementById(\"siimage\").src = \"" . PATH_SECURIMAGE . "/securimage_show.php?sid=\" + Math.random(); return false'><img src='" . PATH_SECURIMAGE . "/images/refresh.gif' alt='Reload Image' border='0' onclick='this.blur()' align='bottom' rel='nofollow'></a>\n\n            </div>\n\n            <p style='clear:both'>Please type the characters you see in the image above<br>(You can <a href='" . $_SERVER["PHP_SELF"] . "' rel='nofollow'>load a new image</a> if you cannot see the characters clearly.)</p>\n            <p><input type='text' id='" . $input_id . "' name='" . $input_id . "' size='12'>\n            <input type='submit' value='Submit'></p>\n\n          </form>\r\n" . "\r\n";
     if (isInPath("_admin") && function_exists("Securimage::getCaptchaHtml")) {
         // -- Alt 2: Use the bundled html-generating method for captcha form (NOP)
         $options = array("securimage_path" => PATH_SECURIMAGE, "image_id" => "captcha_image", "image_alt_text" => "CAPTCHA Image", "show_audio_button" => true, "show_refresh_button" => true, "show_text_input" => true, "refresh_alt_text" => "Refresh Image", "refresh_title_text" => "Refresh Image", "input_id" => CAPTCHA_ID, "input_name" => CAPTCHA_ID, "input_text" => "Type the text:", "input_attributes" => array(), "image_attributes" => array(), "audio_button_bgcol" => "#ff0", "audio_icon_url" => null, "audio_play_url" => null, "audio_swf_url" => null, "error_html" => null, "namespace" => "");
         $stdout = Securimage::getCaptchaHtml($options);
     }
     // end if (isInPath("_admin"))
     return $stdout;
 }
コード例 #16
0
  } elseif (!IS_INDEXPAGE
            && !IS_SUB
            && in_array($GLOBALS["frontselect"],array(1,3,4,5,6,7,8,9,11))
            && (!isset($_SESSION["splashimage"]) || $_SESSION["splashimage"])) {
    $GLOBALS[SUBSITE]["regions"]["headlineleft"][] = "block::Bsplashimage('single','splashimage')" ;
  } elseif (IS_INDEXPAGE
            && in_array($GLOBALS["frontselect"],array(1,3,4,5,6,7,8,9,11))
            && isInPath("nordita2011/")) {
    $GLOBALS[SUBSITE]["regions"]["headlineleft"][] = "block::BsubsiteHeadline('subsiteheadline','framed')";
  }
} else */
if (!IS_ENTRANCE) {
    if (SHOW_SEARCH && (!isset($_SESSION["minimenu"]) || !$_SESSION["minimenu"])) {
        $GLOBALS[SUBSITE]["layout"]["container-scrolled"][] = "searchfield";
    }
    if (isInPath("/" . PATH_NEWS . "/") || isInPath("/" . PATH_NEWSTEST . "/")) {
        $GLOBALS[SUBSITE]["layout"]["container-scrolled"][] = "newsissue";
    }
}
if (!IS_ENTRANCE) {
    if (!IS_INDEXPAGE && $this->getConfig("showsplash") && (!isset($_SESSION["splashimage"]) || $_SESSION["splashimage"])) {
        $GLOBALS[SUBSITE]["layout"]["container-scrolled"][] = "splashimage";
    } elseif (IS_SUB) {
        if ($this->getConfig("defaultsplash") != "") {
            $GLOBALS[SUBSITE]["layout"]["container-scrolled"][] = "splashimage";
        } else {
            $GLOBALS[SUBSITE]["layout"]["container-scrolled"][] = "subsiteheadline";
        }
    }
}
/* RESTORE if test tabs needed */
コード例 #17
0
// -- REGION topcenter
// -----------------------
if (IS_ENTRANCE) {
    $GLOBALS[SUBSITE]["regions"]["topcenter"] = array();
} else {
    $GLOBALS[SUBSITE]["regions"]["topcenter"][] = "block::Btopmenu('topmenu','')";
    $GLOBALS[SUBSITE]["regions"]["topcenter"][] = "block::BfeedLink('feed')";
}
// -----------------------
// -- REGION headlinecenter
// -----------------------
$GLOBALS[SUBSITE]["regions"]["headlinecenter"][] = "block::BcontentHeading('contentheading')";
// -----------------------
// -- REGION columnleft
// -----------------------
if (IS_INDEXPAGE || isInPath("startpage")) {
    // accordion: 0=always open; 1=open on click:
    $GLOBALS[SUBSITE]["regions"]["columnleft"][] = "block::BstartpageAnnouncements('announcements','',0)";
} elseif (IS_ENTRANCE) {
    $GLOBALS[SUBSITE]["regions"]["columnleft"] = array();
} else {
    $GLOBALS[SUBSITE]["regions"]["columnleft"][] = "block::BfullTree('fulltree','','menu')";
}
// -----------------------
// -- REGION columnright
// -----------------------
if (IS_ENTRANCE) {
    $GLOBALS[SUBSITE]["regions"]["columnright"] = array();
} else {
    $GLOBALS[SUBSITE]["regions"]["columnright"][] = "block::getSidebarBoxes()";
    // cache of block::BsidebarBoxes()
コード例 #18
0
 public function updateOnePreprint($inRecord)
 {
     if (!IS_TESTSERVER && isInPath("preprints_test")) {
         return FALSE;
     }
     if (empty($inRecord)) {
         return FALSE;
     }
     $outRecord = $this->translatePrpFieldsFromStandard($inRecord);
     if (!isset($outRecord["RowId"])) {
         return FALSE;
     }
     // ----------------------
     $set = array();
     foreach ($outRecord as $field => $value) {
         if ($field != "RowId") {
             $set[] = "  " . $field . "='" . addslashes(strip_tags($value)) . "'";
         }
     }
     $sql = "UPDATE " . "  " . $this->dbprefix . PP_DATATABLE . " " . "SET " . implode(",", $set) . " " . "WHERE " . "  RowId='" . $outRecord["RowId"] . "'";
     // ----------------------
     return (bool) $this->query($sql, IS_TESTSERVER);
     // includes a call to connect
 }