private static function parseSudoCreated(Module_Audit $module, $row) { $data = explode(':', trim($row)); if (count($data) !== 3) { return self::error('Invalid row: ' . $row); } $id = $data[1]; $filename = $data[2]; $filename = substr($filename, strrpos($filename, '/') + 1); $data = explode('-', $filename); if (count($data) !== 5) { return self::error('Invalid row: ' . $row); } $log = new GWF_AuditLog(array('al_id' => $id, 'al_eusername' => $data[0], 'al_username' => $data[1], 'al_type' => $data[2], 'al_time_start' => $data[3], 'al_time_end' => NULL, 'al_rand' => $data[4], 'al_data' => NULL)); if (false === $log->replace()) { echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); return false; } $filename = $log->getFileName(); if (false === GWF_File::touch($filename)) { echo GWF_HTML::err('ERR_WRITE_FILE', array($filename)); return false; } return self::sendMails($module, $log, 1); }
public static function getPlugins($name) { self::$PLUGIN = array(); GWF_File::filewalker(self::getPlugDir(), array(__CLASS__, 'getPlugRec'), false, true, $name); if (GWF3::getConfig('env') === 'dev') { GWF_File::filewalker(self::getPlugDirDev(), array(__CLASS__, 'getPlugRec'), false, true, $name); } GWF_File::filewalker(self::getPlugDirUser(), array(__CLASS__, 'getPlugRec'), false, true, $name); GWF_File::filewalker(self::getPlugDirSecret(), array(__CLASS__, 'getPlugRec'), false, true, $name); usort(self::$PLUGIN, array(__CLASS__, 'sort_power_descending')); return self::$PLUGIN; }
private static function createDirs(Module_Audit $module, $dropTable) { $dirname = GWF_WWW_PATH . 'dbimg'; if (false === GWF_File::createDir($dirname)) { return GWF_HTML::err('ERR_WRITE_FILE', array($dirname)); } $dirname = GWF_WWW_PATH . 'dbimg/sudosh'; if (false === GWF_File::createDir($dirname)) { return GWF_HTML::err('ERR_WRITE_FILE', array($dirname)); } if (false === GWF_HTAccess::protect($dirname)) { return GWF_HTML::err('ERR_WRITE_FILE', array($dirname . '.htaccess')); } return ''; }
<?php GWF_File::filewalker('/home/user', true, 'cron_level_5', false); function cron_level_5($entry, $fullpath, $args = NULL) { $home = $fullpath; $username = $entry; $dir = $fullpath . '/level'; if (false === ($stat = @stat($dir))) { return; } $chmod = $stat['mode']; if ($chmod & 04) { return; } $filename = $home . '/level/5/solution.txt'; if (!Common::isFile($filename)) { // Create solution file $tmp = '/root/_tmp_5'; @file_put_contents($tmp, "The solution to level 5 is 'OhRightThePerms', without the quotes.\n"); @chmod($tmp, '0700'); @chown($tmp, $username); @chgrp($tmp, $username); // Copy it to user home @rename($tmp, $filename); } }
/** * Clear smarty cache. */ public static function wizard_10() { if (false !== ($error = self::wizard_check_cfg_quick())) { return $error; } $back = self::wizard_h2('10'); $template_cache = GWF_SMARTY_DIRS . 'tplc'; if (false === GWF_File::removeDir($template_cache, true, true, false)) { $back .= self::wizard_error('err_clear_smarty'); } $back .= sprintf('<p>%s</p>', self::$gwfil->lang('step_10_0')); $back .= self::wizard_btn('11'); return $back; }
public static function initCityQuests() { foreach (self::$cities as $city) { $city instanceof SR_City; $fullpath = self::getShadowDir() . 'city/' . $city->getName() . '/quest'; if (Common::isDir($fullpath)) { GWF_File::filewalker($fullpath, array($city, 'initQuests')); } } }
} $create = false; $crypt_pass = escapeshellarg($row['password']); if (false === ($uid = getUID($username))) { $nextuid = trim(file_get_contents($uidfile)); $nextuid++; $uid = $nextuid; file_put_contents($uidfile, $uid); $create = true; } if ($uid > 3000) { if ($create) { system(GWF_PATH . 'core/module/Audit/ruth/adduser.sh' . " {$uid} {$username} {$crypt_pass}"); } else { system("/usr/sbin/usermod -p {$crypt_pass} {$username}"); } GWF_File::filewalker(GWF_CORE_PATH . 'module/Audit/challs', 'setup_chall', true, true, $username); if ($create) { $dirname = "/home/user/{$username}/level"; chmod($dirname, 0705); chown($dirname, $username); chgrp($dirname, $username); $dirname = "/home/user/{$username}"; chmod($dirname, 0700); chown($dirname, $username); chgrp($dirname, $username); } } } $db->free($result); $db->truncateTable('war_audit_add_user');
/** * Insert a new image. * @param int $uid * @param string $url * @param string $description * @return Dog_Link */ public static function insertImage($uid, $url, $content) { $link = new self(array('link_id' => '0', 'link_uid' => $uid, 'link_url' => $url, 'link_text' => Common::substrFrom($url, '/', 'IMAGE', true), 'link_rating' => '0', 'link_date' => GWF_Time::getDate(14), 'link_type' => 'image')); if (false === $link->insert()) { echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); return false; } $path = GWF_WWW_PATH . 'dbimg/dogimg/' . $link->getID(); if (false === GWF_File::writeFile($path, $content)) { echo GWF_HTML::err('ERR_WRITE_FILE', array($path)); $link->delete(); return false; } return $link; }
<?php GWF_File::filewalker(GWF_CORE_PATH . 'module/Audit/challs', 'cron_challs', true); function cron_challs($entry, $fullpath, $args = NULL) { if ($entry === 'cronjob.php') { require_once $fullpath; } elseif ($entry === 'cronjob.sh') { $fullpath = escapeshellcmd($fullpath); system("{$fullpath}"); } }
public static function initTimerTrigDirRep($entry, $fullpath, $data) { $data[] = $entry; GWF_File::filewalker($fullpath, array(__CLASS__, 'initTimerTrig'), true, true, $data); }
/** * Copy .example files and replace Variables * Example files have to be in GWF_CORE_PATH/inc/install/data * @param string $file the filename without extension * @param string $path the destination path * @param string $ext file extension (e.g. .php) */ public static function CopyExampleFile($file, $path, $ext = '.php', &$output) { $copied = $path . $file . $ext; if (false === Common::isFile($copied)) { if (false === GWF_File::isWriteable($copied)) { $output .= GWF_InstallWizard::wizard_error('err_copy', array($copied)); return false; } # Load skeleton. $example = GWF_CORE_PATH . 'inc/install/data/' . $file . '.example' . $ext; if (false === ($content = file_get_contents($example))) { $output .= GWF_HTML::err('ERR_FILE_NOT_FOUND', array($example)); return false; } # Replacements $replace = array('%%GWFPATH%%' => GWF_DETECT_PATH, '%%DB%%' => escapeshellarg(GWF_DB_DATABASE), '%%USER%%' => escapeshellarg(GWF_DB_USER), '%%PASS%%' => escapeshellarg(GWF_DB_PASSWORD), '%%SALT%%' => escapeshellarg(GWF_Random::randomKey(16))); $content = str_replace(array_keys($replace), array_values($replace), $content); # Write custom file. if (false === file_put_contents($copied, $content)) { $output .= GWF_HTML::err('ERR_WRITE_FILE', array($copied)); return false; } if (false === chmod($copied, GWF_CHMOD)) { $output .= GWF_InstallWizard::wizard_error('err_copy', array($example)); return false; } $output .= GWF_InstallWizard::wizard_message('msg_copy', array($copied)); } else { $output .= GWF_InstallWizard::wizard_message('msg_copy_untouched', array($copied)); } return true; }
<?php GWF_File::filewalker('/home/user', true, 'cron_welcome', false); function cron_welcome($entry, $fullpath, $args = NULL) { $source = '/etc/skel/WELCOME.txt'; $destin = $fullpath . '/WELCOME.txt'; copy($source, $destin); chown($destin, 'root'); chgrp($destin, 'root'); chmod($destin, 0444); }
foreach ($modules as $module) { $module instanceof Dog_Module; $triggers = $module->getFilteredTriggers(Dog::getServer(), Dog::getChannel(), Dog::getUser()); if (count($triggers) > 0) { sort($triggers); $out .= ' ' . chr(2) . $module->getName() . chr(2) . ': '; $out .= implode(', ', $triggers); $out .= '.'; } } $user = Dog::getUser(); $user->sendNOTICE(substr($out, 1)); # Plugins $out = ''; $plugdir = Dog_Plugin::getPlugDir(); GWF_File::filewalker($plugdir, 'dogplug_help_all', false, true, strlen($plugdir) + 1); ksort($DPH_ALL); foreach ($DPH_ALL as $folder => $commands) { sort($commands); $out .= ' ' . chr(2) . $folder . chr(2) . ': '; $out .= implode(', ', $commands); $out .= '.'; } $user->sendNOTICE(substr($out, 1)); } elseif ($argc === 1) { if (false !== ($plug = Dog_Plugin::getPlug($argv[0]))) { $scopetxt = dogplug_scopetxt($plugin, $plug->getPriv(), $plug->getScope()); $plugin->reply($plug->getHelp() . $scopetxt); } elseif (false !== ($mod = Dog_Module::getByTrigger($argv[0]))) { $scopetxt = dogplug_scopetxt($plugin, $mod->getPriv($argv[0]), $mod->getScope($argv[0])); $plugin->reply($mod->getHelp($argv[0]) . $scopetxt);
<?php require_once '../../../bootstrap.php'; GWF_File::filewalker('/home/user', true, 'install_level_4', false); function install_level_4($entry, $fullpath, $args = NULL) { $home = $fullpath; $username = $entry; include 'install_user.php'; }
<?php $dirname = $home . '/level/4'; if (!Common::isDir($dirname)) { GWF_File::removeDir($dirname); $dirname2 = "/root/kwd"; @mkdir($dirname2, 0700, true); @chmod($dirname2, 0700); @chown($dirname2, $username); @chgrp($dirname2, $username); @rename($dirname2, $dirname); } $filename = $home . '/level/4/README.txt'; if (!Common::isFile($filename)) { $filename2 = tempnam("/tmp", "kwf"); @file_put_contents($filename2, "The solution to level 4 is 'AndIknowchown' without the quotes.\n"); @chmod($filename2, 00); @chown($filename2, $username); @chgrp($filename2, $username); @rename($filename2, $filename); }
} } } else { if (strpos($fullpath, $search) !== false) { if (strpos($fullpath, '/disabled_modules/') === false) { global $__DOG_TRAC_RESULTS; $__DOG_TRAC_RESULTS[] = Common::substrFrom($fullpath, GWF_PATH); } } } } } # Iterate over these dirs $dirs = array('core', 'www/js', 'www/challenge'); foreach ($dirs as $dir) { GWF_File::filewalker(GWF_PATH . $dir, 'dog_trac_helper4', true, true, $message); } # Print results $url = 'http://trac.gwf3.gizmore.org/browser/'; switch (count($__DOG_TRAC_RESULTS)) { case 0: return $plugin->rply('err_file'); case 1: case 2: case 3: $out = ''; foreach ($__DOG_TRAC_RESULTS as $result) { $out .= ' | ' . $url . $result; } return Dog::reply(substr($out, 3)); default:
public function on_repo_checkout_Pb() { GDO::table('Dog_Repo')->createTable(true); GDO::table('Dog_RepoSubscribes')->createTable(true); GDO::table('Dog_RepoUsers')->createTable(true); GWF_File::removeDir(Dog_Repo::baseDir(), false, true, true); $argv = $this->argv(); $argc = count($argv); if ($argc !== 3) { return $this->showHelp('checkout'); } $type = $argv[1]; if (!Dog_Repo::isValidType($type)) { return $this->rply('err_software'); } $url = @parse_url($argv[2]); if (!isset($url['scheme'])) { return $this->rply('err_url', $url); } $url = $argv[2]; if (!GWF_HTTP::pageExists($url)) { return $this->rply('err_connect'); } $name = $argv[0]; if (!Dog_Repo::isValidName($name)) { return $this->rply('err_repo_name'); } if (Dog_Repo::exists($name)) { return $this->rply('err_repo_taken'); } if (!GWF_File::createDir(Dog_Repo::repoDir($name))) { return $this->rply('err_create_dir'); } if (!($repo = Dog_Repo::create($url, $name, $type))) { return Dog::err('ERR_DATABASE', array(__FILE__, __LINE__)); } call_user_func(array($this, 'checkout_' . $type), $repo); }
private static function createItemLangFile() { // printf("%s\n", __METHOD__); $langfile = Shadowlang::getItemfile(); $items = SR_Item::getAllItems(); usort($items, array('SR_Item', 'sort_type_asc')); $old_type = ''; // printf("%s: sorted items...\n", __METHOD__); foreach (Dog_Lang::getISOCodes() as $iso) { $path = sprintf('%slang/item/shadowitems_%s.php', Shadowrun4::getShadowDir(), $iso); if (false === Common::isFile($path)) { continue; } $out = '<?php' . PHP_EOL; $out .= '$lang = array(' . PHP_EOL; foreach ($items as $item) { $item instanceof SR_Item; $type = $item->getItemType(); if ($old_type !== $type) { // printf("%s: New subsection %s\n", __METHOD__, $type); $old_type = $type; $out .= PHP_EOL; $out .= '# ' . $type . PHP_EOL; } $key = $item->getName(); if ($key === ($trans = $langfile->langISO($iso, $key))) { // printf("%s: Unknown Key %s\n", __METHOD__, $key); $out .= sprintf("'%s' => '%s',", $key, str_replace("'", '\\\'', $trans)); } else { // printf("%s: Old Key %s\n", __METHOD__, $key); $out .= sprintf("'%s' => '%s',", $key, str_replace("'", '\\\'', $trans)); } $out .= PHP_EOL; $key .= '__desc__'; if ($key === ($trans = $langfile->langISO($iso, $key))) { $out .= sprintf("'%s' => '%s',", $key, str_replace("'", '\\\'', $item->getItemDescription())); } else { $out .= sprintf("'%s' => '%s',", $key, str_replace("'", '\\\'', $trans)); } $out .= PHP_EOL; } $out .= ');' . PHP_EOL; $out .= '?>' . PHP_EOL; GWF_File::writeFile($path, $out); } return true; }