No static content on Moin wiki with lighttpd/FastCGI - raspberry-pi

I have installed MoinMoin wiki on a Raspberry Pi 4 with lighttpd using FastCGI following mostly this guide:
https://kia.jimmynguyen.co.nz/python/moin/wiki/lighttpd/2020/10/31/moin-wiki-installation-with-lighttpd.html
The problem is that it does not display any of moin static files, so it looks like this:
I am kind of lost and don't know what to look for, so any help will be gold!
I also have Pi-hole running on the same RPi.
I have installed moin with --prefix=/usr/local and my wiki instance is at /opt/wiki.
All static files are at /usr/local/lib/python2.7/dist-packages/MoinMoin/web/static/htdocs/
My /etc/lighttpd/lighttpd.conf looks like this:
server.modules = (
"mod_access",
"mod_accesslog",
"mod_auth",
"mod_expire",
"mod_redirect",
"mod_setenv",
"mod_rewrite",
"mod_fastcgi"
)
server.document-root = "/var/www/html"
server.error-handler-404 = "/pihole/index.php"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error-pihole.log"
server.pid-file = "/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
...
...
...
$HTTP["url"] =~ "^/wiki/" {
fastcgi.server += ( "/" =>
((
"socket" => "/tmp/moin.socket",
"min-procs" => 1,
"max-procs" => 2,
"check-local" => "disable",
"bin-path" => "/opt/wiki/moin.fcgi",
"fix-root-scriptname" => "enable"
))
)
alias.url += ( "/moin_static1911" => "/usr/local/lib/python2.7/dist-packages/MoinMoin/web/static/htdocs/")
}

After investing more time in this subject I followed the HelpOnConfiguration/IntegratingWithLighttpd advice:
Lighttpd 1.4
MoinMoin is listening in FastCGI mode on port 22000.
$HTTP["url"] =~ "^/wiki" {
fastcgi.server = ("/wiki" => ( "mywiki" =>
( "host" => "127.0.0.1",
"port" => 22000,
"check-local" => "disable",
"broken-scriptfilename" => "enable" )
)) }
Also, 'alias.url' should not be inside wiki condition and I moved my code to 'external.conf'.
The result:
# Add FastCGI module
server.modules += ( "mod_fastcgi",
"mod_alias"
)
$HTTP["url"] =~ "^/wiki" {
fastcgi.server += ("/wiki" => ( "mywiki" =>
( "socket" => "/tmp/moin.socket",
"min-procs" => 1,
"max-procs" => 2,
"check-local" => "disable",
"bin-path" => "/opt/wiki/moin.fcgi"
)
))
}
alias.url += ( "/moin_static1911" => "/usr/local/lib/python2.7/dist-packages/MoinMoin/web/static/htdocs/")

Related

Why my postman hang forever with with GuzzleHttp\Client request?

Working with lumen-passport in lumen 8 I
got client_secret and client_id and make a request with GuzzleHttp\Client and my postman hang forever:
My postman : https://imgur.com/a/LbtUIVi
In routes/web.php :
$router->group(['prefix'=>'api/v1'], function() use($router){
$router->post('/register','AuthController#register');
$router->post('/login', 'AuthController#login');
In my control :
$client = new Client();
try {
$clientResponse = $client->post( 'http://localhost:8000/api/v1/oauth/token' /* config('service.passport.login_endpoint' ) */ , [
"form_params" => [
"client_secret" => 'DfiXey63ABDjgX7upuNaGmGvvASzhGq9kjZTV9nm', //config('service.passport.client_secret'),
"client_id" => 2, //config('service.passport.client_id'),
"grant_type" => "client_credentials",
"username" => $request->email,
"password" => $request->password
]
]);
\Log::info( varDump(-3, ' -3 login $clientResponse::') );
return $clientResponse;
} catch (BadResponseException $e) {
\Log::info( varDump(-4, ' -4 login ::') );
\Log::info( varDump($e->getMessage(), ' -4 login $e->getMessage()::') );
return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
}
In bootstrap/app.php I have :
// Enable auth middleware (shipped with Lumen)
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
//$app->configure('app');
$app->register(App\Providers\AppServiceProvider::class);
// Enable auth middleware (shipped with Lumen)
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
//$app->configure('app');
$app->register(App\Providers\AppServiceProvider::class);
// Finally register two service providers - original one and Lumen adapter
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
// Finally register two service providers - original one and Lumen adapter
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
...
\Dusterio\LumenPassport\LumenPassport::routes($app, ['prefix' => 'api/v1/oauth']);
Under console I see :
ProjectName$ php -S localhost:8000 -t public
[Tue Jun 1 07:27:23 2021] PHP 7.4.18 Development Server (http://localhost:8000) started
[Tue Jun 1 07:27:29 2021] 127.0.0.1:45940 Accepted
[Tue Jun 1 07:27:29 2021] 127.0.0.1:45944 Accepted
[Tue Jun 1 07:27:29 2021] 127.0.0.1:45940 [200]: GET /
[Tue Jun 1 07:27:29 2021] 127.0.0.1:45940 Closing
[Tue Jun 1 07:27:31 2021] 127.0.0.1:45948 Accepted
[Tue Jun 1 07:27:31 2021] 127.0.0.1:45944 [200]: GET /
[Tue Jun 1 07:27:31 2021] 127.0.0.1:45944 Closing
[Tue Jun 1 07:27:41 2021] 127.0.0.1:45956 Accepted
I tried to debug guzzle source and found that it hang in file /vendor/guzzlehttp/guzzle/src/Client.php,
in method:
private function transfer(RequestInterface $request, array $options): PromiseInterface
{
$request = $this->applyOptions($request, $options);
/** #var HandlerStack $handler */
$handler = $options['handler'];
\Log::info( varDump(-21, ' -21 transfer::') );
\Log::info( varDump($handler, ' $handler transfer::') );
try {
return P\Create::promiseFor($handler($request, $options)); // I suppose it hang forever here
} catch (\Exception $e) {
return P\Create::rejectionFor($e);
}
}
Checking content of $handler in log file I see :
[2021-06-01 04:54:47] local.INFO: (Object of GuzzleHttp\HandlerStack) : $handler transfer:: : Array
(
[ GuzzleHttp\HandlerStack handler] => Closure Object
(
[static] => Array
(
[default] => Closure Object
(
[static] => Array
(
[default] => GuzzleHttp\Handler\CurlMultiHandler Object
(
[factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object
(
[handles:GuzzleHttp\Handler\CurlFactory:private] => Array
(
)
[maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50
)
[selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1
[active:GuzzleHttp\Handler\CurlMultiHandler:private] =>
[handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array
(
)
[delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array
(
)
[options:GuzzleHttp\Handler\CurlMultiHandler:private] => Array
(
)
)
[sync] => GuzzleHttp\Handler\CurlHandler Object
(
[factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object
(
[handles:GuzzleHttp\Handler\CurlFactory:private] => Array
(
)
[maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3
)
)
)
[parameter] => Array
(
[$request] => <required>
[$options] => <required>
)
)
[streaming] => GuzzleHttp\Handler\StreamHandler Object
(
[lastHeaders:GuzzleHttp\Handler\StreamHandler:private] => Array
(
)
)
)
[parameter] => Array
(
[$request] => <required>
[$options] => <required>
)
)
[ GuzzleHttp\HandlerStack stack] => Array
(
[0] => Array
(
[0] => Closure Object
(
[static] => Array
(
[bodySummarizer] =>
)
[parameter] => Array
(
[$handler] => <required>
)
)
[1] => http_errors
)
[1] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$handler] => <required>
)
)
[1] => allow_redirects
)
[2] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$handler] => <required>
)
)
[1] => cookies
)
[3] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$handler] => <required>
)
)
[1] => prepare_body
)
)
[ GuzzleHttp\HandlerStack cached] =>
)
Any idea what is wrong? Local server misconfig ?
PHP 7.4.18 under kubuntu
"dusterio/lumen-passport": "^0.3.4",
"guzzlehttp/guzzle": "^7.3",
"laravel/lumen-framework": "^8.0",
Thanks in advance!
I don't have so experience in lumen, but I am using in environment develop this solution without Guzzle.
public function login(Request $request){
$email = $request->email;
$password = $request->password;
//Check if field is not empty
if (empty($email) or empty($password)) {
return response()->json(['status' => 'error', 'message' => 'You must fill all fields']);
}
$user = User::where('email', '=', $email)->exists();
if ($user === false) {
return response()->json(['status' => 'error', 'message' => 'User doesnt exist']);
}
//$client = new \GuzzleHttp\Client();
try{
$tokenRequest = $request->create(
env('PASSPORT_LOGIN_ENDPOINT'),
'POST'
);
$tokenRequest->request->add([
"grant_type" => "password",
"username" => $request->email,
"password" => $request->password,
"client_id" => env('PASSPORT_CLIENT_ID'),
"client_secret" => env('PASSPORT_CLIENT_SECRET'),
]);
$response = app()->handle($tokenRequest);
return $response;
} catch (\Exception $e) {
return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
}
}

Illuminate returns results in JSON - why?

I'm using Illuminate to access my database
<body>
<?php
$edges = Edge::all();
foreach ($edges as $key => $value) {
print $value;
}
?>
</body>
browser returns:
{"childID":"A","parentID":"C","updated_at":null,"created_at":null}{"childID":"B","parentID":"E","updated_at":null,"created_at":null}{"childID":"C","parentID":"D","updated_at":null,"created_at":null}{"childID":"C","parentID":"F","updated_at":null,"created_at":null}{"childID":"Y","parentID":"Z","updated_at":"2014-08-07 10:26:54","created_at":"2014-08-07 10:26:54"}
What's odd or unexpected for me at least is that my results are returned in JSON. If you could
shine some light on this, i.e. why this might be, or the reason is...I'd be grateful.
If I dump the results in the browser with:
<?php
print '<pre>';print_r($edges);
?>
produces:
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => Edge Object
(
[connection:protected] =>
[table:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[original:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[relations:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[appends:protected] => Array
(
)
[fillable:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
[dates:protected] => Array
(
)
[touches:protected] => Array
(
)
[observables:protected] => Array
(
)
[with:protected] => Array
(
)
[morphClass:protected] =>
[exists] => 1
)
[1] => Edge Object
(...)
...
)
In terms of the front-end results - I'm really only interested in the:
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
part of the object; only NOT in JSON; in plain text.

How to access individual elements of perl Hashed object?

I'm a non-programmer attemting to retrieve useful info from our InfoBlox DHCP boxes. I've installed the Perl API and can make some use of it.
I've got an output from the Data::Dumper "thingie" that appears to have some of the info I want. I'd like to directly reference some of that data but I'm unsure how.
print Dumper(\$object)
Here is part of the Data::Dumper output;
$VAR1 = \bless( {
'network' => '10.183.1.0/24',
'override_lease_scavenge_time' => 'false',
'enable_ifmap_publishing' => 'false',
'low_water_mark_reset' => '10',
'use_lease_time' => 0,
'use_enable_option81' => 0,
'network_container' => '/',
'override_ddns_ttl' => 'false',
'rir' => 'NONE',
'network_view' => bless( {
<snip> --------------------------------------
'extattrs' => {
'Use' => bless( {
'value' => 'Voip'
}, 'Infoblox::Grid::Extattr' )
},
<snip> --------------------------------------
'members' => [
bless( {
'ipv4addr' => '10.85.9.242',
'name' => 'ig3-app3.my.net'
}, 'Infoblox::DHCP::Member' ),
bless( {
'ipv4addr' => '10.85.9.210',
'name' => 'ig3-app1.my.net'
}, 'Infoblox::DHCP::Member' ),
bless( {
'ipv4addr' => '10.85.9.226',
'name' => 'ig3-app2.my.net'
}, 'Infoblox::DHCP::Member' )
],
'override_ignore_client_identifier' => 'false',
'email_list' => undef,
'rir_registration_status' => '??
}, 'Infoblox::DHCP::Network' );
How do I view the elements? ie ...
print $object{members->name};
print $object{members->ipv4addr};
print $object{extattrs->Use->value};
I've found the API dox insufficiant for my skill level:) The data I'd like to pull remains just out of reach.
my #retrieved_objs = $session->search (
object => "Infoblox::DHCP::Network",
network => '.*\.*\.*\..*',
);
foreach $object ( #retrieved_objs ) {
my $network = $object->network;
my $comment = $object->comment;
my $extattrs = $object->extattrs;
my $options = $object->options;
print $network, " network ", $comment, " ", $extattrs, " ", $options, "\n";
}
-------- output ---
10.183.2.0/24 network HASH(0x6a2f038) ARRAY(0x1d20eb0)
10.192.1.0/24 network HASH(0x9df6540) ARRAY(0x9df5468)
10.192.2.0/24 network HASH(0xa088fc8) ARRAY(0xa089718)
You shouldn't try to access the internal values of an object directly. The module - in this case Infoblox::DHCP::Network will provide methods that allow you to read or manipulate the values properly.

LWP Get Large File Download Headers Missing

This post is follow on work related to LWP GET large file download. That post was regarding an error from LWP when trying to pass arguments in the header incorrectly. Now I am posting the changes I made and how I am trying to debug the approach. This discussion should be very informative for those interested in POST vs GET header formation, and what the server receives while using the CGI package. It is not information easily found on the net.
Here is my client code snip:
my $bytes_received = 0; # vars used below are set prior to this point
my $filename = $opt{t}."/$srcfile";
open (FH, ">", "$filename") or $logger->error( "Couldn't open $filename for writing: $!" );
my $ua = LWP::UserAgent->new();
my $target = $srcfile;
my $res = $ua->get(
$url,
':content_cb' => \&callback,
'api' => 'olfs', # Note attempted use of different types of quotes had no impact
"cmd" => 'rfile',
"target" => $target,
"bs" => $bs
);
print $logger->info("$bytes_received bytes received");
sub callback{
my($chunk, $res) = #_;
$bytes_received += length($chunk);
print FH $chunk;
}
Here is the server snip (cgi script):
my $query = new CGI;
my $rcvd_data = Dumper($query);
print $rcvd_data;
Here is the output from a GET:
$VAR1 = bless( {
'.parameters' => [],
'use_tempfile' => 1,
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'param' => {},
'.header_printed' => 1,
'escape' => 1
}, 'CGI' );
Here is a client with a POST request:
my $ua = new LWP::UserAgent();
local $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;
my $req =
POST
$url,
'Content_Type' => 'form-data',
'Content' => {
"api" => 'olfs',
"cmd" => 'wfile',
"target" => $target,
"tsize" => $file_size,
"bs" => $bs,
"filename" => [ $file ] };
# HTTP::Message calls set_content, which appears to set the subroutine for content
# LWP::UserAgent
# LWP::Protocol::file::request sends content in chunks
#
$req->content( $req->content() );
$logger->info("Uploading: $file");
my $resp = $ua->request($req);
Here is the output on the server, just like before but now from the POST:
'.parameters' => [
'cmd',
'bs',
'api',
'target',
'filename',
'tsize'
],
'use_tempfile' => 1,
'.tmpfiles' => {
'*Fh::fh00001random23' => {
'info' => {
'Content-Type' => 'text/plain',
'Content-Disposition' => 'form-data; name="filename"; filename="random23"'
},
'name' => bless( do{\(my $o = '/usr/tmp/CGItemp33113')}, 'CGITempFile' ),
'hndl' => bless( \*Fh::fh00001random23, 'Fh' )
}
},
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'param' => {
'cmd' => [
'wfile'
],
'bs' => [
'buffer1'
],
'api' => [
'olfs'
],
'target' => [
'random23'
],
'tsize' => [
'1073741824'
],
'filename' => [
$VAR1->{'.tmpfiles'}{'*Fh::fh00001random23'}{'hndl'}
},
'escape' => 1,
'.header_printed' => 1
}, 'CGI' );
In short, you can see in the POST dump the "key" / "value" pairs, ie "target => random23". In the GET dump I do not find any keys or values from what I submitted on the client side. Can that be explained, or what do I need to do so as to extract key / value pairs in the CGI script?
You're passing your form variables as HTTP headers.
Like I previously mentioned, if you want to build a url, you can use URI.
$url = URI->new($url);
$url->query_form(
api => 'olfs',
cmd => 'rfile',
target => $target,
bs => $bs,
);

How to make an activity to everyone to see on Social Engine?

I am trying to make an activity published by an admin to be visible to every member of the network, not just their friends.
As far as I could make until now, is that the table stream is preventing my message to became public, it only make a profile message. Visible only in its feed.
Does anyone have any idea how to enforce this?
[EDIT]
My code below is picking tweets in my account, I am using some settings i created (like the screen_name from twitter and the user who is publishing the tweet at the feed).
The code is doing as follows:
-> Checking if there is settings for twitter user to read its messages.
-> Save it in a table
-> Authorizing (in theory) to everyone to read this messages, ether is friend of the publisher or not.
-> Adding the activity, that I also created.
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
if ($TwitterUser != '') {
// Ultimo tweet postado
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$query = $table->select ()->order ( 'tweets_id desc')->limit(1);
$lastTweet = $table->fetchRow ( $query );
// Set the configuration parameters
$config = array ('adapter' => 'Zend_Http_Client_Adapter_Socket', 'ssltransport' => 'tls' );
// Instantiate a client object
if (is_null ( $lastTweet )) {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&count=4&include_rts=1", $config );
} else {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&include_rts=1&since_id=" . $lastTweet->real_id, $config );
}
// The following request will be sent over a TLS secure connection.
$response = $client->request ();
// Pegando a resposta
$body = json_decode ( $response->getBody () );
if (! empty ( $body )) {
$db = Engine_Api::_()->getDbtable('tweets', 'user')->getAdapter();
$db->beginTransaction();
try
{
$table = Engine_Api::_ ()->getDbtable ( 'users', 'user' );
$twitter_user = $table->fetchRow ( $table->select ()->where ( 'user_id = ?', Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.user_id' ) ) );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$activityApi = Engine_Api::_ ()->getDbtable ( 'actions', 'activity' );
foreach ( array_reverse($body) as $tweet ) {
$data = explode ( ' ', $tweet->created_at );
$meses = array ('Jan' => '01', 'Fev' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12' );
$tweet_date = $data ['5'] . "-" . $meses [$data [1]] . '-' . $data [2] . " " . $data [3];
$tweet_date = (date ( 'Y-m-d H:i:s', strtotime ( $tweet_date ) ));
$last_tweet = $table->createRow();
$last_tweet->setFromArray(array(
'real_id' => $tweet->id_str,
'user_id' => $tweet->user->id_str,
'screen_name' => $tweet->user->screen_name,
'body' => $tweet->text,
'retweeted' => $tweet->retweeted,
'created_at' => $tweet_date,
'profile_image_url' => $tweet->user->profile_image_url,
'coordinates' => $tweet->coordinates
));
$last_tweet->save();
// Authorizations
$auth = Engine_Api::_()->authorization()->context;
$auth->setAllowed($last_tweet, 'everyone', 'view', true);
$auth->setAllowed($last_tweet, 'everyone', 'comment', true);
$auth->setAllowed($last_tweet, 'everyone', 'likes', true);
$action = $activityApi->addActivity ($twitter_user,$last_tweet, 'post_twitter', $tweet->text);
if( $action ) {
$activityApi->attachActivity($action, $last_tweet);
}
}
// Commit
$db->commit();
} catch ( Exception $e ) {
$db->rollBack ();
throw $e;
}
}
}
No problems happens, but the tweet that I am tracking only could be red by the user I used to publish it.
You should create entries in stream table for this action_id.